Skip to content

Commit fd9e63f

Browse files
committed
refactor: add individual tick price function
1 parent 6d4b872 commit fd9e63f

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

contracts/LpSugar.vy

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ struct Price:
7373
tick_price: int24
7474
liquidity_gross: uint128
7575

76-
struct LpPrice:
77-
lp: address
78-
prices: DynArray[Price, MAX_PRICES]
79-
8076
struct Token:
8177
token_address: address
8278
symbol: String[100]
@@ -999,37 +995,20 @@ def _is_cl_factory(_factory: address) -> (bool):
999995

1000996
@external
1001997
@view
1002-
def prices(_limit: uint256, _offset: uint256) -> DynArray[LpPrice, MAX_POOLS]:
998+
def price(_pool: address, _factory: address) -> DynArray[Price, MAX_PRICES]:
1003999
"""
1004-
@notice Returns a collection of tick price data for pools
1005-
@param _limit The max amount of pools to return
1006-
@param _offset The amount of pools to skip
1007-
@return Array of LpPrice structs
1000+
@notice Returns price data at surrounding ticks for a pool
1001+
@param _pool The pool to check price data of
1002+
@param _factory The factory of the pool
1003+
@return Array of Price structs
10081004
"""
1009-
col: DynArray[LpPrice, MAX_POOLS] = empty(DynArray[LpPrice, MAX_POOLS])
1010-
pools: DynArray[address[3], MAX_POOLS] = self._pools()
1011-
pools_count: uint256 = len(pools)
1012-
1013-
for index in range(_offset, _offset + MAX_POOLS):
1014-
if len(col) == _limit or index >= pools_count:
1015-
break
1016-
1017-
factory: IPoolFactory = IPoolFactory(pools[index][0])
1018-
is_cl_factory: bool = self._is_cl_factory(pools[index][0])
1005+
is_cl_factory: bool = self._is_cl_factory(_factory)
10191006

1020-
if is_cl_factory:
1021-
col.append(LpPrice({
1022-
lp: pools[index][1],
1023-
prices: self._price(pools[index][1])
1024-
}))
1025-
else:
1026-
empty_prices: DynArray[Price, MAX_PRICES] = empty(DynArray[Price, MAX_PRICES])
1027-
col.append(LpPrice({
1028-
lp: pools[index][1],
1029-
prices: empty_prices
1030-
}))
1031-
1032-
return col
1007+
if is_cl_factory:
1008+
return self._price(_pool)
1009+
else:
1010+
empty_prices: DynArray[Price, MAX_PRICES] = empty(DynArray[Price, MAX_PRICES])
1011+
return empty_prices
10331012

10341013
@internal
10351014
@view

0 commit comments

Comments
 (0)