import { Connection } from "@celo/connect"; import { Bip39 } from "@celo/utils/lib/account"; import { Interface } from "@ethersproject/abi"; import BigNumber from "bignumber.js"; import PromiEvent from "promievent"; import Web3 from "web3"; import { Sign } from "web3-core"; import { TransactionConfig, TransactionReceipt } from "web3-eth"; import { Mixed } from "web3-utils"; import { PaymentRequest } from "../PaymentRequest/PaymentRequest"; import { TokenAmount } from "../Tokens"; import { Token } from "../Tokens/Token"; import { TokenTransactionBase } from "../Transactions/types"; import { Address, ChainId, CustomRPC, Interval, PageInfo, TimeFrame, TransactionOptions } from "../constants"; export interface WalletConfig { eoa?: Address; smartWallet?: Address; mnemonic?: string; getMnemonic?: () => Promise; privateKey?: string; getPrivateKey?: () => Promise; bip39?: Bip39; } export interface NodeWalletTransaction { target: string; data: string; description: string; gasEst: number; } export interface ContractTransaction { target: string; contractInterface: Interface; method: string; params?: any[]; } export interface WalletOptions { defaultGasToken?: Address; customRpc?: CustomRPC; } /** * Representation of a wallet * * Can sign and send transactions. */ export declare abstract class Wallet { address: string | undefined; homeChain: ChainId; rpc?: CustomRPC; web3: Web3; getMnemonic: (() => Promise) | undefined; private apiKey; feeCurrency?: Address; connection?: Connection; wid?: number; /** * * @param apiKey string, API key required to authenticate payloads * @param homeChain homechain for the wallet. Default is Celo for now * @param address address of the wallet. EOA or smart wallet */ constructor(apiKey?: string, homeChain?: ChainId, address?: string, options?: WalletOptions); /** * * @param getTokens Callback to fetch a token given its address * @param opts Page options and currency code options * @returns List of transactions for the wallet, additionally with local value transacted */ getHistoricalTransactions(getTokens: (address: string) => Token, opts?: { page?: number; perPage?: number; localCurrencyCode?: string; }): Promise; /** * Registers the wallet with the Node Finance Wallet Service. * * Will return error if wallet is already registered */ register(): Promise; /** * * Fetches details on the wallet from the Node Finace wallet service. Includes metadata set by developer. * * @returns Wallet object */ fetchFromWalletService(): Promise; /** * * Sends a token from this wallet to any other address. * * @param token Token to send * @param amount Amount to send * @param recipient Recipient of transfer * @returns Receipt of transaction of sending the token */ transferToken(token: Token | Address, amount: BigNumber, recipient: Address): Promise; /** * * Set the default gas currency. Only applicable on Celo and Alfajores, otherwise will fail * * @param tokenAddress Token address to use to pay gas fees. */ setFeeCurrency(tokenAddress: Address): void; /** * * @param data Data and type definitions to sign * @returns Signature payload */ signTypedData(data: Mixed[]): Sign; /** * * Handles repaying a portion, or all of, a payment request. * * @param request PaymentRequest object to fulfill * @param amount The total token amount to pay towards this payment request. Does not have to equal the remaining amount. * @returns Request after crediting payment, and receipt of payment */ fulfillPaymentRequest = Record>(request: PaymentRequest, amount: TokenAmount): PromiEvent<{ request: PaymentRequest; receipt: { amountCredited: TokenAmount; isFullyRepaid: boolean; hash: string; rid: number; time: number; }; }>; /** * * Authenticates and creates a new payment request * * @param from Address to request payment from * @param amount Token and amount to request * @param deadline Optional date that payment must be fulfilled * @param metadata Additional metadata to store regarding the request * @returns PaymentRequest object corresponding to the newly-created request */ requestPayment>(from: string, amount: TokenAmount, deadline?: Date, metadata?: T): Promise>; /** * * Fetches payment requests for a wallet. Can fetch pending, completed, or all. Default pagination is page 0, * with 10 per page. * * @param getToken Callback to fetch a token given its address * @param opts Options for the query, including request type, page, and count per page * @returns List of payment requests for the wallet */ fetchPaymentRequests>(getToken: (address: string) => Token, opts?: { type?: "pending" | "completed" | "all"; page?: number; count?: number; }): Promise<{ requests: PaymentRequest[]; pageInfo: PageInfo; }>; /** * * @param data Message to sign * @returns A Sign object, which contains all fields needed to recompute original signer, as well as the signed message */ abstract signMessage(data: string): Sign; /** * * @param attempt tracker to allow for re-attempts on server errors. * @returns true if success, false if unsuccessful */ syncBackendPortfolioValue(): Promise; /** * * Fetches the wallet's historical portfolio for a given time period of resolution. Portfolio value is given in the declared * currency code. * * @param interval time interval between ticks * @param timeframe timeframe on which to view historical portfolio value * @param currency base currency code for the query * @returns an array of portfolio values at specific times, where the time in between ticks corresponds to interval */ fetchBackendPortfolioValue(interval: Interval, timeframe: TimeFrame, currency?: string): Promise<{ total: number; time: number; }[] | undefined>; fetchPortfolioRaw(opts: { resolution?: Interval; startTime?: number; endTime?: number; chain?: number; currency?: string; }): Promise<{ total: number; time: number; }[]>; /** * * @param descriptions descriptions of transactions to sign and process * @returns transaction receipt from executed txn */ signAndSendContractTransactions(descriptions: ContractTransaction[], opts?: TransactionOptions): Promise; /** * * @param transactions transaction descriptions in a more readable format * @returns transaction receipt */ signAndSendNodeTransactions(transactions: NodeWalletTransaction[], opts?: TransactionOptions): Promise; /** * * @param config Configuration object specifying details about the wallet * @returns Boolean flag indicating successful wallet load */ abstract _loadWallet(config: WalletConfig): Promise; /** * * @param transaction web3js transaction objects to sign and process * @returns transaction receipt */ abstract signAndSendTransaction(transaction: TransactionConfig[], opts?: TransactionOptions): Promise; }