From 606f22c423d43853ea0dff511c4d37370c1f3d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stas=20SU=C8=98COV?= Date: Tue, 17 Dec 2024 16:22:49 +0000 Subject: [PATCH] LpSugar: _safe_symbol max len. --- contracts/LpSugar.vy | 11 ++++++----- env.base | 2 +- env.optimism | 2 +- tests/test_lp_sugar.py | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/contracts/LpSugar.vy b/contracts/LpSugar.vy index f49bf73..9df5eca 100644 --- a/contracts/LpSugar.vy +++ b/contracts/LpSugar.vy @@ -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: @@ -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 @@ -83,7 +84,7 @@ struct SwapLp: struct Lp: lp: address - symbol: String[30] + symbol: String[MAX_TOKEN_SYMBOL_LEN] decimals: uint8 liquidity: uint256 @@ -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 @@ -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 "-???-" diff --git a/env.base b/env.base index f5dfc61..5b1c8d7 100644 --- a/env.base +++ b/env.base @@ -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 diff --git a/env.optimism b/env.optimism index d38218e..ce11781 100644 --- a/env.optimism +++ b/env.optimism @@ -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 diff --git a/tests/test_lp_sugar.py b/tests/test_lp_sugar.py index ff2fd49..4a35ff4 100644 --- a/tests/test_lp_sugar.py +++ b/tests/test_lp_sugar.py @@ -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(