@@ -14,9 +14,10 @@ MAX_LPS: constant(uint256) = 500
14
14
MAX_EPOCHS: constant (uint256 ) = 200
15
15
MAX_REWARDS: constant (uint256 ) = 16
16
16
MAX_POSITIONS: constant (uint256 ) = 10
17
+ MAX_PRICES: constant (uint256 ) = 20
17
18
WEEK: constant (uint256 ) = 7 * 24 * 60 * 60
18
19
19
- # Slot0 from V3Pool .sol
20
+ # Slot0 from CLPool .sol
20
21
struct Slot :
21
22
sqrt_price: uint160
22
23
tick: int24
@@ -25,7 +26,7 @@ struct Slot:
25
26
cardinality_next: uint16
26
27
unlocked: bool
27
28
28
- # GaugeFees from V3Pool .sol
29
+ # GaugeFees from CLPool .sol
29
30
struct GaugeFees :
30
31
token0: uint128
31
32
token1: uint128
@@ -43,6 +44,19 @@ struct PositionData:
43
44
unstaked_earned0: uint128
44
45
unstaked_earned1: uint128
45
46
47
+ # Tick.Info from CLPool.sol
48
+ struct TickInfo :
49
+ liquidity_gross: uint128
50
+ liquidity_net: int128
51
+ staked_liquidity_net: int128
52
+ fee_growth_outside0: uint256
53
+ fee_growth_outside1: uint256
54
+ reward_growth_outside: uint256
55
+ tick_cumulative_outside: int56
56
+ seconds_per_liquidity_outside: uint160
57
+ seconds_outside: uint32
58
+ initialized: bool
59
+
46
60
struct Position :
47
61
id: uint256 # NFT ID on v3, 0 on v2
48
62
manager: address # NFT Position Manager on v3, router on v2
@@ -55,6 +69,10 @@ struct Position:
55
69
tick_upper: int24 # Position upper tick on v3, 0 on v2
56
70
alm: bool # True if Position is deposited into ALM on v3, False on v2
57
71
72
+ struct Price :
73
+ tick_price: int24
74
+ liquidity_gross: uint128
75
+
58
76
struct Token :
59
77
token_address: address
60
78
symbol: String[100 ]
@@ -172,6 +190,7 @@ interface IPool:
172
190
def gaugeFees () -> GaugeFees: view # v3 gauge fees amounts
173
191
def fee () -> uint24 : view # v3 fee level
174
192
def unstakedFee () -> uint24 : view # v3 unstaked fee level
193
+ def ticks (_tick: int24 ) -> TickInfo: view # v3 tick data
175
194
176
195
interface IVoter :
177
196
def gauges (_pool_addr: address ) -> address : view
@@ -579,6 +598,7 @@ def _byDataCL(_data: address[3], _token0: address, _token1: address, _account: a
579
598
emissions_token: address = empty (address )
580
599
token0: IERC20 = IERC20 (_token0)
581
600
token1: IERC20 = IERC20 (_token1)
601
+ tick_spacing: int24 = pool.tickSpacing ()
582
602
583
603
fee_voting_reward = gauge.feesVotingReward ()
584
604
emissions_token = gauge.rewardToken ()
@@ -628,7 +648,7 @@ def _byDataCL(_data: address[3], _token0: address, _token1: address, _account: a
628
648
total_supply: 0 ,
629
649
630
650
nft: nft.address ,
631
- type: pool. tickSpacing () ,
651
+ type: tick_spacing ,
632
652
tick: slot.tick,
633
653
price: price,
634
654
@@ -972,3 +992,44 @@ def _is_cl_factory(_factory: address) -> (bool):
972
992
)[1 ]
973
993
974
994
return len (response) > 0
995
+
996
+ @external
997
+ @view
998
+ def prices (_pool: address , _factory: address ) -> DynArray[Price, MAX_PRICES]:
999
+ """
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
1004
+ """
1005
+ is_cl_factory: bool = self ._is_cl_factory (_factory)
1006
+
1007
+ if is_cl_factory:
1008
+ return self ._price (_pool)
1009
+ else :
1010
+ return empty (DynArray[Price, MAX_PRICES])
1011
+
1012
+ @internal
1013
+ @view
1014
+ def _price (_pool: address ) -> DynArray[Price, MAX_PRICES]:
1015
+ """
1016
+ @notice Returns price data at surrounding ticks for a v3 pool
1017
+ @param _pool The pool to check price data of
1018
+ @return Array of Price structs
1019
+ """
1020
+ prices: DynArray[Price, MAX_PRICES] = empty (DynArray[Price, MAX_PRICES])
1021
+ pool: IPool = IPool (_pool)
1022
+ tick_spacing: int24 = pool.tickSpacing ()
1023
+ slot: Slot = pool.slot0 ()
1024
+
1025
+ # fetch liquidity from the ticks surrounding the current tick
1026
+ for index in range ((- 1 * MAX_PRICES / 2 ), (MAX_PRICES / 2 )):
1027
+ tick: int24 = slot.tick + (index * tick_spacing)
1028
+ tick_info: TickInfo = pool.ticks (tick)
1029
+
1030
+ prices.append (Price ({
1031
+ tick_price: tick,
1032
+ liquidity_gross: tick_info.liquidity_gross
1033
+ }))
1034
+
1035
+ return prices
0 commit comments