raiden-ts
Version:
Raiden Light Client Typescript/Javascript SDK
99 lines (98 loc) • 4.34 kB
TypeScript
import type { Contract, ContractReceipt, ContractTransaction } from '@ethersproject/contracts';
import type { Observable, OperatorFunction } from 'rxjs';
import type { HumanStandardToken } from '../contracts';
import type { RaidenState } from '../state';
import type { RaidenEpicDeps } from '../types';
import type { Address, Hash, UInt } from '../utils/types';
import type { Channel, ChannelBalances } from './state';
import type { ChannelKey, ChannelUniqueKey } from './types';
/**
* Returns a key (string) for a channel unique per tokenNetwork+partner
*
* @param channel - Either a Channel or a { tokenNetwork, partner } pair of addresses
* @param channel.tokenNetwork - TokenNetwork address
* @param channel.partner - Partner address
* @returns A string, for now
*/
export declare function channelKey({ tokenNetwork, partner, }: {
tokenNetwork: Address;
} & ({
partner: {
address: Address;
};
} | {
partner: Address;
})): ChannelKey;
/**
* Returns a unique key (string) for a channel per tokenNetwork+partner+id
*
* @param channel - Either a Channel or a { tokenNetwork, partner } pair of addresses
* @returns A string, for now
*/
export declare function channelUniqueKey<C extends {
_id?: ChannelUniqueKey;
id: number;
tokenNetwork: Address;
} & ({
partner: {
address: Address;
};
} | {
partner: Address;
})>(channel: C): ChannelUniqueKey;
/**
* Calculates and returns partial and total amounts of given channel state
*
* @param channel - A Channel state to calculate amounts from
* @returns An object holding own&partner's deposit, withdraw, transferred, locked, balance and
* capacity.
*/
export declare function channelAmounts(channel: Channel): ChannelBalances;
/**
* Reactively on state, emits grouped observables per channel which emits respective channel
* states and completes when channel is settled.
* Can be used either passing input directly or as an operator
*
* @returns Tuple containing grouped Observable and { key, id }: { ChannelKey, number } values
*/
export declare function groupChannel(): OperatorFunction<RaidenState, Observable<Channel>>;
/**
* Performs a contract transaction with retries
* It automatically choose gasPrice from latest provider.getFeeData, and choose which account to
* use for call depending on opts.subkey or config.subkey (defaults to main account, if available),
* it also adds a +5% margin over estimated gasLimit;
* this function errors if tx doesn't succeed; retry must be implemented by caller
*
* @param contract - Contract instance
* @param method - Method name (string)
* @param parameters - Parameters array for contract method
* @param deps - Epics dependencies
* @param opts - transact options
* @param opts.subkey - whether to force use of subkey (true) or main key (false); null uses
* contract instance as is
* @param opts.error - error to throw if tx can't go through
* @returns Observable returning [transaction, receipt] tuple
*/
export declare function transact<C extends Contract, M extends keyof C['estimateGas'] & string>(contract: C, method: M, parameters: Parameters<C['estimateGas'][M]>, deps: Pick<RaidenEpicDeps, 'log' | 'signer' | 'address' | 'main' | 'provider' | 'config$' | 'latest$'>, { subkey, error, }?: {
subkey?: boolean | null;
error?: string;
}): Observable<[ContractTransaction & {
hash: Hash;
}, ContractReceipt & {
transactionHash: Hash;
blockNumber: number;
}]>;
/**
* Approves spender to transfer up to 'deposit' from our tokens; skips if already allowed
* Errors if sender doesn't have enough balance, or transaction fails (may be retried)
*
* @param tokenContract - Token contract instance already connected to sender's signer
* @param spender - Spender address
* @param amount - Amount to be required to be approved
* @param deps - Epics dependencies
* @param deps.log - Logger instance
* @param deps.config$ - Config observable
* @param deps.latest$ - Latest observable
* @returns Observable of true (if already approved) or approval receipt
*/
export declare function ensureApprovedBalance$(tokenContract: HumanStandardToken, spender: Address, amount: UInt<32>, deps: Pick<RaidenEpicDeps, 'log' | 'provider' | 'signer' | 'address' | 'main' | 'config$' | 'latest$'>): Observable<true | ContractReceipt>;