import {IChains, ITxDetails, ITxList, ITxListParams} from "../chains"; import {IReturnResult} from "../../config"; import {BigNumber} from "@ethersproject/bignumber"; export interface IEthereum extends IChains { // 获取 ethers.js utils方法 readonly getUtils: () => any // 获取手续费 readonly getFee: (gasLimit: string, gasPrice: string) => string // 获取 手续费列表 readonly getFeeList: (from: string, to: string, params?: IFeeParams) => Promise> readonly getCountFee: (from: string, to: string, contract: string | undefined, tokenId?: string) => Promise> // 转换正常金额 readonly formatUnits: (value: BigNumber, decimals: number) => string // 转换bignumber金额 readonly parseUnits: (value: string, decimals: number) => BigNumber // 获取正常地址 readonly getNormalAddress: (address: string) => string // 获取 provider readonly getProvider: () => any // 获取 walletProvider readonly getWallet: (privateKey: string) => any // 获取合约 readonly getContract: (address: string, abi: string, provider?: any) => any // 获取Pending交易记录 readonly getPendingTxList: (address: string, params?: ITxListParams) => Promise> // 签名交易 readonly signTransaction: (privateKey: string, params: IEthereumSignTransactionParams) => Promise> // 签名消息 readonly signMessage: (privateKey: string, msgData: string) => Promise> // 签名typed消息 readonly signTypedMessage: (privateKey: string, object: { data: string, raw: string }) => IReturnResult // 签名个人消息 readonly signPersonalMessage: (privateKey: string, msgData: string) => Promise> // 获取地址授权额度 readonly getAllowance: (address: string, exchangeAddress: string, contractAddress: string, abi: string) => Promise> // 签名授权额度 readonly signApprove: (privateKey: string, exchangeAddress: string, contractAddress: string, abi: string, value?: string) => Promise> readonly getTokenList: (address: string) => Promise> readonly getErc721Contract: (contractAddress: string, provider?: any) => any readonly getErc721Details: (contractAddress: string) => Promise> readonly getErc721DataByAccount: (contractAddress: string, address: string) => Promise> readonly getErc721TokenURI: (contractAddress: string, tokenId: number) => Promise> // readonly signErc721:() // swap readonly swap: ISwap // readonly erc721: IErc721 // api 方法 readonly api: IApi // rpc 方法 readonly rpc: IRpc } export type TokenData = { readonly balance: string readonly contractAddress: string readonly decimals: string readonly name: string readonly symbol: string readonly type: 'ERC-20' | 'ERC-721' } // swap export interface ISwap { /** * 判断pair是否存在 * @param factoryAddress 工厂合约地址 * @param factoryAbi 工厂合约abi * @param fromTokenAddress from 合约地址 * @param toTokenAddress to 合约地址 */ readonly hasPair: (factoryAddress: string, factoryAbi: string, fromTokenAddress: string, toTokenAddress: string) => Promise // /** // * 授权swap转账 // * @param privateKey 私钥 // * @param value 金额 // * @param decimals 小数位 // * @param exchange 交易所地址 // * @param exchangeAbi 交易所abi // * @param fromToken from 合约 // * @param toToken to 合约 // */ // readonly signApprove: (privateKey: string, value: string, decimals: number, exchangeAddress: string, exchangeAbi: string, fromToken: string, toToken: string) => Promise /** * 根据转出金额,获取精确的转入金额 * @param routerAddress router 合约地址 * @param routerAbi router abi * @param fromTokenAddress from 合约地址 * @param toTokenAddress to 合约地址 * @param toValue to 转出金额 * @param fromDecimals from 小数位 * @param toDecimals to 小数位 */ readonly getAmountsIn: (routerAddress: string, routerAbi: string, fromTokenAddress: string, toTokenAddress: string, toValue: string, fromDecimals: number, toDecimals: number) => Promise /** * 根据转入金额,获取精确的转出金额 * @param routerAddress router 合约地址 * @param routerAbi router abi * @param fromTokenAddress from 合约地址 * @param toTokenAddress to 合约地址 * @param fromValue from 转入金额 * @param fromDecimals from 小数位 * @param toDecimals to 小数位 */ readonly getAmountsOut: (routerAddress: string, routerAbi: string, fromTokenAddress: string, toTokenAddress: string, fromValue: string, fromDecimals: number, toDecimals: number) => Promise } // api 方法 export interface IApi { // 获取交易记录 pending getPendingTxList: (address: string) => Promise // 获取交易记录 internal getInternalList: (address: string, size: number, page: number) => Promise // 获取交易记录 getTxList: (address: string, size: number, page: number) => Promise // 获取合约交易记录 getContractTxList: (address: string, contract: string, size: number, page: number) => Promise // 根据address 获取全部token getAllToken: (address: string) => Promise } // rpc 方法 export interface IRpc { getCall: (params: { [key: string]: string }) => Promise // 发送交易 sendTransaction: (value: string) => Promise // 获取 block getBlockNumber: () => Promise // 获取 chainId getChainId: () => Promise // 获取 gasLimit getGasLimit: (params: { [key: string]: string }) => Promise // 获取 gasPrice getGasPrice: () => Promise // 获取余额 getBalance: (address) => Promise // 根据hash获取tx数据 getTransactionByHash: (hash: string) => Promise // 根据hash获取交易数据 getTransactionReceipt: (hash: string) => Promise // 获取 nonce getNonce: (address: string) => Promise // 获取 pending nonce getPendingNonce: (address: string) => Promise } // eth SignTransaction params export type IEthereumSignTransactionParams = { from?: string to: string value?: string gasLimit?: string gasPrice?: string data?: string nonce?: number } interface IEthereumTxDetails extends ITxDetails { token: IEthereumTxDetailsToken[], } interface IEthereumTxDetailsToken { name: string, from: string, to: string, value: string, symbol: string, } interface IFeeResult { gasPrice: string gasLimit: string fee: string } export type IFeeParams = { readonly contract?: string decimals?: number tokenId?: number }