UNPKG

@dojima-wallet/connection

Version:

Initialise and connection for layer 1&2 blockchain

56 lines (55 loc) 2.82 kB
import { ChainClientParams, Network } from "../client"; import { SwapAssetList } from "@dojima-wallet/utils"; import { ApiPromise, WsProvider } from "@polkadot/api"; import "@polkadot/api-augment"; import { GasfeeResult, PolkaTxParams, rawTxType } from "./types"; import { PoolData, SwapFeeResult } from "../swap_utils"; export type ChainProviderParams = { provider?: string; }; export declare const defaultDotProvider = "wss://rpc.polkadot.io"; export declare const testnetDotProvider = "wss://westend-rpc.polkadot.io"; export declare const DOT_DECIMAL = 12; export interface PolkaChainClient { createInstance(): Promise<ApiPromise>; getAddress(): Promise<string>; getBalance(address: string): Promise<number>; getFees(params: PolkaTxParams): Promise<GasfeeResult>; buildTx(params: PolkaTxParams): Promise<rawTxType>; transfer(params: PolkaTxParams): Promise<string>; } declare class PolkadotClient implements PolkaChainClient { protected network: Network; protected provider: string; private phrase; constructor({ phrase, network, provider, }: ChainClientParams & ChainProviderParams); rpcProvider(): WsProvider; createInstance(): Promise<ApiPromise>; private mnemonicAccount; /** * Get the current address. * * @param {number} index (optional) Account index for the derivation path * @returns {Address} The current address. * * @throws {Error} Thrown if phrase has not been set before. A phrase is needed to create a wallet and to derive an address from it. */ getAddress(): Promise<string>; getBalance(address: string): Promise<number>; getDecimalFromNetwork(): 12 | 10; buildTx({ recipient, amount }: PolkaTxParams): Promise<rawTxType>; transfer({ recipient, amount }: PolkaTxParams): Promise<string>; dummyTx(recipient: string, amount: number): Promise<string>; getFees({ recipient, amount }: PolkaTxParams): Promise<GasfeeResult>; getSwapOutput(inputAmount: number, pool: PoolData, toDoj: boolean): number; getDoubleSwapOutput(inputAmount: number, pool1: PoolData, pool2: PoolData): number; getSwapSlip(inputAmount: number, pool: PoolData, toDoj: boolean): number; getDoubleSwapSlip(inputAmount: number, pool1: PoolData, pool2: PoolData): number; getSwapFeesData(): Promise<SwapFeeResult>; getPolkadotInboundAddress(hermesApiUrl: string): Promise<string>; getDefaultLiquidityPoolGasFee(hermesApiUrl: string): Promise<number>; polkaBatchTxsToHermes(amount: number, inboundAddress: string, memo: string): Promise<string>; addLiquidityPool(amount: number, inboundAddress: string, hermesAddress?: string): Promise<string>; swap(amount: number, token: SwapAssetList, inboundAddress: string, recipient: string): Promise<string>; } export { PolkadotClient };