(tokenAddress: Address)
| 227 | } |
| 228 | |
| 229 | function fetchTokenName(tokenAddress: Address): string { |
| 230 | let staticToken = StaticToken.fromAddress(tokenAddress); |
| 231 | if (staticToken != null) { |
| 232 | return (staticToken as StaticToken).name; |
| 233 | } |
| 234 | let contract = ERC20.bind(tokenAddress); |
| 235 | let contractNameBytes = ERC20NameBytes.bind(tokenAddress); |
| 236 | |
| 237 | // try types string and bytes32 for name |
| 238 | let nameValue = 'unknown'; |
| 239 | let nameResult = contract.try_name(); |
| 240 | if (nameResult.reverted) { |
| 241 | let nameResultBytes = contractNameBytes.try_name(); |
| 242 | if (!nameResultBytes.reverted) { |
| 243 | // for token that has no name function exposed |
| 244 | if (!isNullEthValue(nameResultBytes.value.toHexString())) { |
| 245 | nameValue = nameResultBytes.value.toString(); |
| 246 | } |
| 247 | } |
| 248 | } else { |
| 249 | nameValue = nameResult.value; |
| 250 | } |
| 251 | |
| 252 | return nameValue; |
| 253 | } |
| 254 | |
| 255 | export function fetchTokenDecimals(tokenAddress: Address): BigInt { |
| 256 | let staticToken = StaticToken.fromAddress(tokenAddress); |
no test coverage detected