Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: calculate updated claimable unstaked fees in LpSugar #34

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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