Skip to content

Commit

Permalink
LpSugar: merge CL positions fetching.
Browse files Browse the repository at this point in the history
Previously ALM and staked positions would loop twice.
Now it's all part of just one loop.
  • Loading branch information
stas committed Oct 11, 2024
1 parent 6da795d commit e810ff2
Showing 1 changed file with 27 additions and 43 deletions.
70 changes: 27 additions & 43 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e810ff2

Please sign in to comment.