UNPKG

@xchainjs/xchain-evm

Version:
163 lines (162 loc) 6.33 kB
import { Address, BaseAmount, TokenAsset } from '@xchainjs/xchain-util'; import { Signer, Contract, Provider, InterfaceAbi } from 'ethers'; import BigNumber from 'bignumber.js'; /** * Maximum approval amount possible, set to 2^256 - 1. */ export declare const MAX_APPROVAL: BigNumber; /** * Validate the given address. * * @param {Address} address The address to validate. * @returns {boolean} `true` if the address is valid, otherwise `false`. */ export declare const validateAddress: (address: Address) => boolean; /** * Get token address from asset. * * @param {TokenAsset} asset The asset to extract the token address from. * @returns {Address|null} The token address if found, otherwise `null`. */ export declare const getTokenAddress: (asset: TokenAsset) => Address | null; /** * Check if the symbol is valid. * * @param {string|null|undefined} symbol The symbol to validate. * @returns {boolean} `true` if the symbol is valid and has a length of at least 3, otherwise `false`. */ export declare const validateSymbol: (symbol?: string | null) => boolean; /** * Calculate fees by multiplying gas price and gas limit. * * @returns {Fees} The calculated fee. */ export declare const getFee: ({ gasPrice, gasLimit, decimals, }: { gasPrice: BaseAmount; gasLimit: BigNumber; decimals: number; }) => BaseAmount; /** * Get address prefix based on the network. * * @returns {string} The address prefix based on the network ('0x'). */ export declare const getPrefix: () => string; /** * Filter self transactions from an array of transactions. * * @param {T[]} txs The transactions array. * @returns {T[]} The filtered transactions array with self transactions removed. */ export declare const filterSelfTxs: <T extends { from: string; to: string; hash: string; }>(txs: T[]) => T[]; /** * Returns approval amount. If amount is not set or zero, returns `MAX_APPROVAL`. * * @param {BaseAmount} amount The amount to check. * @returns {ethers.BigNumber} The approval amount. */ export declare const getApprovalAmount: (amount?: BaseAmount) => BigNumber; /** * Estimate gas required for calling a contract function. * * @param {object} params Parameters for estimating gas. * @param {Provider} provider Provider to interact with the contract. * @param {Address} contractAddress The contract address. * @param {ContractInterface} abi The contract ABI json. * @param {string} funcName The function to be called. * @param {unknown[]} funcParams The parameters of the function. * @returns {BigNumber} The estimated gas required for the function call. */ export declare const estimateCall: ({ provider, contractAddress, abi, funcName, funcParams, }: { provider: Provider; contractAddress: Address; abi: InterfaceAbi; funcName: string; funcParams?: unknown[]; }) => Promise<BigNumber>; /** * Calls a contract function. * * @param {Provider} provider The provider to interact with the contract. * @param {Signer} signer The signer of the transaction (optional - needed for sending transactions only). * @param {Address} contractAddress The contract address. * @param {ContractInterface} abi The contract ABI json. * @param {string} funcName The function to be called. * @param {unknown[]} funcParams (optional) The parameters of the function. * @returns {Promise<T>} The result of the contract function call. */ export declare const call: <T>({ provider, signer, contractAddress, abi, funcName, funcParams, }: { provider: Provider; signer?: Signer; contractAddress: Address; abi: InterfaceAbi; funcName: string; funcParams?: unknown[]; }) => Promise<T>; /** * Load a contract. * * @param {Provider} provider The provider to interact with the contract. * @param {Address} contractAddress The contract address. * @param {ContractInterface} abi The contract ABI json. * @returns {Promise<ethers.Contract>} The loaded contract instance. */ export declare const getContract: ({ provider, contractAddress, abi, }: { provider: Provider; contractAddress: Address; abi: InterfaceAbi; }) => Promise<Contract>; /** * Estimate gas for calling `approve`. * * @param {Provider} provider The provider to interact with the contract. * @param {Address} contractAddress The contract address. * @param {Address} spenderAddress The spender address. * @param {Address} fromAddress The address a transaction is sent from. * @param {ContractInterface} abi The contract ABI json. * @param {BaseAmount} amount (optional) The amount of token. By default, it will be unlimited token allowance. * @returns {Promise<ethers.BigNumber>} The estimated gas. */ export declare function estimateApprove({ provider, contractAddress, spenderAddress, fromAddress, abi, amount, }: { provider: Provider; contractAddress: Address; spenderAddress: Address; fromAddress: Address; abi: InterfaceAbi; amount?: BaseAmount; }): Promise<BigNumber>; /** * Check allowance. * * @param {Provider} provider The provider to interact with the contract. * @param {Address} contractAddress The contract (ERC20 token) address. * @param {Address} spenderAddress The spender address (router). * @param {Address} fromAddress The address a transaction is sent from. * @param {BaseAmount} amount The amount to check if it's allowed to spend or not (optional). * @param {number} walletIndex (optional) HD wallet index * @returns {Promise<boolean>} `true` if the spender is allowed to spend the specified amount, `false` otherwise. */ export declare function isApproved({ provider, contractAddress, spenderAddress, fromAddress, amount, }: { provider: Provider; contractAddress: Address; spenderAddress: Address; fromAddress: Address; amount?: BaseAmount; }): Promise<boolean>; /** * Removes `0x` or `0X` from the beginning of the address string. * * @param {Address} addr The address to remove the `0x` or `0X` prefix from. * @returns {string} The address without the `0x` or `0X` prefix. */ export declare const strip0x: (addr: Address) => string; /** * Get the chain identifier the provider is connected with * @param {Provider} provider Provider * @returns {number} the chain identifier the provider is connected with */ export declare const getNetworkId: (provider: Provider) => Promise<number>;