UNPKG

@lifi/sdk

Version:

LI.FI Any-to-Any Cross-Chain-Swap SDK

25 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stepComparison = void 0; const constants_js_1 = require("../errors/constants.js"); const errors_js_1 = require("../errors/errors.js"); const utils_js_1 = require("./utils.js"); const stepComparison = async (statusManager, oldStep, newStep, allowUserInteraction, executionOptions) => { if ((0, utils_js_1.checkStepSlippageThreshold)(oldStep, newStep)) { return statusManager.updateStepInRoute(newStep); } let allowStepUpdate; if (allowUserInteraction) { allowStepUpdate = await executionOptions?.acceptExchangeRateUpdateHook?.({ oldToAmount: oldStep.estimate.toAmount, newToAmount: newStep.estimate.toAmount, toToken: newStep.action.toToken, }); } if (!allowStepUpdate) { throw new errors_js_1.TransactionError(constants_js_1.LiFiErrorCode.ExchangeRateUpdateCanceled, 'Exchange rate has changed!\nTransaction was not sent, your funds are still in your wallet.\nThe exchange rate has changed and the previous estimation can not be fulfilled due to value loss.'); } return statusManager.updateStepInRoute(newStep); }; exports.stepComparison = stepComparison; //# sourceMappingURL=stepComparison.js.map