diff --git a/contracts/LpSugar.vy b/contracts/LpSugar.vy index eb26369..435552e 100644 --- a/contracts/LpSugar.vy +++ b/contracts/LpSugar.vy @@ -663,13 +663,12 @@ def _positions( break factory: IPoolFactory = IPoolFactory(_factories[index]) + pools_count: uint256 = factory.allPoolsLength() nfpm: INFPositionManager = \ INFPositionManager(self._fetch_nfpm(factory.address)) # V2/Basic pool if nfpm.address == empty(address): - pools_count: uint256 = factory.allPoolsLength() - for pindex in range(0, MAX_ITERATIONS): if pindex >= pools_count or pools_done >= _limit: break @@ -720,9 +719,7 @@ def _positions( else: break - pools_count: uint256 = factory.allPoolsLength() - - # fetch ALM positions + # Fetch CL positions (staked + ALM) for pindex in range(0, MAX_POOLS): if pindex >= pools_count or pools_done >= _limit: break @@ -741,6 +738,31 @@ def _positions( gauge: ICLGauge = ICLGauge(self.voter.gauges(pool_addr)) staked: bool = False + # Fetch staked CL positions first! + if gauge.address != empty(address): + staked_position_ids: DynArray[uint256, MAX_POSITIONS] = \ + gauge.stakedValues(_account) + + for sindex in range(0, MAX_POSITIONS): + if sindex >= len(staked_position_ids): + break + + pos: Position = self._cl_position( + staked_position_ids[sindex], + _account, + pool_addr, + gauge.address, + factory.address, + nfpm.address + ) + + if len(positions) < MAX_POSITIONS: + positions.append(pos) + else: + break + + # Next, continue with fetching the ALM positions! + if alm_vault.address == empty(address): continue @@ -790,44 +812,6 @@ def _positions( else: break - # fetch staked CL positions - for pindex in range(0, MAX_ITERATIONS): - if pindex >= pools_count or pools_done >= _limit: - break - - # Basically skip calls for offset records... - if to_skip > 0: - to_skip -= 1 - continue - else: - pools_done += 1 - - pool_addr: address = factory.allPools(pindex) - gauge: ICLGauge = ICLGauge(self.voter.gauges(pool_addr)) - - if gauge.address == empty(address): - continue - - staked_position_ids: DynArray[uint256, MAX_POSITIONS] = gauge.stakedValues(_account) - - for sindex in range(0, MAX_POSITIONS): - if sindex >= len(staked_position_ids): - break - - pos: Position = self._cl_position( - staked_position_ids[sindex], - _account, - pool_addr, - gauge.address, - factory.address, - nfpm.address - ) - - if len(positions) < MAX_POSITIONS: - positions.append(pos) - else: - break - return positions @internal