From 1a899e5273c35900e5add050327d8843f6b92755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stas=20SU=C8=98COV?= Date: Wed, 18 Dec 2024 18:45:27 +0000 Subject: [PATCH 1/3] LpSugar: alm v2. --- contracts/LpSugar.vy | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/contracts/LpSugar.vy b/contracts/LpSugar.vy index 9df5eca..1f42107 100644 --- a/contracts/LpSugar.vy +++ b/contracts/LpSugar.vy @@ -121,7 +121,7 @@ struct Lp: root: address # See: -# https://github.com/mellow-finance/mellow-alm-toolkit/blob/main/src/interfaces/ICore.sol#L12-L60 +# https://github.com/mellow-finance/mellow-alm-toolkit/blob/main/src/interfaces/ICore.sol#L71-L120 struct AlmManagedPositionInfo: slippageD9: uint32 property: uint24 @@ -195,15 +195,14 @@ interface ISlipstreamHelper: def poolFees(_pool: address, _liquidity: uint128, _current_tick: int24, _lower_tick: int24, _upper_tick: int24) -> Amounts: view interface IAlmFactory: - def poolToAddresses(pool: address) -> address[2]: view - def getImmutableParams() -> address[5]: view + def poolToWrapper(pool: address) -> address: view + def core() -> address: view interface IAlmCore: def managedPositionAt(_id: uint256) -> AlmManagedPositionInfo: view interface IAlmLpWrapper: def positionId() -> uint256: view - def totalSupply() -> uint256: view # Vars cl_helper: public(ISlipstreamHelper) @@ -557,7 +556,7 @@ def _positions( alm_core: IAlmCore = empty(IAlmCore) if self.alm_factory != empty(IAlmFactory): - alm_core = IAlmCore((staticcall self.alm_factory.getImmutableParams())[0]) + alm_core = IAlmCore(staticcall self.alm_factory.core()) for index: uint256 in range(0, lp_shared.MAX_FACTORIES): if index >= factories_count: @@ -669,11 +668,11 @@ def _positions( if self.alm_factory == empty(IAlmFactory): continue - alm_addresses: address[2] = staticcall self.alm_factory.poolToAddresses(pool_addr) - alm_staking: IGauge = IGauge(alm_addresses[0]) - alm_vault: IAlmLpWrapper = IAlmLpWrapper(alm_addresses[1]) + alm_staking: IGauge = IGauge( + staticcall self.alm_factory.poolToWrapper(pool_addr) + ) - if alm_vault.address == empty(address): + if alm_staking.address == empty(address): continue alm_user_liq: uint256 = staticcall alm_staking.balanceOf(_account) @@ -682,7 +681,7 @@ def _positions( continue alm_pos: AlmManagedPositionInfo = staticcall alm_core.managedPositionAt( - staticcall alm_vault.positionId() + staticcall IAlmLpWrapper(alm_staking.address).positionId() ) if gauge.address != empty(address) and len(alm_pos.ammPositionIds) > 0: @@ -700,7 +699,7 @@ def _positions( nfpm.address ) - alm_liq: uint256 = staticcall alm_vault.totalSupply() + alm_liq: uint256 = staticcall alm_staking.totalSupply() # adjust user share of the vault... pos.amount0 = (alm_user_liq * pos.amount0) // alm_liq pos.amount1 = (alm_user_liq * pos.amount1) // alm_liq @@ -715,7 +714,7 @@ def _positions( pos.liquidity = (alm_user_liq * pos.liquidity) // alm_liq pos.staked = (alm_user_liq * pos.staked) // alm_liq - pos.alm = alm_vault.address + pos.alm = alm_staking.address if len(positions) < MAX_POSITIONS: positions.append(pos) @@ -980,9 +979,9 @@ def _cl_lp(_data: address[4], _token0: address, _token1: address) -> Lp: if gauge_alive and staticcall gauge.periodFinish() > block.timestamp: emissions = staticcall gauge.rewardRate() - alm_addresses: address[2] = [empty(address), empty(address)] + alm_wrapper: address = empty(address) if self.alm_factory != empty(IAlmFactory): - alm_addresses = staticcall self.alm_factory.poolToAddresses(pool.address) + alm_wrapper = staticcall self.alm_factory.poolToWrapper(pool.address) return Lp({ lp: pool.address, @@ -1019,7 +1018,7 @@ def _cl_lp(_data: address[4], _token0: address, _token1: address) -> Lp: token1_fees: token1_fees, nfpm: _data[3], - alm: alm_addresses[1], + alm: alm_wrapper, root: lp_shared._root_lp_address(_data[0], _token0, _token1, tick_spacing), }) From 810b14ff93f9a637b54a2189db2928fb6cc437a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stas=20SU=C8=98COV?= Date: Wed, 18 Dec 2024 18:46:06 +0000 Subject: [PATCH 2/3] env: alm v2 releases. --- env.base | 4 ++-- env.optimism | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/env.base b/env.base index 5b1c8d7..48896fb 100644 --- a/env.base +++ b/env.base @@ -5,7 +5,7 @@ VOTER_8453=0x16613524e02ad97eDfeF371bC883F2F5d6C480A5 REGISTRY_8453=0x5C3F18F06CC09CA1910767A34a20F771039E37C0 CONVERTOR_8453=0x1111111111111111111111111111111111111111 SLIPSTREAM_HELPER_8453=0x9c62ab10577fB3C20A22E231b7703Ed6D456CC7a -ALM_FACTORY_8453=0x5B1b1aaC71bDca9Ed1dCb2AA357f678584db4029 +ALM_FACTORY_8453=0xb4eA34bDD77D75b97dF6b07DA0b2A3021B6D2227 DIST_8453=0x227f65131A261548b057215bB1D5Ab2997964C7d RELAY_REGISTRY_ADDRESSES_8453=0x05e41604B9463e2224227053980dfF3f57fb6dB5,0xD308aBCe663302d3b86b36d332CEFd8A4F62C5Ed GOVERNOR_8453=0x94C012A23A8A65A6f40608dA30534a46a433F410 @@ -14,7 +14,7 @@ TEST_FACTORY_ADDRESS_8453=0x5e7BB104d84c7CB9B682AaC2F3d509f5F406809A TEST_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac TEST_ALM_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac -LP_SUGAR_ADDRESS_8453=0xF117AFbE285f867c67960F4bfEDe3121Cf6d8F76 +LP_SUGAR_ADDRESS_8453=0x90965Bab5cb1e65C3084e972e6ce8E21BAC98406 REWARDS_SUGAR_ADDRESS_8453=0xA44600F4DBA6683d8BD99270B1A6a143fB9F1C3B VE_SUGAR_ADDRESS_8453=0x4c5d3925fe65DFeB5A079485136e4De09cb664A5 RELAY_SUGAR_ADDRESS_8453=0x8932B5FE23C07Df06533F8f09E43e7cca6a24143 diff --git a/env.optimism b/env.optimism index ce11781..e0fae5b 100644 --- a/env.optimism +++ b/env.optimism @@ -5,7 +5,7 @@ VOTER_10=0x41C914ee0c7E1A5edCD0295623e6dC557B5aBf3C REGISTRY_10=0xF4c67CdEAaB8360370F41514d06e32CcD8aA1d7B CONVERTOR_10=0x585Af0b397AC42dbeF7f18395426BF878634f18D SLIPSTREAM_HELPER_10=0xD45624bf2CB9f65ecbdF3067d21992b099b56202 -ALM_FACTORY_10=0xeD8b81E3fF6c54951621715F5992CA52007D88bA +ALM_FACTORY_10=0xb4eA34bDD77D75b97dF6b07DA0b2A3021B6D2227 DIST_10=0x9D4736EC60715e71aFe72973f7885DCBC21EA99b RELAY_REGISTRY_ADDRESSES_10=0xe9F00f2e61CB0c6fb00A2e457546aCbF0fC303C2,0x6b1253B116B5919932399295C75116d33F8EfF96 GOVERNOR_10=0x1F82e10D58aEf03DeA2e478029fB0387A1cbE989 @@ -13,7 +13,7 @@ GOVERNOR_10=0x1F82e10D58aEf03DeA2e478029fB0387A1cbE989 TEST_ADDRESS_10=0x892ff98a46e5bd141e2d12618f4b2fe6284debac TEST_ALM_ADDRESS_10=0x892ff98a46e5bd141e2d12618f4b2fe6284debac -LP_SUGAR_ADDRESS_10=0x191FF5F5EAC07b082ff877236E8e7537c2d9D2A7 +LP_SUGAR_ADDRESS_10=0x1daB29f962443cEC71AD43292B0F4d554ABC0A5B REWARDS_SUGAR_ADDRESS_10=0x62CCFB2496f49A80B0184AD720379B529E9152fB VE_SUGAR_ADDRESS_10=0x94f913362b232e31daB49a1aFB775cfd25DaA6a1 RELAY_SUGAR_ADDRESS_10=0xb8307e5842B9aeE75C704183F0355076aa74b4e2 From c4c7fe0154a75ea20b0f19d4079509ea80c1022d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stas=20SU=C8=98COV?= Date: Thu, 19 Dec 2024 19:17:32 +0000 Subject: [PATCH 3/3] LpSugar: account for ALM temper strategy. --- contracts/LpSugar.vy | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/contracts/LpSugar.vy b/contracts/LpSugar.vy index 1f42107..415a6e3 100644 --- a/contracts/LpSugar.vy +++ b/contracts/LpSugar.vy @@ -699,6 +699,22 @@ def _positions( nfpm.address ) + # For the Temper strategy we might have a second position to add up + if len(alm_pos.ammPositionIds) > 1: + pos2: Position = self._cl_position( + alm_pos.ammPositionIds[1], + # Account is the ALM Core contract here... + alm_core.address, + pool_addr, + gauge.address if staked else empty(address), + factory.address, + nfpm.address + ) + pos.amount0 += pos2.amount0 + pos.amount1 += pos2.amount1 + pos.staked0 += pos2.staked0 + pos.staked1 += pos2.staked1 + alm_liq: uint256 = staticcall alm_staking.totalSupply() # adjust user share of the vault... pos.amount0 = (alm_user_liq * pos.amount0) // alm_liq @@ -706,14 +722,13 @@ def _positions( pos.staked0 = (alm_user_liq * pos.staked0) // alm_liq pos.staked1 = (alm_user_liq * pos.staked1) // alm_liq - pos.emissions_earned = staticcall alm_staking.earned(_account) # ignore dust as the rebalancing might report "fees" pos.unstaked_earned0 = 0 pos.unstaked_earned1 = 0 - pos.liquidity = (alm_user_liq * pos.liquidity) // alm_liq - pos.staked = (alm_user_liq * pos.staked) // alm_liq - + pos.emissions_earned = staticcall alm_staking.earned(_account) + pos.liquidity = alm_user_liq + pos.staked = alm_user_liq pos.alm = alm_staking.address if len(positions) < MAX_POSITIONS: