Skip to content

Commit

Permalink
fix: CL gauge reward rate, CL gauge fees overflow (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethzoomer authored Mar 25, 2024
1 parent d6f2135 commit f6238b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
17 changes: 7 additions & 10 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ interface IGauge:
def rewardRate() -> uint256: view
def rewardRateByEpoch(_ts: uint256) -> uint256: view
def rewardToken() -> address: view
def lastTimeRewardApplicable() -> uint256: view
def periodFinish() -> uint256: view

interface ICLGauge:
def earned(_account: address, _position_id: uint256) -> uint256: view
Expand All @@ -206,7 +206,7 @@ interface ICLGauge:
def feesVotingReward() -> address: view
def stakedContains(_account: address, _position_id: uint256) -> bool: view
def stakedValues(_account: address) -> DynArray[uint256, MAX_POSITIONS]: view
def lastTimeRewardApplicable() -> uint256: view
def periodFinish() -> uint256: view

interface INFPositionManager:
def positions(_position_id: uint256) -> PositionData: view
Expand Down Expand Up @@ -534,7 +534,7 @@ def _v2_lp(_data: address[4], _token0: address, _token1: address) -> Lp:
gauge_liquidity = gauge.totalSupply()
emissions_token = gauge.rewardToken()

if gauge_alive and gauge.lastTimeRewardApplicable() > block.timestamp:
if gauge_alive and gauge.periodFinish() > block.timestamp:
emissions = gauge.rewardRate()
if gauge_liquidity > 0:
token0_fees = (pool.claimable0(_data[2]) * pool_liquidity) / gauge_liquidity
Expand Down Expand Up @@ -864,14 +864,11 @@ def _cl_lp(_data: address[4], _token0: address, _token1: address) -> Lp:

# Estimate based on the ratio of staked liquidity...
gauge_fees: GaugeFees = pool.gaugeFees()
token0_fees = convert(
(gauge_fees.token0 * pool_liquidity) / gauge_liquidity, uint256
)
token1_fees = convert(
(gauge_fees.token1 * pool_liquidity) / gauge_liquidity, uint256
)
# Convert to uint256 first to prevent overflows
token0_fees = (convert(gauge_fees.token0, uint256) * convert(pool_liquidity, uint256)) / convert(gauge_liquidity, uint256)
token1_fees = (convert(gauge_fees.token1, uint256) * convert(pool_liquidity, uint256)) / convert(gauge_liquidity, uint256)

if gauge_alive and gauge.lastTimeRewardApplicable() > block.timestamp:
if gauge_alive and gauge.periodFinish() > block.timestamp:
emissions = gauge.rewardRate()

return Lp({
Expand Down
2 changes: 1 addition & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ RELAY_REGISTRY_ADDRESSES=0xe9F00f2e61CB0c6fb00A2e457546aCbF0fC303C2,0x6b1253B116
NFPM_ADDRESS=0xbB5DFE1380333CEE4c2EeBd7202c80dE2256AdF4
SLIPSTREAM_HELPER_ADDRESS=0x5Bd7E2221C2d59c99e6A9Cd18D80A5F4257D0f32
GOVERNOR_ADDRESS=0x0000000000000000000000000000000000000000
LP_SUGAR_ADDRESS=0x72F7e299D2634D4036ce37A495600B157570559C
LP_SUGAR_ADDRESS=0x5c11A74bCC258EE53c6E5Ae7afd83C0976e092C4
VE_SUGAR_ADDRESS=0x37403dBd6f1b583ea244F7956fF9e37EF45c63eB
RELAY_SUGAR_ADDRESS=0x062185EEF2726EFc11880856CD356FA2Ac2B38Ff
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Below is the list of datasets we support.
### Liquidity Pools Data

> [!NOTE]
> `LpSugar.vy` is deployed at `0x4209B82ad1D140C94518E11B05094E76bC1c6E27`
> `LpSugar.vy` is deployed at `0x5c11A74bCC258EE53c6E5Ae7afd83C0976e092C4`
It allows fetching on-chain pools data.
The returned data/struct of type `Lp` values represent:
Expand Down

0 comments on commit f6238b5

Please sign in to comment.