Finschia / finschia-js

finschia-js is javascript sdk for Finschia
Apache License 2.0
7 stars 4 forks source link

feat: update swapAndBridge function #116

Closed zemyblue closed 3 months ago

zemyblue commented 3 months ago

Description

How to Use

export interface SwapAndBridgeOptions {
  readonly gas?: StdFee | number;
  readonly memo?: string;
  /** The balance to swap and bridge. */
  readonly amount?: string | number;
  /** Set broadcast mode. If true, BROADCAST_ASYNC_MODE, if false, BROADCAST_SYNC_MODE */
  readonly asyncBroadcast?: boolean;
}

// swapAndBridge define
public async swapAndBridge(
    senderAddress: string,
    toAddress: string,
    { gas = 150_000, memo = "", amount = undefined, asyncBroadcast = false }: SwapAndBridgeOptions = {},
  ): Promise<Uint8Array | DeliverTxResponse>

// Usage
const fromAddr = "link146asaycmtydq45kxc8evntqfgepagygelel00h";
const toAddr = "0xf7bAc63fc7CEaCf0589F25454Ecf5C2ce904997c";
// If you swap and bridge all balance. 
const result = await client.swapAndBridge(fromAddr, toAddr);

// if you swap and bridge part of the balance.
const result2 = await client.swapAndBridge(fromAddr, toAddr, { amount: 500_000 });

// if you want to broadcast tx in async mode
const result3 = await client.swapAndBridge(from, toAddr, { asyncBroadcast: true });

Motivation and context

How has this been tested?

Screenshots (if appropriate):

Checklist: