-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathdeploy.ts
208 lines (183 loc) · 11.7 KB
/
deploy.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* eslint-disable no-case-declarations */
import { task, types } from 'hardhat/config'
import { IgnitionHelper } from 'hardhat-graph-protocol/sdk'
import type { AddressBook } from '../../hardhat-graph-protocol/src/sdk/address-book'
import type { HardhatRuntimeEnvironment } from 'hardhat/types'
import Deploy1Module from '../ignition/modules/deploy/deploy-1'
import Deploy2Module from '../ignition/modules/deploy/deploy-2'
import HorizonModule from '@graphprotocol/horizon/ignition/modules/deploy'
// Horizon needs the SubgraphService proxy address before it can be deployed
// But SubgraphService and DisputeManager implementations need Horizon...
// So the deployment order is:
// - Deploy SubgraphService and DisputeManager proxies
// - Deploy Horizon
// - Deploy SubgraphService and DisputeManager implementations
task('deploy:protocol', 'Deploy a new version of the Graph Protocol Horizon contracts - with Subgraph Service')
.addOptionalParam('subgraphServiceConfig', 'Name of the Subgraph Service configuration file to use. Format is "protocol.<name>.json5", file must be in the "ignition/configs/" directory. Defaults to network name.', undefined, types.string)
.addOptionalParam('horizonConfig', 'Name of the Horizon configuration file to use. Format is "protocol.<name>.json5", file must be in the "ignition/configs/" directory in the horizon package. Defaults to network name.', undefined, types.string)
.setAction(async (args, hre: HardhatRuntimeEnvironment) => {
const graph = hre.graph()
// Load configuration files for the deployment
console.log('\n========== ⚙️ Deployment configuration ==========')
const { config: HorizonConfig, file: horizonFile } = IgnitionHelper.loadConfig('./node_modules/@graphprotocol/horizon/ignition/configs', 'protocol', args.horizonConfig ?? hre.network.name)
const { config: SubgraphServiceConfig, file: subgraphServiceFile } = IgnitionHelper.loadConfig('./ignition/configs/', 'protocol', args.subgraphServiceConfig ?? hre.network.name)
console.log(`Loaded Horizon migration configuration from ${horizonFile}`)
console.log(`Loaded Subgraph Service migration configuration from ${subgraphServiceFile}`)
// Display the deployer -- this also triggers the secure accounts prompt if being used
console.log('\n========== 🔑 Deployer account ==========')
const signers = await hre.ethers.getSigners()
const deployer = signers[0]
console.log('Using deployer account:', deployer.address)
const balance = await hre.ethers.provider.getBalance(deployer.address)
console.log('Deployer balance:', hre.ethers.formatEther(balance), 'ETH')
if (balance === 0n) {
console.error('Error: Deployer account has no ETH balance')
process.exit(1)
}
// 1. Deploy SubgraphService and DisputeManager proxies
console.log(`\n========== 🚧 SubgraphService and DisputeManager proxies ==========`)
const proxiesDeployment = await hre.ignition.deploy(Deploy1Module, {
displayUi: true,
parameters: SubgraphServiceConfig,
})
// 2. Deploy Horizon
console.log(`\n========== 🚧 Deploy Horizon ==========`)
const horizonDeployment = await hre.ignition.deploy(HorizonModule, {
displayUi: true,
parameters: IgnitionHelper.patchConfig(HorizonConfig, {
$global: {
subgraphServiceProxyAddress: proxiesDeployment.Transparent_Proxy_SubgraphService.target as string,
},
}),
})
// 3. Deploy SubgraphService and DisputeManager implementations
console.log(`\n========== 🚧 Deploy SubgraphService implementations and upgrade them ==========`)
const subgraphServiceDeployment = await hre.ignition.deploy(Deploy2Module, {
displayUi: true,
parameters: IgnitionHelper.patchConfig(SubgraphServiceConfig, {
$global: {
controllerAddress: horizonDeployment.Controller.target as string,
disputeManagerProxyAddress: proxiesDeployment.Transparent_Proxy_DisputeManager.target as string,
curationAddress: horizonDeployment.Graph_Proxy_L2Curation.target as string,
curationImplementationAddress: horizonDeployment.Implementation_L2Curation.target as string,
subgraphServiceProxyAddress: proxiesDeployment.Transparent_Proxy_SubgraphService.target as string,
},
DisputeManager: {
disputeManagerProxyAdminAddress: proxiesDeployment.Transparent_ProxyAdmin_DisputeManager.target as string,
},
SubgraphService: {
subgraphServiceProxyAdminAddress: proxiesDeployment.Transparent_ProxyAdmin_SubgraphService.target as string,
graphTallyCollectorAddress: horizonDeployment.GraphTallyCollector.target as string,
},
}),
})
// Save the addresses to the address book
console.log('\n========== 📖 Updating address book ==========')
IgnitionHelper.saveToAddressBook(horizonDeployment, hre.network.config.chainId, graph.horizon!.addressBook)
IgnitionHelper.saveToAddressBook(proxiesDeployment, hre.network.config.chainId, graph.subgraphService!.addressBook)
IgnitionHelper.saveToAddressBook(subgraphServiceDeployment, hre.network.config.chainId, graph.subgraphService!.addressBook)
console.log(`Address book at ${graph.horizon!.addressBook.file} updated!`)
console.log(`Address book at ${graph.subgraphService!.addressBook.file} updated!`)
console.log('Note that Horizon deployment addresses are updated in the Horizon address book')
console.log('\n\n🎉 ✨ 🚀 ✅ Deployment complete! 🎉 ✨ 🚀 ✅')
})
task('deploy:migrate', 'Deploy the Subgraph Service on an existing Horizon deployment')
.addOptionalParam('step', 'Migration step to run (1, 2)', undefined, types.int)
.addOptionalParam('subgraphServiceConfig', 'Name of the Subgraph Service configuration file to use. Format is "migrate.<name>.json5", file must be in the "ignition/configs/" directory. Defaults to network name.', undefined, types.string)
.addFlag('patchConfig', 'Patch configuration file using address book values - does not save changes')
.setAction(async (args, hre: HardhatRuntimeEnvironment) => {
// Task parameters
const step: number = args.step ?? 0
const patchConfig: boolean = args.patchConfig ?? false
const graph = hre.graph()
console.log(getHorizonBanner())
// Migration step to run
console.log('\n========== 🏗️ Migration steps ==========')
const validSteps = [1, 2]
if (!validSteps.includes(step)) {
console.error(`Error: Invalid migration step provided: ${step}`)
console.error(`Valid steps are: ${validSteps.join(', ')}`)
process.exit(1)
}
console.log(`Running migration step: ${step}`)
// Load configuration for the migration
console.log('\n========== ⚙️ Deployment configuration ==========')
const { config: SubgraphServiceMigrateConfig, file } = IgnitionHelper.loadConfig('./ignition/configs/', 'migrate', args.subgraphServiceConfig ?? hre.network.name)
console.log(`Loaded migration configuration from ${file}`)
// Display the deployer -- this also triggers the secure accounts prompt if being used
console.log('\n========== 🔑 Deployer account ==========')
const signers = await hre.ethers.getSigners()
const deployer = signers[0]
console.log('Using deployer account:', deployer.address)
const balance = await hre.ethers.provider.getBalance(deployer.address)
console.log('Deployer balance:', hre.ethers.formatEther(balance), 'ETH')
if (balance === 0n) {
console.error('Error: Deployer account has no ETH balance')
process.exit(1)
}
// Run migration step
console.log(`\n========== 🚧 Running migration: step ${step} ==========`)
const MigrationModule = require(`../ignition/modules/migrate/migrate-${step}`).default
const deployment = await hre.ignition.deploy(
MigrationModule,
{
displayUi: true,
parameters: patchConfig ? _patchStepConfig(step, SubgraphServiceMigrateConfig, graph.subgraphService!.addressBook, graph.horizon!.addressBook) : SubgraphServiceMigrateConfig,
deploymentId: `subgraph-service-${hre.network.name}`,
})
// Update address book
console.log('\n========== 📖 Updating address book ==========')
IgnitionHelper.saveToAddressBook(deployment, hre.network.config.chainId, graph.subgraphService!.addressBook)
console.log(`Address book at ${graph.subgraphService!.addressBook.file} updated!`)
console.log('\n\n🎉 ✨ 🚀 ✅ Migration complete! 🎉 ✨ 🚀 ✅')
})
// This function patches the Ignition configuration object using an address book to fill in the gaps
// The resulting configuration is not saved back to the configuration file
function _patchStepConfig<ChainId extends number, ContractName extends string, HorizonContractName extends string>(
step: number,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
config: any,
addressBook: AddressBook<ChainId, ContractName>,
horizonAddressBook: AddressBook<ChainId, HorizonContractName>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any {
let patchedConfig = config
switch (step) {
case 2:
const SubgraphService = addressBook.getEntry('SubgraphService')
const DisputeManager = addressBook.getEntry('DisputeManager')
const GraphTallyCollector = horizonAddressBook.getEntry('GraphTallyCollector')
patchedConfig = IgnitionHelper.patchConfig(config, {
$global: {
subgraphServiceProxyAddress: SubgraphService.address,
},
SubgraphService: {
subgraphServiceProxyAdminAddress: SubgraphService.proxyAdmin,
graphTallyCollectorAddress: GraphTallyCollector.address,
disputeManagerProxyAddress: DisputeManager.address,
},
DisputeManager: {
disputeManagerProxyAddress: DisputeManager.address,
disputeManagerProxyAdminAddress: DisputeManager.proxyAdmin,
},
})
break
}
return patchedConfig
}
function getHorizonBanner(): string {
return `
██╗ ██╗ ██████╗ ██████╗ ██╗███████╗ ██████╗ ███╗ ██╗
██║ ██║██╔═══██╗██╔══██╗██║╚══███╔╝██╔═══██╗████╗ ██║
███████║██║ ██║██████╔╝██║ ███╔╝ ██║ ██║██╔██╗ ██║
██╔══██║██║ ██║██╔══██╗██║ ███╔╝ ██║ ██║██║╚██╗██║
██║ ██║╚██████╔╝██║ ██║██║███████╗╚██████╔╝██║ ╚████║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═══╝
██╗ ██╗██████╗ ██████╗ ██████╗ █████╗ ██████╗ ███████╗
██║ ██║██╔══██╗██╔════╝ ██╔══██╗██╔══██╗██╔══██╗██╔════╝
██║ ██║██████╔╝██║ ███╗██████╔╝███████║██║ ██║█████╗
██║ ██║██╔═══╝ ██║ ██║██╔══██╗██╔══██║██║ ██║██╔══╝
╚██████╔╝██║ ╚██████╔╝██║ ██║██║ ██║██████╔╝███████╗
╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝
`
}