Skip to content

Commit fbdb3f1

Browse files
committed
feat: create migration scripts for subgraph service
Signed-off-by: Tomás Migone <[email protected]>
1 parent 8c29d86 commit fbdb3f1

File tree

19 files changed

+261
-152
lines changed

19 files changed

+261
-152
lines changed

packages/hardhat-graph-protocol/src/sdk/hardhat.base.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ export const hardhatBaseConfig: HardhatUserConfig & { etherscan: Partial<Ethersc
9696
networks: networksUserConfig,
9797
graph: {
9898
deployments: {
99-
horizon: {
100-
addressBook: 'addresses.json',
101-
},
99+
horizon: require.resolve('@graphprotocol/horizon/addresses.json'),
100+
subgraphService: require.resolve('@graphprotocol/subgraph-service/addresses.json'),
102101
},
103102
},
104103
etherscan: etherscanUserConfig,

packages/hardhat-graph-protocol/src/sdk/ignition/ignition.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-prototype-builtins */
2+
/* eslint-disable @typescript-eslint/no-unsafe-return */
13
/* eslint-disable @typescript-eslint/no-explicit-any */
24
require('json5/lib/register')
35

@@ -20,6 +22,39 @@ export function loadConfig(configPath: string, prefix: string, networkName: stri
2022
return removeNFromBigInts(require(configFile))
2123
}
2224

25+
export function patchConfig(jsonData: any, patches: Record<string, any>) {
26+
function recursivePatch(obj: any) {
27+
if (typeof obj === 'object' && obj !== null) {
28+
for (const key in obj) {
29+
if (key in patches) {
30+
obj[key] = patches[key]
31+
} else {
32+
recursivePatch(obj[key])
33+
}
34+
}
35+
}
36+
}
37+
38+
recursivePatch(jsonData)
39+
return jsonData
40+
}
41+
42+
export function mergeConfigs(obj1: any, obj2: any) {
43+
const merged = { ...obj1 }
44+
45+
for (const key in obj2) {
46+
if (obj2.hasOwnProperty(key)) {
47+
if (typeof obj2[key] === 'object' && obj2[key] !== null && obj1[key]) {
48+
merged[key] = mergeConfigs(obj1[key], obj2[key])
49+
} else {
50+
merged[key] = obj2[key]
51+
}
52+
}
53+
}
54+
55+
return merged
56+
}
57+
2358
export function saveAddressBook(
2459
contracts: any,
2560
chainId: number | undefined,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { loadConfig, saveAddressBook } from './ignition/ignition'
1+
import { loadConfig, mergeConfigs, patchConfig, saveAddressBook } from './ignition/ignition'
22
import { hardhatBaseConfig } from './hardhat.base.config'
33

4-
const IgnitionHelper = { saveAddressBook, loadConfig }
4+
const IgnitionHelper = { saveAddressBook, loadConfig, patchConfig, mergeConfigs }
55
export { hardhatBaseConfig, IgnitionHelper }

packages/horizon/addresses.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

packages/horizon/ignition/modules/core/GraphPayments.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'
22
import { deployImplementation } from '../proxy/implementation'
3-
import { upgradeTransparentUpgradeableProxyNoLoad } from '../proxy/TransparentUpgradeableProxy'
3+
import { upgradeTransparentUpgradeableProxy } from '../proxy/TransparentUpgradeableProxy'
44

55
import GraphPeripheryModule, { MigratePeripheryModule } from '../periphery/periphery'
66
import HorizonProxiesModule, { MigrateHorizonProxiesDeployerModule } from './HorizonProxies'
@@ -22,7 +22,7 @@ export default buildModule('GraphPayments', (m) => {
2222
}, { after: [GraphPeripheryModule, HorizonProxiesModule] })
2323

2424
// Upgrade proxy to implementation contract
25-
const GraphPayments = upgradeTransparentUpgradeableProxyNoLoad(m,
25+
const GraphPayments = upgradeTransparentUpgradeableProxy(m,
2626
GraphPaymentsProxyAdmin,
2727
GraphPaymentsProxy,
2828
GraphPaymentsImplementation, {
@@ -55,7 +55,7 @@ export const MigrateGraphPaymentsModule = buildModule('GraphPayments', (m) => {
5555
})
5656

5757
// Upgrade proxy to implementation contract
58-
const GraphPayments = upgradeTransparentUpgradeableProxyNoLoad(m,
58+
const GraphPayments = upgradeTransparentUpgradeableProxy(m,
5959
GraphPaymentsProxyAdmin,
6060
GraphPaymentsProxy,
6161
GraphPaymentsImplementation, {

packages/horizon/ignition/modules/core/PaymentsEscrow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { buildModule } from '@nomicfoundation/hardhat-ignition/modules'
22
import { deployImplementation } from '../proxy/implementation'
3-
import { upgradeTransparentUpgradeableProxyNoLoad } from '../proxy/TransparentUpgradeableProxy'
3+
import { upgradeTransparentUpgradeableProxy } from '../proxy/TransparentUpgradeableProxy'
44

55
import GraphPeripheryModule, { MigratePeripheryModule } from '../periphery/periphery'
66
import HorizonProxiesModule, { MigrateHorizonProxiesDeployerModule } from './HorizonProxies'
@@ -22,7 +22,7 @@ export default buildModule('PaymentsEscrow', (m) => {
2222
}, { after: [GraphPeripheryModule, HorizonProxiesModule] })
2323

2424
// Upgrade proxy to implementation contract
25-
const PaymentsEscrow = upgradeTransparentUpgradeableProxyNoLoad(m,
25+
const PaymentsEscrow = upgradeTransparentUpgradeableProxy(m,
2626
PaymentsEscrowProxyAdmin,
2727
PaymentsEscrowProxy,
2828
PaymentsEscrowImplementation, {
@@ -55,7 +55,7 @@ export const MigratePaymentsEscrowModule = buildModule('PaymentsEscrow', (m) =>
5555
})
5656

5757
// Upgrade proxy to implementation contract
58-
const PaymentsEscrow = upgradeTransparentUpgradeableProxyNoLoad(m,
58+
const PaymentsEscrow = upgradeTransparentUpgradeableProxy(m,
5959
PaymentsEscrowProxyAdmin,
6060
PaymentsEscrowProxy,
6161
PaymentsEscrowImplementation, {

packages/horizon/ignition/modules/migrate/migrate-2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import { MigrateHorizonProxiesGovernorModule } from '../core/HorizonProxies'
55
export default buildModule('GraphHorizon_Migrate_2', (m) => {
66
m.useModule(MigrateHorizonProxiesGovernorModule)
77

8-
return { }
8+
return {}
99
})

packages/horizon/ignition/modules/proxy/TransparentUpgradeableProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function deployTransparentUpgradeableProxy(
4545
}
4646
}
4747

48-
export function upgradeTransparentUpgradeableProxyNoLoad(
48+
export function upgradeTransparentUpgradeableProxy(
4949
m: IgnitionModuleBuilder,
5050
proxyAdmin: CallableContractFuture<string>,
5151
proxy: CallableContractFuture<string>,
Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,16 @@
1+
import { hardhatBaseConfig } from 'hardhat-graph-protocol/sdk'
2+
3+
// Hardhat plugins
14
import '@nomicfoundation/hardhat-foundry'
2-
import '@nomicfoundation/hardhat-ignition-ethers'
35
import '@nomicfoundation/hardhat-toolbox'
4-
import 'hardhat-contract-sizer'
6+
import '@nomicfoundation/hardhat-ignition-ethers'
57
import 'hardhat-storage-layout'
8+
import 'hardhat-contract-sizer'
69
import 'hardhat-secure-accounts'
710
import 'solidity-docgen'
811

9-
import { HardhatUserConfig } from 'hardhat/config'
10-
1112
if (process.env.BUILD_RUN !== 'true') {
1213
require('hardhat-graph-protocol')
1314
}
1415

15-
const config: HardhatUserConfig = {
16-
solidity: {
17-
version: '0.8.27',
18-
settings: {
19-
optimizer: {
20-
enabled: true,
21-
runs: 1,
22-
},
23-
},
24-
},
25-
paths: {
26-
artifacts: './build/contracts',
27-
sources: './contracts',
28-
},
29-
secureAccounts: {
30-
enabled: true,
31-
},
32-
networks: {
33-
hardhat: {
34-
secureAccounts: {
35-
enabled: false,
36-
},
37-
accounts: {
38-
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect',
39-
},
40-
},
41-
arbitrumSepolia: {
42-
chainId: 421614,
43-
url: 'https://sepolia-rollup.arbitrum.io/rpc',
44-
},
45-
},
46-
graph: {
47-
deployments: {
48-
horizon: require.resolve('@graphprotocol/horizon/addresses.json'),
49-
subgraphService: 'addresses.json',
50-
},
51-
},
52-
}
53-
54-
export default config
16+
export default hardhatBaseConfig
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$global": {
3+
// Accounts
4+
"governor": "0x72ee30d43Fb5A90B3FE983156C5d2fBE6F6d07B3",
5+
"arbitrator": "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0",
6+
7+
// Addresses for contracts deployed in the original Graph Protocol
8+
"controllerAddress": "0x9DB3ee191681f092607035d9BDA6e59FbEaCa695",
9+
"curationAddress": "0xDe761f075200E75485F4358978FB4d1dC8644FD5",
10+
"tapCollectorAddress": "0x0000000000000000000000000000000000000000",
11+
12+
// Must be set for step 2 of the migration
13+
"disputeManagerAddress": "0x0000000000000000000000000000000000000000",
14+
"disputeManagerProxyAdminAddress": "0x0000000000000000000000000000000000000000",
15+
"subgraphServiceAddress": "0x0000000000000000000000000000000000000000",
16+
"subgraphServiceProxyAdminAddress": "0x0000000000000000000000000000000000000000"
17+
},
18+
"DisputeManager": {
19+
"disputePeriod": 2419200,
20+
"disputeDeposit": "10000000000000000000000n",
21+
"fishermanRewardCut": 500000,
22+
"maxSlashingCut": 1000000
23+
},
24+
"SubgraphService": {
25+
"minimumProvisionTokens": "100000000000000000000000n",
26+
"maximumDelegationRatio": 16,
27+
"stakeToFeesRatio": 2
28+
}
29+
}

0 commit comments

Comments
 (0)