@lifi/sdk
Advanced tools
Comparing version 1.6.4 to 1.7.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [1.7.0](https://github.com/lifinance/sdk/compare/v1.6.4...v1.7.0) (2022-11-23) | ||
### Features | ||
* add acceptExchangeRateUpdateHook and return gas info during route execution ([#111](https://github.com/lifinance/sdk/issues/111)) ([65c4cb1](https://github.com/lifinance/sdk/commit/65c4cb1c68fc0e7b60f1c19a42105772998cdb16)) | ||
### [1.6.4](https://github.com/lifinance/sdk/compare/v1.6.3...v1.6.4) (2022-11-16) | ||
@@ -7,0 +14,0 @@ |
@@ -1,22 +0,2 @@ | ||
import { Token } from '@lifi/types'; | ||
import { Signer } from 'ethers'; | ||
import { RevokeTokenData } from '../types'; | ||
export interface ApproveTokenRequest { | ||
signer: Signer; | ||
token: Token; | ||
approvalAddress: string; | ||
amount: string; | ||
infiniteApproval?: boolean; | ||
} | ||
export interface RevokeApprovalRequest { | ||
signer: Signer; | ||
token: Token; | ||
approvalAddress: string; | ||
} | ||
export declare const getTokenApproval: (signer: Signer, token: Token, approvalAddress: string) => Promise<string | undefined>; | ||
export declare const bulkGetTokenApproval: (signer: Signer, tokenData: RevokeTokenData[]) => Promise<{ | ||
token: Token; | ||
approval: string | undefined; | ||
}[]>; | ||
export declare const approveToken: ({ signer, token, approvalAddress, amount, infiniteApproval, }: ApproveTokenRequest) => Promise<void>; | ||
export declare const revokeTokenApproval: ({ signer, token, approvalAddress, }: RevokeApprovalRequest) => Promise<void>; | ||
export * from './checkAllowance'; | ||
export * from './tokenApproval'; |
@@ -1,68 +0,2 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import BigNumber from 'bignumber.js'; | ||
import { constants } from 'ethers'; | ||
import { isSameToken } from '../helpers'; | ||
import { isNativeTokenAddress } from '../utils/utils'; | ||
import { getAllowanceViaMulticall, getApproved, groupByChain, setApproval, } from './utils'; | ||
export const getTokenApproval = (signer, token, approvalAddress) => __awaiter(void 0, void 0, void 0, function* () { | ||
// native token don't need approval | ||
if (isNativeTokenAddress(token.address)) { | ||
return; | ||
} | ||
const approved = yield getApproved(signer, token.address, approvalAddress); | ||
return approved.toString(); | ||
}); | ||
export const bulkGetTokenApproval = (signer, tokenData) => __awaiter(void 0, void 0, void 0, function* () { | ||
// filter out native tokens | ||
const filteredTokenData = tokenData.filter(({ token }) => !isNativeTokenAddress(token.address)); | ||
// group by chain | ||
const tokenDataByChain = groupByChain(filteredTokenData); | ||
const approvalPromises = Object.keys(tokenDataByChain).map((chainId) => __awaiter(void 0, void 0, void 0, function* () { | ||
const parsedChainId = Number.parseInt(chainId); | ||
// get allowances for current chain and token list | ||
return getAllowanceViaMulticall(signer, parsedChainId, tokenDataByChain[parsedChainId]); | ||
})); | ||
const approvalsByChain = yield Promise.all(approvalPromises); | ||
const approvals = approvalsByChain.flat(); | ||
return tokenData.map(({ token }) => { | ||
// native token don't need approval | ||
if (isNativeTokenAddress(token.address)) { | ||
return { token, approval: undefined }; | ||
} | ||
const approved = approvals.find((approval) => isSameToken(approval.token, token)); | ||
return { token, approval: approved === null || approved === void 0 ? void 0 : approved.approvedAmount.toString() }; | ||
}); | ||
}); | ||
export const approveToken = ({ signer, token, approvalAddress, amount, infiniteApproval = false, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
// native token don't need approval | ||
if (isNativeTokenAddress(token.address)) { | ||
return; | ||
} | ||
const approvedAmount = yield getApproved(signer, token.address, approvalAddress); | ||
if (new BigNumber(amount).gt(approvedAmount)) { | ||
const approvalAmount = infiniteApproval | ||
? constants.MaxUint256.toString() | ||
: amount; | ||
const approveTx = yield setApproval(signer, token.address, approvalAddress, approvalAmount); | ||
yield approveTx.wait(); | ||
} | ||
}); | ||
export const revokeTokenApproval = ({ signer, token, approvalAddress, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
// native token don't need approval | ||
if (isNativeTokenAddress(token.address)) { | ||
return; | ||
} | ||
const approvedAmount = yield getApproved(signer, token.address, approvalAddress); | ||
if (!approvedAmount.isZero()) { | ||
const approveTx = yield setApproval(signer, token.address, approvalAddress, '0'); | ||
yield approveTx.wait(); | ||
} | ||
}); | ||
export * from './checkAllowance'; | ||
export * from './tokenApproval'; |
@@ -1,22 +0,2 @@ | ||
import { Token } from '@lifi/types'; | ||
import { Signer } from 'ethers'; | ||
import { RevokeTokenData } from '../types'; | ||
export interface ApproveTokenRequest { | ||
signer: Signer; | ||
token: Token; | ||
approvalAddress: string; | ||
amount: string; | ||
infiniteApproval?: boolean; | ||
} | ||
export interface RevokeApprovalRequest { | ||
signer: Signer; | ||
token: Token; | ||
approvalAddress: string; | ||
} | ||
export declare const getTokenApproval: (signer: Signer, token: Token, approvalAddress: string) => Promise<string | undefined>; | ||
export declare const bulkGetTokenApproval: (signer: Signer, tokenData: RevokeTokenData[]) => Promise<{ | ||
token: Token; | ||
approval: string | undefined; | ||
}[]>; | ||
export declare const approveToken: ({ signer, token, approvalAddress, amount, infiniteApproval, }: ApproveTokenRequest) => Promise<void>; | ||
export declare const revokeTokenApproval: ({ signer, token, approvalAddress, }: RevokeApprovalRequest) => Promise<void>; | ||
export * from './checkAllowance'; | ||
export * from './tokenApproval'; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.revokeTokenApproval = exports.approveToken = exports.bulkGetTokenApproval = exports.getTokenApproval = void 0; | ||
const bignumber_js_1 = __importDefault(require("bignumber.js")); | ||
const ethers_1 = require("ethers"); | ||
const helpers_1 = require("../helpers"); | ||
const utils_1 = require("../utils/utils"); | ||
const utils_2 = require("./utils"); | ||
const getTokenApproval = (signer, token, approvalAddress) => __awaiter(void 0, void 0, void 0, function* () { | ||
// native token don't need approval | ||
if ((0, utils_1.isNativeTokenAddress)(token.address)) { | ||
return; | ||
} | ||
const approved = yield (0, utils_2.getApproved)(signer, token.address, approvalAddress); | ||
return approved.toString(); | ||
}); | ||
exports.getTokenApproval = getTokenApproval; | ||
const bulkGetTokenApproval = (signer, tokenData) => __awaiter(void 0, void 0, void 0, function* () { | ||
// filter out native tokens | ||
const filteredTokenData = tokenData.filter(({ token }) => !(0, utils_1.isNativeTokenAddress)(token.address)); | ||
// group by chain | ||
const tokenDataByChain = (0, utils_2.groupByChain)(filteredTokenData); | ||
const approvalPromises = Object.keys(tokenDataByChain).map((chainId) => __awaiter(void 0, void 0, void 0, function* () { | ||
const parsedChainId = Number.parseInt(chainId); | ||
// get allowances for current chain and token list | ||
return (0, utils_2.getAllowanceViaMulticall)(signer, parsedChainId, tokenDataByChain[parsedChainId]); | ||
})); | ||
const approvalsByChain = yield Promise.all(approvalPromises); | ||
const approvals = approvalsByChain.flat(); | ||
return tokenData.map(({ token }) => { | ||
// native token don't need approval | ||
if ((0, utils_1.isNativeTokenAddress)(token.address)) { | ||
return { token, approval: undefined }; | ||
} | ||
const approved = approvals.find((approval) => (0, helpers_1.isSameToken)(approval.token, token)); | ||
return { token, approval: approved === null || approved === void 0 ? void 0 : approved.approvedAmount.toString() }; | ||
}); | ||
}); | ||
exports.bulkGetTokenApproval = bulkGetTokenApproval; | ||
const approveToken = ({ signer, token, approvalAddress, amount, infiniteApproval = false, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
// native token don't need approval | ||
if ((0, utils_1.isNativeTokenAddress)(token.address)) { | ||
return; | ||
} | ||
const approvedAmount = yield (0, utils_2.getApproved)(signer, token.address, approvalAddress); | ||
if (new bignumber_js_1.default(amount).gt(approvedAmount)) { | ||
const approvalAmount = infiniteApproval | ||
? ethers_1.constants.MaxUint256.toString() | ||
: amount; | ||
const approveTx = yield (0, utils_2.setApproval)(signer, token.address, approvalAddress, approvalAmount); | ||
yield approveTx.wait(); | ||
} | ||
}); | ||
exports.approveToken = approveToken; | ||
const revokeTokenApproval = ({ signer, token, approvalAddress, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
// native token don't need approval | ||
if ((0, utils_1.isNativeTokenAddress)(token.address)) { | ||
return; | ||
} | ||
const approvedAmount = yield (0, utils_2.getApproved)(signer, token.address, approvalAddress); | ||
if (!approvedAmount.isZero()) { | ||
const approveTx = yield (0, utils_2.setApproval)(signer, token.address, approvalAddress, '0'); | ||
yield approveTx.wait(); | ||
} | ||
}); | ||
exports.revokeTokenApproval = revokeTokenApproval; | ||
__exportStar(require("./checkAllowance"), exports); | ||
__exportStar(require("./tokenApproval"), exports); |
@@ -6,7 +6,10 @@ import { Execution, InternalExecutionSettings, Process, ProcessType, Route, Status, Step, Token } from '../types'; | ||
toToken?: Token; | ||
gasPrice?: string; | ||
gasUsed?: string; | ||
gasPrice?: string; | ||
gasToken?: Token; | ||
gasAmount?: string; | ||
gasAmountUSD?: string; | ||
} | ||
declare type InternalUpdateRouteCallback = (route: Route) => void; | ||
declare type OptionalParameters = Partial<Pick<Process, 'doneAt' | 'failedAt' | 'txHash' | 'txLink' | 'error' | 'substatus' | 'substatusMessage'>>; | ||
type InternalUpdateRouteCallback = (route: Route) => void; | ||
type OptionalParameters = Partial<Pick<Process, 'doneAt' | 'failedAt' | 'txHash' | 'txLink' | 'error' | 'substatus' | 'substatusMessage'>>; | ||
/** | ||
@@ -13,0 +16,0 @@ * Manages status updates of a route and provides various functions for tracking processes |
@@ -163,5 +163,3 @@ "use strict"; | ||
if (receipt) { | ||
step.execution.fromAmount = receipt.fromAmount; | ||
step.execution.toAmount = receipt.toAmount; | ||
step.execution.toToken = receipt.toToken; | ||
step.execution = Object.assign(Object.assign({}, step.execution), receipt); | ||
} | ||
@@ -168,0 +166,0 @@ this.updateStepInRoute(step); |
import { StatusManager } from '.'; | ||
import { AcceptSlippageUpdateHook, Step } from '../types'; | ||
import { InternalExecutionSettings, Step } from '../types'; | ||
/** | ||
* This method checks whether the new and updated Step meets the required slippage conditions. | ||
* This method checks whether the new and updated Step meets the required exchange rate conditions. | ||
* If yes it returns the updated Step. | ||
* If no and if user interaction is allowed it triggers the acceptSlippageUpdateHook. If no user interaction is allowed it aborts. | ||
* If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts. | ||
* | ||
@@ -14,2 +14,2 @@ * @param statusManager | ||
*/ | ||
export declare const stepComparison: (statusManager: StatusManager, oldStep: Step, newStep: Step, acceptSlippageUpdateHook: AcceptSlippageUpdateHook, allowUserInteraction: boolean) => Promise<Step>; | ||
export declare const stepComparison: (statusManager: StatusManager, oldStep: Step, newStep: Step, settings: InternalExecutionSettings, allowUserInteraction: boolean) => Promise<Step>; |
@@ -14,8 +14,7 @@ "use strict"; | ||
const errors_1 = require("../utils/errors"); | ||
const parseError_1 = require("../utils/parseError"); | ||
const utils_1 = require("./utils"); | ||
/** | ||
* This method checks whether the new and updated Step meets the required slippage conditions. | ||
* This method checks whether the new and updated Step meets the required exchange rate conditions. | ||
* If yes it returns the updated Step. | ||
* If no and if user interaction is allowed it triggers the acceptSlippageUpdateHook. If no user interaction is allowed it aborts. | ||
* If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts. | ||
* | ||
@@ -28,9 +27,12 @@ * @param statusManager | ||
*/ | ||
const stepComparison = (statusManager, oldStep, newStep, acceptSlippageUpdateHook, allowUserInteraction) => __awaiter(void 0, void 0, void 0, function* () { | ||
if ((0, utils_1.updatedStepMeetsSlippageConditions)(oldStep, newStep)) { | ||
const stepComparison = (statusManager, oldStep, newStep, settings, allowUserInteraction) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a; | ||
// Check if changed exchange rate is in the range of slippage threshold | ||
if ((0, utils_1.checkStepSlippageThreshold)(oldStep, newStep)) { | ||
return statusManager.updateStepInRoute(newStep); | ||
} | ||
const acceptExchangeRateUpdateHook = (_a = settings.acceptExchangeRateUpdateHook) !== null && _a !== void 0 ? _a : settings.acceptSlippageUpdateHook; | ||
let allowStepUpdate; | ||
if (allowUserInteraction) { | ||
allowStepUpdate = yield acceptSlippageUpdateHook({ | ||
allowStepUpdate = yield acceptExchangeRateUpdateHook({ | ||
oldToAmount: oldStep.estimate.toAmount, | ||
@@ -44,3 +46,5 @@ newToAmount: newStep.estimate.toAmount, | ||
if (!allowStepUpdate) { | ||
throw new errors_1.TransactionError(errors_1.LifiErrorCode.SlippageNotMet, 'Slippage conditions not met!', (0, parseError_1.getSlippageNotMetMessage)(oldStep)); | ||
// The user declined the new exchange rate, so we are not going to proceed | ||
throw new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionCanceled, 'Exchange rate has changed!', `Transaction was not sent, your funds are still in your wallet. | ||
The exchange rate has changed and the previous estimation can not be fulfilled due to value loss.`); | ||
} | ||
@@ -47,0 +51,0 @@ return statusManager.updateStepInRoute(newStep); |
import { Signer } from 'ethers'; | ||
import { InteractionSettings, InternalExecutionSettings, Step } from '../types'; | ||
import { ExecutionManager } from './ExecutionManager'; | ||
import { StatusManager } from './StatusManager'; | ||
export declare class StepExecutor { | ||
executionManager: ExecutionManager; | ||
statusManager: StatusManager; | ||
settings: InternalExecutionSettings; | ||
statusManager: StatusManager; | ||
private swapExecutionManager; | ||
private bridgeExecutionManager; | ||
allowUserInteraction: boolean; | ||
@@ -15,4 +15,2 @@ executionStopped: boolean; | ||
executeStep: (signer: Signer, step: Step) => Promise<Step>; | ||
private executeSwap; | ||
private executeCross; | ||
} |
@@ -13,4 +13,3 @@ "use strict"; | ||
exports.StepExecutor = void 0; | ||
const bridge_execute_1 = require("./bridges/bridge.execute"); | ||
const swap_execute_1 = require("./exchanges/swap.execute"); | ||
const ExecutionManager_1 = require("./ExecutionManager"); | ||
const switchChain_1 = require("./switchChain"); | ||
@@ -25,4 +24,2 @@ // Please be careful when changing the defaults as it may break the behavior (e.g., background execution) | ||
constructor(statusManager, settings) { | ||
this.swapExecutionManager = new swap_execute_1.SwapExecutionManager(); | ||
this.bridgeExecutionManager = new bridge_execute_1.BridgeExecutionManager(); | ||
this.allowUserInteraction = true; | ||
@@ -33,4 +30,3 @@ this.executionStopped = false; | ||
this.allowUserInteraction = interactionSettings.allowInteraction; | ||
this.swapExecutionManager.allowInteraction(interactionSettings.allowInteraction); | ||
this.bridgeExecutionManager.allowInteraction(interactionSettings.allowInteraction); | ||
this.executionManager.allowInteraction(interactionSettings.allowInteraction); | ||
this.statusManager.allowUpdates(interactionSettings.allowUpdates); | ||
@@ -53,17 +49,3 @@ this.executionStopped = interactionSettings.stopExecution; | ||
signer = updatedSigner; | ||
switch (step.type) { | ||
case 'lifi': | ||
case 'cross': | ||
yield this.executeCross(signer, step); | ||
break; | ||
case 'swap': | ||
yield this.executeSwap(signer, step); | ||
break; | ||
default: | ||
throw new Error('Unsupported step type.'); | ||
} | ||
return step; | ||
}); | ||
this.executeSwap = (signer, step) => { | ||
const swapParams = { | ||
const parameters = { | ||
signer, | ||
@@ -74,13 +56,6 @@ step, | ||
}; | ||
return this.swapExecutionManager.execute(swapParams); | ||
}; | ||
this.executeCross = (signer, step) => { | ||
const crossParams = { | ||
signer, | ||
step, | ||
settings: this.settings, | ||
statusManager: this.statusManager, | ||
}; | ||
return this.bridgeExecutionManager.execute(crossParams); | ||
}; | ||
yield this.executionManager.execute(parameters); | ||
return step; | ||
}); | ||
this.executionManager = new ExecutionManager_1.ExecutionManager(); | ||
this.statusManager = statusManager; | ||
@@ -87,0 +62,0 @@ this.settings = settings; |
@@ -48,3 +48,3 @@ "use strict"; | ||
catch (error) { | ||
switchProcess = statusManager.updateProcess(step, switchProcess.type, 'FAILED', { | ||
statusManager.updateProcess(step, switchProcess.type, 'FAILED', { | ||
error: { | ||
@@ -51,0 +51,0 @@ message: error.message, |
@@ -6,2 +6,2 @@ import { ProcessType, Status, StatusMessage, StatusResponse, Step, Substatus } from '@lifi/types'; | ||
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined; | ||
export declare function updatedStepMeetsSlippageConditions(oldStep: Step, newStep: Step): boolean; | ||
export declare function checkStepSlippageThreshold(oldStep: Step, newStep: Step): boolean; |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updatedStepMeetsSlippageConditions = exports.getSubstatusMessage = exports.getProcessMessage = exports.waitForReceivingTransaction = void 0; | ||
exports.checkStepSlippageThreshold = exports.getSubstatusMessage = exports.getProcessMessage = exports.waitForReceivingTransaction = void 0; | ||
const bignumber_js_1 = __importDefault(require("bignumber.js")); | ||
@@ -80,16 +80,16 @@ const ApiService_1 = __importDefault(require("../services/ApiService")); | ||
SWAP: { | ||
STARTED: 'Preparing swap.', | ||
STARTED: 'Preparing swap transaction.', | ||
ACTION_REQUIRED: 'Please sign the transaction.', | ||
PENDING: 'Swapping.', | ||
PENDING: 'Waiting for swap transaction.', | ||
DONE: 'Swap completed.', | ||
}, | ||
CROSS_CHAIN: { | ||
STARTED: 'Preparing transaction.', | ||
STARTED: 'Preparing bridge transaction.', | ||
ACTION_REQUIRED: 'Please sign the transaction.', | ||
PENDING: 'Waiting for transaction.', | ||
DONE: 'Transaction approved.', | ||
PENDING: 'Waiting for bridge transaction.', | ||
DONE: 'Bridge transaction confirmed.', | ||
}, | ||
RECEIVING_CHAIN: { | ||
PENDING: 'Waiting for receiving chain.', | ||
DONE: 'Funds received.', | ||
PENDING: 'Waiting for destination chain.', | ||
DONE: 'Bridge completed.', | ||
}, | ||
@@ -129,3 +129,4 @@ TRANSACTION: {}, | ||
exports.getSubstatusMessage = getSubstatusMessage; | ||
function updatedStepMeetsSlippageConditions(oldStep, newStep) { | ||
// Used to check if changed exchange rate is in the range of slippage threshold | ||
function checkStepSlippageThreshold(oldStep, newStep) { | ||
const setSlippage = new bignumber_js_1.default(oldStep.action.slippage); | ||
@@ -139,2 +140,2 @@ const oldEstimatedToAmount = new bignumber_js_1.default(oldStep.estimate.toAmountMin); | ||
} | ||
exports.updatedStepMeetsSlippageConditions = updatedStepMeetsSlippageConditions; | ||
exports.checkStepSlippageThreshold = checkStepSlippageThreshold; |
@@ -173,3 +173,3 @@ import { FallbackProvider } from '@ethersproject/providers'; | ||
* @param {{ [chainId: number]: Token[] }} tokensByChain - A list of Token objects organized by chain ids. | ||
* @return {Promise<{ [chainId: number]: TokenAmount[] }} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains. | ||
* @return {Promise<{ [chainId: number]: TokenAmount[] }>} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains. | ||
* @throws {ValidationError} Throws a ValidationError if parameters are invalid. | ||
@@ -176,0 +176,0 @@ */ |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -16,3 +39,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
const allowance_1 = require("./allowance"); | ||
const balances_1 = __importDefault(require("./balances")); | ||
const balance = __importStar(require("./balance")); | ||
const connectors_1 = require("./connectors"); | ||
@@ -342,3 +365,3 @@ const StatusManager_1 = require("./execution/StatusManager"); | ||
} | ||
return balances_1.default.getTokenBalance(walletAddress, token); | ||
return balance.getTokenBalance(walletAddress, token); | ||
}); | ||
@@ -360,3 +383,3 @@ /** | ||
} | ||
return balances_1.default.getTokenBalances(walletAddress, tokens); | ||
return balance.getTokenBalances(walletAddress, tokens); | ||
}); | ||
@@ -367,3 +390,3 @@ /** | ||
* @param {{ [chainId: number]: Token[] }} tokensByChain - A list of Token objects organized by chain ids. | ||
* @return {Promise<{ [chainId: number]: TokenAmount[] }} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains. | ||
* @return {Promise<{ [chainId: number]: TokenAmount[] }>} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains. | ||
* @throws {ValidationError} Throws a ValidationError if parameters are invalid. | ||
@@ -380,3 +403,3 @@ */ | ||
} | ||
return balances_1.default.getTokenBalancesForChains(walletAddress, tokensByChain); | ||
return balance.getTokenBalancesForChains(walletAddress, tokensByChain); | ||
}); | ||
@@ -383,0 +406,0 @@ /** |
@@ -18,2 +18,3 @@ "use strict"; | ||
acceptSlippageUpdateHook: () => Promise.resolve(undefined), | ||
acceptExchangeRateUpdateHook: () => Promise.resolve(undefined), | ||
infiniteApproval: false, | ||
@@ -20,0 +21,0 @@ executeInBackground: false, |
@@ -11,3 +11,3 @@ import { Route, RouteOptions, Step, Token } from '@lifi/types'; | ||
} | ||
export declare type ParsedReceipt = { | ||
export type ParsedReceipt = { | ||
fromAmount?: string; | ||
@@ -20,3 +20,3 @@ toAmount: string; | ||
}; | ||
interface ExecutionParams { | ||
export interface ExecutionParams { | ||
signer: Signer; | ||
@@ -27,10 +27,4 @@ step: Step; | ||
} | ||
export interface ExecuteSwapParams extends ExecutionParams { | ||
step: Step; | ||
} | ||
export interface ExecuteCrossParams extends ExecutionParams { | ||
step: Step; | ||
} | ||
export declare type CallbackFunction = (updatedRoute: Route) => void; | ||
export declare type Config = { | ||
export type CallbackFunction = (updatedRoute: Route) => void; | ||
export type Config = { | ||
apiUrl: string; | ||
@@ -43,3 +37,3 @@ rpcs: Record<ChainId, string[]>; | ||
}; | ||
export declare type ConfigUpdate = { | ||
export type ConfigUpdate = { | ||
apiUrl?: string; | ||
@@ -52,3 +46,3 @@ rpcs?: Record<number, string[]>; | ||
}; | ||
export declare type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>; | ||
export type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>; | ||
export interface AcceptSlippageUpdateHookParams { | ||
@@ -61,3 +55,9 @@ toToken: Token; | ||
} | ||
export declare type AcceptSlippageUpdateHook = (params: AcceptSlippageUpdateHookParams) => Promise<boolean | undefined>; | ||
export type AcceptSlippageUpdateHook = (params: AcceptSlippageUpdateHookParams) => Promise<boolean | undefined>; | ||
export interface ExchangeRateUpdateParams { | ||
toToken: Token; | ||
oldToAmount: string; | ||
newToAmount: string; | ||
} | ||
export type AcceptExchangeRateUpdateHook = (params: ExchangeRateUpdateParams) => Promise<boolean | undefined>; | ||
export interface ExecutionData { | ||
@@ -68,17 +68,12 @@ route: Route; | ||
} | ||
export interface ExecutionSettings { | ||
updateCallback?: CallbackFunction; | ||
switchChainHook?: SwitchChainHook; | ||
acceptSlippageUpdateHook?: AcceptSlippageUpdateHook; | ||
infiniteApproval?: boolean; | ||
executeInBackground?: boolean; | ||
} | ||
export interface InternalExecutionSettings extends ExecutionSettings { | ||
export type ExecutionSettings = Partial<InternalExecutionSettings>; | ||
export interface InternalExecutionSettings { | ||
updateCallback: CallbackFunction; | ||
switchChainHook: SwitchChainHook; | ||
acceptSlippageUpdateHook: AcceptSlippageUpdateHook; | ||
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook; | ||
infiniteApproval: boolean; | ||
executeInBackground: boolean; | ||
} | ||
export declare type EnforcedObjectProperties<T> = T & { | ||
export type EnforcedObjectProperties<T> = T & { | ||
[P in keyof T]-?: T[P]; | ||
@@ -89,3 +84,3 @@ }; | ||
} | ||
export declare type RevokeTokenData = { | ||
export type RevokeTokenData = { | ||
token: Token; | ||
@@ -99,2 +94,1 @@ approvalAddress: string; | ||
} | ||
export {}; |
@@ -22,5 +22,6 @@ declare enum ErrorType { | ||
GasLimitError = 1009, | ||
SlippageNotMet = 1010, | ||
TransactionCanceled = 1010, | ||
SlippageError = 1011, | ||
TransactionRejected = 1012 | ||
TransactionRejected = 1012, | ||
BalanceError = 1013 | ||
} | ||
@@ -47,3 +48,3 @@ export declare enum MetaMaskRPCErrorCode { | ||
} | ||
export declare type ErrorCode = LifiErrorCode | MetaMaskRPCErrorCode | MetaMaskProviderErrorCode; | ||
export type ErrorCode = LifiErrorCode | MetaMaskRPCErrorCode | MetaMaskProviderErrorCode; | ||
export declare class LifiError extends Error { | ||
@@ -72,2 +73,5 @@ code: ErrorCode; | ||
} | ||
export declare class BalanceError extends LifiError { | ||
constructor(message: string, htmlMessage?: string, stack?: string); | ||
} | ||
export declare class NotFoundError extends LifiError { | ||
@@ -74,0 +78,0 @@ constructor(message: string, htmlMessage?: string, stack?: string); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnknownError = exports.NotFoundError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.LifiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.LifiErrorCode = void 0; | ||
exports.UnknownError = exports.NotFoundError = exports.BalanceError = exports.SlippageError = exports.TransactionError = exports.ValidationError = exports.ServerError = exports.ProviderError = exports.RPCError = exports.LifiError = exports.MetaMaskProviderErrorCode = exports.MetaMaskRPCErrorCode = exports.LifiErrorCode = void 0; | ||
var ErrorType; | ||
@@ -27,5 +27,6 @@ (function (ErrorType) { | ||
LifiErrorCode[LifiErrorCode["GasLimitError"] = 1009] = "GasLimitError"; | ||
LifiErrorCode[LifiErrorCode["SlippageNotMet"] = 1010] = "SlippageNotMet"; | ||
LifiErrorCode[LifiErrorCode["TransactionCanceled"] = 1010] = "TransactionCanceled"; | ||
LifiErrorCode[LifiErrorCode["SlippageError"] = 1011] = "SlippageError"; | ||
LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected"; | ||
LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError"; | ||
})(LifiErrorCode = exports.LifiErrorCode || (exports.LifiErrorCode = {})); | ||
@@ -106,2 +107,8 @@ var MetaMaskRPCErrorCode; | ||
exports.SlippageError = SlippageError; | ||
class BalanceError extends LifiError { | ||
constructor(message, htmlMessage, stack) { | ||
super(ErrorType.ValidationError, LifiErrorCode.BalanceError, message, htmlMessage, stack); | ||
} | ||
} | ||
exports.BalanceError = BalanceError; | ||
class NotFoundError extends LifiError { | ||
@@ -108,0 +115,0 @@ constructor(message, htmlMessage, stack) { |
import { Fragment, JsonFragment } from '@ethersproject/abi'; | ||
export declare type MultiCallData = { | ||
export type MultiCallData = { | ||
address: string; | ||
@@ -4,0 +4,0 @@ name: string; |
@@ -38,2 +38,1 @@ import { Process, Step } from '@lifi/types'; | ||
export declare const parseBackendError: (e: any) => LifiError; | ||
export declare const getSlippageNotMetMessage: (step: Step) => string; |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getSlippageNotMetMessage = exports.parseBackendError = exports.parseError = exports.getTransactionFailedMessage = exports.getTransactionNotSentMessage = void 0; | ||
exports.parseBackendError = exports.parseError = exports.getTransactionFailedMessage = exports.getTransactionNotSentMessage = void 0; | ||
const types_1 = require("@lifi/types"); | ||
@@ -139,7 +139,1 @@ const eth_rpc_errors_1 = require("eth-rpc-errors"); | ||
exports.parseBackendError = parseBackendError; | ||
const getSlippageNotMetMessage = (step) => { | ||
const { slippage } = step.action; | ||
return `Transaction was not sent, your funds are still in your wallet. | ||
The updated quote for the current transaction does not meet your set slippage of ${slippage * 100}%.`; | ||
}; | ||
exports.getSlippageNotMetMessage = getSlippageNotMetMessage; |
export declare const name = "@lifi/sdk"; | ||
export declare const version = "1.6.4"; | ||
export declare const version = "1.7.0"; |
@@ -5,2 +5,2 @@ "use strict"; | ||
exports.name = '@lifi/sdk'; | ||
exports.version = '1.6.4'; | ||
exports.version = '1.7.0'; |
@@ -6,7 +6,10 @@ import { Execution, InternalExecutionSettings, Process, ProcessType, Route, Status, Step, Token } from '../types'; | ||
toToken?: Token; | ||
gasPrice?: string; | ||
gasUsed?: string; | ||
gasPrice?: string; | ||
gasToken?: Token; | ||
gasAmount?: string; | ||
gasAmountUSD?: string; | ||
} | ||
declare type InternalUpdateRouteCallback = (route: Route) => void; | ||
declare type OptionalParameters = Partial<Pick<Process, 'doneAt' | 'failedAt' | 'txHash' | 'txLink' | 'error' | 'substatus' | 'substatusMessage'>>; | ||
type InternalUpdateRouteCallback = (route: Route) => void; | ||
type OptionalParameters = Partial<Pick<Process, 'doneAt' | 'failedAt' | 'txHash' | 'txLink' | 'error' | 'substatus' | 'substatusMessage'>>; | ||
/** | ||
@@ -13,0 +16,0 @@ * Manages status updates of a route and provides various functions for tracking processes |
@@ -160,5 +160,3 @@ import { emptyExecution, } from '../types'; | ||
if (receipt) { | ||
step.execution.fromAmount = receipt.fromAmount; | ||
step.execution.toAmount = receipt.toAmount; | ||
step.execution.toToken = receipt.toToken; | ||
step.execution = Object.assign(Object.assign({}, step.execution), receipt); | ||
} | ||
@@ -165,0 +163,0 @@ this.updateStepInRoute(step); |
import { StatusManager } from '.'; | ||
import { AcceptSlippageUpdateHook, Step } from '../types'; | ||
import { InternalExecutionSettings, Step } from '../types'; | ||
/** | ||
* This method checks whether the new and updated Step meets the required slippage conditions. | ||
* This method checks whether the new and updated Step meets the required exchange rate conditions. | ||
* If yes it returns the updated Step. | ||
* If no and if user interaction is allowed it triggers the acceptSlippageUpdateHook. If no user interaction is allowed it aborts. | ||
* If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts. | ||
* | ||
@@ -14,2 +14,2 @@ * @param statusManager | ||
*/ | ||
export declare const stepComparison: (statusManager: StatusManager, oldStep: Step, newStep: Step, acceptSlippageUpdateHook: AcceptSlippageUpdateHook, allowUserInteraction: boolean) => Promise<Step>; | ||
export declare const stepComparison: (statusManager: StatusManager, oldStep: Step, newStep: Step, settings: InternalExecutionSettings, allowUserInteraction: boolean) => Promise<Step>; |
@@ -11,8 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { LifiErrorCode, TransactionError } from '../utils/errors'; | ||
import { getSlippageNotMetMessage } from '../utils/parseError'; | ||
import { updatedStepMeetsSlippageConditions } from './utils'; | ||
import { checkStepSlippageThreshold } from './utils'; | ||
/** | ||
* This method checks whether the new and updated Step meets the required slippage conditions. | ||
* This method checks whether the new and updated Step meets the required exchange rate conditions. | ||
* If yes it returns the updated Step. | ||
* If no and if user interaction is allowed it triggers the acceptSlippageUpdateHook. If no user interaction is allowed it aborts. | ||
* If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts. | ||
* | ||
@@ -25,9 +24,12 @@ * @param statusManager | ||
*/ | ||
export const stepComparison = (statusManager, oldStep, newStep, acceptSlippageUpdateHook, allowUserInteraction) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (updatedStepMeetsSlippageConditions(oldStep, newStep)) { | ||
export const stepComparison = (statusManager, oldStep, newStep, settings, allowUserInteraction) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a; | ||
// Check if changed exchange rate is in the range of slippage threshold | ||
if (checkStepSlippageThreshold(oldStep, newStep)) { | ||
return statusManager.updateStepInRoute(newStep); | ||
} | ||
const acceptExchangeRateUpdateHook = (_a = settings.acceptExchangeRateUpdateHook) !== null && _a !== void 0 ? _a : settings.acceptSlippageUpdateHook; | ||
let allowStepUpdate; | ||
if (allowUserInteraction) { | ||
allowStepUpdate = yield acceptSlippageUpdateHook({ | ||
allowStepUpdate = yield acceptExchangeRateUpdateHook({ | ||
oldToAmount: oldStep.estimate.toAmount, | ||
@@ -41,5 +43,7 @@ newToAmount: newStep.estimate.toAmount, | ||
if (!allowStepUpdate) { | ||
throw new TransactionError(LifiErrorCode.SlippageNotMet, 'Slippage conditions not met!', getSlippageNotMetMessage(oldStep)); | ||
// The user declined the new exchange rate, so we are not going to proceed | ||
throw new TransactionError(LifiErrorCode.TransactionCanceled, 'Exchange rate has changed!', `Transaction was not sent, your funds are still in your wallet. | ||
The exchange rate has changed and the previous estimation can not be fulfilled due to value loss.`); | ||
} | ||
return statusManager.updateStepInRoute(newStep); | ||
}); |
import { Signer } from 'ethers'; | ||
import { InteractionSettings, InternalExecutionSettings, Step } from '../types'; | ||
import { ExecutionManager } from './ExecutionManager'; | ||
import { StatusManager } from './StatusManager'; | ||
export declare class StepExecutor { | ||
executionManager: ExecutionManager; | ||
statusManager: StatusManager; | ||
settings: InternalExecutionSettings; | ||
statusManager: StatusManager; | ||
private swapExecutionManager; | ||
private bridgeExecutionManager; | ||
allowUserInteraction: boolean; | ||
@@ -15,4 +15,2 @@ executionStopped: boolean; | ||
executeStep: (signer: Signer, step: Step) => Promise<Step>; | ||
private executeSwap; | ||
private executeCross; | ||
} |
@@ -10,4 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { BridgeExecutionManager } from './bridges/bridge.execute'; | ||
import { SwapExecutionManager } from './exchanges/swap.execute'; | ||
import { ExecutionManager } from './ExecutionManager'; | ||
import { switchChain } from './switchChain'; | ||
@@ -22,4 +21,2 @@ // Please be careful when changing the defaults as it may break the behavior (e.g., background execution) | ||
constructor(statusManager, settings) { | ||
this.swapExecutionManager = new SwapExecutionManager(); | ||
this.bridgeExecutionManager = new BridgeExecutionManager(); | ||
this.allowUserInteraction = true; | ||
@@ -30,4 +27,3 @@ this.executionStopped = false; | ||
this.allowUserInteraction = interactionSettings.allowInteraction; | ||
this.swapExecutionManager.allowInteraction(interactionSettings.allowInteraction); | ||
this.bridgeExecutionManager.allowInteraction(interactionSettings.allowInteraction); | ||
this.executionManager.allowInteraction(interactionSettings.allowInteraction); | ||
this.statusManager.allowUpdates(interactionSettings.allowUpdates); | ||
@@ -50,17 +46,3 @@ this.executionStopped = interactionSettings.stopExecution; | ||
signer = updatedSigner; | ||
switch (step.type) { | ||
case 'lifi': | ||
case 'cross': | ||
yield this.executeCross(signer, step); | ||
break; | ||
case 'swap': | ||
yield this.executeSwap(signer, step); | ||
break; | ||
default: | ||
throw new Error('Unsupported step type.'); | ||
} | ||
return step; | ||
}); | ||
this.executeSwap = (signer, step) => { | ||
const swapParams = { | ||
const parameters = { | ||
signer, | ||
@@ -71,13 +53,6 @@ step, | ||
}; | ||
return this.swapExecutionManager.execute(swapParams); | ||
}; | ||
this.executeCross = (signer, step) => { | ||
const crossParams = { | ||
signer, | ||
step, | ||
settings: this.settings, | ||
statusManager: this.statusManager, | ||
}; | ||
return this.bridgeExecutionManager.execute(crossParams); | ||
}; | ||
yield this.executionManager.execute(parameters); | ||
return step; | ||
}); | ||
this.executionManager = new ExecutionManager(); | ||
this.statusManager = statusManager; | ||
@@ -84,0 +59,0 @@ this.settings = settings; |
@@ -45,3 +45,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
catch (error) { | ||
switchProcess = statusManager.updateProcess(step, switchProcess.type, 'FAILED', { | ||
statusManager.updateProcess(step, switchProcess.type, 'FAILED', { | ||
error: { | ||
@@ -48,0 +48,0 @@ message: error.message, |
@@ -6,2 +6,2 @@ import { ProcessType, Status, StatusMessage, StatusResponse, Step, Substatus } from '@lifi/types'; | ||
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined; | ||
export declare function updatedStepMeetsSlippageConditions(oldStep: Step, newStep: Step): boolean; | ||
export declare function checkStepSlippageThreshold(oldStep: Step, newStep: Step): boolean; |
@@ -72,16 +72,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
SWAP: { | ||
STARTED: 'Preparing swap.', | ||
STARTED: 'Preparing swap transaction.', | ||
ACTION_REQUIRED: 'Please sign the transaction.', | ||
PENDING: 'Swapping.', | ||
PENDING: 'Waiting for swap transaction.', | ||
DONE: 'Swap completed.', | ||
}, | ||
CROSS_CHAIN: { | ||
STARTED: 'Preparing transaction.', | ||
STARTED: 'Preparing bridge transaction.', | ||
ACTION_REQUIRED: 'Please sign the transaction.', | ||
PENDING: 'Waiting for transaction.', | ||
DONE: 'Transaction approved.', | ||
PENDING: 'Waiting for bridge transaction.', | ||
DONE: 'Bridge transaction confirmed.', | ||
}, | ||
RECEIVING_CHAIN: { | ||
PENDING: 'Waiting for receiving chain.', | ||
DONE: 'Funds received.', | ||
PENDING: 'Waiting for destination chain.', | ||
DONE: 'Bridge completed.', | ||
}, | ||
@@ -119,3 +119,4 @@ TRANSACTION: {}, | ||
} | ||
export function updatedStepMeetsSlippageConditions(oldStep, newStep) { | ||
// Used to check if changed exchange rate is in the range of slippage threshold | ||
export function checkStepSlippageThreshold(oldStep, newStep) { | ||
const setSlippage = new BigNumber(oldStep.action.slippage); | ||
@@ -122,0 +123,0 @@ const oldEstimatedToAmount = new BigNumber(oldStep.estimate.toAmountMin); |
@@ -173,3 +173,3 @@ import { FallbackProvider } from '@ethersproject/providers'; | ||
* @param {{ [chainId: number]: Token[] }} tokensByChain - A list of Token objects organized by chain ids. | ||
* @return {Promise<{ [chainId: number]: TokenAmount[] }} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains. | ||
* @return {Promise<{ [chainId: number]: TokenAmount[] }>} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains. | ||
* @throws {ValidationError} Throws a ValidationError if parameters are invalid. | ||
@@ -176,0 +176,0 @@ */ |
@@ -11,3 +11,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { approveToken, bulkGetTokenApproval, getTokenApproval, revokeTokenApproval, } from './allowance'; | ||
import balances from './balances'; | ||
import * as balance from './balance'; | ||
import { getRpcProvider } from './connectors'; | ||
@@ -337,3 +337,3 @@ import { StatusManager } from './execution/StatusManager'; | ||
} | ||
return balances.getTokenBalance(walletAddress, token); | ||
return balance.getTokenBalance(walletAddress, token); | ||
}); | ||
@@ -355,3 +355,3 @@ /** | ||
} | ||
return balances.getTokenBalances(walletAddress, tokens); | ||
return balance.getTokenBalances(walletAddress, tokens); | ||
}); | ||
@@ -362,3 +362,3 @@ /** | ||
* @param {{ [chainId: number]: Token[] }} tokensByChain - A list of Token objects organized by chain ids. | ||
* @return {Promise<{ [chainId: number]: TokenAmount[] }} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains. | ||
* @return {Promise<{ [chainId: number]: TokenAmount[] }>} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains. | ||
* @throws {ValidationError} Throws a ValidationError if parameters are invalid. | ||
@@ -375,3 +375,3 @@ */ | ||
} | ||
return balances.getTokenBalancesForChains(walletAddress, tokensByChain); | ||
return balance.getTokenBalancesForChains(walletAddress, tokensByChain); | ||
}); | ||
@@ -378,0 +378,0 @@ /** |
@@ -16,2 +16,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
acceptSlippageUpdateHook: () => Promise.resolve(undefined), | ||
acceptExchangeRateUpdateHook: () => Promise.resolve(undefined), | ||
infiniteApproval: false, | ||
@@ -18,0 +19,0 @@ executeInBackground: false, |
@@ -11,3 +11,3 @@ import { Route, RouteOptions, Step, Token } from '@lifi/types'; | ||
} | ||
export declare type ParsedReceipt = { | ||
export type ParsedReceipt = { | ||
fromAmount?: string; | ||
@@ -20,3 +20,3 @@ toAmount: string; | ||
}; | ||
interface ExecutionParams { | ||
export interface ExecutionParams { | ||
signer: Signer; | ||
@@ -27,10 +27,4 @@ step: Step; | ||
} | ||
export interface ExecuteSwapParams extends ExecutionParams { | ||
step: Step; | ||
} | ||
export interface ExecuteCrossParams extends ExecutionParams { | ||
step: Step; | ||
} | ||
export declare type CallbackFunction = (updatedRoute: Route) => void; | ||
export declare type Config = { | ||
export type CallbackFunction = (updatedRoute: Route) => void; | ||
export type Config = { | ||
apiUrl: string; | ||
@@ -43,3 +37,3 @@ rpcs: Record<ChainId, string[]>; | ||
}; | ||
export declare type ConfigUpdate = { | ||
export type ConfigUpdate = { | ||
apiUrl?: string; | ||
@@ -52,3 +46,3 @@ rpcs?: Record<number, string[]>; | ||
}; | ||
export declare type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>; | ||
export type SwitchChainHook = (requiredChainId: number) => Promise<Signer | undefined>; | ||
export interface AcceptSlippageUpdateHookParams { | ||
@@ -61,3 +55,9 @@ toToken: Token; | ||
} | ||
export declare type AcceptSlippageUpdateHook = (params: AcceptSlippageUpdateHookParams) => Promise<boolean | undefined>; | ||
export type AcceptSlippageUpdateHook = (params: AcceptSlippageUpdateHookParams) => Promise<boolean | undefined>; | ||
export interface ExchangeRateUpdateParams { | ||
toToken: Token; | ||
oldToAmount: string; | ||
newToAmount: string; | ||
} | ||
export type AcceptExchangeRateUpdateHook = (params: ExchangeRateUpdateParams) => Promise<boolean | undefined>; | ||
export interface ExecutionData { | ||
@@ -68,17 +68,12 @@ route: Route; | ||
} | ||
export interface ExecutionSettings { | ||
updateCallback?: CallbackFunction; | ||
switchChainHook?: SwitchChainHook; | ||
acceptSlippageUpdateHook?: AcceptSlippageUpdateHook; | ||
infiniteApproval?: boolean; | ||
executeInBackground?: boolean; | ||
} | ||
export interface InternalExecutionSettings extends ExecutionSettings { | ||
export type ExecutionSettings = Partial<InternalExecutionSettings>; | ||
export interface InternalExecutionSettings { | ||
updateCallback: CallbackFunction; | ||
switchChainHook: SwitchChainHook; | ||
acceptSlippageUpdateHook: AcceptSlippageUpdateHook; | ||
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook; | ||
infiniteApproval: boolean; | ||
executeInBackground: boolean; | ||
} | ||
export declare type EnforcedObjectProperties<T> = T & { | ||
export type EnforcedObjectProperties<T> = T & { | ||
[P in keyof T]-?: T[P]; | ||
@@ -89,3 +84,3 @@ }; | ||
} | ||
export declare type RevokeTokenData = { | ||
export type RevokeTokenData = { | ||
token: Token; | ||
@@ -99,2 +94,1 @@ approvalAddress: string; | ||
} | ||
export {}; |
@@ -22,5 +22,6 @@ declare enum ErrorType { | ||
GasLimitError = 1009, | ||
SlippageNotMet = 1010, | ||
TransactionCanceled = 1010, | ||
SlippageError = 1011, | ||
TransactionRejected = 1012 | ||
TransactionRejected = 1012, | ||
BalanceError = 1013 | ||
} | ||
@@ -47,3 +48,3 @@ export declare enum MetaMaskRPCErrorCode { | ||
} | ||
export declare type ErrorCode = LifiErrorCode | MetaMaskRPCErrorCode | MetaMaskProviderErrorCode; | ||
export type ErrorCode = LifiErrorCode | MetaMaskRPCErrorCode | MetaMaskProviderErrorCode; | ||
export declare class LifiError extends Error { | ||
@@ -72,2 +73,5 @@ code: ErrorCode; | ||
} | ||
export declare class BalanceError extends LifiError { | ||
constructor(message: string, htmlMessage?: string, stack?: string); | ||
} | ||
export declare class NotFoundError extends LifiError { | ||
@@ -74,0 +78,0 @@ constructor(message: string, htmlMessage?: string, stack?: string); |
@@ -24,5 +24,6 @@ var ErrorType; | ||
LifiErrorCode[LifiErrorCode["GasLimitError"] = 1009] = "GasLimitError"; | ||
LifiErrorCode[LifiErrorCode["SlippageNotMet"] = 1010] = "SlippageNotMet"; | ||
LifiErrorCode[LifiErrorCode["TransactionCanceled"] = 1010] = "TransactionCanceled"; | ||
LifiErrorCode[LifiErrorCode["SlippageError"] = 1011] = "SlippageError"; | ||
LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected"; | ||
LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError"; | ||
})(LifiErrorCode || (LifiErrorCode = {})); | ||
@@ -96,2 +97,7 @@ export var MetaMaskRPCErrorCode; | ||
} | ||
export class BalanceError extends LifiError { | ||
constructor(message, htmlMessage, stack) { | ||
super(ErrorType.ValidationError, LifiErrorCode.BalanceError, message, htmlMessage, stack); | ||
} | ||
} | ||
export class NotFoundError extends LifiError { | ||
@@ -98,0 +104,0 @@ constructor(message, htmlMessage, stack) { |
import { Fragment, JsonFragment } from '@ethersproject/abi'; | ||
export declare type MultiCallData = { | ||
export type MultiCallData = { | ||
address: string; | ||
@@ -4,0 +4,0 @@ name: string; |
@@ -38,2 +38,1 @@ import { Process, Step } from '@lifi/types'; | ||
export declare const parseBackendError: (e: any) => LifiError; | ||
export declare const getSlippageNotMetMessage: (step: Step) => string; |
@@ -128,6 +128,1 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
export const getSlippageNotMetMessage = (step) => { | ||
const { slippage } = step.action; | ||
return `Transaction was not sent, your funds are still in your wallet. | ||
The updated quote for the current transaction does not meet your set slippage of ${slippage * 100}%.`; | ||
}; |
export declare const name = "@lifi/sdk"; | ||
export declare const version = "1.6.4"; | ||
export declare const version = "1.7.0"; |
export const name = '@lifi/sdk'; | ||
export const version = '1.6.4'; | ||
export const version = '1.7.0'; |
{ | ||
"name": "@lifi/sdk", | ||
"version": "1.6.4", | ||
"version": "1.7.0", | ||
"description": "LI.FI Any-to-Any Cross-Chain-Swap SDK", | ||
@@ -79,3 +79,3 @@ "main": "./dist/cjs/index.js", | ||
"@ethersproject/contracts": "^5.7.0", | ||
"@lifi/types": "^1.16.0", | ||
"@lifi/types": "^1.18.0", | ||
"axios": "^1.1.3", | ||
@@ -87,25 +87,23 @@ "bignumber.js": "^9.1.0", | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.1.2", | ||
"@commitlint/config-conventional": "^17.1.0", | ||
"@types/chai": "^4.3.3", | ||
"@commitlint/cli": "^17.3.0", | ||
"@commitlint/config-conventional": "^17.3.0", | ||
"@types/chai": "^4.3.4", | ||
"@types/hdkey": "^2.0.0", | ||
"@types/jest": "^29.2.0", | ||
"@types/jest": "^29.2.3", | ||
"@types/websocket": "^1.0.4", | ||
"@typescript-eslint/eslint-plugin": "^5.41.0", | ||
"@typescript-eslint/parser": "^5.41.0", | ||
"eslint": "^8.26.0", | ||
"@typescript-eslint/eslint-plugin": "^5.44.0", | ||
"@typescript-eslint/parser": "^5.44.0", | ||
"eslint": "^8.28.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"husky": "^8.0.1", | ||
"jest": "^29.2.2", | ||
"husky": "^8.0.2", | ||
"jest": "^29.3.1", | ||
"lint-staged": "^13.0.3", | ||
"npm-run-all": "^4.1.5", | ||
"pinst": "^3.0.0", | ||
"prettier": "^2.7.1", | ||
"prettier": "^2.8.0", | ||
"standard-version": "^9.5.0", | ||
"ts-jest": "^29.0.3", | ||
"ts-loader": "^9.4.1", | ||
"typescript": "^4.8.4", | ||
"webpack": "^5.73.0", | ||
"webpack-cli": "^4.10.0" | ||
"typescript": "^4.9.3" | ||
}, | ||
@@ -112,0 +110,0 @@ "directories": { |
21
138
397343
7662
Updated@lifi/types@^1.18.0