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 4d2e291
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 5 additions & 4 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)) = 30

# Slot0 from CLPool.sol
struct Slot:
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)
if resp_len > 0 and resp_len <= 96:
return abi_decode(response, String[30])
# And that the symbol size is not some large value (probably spam)
if resp_len > 0 and resp_len <= MAX_TOKEN_SYMBOL_LEN:
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=0xECd02f59C82D713191b0CD6337c6F3a750a55d72
REWARDS_SUGAR_ADDRESS_8453=0xA44600F4DBA6683d8BD99270B1A6a143fB9F1C3B
VE_SUGAR_ADDRESS_8453=0x4c5d3925fe65DFeB5A079485136e4De09cb664A5
RELAY_SUGAR_ADDRESS_8453=0x8932B5FE23C07Df06533F8f09E43e7cca6a24143
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_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 4d2e291

Please sign in to comment.