Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c04c236
feat: implement distribution of rewards to L1 and L2 using a Reservoir
pcarranzav May 17, 2022
bef792e
fix: document potential drip reverts if issuance rate is updated [L-01]
pcarranzav Jul 11, 2022
a34e508
fix: document drip revert when l2RewardsFraction changed [L-02]
pcarranzav Jul 11, 2022
d2e53fd
fix: rename variables related to supply to issuanceBase to make it cl…
pcarranzav Jul 11, 2022
4ad867a
fix: use issuanceBase check to prevent calling initialSnapshot twice …
pcarranzav Jul 11, 2022
a8144df
test: fix tests after not allowing initialSnapshot to be called twice
pcarranzav Jul 12, 2022
5c6802f
fix: document the need for drip after a param update [L-06]
pcarranzav Jul 13, 2022
b6e1497
fix: validate L2Reservoir address on L1Reservoir [L-07]
pcarranzav Jul 12, 2022
ad09ca0
fix: rename normalizedSupply to l2IssuanceBase in L2 message to avoid…
pcarranzav Jul 13, 2022
8cd3270
fix: remove silent failure if rewardsManager is not set [L-12]
pcarranzav Jul 13, 2022
19dd310
fix: general code improvements [N-05]
pcarranzav Jul 13, 2022
6a50012
fix: use internal function to consistently set dripInterval [N-07]
pcarranzav Jul 13, 2022
965dbb3
fix: remove named returns [N-08]
pcarranzav Jul 13, 2022
f4bc6f9
fix: update some outdated docstrings and comments [N-09]
pcarranzav Jul 13, 2022
2c89ea7
fix: document why some variables are not set during initialization [N…
pcarranzav Jul 13, 2022
c1336ef
fix: add missing getters to Managed [N-11]
pcarranzav Jul 13, 2022
86cddb8
fix: separate contracts into different files [N-13]
pcarranzav Jul 14, 2022
d327b36
fix: rename some variables for clarity [N-14]
pcarranzav Jul 14, 2022
af81533
fix: document the need to retry tickets if drip is received out-of-or…
pcarranzav Jul 14, 2022
f20124a
fix: various typos [N-16]
pcarranzav Jul 14, 2022
1d1e319
fix: replace MAX_UINT256 with type().max [N-18] [N-20]
pcarranzav Jul 14, 2022
9031651
fix: remove an unused import [N-21]
pcarranzav Jul 14, 2022
e2e08d1
test: remove repeated addToCallhookWhitelist
pcarranzav Jul 15, 2022
bbb3fad
fix: use SafeMath more consistently
pcarranzav Jul 15, 2022
e2766b3
feat: keeper reward for reservoir drip through token issuance
pcarranzav Jun 5, 2022
fc42c3f
fix: don't use tx.origin as it will not work
pcarranzav Jun 8, 2022
e69c095
fix: only allow indexers, their operators, or whitelisted addresses t…
pcarranzav Jun 21, 2022
c274636
test: fix rewards and reservoir tests after restricting drip callers
pcarranzav Jun 21, 2022
51db5f9
test: add a test for the keeper reward delivery in L2
pcarranzav Jun 23, 2022
a54a629
fix: provide part of the keeper reward to L2 redeemer
pcarranzav Jun 27, 2022
e275908
fix: clean up comments about redeemer
pcarranzav Jul 15, 2022
6d0c39d
fix: more documentation details
pcarranzav Jul 15, 2022
e727133
fix: use safe math for minDripInterval
pcarranzav Jul 15, 2022
c4d583a
fix: validate input when granting/revoking drip permission
pcarranzav Jul 15, 2022
304d055
fix: docs and inheritance for IArbTxWithRedeemer
pcarranzav Jul 28, 2022
a570c8c
fix: remove minDripInterval from the drip keeper reward calculation […
pcarranzav Aug 5, 2022
2432862
fix: use L2 alias of l1ReservoirAddress when comparing getCurrentRede…
pcarranzav Aug 8, 2022
f1c9530
fix: don't include keeper reward twice when computing what to send to…
pcarranzav Aug 17, 2022
26a4922
test: add test to ensure no DoS if l2RewardsFraction is zeroed [H-04]
pcarranzav Aug 22, 2022
8869e69
test: optimize functions to advance blocks and fix some race conditions
pcarranzav Aug 22, 2022
7207a23
fix: add some missing validation on reservoirs [M-01]
pcarranzav Aug 22, 2022
117cb4a
fix: add some missing docstrings [L-04]
pcarranzav Aug 22, 2022
f2e1f81
fix: use a single-condition requires for the drip auth check [L-05]
pcarranzav Aug 22, 2022
33f7ec2
fix: add indexed params to dripper change events [N-01]
pcarranzav Aug 22, 2022
fb3ed11
fix: use explicit imports in relevant reservoir contracts [N-02]
pcarranzav Aug 22, 2022
53e0a80
test: fix call in l2Reservoir test
pcarranzav Sep 1, 2022
559ea00
fix: adjust gre, e2e and configs to account for reservoirs
pcarranzav Sep 27, 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
Prev Previous commit
Next Next commit
fix: remove named returns [N-08]
  • Loading branch information
pcarranzav committed Sep 28, 2022
commit 965dbb3dd274fc349274169c3577bb2e0ec200f8
13 changes: 7 additions & 6 deletions contracts/l2/reservoir/L2Reservoir.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,23 @@ contract L2Reservoir is L2ReservoirV1Storage, Reservoir, IL2Reservoir {
* - t0 is the last drip block, i.e. lastRewardsUpdateBlock
* - r is the issuanceRate
* @param _blocknum Block number at which to calculate rewards
* @return deltaRewards New total rewards on L2 since the last drip
* @return New total rewards on L2 since the last drip
*/
function getNewRewards(uint256 _blocknum)
public
view
override(Reservoir, IReservoir)
returns (uint256 deltaRewards)
returns (uint256)
{
uint256 t0 = lastRewardsUpdateBlock;
if (issuanceRate <= MIN_ISSUANCE_RATE || _blocknum == t0) {
return 0;
}
deltaRewards = issuanceBase
.mul(_pow(issuanceRate, _blocknum.sub(t0), TOKEN_DECIMALS))
.div(TOKEN_DECIMALS)
.sub(issuanceBase);
return
issuanceBase
.mul(_pow(issuanceRate, _blocknum.sub(t0), TOKEN_DECIMALS))
.div(TOKEN_DECIMALS)
.sub(issuanceBase);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions contracts/reservoir/IReservoir.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ interface IReservoir {
/**
* @dev Get accumulated total rewards on this layer at a particular block
* @param _blocknum Block number at which to calculate rewards
* @return totalRewards Accumulated total rewards on this layer
* @return Accumulated total rewards on this layer
*/
function getAccumulatedRewards(uint256 _blocknum) external view returns (uint256 totalRewards);
function getAccumulatedRewards(uint256 _blocknum) external view returns (uint256);

/**
* @dev Get new total rewards on this layer at a particular block, since the last drip event
* @param _blocknum Block number at which to calculate rewards
* @return deltaRewards New total rewards on this layer since the last drip
* @return New total rewards on this layer since the last drip
*/
function getNewRewards(uint256 _blocknum) external view returns (uint256 deltaRewards);
function getNewRewards(uint256 _blocknum) external view returns (uint256);
}

/**
Expand Down
24 changes: 13 additions & 11 deletions contracts/reservoir/L1Reservoir.sol
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,18 @@ contract L1Reservoir is L1ReservoirV1Storage, Reservoir {
* - t0 is the last drip block, i.e. lastRewardsUpdateBlock
* - r is the issuanceRate
* @param _blocknum Block number at which to calculate rewards
* @return deltaRewards New total rewards on both layers since the last drip
* @return New total rewards on both layers since the last drip
*/
function getNewGlobalRewards(uint256 _blocknum) public view returns (uint256 deltaRewards) {
function getNewGlobalRewards(uint256 _blocknum) public view returns (uint256) {
uint256 t0 = lastRewardsUpdateBlock;
if (issuanceRate <= MIN_ISSUANCE_RATE || _blocknum == t0) {
return 0;
}
deltaRewards = issuanceBase
.mul(_pow(issuanceRate, _blocknum.sub(t0), TOKEN_DECIMALS))
.div(TOKEN_DECIMALS)
.sub(issuanceBase);
return
issuanceBase
.mul(_pow(issuanceRate, _blocknum.sub(t0), TOKEN_DECIMALS))
.div(TOKEN_DECIMALS)
.sub(issuanceBase);
}

/**
Expand All @@ -253,12 +254,13 @@ contract L1Reservoir is L1ReservoirV1Storage, Reservoir {
* - deltaR is the new global rewards on both layers (see getNewGlobalRewards)
* - lambda is the fraction of rewards sent to L2, i.e. l2RewardsFraction
* @param _blocknum Block number at which to calculate rewards
* @return deltaRewards New total rewards on Layer 1 since the last drip
* @return New total rewards on Layer 1 since the last drip
*/
function getNewRewards(uint256 _blocknum) public view override returns (uint256 deltaRewards) {
deltaRewards = getNewGlobalRewards(_blocknum)
.mul(TOKEN_DECIMALS.sub(l2RewardsFraction))
.div(TOKEN_DECIMALS);
function getNewRewards(uint256 _blocknum) public view override returns (uint256) {
return
getNewGlobalRewards(_blocknum).mul(TOKEN_DECIMALS.sub(l2RewardsFraction)).div(
TOKEN_DECIMALS
);
}

/**
Expand Down
26 changes: 9 additions & 17 deletions contracts/reservoir/Reservoir.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,35 @@ abstract contract Reservoir is GraphUpgradeable, ReservoirV1Storage, IReservoir
/**
* @dev Get accumulated total rewards on this layer at a particular block
* @param _blocknum Block number at which to calculate rewards
* @return totalRewards Accumulated total rewards on this layer
* @return Accumulated total rewards on this layer
*/
function getAccumulatedRewards(uint256 _blocknum)
public
view
override
returns (uint256 totalRewards)
{
function getAccumulatedRewards(uint256 _blocknum) public view override returns (uint256) {
// R(t) = R(t0) + (DeltaR(t, t0))
totalRewards = accumulatedLayerRewards + getNewRewards(_blocknum);
return accumulatedLayerRewards + getNewRewards(_blocknum);
}

/**
* @dev Get new total rewards on this layer at a particular block, since the last drip event.
* Must be implemented by the reservoir on each layer.
* @param _blocknum Block number at which to calculate rewards
* @return deltaRewards New total rewards on this layer since the last drip
* @return New total rewards on this layer since the last drip
*/
function getNewRewards(uint256 _blocknum)
public
view
virtual
override
returns (uint256 deltaRewards);
function getNewRewards(uint256 _blocknum) public view virtual override returns (uint256);

/**
* @dev Raises _x to the power of _n with scaling factor of _base.
* Based on: https://github.com/makerdao/dss/blob/master/src/pot.sol#L81
* @param _x Base of the exponentiation
* @param _n Exponent
* @param _base Scaling factor
* @return z Exponential of _n with base _x
* @return Exponential of _n with base _x
*/
function _pow(
uint256 _x,
uint256 _n,
uint256 _base
) internal pure returns (uint256 z) {
) internal pure returns (uint256) {
uint256 z;
// solhint-disable-next-line no-inline-assembly
assembly {
switch _x
Expand Down Expand Up @@ -120,5 +111,6 @@ abstract contract Reservoir is GraphUpgradeable, ReservoirV1Storage, IReservoir
}
}
}
return z;
}
}