-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnexus.ts
104 lines (87 loc) · 4.81 KB
/
nexus.ts
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
import { keccak256, toUtf8Bytes } from "ethers/lib/utils"
import { subtask, task, types } from "hardhat/config"
import { Nexus__factory } from "types/generated"
import { MTA } from "./utils"
import { deployContract, logTxDetails } from "./utils/deploy-utils"
import { verifyEtherscan } from "./utils/etherscan"
import { logger } from "./utils/logger"
import { getChain, resolveAddress } from "./utils/networkAddressFactory"
import { getSigner } from "./utils/signerFactory"
import type { Signer } from "ethers"
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import type { Nexus } from "types/generated"
const log = logger("task:nexus")
export async function deployNexus(hre: HardhatRuntimeEnvironment, signer: Signer, governorAddress: string) {
const constructorArguments = [governorAddress]
const nexus = await deployContract<Nexus>(new Nexus__factory(signer), "Nexus", constructorArguments)
// initialize is only callable by the governor so this only works on testnets where the governor is an eternally owned account
// Mainnet will need a ProtocolDAO transaction
const metaTokenKey = keccak256(toUtf8Bytes("MetaToken"))
const tx = await nexus.connect(signer).initialize([metaTokenKey], [MTA.address], [true], governorAddress)
await logTxDetails(tx, "Nexus.initialize")
await verifyEtherscan(hre, {
address: nexus.address,
contract: "contracts/nexus/Nexus.sol:Nexus",
constructorArguments,
})
return nexus
}
subtask("nexus-deploy", "Deploys a new Nexus contract")
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.addOptionalParam("governor", "Governor address override", "Governor", types.string)
.setAction(async (taskArgs, hre) => {
const chain = getChain(hre)
const signer = await getSigner(hre, taskArgs.speed)
const governorAddress = resolveAddress(taskArgs.governor, chain)
return deployNexus(hre, signer, governorAddress)
})
task("nexus-deploy").setAction(async (_, __, runSuper) => {
return runSuper()
})
task("nexus-module", "Resolve address of a Nexus module")
.addParam("module", "Name of module. eg LiquidatorV2", undefined, types.string)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const chain = getChain(hre)
const signer = await getSigner(hre, taskArgs.speed)
const nexusAddress = resolveAddress("Nexus", chain)
const nexus = Nexus__factory.connect(nexusAddress, signer)
const key = keccak256(toUtf8Bytes(taskArgs.module))
log(`Key for module ${taskArgs.module}: ${key}`)
const moduleAddress = await nexus.getModule(key)
log(`Address of module ${taskArgs.module}: ${moduleAddress}`)
})
subtask("nexus-prop-mod", "Propose a new Nexus module")
.addParam("module", "Name of module. eg LiquidatorV2", undefined, types.string)
.addParam("address", "Name or address of the account or account the module should resolve to. eg LiquidatorV2", undefined, types.string)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const chain = getChain(hre)
const signer = await getSigner(hre, taskArgs.speed, false)
const nexusAddress = resolveAddress("Nexus", chain)
const nexus = Nexus__factory.connect(nexusAddress, signer)
const key = keccak256(toUtf8Bytes(taskArgs.module))
log(`Key for module ${taskArgs.module}: ${key}`)
const moduleAddress = resolveAddress(taskArgs.address, chain)
const tx = await nexus.proposeModule(key, moduleAddress)
logTxDetails(tx, `propose module ${taskArgs.module} with address ${moduleAddress}`)
})
task("nexus-prop-mod").setAction(async (_, __, runSuper) => {
return runSuper()
})
subtask("nexus-acc-mod", "Accept a new Nexus module after 1 week")
.addParam("module", "Name of module. eg LiquidatorV2", undefined, types.string)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const chain = getChain(hre)
const signer = await getSigner(hre, taskArgs.speed, false)
const nexusAddress = resolveAddress("Nexus", chain)
const nexus = Nexus__factory.connect(nexusAddress, signer)
const key = keccak256(toUtf8Bytes(taskArgs.module))
log(`Key for module ${taskArgs.module}: ${key}`)
const tx = await nexus.acceptProposedModule(key)
logTxDetails(tx, `accept module ${taskArgs.module}`)
})
task("nexus-acc-mod").setAction(async (_, __, runSuper) => {
return runSuper()
})