Skip to content

Commit

Permalink
feat: add pool_fee to forswaps, update v2 claimable unstaked fees
Browse files Browse the repository at this point in the history
  • Loading branch information
ethzoomer committed Jan 4, 2024
1 parent 908f286 commit f46069d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
35 changes: 30 additions & 5 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct SwapLp:
token0: address
token1: address
factory: address
pool_fee: uint256

struct Lp:
lp: address
Expand Down Expand Up @@ -154,6 +155,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 @@ -302,6 +307,7 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:
token0: address = pool.token0()
token1: address = pool.token1()
reserve0: uint256 = 0
pool_fee: uint256 = 0

is_cl_pool: bool = False
is_stable: bool = factory.getPool(token0, token1, 0) == pool_addr
Expand All @@ -312,19 +318,22 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:
if is_cl_pool:
type = pool.tickSpacing()
reserve0 = IERC20(token0).balanceOf(pool_addr)
pool_fee = convert(pool.fee(), uint256)

else:
if is_stable:
type = 0
reserve0 = pool.reserve0()
pool_fee = factory.getFee(pool_addr, is_stable)

if reserve0 > 0:
pools.append(SwapLp({
lp: pool_addr,
type: type,
token0: token0,
token1: token1,
factory: factory.address
factory: factory.address,
pool_fee: pool_fee
}))

return pools
Expand Down Expand Up @@ -489,6 +498,10 @@ def _byData(_data: address[3], _token0: address, _token1: address, _account: add
token0: IERC20 = IERC20(_token0)
token1: IERC20 = IERC20(_token1)
gauge_alive: bool = self.voter.isAlive(gauge.address)
decimals: uint8 = pool.decimals()
claimable0: uint256 = 0
claimable1: uint256 = 0
acc_balance: uint256 = 0

type: int24 = -1
if is_stable:
Expand All @@ -503,16 +516,28 @@ def _byData(_data: address[3], _token0: address, _token1: address, _account: add
if gauge_alive:
emissions = gauge.rewardRate()

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)

positions: DynArray[Position, MAX_POSITIONS] = empty(DynArray[Position, MAX_POSITIONS])

positions.append(
Position({
id: 0,
manager: self.router,
liquidity: pool.balanceOf(_account),
liquidity: acc_balance,
staked: acc_staked,
unstaked_earned0: pool.claimable0(_account),
unstaked_earned1: pool.claimable1(_account),
unstaked_earned0: claimable0,
unstaked_earned1: claimable1,
emissions_earned: earned,
tick_lower: 0,
tick_upper: 0,
Expand All @@ -523,7 +548,7 @@ def _byData(_data: address[3], _token0: address, _token1: address, _account: add
return Lp({
lp: _data[1],
symbol: pool.symbol(),
decimals: pool.decimals(),
decimals: decimals,
total_supply: pool.totalSupply(),

nft: empty(address),
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 `0x211D33f1ccfb8128aB9FAF1f502531c1De31d997`
`LpSugar.vy` is deployed at `0xc1300feCf066aC49a067F094747a5d150E878528`

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

0 comments on commit f46069d

Please sign in to comment.