Skip to content

Commit

Permalink
feat: filter factories on optimism
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrovalido committed Oct 6, 2024
1 parent 4158617 commit c3dd2ea
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def _pools(_limit: uint256, _offset: uint256)\
@notice Returns a compiled list of pool and its factory and gauge
@return Array of four addresses (factory, pool, gauge, nfpm)
"""
is_root: bool = chain.id == 10
factories: DynArray[address, MAX_FACTORIES] = self.registry.poolFactories()
factories_count: uint256 = len(factories)

Expand All @@ -302,6 +303,9 @@ def _pools(_limit: uint256, _offset: uint256)\
break

factory: IPoolFactory = IPoolFactory(factories[index])
if is_root and self._is_root_factory(factory.address):
continue

pools_count: uint256 = factory.allPoolsLength()
nfpm: address = self._fetch_nfpm(factory.address)

Expand Down Expand Up @@ -336,6 +340,7 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:
@param _offset The amount of pools to skip
@return `SwapLp` structs
"""
is_root: bool = chain.id == 10
factories: DynArray[address, MAX_FACTORIES] = self.registry.poolFactories()
factories_count: uint256 = len(factories)

Expand All @@ -348,6 +353,9 @@ def forSwaps(_limit: uint256, _offset: uint256) -> DynArray[SwapLp, MAX_POOLS]:
break

factory: IPoolFactory = IPoolFactory(factories[index])
if is_root and self._is_root_factory(factory.address):
continue

nfpm: address = self._fetch_nfpm(factory.address)
pools_count: uint256 = factory.allPoolsLength()

Expand Down Expand Up @@ -646,6 +654,7 @@ def _positions(
@param _factories The factories to fetch from
@return Array for Lp structs
"""
is_root: bool = chain.id == 10
positions: DynArray[Position, MAX_POSITIONS] = \
empty(DynArray[Position, MAX_POSITIONS])

Expand All @@ -666,6 +675,9 @@ def _positions(
break

factory: IPoolFactory = IPoolFactory(_factories[index])
if is_root and self._is_root_factory(factory.address):
continue

nfpm: INFPositionManager = \
INFPositionManager(self._fetch_nfpm(factory.address))

Expand Down Expand Up @@ -1432,3 +1444,39 @@ def _safe_symbol(_token: address) -> String[100]:
return IERC20(_token).symbol()

return "-NA-"

@internal
@view
def _is_root_factory(_factory: address) -> bool:
"""
@notice Returns true if the factory is a root pool factory.
@param _factory The factory address
"""

# v2 root factory doesn't have a MAX_FEE
response1: Bytes[32] = raw_call(
_factory,
method_id("MAX_FEE()"),
max_outsize=32,
is_delegate_call=False,
is_static_call=True,
revert_on_failure=False
)[1]

if len(response1) > 0:
return False

# slipstream root factory doesn't have a nft
response2: Bytes[32] = raw_call(
_factory,
method_id("nft()"),
max_outsize=32,
is_delegate_call=False,
is_static_call=True,
revert_on_failure=False
)[1]

if len(response2) > 0:
return False

return True

0 comments on commit c3dd2ea

Please sign in to comment.