Skip to content

Commit

Permalink
feat: calculate updated claimable unstaked fees in LpSugar (#34)
Browse files Browse the repository at this point in the history
* feat: calculate updated claimable unstaked fees in LpSugar

* perf: only calculate claimable unstaked fees if nonzero account

* fix: pool decimals int conversion

* docs: add latest LpSugar deployment to readme
  • Loading branch information
ethzoomer authored Nov 15, 2023
1 parent c3f2a8d commit c30be94
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
28 changes: 24 additions & 4 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ interface IPool:
def reserve1() -> uint256: view
def claimable0(_account: address) -> uint256: view
def claimable1(_account: address) -> uint256: view
def supplyIndex0(_account: address) -> uint256: view
def supplyIndex1(_account: address) -> uint256: view
def index0() -> uint256: view
def index1() -> uint256: view
def totalSupply() -> uint256: view
def symbol() -> String[100]: view
def decimals() -> uint8: view
Expand Down Expand Up @@ -353,6 +357,22 @@ def _byData(_data: address[3], _account: address) -> Lp:
token0: IERC20 = IERC20(pool.token0())
token1: IERC20 = IERC20(pool.token1())
gauge_alive: bool = self.voter.isAlive(gauge.address)
decimals: uint8 = pool.decimals()
claimable0: uint256 = 0
claimable1: uint256 = 0
acc_balance: uint256 = 0

if _account != empty(address):
acc_balance = pool.balanceOf(_account)
claimable0 = pool.claimable0(_account)
claimable1 = pool.claimable1(_account)
claimable_delta0: uint256 = pool.index0() - pool.supplyIndex0(_account)
claimable_delta1: uint256 = pool.index1() - pool.supplyIndex1(_account)

if claimable_delta0 > 0:
claimable0 += (acc_balance * claimable_delta0) / 10**convert(decimals, uint256)
if claimable_delta1 > 0:
claimable1 += (acc_balance * claimable_delta1) / 10**convert(decimals, uint256)

if gauge.address != empty(address):
acc_staked = gauge.balanceOf(_account)
Expand All @@ -366,17 +386,17 @@ def _byData(_data: address[3], _account: address) -> Lp:
return Lp({
lp: _data[1],
symbol: pool.symbol(),
decimals: pool.decimals(),
decimals: decimals,
stable: is_stable,
total_supply: pool.totalSupply(),

token0: token0.address,
reserve0: pool.reserve0(),
claimable0: pool.claimable0(_account),
claimable0: claimable0,

token1: token1.address,
reserve1: pool.reserve1(),
claimable1: pool.claimable1(_account),
claimable1: claimable1,

gauge: gauge.address,
gauge_total_supply: gauge_total_supply,
Expand All @@ -389,7 +409,7 @@ def _byData(_data: address[3], _account: address) -> Lp:
emissions: emissions,
emissions_token: emissions_token,

account_balance: pool.balanceOf(_account),
account_balance: acc_balance,
account_earned: earned,
account_staked: acc_staked,

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Below is the list of datasets we support.

### Liquidity Pools Data

`LpSugar.vy` is deployed at `0xa1f09427fa89b92e9b4e4c7003508c8614f19791`
`LpSugar.vy` is deployed at `0x43479F2FF090A787E4e70d91f4485c7A75B0a964`

It allows fetching on-chain pools data.
The returned data/struct of type `Lp` values represent:
Expand Down

0 comments on commit c30be94

Please sign in to comment.