From c3dd2ea0a276bd6e592ad9973cbd7e4c85b5ce4d Mon Sep 17 00:00:00 2001 From: Pedro Valido <80268365+pedrovalido@users.noreply.github.com> Date: Sun, 6 Oct 2024 15:37:57 +0100 Subject: [PATCH] feat: filter factories on optimism --- contracts/LpSugar.vy | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/contracts/LpSugar.vy b/contracts/LpSugar.vy index 3be5c0d..04af53c 100644 --- a/contracts/LpSugar.vy +++ b/contracts/LpSugar.vy @@ -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) @@ -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) @@ -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) @@ -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() @@ -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]) @@ -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)) @@ -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