MCPcopy Create free account
hub / github.com/cardstack/cardstack / fetchTokenSymbol

Function fetchTokenSymbol

packages/cardpay-subgraph/src/utils.ts:202–227  ·  view source on GitHub ↗
(tokenAddress: Address)

Source from the content-addressed store, hash-verified

200}
201
202function fetchTokenSymbol(tokenAddress: Address): string {
203 let staticToken = StaticToken.fromAddress(tokenAddress);
204 if (staticToken != null) {
205 return (staticToken as StaticToken).symbol;
206 }
207
208 let contract = ERC20.bind(tokenAddress);
209 let contractSymbolBytes = ERC20SymbolBytes.bind(tokenAddress);
210
211 // try types string and bytes32 for symbol
212 let symbolValue = 'unknown';
213 let symbolResult = contract.try_symbol();
214 if (symbolResult.reverted) {
215 let symbolResultBytes = contractSymbolBytes.try_symbol();
216 if (!symbolResultBytes.reverted) {
217 // for token that has no symbol function exposed
218 if (!isNullEthValue(symbolResultBytes.value.toHexString())) {
219 symbolValue = symbolResultBytes.value.toString();
220 }
221 }
222 } else {
223 symbolValue = symbolResult.value;
224 }
225
226 return symbolValue;
227}
228
229function fetchTokenName(tokenAddress: Address): string {
230 let staticToken = StaticToken.fromAddress(tokenAddress);

Callers 1

makeTokenFunction · 0.85

Calls 2

isNullEthValueFunction · 0.85
fromAddressMethod · 0.80

Tested by

no test coverage detected