Skip to content

feat: stake and delegation transfer tools for L2 #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
83fffa3
feat: stake and delegation migration helpers for L2
pcarranzav Jan 20, 2023
00f5c94
fix: correct proxy check in Staking fallback
pcarranzav Mar 15, 2023
ff8ce4d
fix(L1Staking): require exact msg.value for migration (OZ M-01)
pcarranzav Apr 13, 2023
ab4c92e
fix: make sure delegation params are initialized when migrated stake …
pcarranzav Apr 13, 2023
1df3808
test: check delegation param values in L2Staking
pcarranzav Apr 13, 2023
c076852
fix: make staking migrators revert if protocol is partially paused (O…
tmigone Apr 14, 2023
ced9d17
fix: enforce minimum stake when restaking (OZ M-08)
pcarranzav Apr 14, 2023
520ff1d
fix: do not enforce minimum stake when receiving from L1
pcarranzav Apr 14, 2023
45b28d8
Merge branch 'dev' into pcv/786-m09-zero-shares
pcarranzav Apr 14, 2023
79fbd32
fix: return migrated delegation to the delegator if it would mint zer…
pcarranzav Apr 14, 2023
9fa7d69
test: fix epoch alignment in allocation tests
pcarranzav Apr 14, 2023
c4917d2
fix(Staking): use encodeWithSelector instead of encodeWithSignature (…
pcarranzav Apr 14, 2023
e8a24d5
fix: improve test coverage (OZ N-05)
pcarranzav Apr 14, 2023
63f64ed
fix: use tokensLocked to check that delegation is not locked (OZ N-08)
pcarranzav Apr 14, 2023
25f5f7e
fix: remove unused CloseAllocationRequest struct (OZ N-09)
pcarranzav Apr 17, 2023
495ea0c
fix: typo (OZ N-12)
pcarranzav Apr 17, 2023
19c55b7
fix: add comment on dangerous packing assumption (OZ N-14)
pcarranzav Apr 17, 2023
5fcd2dc
fix: unit for thawingPeriod in docstring (OZ N-15)
pcarranzav Apr 17, 2023
bc506ba
fix: do not double count tokens when checking minimum stake (OZ M-08)
pcarranzav May 2, 2023
c4b39d2
fix: rename L2 migration to transfer in Staking
pcarranzav May 5, 2023
6dc8876
fix: rename test file
pcarranzav May 5, 2023
8374f92
Merge branch 'dev' into pcv/l2-stake-migration
pcarranzav Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports = {
},
skipFiles,
istanbulFolder: './reports/coverage',
configureYulOptimizer: true,
}
8 changes: 4 additions & 4 deletions addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"txHash": "0x218dbb4fd680db263524fc6be36462c18f3e267b87951cd86296eabd4a381183"
}
},
"Staking": {
"L1Staking": {
"address": "0xF55041E37E12cD407ad00CE2910B8269B01263b9",
"initArgs": [
{
Expand Down Expand Up @@ -443,7 +443,7 @@
"txHash": "0xbc6e9171943020d30c22197282311f003e79374e6eeeaab9c360942bdf4193f4"
}
},
"Staking": {
"L1Staking": {
"address": "0x35e3Cb6B317690d662160d5d02A5b364578F62c9",
"initArgs": [
"0x48eD7AfbaB432d1Fc6Ea84EEC70E745d9DAcaF3B",
Expand Down Expand Up @@ -647,7 +647,7 @@
"txHash": "0xb1e63211ea7b036bf35423034bc60490b3b35b199bddc85200ea926b76e16a4e"
}
},
"Staking": {
"L1Staking": {
"address": "0x5f8e26fAcC23FA4cbd87b8d9Dbbd33D5047abDE1",
"initArgs": [
"0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B",
Expand Down Expand Up @@ -1099,7 +1099,7 @@
"txHash": "0x3bb004adf949e9c896e85f6e3124ecea0c223470e3a091e42539613d52679c4d"
}
},
"Staking": {
"L2Staking": {
"address": "0xcd549d0C43d915aEB21d3a331dEaB9B7aF186D26",
"initArgs": [
"0x7f734E995010Aa8d28b912703093d532C37b6EAb",
Expand Down
6 changes: 4 additions & 2 deletions cli/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ let allContracts = [
'SubgraphNFTDescriptor',
'SubgraphNFT',
'L1GNS',
'Staking',
'StakingExtension',
'L1Staking',
'RewardsManager',
'DisputeManager',
'AllocationExchange',
Expand All @@ -49,7 +50,8 @@ const l2Contracts = [
'SubgraphNFTDescriptor',
'SubgraphNFT',
'L2GNS',
'Staking',
'StakingExtension',
'L2Staking',
'RewardsManager',
'DisputeManager',
'AllocationExchange',
Expand Down
26 changes: 24 additions & 2 deletions cli/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { getContractAt } from './network'

import { EpochManager } from '../build/types/EpochManager'
import { DisputeManager } from '../build/types/DisputeManager'
import { Staking } from '../build/types/Staking'
import { L1Staking } from '../build/types/L1Staking'
import { L2Staking } from '../build/types/L2Staking'
import { ServiceRegistry } from '../build/types/ServiceRegistry'
import { Curation } from '../build/types/Curation'
import { RewardsManager } from '../build/types/RewardsManager'
Expand All @@ -40,11 +41,15 @@ import { L2GraphToken } from '../build/types/L2GraphToken'
import { L2GraphTokenGateway } from '../build/types/L2GraphTokenGateway'
import { BridgeEscrow } from '../build/types/BridgeEscrow'
import { L2Curation } from '../build/types/L2Curation'
import { IL1Staking } from '../build/types/IL1Staking'
import { IL2Staking } from '../build/types/IL2Staking'
import { Interface } from 'ethers/lib/utils'
import { loadArtifact } from './artifacts'

export interface NetworkContracts {
EpochManager: EpochManager
DisputeManager: DisputeManager
Staking: Staking
Staking: IL1Staking | IL2Staking
ServiceRegistry: ServiceRegistry
Curation: Curation | L2Curation
L2Curation: L2Curation
Expand All @@ -66,6 +71,8 @@ export interface NetworkContracts {
L2GraphTokenGateway: L2GraphTokenGateway
L1GNS: L1GNS
L2GNS: L2GNS
L1Staking: IL1Staking
L2Staking: IL2Staking
}

export const loadAddressBookContract = (
Expand Down Expand Up @@ -97,6 +104,15 @@ export const loadContracts = (
contract.connect = getWrappedConnect(contract, contractName)
contract = wrapCalls(contract, contractName)
}
if (contractName == 'L1Staking') {
// Hack the contract into behaving like an IL1Staking
const iface = new Interface(loadArtifact('IL1Staking').abi)
contract = new Contract(contract.address, iface) as unknown as IL1Staking
} else if (contractName == 'L2Staking') {
// Hack the contract into behaving like an IL2Staking
const iface = new Interface(loadArtifact('IL2Staking').abi)
contract = new Contract(contract.address, iface) as unknown as IL2Staking
}
contracts[contractName] = contract

if (signerOrProvider) {
Expand All @@ -110,12 +126,18 @@ export const loadContracts = (
if (signerOrProvider && chainIdIsL2(chainId) && contractName == 'L2GNS') {
contracts['GNS'] = contracts[contractName]
}
if (signerOrProvider && chainIdIsL2(chainId) && contractName == 'L2Staking') {
contracts['Staking'] = contracts[contractName]
}
if (signerOrProvider && chainIdIsL2(chainId) && contractName == 'L2Curation') {
contracts['Curation'] = contracts[contractName]
}
if (signerOrProvider && !chainIdIsL2(chainId) && contractName == 'L1GNS') {
contracts['GNS'] = contracts[contractName]
}
if (signerOrProvider && !chainIdIsL2(chainId) && contractName == 'L1Staking') {
contracts['Staking'] = contracts[contractName]
}
} catch (err) {
logger.warn(`Could not load contract ${contractName} - ${err.message}`)
}
Expand Down
14 changes: 13 additions & 1 deletion cli/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { AddressBook } from './address-book'
import { loadArtifact } from './artifacts'
import { defaultOverrides } from './defaults'
import { GraphToken } from '../build/types/GraphToken'
import { Interface } from 'ethers/lib/utils'
import { IL1Staking } from '../build/types/IL1Staking'
import { IL2Staking } from '../build/types/IL2Staking'

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

Expand Down Expand Up @@ -197,7 +200,7 @@ export const deployContract = async (

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

if (name == 'L1Staking') {
// Hack the contract into behaving like an IL1Staking
const iface = new Interface(loadArtifact('IL1Staking').abi)
contract = new Contract(contract.address, iface, sender) as unknown as IL1Staking
} else if (name == 'L2Staking') {
// Hack the contract into behaving like an IL2Staking
const iface = new Interface(loadArtifact('IL2Staking').abi)
contract = new Contract(contract.address, iface, sender) as unknown as IL2Staking
}
return { contract, creationCodeHash, runtimeCodeHash, txHash, libraries }
}

Expand Down
7 changes: 4 additions & 3 deletions config/graph.arbitrum-goerli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contracts:
contractAddress: "${{RewardsManager.address}}"
- fn: "setContractProxy"
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
contractAddress: "${{Staking.address}}"
contractAddress: "${{L2Staking.address}}"
- fn: "setContractProxy"
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
contractAddress: "${{L2GraphToken.address}}"
Expand Down Expand Up @@ -100,7 +100,7 @@ contracts:
minter: "${{L2GNS.address}}"
- fn: "transferOwnership"
owner: *governor
Staking:
L2Staking:
proxy: true
init:
controller: "${{Controller.address}}"
Expand All @@ -114,6 +114,7 @@ contracts:
delegationRatio: 16 # delegated stake to indexer stake multiplier
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
extensionImpl: "${{StakingExtension.address}}"
calls:
- fn: "setDelegationTaxPercentage"
delegationTaxPercentage: 5000 # parts per million
Expand All @@ -137,7 +138,7 @@ contracts:
AllocationExchange:
init:
graphToken: "${{L2GraphToken.address}}"
staking: "${{Staking.address}}"
staking: "${{L2Staking.address}}"
governor: *allocationExchangeOwner
authority: *authority
calls:
Expand Down
7 changes: 4 additions & 3 deletions config/graph.arbitrum-localhost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contracts:
contractAddress: "${{RewardsManager.address}}"
- fn: "setContractProxy"
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
contractAddress: "${{Staking.address}}"
contractAddress: "${{L2Staking.address}}"
- fn: "setContractProxy"
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
contractAddress: "${{L2GraphToken.address}}"
Expand Down Expand Up @@ -100,7 +100,7 @@ contracts:
minter: "${{L2GNS.address}}"
- fn: "transferOwnership"
owner: *governor
Staking:
L2Staking:
proxy: true
init:
controller: "${{Controller.address}}"
Expand All @@ -114,6 +114,7 @@ contracts:
delegationRatio: 16 # delegated stake to indexer stake multiplier
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
extensionImpl: "${{StakingExtension.address}}"
calls:
- fn: "setDelegationTaxPercentage"
delegationTaxPercentage: 5000 # parts per million
Expand All @@ -137,7 +138,7 @@ contracts:
AllocationExchange:
init:
graphToken: "${{L2GraphToken.address}}"
staking: "${{Staking.address}}"
staking: "${{L2Staking.address}}"
governor: *allocationExchangeOwner
authority: *authority
calls:
Expand Down
7 changes: 4 additions & 3 deletions config/graph.arbitrum-one.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contracts:
contractAddress: "${{RewardsManager.address}}"
- fn: "setContractProxy"
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
contractAddress: "${{Staking.address}}"
contractAddress: "${{L2Staking.address}}"
- fn: "setContractProxy"
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
contractAddress: "${{L2GraphToken.address}}"
Expand Down Expand Up @@ -100,7 +100,7 @@ contracts:
minter: "${{L2GNS.address}}"
- fn: "transferOwnership"
owner: *governor
Staking:
L2Staking:
proxy: true
init:
controller: "${{Controller.address}}"
Expand All @@ -114,6 +114,7 @@ contracts:
delegationRatio: 16 # delegated stake to indexer stake multiplier
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
extensionImpl: "${{StakingExtension.address}}"
calls:
- fn: "setDelegationTaxPercentage"
delegationTaxPercentage: 5000 # parts per million
Expand All @@ -137,7 +138,7 @@ contracts:
AllocationExchange:
init:
graphToken: "${{L2GraphToken.address}}"
staking: "${{Staking.address}}"
staking: "${{L2Staking.address}}"
governor: *allocationExchangeOwner
authority: *authority
calls:
Expand Down
7 changes: 4 additions & 3 deletions config/graph.goerli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contracts:
contractAddress: "${{RewardsManager.address}}"
- fn: "setContractProxy"
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
contractAddress: "${{Staking.address}}"
contractAddress: "${{L1Staking.address}}"
- fn: "setContractProxy"
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
contractAddress: "${{GraphToken.address}}"
Expand Down Expand Up @@ -103,7 +103,7 @@ contracts:
minter: "${{L1GNS.address}}"
- fn: "transferOwnership"
owner: *governor
Staking:
L1Staking:
proxy: true
init:
controller: "${{Controller.address}}"
Expand All @@ -117,6 +117,7 @@ contracts:
delegationRatio: 16 # delegated stake to indexer stake multiplier
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
extensionImpl: "${{StakingExtension.address}}"
calls:
- fn: "setDelegationTaxPercentage"
delegationTaxPercentage: 5000 # parts per million
Expand All @@ -140,7 +141,7 @@ contracts:
AllocationExchange:
init:
graphToken: "${{GraphToken.address}}"
staking: "${{Staking.address}}"
staking: "${{L1Staking.address}}"
governor: *allocationExchangeOwner
authority: *authority
calls:
Expand Down
7 changes: 4 additions & 3 deletions config/graph.localhost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contracts:
contractAddress: "${{RewardsManager.address}}"
- fn: "setContractProxy"
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
contractAddress: "${{Staking.address}}"
contractAddress: "${{L1Staking.address}}"
- fn: "setContractProxy"
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
contractAddress: "${{GraphToken.address}}"
Expand Down Expand Up @@ -103,7 +103,7 @@ contracts:
minter: "${{L1GNS.address}}"
- fn: "transferOwnership"
owner: *governor
Staking:
L1Staking:
proxy: true
init:
controller: "${{Controller.address}}"
Expand All @@ -117,6 +117,7 @@ contracts:
delegationRatio: 16 # delegated stake to indexer stake multiplier
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
extensionImpl: "${{StakingExtension.address}}"
calls:
- fn: "setDelegationTaxPercentage"
delegationTaxPercentage: 5000 # parts per million
Expand All @@ -140,7 +141,7 @@ contracts:
AllocationExchange:
init:
graphToken: "${{GraphToken.address}}"
staking: "${{Staking.address}}"
staking: "${{L1Staking.address}}"
governor: *allocationExchangeOwner
authority: *authority
calls:
Expand Down
7 changes: 4 additions & 3 deletions config/graph.mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contracts:
contractAddress: "${{RewardsManager.address}}"
- fn: "setContractProxy"
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
contractAddress: "${{Staking.address}}"
contractAddress: "${{L1Staking.address}}"
- fn: "setContractProxy"
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
contractAddress: "${{GraphToken.address}}"
Expand Down Expand Up @@ -103,7 +103,7 @@ contracts:
minter: "${{L1GNS.address}}"
- fn: "transferOwnership"
owner: *governor
Staking:
L1Staking:
proxy: true
init:
controller: "${{Controller.address}}"
Expand All @@ -117,6 +117,7 @@ contracts:
delegationRatio: 16 # delegated stake to indexer stake multiplier
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
extensionImpl: "${{StakingExtension.address}}"
calls:
- fn: "setDelegationTaxPercentage"
delegationTaxPercentage: 5000 # parts per million
Expand All @@ -140,7 +141,7 @@ contracts:
AllocationExchange:
init:
graphToken: "${{GraphToken.address}}"
staking: "${{Staking.address}}"
staking: "${{L1Staking.address}}"
governor: *allocationExchangeOwner
authority: *authority
calls:
Expand Down
Loading