KibbleDeployer.sol
74 lines · sha256 bd36848c8f1e2846d85e84b6078fa52e8f4ffe98c1029192fe065618f13884ce · Raw
| 1 | // SPDX-License-Identifier: MIT |
| 2 | pragma solidity ^0.8.26; |
| 3 | |
| 4 | import {Vm} from "forge-std/Vm.sol"; |
| 5 | import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; |
| 6 | import {KibbleToken} from "../src/KibbleToken.sol"; |
| 7 | import {Emission} from "../src/Emission.sol"; |
| 8 | import {Genesis} from "../src/Genesis.sol"; |
| 9 | import {Miner} from "../src/Miner.sol"; |
| 10 | import {Zapper} from "../src/Zapper.sol"; |
| 11 | import {Burner} from "../src/Burner.sol"; |
| 12 | import {Oracle} from "../src/Oracle.sol"; |
| 13 | import {LpLocker} from "../src/LpLocker.sol"; |
| 14 | |
| 15 | /// @notice Deploys the 8 KIBBLE contracts in a fixed order from `deployer`, wiring immutable addresses by |
| 16 | /// precomputing CREATE addresses (no initializer, no admin). Shared by Deploy.s.sol and the tests. |
| 17 | library KibbleDeployer { |
| 18 | Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); |
| 19 | |
| 20 | struct System { |
| 21 | KibbleToken token; |
| 22 | Emission emission; |
| 23 | Genesis genesis; |
| 24 | Miner miner; |
| 25 | Zapper zapper; |
| 26 | Burner burner; |
| 27 | Oracle oracle; |
| 28 | LpLocker lpLocker; |
| 29 | } |
| 30 | |
| 31 | error AddressMismatch(uint256 index); |
| 32 | |
| 33 | function deploy(IPoolManager pm, uint256 preorderEndBlock, address deployer) internal returns (System memory s) { |
| 34 | uint64 n = vm.getNonce(deployer); |
| 35 | address[8] memory a; |
| 36 | for (uint256 i; i < 8; ++i) { |
| 37 | a[i] = vm.computeCreateAddress(deployer, n + i); |
| 38 | } |
| 39 | s.token = new KibbleToken(a[1], a[2]); |
| 40 | s.emission = new Emission(KibbleToken(a[0]), Genesis(payable(a[2])), a[3]); |
| 41 | s.genesis = new Genesis( |
| 42 | pm, |
| 43 | KibbleToken(a[0]), |
| 44 | Miner(a[3]), |
| 45 | Emission(a[1]), |
| 46 | Oracle(a[6]), |
| 47 | LpLocker(a[7]), |
| 48 | payable(a[5]), |
| 49 | preorderEndBlock |
| 50 | ); |
| 51 | s.miner = new Miner( |
| 52 | KibbleToken(a[0]), |
| 53 | Emission(a[1]), |
| 54 | Genesis(payable(a[2])), |
| 55 | Oracle(a[6]), |
| 56 | Zapper(payable(a[4])), |
| 57 | Burner(payable(a[5])) |
| 58 | ); |
| 59 | s.zapper = new Zapper(pm, KibbleToken(a[0]), Oracle(a[6]), LpLocker(a[7])); |
| 60 | s.burner = new Burner(pm, KibbleToken(a[0]), Oracle(a[6])); |
| 61 | s.oracle = new Oracle(pm, a[0], a[2]); |
| 62 | s.lpLocker = new LpLocker(pm, a[0]); |
| 63 | |
| 64 | if (address(s.token) != a[0]) revert AddressMismatch(0); |
| 65 | if (address(s.emission) != a[1]) revert AddressMismatch(1); |
| 66 | if (address(s.genesis) != a[2]) revert AddressMismatch(2); |
| 67 | if (address(s.miner) != a[3]) revert AddressMismatch(3); |
| 68 | if (address(s.zapper) != a[4]) revert AddressMismatch(4); |
| 69 | if (address(s.burner) != a[5]) revert AddressMismatch(5); |
| 70 | if (address(s.oracle) != a[6]) revert AddressMismatch(6); |
| 71 | if (address(s.lpLocker) != a[7]) revert AddressMismatch(7); |
| 72 | } |
| 73 | } |
| 74 |