Utils

xchainNetworkToEths

Network -> EthNetwork

Parameters

  • network Network

Returns EthNetwork

ethNetworkToXchains

EthNetwork -> Network

Parameters

  • network EthNetwork

Returns Network

validateAddress

Validate the given address.

Parameters

  • address Address

Returns boolean true or false

getTokenAddress

Get token address from asset.

Parameters

  • asset Asset

Returns (Address | null) The token address.

isEthAsset

Checks whether an Asset is AssetETH or not

Parameters

  • asset Asset

Returns boolean Result of check if an asset is ETH or not

getAssetAddress

Parses asset address from Asset

Parameters

  • asset Asset

Returns (Address | null) Asset address

validateSymbol

Check if the symbol is valid.

Parameters

Returns boolean true or false.

getTxFromTokenTransaction

Get transactions from token tx

Parameters

  • tx TokenTransactionInfo

Returns (Tx | null) The parsed transaction.

getTxFromEthTransaction

Get transactions from ETH transaction

Parameters

  • tx ETHTransactionInfo

Returns Tx The parsed transaction.

getTxFromEthplorerTokenOperation

Get transactions from operation

Parameters

  • operation TransactionOperation

Returns (Tx | null) The parsed transaction.

getTxFromEthplorerEthTransaction

Get transactions from ETH transaction

Parameters

  • txInfo TransactionInfo

Returns Tx The parsed transaction.

getFee

Calculate fees by multiplying .

Parameters

  • $0 Object
    • $0.gasPrice
    • $0.gasLimit

Returns Fees The default gas price.

getDefaultFees

Get the default fees.

Parameters

  • asset

Returns Fees The default gas price.

getDefaultGasPrices

Get the default gas price.

Parameters

  • asset

Returns Fees The default gas prices.

getPrefix

Get address prefix based on the network.

Returns string The address prefix based on the network.*

filterSelfTxs

Filter self txs

Parameters

  • txs

Returns Array<T> *

getApprovalAmount

Returns approval amount

If given amount is not set or zero, MAX_APPROVAL amount is used

Parameters

  • amount

estimateCall

Call a contract function.

Parameters

  • $0 Object
    • $0.provider
    • $0.contractAddress
    • $0.abi
    • $0.funcName
    • $0.funcParams (optional, default [])
  • provider Provider Provider to interact with the contract.
  • contractAddress Address The contract address.
  • abi ContractInterface The contract ABI json.
  • funcName string The function to be called.
  • funcParams Array<unknown> The parameters of the function.

Returns BigNumber The result of the contract function call.

call

Calls a contract function.

Parameters

  • $0 Object
    • $0.provider
    • $0.signer
    • $0.contractAddress
    • $0.abi
    • $0.funcName
    • $0.funcParams (optional, default [])
  • provider Provider Provider to interact with the contract.
  • Signer signer of the transaction (optional - needed for sending transactions only)
  • contractAddress Address The contract address.
  • abi ContractInterface The contract ABI json.
  • funcName string The function to be called.
  • funcParams Array<unknow> (optional) The parameters of the function.

Returns T The result of the contract function call.

estimateApprove

Estimate gas for calling approve.

Parameters

  • $0 Object
    • $0.provider
    • $0.contractAddress
    • $0.spenderAddress
    • $0.fromAddress
    • $0.abi
    • $0.amount
  • provider Provider Provider to interact with the contract.
  • contractAddress Address The contract address.
  • spenderAddress Address The spender address.
  • fromAddress Address The address a transaction is sent from.
  • amount BaseAmount (optional) The amount of token. By default, it will be unlimited token allowance.

Returns BigNumber Estimated gas

getDecimal

Get Decimals

Parameters

  • asset Asset
  • provider

  • Throws "Invalid asset" Thrown if the given asset is invalid

Returns Number the decimal of a given asset

isApproved

Check allowance.

Parameters

  • $0 Object
    • $0.provider
    • $0.contractAddress
    • $0.spenderAddress
    • $0.fromAddress
    • $0.amount
  • provider Provider Provider to interact with the contract.
  • contractAddress Address The contract (ERC20 token) address.
  • spenderAddress Address The spender address (router).
  • fromAddress Address The address a transaction is sent from.
  • amount BaseAmount The amount to check if it's allowed to spend or not (optional).
  • walletIndex number (optional) HD wallet index

Returns boolean true or false.

getTokenBalances

Get Token Balances

Parameters

  • tokenBalances Array<TokenBalance>

Returns Array<Balance> the parsed balances