Skip to content

Commit

Permalink
LpSugar: cleanups and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
stas committed Dec 6, 2024
1 parent 637478a commit c4ba768
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
26 changes: 6 additions & 20 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ struct AlmManagedPositionInfo:

# Our contracts / Interfaces

interface IERC20:
def decimals() -> uint8: view
def symbol() -> String[100]: view
def balanceOf(_account: address) -> uint256: view

interface IPool:
def token0() -> address: view
def token1() -> address: view
Expand Down Expand Up @@ -348,7 +343,6 @@ def tokens(_limit: uint256, _offset: uint256, _account: address, \
@internal
@view
def _token(_address: address, _account: address) -> Token:
token: IERC20 = IERC20(_address)
bal: uint256 = empty(uint256)

if _account != empty(address):
Expand Down Expand Up @@ -433,8 +427,6 @@ def _v2_lp(_data: address[4], _token0: address, _token1: address) -> Lp:
is_stable: bool = staticcall pool.stable()
pool_fee: uint256 = staticcall lp_shared.IPoolFactory(_data[0]).getFee(pool.address, is_stable)
pool_fees: address = staticcall pool.poolFees()
token0: IERC20 = IERC20(_token0)
token1: IERC20 = IERC20(_token1)
token0_fees: uint256 = self._safe_balance_of(_token0, pool_fees)
token1_fees: uint256 = self._safe_balance_of(_token1, pool_fees)
gauge_alive: bool = staticcall lp_shared.voter.isAlive(gauge.address)
Expand Down Expand Up @@ -473,11 +465,11 @@ def _v2_lp(_data: address[4], _token0: address, _token1: address) -> Lp:
tick: 0,
sqrt_ratio: 0,

token0: token0.address,
token0: _token0,
reserve0: reserve0,
staked0: staked0,

token1: token1.address,
token1: _token1,
reserve1: reserve1,
staked1: staked1,

Expand All @@ -500,9 +492,7 @@ def _v2_lp(_data: address[4], _token0: address, _token1: address) -> Lp:
nfpm: empty(address),
alm: empty(address),

root: lp_shared._root_lp_address(
_data[0], token0.address, token1.address, type
)
root: lp_shared._root_lp_address(_data[0], _token0, _token1, type)
})

@external
Expand Down Expand Up @@ -958,8 +948,6 @@ def _cl_lp(_data: address[4], _token0: address, _token1: address) -> Lp:
fee_voting_reward: address = empty(address)
emissions: uint256 = 0
emissions_token: address = empty(address)
token0: IERC20 = IERC20(_token0)
token1: IERC20 = IERC20(_token1)
staked0: uint256 = 0
staked1: uint256 = 0
tick_spacing: int24 = staticcall pool.tickSpacing()
Expand Down Expand Up @@ -1006,11 +994,11 @@ def _cl_lp(_data: address[4], _token0: address, _token1: address) -> Lp:
tick: slot.tick,
sqrt_ratio: slot.sqrtPriceX96,

token0: token0.address,
token0: _token0,
reserve0: self._safe_balance_of(_token0, pool.address),
staked0: staked0,

token1: token1.address,
token1: _token1,
reserve1: self._safe_balance_of(_token1, pool.address),
staked1: staked1,

Expand All @@ -1033,9 +1021,7 @@ def _cl_lp(_data: address[4], _token0: address, _token1: address) -> Lp:
nfpm: _data[3],
alm: alm_addresses[1],

root: lp_shared._root_lp_address(
_data[0], token0.address, token1.address, tick_spacing
),
root: lp_shared._root_lp_address(_data[0], _token0, _token1, tick_spacing),
})

@internal
Expand Down
2 changes: 1 addition & 1 deletion env.optimism
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GOVERNOR_10=0x1F82e10D58aEf03DeA2e478029fB0387A1cbE989
TEST_ADDRESS_10=0x892ff98a46e5bd141e2d12618f4b2fe6284debac
TEST_ALM_ADDRESS_10=0x892ff98a46e5bd141e2d12618f4b2fe6284debac

LP_SUGAR_ADDRESS_10=0x54F8968CC76ECB17018E44049FdcC14ff833fa67
LP_SUGAR_ADDRESS_10=0x4edB8d7DEdf4C5Bc63fe2704Cc83166895905719
REWARDS_SUGAR_ADDRESS_10=0x62CCFB2496f49A80B0184AD720379B529E9152fB
VE_SUGAR_ADDRESS_10=0x94f913362b232e31daB49a1aFB775cfd25DaA6a1
RELAY_SUGAR_ADDRESS_10=0xb8307e5842B9aeE75C704183F0355076aa74b4e2
16 changes: 16 additions & 0 deletions tests/test_lp_sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ def test_tokens(sugar_contract, TokenStruct, LpStruct):
assert token1.token_address == first_lp.token1


@pytest.mark.skipif(int(CHAIN_ID) not in [10], reason="Only OP")
def test_tokens_long_symbol(sugar_contract, TokenStruct, LpStruct):
tokens = list(map(
lambda _p: TokenStruct(*_p),
sugar_contract.tokens(1, 995, ADDRESS_ZERO, [])
))

assert tokens is not None
assert len(tokens) > 1

token = tokens[0]

assert token.symbol is not None
assert token.symbol == '-???-'


def test_all(sugar_contract, LpStruct):
first_lp = LpStruct(*sugar_contract.byIndex(0))
second_lp = LpStruct(*sugar_contract.byIndex(1))
Expand Down

0 comments on commit c4ba768

Please sign in to comment.