Skip to content

Commit

Permalink
feat: truncate symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
ethzoomer authored Nov 20, 2024
1 parent eeff98a commit efe9b6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions contracts/LpSugar.vy
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct Position:

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

struct Lp:
lp: address
symbol: String[128]
symbol: String[100]
decimals: uint8
liquidity: uint256

Expand Down Expand Up @@ -133,7 +133,7 @@ struct AlmManagedPositionInfo:

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

interface IPool:
Expand All @@ -148,7 +148,7 @@ interface IPool:
def index0() -> uint256: view
def index1() -> uint256: view
def totalSupply() -> uint256: view
def symbol() -> String[128]: view
def symbol() -> String[100]: view
def decimals() -> uint8: view
def stable() -> bool: view
def balanceOf(_account: address) -> uint256: view
Expand Down Expand Up @@ -1088,27 +1088,30 @@ def _safe_decimals(_token: address) -> uint8:

@internal
@view
def _safe_symbol(_token: address) -> String[128]:
def _safe_symbol(_token: address) -> String[100]:
"""
@notice Returns the `ERC20.symbol()` result safely
@param _token The token to call
"""
# >=192 input size is required by Vyper's _abi_decode()
response: Bytes[192] = b""
# Large input size is required by Vyper's _abi_decode()
response: Bytes[2048] = b""
response = raw_call(
_token,
method_id("symbol()"),
max_outsize=192,
max_outsize=2048,
gas=50000,
is_delegate_call=False,
is_static_call=True,
revert_on_failure=False
)[1]

# Check response as revert_on_failure is set to False
# String size cannot be larger than max_outsize - 64 bytes
if len(response) > 0 and len(response) <= 128:
return abi_decode(response, String[128])
# ABI decoded string size cannot be larger than Bytes size - 64 bytes
if len(response) > 0:
decoded_symbol: String[1984] = abi_decode(response, String[1984])
end: uint256 = min(100, len(decoded_symbol))
truncated_symbol: String[100] = convert(slice(decoded_symbol, 0, end), String[100])
return truncated_symbol

return "-NA-"

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=0x065CA8CD19367A7c9773BC563940a4c0016de0DE
LP_SUGAR_ADDRESS_10=0x54F8968CC76ECB17018E44049FdcC14ff833fa67
REWARDS_SUGAR_ADDRESS_10=0x62CCFB2496f49A80B0184AD720379B529E9152fB
VE_SUGAR_ADDRESS_10=0x94f913362b232e31daB49a1aFB775cfd25DaA6a1
RELAY_SUGAR_ADDRESS_10=0xb8307e5842B9aeE75C704183F0355076aa74b4e2
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Below is the list of datasets we support.

> [!NOTE]
> `LpSugar.vy` is deployed on:
> Optimism - `0x065CA8CD19367A7c9773BC563940a4c0016de0DE`
> Optimism - `0x54F8968CC76ECB17018E44049FdcC14ff833fa67`
> Base - `0x63a73829C74e936C1D2EEbE64164694f16700138`
It allows fetching on-chain pools data.
Expand Down

0 comments on commit efe9b6f

Please sign in to comment.