1
1
import { Signer } from 'ethers' ;
2
2
import { ethers } from 'hardhat' ;
3
- import { impersonateAccountWithFunds , stopImpersonateAccount } from '../shared /AccountManipulation' ;
4
- import { increaseNextBlockTime , setNextBlockNumber } from '../shared /TimeManipulation' ;
3
+ import { impersonateAccountWithFunds , stopImpersonateAccount } from './AccountManipulation' ;
4
+ import { increaseNextBlockTime , setNextBlockNumber } from './TimeManipulation' ;
5
5
import { POLYGON_AVERAGE_BLOCK_TIME } from './Constants' ;
6
6
import { DeployedContracts } from './Forking' ;
7
+ import { getABIFromPolygonscan } from './Polygonscan' ;
7
8
8
9
export const createAndExecuteProposal = async ( {
9
10
governor,
@@ -23,15 +24,18 @@ export const createAndExecuteProposal = async ({
23
24
const timeLockSigner = await impersonateAccountWithFunds ( timeLock . address ) ;
24
25
let originalVotingDelay = await governor . votingDelay ( ) ;
25
26
let originalVotingPeriod = await governor . votingPeriod ( ) ;
27
+ console . log ( 'setting voting delay and duration to 2 blocks...' ) ;
26
28
await governor . connect ( timeLockSigner ) . setVotingDelay ( `2` ) ;
27
29
await governor . connect ( timeLockSigner ) . setVotingPeriod ( `2` ) ;
28
30
29
31
// 1. borrow some treasury tokens to user as we need signer with min. proposalThreshold tokens to propose
30
32
const quorumAmount = await governor . quorumVotes ( ) ;
31
33
// careful, this sends ETH to timelock which might break real-world simulation for proposals involving Timelock ETH
34
+ console . log ( 'transferring tokens to user for proposal creation...' ) ;
32
35
await arenaToken . connect ( timeLockSigner ) . transfer ( await user . getAddress ( ) , quorumAmount ) ;
33
36
await arenaToken . connect ( user ) . delegate ( await user . getAddress ( ) ) ;
34
37
const descriptionHash = ethers . utils . keccak256 ( [ ] ) ; // keccak(``)
38
+ console . log ( 'creating proposal...' ) ;
35
39
let tx = await governor . connect ( user ) [ 'propose(address[],uint256[],bytes[],string)' ] ( targets , values , calldatas , `` ) ;
36
40
let { events} = await tx . wait ( ) ;
37
41
// get first event (ProposalCreated), then get first arg of that event (proposalId)
@@ -42,6 +46,7 @@ export const createAndExecuteProposal = async ({
42
46
// simulate elapsed time close to original voting delay
43
47
await increaseNextBlockTime ( Math . floor ( POLYGON_AVERAGE_BLOCK_TIME * originalVotingDelay . toNumber ( ) ) ) ;
44
48
await setNextBlockNumber ( voteStartBlock . toNumber ( ) + 1 ) ; // is a blocknumber which fits in Number
49
+ console . log ( 'casting vote...' ) ;
45
50
tx = await governor . connect ( user ) [ 'castVote' ] ( proposalId , `1` ) ;
46
51
47
52
// 3. return borrowed tokens
@@ -52,22 +57,48 @@ export const createAndExecuteProposal = async ({
52
57
// simulate elapsed time close to original voting delay
53
58
await increaseNextBlockTime ( Math . floor ( POLYGON_AVERAGE_BLOCK_TIME * originalVotingPeriod . toNumber ( ) ) ) ;
54
59
await setNextBlockNumber ( voteEndBlock . toNumber ( ) + 1 ) ; // is a blocknumber which fits in Number
55
- tx = await governor
56
- . connect ( user )
57
- [ 'queue(address[],uint256[],bytes[],bytes32)' ] ( targets , values , calldatas , descriptionHash ) ;
60
+ console . log ( 'queueing proposal...' ) ;
61
+ tx = await governor . connect ( user ) [ 'queue(uint256)' ] ( proposalId ) ;
58
62
await tx . wait ( ) ;
59
63
60
64
// can revert Governor changes now
65
+ console . log ( 'resetting voting delay and period...' ) ;
61
66
await governor . connect ( timeLockSigner ) . setVotingDelay ( originalVotingDelay ) ;
62
67
await governor . connect ( timeLockSigner ) . setVotingPeriod ( originalVotingPeriod ) ;
63
68
await stopImpersonateAccount ( timeLock . address ) ;
64
69
65
70
// 5. advance time past timelock delay and then execute
66
71
const timeLockMinDelaySeconds = await timeLock . getMinDelay ( ) ;
67
72
await increaseNextBlockTime ( timeLockMinDelaySeconds . toNumber ( ) ) ;
68
- await governor
69
- . connect ( user )
70
- [ 'execute(address[],uint256[],bytes[],bytes32)' ] ( targets , values , calldatas , descriptionHash ) ;
73
+ console . log ( 'executing proposal...' ) ;
74
+ tx = await governor . connect ( user ) [ 'execute(uint256)' ] ( proposalId ) ;
75
+
76
+ let result = await tx . wait ( 1 ) ;
77
+
78
+ for ( let i = 0 ; i < targets . length ; i ++ ) {
79
+ let abi = await getABIFromPolygonscan ( targets [ i ] ) ;
80
+ let iface = new ethers . utils . Interface ( abi ) ;
81
+ let events = result . logs . map ( ( log ) => {
82
+ try {
83
+ return iface . parseLog ( log ) ;
84
+ } catch ( e ) {
85
+ // no matching event
86
+ }
87
+ } ) ;
88
+ console . log ( `### TARGET ${ targets [ i ] } EVENTS ###` ) ;
89
+ console . log ( events ) ;
90
+ console . log ( `###################################` ) ;
91
+ }
92
+
93
+ let timelockEvents = result . logs . map ( ( log ) => {
94
+ try {
95
+ return timeLock . interface . parseLog ( log ) ;
96
+ } catch ( e ) {
97
+ // no matching event
98
+ }
99
+ } ) ;
100
+ console . log ( `### TIMELOCK EVENTS ###` ) ;
101
+ console . log ( timelockEvents ) ;
71
102
72
103
return proposalId ;
73
104
} ;
0 commit comments