UNPKG

@reservoir0x/relay-sdk

Version:

Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.

64 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execute = void 0; const client_js_1 = require("../client.js"); const index_js_1 = require("../utils/index.js"); const viemWallet_js_1 = require("../utils/viemWallet.js"); const address_js_1 = require("../constants/address.js"); async function execute(data) { const { quote, wallet, depositGasLimit, onProgress } = data; const client = (0, client_js_1.getClient)(); if (!client.baseApiUrl || !client.baseApiUrl.length) { throw new ReferenceError('RelayClient missing api url configuration'); } let adaptedWallet; if (wallet) { adaptedWallet = (0, viemWallet_js_1.isViemWalletClient)(wallet) ? (0, index_js_1.adaptViemWallet)(wallet) : wallet; } try { if (!adaptedWallet) { throw new Error('AdaptedWallet is required to execute steps'); } const chainId = quote.details?.currencyIn?.currency?.chainId; if (chainId === undefined) { throw new Error('Missing chainId from quote'); } if ((0, address_js_1.isDeadAddress)(quote?.details?.recipient)) { throw new Error('Recipient should never be burn address'); } if ((0, address_js_1.isDeadAddress)(quote?.details?.sender)) { throw new Error('Sender should never be burn address'); } const { request, ...restOfQuote } = quote; const _quote = (0, index_js_1.safeStructuredClone)(restOfQuote); const data = await (0, index_js_1.executeSteps)(chainId, request, adaptedWallet, ({ steps, fees, breakdown, details, refunded, error }) => { const { currentStep, currentStepItem, txHashes } = (0, index_js_1.getCurrentStepData)(steps); onProgress?.({ steps, fees, breakdown, details, currentStep, currentStepItem, txHashes, refunded, error }); }, _quote, depositGasLimit ? { deposit: { gasLimit: depositGasLimit } } : undefined); return data; } catch (err) { console.error(err); throw err; } } exports.execute = execute; //# sourceMappingURL=execute.js.map