@broxus/js-bridge-essentials
Version:
Bridge JavaScript Essentials library
36 lines (35 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenRootAlienEvmUtils = void 0;
const js_core_1 = require("@broxus/js-core");
const bignumber_js_1 = require("bignumber.js");
const contracts_1 = require("../../models/token-root-alien-evm/contracts");
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 (0, js_core_1.getFullContractState)(connection, tokenAddress);
const result = await (0, contracts_1.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${(0, bignumber_js_1.BigNumber)(result.base_token).toString(16).padStart(40, '0')}`,
name: result.name,
symbol: result.symbol,
};
}
}
exports.TokenRootAlienEvmUtils = TokenRootAlienEvmUtils;