Skip to content

Commit 190f052

Browse files
committed
fix: Take a snapshot of GRT supply when signal is updated
1 parent 5272f4a commit 190f052

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

config/graph.mainnet.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ contracts:
103103
proxy: true
104104
init:
105105
controller: "${{Controller.address}}"
106-
issuanceRate: "1000000012184945188" # per block increase of total supply, blocks in a year = 365*60*60*24/13
106+
calls:
107+
- fn: "setIssuanceRate"
108+
_issuanceRate: "1000000012184945188" # per block increase of total supply, blocks in a year = 365*60*60*24/13
107109
AllocationExchange:
108110
init:
109111
graphToken: "${{GraphToken.address}}"

contracts/rewards/RewardsManager.sol

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import "./IRewardsManager.sol";
2727
* These functions may overestimate the actual rewards due to changes in the total supply
2828
* until the actual takeRewards function is called.
2929
*/
30-
contract RewardsManager is RewardsManagerV2Storage, GraphUpgradeable, IRewardsManager {
30+
contract RewardsManager is RewardsManagerV3Storage, GraphUpgradeable, IRewardsManager {
3131
using SafeMath for uint256;
3232

3333
uint256 private constant TOKEN_DECIMALS = 1e18;
@@ -68,11 +68,8 @@ contract RewardsManager is RewardsManagerV2Storage, GraphUpgradeable, IRewardsMa
6868
/**
6969
* @dev Initialize this contract.
7070
*/
71-
function initialize(address _controller, uint256 _issuanceRate) external onlyImpl {
71+
function initialize(address _controller) external onlyImpl {
7272
Managed._initialize(_controller);
73-
74-
// Settings
75-
_setIssuanceRate(_issuanceRate);
7673
}
7774

7875
// -- Config --
@@ -224,7 +221,7 @@ contract RewardsManager is RewardsManagerV2Storage, GraphUpgradeable, IRewardsMa
224221
}
225222

226223
uint256 r = issuanceRate;
227-
uint256 p = graphToken.totalSupply();
224+
uint256 p = tokenSupplySnapshot;
228225
uint256 a = p.mul(_pow(r, t, TOKEN_DECIMALS)).div(TOKEN_DECIMALS);
229226

230227
// New issuance of tokens during time steps
@@ -315,6 +312,7 @@ contract RewardsManager is RewardsManagerV2Storage, GraphUpgradeable, IRewardsMa
315312
function updateAccRewardsPerSignal() public override returns (uint256) {
316313
accRewardsPerSignal = getAccRewardsPerSignal();
317314
accRewardsPerSignalLastBlockUpdated = block.number;
315+
tokenSupplySnapshot = graphToken().totalSupply();
318316
return accRewardsPerSignal;
319317
}
320318

contracts/rewards/RewardsManagerStorage.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ contract RewardsManagerV2Storage is RewardsManagerV1Storage {
2626
// Minimum amount of signaled tokens on a subgraph required to accrue rewards
2727
uint256 public minimumSubgraphSignal;
2828
}
29+
30+
contract RewardsManagerV3Storage is RewardsManagerV2Storage {
31+
// Snapshot of the total supply of GRT when accRewardsPerSignal was last updated
32+
uint256 public tokenSupplySnapshot;
33+
}

test/lib/deployment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export async function deployRewardsManager(
231231
return network.deployContractWithProxy(
232232
proxyAdmin,
233233
'RewardsManager',
234-
[controller, defaults.rewards.issuanceRate],
234+
[controller],
235235
deployer,
236236
) as unknown as RewardsManager
237237
}

test/lib/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class NetworkFixture {
7575
await staking.connect(deployer).setSlasher(slasherAddress, true)
7676
await grt.connect(deployer).addMinter(rewardsManager.address)
7777
await gns.connect(deployer).approveAll()
78+
await rewardsManager.connect(deployer).setIssuanceRate(deployment.defaults.rewards.issuanceRate)
7879

7980
// Unpause the protocol
8081
await controller.connect(deployer).setPaused(false)

test/staking/allocation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
Account,
1818
} from '../lib/testHelpers'
1919

20-
const { AddressZero, HashZero } = constants
20+
const { AddressZero } = constants
2121

2222
const MAX_PPM = toBN('1000000')
2323

0 commit comments

Comments
 (0)