@lifi/sdk 2.0.0-beta.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LiFi.d.ts +9 -9
- package/dist/LiFi.js +11 -11
- package/dist/allowance/checkAllowance.js +4 -2
- package/dist/cjs/LiFi.d.ts +9 -9
- package/dist/cjs/LiFi.js +12 -13
- package/dist/cjs/allowance/checkAllowance.js +4 -2
- package/dist/cjs/connectors.d.ts +1 -1
- package/dist/cjs/connectors.js +7 -9
- package/dist/cjs/execution/RouteExecutionManager.d.ts +1 -1
- package/dist/cjs/execution/RouteExecutionManager.js +1 -1
- package/dist/cjs/execution/StatusManager.js +1 -1
- package/dist/cjs/execution/StepExecutionManager.js +16 -2
- package/dist/cjs/execution/StepExecutor.js +13 -5
- package/dist/cjs/execution/stepComparison.d.ts +1 -1
- package/dist/cjs/execution/stepComparison.js +2 -5
- package/dist/cjs/execution/utils.js +5 -1
- package/dist/cjs/helpers.d.ts +2 -0
- package/dist/cjs/helpers.js +6 -1
- package/dist/cjs/services/ApiService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.d.ts +1 -1
- package/dist/cjs/services/ConfigService.js +1 -2
- package/dist/cjs/typeguards.d.ts +2 -2
- package/dist/cjs/types/internal.types.d.ts +6 -10
- package/dist/cjs/utils/errors.d.ts +4 -2
- package/dist/cjs/utils/errors.js +9 -7
- package/dist/cjs/utils/parseError.js +19 -11
- package/dist/cjs/utils/preRestart.d.ts +2 -1
- package/dist/cjs/utils/preRestart.js +24 -3
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +1 -1
- package/dist/connectors.js +7 -9
- package/dist/execution/RouteExecutionManager.d.ts +1 -1
- package/dist/execution/RouteExecutionManager.js +1 -1
- package/dist/execution/StatusManager.js +1 -1
- package/dist/execution/StepExecutionManager.js +16 -2
- package/dist/execution/StepExecutor.js +13 -5
- package/dist/execution/stepComparison.d.ts +1 -1
- package/dist/execution/stepComparison.js +2 -5
- package/dist/execution/utils.js +5 -1
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +4 -0
- package/dist/services/ApiService.d.ts +1 -1
- package/dist/services/ConfigService.d.ts +1 -1
- package/dist/services/ConfigService.js +1 -2
- package/dist/typeguards.d.ts +2 -2
- package/dist/types/internal.types.d.ts +6 -10
- package/dist/utils/errors.d.ts +4 -2
- package/dist/utils/errors.js +3 -1
- package/dist/utils/parseError.js +20 -12
- package/dist/utils/preRestart.d.ts +2 -1
- package/dist/utils/preRestart.js +24 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -15
- package/dist/cjs/services/ApiService.unit.handlers.d.ts +0 -1
- package/dist/cjs/services/ApiService.unit.handlers.js +0 -50
- package/dist/services/ApiService.unit.handlers.d.ts +0 -1
- package/dist/services/ApiService.unit.handlers.js +0 -44
|
@@ -2,24 +2,45 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlePreRestart = void 0;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
|
-
const handlePreRestart = (route) => {
|
|
5
|
+
const handlePreRestart = async (route, signer) => {
|
|
6
6
|
for (let index = 0; index < route.steps.length; index++) {
|
|
7
7
|
const stepHasFailed = route.steps[index].execution?.status === 'FAILED';
|
|
8
8
|
if (stepHasFailed) {
|
|
9
|
-
handleErrorType(route, index);
|
|
9
|
+
await handleErrorType(route, index, signer);
|
|
10
10
|
deleteFailedProcesses(route, index);
|
|
11
11
|
deleteTransactionData(route, index);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
exports.handlePreRestart = handlePreRestart;
|
|
16
|
-
const handleErrorType = (route, index) => {
|
|
16
|
+
const handleErrorType = async (route, index, signer) => {
|
|
17
17
|
const isGasLimitError = route.steps[index].execution?.process.some((p) => p.error?.code === errors_1.LifiErrorCode.GasLimitError);
|
|
18
18
|
const isGasPriceError = route.steps[index].execution?.process.some((p) => p.error?.code === errors_1.LifiErrorCode.TransactionUnderpriced);
|
|
19
|
+
const { transactionRequest } = route.steps[index];
|
|
19
20
|
if (isGasLimitError) {
|
|
21
|
+
if (transactionRequest) {
|
|
22
|
+
let gasLimit = transactionRequest.gasLimit;
|
|
23
|
+
try {
|
|
24
|
+
gasLimit = await signer.estimateGas(transactionRequest);
|
|
25
|
+
}
|
|
26
|
+
catch (error) { }
|
|
27
|
+
if (gasLimit) {
|
|
28
|
+
transactionRequest.gasLimit = `${(BigInt(gasLimit.toString()) * 125n) / 100n}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
20
31
|
route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
|
|
21
32
|
}
|
|
22
33
|
if (isGasPriceError) {
|
|
34
|
+
if (transactionRequest) {
|
|
35
|
+
let gasPrice = transactionRequest.gasPrice;
|
|
36
|
+
try {
|
|
37
|
+
gasPrice = await signer.getGasPrice();
|
|
38
|
+
}
|
|
39
|
+
catch (error) { }
|
|
40
|
+
if (gasPrice) {
|
|
41
|
+
transactionRequest.gasPrice = `${(BigInt(gasPrice.toString()) * 125n) / 100n}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
23
44
|
route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`));
|
|
24
45
|
}
|
|
25
46
|
};
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.0.
|
|
2
|
+
export declare const version = "2.0.1";
|
package/dist/cjs/version.js
CHANGED
package/dist/connectors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChainId } from './types';
|
|
2
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
+
import { ChainId } from './types';
|
|
3
3
|
export declare const getRpcUrl: (chainId: ChainId, archive?: boolean) => Promise<string>;
|
|
4
4
|
export declare const getRpcUrls: (chainId: ChainId, archive?: boolean) => Promise<string[]>;
|
|
5
5
|
export declare const getRpcProvider: (chainId: number, archive?: boolean) => Promise<FallbackProvider>;
|
package/dist/connectors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ChainId } from './types';
|
|
3
|
-
import ConfigService from './services/ConfigService';
|
|
1
|
+
import { FallbackProvider, StaticJsonRpcProvider, } from '@ethersproject/providers';
|
|
4
2
|
import { getRandomNumber } from './helpers';
|
|
3
|
+
import ConfigService from './services/ConfigService';
|
|
4
|
+
import { ChainId } from './types';
|
|
5
5
|
import { ServerError } from './utils/errors';
|
|
6
6
|
// cached providers
|
|
7
7
|
const chainProviders = {};
|
|
@@ -33,17 +33,15 @@ const getRandomProvider = (providerList) => {
|
|
|
33
33
|
export const getRpcProvider = async (chainId, archive = false) => {
|
|
34
34
|
if (archive && archiveRpcs[chainId]) {
|
|
35
35
|
// return archive PRC, but don't cache it
|
|
36
|
-
return new
|
|
37
|
-
new
|
|
36
|
+
return new FallbackProvider([
|
|
37
|
+
new StaticJsonRpcProvider(await getRpcUrl(chainId, archive), chainId),
|
|
38
38
|
]);
|
|
39
39
|
}
|
|
40
|
-
if (!chainProviders[chainId]) {
|
|
40
|
+
if (!chainProviders[chainId]?.length) {
|
|
41
41
|
chainProviders[chainId] = [];
|
|
42
42
|
const urls = await getRpcUrls(chainId, archive);
|
|
43
43
|
urls.forEach((url) => {
|
|
44
|
-
chainProviders[chainId].push(new
|
|
45
|
-
new providers.StaticJsonRpcProvider(url, chainId),
|
|
46
|
-
]));
|
|
44
|
+
chainProviders[chainId].push(new FallbackProvider([new StaticJsonRpcProvider(url, chainId)]));
|
|
47
45
|
});
|
|
48
46
|
}
|
|
49
47
|
if (!chainProviders[chainId].length) {
|
|
@@ -6,7 +6,7 @@ export declare class RouteExecutionManager {
|
|
|
6
6
|
private executionDictionary;
|
|
7
7
|
private executionPromiseDictionary;
|
|
8
8
|
protected configService: ConfigService;
|
|
9
|
-
constructor(configUpdate
|
|
9
|
+
constructor(configUpdate: ConfigUpdate);
|
|
10
10
|
/**
|
|
11
11
|
* Execute a route.
|
|
12
12
|
* @param {Signer} signer - The signer required to send the transactions.
|
|
@@ -50,7 +50,7 @@ export class RouteExecutionManager {
|
|
|
50
50
|
return executionPromise ?? clonedRoute;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
handlePreRestart(clonedRoute);
|
|
53
|
+
await handlePreRestart(clonedRoute, signer);
|
|
54
54
|
const executionPromise = this.executeSteps(signer, clonedRoute, settings);
|
|
55
55
|
this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
|
|
56
56
|
return executionPromise;
|
|
@@ -133,7 +133,7 @@ export class StatusManager {
|
|
|
133
133
|
throw new Error("Couldn't find a step to update.");
|
|
134
134
|
}
|
|
135
135
|
this.route.steps[stepIndex] = Object.assign(this.route.steps[stepIndex], step);
|
|
136
|
-
this.settings.
|
|
136
|
+
this.settings.updateRouteHook(this.route);
|
|
137
137
|
this.internalUpdateRouteCallback(this.route);
|
|
138
138
|
return this.route.steps[stepIndex];
|
|
139
139
|
};
|
|
@@ -75,14 +75,28 @@ export class StepExecutionManager {
|
|
|
75
75
|
if (!this.allowUserInteraction) {
|
|
76
76
|
return step.execution;
|
|
77
77
|
}
|
|
78
|
-
if (settings.
|
|
79
|
-
const customConfig = await settings.
|
|
78
|
+
if (settings.updateTransactionRequestHook) {
|
|
79
|
+
const customConfig = await settings.updateTransactionRequestHook(transactionRequest);
|
|
80
80
|
transactionRequest.gasLimit = customConfig.gasLimit;
|
|
81
81
|
transactionRequest.gasPrice = customConfig.gasPrice;
|
|
82
82
|
transactionRequest.maxPriorityFeePerGas =
|
|
83
83
|
customConfig.maxPriorityFeePerGas;
|
|
84
84
|
transactionRequest.maxFeePerGas = customConfig.maxFeePerGas;
|
|
85
85
|
}
|
|
86
|
+
else {
|
|
87
|
+
try {
|
|
88
|
+
const estimatedGasLimit = await signer.estimateGas(transactionRequest);
|
|
89
|
+
if (estimatedGasLimit) {
|
|
90
|
+
transactionRequest.gasLimit = `${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`;
|
|
91
|
+
}
|
|
92
|
+
// Fetch latest gasPrice from provider and use it
|
|
93
|
+
const gasPrice = await signer.getGasPrice();
|
|
94
|
+
if (gasPrice) {
|
|
95
|
+
transactionRequest.gasPrice = gasPrice;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) { }
|
|
99
|
+
}
|
|
86
100
|
// Submit the transaction
|
|
87
101
|
transaction = await signer.sendTransaction(transactionRequest);
|
|
88
102
|
// STEP 4: Wait for the transaction
|
|
@@ -28,12 +28,20 @@ export class StepExecutor {
|
|
|
28
28
|
};
|
|
29
29
|
this.executeStep = async (signer, step) => {
|
|
30
30
|
// Make sure that the chain is still correct
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
// Find if it's bridging and the step is waiting for a transaction on the receiving chain
|
|
32
|
+
const recievingChainProcess = step.execution?.process.find((process) => process.type === 'RECEIVING_CHAIN');
|
|
33
|
+
// If the step is waiting for a transaction on the receiving chain, we do not switch the chain
|
|
34
|
+
// All changes are already done from the source chain
|
|
35
|
+
// Return the step
|
|
36
|
+
if (recievingChainProcess?.substatus !== 'WAIT_DESTINATION_TRANSACTION' ||
|
|
37
|
+
!recievingChainProcess) {
|
|
38
|
+
const updatedSigner = await switchChain(signer, this.statusManager, step, this.settings.switchChainHook, this.allowUserInteraction);
|
|
39
|
+
if (!updatedSigner) {
|
|
40
|
+
// Chain switch was not successful, stop execution here
|
|
41
|
+
return step;
|
|
42
|
+
}
|
|
43
|
+
signer = updatedSigner;
|
|
35
44
|
}
|
|
36
|
-
signer = updatedSigner;
|
|
37
45
|
const parameters = {
|
|
38
46
|
signer,
|
|
39
47
|
step,
|
|
@@ -8,7 +8,7 @@ import { InternalExecutionSettings, LifiStep } from '../types';
|
|
|
8
8
|
* @param statusManager
|
|
9
9
|
* @param oldStep
|
|
10
10
|
* @param newStep
|
|
11
|
-
* @param
|
|
11
|
+
* @param settings
|
|
12
12
|
* @param allowUserInteraction
|
|
13
13
|
*/
|
|
14
14
|
export declare const stepComparison: (statusManager: StatusManager, oldStep: LifiStep, newStep: LifiStep, settings: InternalExecutionSettings, allowUserInteraction: boolean) => Promise<LifiStep>;
|
|
@@ -8,7 +8,7 @@ import { checkStepSlippageThreshold } from './utils';
|
|
|
8
8
|
* @param statusManager
|
|
9
9
|
* @param oldStep
|
|
10
10
|
* @param newStep
|
|
11
|
-
* @param
|
|
11
|
+
* @param settings
|
|
12
12
|
* @param allowUserInteraction
|
|
13
13
|
*/
|
|
14
14
|
export const stepComparison = async (statusManager, oldStep, newStep, settings, allowUserInteraction) => {
|
|
@@ -16,15 +16,12 @@ export const stepComparison = async (statusManager, oldStep, newStep, settings,
|
|
|
16
16
|
if (checkStepSlippageThreshold(oldStep, newStep)) {
|
|
17
17
|
return statusManager.updateStepInRoute(newStep);
|
|
18
18
|
}
|
|
19
|
-
const acceptExchangeRateUpdateHook = settings.acceptExchangeRateUpdateHook ?? settings.acceptSlippageUpdateHook;
|
|
20
19
|
let allowStepUpdate;
|
|
21
20
|
if (allowUserInteraction) {
|
|
22
|
-
allowStepUpdate = await acceptExchangeRateUpdateHook({
|
|
21
|
+
allowStepUpdate = await settings.acceptExchangeRateUpdateHook({
|
|
23
22
|
oldToAmount: oldStep.estimate.toAmount,
|
|
24
23
|
newToAmount: newStep.estimate.toAmount,
|
|
25
24
|
toToken: newStep.action.toToken,
|
|
26
|
-
oldSlippage: oldStep.action.slippage,
|
|
27
|
-
newSlippage: newStep.action.slippage,
|
|
28
25
|
});
|
|
29
26
|
}
|
|
30
27
|
if (!allowStepUpdate) {
|
package/dist/execution/utils.js
CHANGED
|
@@ -114,7 +114,11 @@ export function checkStepSlippageThreshold(oldStep, newStep) {
|
|
|
114
114
|
const oldEstimatedToAmount = new BigNumber(oldStep.estimate.toAmountMin);
|
|
115
115
|
const newEstimatedToAmount = new BigNumber(newStep.estimate.toAmountMin);
|
|
116
116
|
const amountDifference = oldEstimatedToAmount.minus(newEstimatedToAmount);
|
|
117
|
-
|
|
117
|
+
// oldEstimatedToAmount can be 0 when we use conract calls
|
|
118
|
+
let actualSlippage = new BigNumber(0);
|
|
119
|
+
if (oldEstimatedToAmount.gt(0)) {
|
|
120
|
+
actualSlippage = amountDifference.dividedBy(oldEstimatedToAmount);
|
|
121
|
+
}
|
|
118
122
|
return (newEstimatedToAmount.gte(oldEstimatedToAmount) &&
|
|
119
123
|
actualSlippage.lte(setSlippage));
|
|
120
124
|
}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LifiStep, Route, Token } from '@lifi/types';
|
|
2
|
+
import { TenderlyResponse } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Predefined hook that decrypts calldata using EIP-1193 compliant wallet functions.
|
|
4
5
|
* @param {string} walletAddress - The wallet address of the user that should decrypt the calldata.
|
|
@@ -24,3 +25,4 @@ export declare const checkPackageUpdates: (packageName?: string, packageVersion?
|
|
|
24
25
|
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
25
26
|
*/
|
|
26
27
|
export declare const convertQuoteToRoute: (step: LifiStep) => Route;
|
|
28
|
+
export declare const fetchTxErrorDetails: (txHash: string, chainId: number) => Promise<TenderlyResponse>;
|
package/dist/helpers.js
CHANGED
|
@@ -100,3 +100,7 @@ export const convertQuoteToRoute = (step) => {
|
|
|
100
100
|
};
|
|
101
101
|
return route;
|
|
102
102
|
};
|
|
103
|
+
export const fetchTxErrorDetails = async (txHash, chainId) => {
|
|
104
|
+
const response = await request(`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`);
|
|
105
|
+
return response;
|
|
106
|
+
};
|
|
@@ -9,7 +9,7 @@ declare const _default: {
|
|
|
9
9
|
getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
10
10
|
getStatus: (requestConfig: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
11
11
|
getStepTransaction: (step: LifiStep, options?: RequestOptions | undefined) => Promise<LifiStep>;
|
|
12
|
-
getToken: (chain:
|
|
12
|
+
getToken: (chain: ChainId | ChainKey, token: string, options?: RequestOptions | undefined) => Promise<Token>;
|
|
13
13
|
getTokens: (requestConfig?: TokensRequest | undefined, options?: RequestOptions | undefined) => Promise<TokensResponse>;
|
|
14
14
|
getTools: (requestConfig?: ToolsRequest | undefined, options?: RequestOptions | undefined) => Promise<ToolsResponse>;
|
|
15
15
|
getAvailableConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
|
@@ -18,6 +18,6 @@ export default class ConfigService {
|
|
|
18
18
|
* Use this if you need access to chain data (RPCs or multicalls)
|
|
19
19
|
*/
|
|
20
20
|
getConfigAsync: () => Promise<Config>;
|
|
21
|
-
updateConfig: (configUpdate: ConfigUpdate) => Config;
|
|
21
|
+
updateConfig: (configUpdate: Partial<ConfigUpdate>) => Config;
|
|
22
22
|
updateChains: (chains: Chain[]) => Config;
|
|
23
23
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ChainId, } from '../types';
|
|
2
2
|
const DefaultExecutionSettings = {
|
|
3
3
|
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
|
|
4
|
-
|
|
4
|
+
updateRouteHook: () => { },
|
|
5
5
|
switchChainHook: () => Promise.resolve(undefined),
|
|
6
|
-
acceptSlippageUpdateHook: () => Promise.resolve(undefined),
|
|
7
6
|
acceptExchangeRateUpdateHook: () => Promise.resolve(undefined),
|
|
8
7
|
infiniteApproval: false,
|
|
9
8
|
executeInBackground: false,
|
package/dist/typeguards.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LifiStep, RoutesRequest,
|
|
1
|
+
import { LifiStep, RoutesRequest, StaticToken } from './types';
|
|
2
2
|
export declare const isRoutesRequest: (routesRequest: RoutesRequest) => routesRequest is RoutesRequest;
|
|
3
3
|
export declare const isStep: (step: LifiStep) => step is LifiStep;
|
|
4
|
-
export declare const isToken: (token:
|
|
4
|
+
export declare const isToken: (token: StaticToken) => token is StaticToken;
|
|
@@ -23,8 +23,8 @@ export interface ExecutionParams {
|
|
|
23
23
|
statusManager: StatusManager;
|
|
24
24
|
settings: InternalExecutionSettings;
|
|
25
25
|
}
|
|
26
|
-
export type
|
|
27
|
-
export type
|
|
26
|
+
export type UpdateRouteHook = (updatedRoute: Route) => void;
|
|
27
|
+
export type TransactionRequestUpdateHook = (updatedTxRequest: TransactionRequest) => Promise<TransactionRequest>;
|
|
28
28
|
export type Config = {
|
|
29
29
|
apiUrl: string;
|
|
30
30
|
rpcs: Record<ChainId, string[]>;
|
|
@@ -69,17 +69,13 @@ export interface RouteExecutionData {
|
|
|
69
69
|
}
|
|
70
70
|
export type ExecutionSettings = Partial<InternalExecutionSettings>;
|
|
71
71
|
export interface InternalExecutionSettings {
|
|
72
|
-
updateCallback: CallbackFunction;
|
|
73
|
-
switchChainHook: SwitchChainHook;
|
|
74
|
-
acceptSlippageUpdateHook: AcceptSlippageUpdateHook;
|
|
75
72
|
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook;
|
|
76
|
-
|
|
73
|
+
switchChainHook: SwitchChainHook;
|
|
74
|
+
updateRouteHook: UpdateRouteHook;
|
|
75
|
+
updateTransactionRequestHook?: TransactionRequestUpdateHook;
|
|
77
76
|
executeInBackground: boolean;
|
|
78
|
-
|
|
77
|
+
infiniteApproval: boolean;
|
|
79
78
|
}
|
|
80
|
-
export type EnforcedObjectProperties<T> = T & {
|
|
81
|
-
[P in keyof T]-?: T[P];
|
|
82
|
-
};
|
|
83
79
|
export type RouteExecutionDictionary = Partial<Record<string, RouteExecutionData>>;
|
|
84
80
|
export type RouteExecutionPromiseDictionary = Partial<Record<string, Promise<Route>>>;
|
|
85
81
|
export type RevokeTokenData = {
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -23,11 +23,13 @@ export declare enum LifiErrorCode {
|
|
|
23
23
|
SlippageError = 1011,
|
|
24
24
|
TransactionRejected = 1012,
|
|
25
25
|
BalanceError = 1013,
|
|
26
|
-
AllowanceRequired = 1014
|
|
26
|
+
AllowanceRequired = 1014,
|
|
27
|
+
InsufficientFunds = 1015
|
|
27
28
|
}
|
|
28
29
|
export declare enum EthersErrorType {
|
|
30
|
+
ActionRejected = "ACTION_REJECTED",
|
|
29
31
|
CallExecption = "CALL_EXCEPTION",
|
|
30
|
-
|
|
32
|
+
InsufficientFunds = "INSUFFICIENT_FUNDS"
|
|
31
33
|
}
|
|
32
34
|
export declare enum EthersErrorMessage {
|
|
33
35
|
ERC20Allowance = "ERC20: transfer amount exceeds allowance",
|
package/dist/utils/errors.js
CHANGED
|
@@ -26,11 +26,13 @@ export var LifiErrorCode;
|
|
|
26
26
|
LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected";
|
|
27
27
|
LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError";
|
|
28
28
|
LifiErrorCode[LifiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
|
|
29
|
+
LifiErrorCode[LifiErrorCode["InsufficientFunds"] = 1015] = "InsufficientFunds";
|
|
29
30
|
})(LifiErrorCode || (LifiErrorCode = {}));
|
|
30
31
|
export var EthersErrorType;
|
|
31
32
|
(function (EthersErrorType) {
|
|
32
|
-
EthersErrorType["CallExecption"] = "CALL_EXCEPTION";
|
|
33
33
|
EthersErrorType["ActionRejected"] = "ACTION_REJECTED";
|
|
34
|
+
EthersErrorType["CallExecption"] = "CALL_EXCEPTION";
|
|
35
|
+
EthersErrorType["InsufficientFunds"] = "INSUFFICIENT_FUNDS";
|
|
34
36
|
})(EthersErrorType || (EthersErrorType = {}));
|
|
35
37
|
export var EthersErrorMessage;
|
|
36
38
|
(function (EthersErrorMessage) {
|
package/dist/utils/parseError.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { errorCodes as MetaMaskErrorCodes, getMessageFromCode, } from 'eth-rpc-errors';
|
|
2
|
+
import { fetchTxErrorDetails } from '../helpers';
|
|
2
3
|
import ChainsService from '../services/ChainsService';
|
|
3
|
-
import { ErrorMessage,
|
|
4
|
+
import { ErrorMessage, EthersErrorMessage, EthersErrorType, LifiError, LifiErrorCode, MetaMaskProviderErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
|
|
4
5
|
import { formatTokenAmountOnly } from './utils';
|
|
5
6
|
/**
|
|
6
7
|
* Available MetaMask error codes:
|
|
@@ -89,10 +90,25 @@ export const parseError = async (e, step, process) => {
|
|
|
89
90
|
}
|
|
90
91
|
switch (e.code) {
|
|
91
92
|
case EthersErrorType.CallExecption:
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
const defaultErrorMessage = await getTransactionNotSentMessage(step, process);
|
|
94
|
+
try {
|
|
95
|
+
if (!step?.action.fromChainId) {
|
|
96
|
+
throw new Error('Signer is not defined.');
|
|
97
|
+
}
|
|
98
|
+
const response = await fetchTxErrorDetails(e.transactionHash, step?.action.fromChainId);
|
|
99
|
+
const errorMessage = response?.error_message ?? e.reason;
|
|
100
|
+
const isAllowanceError = response?.error_message?.includes(EthersErrorMessage.ERC20Allowance) || e.reason?.includes(EthersErrorMessage.ERC20Allowance);
|
|
101
|
+
if (isAllowanceError) {
|
|
102
|
+
return new TransactionError(LifiErrorCode.AllowanceRequired, e.reason, errorMessage, e.stack);
|
|
103
|
+
}
|
|
104
|
+
// Error messages other than allowance error will be handled in catch block
|
|
105
|
+
throw new Error(e);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return new ProviderError(LifiErrorCode.TransactionFailed, e.reason, defaultErrorMessage, e.stack);
|
|
94
109
|
}
|
|
95
|
-
|
|
110
|
+
case EthersErrorType.InsufficientFunds:
|
|
111
|
+
return new TransactionError(LifiErrorCode.InsufficientFunds, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
96
112
|
case EthersErrorType.ActionRejected:
|
|
97
113
|
case MetaMaskProviderErrorCode.userRejectedRequest:
|
|
98
114
|
return new TransactionError(LifiErrorCode.TransactionRejected, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
@@ -126,11 +142,3 @@ export const parseBackendError = async (e) => {
|
|
|
126
142
|
}
|
|
127
143
|
return new ServerError(ErrorMessage.Default, undefined, e.stack);
|
|
128
144
|
};
|
|
129
|
-
// const fetchTxErrorDetails = async (txHash: string, chainId: number) => {
|
|
130
|
-
// const response = await request<TenderlyResponse>(
|
|
131
|
-
// `https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`,
|
|
132
|
-
// undefined,
|
|
133
|
-
// 0
|
|
134
|
-
// )
|
|
135
|
-
// return response
|
|
136
|
-
// }
|
package/dist/utils/preRestart.js
CHANGED
|
@@ -1,21 +1,42 @@
|
|
|
1
1
|
import { LifiErrorCode } from './errors';
|
|
2
|
-
export const handlePreRestart = (route) => {
|
|
2
|
+
export const handlePreRestart = async (route, signer) => {
|
|
3
3
|
for (let index = 0; index < route.steps.length; index++) {
|
|
4
4
|
const stepHasFailed = route.steps[index].execution?.status === 'FAILED';
|
|
5
5
|
if (stepHasFailed) {
|
|
6
|
-
handleErrorType(route, index);
|
|
6
|
+
await handleErrorType(route, index, signer);
|
|
7
7
|
deleteFailedProcesses(route, index);
|
|
8
8
|
deleteTransactionData(route, index);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
const handleErrorType = (route, index) => {
|
|
12
|
+
const handleErrorType = async (route, index, signer) => {
|
|
13
13
|
const isGasLimitError = route.steps[index].execution?.process.some((p) => p.error?.code === LifiErrorCode.GasLimitError);
|
|
14
14
|
const isGasPriceError = route.steps[index].execution?.process.some((p) => p.error?.code === LifiErrorCode.TransactionUnderpriced);
|
|
15
|
+
const { transactionRequest } = route.steps[index];
|
|
15
16
|
if (isGasLimitError) {
|
|
17
|
+
if (transactionRequest) {
|
|
18
|
+
let gasLimit = transactionRequest.gasLimit;
|
|
19
|
+
try {
|
|
20
|
+
gasLimit = await signer.estimateGas(transactionRequest);
|
|
21
|
+
}
|
|
22
|
+
catch (error) { }
|
|
23
|
+
if (gasLimit) {
|
|
24
|
+
transactionRequest.gasLimit = `${(BigInt(gasLimit.toString()) * 125n) / 100n}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
16
27
|
route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`));
|
|
17
28
|
}
|
|
18
29
|
if (isGasPriceError) {
|
|
30
|
+
if (transactionRequest) {
|
|
31
|
+
let gasPrice = transactionRequest.gasPrice;
|
|
32
|
+
try {
|
|
33
|
+
gasPrice = await signer.getGasPrice();
|
|
34
|
+
}
|
|
35
|
+
catch (error) { }
|
|
36
|
+
if (gasPrice) {
|
|
37
|
+
transactionRequest.gasPrice = `${(BigInt(gasPrice.toString()) * 125n) / 100n}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
19
40
|
route.steps[index].estimate.gasCosts?.forEach((gasCost) => (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`));
|
|
20
41
|
}
|
|
21
42
|
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.0.
|
|
2
|
+
export declare const version = "2.0.1";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk';
|
|
2
|
-
export const version = '2.0.
|
|
2
|
+
export const version = '2.0.1';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -76,34 +76,34 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@ethersproject/abi": "^5.7.0",
|
|
78
78
|
"@ethersproject/contracts": "^5.7.0",
|
|
79
|
-
"@lifi/types": "^
|
|
79
|
+
"@lifi/types": "^6.0.0",
|
|
80
80
|
"bignumber.js": "^9.1.1",
|
|
81
81
|
"eth-rpc-errors": "^4.0.3",
|
|
82
82
|
"ethers": "^5.7.2"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@commitlint/cli": "^17.6.
|
|
86
|
-
"@commitlint/config-conventional": "^17.6.
|
|
87
|
-
"@
|
|
88
|
-
"@typescript-eslint/
|
|
89
|
-
"@
|
|
90
|
-
"
|
|
91
|
-
"
|
|
85
|
+
"@commitlint/cli": "^17.6.5",
|
|
86
|
+
"@commitlint/config-conventional": "^17.6.5",
|
|
87
|
+
"@mswjs/interceptors": "^0.22.15",
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
|
89
|
+
"@typescript-eslint/parser": "^5.59.9",
|
|
90
|
+
"@vitest/coverage-c8": "^0.32.0",
|
|
91
|
+
"cross-fetch": "^3.1.6",
|
|
92
|
+
"eslint": "^8.42.0",
|
|
92
93
|
"eslint-config-prettier": "^8.8.0",
|
|
93
94
|
"eslint-plugin-prettier": "^4.2.1",
|
|
94
95
|
"husky": "^8.0.3",
|
|
95
|
-
"lint-staged": "^13.2.
|
|
96
|
+
"lint-staged": "^13.2.2",
|
|
96
97
|
"msw": "1.0.1",
|
|
97
98
|
"npm-run-all": "^4.1.5",
|
|
98
99
|
"pinst": "^3.0.0",
|
|
99
|
-
"prettier": "^2.8.
|
|
100
|
+
"prettier": "^2.8.8",
|
|
100
101
|
"standard-version": "^9.5.0",
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"vitest": "^0.30.1"
|
|
102
|
+
"typescript": "^5.1.3",
|
|
103
|
+
"vitest": "^0.32.0"
|
|
104
104
|
},
|
|
105
105
|
"directories": {
|
|
106
106
|
"test": "test"
|
|
107
107
|
},
|
|
108
|
-
"packageManager": "yarn@3.5.
|
|
108
|
+
"packageManager": "yarn@3.5.1"
|
|
109
109
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const handlers: import("msw").RestHandler<import("msw/lib/glossary-de6278a9").M<import("msw/lib/glossary-de6278a9").h>>[];
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.handlers = void 0;
|
|
7
|
-
const types_1 = require("@lifi/types");
|
|
8
|
-
const msw_1 = require("msw");
|
|
9
|
-
const ConfigService_1 = __importDefault(require("./ConfigService"));
|
|
10
|
-
const config = ConfigService_1.default.getInstance().getConfig();
|
|
11
|
-
exports.handlers = [
|
|
12
|
-
msw_1.rest.post(`${config.apiUrl}/advanced/routes`, async (request, response, context) => {
|
|
13
|
-
const data = await request.json();
|
|
14
|
-
if (isNaN(parseFloat(data.fromAmount))) {
|
|
15
|
-
return response(context.status(500), context.json({ message: `Oops` }));
|
|
16
|
-
}
|
|
17
|
-
return response(context.json({}));
|
|
18
|
-
}),
|
|
19
|
-
msw_1.rest.post(`${config.apiUrl}/advanced/possibilities`, async (request, response, context) => {
|
|
20
|
-
return response(context.json({}));
|
|
21
|
-
}),
|
|
22
|
-
msw_1.rest.get(`${config.apiUrl}/token`, async (request, response, context) => {
|
|
23
|
-
return response(context.json({}));
|
|
24
|
-
}),
|
|
25
|
-
msw_1.rest.get(`${config.apiUrl}/quote`, async (request, response, context) => {
|
|
26
|
-
return response(context.json({}));
|
|
27
|
-
}),
|
|
28
|
-
msw_1.rest.get(`${config.apiUrl}/status`, async (request, response, context) => {
|
|
29
|
-
return response(context.json({}));
|
|
30
|
-
}),
|
|
31
|
-
msw_1.rest.get(`${config.apiUrl}/chains`, async (request, response, context) => {
|
|
32
|
-
return response(context.json({ chains: [{ id: 1 }] }));
|
|
33
|
-
}),
|
|
34
|
-
msw_1.rest.get(`${config.apiUrl}/tools`, async (request, response, context) => {
|
|
35
|
-
return response(context.json({ bridges: [], exchanges: [] }));
|
|
36
|
-
}),
|
|
37
|
-
msw_1.rest.get(`${config.apiUrl}/tokens`, async (request, response, context) => {
|
|
38
|
-
return response(context.json({
|
|
39
|
-
tokens: {
|
|
40
|
-
[types_1.ChainId.ETH]: [(0, types_1.findDefaultToken)(types_1.CoinKey.ETH, types_1.ChainId.ETH)],
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
}),
|
|
44
|
-
msw_1.rest.post(`${config.apiUrl}/advanced/stepTransaction`, async (request, response, context) => {
|
|
45
|
-
return response(context.json({}));
|
|
46
|
-
}),
|
|
47
|
-
msw_1.rest.get(`${config.apiUrl}/gas/suggestion/${types_1.ChainId.OPT}`, async (request, response, context) => {
|
|
48
|
-
return response(context.json({}));
|
|
49
|
-
}),
|
|
50
|
-
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const handlers: import("msw").RestHandler<import("msw/lib/glossary-de6278a9").M<import("msw/lib/glossary-de6278a9").h>>[];
|