|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity ^0.8.28; |
| 3 | + |
| 4 | +import {BaseScript} from "../utils/Base.s.sol"; |
| 5 | +import {SuccinctStaking} from "../../src/SuccinctStaking.sol"; |
| 6 | +import {SuccinctVApp} from "../../src/SuccinctVApp.sol"; |
| 7 | +import {IntermediateSuccinct} from "../../src/tokens/IntermediateSuccinct.sol"; |
| 8 | +import {SuccinctGovernor} from "../../src/SuccinctGovernor.sol"; |
| 9 | +import {Succinct} from "../../src/tokens/Succinct.sol"; |
| 10 | +import {FixtureLoader} from "../../test/utils/FixtureLoader.sol"; |
| 11 | +import {ERC1967Proxy} from |
| 12 | + "../../lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol"; |
| 13 | +import {SP1VerifierGateway} from "../../lib/sp1-contracts/contracts/src/SP1VerifierGateway.sol"; |
| 14 | +import {SP1Verifier} from "../../lib/sp1-contracts/contracts/src/v5.0.0/SP1VerifierGroth16.sol"; |
| 15 | + |
| 16 | +contract AtomicDeployer { |
| 17 | + // Staking proxy param |
| 18 | + address public stakingImpl; |
| 19 | + |
| 20 | + // IntermediateSuccinct param |
| 21 | + address public prove; |
| 22 | + |
| 23 | + // Governor params |
| 24 | + uint48 public votingDelay; |
| 25 | + uint32 public votingPeriod; |
| 26 | + uint256 public proposalThreshold; |
| 27 | + uint256 public quorumFraction; |
| 28 | + |
| 29 | + address public vappImpl; |
| 30 | + address public owner; |
| 31 | + address public auctioneer; |
| 32 | + address public verifier; |
| 33 | + uint256 public minDepositAmount; |
| 34 | + bytes32 public vkey; |
| 35 | + address public dispenser; |
| 36 | + uint256 public minStakeAmount; |
| 37 | + uint256 public maxUnstakeRequests; |
| 38 | + uint256 public unstakePeriod; |
| 39 | + uint256 public slashCancellationPeriod; |
| 40 | + bytes32 public genesisStateRoot; |
| 41 | + |
| 42 | + address public deployerOwner; |
| 43 | + |
| 44 | + constructor() { |
| 45 | + deployerOwner = msg.sender; |
| 46 | + } |
| 47 | + |
| 48 | + modifier onlyOwner() { |
| 49 | + require(msg.sender == deployerOwner); |
| 50 | + _; |
| 51 | + } |
| 52 | + |
| 53 | + function setParams1( |
| 54 | + address _stakingImpl, |
| 55 | + address _prove, |
| 56 | + uint48 _votingDelay, |
| 57 | + uint32 _votingPeriod, |
| 58 | + uint256 _proposalThreshold, |
| 59 | + uint256 _quorumFraction |
| 60 | + ) external onlyOwner { |
| 61 | + stakingImpl = _stakingImpl; |
| 62 | + prove = _prove; |
| 63 | + votingDelay = _votingDelay; |
| 64 | + votingPeriod = _votingPeriod; |
| 65 | + proposalThreshold = _proposalThreshold; |
| 66 | + quorumFraction = _quorumFraction; |
| 67 | + } |
| 68 | + |
| 69 | + function setParams2( |
| 70 | + address _vappImpl, |
| 71 | + address _owner, |
| 72 | + address _auctioneer, |
| 73 | + address _verifier, |
| 74 | + uint256 _minDepositAmount, |
| 75 | + bytes32 _vkey |
| 76 | + ) external onlyOwner { |
| 77 | + vappImpl = _vappImpl; |
| 78 | + owner = _owner; |
| 79 | + auctioneer = _auctioneer; |
| 80 | + verifier = _verifier; |
| 81 | + minDepositAmount = _minDepositAmount; |
| 82 | + vkey = _vkey; |
| 83 | + } |
| 84 | + |
| 85 | + function setParams3( |
| 86 | + address _dispenser, |
| 87 | + uint256 _minStakeAmount, |
| 88 | + uint256 _maxUnstakeRequests, |
| 89 | + uint256 _unstakePeriod, |
| 90 | + uint256 _slashCancellationPeriod, |
| 91 | + bytes32 _genesisStateRoot |
| 92 | + ) external onlyOwner { |
| 93 | + dispenser = _dispenser; |
| 94 | + minStakeAmount = _minStakeAmount; |
| 95 | + maxUnstakeRequests = _maxUnstakeRequests; |
| 96 | + unstakePeriod = _unstakePeriod; |
| 97 | + slashCancellationPeriod = _slashCancellationPeriod; |
| 98 | + genesisStateRoot = _genesisStateRoot; |
| 99 | + } |
| 100 | + |
| 101 | + function deploy(bytes32 salt, bytes calldata iproveCode, bytes calldata governorCode) |
| 102 | + external |
| 103 | + onlyOwner |
| 104 | + returns (address, address, address, address) |
| 105 | + { |
| 106 | + address STAKING; |
| 107 | + { |
| 108 | + STAKING = address(new ERC1967Proxy{salt: salt}(stakingImpl, "")); |
| 109 | + } |
| 110 | + |
| 111 | + address I_PROVE; |
| 112 | + { |
| 113 | + // I_PROVE = address(new IntermediateSuccinct{salt: salt}(prove, STAKING)); |
| 114 | + bytes memory args = abi.encode(prove, STAKING); |
| 115 | + bytes memory initCode = abi.encodePacked(iproveCode, args); |
| 116 | + |
| 117 | + assembly { |
| 118 | + I_PROVE := create2(0, add(initCode, 0x20), mload(initCode), salt) |
| 119 | + if iszero(extcodesize(I_PROVE)) { revert(0, 0) } |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + address GOVERNOR; |
| 124 | + { |
| 125 | + // GOVERNOR = address( |
| 126 | + // new SuccinctGovernor{salt: salt}( |
| 127 | + // I_PROVE, votingDelay, votingPeriod, proposalThreshold, quorumFraction |
| 128 | + // ) |
| 129 | + // ); |
| 130 | + bytes memory args = |
| 131 | + abi.encode(I_PROVE, votingDelay, votingPeriod, proposalThreshold, quorumFraction); |
| 132 | + bytes memory initCode = abi.encodePacked(governorCode, args); |
| 133 | + |
| 134 | + assembly { |
| 135 | + GOVERNOR := create2(0, add(initCode, 0x20), mload(initCode), salt) |
| 136 | + if iszero(extcodesize(GOVERNOR)) { revert(0, 0) } |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + address VAPP; |
| 141 | + { |
| 142 | + // Encode the initialize function call data |
| 143 | + bytes memory vappInitData; |
| 144 | + { |
| 145 | + vappInitData = abi.encodeCall( |
| 146 | + SuccinctVApp.initialize, |
| 147 | + ( |
| 148 | + owner, |
| 149 | + prove, |
| 150 | + I_PROVE, |
| 151 | + auctioneer, |
| 152 | + STAKING, |
| 153 | + verifier, |
| 154 | + minDepositAmount, |
| 155 | + vkey, |
| 156 | + genesisStateRoot |
| 157 | + ) |
| 158 | + ); |
| 159 | + } |
| 160 | + VAPP = address(new ERC1967Proxy{salt: salt}(vappImpl, vappInitData)); |
| 161 | + } |
| 162 | + |
| 163 | + SuccinctStaking(STAKING).initialize( |
| 164 | + owner, |
| 165 | + GOVERNOR, |
| 166 | + VAPP, |
| 167 | + prove, |
| 168 | + I_PROVE, |
| 169 | + dispenser, |
| 170 | + minStakeAmount, |
| 171 | + maxUnstakeRequests, |
| 172 | + unstakePeriod, |
| 173 | + slashCancellationPeriod |
| 174 | + ); |
| 175 | + |
| 176 | + return (STAKING, VAPP, I_PROVE, GOVERNOR); |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +// Deploy all contracts. |
| 181 | +contract AllAtomicScript is BaseScript, FixtureLoader { |
| 182 | + function run() external broadcaster { |
| 183 | + // Read config |
| 184 | + bytes32 salt = readBytes32("CREATE2_SALT"); |
| 185 | + address OWNER = readAddress("OWNER"); |
| 186 | + address PROVE = readAddress("PROVE"); |
| 187 | + address VERIFIER = readAddress("VERIFIER"); |
| 188 | + |
| 189 | + // Deploy implementation contracts |
| 190 | + address STAKING_IMPL = address(new SuccinctStaking{salt: salt}()); |
| 191 | + address VAPP_IMPL = address(new SuccinctVApp{salt: salt}()); |
| 192 | + |
| 193 | + // Atomically deploy the rest of the contracts |
| 194 | + { |
| 195 | + AtomicDeployer deployer = new AtomicDeployer(); |
| 196 | + { |
| 197 | + uint48 VOTING_DELAY = readUint48("VOTING_DELAY"); |
| 198 | + uint32 VOTING_PERIOD = readUint32("VOTING_PERIOD"); |
| 199 | + uint256 PROPOSAL_THRESHOLD = readUint256("PROPOSAL_THRESHOLD"); |
| 200 | + uint256 QUORUM_FRACTION = readUint256("QUORUM_FRACTION"); |
| 201 | + deployer.setParams1( |
| 202 | + STAKING_IMPL, |
| 203 | + PROVE, |
| 204 | + VOTING_DELAY, |
| 205 | + VOTING_PERIOD, |
| 206 | + PROPOSAL_THRESHOLD, |
| 207 | + QUORUM_FRACTION |
| 208 | + ); |
| 209 | + } |
| 210 | + { |
| 211 | + address AUCTIONEER = readAddress("AUCTIONEER"); |
| 212 | + uint256 MIN_DEPOSIT_AMOUNT = readUint256("MIN_DEPOSIT_AMOUNT"); |
| 213 | + bytes32 VKEY = readBytes32("VKEY"); |
| 214 | + deployer.setParams2( |
| 215 | + VAPP_IMPL, OWNER, AUCTIONEER, VERIFIER, MIN_DEPOSIT_AMOUNT, VKEY |
| 216 | + ); |
| 217 | + } |
| 218 | + { |
| 219 | + address DISPENSER = readAddress("DISPENSER"); |
| 220 | + uint256 MIN_STAKE_AMOUNT = readUint256("MIN_STAKE_AMOUNT"); |
| 221 | + uint256 MAX_UNSTAKE_REQUESTS = readUint256("MAX_UNSTAKE_REQUESTS"); |
| 222 | + uint256 UNSTAKE_PERIOD = readUint256("UNSTAKE_PERIOD"); |
| 223 | + uint256 SLASH_CANCELLATION_PERIOD = readUint256("SLASH_CANCELLATION_PERIOD"); |
| 224 | + bytes32 GENESIS_STATE_ROOT = readBytes32("GENESIS_STATE_ROOT"); |
| 225 | + deployer.setParams3( |
| 226 | + DISPENSER, |
| 227 | + MIN_STAKE_AMOUNT, |
| 228 | + MAX_UNSTAKE_REQUESTS, |
| 229 | + UNSTAKE_PERIOD, |
| 230 | + SLASH_CANCELLATION_PERIOD, |
| 231 | + GENESIS_STATE_ROOT |
| 232 | + ); |
| 233 | + } |
| 234 | + (address STAKING, address VAPP, address I_PROVE, address GOVERNOR) = deployer.deploy( |
| 235 | + salt, type(IntermediateSuccinct).creationCode, type(SuccinctGovernor).creationCode |
| 236 | + ); |
| 237 | + writeAddress("STAKING", STAKING); |
| 238 | + writeAddress("VAPP", VAPP); |
| 239 | + writeAddress("I_PROVE", I_PROVE); |
| 240 | + writeAddress("GOVERNOR", GOVERNOR); |
| 241 | + } |
| 242 | + |
| 243 | + // Write addresses |
| 244 | + writeAddress("STAKING_IMPL", STAKING_IMPL); |
| 245 | + writeAddress("VAPP_IMPL", VAPP_IMPL); |
| 246 | + } |
| 247 | +} |
0 commit comments