UNPKG

@dojima-wallet/connection

Version:

Initialise and connection for layer 1&2 blockchain

239 lines (237 loc) 8.4 kB
import { Balance, Fees, Network, Tx } from "../client"; import { Address, Asset, BaseAmount } from "@dojima-wallet/utils"; import { Signer, ethers, providers } from "ethers"; import { ETHTransactionInfo, EthNetwork, FeesWithGasPricesAndLimits, GasPrices, TokenBalance, TokenTransactionInfo, TransactionInfo, TransactionOperation } from "./types"; export declare const ETHPLORER_FREEKEY = "freekey"; export declare const SIMPLE_GAS_COST: ethers.BigNumber; export declare const BASE_TOKEN_GAS_COST: ethers.BigNumber; export declare const DEFAULT_GAS_PRICE = 50; export declare const ETHAddress = "0x0000000000000000000000000000000000000000"; export declare const MAX_APPROVAL: ethers.BigNumber; /** * Network -> EthNetwork * * @param {Network} network * @returns {EthNetwork} */ export declare const chainNetworkToEths: (network: Network) => EthNetwork; /** * EthNetwork -> Network * * @param {EthNetwork} network * @returns {Network} */ export declare const ethNetworkTochains: (network: EthNetwork) => Network; /** * Validate the given address. * * @param {Address} address * @returns {boolean} `true` or `false` */ export declare const validateAddress: (address: Address) => boolean; /** * Get token address from asset. * * @param {Asset} asset * @returns {Address|null} The token address. */ export declare const getTokenAddress: (asset: Asset) => Address | null; /** * Checks whether an `Asset` is `AssetETH` or not * * @param {Asset} asset * @returns {boolean} Result of check if an asset is ETH or not */ export declare const isEthAsset: (asset: Asset) => boolean; /** * Parses asset address from `Asset` * * @param {Asset} asset * @returns {Address|null} Asset address */ export declare const getAssetAddress: (asset: Asset) => Address | null; /** * Check if the symbol is valid. * * @param {string|null|undefined} symbol * @returns {boolean} `true` or `false`. */ export declare const validateSymbol: (symbol?: string | null) => boolean; /** * Get transactions from token tx * * @param {TokenTransactionInfo} tx * @returns {Tx|null} The parsed transaction. */ export declare const getTxFromTokenTransaction: (tx: TokenTransactionInfo) => Tx | null; /** * Get transactions from ETH transaction * * @param {ETHTransactionInfo} tx * @returns {Tx} The parsed transaction. */ export declare const getTxFromEthTransaction: (tx: ETHTransactionInfo) => Tx; /** * Get transactions from operation * * @param {TransactionOperation} operation * @returns {Tx|null} The parsed transaction. */ export declare const getTxFromEthplorerTokenOperation: (operation: TransactionOperation) => Tx | null; /** * Get transactions from ETH transaction * * @param {TransactionInfo} txInfo * @returns {Tx} The parsed transaction. */ export declare const getTxFromEthplorerEthTransaction: (txInfo: TransactionInfo) => Tx; /** * Calculate fees by multiplying . * * @returns {Fees} The default gas price. */ export declare const getFee: ({ gasPrice, gasLimit, }: { gasPrice: BaseAmount; gasLimit: ethers.BigNumber; }) => { type: import("@dojima-wallet/utils").Denomination.Base; amount: () => import("bignumber.js").BigNumber; plus: (value: any | import("bignumber.js").BigNumber.Value, decimal?: number) => any; minus: (value: any | import("bignumber.js").BigNumber.Value, decimal?: number) => any; times: (value: any | import("bignumber.js").BigNumber.Value, decimal?: number) => any; div: (value: any | import("bignumber.js").BigNumber.Value, decimal?: number) => any; gt: (value: any | import("bignumber.js").BigNumber.Value) => boolean; gte: (value: any | import("bignumber.js").BigNumber.Value) => boolean; lt: (value: any | import("bignumber.js").BigNumber.Value) => boolean; lte: (value: any | import("bignumber.js").BigNumber.Value) => boolean; eq: (value: any | import("bignumber.js").BigNumber.Value) => boolean; decimal: number; }; export declare const estimateDefaultFeesWithGasPricesAndLimits: (asset?: Asset) => FeesWithGasPricesAndLimits; /** * Get the default fees. * * @returns {Fees} The default gas price. */ export declare const getDefaultFees: (asset?: Asset) => Fees; /** * Get the default gas price. * * @returns {Fees} The default gas prices. */ export declare const getDefaultGasPrices: (asset?: Asset) => GasPrices; /** * Get address prefix based on the network. * * @returns {string} The address prefix based on the network. * **/ export declare const getPrefix: () => string; /** * Filter self txs * * @returns {T[]} * **/ export declare const filterSelfTxs: <T extends { from: string; to: string; hash: string; }>(txs: T[]) => T[]; /** * Returns approval amount * * If given amount is not set or zero, `MAX_APPROVAL` amount is used */ export declare const getApprovalAmount: (amount?: BaseAmount) => ethers.BigNumber; /** * Call a contract function. * * @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 result of the contract function call. */ export declare const estimateCall: ({ provider, contractAddress, abi, funcName, funcParams, }: { provider: providers.Provider; contractAddress: Address; abi: ethers.ContractInterface; funcName: string; funcParams?: unknown[]; }) => Promise<ethers.BigNumber>; /** * Calls a contract function. * * @param {Provider} provider Provider to interact with the contract. * @param {signer} 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 {T} The result of the contract function call. */ export declare const call: <T>({ provider, signer, contractAddress, abi, funcName, funcParams, }: { provider: providers.Provider; signer?: Signer; contractAddress: Address; abi: ethers.ContractInterface; funcName: string; funcParams?: unknown[]; }) => Promise<T>; /** * Estimate gas for calling `approve`. * * @param {Provider} provider 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 {BaseAmount} amount (optional) The amount of token. By default, it will be unlimited token allowance. * * @returns {BigNumber} Estimated gas */ export declare const estimateApprove: ({ provider, contractAddress, spenderAddress, fromAddress, abi, amount, }: { provider: providers.Provider; contractAddress: Address; spenderAddress: Address; fromAddress: Address; abi: ethers.ContractInterface; amount?: BaseAmount; }) => Promise<ethers.BigNumber>; /** * Get Decimals * * @param {Asset} asset * @returns {Number} the decimal of a given asset * * @throws {"Invalid asset"} Thrown if the given asset is invalid */ export declare const getDecimal: (asset: Asset, provider: providers.Provider) => Promise<number>; /** * Check allowance. * * @param {Provider} provider 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 {boolean} `true` or `false`. */ export declare const isApproved: ({ provider, contractAddress, spenderAddress, fromAddress, amount, }: { provider: providers.Provider; contractAddress: Address; spenderAddress: Address; fromAddress: Address; amount?: BaseAmount; }) => Promise<boolean>; /** * Get Token Balances * * @param {TokenBalance[]} tokenBalances * @returns {Balance[]} the parsed balances * */ export declare const getTokenBalances: (tokenBalances: TokenBalance[]) => Balance[];