Skip to content

Commit 5140ab3

Browse files
committed
Refactor CL position fetching.
1 parent 25c1178 commit 5140ab3

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

contracts/LpSugar.vy

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ interface ICLGauge:
217217
interface INFPositionManager:
218218
def positions(_position_id: uint256) -> PositionData: view
219219
def tokenOfOwnerByIndex(_account: address, _index: uint256) -> uint256: view
220+
def balanceOf(_account: address) -> uint256: view
220221

221222
interface IReward:
222223
def getPriorSupplyIndex(_ts: uint256) -> uint256: view
@@ -626,7 +627,14 @@ def _byDataCL(_data: address[4], _token0: address, _token1: address, \
626627
emissions_token: address = empty(address)
627628
token0: IERC20 = IERC20(_token0)
628629
token1: IERC20 = IERC20(_token1)
629-
tick_spacing: int24 = pool.tickSpacing()
630+
positions_count: uint256 = 0
631+
632+
slot: Slot = pool.slot0()
633+
positions: DynArray[Position, MAX_POSITIONS] = \
634+
empty(DynArray[Position, MAX_POSITIONS])
635+
636+
if _account != empty(address):
637+
positions_count = self.nfpm.balanceOf(_account)
630638

631639
if gauge.address != empty(address):
632640
fee_voting_reward = gauge.feesVotingReward()
@@ -635,18 +643,11 @@ def _byDataCL(_data: address[4], _token0: address, _token1: address, \
635643
if gauge_alive:
636644
emissions = gauge.rewardRate()
637645

638-
slot: Slot = pool.slot0()
639-
price: uint160 = slot.sqrtPriceX96
640-
641-
positions: DynArray[Position, MAX_POSITIONS] = \
642-
empty(DynArray[Position, MAX_POSITIONS])
643-
644646
for index in range(0, MAX_POSITIONS):
645-
position_id: uint256 = self.nfpm.tokenOfOwnerByIndex(_account, index)
646-
647-
if position_id == 0:
647+
if index >= positions_count:
648648
break
649649

650+
position_id: uint256 = self.nfpm.tokenOfOwnerByIndex(_account, index)
650651
position_data: PositionData = self.nfpm.positions(position_id)
651652

652653
emissions_earned: uint256 = 0
@@ -676,9 +677,9 @@ def _byDataCL(_data: address[4], _token0: address, _token1: address, \
676677
decimals: 0,
677678
total_supply: 0,
678679

679-
type: tick_spacing,
680+
type: pool.tickSpacing(),
680681
tick: slot.tick,
681-
price: price,
682+
price: slot.sqrtPriceX96,
682683

683684
token0: token0.address,
684685
reserve0: token0.balanceOf(pool.address),

0 commit comments

Comments
 (0)