@wormhole-foundation/sdk-connect
Version:
The core package for the Connect SDK, used in conjunction with 1 or more of the chain packages
66 lines • 2.67 kB
JavaScript
import { amount } from "@wormhole-foundation/sdk-base";
import { getTokenDetails } from "./token.js";
export 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 amount.parse(amt, this.source.decimals);
}
amountFromBaseUnits(amt) {
return amount.fromBaseUnits(amt, this.source.decimals);
}
async displayQuote(quote, params, details) {
let dq = {
success: true,
sourceToken: {
token: quote.sourceToken.token,
amount: amount.fromBaseUnits(quote.sourceToken.amount, this.source.decimals),
},
destinationToken: {
token: quote.destinationToken.token,
amount: 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: amount.fromBaseUnits(quote.relayFee.amount, relayFeeDecimals),
};
}
if (quote.destinationNativeGas) {
const dstDecimals = await this.toChain.getDecimals("native");
dq.destinationNativeGas = 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 getTokenDetails(fromChain, params.source, params.sourceDecimals);
const destDetails = await getTokenDetails(toChain, params.destination, params.destinationDecimals);
const rtr = new RouteTransferRequest(fromChain, toChain, sourceDetails, destDetails, params.recipient);
return rtr;
}
}
//# sourceMappingURL=request.js.map