@broxus/js-bridge-essentials
Version:
Bridge JavaScript Essentials library
26 lines (25 loc) • 1.19 kB
JavaScript
import { getFullContractState } from '@broxus/js-core';
import BigNumber from 'bignumber.js';
import bs58 from 'bs58';
import { tokenRootAlienSolanaContract } from '../../models/token-root-alien-solana/contracts';
export class TokenRootAlienSolanaUtils {
/**
* Get alien token meta by the given TVM-like token address
* @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 tokenRootAlienSolanaContract(connection, tokenAddress)
.methods.meta({ answerId: 0 })
.call({ cachedState: state, responsible: true });
return {
baseToken: result.base_token,
decimals: result.decimals,
name: result.name,
solTokenAddress: bs58.encode(Buffer.from(BigNumber(result.base_token).toString(16).padStart(64, '0'), 'hex')),
symbol: result.symbol,
};
}
}