This repository was archived by the owner on Apr 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdeployFull.ts
More file actions
173 lines (136 loc) · 6.52 KB
/
deployFull.ts
File metadata and controls
173 lines (136 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import {expect} from 'chai';
import fs from 'fs';
import {
ArenaToken__factory,
ArenaToken,
RevokableTokenLock__factory,
RevokableTokenLock,
TimelockController__factory,
TimelockController,
ArenaGovernor__factory,
ArenaGovernor,
} from '../../typechain';
import {allConfigs} from './config';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
let deployerAddress: string;
let token: ArenaToken;
let revokableTokenLock: RevokableTokenLock;
let timelock: TimelockController;
let governor: ArenaGovernor;
// see OZ docs: https://docs.openzeppelin.com/contracts/4.x/api/governance#timelock-roles
const ADMIN_ROLE = '0x5f58e3a2316349923ce3780f8d587db2d72378aed66a8261c916544fa6846ca5';
const PROPOSER_ROLE = '0xb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1';
const EXECUTOR_ROLE = '0xd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63';
export async function deployFull(hre: HardhatRuntimeEnvironment) {
const networkId = hre.network.config.chainId as number;
const [deployer] = await hre.ethers.getSigners();
deployerAddress = await deployer.getAddress();
console.log(`Deployer: ${deployerAddress}`);
let config = allConfigs[networkId];
console.log(`deploying token...`);
const TokenFactory = (await hre.ethers.getContractFactory('ArenaToken')) as ArenaToken__factory;
token = await TokenFactory.deploy(
config.FREE_SUPPLY,
config.AIRDROP_SUPPLY,
config.CLAIMABLE_PROPORTION,
new Date(config.CLAIM_END_DATE).getTime() / 1000,
config.VEST_DURATION
);
await token.deployed();
console.log(`token address: ${token.address}`);
console.log(`deploying lock...`);
const RevokableTokenLockFactory = (await hre.ethers.getContractFactory(
'RevokableTokenLock'
)) as RevokableTokenLock__factory;
revokableTokenLock = await RevokableTokenLockFactory.deploy(token.address, deployerAddress);
await revokableTokenLock.deployed();
console.log(`revokableLock address: ${revokableTokenLock.address}`);
// set lock in token
await token.setTokenLock(revokableTokenLock.address);
await token.setMerkleRoot(config.MERKLE_ROOT);
console.log(`deploying timelock...`);
const TimelockControllerFactory = (await hre.ethers.getContractFactory(
'TimelockController'
)) as TimelockController__factory;
timelock = await TimelockControllerFactory.deploy(
config.TIMELOCK_DELAY, // minDelay of 1 day
[], // proposer and executor roles to be set after governor deployment
[]
);
await timelock.deployed();
console.log(`timelock address: ${timelock.address}`);
console.log(`deploying governor...`);
const ArenaGovernorFactory = (await hre.ethers.getContractFactory('ArenaGovernor')) as ArenaGovernor__factory;
governor = await ArenaGovernorFactory.deploy(token.address, timelock.address);
await governor.deployed();
console.log(`governor address: ${governor.address}`);
console.log(`transfer remaining tokens to timelock`);
await token.transfer(timelock.address, config.FREE_SUPPLY);
// give governor proposer role
// https://docs.openzeppelin.com/contracts/4.x/api/governance#timelock-proposer
await timelock.grantRole(PROPOSER_ROLE, governor.address);
// set executor role to null address so that ANY address can execute a queued proposal
// https://docs.openzeppelin.com/contracts/4.x/api/governance#timelock-executor
await timelock.grantRole(EXECUTOR_ROLE, hre.ethers.constants.AddressZero);
// https://docs.openzeppelin.com/contracts/4.x/api/governance#timelock-admin
// Timelock is self-governed, admin role has already been bestowed to itself
// Deployer renounce roles so that all further maintenance operations have to go through the timelock process
await timelock.renounceRole(ADMIN_ROLE, deployerAddress);
// set revoker role in TokenLock to timelock
await revokableTokenLock.setRevoker(timelock.address);
// transfer tokenlock admin role to timelock
await revokableTokenLock.transferOwnership(timelock.address);
// transfer token admin role to timelock
await token.transferOwnership(timelock.address);
console.log('exporting addresses...');
let addressesToExport = {
deployer: deployerAddress,
token: token.address,
tokenLock: revokableTokenLock.address,
timelock: timelock.address,
governor: governor.address,
};
let exportJson = JSON.stringify(addressesToExport, null, 2);
fs.writeFileSync(config.EXPORT_FILENAME, exportJson);
/////////////////////////////////
// ACCESS CONTROL VERIFICATION //
/////////////////////////////////
console.log('verifying access control settings...');
// deployer does not hold any role in timelock
expect(await timelock.hasRole(ADMIN_ROLE, deployerAddress)).to.be.false;
expect(await timelock.hasRole(PROPOSER_ROLE, deployerAddress)).to.be.false;
expect(await timelock.hasRole(EXECUTOR_ROLE, deployerAddress)).to.be.false;
// timelock is admin of itself
expect(await timelock.hasRole(ADMIN_ROLE, timelock.address)).to.be.true;
// governor is given proposer role
expect(await timelock.hasRole(PROPOSER_ROLE, governor.address)).to.be.true;
// null address is given executor role so that any address is allowed to execute proposal
// see onlyRoleOrOpenRole modifier of TimelockController
expect(await timelock.hasRole(EXECUTOR_ROLE, hre.ethers.constants.AddressZero)).to.be.true;
// TokenLock revoker should be timelock
expect(await revokableTokenLock.revoker()).to.be.eq(timelock.address);
// TokenLock owner should be timelock
expect(await revokableTokenLock.owner()).to.be.eq(timelock.address);
// Token's owner should be timelock
expect(await token.owner()).to.be.eq(timelock.address);
// check Token's tokenlock has been set
expect(await token.tokenLock()).to.be.eq(revokableTokenLock.address);
/////////////////////////
// CONFIG VERIFICATION //
/////////////////////////
console.log('verifying config settings...');
// check ArenaToken's token balance == AIRDROP_SUPPLY
expect(await token.balanceOf(token.address)).to.be.eq(config.AIRDROP_SUPPLY);
// check timelock's token balance == FREE_SUPPLY
expect(await token.balanceOf(timelock.address)).to.be.eq(config.FREE_SUPPLY);
// check timelock's minDelay
expect(await timelock.getMinDelay()).to.be.eq(config.TIMELOCK_DELAY);
// check merkle root is set
expect(await token.merkleRoot()).to.be.eq(config.MERKLE_ROOT);
// check claimable proportion
expect(await token.claimableProportion()).to.be.eq(config.CLAIMABLE_PROPORTION);
// check vest duration
expect(await token.vestDuration()).to.be.eq(config.VEST_DURATION);
console.log('verification complete!');
process.exit(0);
}