|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.21; |
| 3 | + |
| 4 | +import { Script, console } from "forge-std/Script.sol"; |
| 5 | +import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; |
| 6 | +import { IVotes } from "@openzeppelin/contracts/governance/utils/IVotes.sol"; |
| 7 | +import { Proposal } from "./Proposal.sol"; |
| 8 | +import { IGovernor } from "@openzeppelin/contracts/governance/IGovernor.sol"; |
| 9 | +import { SeamlessAddressBook } from "../../helpers/SeamlessAddressBook.sol"; |
| 10 | +import { IVotes } from "@openzeppelin/contracts/governance/utils/IVotes.sol"; |
| 11 | + |
| 12 | +contract TenderlySimulation is Script { |
| 13 | + // Change this to GOVERNOR_LONG if the proposal is made on the long governor |
| 14 | + IGovernor governance = IGovernor(SeamlessAddressBook.GOVERNOR_SHORT); |
| 15 | + IVotes seam = IVotes(SeamlessAddressBook.SEAM); |
| 16 | + |
| 17 | + Proposal proposal = new Proposal(); |
| 18 | + |
| 19 | + address proposerAddress = 0x67b6dB42115d94Cc3FE27E92a3d12bB224041ac0; |
| 20 | + uint256 proposerPk = |
| 21 | + 0x82fe25cccae9752b856c8857de74671320277f92e737b2116a5d9739dec59a26; |
| 22 | + |
| 23 | + function _getProposalData(string memory descriptionPath) |
| 24 | + internal |
| 25 | + view |
| 26 | + returns (uint256 proposalId, bytes32 descriptionHash) |
| 27 | + { |
| 28 | + string memory description = vm.readFile(descriptionPath); |
| 29 | + descriptionHash = keccak256(bytes(description)); |
| 30 | + |
| 31 | + proposalId = governance.hashProposal( |
| 32 | + proposal.getTargets(), |
| 33 | + proposal.getValues(), |
| 34 | + proposal.getCalldatas(), |
| 35 | + descriptionHash |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + function setupProposer() public { |
| 40 | + console.log("Setting up proposer"); |
| 41 | + |
| 42 | + _fundETH(); |
| 43 | + _fundSEAM(); |
| 44 | + |
| 45 | + moveOneBlockForwardOneSecond(); |
| 46 | + } |
| 47 | + |
| 48 | + function delegateToProposer() public { |
| 49 | + vm.startBroadcast(proposerPk); |
| 50 | + seam.delegate(proposerAddress); |
| 51 | + vm.stopBroadcast(); |
| 52 | + } |
| 53 | + |
| 54 | + function moveOneBlockForwardOneSecond() public { |
| 55 | + vm.rpc("evm_increaseTime", "[\"0x1\"]"); |
| 56 | + } |
| 57 | + |
| 58 | + function _fundSEAM() public { |
| 59 | + string memory params = string.concat( |
| 60 | + "[\"", |
| 61 | + Strings.toHexString(address(seam)), |
| 62 | + "\",[\"", |
| 63 | + Strings.toHexString(proposerAddress), |
| 64 | + "\"],\"0x13DA329B6336471800000\"]" // 1.5M SEAM which is quorum |
| 65 | + ); |
| 66 | + vm.rpc("tenderly_setErc20Balance", params); |
| 67 | + } |
| 68 | + |
| 69 | + function _fundETH() public { |
| 70 | + string memory params = string.concat( |
| 71 | + "[[\"", |
| 72 | + Strings.toHexString(proposerAddress), |
| 73 | + "\"],\"0xDE0B6B3A7640000\"]" // 1 ETH |
| 74 | + ); |
| 75 | + vm.rpc("tenderly_setBalance", params); |
| 76 | + } |
| 77 | + |
| 78 | + function createProposal(string memory descriptionPath) public { |
| 79 | + string memory description = vm.readFile(descriptionPath); |
| 80 | + |
| 81 | + vm.startBroadcast(proposerPk); |
| 82 | + governance.propose( |
| 83 | + proposal.getTargets(), |
| 84 | + proposal.getValues(), |
| 85 | + proposal.getCalldatas(), |
| 86 | + description |
| 87 | + ); |
| 88 | + vm.stopBroadcast(); |
| 89 | + } |
| 90 | + |
| 91 | + function increaseTimeVotingDelay() public { |
| 92 | + console.log("Increasing voting delay"); |
| 93 | + string memory params = string.concat( |
| 94 | + "[", |
| 95 | + Strings.toString(block.timestamp + governance.votingDelay() + 1), |
| 96 | + "]" |
| 97 | + ); |
| 98 | + vm.rpc("evm_setNextBlockTimestamp", params); |
| 99 | + vm.rpc("evm_mine", "[]"); |
| 100 | + } |
| 101 | + |
| 102 | + function castVote(string memory descriptionPath) public { |
| 103 | + console.log("Casting vote"); |
| 104 | + (uint256 proposalId,) = _getProposalData(descriptionPath); |
| 105 | + |
| 106 | + vm.startBroadcast(proposerPk); |
| 107 | + governance.castVote(proposalId, 1); |
| 108 | + vm.stopBroadcast(); |
| 109 | + } |
| 110 | + |
| 111 | + function increaseTimeVotingPeriod() public { |
| 112 | + console.log("Increasing voting period"); |
| 113 | + string memory params = string.concat( |
| 114 | + "[", |
| 115 | + Strings.toString(block.timestamp + governance.votingPeriod() + 1), |
| 116 | + "]" |
| 117 | + ); |
| 118 | + vm.rpc("evm_setNextBlockTimestamp", params); |
| 119 | + vm.rpc("evm_mine", "[]"); |
| 120 | + } |
| 121 | + |
| 122 | + function queueProposal(string memory descriptionPath) public { |
| 123 | + console.log("Queueing proposal"); |
| 124 | + (, bytes32 descriptionHash) = _getProposalData(descriptionPath); |
| 125 | + |
| 126 | + vm.startBroadcast(proposerPk); |
| 127 | + governance.queue( |
| 128 | + proposal.getTargets(), |
| 129 | + proposal.getValues(), |
| 130 | + proposal.getCalldatas(), |
| 131 | + descriptionHash |
| 132 | + ); |
| 133 | + vm.stopBroadcast(); |
| 134 | + } |
| 135 | + |
| 136 | + function setTimeToProposalEta(string memory descriptionPath) public { |
| 137 | + console.log("Setting time to proposal eta"); |
| 138 | + (uint256 proposalId,) = _getProposalData(descriptionPath); |
| 139 | + string memory params = string.concat( |
| 140 | + "[", Strings.toString(governance.proposalEta(proposalId) + 1), "]" |
| 141 | + ); |
| 142 | + vm.rpc("evm_setNextBlockTimestamp", params); |
| 143 | + vm.rpc("evm_mine", "[]"); |
| 144 | + } |
| 145 | + |
| 146 | + function executeProposal(string memory descriptionPath) public { |
| 147 | + console.log("Executing proposal"); |
| 148 | + (, bytes32 descriptionHash) = _getProposalData(descriptionPath); |
| 149 | + |
| 150 | + vm.startBroadcast(proposerPk); |
| 151 | + governance.execute( |
| 152 | + proposal.getTargets(), |
| 153 | + proposal.getValues(), |
| 154 | + proposal.getCalldatas(), |
| 155 | + descriptionHash |
| 156 | + ); |
| 157 | + vm.stopBroadcast(); |
| 158 | + } |
| 159 | +} |
0 commit comments