Skip to main content
Helpful?

SafeCurrencyMetadata

Git Source - Generated with forge doc

can produce symbols and decimals from inconsistent or absent ERC20 implementations

Reference: https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/SafeERC20Namer.sol

State Variables

MAX_SYMBOL_LENGTH

uint8 constant MAX_SYMBOL_LENGTH = 12;

Functions

currencySymbol

attempts to extract the currency symbol. if it does not implement symbol, returns a symbol derived from the address

function currencySymbol(address currency, string memory nativeLabel) internal view returns (string memory);

Parameters

NameTypeDescription
currencyaddressThe currency address
nativeLabelstringThe native label

Returns

NameTypeDescription
<none>stringthe currency symbol

currencyDecimals

attempts to extract the token decimals, returns 0 if not implemented or not a uint8

function currencyDecimals(address currency) internal view returns (uint8);

Parameters

NameTypeDescription
currencyaddressThe currency address

Returns

NameTypeDescription
<none>uint8the currency decimals

bytes32ToString

function bytes32ToString(bytes32 x) private pure returns (string memory);

addressToSymbol

produces a symbol from the address - the first 6 hex of the address string in upper case

function addressToSymbol(address currencyAddress) private pure returns (string memory);

Parameters

NameTypeDescription
currencyAddressaddressthe address of the currency

Returns

NameTypeDescription
<none>stringthe symbol

callAndParseStringReturn

calls an external view contract method that returns a symbol, and parses the output into a string

function callAndParseStringReturn(address currencyAddress, bytes4 selector) private view returns (string memory);

Parameters

NameTypeDescription
currencyAddressaddressthe address of the currency
selectorbytes4the selector of the symbol method

Returns

NameTypeDescription
<none>stringthe symbol

truncateSymbol

truncates the symbol to the MAX_SYMBOL_LENGTH

assumes the string is already longer than MAX_SYMBOL_LENGTH (or the same)

function truncateSymbol(string memory str) internal pure returns (string memory);

Parameters

NameTypeDescription
strstringthe symbol

Returns

NameTypeDescription
<none>stringthe truncated symbol
Helpful?