Skip to content

Commit

Permalink
update rounding up comments and var name
Browse files Browse the repository at this point in the history
  • Loading branch information
trmid committed Apr 5, 2024
1 parent 633865a commit b076f59
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/abstract/TieredLiquidityDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,17 @@ contract TieredLiquidityDistributor {
_tierStruct.prizeTokenPerShare = prizeTokenPerShare;
} else {
uint8 _remainder = uint8(_liquidity % _tierShares);
uint8 _overConsumption = _remainder == 0 ? 0 : _tierShares - _remainder;
if (_overConsumption > 0) {
uint8 _roundUpConsumption = _remainder == 0 ? 0 : _tierShares - _remainder;
if (_roundUpConsumption > 0) {
// We must round up our tier prize token per share value to ensure we don't over-award the tier's
// liquidity, but any over-consumption can be contributed to the reserve so every wei is accounted
// for.
_reserve += _overConsumption;
// liquidity, but any extra rounded up consumption can be contributed to the reserve so every wei
// is accounted for.
_reserve += _roundUpConsumption;
}

_tierStruct.prizeTokenPerShare += SafeCast.toUint104(uint256(_liquidity) + _overConsumption) / _tierShares;
// We know that the rounded up `liquidity` won't exceed the `remainingLiquidity` since the `remainingLiquidity`
// is an integer multiple of `_tierShares` and we check above that `_liquidity <= remainingLiquidity`.
_tierStruct.prizeTokenPerShare += SafeCast.toUint104(uint256(_liquidity) + _roundUpConsumption) / _tierShares;
}

_tiers[_tier] = _tierStruct;
Expand Down

0 comments on commit b076f59

Please sign in to comment.