UNPKG

@broxus/js-bridge-essentials

Version:

Bridge JavaScript Essentials library

32 lines (31 loc) 1.5 kB
import { getFullContractState } from '@broxus/js-core'; import BigNumber from 'bignumber.js'; import { tokenRootAlienEvmContract } from '../../models/token-root-alien-evm/contracts'; export class TokenRootAlienEvmUtils { /** * Get alien token meta by the given TVM-like token address * * - If request passed and `base_chainId` equal to target EVM network - it means token is alien * for TVM and native for target EVM network. * - If request failed, or passed, but `base_chainId` not equal to target EVM network - it * means token is native for TVM and alien for target EVM network * * @param {ProviderRpcClient} connection * @param {Address | string} tokenAddress * @param {FullContractState} [cachedState] - optional. Full contract state of the token root alien EVM contract */ static async meta(connection, tokenAddress, cachedState) { const state = cachedState ?? await getFullContractState(connection, tokenAddress); const result = await tokenRootAlienEvmContract(connection, tokenAddress) .methods.meta({ answerId: 0 }) .call({ cachedState: state, responsible: true }); return { baseChainId: result.base_chainId, baseToken: result.base_token, decimals: result.decimals, evmTokenAddress: `0x${BigNumber(result.base_token).toString(16).padStart(40, '0')}`, name: result.name, symbol: result.symbol, }; } }