@broxus/js-bridge-essentials
Version:
Bridge JavaScript Essentials library
29 lines (28 loc) • 1.32 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';
import { resolveSolanaAddress } from '../../utils';
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 });
const hex = BigNumber(result.base_token).toString(16).padStart(64, '0');
const buffer = Buffer.from(hex, 'hex');
return {
baseToken: result.base_token,
decimals: result.decimals,
name: result.name,
solTokenAddress: resolveSolanaAddress(bs58.encode(buffer)),
symbol: result.symbol,
};
}
}