-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement distribution of rewards to L1 and L2 using a Reservoir
BREAKING CHANGE: remove setIssuanceRate from RewardsManager interface
- Loading branch information
1 parent
1576535
commit 574e962
Showing
24 changed files
with
1,192 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.7.6; | ||
pragma abicoder v2; | ||
|
||
import "@openzeppelin/contracts/math/SafeMath.sol"; | ||
|
||
import "../../reservoir/IReservoir.sol"; | ||
import "../../reservoir/Reservoir.sol"; | ||
import "./L2ReservoirStorage.sol"; | ||
|
||
/** | ||
* @title L2 Rewards Reservoir | ||
* @dev TODO | ||
*/ | ||
contract L2Reservoir is L2ReservoirV1Storage, Reservoir, IL2Reservoir { | ||
using SafeMath for uint256; | ||
|
||
modifier onlyL2Gateway() { | ||
require(msg.sender == _resolveContract(keccak256("GraphTokenGateway")), "ONLY_GATEWAY"); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Initialize this contract. | ||
* The contract will be paused. | ||
* @param _controller Address of the Controller that manages this contract | ||
*/ | ||
function initialize(address _controller) external onlyImpl { | ||
Managed._initialize(_controller); | ||
} | ||
|
||
function deltaRewards(uint256 t1, uint256 t0) | ||
public | ||
view | ||
override(Reservoir, IReservoir) | ||
returns (uint256) | ||
{ | ||
if (issuanceRate <= MIN_ISSUANCE_RATE || t1 == t0) { | ||
return 0; | ||
} | ||
return | ||
normalizedTokenSupplyCache.mul(_pow(issuanceRate, t1.sub(t0), TOKEN_DECIMALS)).div( | ||
TOKEN_DECIMALS | ||
); | ||
} | ||
|
||
/** | ||
* @dev TODO | ||
* If we change bridge to use an onTokenTransfer function, we should make | ||
* that function parse the calldata and call this. | ||
*/ | ||
function receiveDrip(uint256 _normalizedTokenSupply, uint256 _issuanceRate) | ||
external | ||
override | ||
onlyL2Gateway | ||
{ | ||
if (_normalizedTokenSupply > normalizedTokenSupplyCache) { | ||
if (_issuanceRate != issuanceRate) { | ||
rewardsManager().updateAccRewardsPerSignal(); | ||
snapshotAccumulatedRewards(); | ||
issuanceRate = _issuanceRate; | ||
} else { | ||
snapshotAccumulatedRewards(); | ||
} | ||
normalizedTokenSupplyCache = _normalizedTokenSupply; | ||
} | ||
} | ||
|
||
function snapshotAccumulatedRewards() internal { | ||
accumulatedLayerRewards = getAccumulatedRewards(block.number); | ||
lastRewardsUpdateBlock = block.number; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.7.6; | ||
|
||
contract L2ReservoirV1Storage { | ||
uint256 public normalizedTokenSupplyCache; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
pragma solidity ^0.7.6; | ||
|
||
interface IReservoir { | ||
function approveRewardsManager() external; | ||
|
||
function getAccumulatedRewards(uint256 blocknum) external view returns (uint256); | ||
|
||
function deltaRewards(uint256 t1, uint256 t0) external view returns (uint256); | ||
} | ||
|
||
interface IL2Reservoir is IReservoir { | ||
function receiveDrip(uint256 _normalizedTokenSupply, uint256 _issuanceRate) external; | ||
} |
Oops, something went wrong.