UNPKG

@wormhole-foundation/sdk-connect

Version:

The core package for the Connect SDK, used in conjunction with 1 or more of the chain packages

70 lines 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RouteTransferRequest = void 0; const sdk_base_1 = require("@wormhole-foundation/sdk-base"); const token_js_1 = require("./token.js"); class RouteTransferRequest { source; destination; fromChain; toChain; recipient; constructor(fromChain, toChain, source, destination, recipient) { this.fromChain = fromChain; this.toChain = toChain; this.source = source; this.destination = destination; this.recipient = recipient; } parseAmount(amt) { return sdk_base_1.amount.parse(amt, this.source.decimals); } amountFromBaseUnits(amt) { return sdk_base_1.amount.fromBaseUnits(amt, this.source.decimals); } async displayQuote(quote, params, details) { let dq = { success: true, sourceToken: { token: quote.sourceToken.token, amount: sdk_base_1.amount.fromBaseUnits(quote.sourceToken.amount, this.source.decimals), }, destinationToken: { token: quote.destinationToken.token, amount: sdk_base_1.amount.fromBaseUnits(quote.destinationToken.amount, this.destination.decimals), }, params, }; if (quote.relayFee) { const relayFeeChain = quote.relayFee.token.chain === this.fromChain.chain ? this.fromChain : this.toChain; const relayFeeDecimals = await relayFeeChain.getDecimals(quote.relayFee.token.address); dq.relayFee = { token: quote.relayFee.token, amount: sdk_base_1.amount.fromBaseUnits(quote.relayFee.amount, relayFeeDecimals), }; } if (quote.destinationNativeGas) { const dstDecimals = await this.toChain.getDecimals("native"); dq.destinationNativeGas = sdk_base_1.amount.fromBaseUnits(quote.destinationNativeGas, dstDecimals); } if (quote.warnings && quote.warnings.length > 0) { dq.warnings = [...quote.warnings]; } dq.eta = quote.eta; dq.expires = quote.expires; if (details) { dq.details = details; } return dq; } static async create(wh, params, fromChain, toChain) { fromChain = fromChain ?? wh.getChain(params.source.chain); toChain = toChain ?? wh.getChain(params.destination.chain); const sourceDetails = await (0, token_js_1.getTokenDetails)(fromChain, params.source, params.sourceDecimals); const destDetails = await (0, token_js_1.getTokenDetails)(toChain, params.destination, params.destinationDecimals); const rtr = new RouteTransferRequest(fromChain, toChain, sourceDetails, destDetails, params.recipient); return rtr; } } exports.RouteTransferRequest = RouteTransferRequest; //# sourceMappingURL=request.js.map