Skip to content

Commit

Permalink
LpSugar: _safe_symbol max len.
Browse files Browse the repository at this point in the history
  • Loading branch information
stas committed Dec 17, 2024
1 parent ffc81d4 commit 606f22c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
11 changes: 6 additions & 5 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ initializes: lp_shared
MAX_TOKENS: public(constant(uint256)) = 2000
MAX_LPS: public(constant(uint256)) = 500
MAX_POSITIONS: public(constant(uint256)) = 200
MAX_TOKEN_SYMBOL_LEN: public(constant(uint256)) = 32

# Slot0 from CLPool.sol
struct Slot:
Expand Down Expand Up @@ -68,7 +69,7 @@ struct Position:

struct Token:
token_address: address
symbol: String[30]
symbol: String[MAX_TOKEN_SYMBOL_LEN]
decimals: uint8
account_balance: uint256
listed: bool
Expand All @@ -83,7 +84,7 @@ struct SwapLp:

struct Lp:
lp: address
symbol: String[30]
symbol: String[MAX_TOKEN_SYMBOL_LEN]
decimals: uint8
liquidity: uint256

Expand Down Expand Up @@ -1073,7 +1074,7 @@ def _safe_decimals(_token: address) -> uint8:

@internal
@view
def _safe_symbol(_token: address) -> String[30]:
def _safe_symbol(_token: address) -> String[MAX_TOKEN_SYMBOL_LEN]:
"""
@notice Returns the `ERC20.symbol()` safely (max 30 chars)
@param _token The token to call
Expand All @@ -1092,9 +1093,9 @@ def _safe_symbol(_token: address) -> String[30]:
resp_len: uint256 = len(response)

# Check response as revert_on_failure is set to False
# And that the symbol size is not more than 10 chars (96 bytes)
# And that the symbol size is not some large value (probably spam)
if resp_len > 0 and resp_len <= 96:
return abi_decode(response, String[30])
return abi_decode(response, String[MAX_TOKEN_SYMBOL_LEN])

return "-???-"

Expand Down
2 changes: 1 addition & 1 deletion env.base
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST_FACTORY_ADDRESS_8453=0x5e7BB104d84c7CB9B682AaC2F3d509f5F406809A
TEST_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac
TEST_ALM_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac

LP_SUGAR_ADDRESS_8453=0x82dA79111A0C79639B7a4c6dc149283D103f1860
LP_SUGAR_ADDRESS_8453=0xF117AFbE285f867c67960F4bfEDe3121Cf6d8F76
REWARDS_SUGAR_ADDRESS_8453=0xA44600F4DBA6683d8BD99270B1A6a143fB9F1C3B
VE_SUGAR_ADDRESS_8453=0x4c5d3925fe65DFeB5A079485136e4De09cb664A5
RELAY_SUGAR_ADDRESS_8453=0x8932B5FE23C07Df06533F8f09E43e7cca6a24143
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=0xf01d04b0963a175Ac43D31C515A4397356cF74D8
LP_SUGAR_ADDRESS_10=0x191FF5F5EAC07b082ff877236E8e7537c2d9D2A7
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 @@ -108,6 +108,22 @@ def test_tokens_long_symbol(sugar_contract, TokenStruct):
assert token.symbol == '-???-'


@pytest.mark.skipif(int(CHAIN_ID) not in [8453], reason="Only BASE")
def test_tokens_max_long_symbol(sugar_contract, TokenStruct):
tokens = list(map(
lambda _p: TokenStruct(*_p),
sugar_contract.tokens(1, 2508, ADDRESS_ZERO, [])
))

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

token = tokens[0]

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


@pytest.mark.skipif(int(CHAIN_ID) not in [10], reason="Only OP")
def test_all_long_symbol(sugar_contract, LpStruct):
pools = list(map(
Expand Down

0 comments on commit 606f22c

Please sign in to comment.