Skip to content

Arbitrum devnet with rewards distribution #571

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 44 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
497a7d8
fix: Take a snapshot of GRT supply when signal is updated
pcarranzav May 4, 2022
1bf6515
test: add a test for rewards distribution accrual with multiple alloc…
abarmat May 15, 2022
ebf51fe
test: Add a test for two simultaneous allocations with a GRT burn in …
pcarranzav May 16, 2022
dbeaa7c
fix: Typo fix in tests
pcarranzav May 16, 2022
403be94
feat: implement distribution of rewards to L1 and L2 using a Reservoir
pcarranzav May 17, 2022
57dbbb8
fix: document potential drip reverts if issuance rate is updated [L-01]
pcarranzav Jul 11, 2022
b5967ac
fix: document drip revert when l2RewardsFraction changed [L-02]
pcarranzav Jul 11, 2022
d5fa0a8
fix: rename variables related to supply to issuanceBase to make it cl…
pcarranzav Jul 11, 2022
494df53
fix: use issuanceBase check to prevent calling initialSnapshot twice …
pcarranzav Jul 11, 2022
a15bc1d
test: fix tests after not allowing initialSnapshot to be called twice
pcarranzav Jul 12, 2022
29702d6
fix: hardcode L2 initial supply to 0 [L-05]
pcarranzav Jul 12, 2022
68cc8d3
fix: add more input validation [L-07]
pcarranzav Jul 12, 2022
06275b7
fix: remove redundant callhook whitelist on L2 [L-08]
pcarranzav Jul 12, 2022
395d858
fix: allow bigger msg.value than needed [L-09]
pcarranzav Jul 12, 2022
2f41f81
fix: document the need for drip after a param update [L-06]
pcarranzav Jul 13, 2022
e8544e8
fix: validate L2Reservoir address on L1Reservoir [L-07]
pcarranzav Jul 12, 2022
0b51643
fix: rename normalizedSupply to l2IssuanceBase in L2 message to avoid…
pcarranzav Jul 13, 2022
f561a34
fix: remove silent failure if rewardsManager is not set [L-12]
pcarranzav Jul 13, 2022
061ab3f
fix: document non-expiring permits on L2GraphToken [M-02]
pcarranzav Jul 13, 2022
88fac68
Merge branch 'pcv/552-m02-document-non-expiring-permits' into pcv/571…
pcarranzav Jul 13, 2022
f2641f1
test: remove unneeded L2 callhook whitelist entry
pcarranzav Jul 13, 2022
2582b10
fix: document the need for providing the gateways with allowance [N-01]
pcarranzav Jul 13, 2022
bb7f2e7
fix: remove unused event in L2GraphTokenGateway [N-02]
pcarranzav Jul 13, 2022
0ea0d30
fix: move nonce change to reduce gas on reverted permit call [N-03]
pcarranzav Jul 13, 2022
31e07c4
fix: general code improvements [N-05]
pcarranzav Jul 13, 2022
14ada45
fix: add some missing parameters in docstrings [N-06]
pcarranzav Jul 13, 2022
8742cc8
fix: use internal function to consistently set dripInterval [N-07]
pcarranzav Jul 13, 2022
3002d3e
fix: remove named returns [N-08]
pcarranzav Jul 13, 2022
5c1f877
fix: update some outdated docstrings and comments [N-09]
pcarranzav Jul 13, 2022
bd23616
fix: document why some variables are not set during initialization [N…
pcarranzav Jul 13, 2022
0f5fc9b
fix: add missing getters to Managed [N-11]
pcarranzav Jul 13, 2022
46a8444
fix: use Arbitrum's AddressAliasHelper instead of reimplementing it […
pcarranzav Jul 13, 2022
505a204
fix: separate contracts into different files [N-13]
pcarranzav Jul 14, 2022
b7b2a6c
fix: rename some variables for clarity [N-14]
pcarranzav Jul 14, 2022
1f798d8
fix: document the need to retry tickets if drip is received out-of-or…
pcarranzav Jul 14, 2022
012e3d2
fix: various typos [N-16]
pcarranzav Jul 14, 2022
1e171db
fix: remove unneeded ERC20Upgradeable inheritance [N-17]
pcarranzav Jul 14, 2022
65829af
fix: remove some unnecessary bits of code [N-19]
pcarranzav Jul 14, 2022
a11501f
fix: replace MAX_UINT256 with type().max [N-18] [N-20]
pcarranzav Jul 14, 2022
960cc04
fix: remove an unused import [N-21]
pcarranzav Jul 14, 2022
3a6c3b5
fix: check before adding/removing whitelisted addresses [N-23]
pcarranzav Jul 14, 2022
37d70a5
test: remove repeated addToCallhookWhitelist
pcarranzav Jul 15, 2022
9e7686f
fix: use SafeMath more consistently
pcarranzav Jul 15, 2022
8426b4c
fix: add more docs on the design behind callhook reverts [L-13]
pcarranzav Jul 26, 2022
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
42 changes: 20 additions & 22 deletions cli/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,28 @@ let allContracts = [
'AllocationExchange',
'L1GraphTokenGateway',
'BridgeEscrow',
'L1Reservoir',
]

// This is all we'll want to deploy to L2 eventually:
// const l2Contracts = [
// 'GraphProxyAdmin',
// 'BancorFormula',
// 'Controller',
// 'EpochManager',
// 'L2GraphToken',
// 'GraphCurationToken',
// 'ServiceRegistry',
// 'Curation',
// 'SubgraphNFTDescriptor',
// 'SubgraphNFT',
// 'GNS',
// 'Staking',
// 'RewardsManager',
// 'DisputeManager',
// 'AllocationExchange',
// 'L2GraphTokenGateway',
// ]
//
// But for now we'll only include a subset:
const l2Contracts = ['GraphProxyAdmin', 'Controller', 'L2GraphToken', 'L2GraphTokenGateway']
const l2Contracts = [
'GraphProxyAdmin',
'BancorFormula',
'Controller',
'EpochManager',
'L2GraphToken',
'GraphCurationToken',
'ServiceRegistry',
'Curation',
'SubgraphNFTDescriptor',
'SubgraphNFT',
'GNS',
'Staking',
'RewardsManager',
'DisputeManager',
'AllocationExchange',
'L2GraphTokenGateway',
'L2Reservoir',
]

export const migrate = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
const graphConfigPath = cliArgs.graphConfig
Expand Down
106 changes: 105 additions & 1 deletion config/graph.arbitrum-one.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,122 @@ general:
contracts:
Controller:
calls:
- fn: "setContractProxy"
id: "0xe6876326c1291dfcbbd3864a6816d698cd591defc7aa2153d7f9c4c04016c89f" # keccak256('Curation')
contractAddress: "${{Curation.address}}"
- fn: "setContractProxy"
id: "0x39605a6c26a173774ca666c67ef70cf491880e5d3d6d0ca66ec0a31034f15ea3" # keccak256('GNS')
contractAddress: "${{GNS.address}}"
- fn: "setContractProxy"
id: "0xf942813d07d17b56de9a9afc8de0ced6e8c053bbfdcc87b7badea4ddcf27c307" # keccak256('DisputeManager')
contractAddress: "${{DisputeManager.address}}"
- fn: "setContractProxy"
id: "0xc713c3df6d14cdf946460395d09af88993ee2b948b1a808161494e32c5f67063" # keccak256('EpochManager')
contractAddress: "${{EpochManager.address}}"
- fn: "setContractProxy"
id: "0x966f1e8d8d8014e05f6ec4a57138da9be1f7c5a7f802928a18072f7c53180761" # keccak256('RewardsManager')
contractAddress: "${{RewardsManager.address}}"
- fn: "setContractProxy"
id: "0x1df41cd916959d1163dc8f0671a666ea8a3e434c13e40faef527133b5d167034" # keccak256('Staking')
contractAddress: "${{Staking.address}}"
- fn: "setContractProxy"
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
contractAddress: "${{L2GraphToken.address}}"
- fn: "setContractProxy"
id: "0xd362cac9cb75c10d67bcc0b7eeb0b1ef48bb5420b556c092d4fd7f758816fcf0" # keccak256('GraphTokenGateway')
contractAddress: "${{L2GraphTokenGateway.address}}"
- fn: "setContractProxy"
id: "0x96ba401694892957e25e29c7a1e4171ae9945b5ee36339de79b199a530436e9e" # keccak256('Reservoir')
contractAddress: "${{L2Reservoir.address}}"
ServiceRegistry:
proxy: true
init:
controller: "${{Controller.address}}"
EpochManager:
proxy: true
init:
controller: "${{Controller.address}}"
lengthInBlocks: 1108 # 4 hours (in 13 second blocks)
L2GraphToken:
proxy: true
init:
owner: *governor
initialSupply: "0"
Curation:
proxy: true
init:
controller: "${{Controller.address}}"
bondingCurve: "${{BancorFormula.address}}"
curationTokenMaster: "${{GraphCurationToken.address}}"
reserveRatio: 500000 # 50% (parts per million)
curationTaxPercentage: 10000 # 1% (parts per million)
minimumCurationDeposit: "1000000000000000000" # 1 GRT
DisputeManager:
proxy: true
init:
controller: "${{Controller.address}}"
arbitrator: *arbitrator
minimumDeposit: "10000000000000000000000" # 10,000 GRT (in wei)
fishermanRewardPercentage: 500000 # 50% (parts per million)
idxSlashingPercentage: 25000 # 2.5% (parts per million)
qrySlashingPercentage: 5000 # 0.5% (parts per million)
GNS:
proxy: true
init:
controller: "${{Controller.address}}"
bondingCurve: "${{BancorFormula.address}}"
subgraphNFT: "${{SubgraphNFT.address}}"
calls:
- fn: "approveAll"
SubgraphNFT:
init:
governor: "${{Env.deployer}}"
calls:
- fn: "setTokenDescriptor"
tokenDescriptor: "${{SubgraphNFTDescriptor.address}}"
- fn: "setMinter"
minter: "${{GNS.address}}"
Staking:
proxy: true
init:
controller: "${{Controller.address}}"
minimumIndexerStake: "100000000000000000000000" # 100,000 GRT (in wei)
thawingPeriod: 6646 # 10 days (in blocks)
protocolPercentage: 10000 # 1% (parts per million)
curationPercentage: 100000 # 10% (parts per million)
channelDisputeEpochs: 2 # (in epochs)
maxAllocationEpochs: 6 # Based on epoch length this is 28 days (in epochs)
delegationUnbondingPeriod: 6 # Based on epoch length this is 28 days (in epochs)
delegationRatio: 16 # 16x (delegated stake to indexer stake multiplier)
rebateAlphaNumerator: 77 # rebateAlphaNumerator / rebateAlphaDenominator
rebateAlphaDenominator: 100 # rebateAlphaNumerator / rebateAlphaDenominator
calls:
- fn: "setDelegationTaxPercentage"
delegationTaxPercentage: 5000 # 0.5% (parts per million)
- fn: "setSlasher"
slasher: "${{DisputeManager.address}}"
allowed: true
- fn: "setAssetHolder"
assetHolder: "${{AllocationExchange.address}}"
allowed: true
RewardsManager:
proxy: true
init:
controller: "${{Controller.address}}"
AllocationExchange:
init:
graphToken: "${{GraphToken.address}}"
staking: "${{Staking.address}}"
governor: *governor
authority: *authority
calls:
- fn: "approveAll"
L2GraphTokenGateway:
proxy: true
init:
controller: "${{Controller.address}}"
L2Reservoir:
proxy: true
init:
controller: "${{Controller.address}}"
calls:
- fn: "approveRewardsManager"
14 changes: 12 additions & 2 deletions config/graph.mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ contracts:
- fn: "setContractProxy"
id: "0xd362cac9cb75c10d67bcc0b7eeb0b1ef48bb5420b556c092d4fd7f758816fcf0" # keccak256('GraphTokenGateway')
contractAddress: "${{L1GraphTokenGateway.address}}"
- fn: "setContractProxy"
id: "0x96ba401694892957e25e29c7a1e4171ae9945b5ee36339de79b199a530436e9e" # keccak256('Reservoir')
contractAddress: "${{L1Reservoir.address}}"
ServiceRegistry:
proxy: true
init:
Expand All @@ -44,7 +47,7 @@ contracts:
initialSupply: "10000000000000000000000000000" # in wei
calls:
- fn: "addMinter"
minter: "${{RewardsManager.address}}"
minter: "${{L1Reservoir.address}}"
Curation:
proxy: true
init:
Expand Down Expand Up @@ -106,7 +109,6 @@ contracts:
proxy: true
init:
controller: "${{Controller.address}}"
issuanceRate: "1000000012184945188" # per block increase of total supply, blocks in a year = 365*60*60*24/13
AllocationExchange:
init:
graphToken: "${{GraphToken.address}}"
Expand All @@ -123,3 +125,11 @@ contracts:
proxy: true
init:
controller: "${{Controller.address}}"
L1Reservoir:
proxy: true
init:
controller: "${{Controller.address}}"
dripInterval: 50400
calls:
- fn: "approveRewardsManager"
- fn: "initialSnapshot"
46 changes: 46 additions & 0 deletions contracts/arbitrum/AddressAliasHelper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright 2019-2021, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Originally copied from:
* https://github.com/OffchainLabs/arbitrum/tree/84e64dee6ee82adbf8ec34fd4b86c207a61d9007/packages/arb-bridge-eth
*
* MODIFIED from Offchain Labs' implementation:
* - Changed solidity version to 0.7.6 ([email protected])
*
*/

pragma solidity ^0.7.6;

library AddressAliasHelper {
uint160 constant offset = uint160(0x1111000000000000000000000000000000001111);

/// @notice Utility function that converts the address in the L1 that submitted a tx to
/// the inbox to the msg.sender viewed in the L2
/// @param l1Address the address in the L1 that triggered the tx to L2
/// @return l2Address L2 address as viewed in msg.sender
function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) {
l2Address = address(uint160(l1Address) + offset);
}

/// @notice Utility function that converts the msg.sender viewed in the L2 to the
/// address in the L1 that submitted a tx to the inbox
/// @param l2Address L2 address as viewed in msg.sender
/// @return l1Address the address in the L1 that triggered the tx to L2
function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) {
l1Address = address(uint160(l2Address) - offset);
}
}
2 changes: 1 addition & 1 deletion contracts/arbitrum/ITokenGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface ITokenGateway {
/**
* @notice Calculate the address used when bridging an ERC20 token
* @dev the L1 and L2 address oracles may not always be in sync.
* For example, a custom token may have been registered but not deploy or the contract self destructed.
* For example, a custom token may have been registered but not deployed or the contract self destructed.
* @param l1ERC20 address of L1 token
* @return L2 address of a bridged ERC20 token
*/
Expand Down
14 changes: 6 additions & 8 deletions contracts/gateway/BridgeEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import "../token/IGraphToken.sol";
* approved as a spender.
*/
contract BridgeEscrow is GraphUpgradeable, Managed {
uint256 private constant MAX_UINT256 = 2**256 - 1;

/**
* @dev Initialize this contract.
* @param _controller Address of the Controller that manages this contract
Expand All @@ -25,18 +23,18 @@ contract BridgeEscrow is GraphUpgradeable, Managed {

/**
* @dev Approve a spender (i.e. a bridge that manages the GRT funds held by the escrow)
* @param spender Address of the spender that will be approved
* @param _spender Address of the spender that will be approved
*/
function approveAll(address spender) external onlyGovernor {
graphToken().approve(spender, MAX_UINT256);
function approveAll(address _spender) external onlyGovernor {
graphToken().approve(_spender, type(uint256).max);
}

/**
* @dev Revoke a spender (i.e. a bridge that will no longer manage the GRT funds held by the escrow)
* @param spender Address of the spender that will be revoked
* @param _spender Address of the spender that will be revoked
*/
function revokeAll(address spender) external onlyGovernor {
function revokeAll(address _spender) external onlyGovernor {
IGraphToken grt = graphToken();
grt.decreaseAllowance(spender, grt.allowance(address(this), spender));
grt.decreaseAllowance(_spender, grt.allowance(address(this), _spender));
}
}
6 changes: 3 additions & 3 deletions contracts/gateway/GraphTokenGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ abstract contract GraphTokenGateway is GraphUpgradeable, Pausable, Managed, ITok

/**
* @notice Change the paused state of the contract
* @param newPaused New value for the pause state (true means the transfers will be paused)
* @param _newPaused New value for the pause state (true means the transfers will be paused)
*/
function setPaused(bool newPaused) external onlyGovernorOrGuardian {
_setPaused(newPaused);
function setPaused(bool _newPaused) external onlyGovernorOrGuardian {
_setPaused(_newPaused);
}

/**
Expand Down
Loading