UNPKG

raiden-ts

Version:

Raiden Light Client Typescript/Javascript SDK

183 lines (182 loc) 7.84 kB
import { Signer } from '@ethersproject/abstract-signer'; import type { BigNumber } from '@ethersproject/bignumber'; import type { Contract, ContractReceipt } from '@ethersproject/contracts'; import { JsonRpcProvider } from '@ethersproject/providers'; import type { Observable } from 'rxjs'; import type { RaidenAction } from './actions'; import { raidenSynced } from './actions'; import type { channelSettle } from './channels/actions'; import type { RaidenChannels } from './channels/state'; import { ChannelState } from './channels/state'; import type { PartialRaidenConfig } from './config'; import type { RaidenDatabase } from './db/types'; import { RaidenState } from './state'; import type { RaidenTransfer } from './transfers/state'; import type { Latest, RaidenEpicDeps } from './types'; import { ContractsInfo } from './types'; import type { UInt } from './utils/types'; import { Address } from './utils/types'; /** * Returns a [[Signer]] based on the `account` and `provider`. * Throws an exception if the `account` is not a valid address or private key. * * @param account - an account used for signing * @param provider - a provider * @param subkey - Whether to generate a subkey * @param subkeyOriginUrl - URL of the origin to generate a subkey for * @returns a [[Signer]] or [[Wallet]] that can be used for signing */ export declare const getSigner: (account: string | number | Signer, provider: JsonRpcProvider, subkey?: boolean, subkeyOriginUrl?: string) => Promise<{ signer: Signer; address: Address; main: { signer: Signer; address: Address; } | undefined; }>; /** * Provides a live stream of transfer documents containing transfer updates * If you want pagination, use [[getTransfers]] instead * * @param db - Database instance * @returns observable of sent and completed Raiden transfers */ export declare function initTransfers$(db: RaidenDatabase): Observable<RaidenTransfer>; /** * Transforms the redux channel state to [[RaidenChannels]] * * @param channels - RaidenState.channels * @returns Raiden public channels mapping */ export declare const mapRaidenChannels: (channels: RaidenState['channels']) => RaidenChannels; /** * Return signer & address to use for on-chain txs depending on subkey param * * @param deps - RaidenEpicDeps subset * @param deps.signer - Signer instance * @param deps.address - Own address * @param deps.main - Main signer/address, if any * @param subkey - Whether to prefer the subkey or the main key * @returns Signer & Address to use for on-chain operations */ export declare function chooseOnchainAccount({ signer, address, main, }: { signer: RaidenEpicDeps['signer']; address: RaidenEpicDeps['address']; main?: RaidenEpicDeps['main']; }, subkey?: boolean): { signer: Signer; address: Address; }; /** * Returns a contract instance with attached signer * * @param contract - Contract instance * @param signer - Signer to use on contract * @returns contract instance with signer */ export declare function getContractWithSigner<C extends Contract>(contract: C, signer: Signer): C; /** * Waits for receipt to have at least `confBlocks` confirmations; resolves immediately if already; * throws if it gets removed by a reorg. * * @param receipt - Receipt to wait for confirmation * @param deps - RaidenEpicDeps * @param deps.latest$ - Latest observable * @param deps.config$ - Config observable * @param deps.provider - Eth provider * @param confBlocks - Confirmation blocks, defaults to `config.confirmationBlocks` * @returns Promise to final blockNumber of transaction */ export declare function waitConfirmation(receipt: ContractReceipt, { latest$, config$, provider }: RaidenEpicDeps, confBlocks?: number): Promise<number>; /** * Resolves to our current UDC balance, as seen from [[monitorUdcBalanceEpic]] * * @param latest$ - Latest observable * @returns Promise to our current UDC balance */ export declare function getUdcBalance(latest$: Observable<Latest>): Promise<UInt<32>>; /** * @param action$ - Observable of RaidenActions * @returns Promise which resolves when Raiden is synced */ export declare function makeSyncedPromise(action$: Observable<RaidenAction>): Promise<raidenSynced['payload'] | undefined>; /** * @param deps - Epics dependencies * @param deps.log - Logger instance * @param deps.getTokenContract - Token contract factory/getter * @returns Memoized function to fetch token info */ export declare function makeTokenInfoGetter({ log, getTokenContract, }: Pick<RaidenEpicDeps, 'log' | 'getTokenContract'>): (token: string) => Promise<{ totalSupply: BigNumber; decimals: number; name?: string; symbol?: string; }>; /** * Loads state from `storageOrState`. Returns the initial [[RaidenState]] if * `storageOrState` does not exist. * * @param deps - Partial epics dependencies-like object * @param deps.provider - Provider instance * @param deps.address - current address of the signer * @param deps.network - current network * @param deps.log - Logger instance * @param contractsOrUDCAddress - ContractsInfo object or UDC address * @param storage - diverse storage related parameters to load from and save to * @param storage.state - Uploaded state: replaces database state; must be newer than database * @param storage.adapter - PouchDB adapter; default to 'indexeddb' on browsers and 'leveldb' on * node. If you provide a custom one, ensure you call PouchDB.plugin on it. * @param storage.prefix - Database name prefix; use to set a directory to store leveldown db; * @returns database and RaidenDoc object */ export declare function getState({ provider, address, network, log, }: Pick<RaidenEpicDeps, 'provider' | 'address' | 'network' | 'log'>, contractsOrUDCAddress?: ContractsInfo | string, storage?: { state?: any; adapter?: any; prefix?: string; }): Promise<{ db: RaidenDatabase; state: RaidenState; }>; declare const settleableStates: readonly [ChannelState.settleable, ChannelState.settling]; /** * Waits for channel to become settleable * * Errors if channel doesn't exist or isn't closed, settleable or settling (states which precede * or are considered settleable) * * @param state$ - Observable of RaidenStates * @param meta - meta of channel for which to wait * @returns Observable which waits until channel becomes settleable */ export declare function waitChannelSettleable$(state$: Observable<RaidenState>, meta: channelSettle.request['meta']): Observable<Readonly<{ _id: `0x${string}@0x${string}#${number}`; id: number; token: Address; tokenNetwork: Address; isFirstParticipant: boolean; openBlock: number; own: import("./channels/state").ChannelEnd; partner: import("./channels/state").ChannelEnd; }> & Readonly<{ closeBlock: number; closeParticipant: Address; }> & Readonly<{ state: ChannelState.closed | ChannelState.settleable | ChannelState.settling; }> & { state: (typeof settleableStates)[number]; }>; /** * Helper function to create the RaidenEpicDeps dependencies object for Raiden Epics * * @param state - Initial/previous RaidenState * @param config - defaultConfig overwrites * @param opts - Options * @param opts.signer - Signer holding raiden account connected to a JsonRpcProvider * @param opts.contractsInfo - Object holding deployment information from Raiden contracts on * current network * @param opts.db - Database instance * @param opts.main - Main account object, set when using a subkey as raiden signer * @returns Constructed epics dependencies object */ export declare function makeDependencies(state: RaidenState, config: PartialRaidenConfig | undefined, { signer, contractsInfo, db, main, }: Pick<RaidenEpicDeps, 'signer' | 'contractsInfo' | 'db' | 'main'>): RaidenEpicDeps; export {};