Skip to content

Commit 99d7c97

Browse files
authored
Merge pull request #786 from graphprotocol/pcv/l2-stake-migration
feat: stake and delegation transfer tools for L2
2 parents 3f0f113 + 8374f92 commit 99d7c97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4779
-1303
lines changed

.solcover.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ module.exports = {
77
},
88
skipFiles,
99
istanbulFolder: './reports/coverage',
10+
configureYulOptimizer: true,
1011
}

addresses.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"txHash": "0x218dbb4fd680db263524fc6be36462c18f3e267b87951cd86296eabd4a381183"
147147
}
148148
},
149-
"Staking": {
149+
"L1Staking": {
150150
"address": "0xF55041E37E12cD407ad00CE2910B8269B01263b9",
151151
"initArgs": [
152152
{
@@ -443,7 +443,7 @@
443443
"txHash": "0xbc6e9171943020d30c22197282311f003e79374e6eeeaab9c360942bdf4193f4"
444444
}
445445
},
446-
"Staking": {
446+
"L1Staking": {
447447
"address": "0x35e3Cb6B317690d662160d5d02A5b364578F62c9",
448448
"initArgs": [
449449
"0x48eD7AfbaB432d1Fc6Ea84EEC70E745d9DAcaF3B",
@@ -647,7 +647,7 @@
647647
"txHash": "0xb1e63211ea7b036bf35423034bc60490b3b35b199bddc85200ea926b76e16a4e"
648648
}
649649
},
650-
"Staking": {
650+
"L1Staking": {
651651
"address": "0x5f8e26fAcC23FA4cbd87b8d9Dbbd33D5047abDE1",
652652
"initArgs": [
653653
"0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B",
@@ -1099,7 +1099,7 @@
10991099
"txHash": "0x3bb004adf949e9c896e85f6e3124ecea0c223470e3a091e42539613d52679c4d"
11001100
}
11011101
},
1102-
"Staking": {
1102+
"L2Staking": {
11031103
"address": "0xcd549d0C43d915aEB21d3a331dEaB9B7aF186D26",
11041104
"initArgs": [
11051105
"0x7f734E995010Aa8d28b912703093d532C37b6EAb",

cli/commands/migrate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ let allContracts = [
3030
'SubgraphNFTDescriptor',
3131
'SubgraphNFT',
3232
'L1GNS',
33-
'Staking',
33+
'StakingExtension',
34+
'L1Staking',
3435
'RewardsManager',
3536
'DisputeManager',
3637
'AllocationExchange',
@@ -49,7 +50,8 @@ const l2Contracts = [
4950
'SubgraphNFTDescriptor',
5051
'SubgraphNFT',
5152
'L2GNS',
52-
'Staking',
53+
'StakingExtension',
54+
'L2Staking',
5355
'RewardsManager',
5456
'DisputeManager',
5557
'AllocationExchange',

cli/contracts.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { getContractAt } from './network'
1818

1919
import { EpochManager } from '../build/types/EpochManager'
2020
import { DisputeManager } from '../build/types/DisputeManager'
21-
import { Staking } from '../build/types/Staking'
21+
import { L1Staking } from '../build/types/L1Staking'
22+
import { L2Staking } from '../build/types/L2Staking'
2223
import { ServiceRegistry } from '../build/types/ServiceRegistry'
2324
import { Curation } from '../build/types/Curation'
2425
import { RewardsManager } from '../build/types/RewardsManager'
@@ -40,11 +41,15 @@ import { L2GraphToken } from '../build/types/L2GraphToken'
4041
import { L2GraphTokenGateway } from '../build/types/L2GraphTokenGateway'
4142
import { BridgeEscrow } from '../build/types/BridgeEscrow'
4243
import { L2Curation } from '../build/types/L2Curation'
44+
import { IL1Staking } from '../build/types/IL1Staking'
45+
import { IL2Staking } from '../build/types/IL2Staking'
46+
import { Interface } from 'ethers/lib/utils'
47+
import { loadArtifact } from './artifacts'
4348

4449
export interface NetworkContracts {
4550
EpochManager: EpochManager
4651
DisputeManager: DisputeManager
47-
Staking: Staking
52+
Staking: IL1Staking | IL2Staking
4853
ServiceRegistry: ServiceRegistry
4954
Curation: Curation | L2Curation
5055
L2Curation: L2Curation
@@ -66,6 +71,8 @@ export interface NetworkContracts {
6671
L2GraphTokenGateway: L2GraphTokenGateway
6772
L1GNS: L1GNS
6873
L2GNS: L2GNS
74+
L1Staking: IL1Staking
75+
L2Staking: IL2Staking
6976
}
7077

7178
export const loadAddressBookContract = (
@@ -97,6 +104,15 @@ export const loadContracts = (
97104
contract.connect = getWrappedConnect(contract, contractName)
98105
contract = wrapCalls(contract, contractName)
99106
}
107+
if (contractName == 'L1Staking') {
108+
// Hack the contract into behaving like an IL1Staking
109+
const iface = new Interface(loadArtifact('IL1Staking').abi)
110+
contract = new Contract(contract.address, iface) as unknown as IL1Staking
111+
} else if (contractName == 'L2Staking') {
112+
// Hack the contract into behaving like an IL2Staking
113+
const iface = new Interface(loadArtifact('IL2Staking').abi)
114+
contract = new Contract(contract.address, iface) as unknown as IL2Staking
115+
}
100116
contracts[contractName] = contract
101117

102118
if (signerOrProvider) {
@@ -110,12 +126,18 @@ export const loadContracts = (
110126
if (signerOrProvider && chainIdIsL2(chainId) && contractName == 'L2GNS') {
111127
contracts['GNS'] = contracts[contractName]
112128
}
129+
if (signerOrProvider && chainIdIsL2(chainId) && contractName == 'L2Staking') {
130+
contracts['Staking'] = contracts[contractName]
131+
}
113132
if (signerOrProvider && chainIdIsL2(chainId) && contractName == 'L2Curation') {
114133
contracts['Curation'] = contracts[contractName]
115134
}
116135
if (signerOrProvider && !chainIdIsL2(chainId) && contractName == 'L1GNS') {
117136
contracts['GNS'] = contracts[contractName]
118137
}
138+
if (signerOrProvider && !chainIdIsL2(chainId) && contractName == 'L1Staking') {
139+
contracts['Staking'] = contracts[contractName]
140+
}
119141
} catch (err) {
120142
logger.warn(`Could not load contract ${contractName} - ${err.message}`)
121143
}

cli/network.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import { AddressBook } from './address-book'
1818
import { loadArtifact } from './artifacts'
1919
import { defaultOverrides } from './defaults'
2020
import { GraphToken } from '../build/types/GraphToken'
21+
import { Interface } from 'ethers/lib/utils'
22+
import { IL1Staking } from '../build/types/IL1Staking'
23+
import { IL2Staking } from '../build/types/IL2Staking'
2124

2225
const { keccak256, randomBytes, parseUnits, hexlify } = utils
2326

@@ -197,7 +200,7 @@ export const deployContract = async (
197200

198201
// Deploy
199202
const factory = getContractFactory(name, libraries)
200-
const contract = await factory.connect(sender).deploy(...args)
203+
let contract = await factory.connect(sender).deploy(...args)
201204
const txHash = contract.deployTransaction.hash
202205
logger.info(`> Deploy ${name}, txHash: ${txHash}`)
203206
await sender.provider.waitForTransaction(txHash)
@@ -209,6 +212,15 @@ export const deployContract = async (
209212
logger.info(`= RuntimeCodeHash: ${runtimeCodeHash}`)
210213
logger.info(`${name} has been deployed to address: ${contract.address}`)
211214

215+
if (name == 'L1Staking') {
216+
// Hack the contract into behaving like an IL1Staking
217+
const iface = new Interface(loadArtifact('IL1Staking').abi)
218+
contract = new Contract(contract.address, iface, sender) as unknown as IL1Staking
219+
} else if (name == 'L2Staking') {
220+
// Hack the contract into behaving like an IL2Staking
221+
const iface = new Interface(loadArtifact('IL2Staking').abi)
222+
contract = new Contract(contract.address, iface, sender) as unknown as IL2Staking
223+
}
212224
return { contract, creationCodeHash, runtimeCodeHash, txHash, libraries }
213225
}
214226

config/graph.arbitrum-goerli.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contracts:
2626
contractAddress: "${{RewardsManager.address}}"
2727
- fn: "setContractProxy"
2828
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
29-
contractAddress: "${{Staking.address}}"
29+
contractAddress: "${{L2Staking.address}}"
3030
- fn: "setContractProxy"
3131
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
3232
contractAddress: "${{L2GraphToken.address}}"
@@ -100,7 +100,7 @@ contracts:
100100
minter: "${{L2GNS.address}}"
101101
- fn: "transferOwnership"
102102
owner: *governor
103-
Staking:
103+
L2Staking:
104104
proxy: true
105105
init:
106106
controller: "${{Controller.address}}"
@@ -114,6 +114,7 @@ contracts:
114114
delegationRatio: 16 # delegated stake to indexer stake multiplier
115115
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
116116
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
117+
extensionImpl: "${{StakingExtension.address}}"
117118
calls:
118119
- fn: "setDelegationTaxPercentage"
119120
delegationTaxPercentage: 5000 # parts per million
@@ -137,7 +138,7 @@ contracts:
137138
AllocationExchange:
138139
init:
139140
graphToken: "${{L2GraphToken.address}}"
140-
staking: "${{Staking.address}}"
141+
staking: "${{L2Staking.address}}"
141142
governor: *allocationExchangeOwner
142143
authority: *authority
143144
calls:

config/graph.arbitrum-localhost.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contracts:
2626
contractAddress: "${{RewardsManager.address}}"
2727
- fn: "setContractProxy"
2828
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
29-
contractAddress: "${{Staking.address}}"
29+
contractAddress: "${{L2Staking.address}}"
3030
- fn: "setContractProxy"
3131
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
3232
contractAddress: "${{L2GraphToken.address}}"
@@ -100,7 +100,7 @@ contracts:
100100
minter: "${{L2GNS.address}}"
101101
- fn: "transferOwnership"
102102
owner: *governor
103-
Staking:
103+
L2Staking:
104104
proxy: true
105105
init:
106106
controller: "${{Controller.address}}"
@@ -114,6 +114,7 @@ contracts:
114114
delegationRatio: 16 # delegated stake to indexer stake multiplier
115115
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
116116
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
117+
extensionImpl: "${{StakingExtension.address}}"
117118
calls:
118119
- fn: "setDelegationTaxPercentage"
119120
delegationTaxPercentage: 5000 # parts per million
@@ -137,7 +138,7 @@ contracts:
137138
AllocationExchange:
138139
init:
139140
graphToken: "${{L2GraphToken.address}}"
140-
staking: "${{Staking.address}}"
141+
staking: "${{L2Staking.address}}"
141142
governor: *allocationExchangeOwner
142143
authority: *authority
143144
calls:

config/graph.arbitrum-one.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contracts:
2626
contractAddress: "${{RewardsManager.address}}"
2727
- fn: "setContractProxy"
2828
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
29-
contractAddress: "${{Staking.address}}"
29+
contractAddress: "${{L2Staking.address}}"
3030
- fn: "setContractProxy"
3131
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
3232
contractAddress: "${{L2GraphToken.address}}"
@@ -100,7 +100,7 @@ contracts:
100100
minter: "${{L2GNS.address}}"
101101
- fn: "transferOwnership"
102102
owner: *governor
103-
Staking:
103+
L2Staking:
104104
proxy: true
105105
init:
106106
controller: "${{Controller.address}}"
@@ -114,6 +114,7 @@ contracts:
114114
delegationRatio: 16 # delegated stake to indexer stake multiplier
115115
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
116116
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
117+
extensionImpl: "${{StakingExtension.address}}"
117118
calls:
118119
- fn: "setDelegationTaxPercentage"
119120
delegationTaxPercentage: 5000 # parts per million
@@ -137,7 +138,7 @@ contracts:
137138
AllocationExchange:
138139
init:
139140
graphToken: "${{L2GraphToken.address}}"
140-
staking: "${{Staking.address}}"
141+
staking: "${{L2Staking.address}}"
141142
governor: *allocationExchangeOwner
142143
authority: *authority
143144
calls:

config/graph.goerli.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contracts:
2626
contractAddress: "${{RewardsManager.address}}"
2727
- fn: "setContractProxy"
2828
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
29-
contractAddress: "${{Staking.address}}"
29+
contractAddress: "${{L1Staking.address}}"
3030
- fn: "setContractProxy"
3131
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
3232
contractAddress: "${{GraphToken.address}}"
@@ -103,7 +103,7 @@ contracts:
103103
minter: "${{L1GNS.address}}"
104104
- fn: "transferOwnership"
105105
owner: *governor
106-
Staking:
106+
L1Staking:
107107
proxy: true
108108
init:
109109
controller: "${{Controller.address}}"
@@ -117,6 +117,7 @@ contracts:
117117
delegationRatio: 16 # delegated stake to indexer stake multiplier
118118
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
119119
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
120+
extensionImpl: "${{StakingExtension.address}}"
120121
calls:
121122
- fn: "setDelegationTaxPercentage"
122123
delegationTaxPercentage: 5000 # parts per million
@@ -140,7 +141,7 @@ contracts:
140141
AllocationExchange:
141142
init:
142143
graphToken: "${{GraphToken.address}}"
143-
staking: "${{Staking.address}}"
144+
staking: "${{L1Staking.address}}"
144145
governor: *allocationExchangeOwner
145146
authority: *authority
146147
calls:

config/graph.localhost.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contracts:
2626
contractAddress: "${{RewardsManager.address}}"
2727
- fn: "setContractProxy"
2828
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
29-
contractAddress: "${{Staking.address}}"
29+
contractAddress: "${{L1Staking.address}}"
3030
- fn: "setContractProxy"
3131
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
3232
contractAddress: "${{GraphToken.address}}"
@@ -103,7 +103,7 @@ contracts:
103103
minter: "${{L1GNS.address}}"
104104
- fn: "transferOwnership"
105105
owner: *governor
106-
Staking:
106+
L1Staking:
107107
proxy: true
108108
init:
109109
controller: "${{Controller.address}}"
@@ -117,6 +117,7 @@ contracts:
117117
delegationRatio: 16 # delegated stake to indexer stake multiplier
118118
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
119119
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
120+
extensionImpl: "${{StakingExtension.address}}"
120121
calls:
121122
- fn: "setDelegationTaxPercentage"
122123
delegationTaxPercentage: 5000 # parts per million
@@ -140,7 +141,7 @@ contracts:
140141
AllocationExchange:
141142
init:
142143
graphToken: "${{GraphToken.address}}"
143-
staking: "${{Staking.address}}"
144+
staking: "${{L1Staking.address}}"
144145
governor: *allocationExchangeOwner
145146
authority: *authority
146147
calls:

0 commit comments

Comments
 (0)