@lifi/sdk 2.0.0-beta.10 → 2.0.0-beta.12
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/StatusManager.js +1 -1
- package/dist/cjs/execution/StepExecutionManager.js +2 -2
- package/dist/cjs/execution/stepComparison.d.ts +1 -1
- package/dist/cjs/execution/stepComparison.js +2 -5
- 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/parseError.js +17 -11
- 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/StatusManager.js +1 -1
- package/dist/execution/StepExecutionManager.js +2 -2
- package/dist/execution/stepComparison.d.ts +1 -1
- package/dist/execution/stepComparison.js +2 -5
- 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/parseError.js +17 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +12 -12
package/dist/LiFi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
|
6
6
|
import { Config, ConfigUpdate, RevokeTokenData } from './types';
|
|
7
7
|
export declare class LiFi extends RouteExecutionManager {
|
|
8
8
|
private chainsService;
|
|
9
|
-
constructor(configUpdate
|
|
9
|
+
constructor(configUpdate: ConfigUpdate);
|
|
10
10
|
/**
|
|
11
11
|
* Get the current configuration of the SDK
|
|
12
12
|
* @return {Config} - The config object
|
|
@@ -18,7 +18,7 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
18
18
|
*/
|
|
19
19
|
getConfigAsync: () => Promise<Config>;
|
|
20
20
|
/**
|
|
21
|
-
* Get an instance of a provider for a specific
|
|
21
|
+
* Get an instance of a provider for a specific chain
|
|
22
22
|
* @param {number} chainId - Id of the chain the provider is for
|
|
23
23
|
* @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
|
|
24
24
|
* @return {FallbackProvider} The provider for the given chain
|
|
@@ -29,7 +29,7 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
29
29
|
* @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
|
|
30
30
|
* @return {Config} The renewed config object
|
|
31
31
|
*/
|
|
32
|
-
setConfig: (configUpdate: ConfigUpdate) => Config;
|
|
32
|
+
setConfig: (configUpdate: Partial<ConfigUpdate>) => Config;
|
|
33
33
|
/**
|
|
34
34
|
* Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
|
|
35
35
|
* @param {PossibilitiesRequest} request - Object defining preferences regarding chain, exchanges and bridges
|
|
@@ -154,10 +154,10 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
154
154
|
* @param { RevokeApprovalRequest } request - The revoke request
|
|
155
155
|
*/
|
|
156
156
|
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Get all the available connections for swap/bridging tokens
|
|
159
|
+
* @param connectionRequest ConnectionsRequest
|
|
160
|
+
* @returns ConnectionsResponse
|
|
161
|
+
*/
|
|
162
|
+
getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
|
157
163
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Get all the available connections for swap/bridging tokens
|
|
160
|
-
* @param connectionRequest ConnectionsRequest
|
|
161
|
-
* @returns ConnectionsResponse
|
|
162
|
-
*/
|
|
163
|
-
export declare const getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
package/dist/LiFi.js
CHANGED
|
@@ -26,7 +26,7 @@ export class LiFi extends RouteExecutionManager {
|
|
|
26
26
|
return this.configService.getConfigAsync();
|
|
27
27
|
};
|
|
28
28
|
/**
|
|
29
|
-
* Get an instance of a provider for a specific
|
|
29
|
+
* Get an instance of a provider for a specific chain
|
|
30
30
|
* @param {number} chainId - Id of the chain the provider is for
|
|
31
31
|
* @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
|
|
32
32
|
* @return {FallbackProvider} The provider for the given chain
|
|
@@ -216,19 +216,19 @@ export class LiFi extends RouteExecutionManager {
|
|
|
216
216
|
this.revokeTokenApproval = (request) => {
|
|
217
217
|
return revokeTokenApproval(request);
|
|
218
218
|
};
|
|
219
|
+
/**
|
|
220
|
+
* Get all the available connections for swap/bridging tokens
|
|
221
|
+
* @param connectionRequest ConnectionsRequest
|
|
222
|
+
* @returns ConnectionsResponse
|
|
223
|
+
*/
|
|
224
|
+
this.getConnections = async (connectionRequest) => {
|
|
225
|
+
const connections = await ApiService.getAvailableConnections(connectionRequest);
|
|
226
|
+
return connections;
|
|
227
|
+
};
|
|
219
228
|
this.chainsService = ChainsService.getInstance();
|
|
220
229
|
this.chainsService.getChains().then((chains) => {
|
|
221
230
|
this.configService.updateChains(chains);
|
|
222
231
|
});
|
|
223
|
-
checkPackageUpdates(name, version, configUpdate
|
|
232
|
+
checkPackageUpdates(name, version, configUpdate.disableVersionCheck);
|
|
224
233
|
}
|
|
225
234
|
}
|
|
226
|
-
/**
|
|
227
|
-
* Get all the available connections for swap/bridging tokens
|
|
228
|
-
* @param connectionRequest ConnectionsRequest
|
|
229
|
-
* @returns ConnectionsResponse
|
|
230
|
-
*/
|
|
231
|
-
export const getConnections = async (connectionRequest) => {
|
|
232
|
-
const connections = await ApiService.getAvailableConnections(connectionRequest);
|
|
233
|
-
return connections;
|
|
234
|
-
};
|
|
@@ -20,10 +20,12 @@ export const checkAllowance = async (signer, step, statusManager, settings, chai
|
|
|
20
20
|
from: step.action.fromToken.address,
|
|
21
21
|
to: step.estimate.approvalAddress,
|
|
22
22
|
};
|
|
23
|
-
if (settings.
|
|
24
|
-
const config = await settings.
|
|
23
|
+
if (settings.updateTransactionRequestHook) {
|
|
24
|
+
const config = await settings.updateTransactionRequestHook(approvalRequest);
|
|
25
25
|
approvalRequest.gasLimit = config.gasLimit;
|
|
26
26
|
approvalRequest.gasPrice = config.gasPrice;
|
|
27
|
+
approvalRequest.maxFeePerGas = config.maxFeePerGas;
|
|
28
|
+
approvalRequest.maxPriorityFeePerGas = config.maxPriorityFeePerGas;
|
|
27
29
|
}
|
|
28
30
|
if (!approvalRequest.from) {
|
|
29
31
|
throw new Error('Missing Signer address');
|
package/dist/cjs/LiFi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
|
6
6
|
import { Config, ConfigUpdate, RevokeTokenData } from './types';
|
|
7
7
|
export declare class LiFi extends RouteExecutionManager {
|
|
8
8
|
private chainsService;
|
|
9
|
-
constructor(configUpdate
|
|
9
|
+
constructor(configUpdate: ConfigUpdate);
|
|
10
10
|
/**
|
|
11
11
|
* Get the current configuration of the SDK
|
|
12
12
|
* @return {Config} - The config object
|
|
@@ -18,7 +18,7 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
18
18
|
*/
|
|
19
19
|
getConfigAsync: () => Promise<Config>;
|
|
20
20
|
/**
|
|
21
|
-
* Get an instance of a provider for a specific
|
|
21
|
+
* Get an instance of a provider for a specific chain
|
|
22
22
|
* @param {number} chainId - Id of the chain the provider is for
|
|
23
23
|
* @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
|
|
24
24
|
* @return {FallbackProvider} The provider for the given chain
|
|
@@ -29,7 +29,7 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
29
29
|
* @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
|
|
30
30
|
* @return {Config} The renewed config object
|
|
31
31
|
*/
|
|
32
|
-
setConfig: (configUpdate: ConfigUpdate) => Config;
|
|
32
|
+
setConfig: (configUpdate: Partial<ConfigUpdate>) => Config;
|
|
33
33
|
/**
|
|
34
34
|
* Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
|
|
35
35
|
* @param {PossibilitiesRequest} request - Object defining preferences regarding chain, exchanges and bridges
|
|
@@ -154,10 +154,10 @@ export declare class LiFi extends RouteExecutionManager {
|
|
|
154
154
|
* @param { RevokeApprovalRequest } request - The revoke request
|
|
155
155
|
*/
|
|
156
156
|
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Get all the available connections for swap/bridging tokens
|
|
159
|
+
* @param connectionRequest ConnectionsRequest
|
|
160
|
+
* @returns ConnectionsResponse
|
|
161
|
+
*/
|
|
162
|
+
getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
|
157
163
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Get all the available connections for swap/bridging tokens
|
|
160
|
-
* @param connectionRequest ConnectionsRequest
|
|
161
|
-
* @returns ConnectionsResponse
|
|
162
|
-
*/
|
|
163
|
-
export declare const getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
package/dist/cjs/LiFi.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.LiFi = void 0;
|
|
30
30
|
const allowance_1 = require("./allowance");
|
|
31
31
|
const balance = __importStar(require("./balance"));
|
|
32
32
|
const connectors_1 = require("./connectors");
|
|
@@ -55,7 +55,7 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
|
|
|
55
55
|
return this.configService.getConfigAsync();
|
|
56
56
|
};
|
|
57
57
|
/**
|
|
58
|
-
* Get an instance of a provider for a specific
|
|
58
|
+
* Get an instance of a provider for a specific chain
|
|
59
59
|
* @param {number} chainId - Id of the chain the provider is for
|
|
60
60
|
* @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
|
|
61
61
|
* @return {FallbackProvider} The provider for the given chain
|
|
@@ -245,21 +245,20 @@ class LiFi extends RouteExecutionManager_1.RouteExecutionManager {
|
|
|
245
245
|
this.revokeTokenApproval = (request) => {
|
|
246
246
|
return (0, allowance_1.revokeTokenApproval)(request);
|
|
247
247
|
};
|
|
248
|
+
/**
|
|
249
|
+
* Get all the available connections for swap/bridging tokens
|
|
250
|
+
* @param connectionRequest ConnectionsRequest
|
|
251
|
+
* @returns ConnectionsResponse
|
|
252
|
+
*/
|
|
253
|
+
this.getConnections = async (connectionRequest) => {
|
|
254
|
+
const connections = await ApiService_1.default.getAvailableConnections(connectionRequest);
|
|
255
|
+
return connections;
|
|
256
|
+
};
|
|
248
257
|
this.chainsService = ChainsService_1.default.getInstance();
|
|
249
258
|
this.chainsService.getChains().then((chains) => {
|
|
250
259
|
this.configService.updateChains(chains);
|
|
251
260
|
});
|
|
252
|
-
(0, helpers_1.checkPackageUpdates)(version_1.name, version_1.version, configUpdate
|
|
261
|
+
(0, helpers_1.checkPackageUpdates)(version_1.name, version_1.version, configUpdate.disableVersionCheck);
|
|
253
262
|
}
|
|
254
263
|
}
|
|
255
264
|
exports.LiFi = LiFi;
|
|
256
|
-
/**
|
|
257
|
-
* Get all the available connections for swap/bridging tokens
|
|
258
|
-
* @param connectionRequest ConnectionsRequest
|
|
259
|
-
* @returns ConnectionsResponse
|
|
260
|
-
*/
|
|
261
|
-
const getConnections = async (connectionRequest) => {
|
|
262
|
-
const connections = await ApiService_1.default.getAvailableConnections(connectionRequest);
|
|
263
|
-
return connections;
|
|
264
|
-
};
|
|
265
|
-
exports.getConnections = getConnections;
|
|
@@ -26,10 +26,12 @@ const checkAllowance = async (signer, step, statusManager, settings, chain, allo
|
|
|
26
26
|
from: step.action.fromToken.address,
|
|
27
27
|
to: step.estimate.approvalAddress,
|
|
28
28
|
};
|
|
29
|
-
if (settings.
|
|
30
|
-
const config = await settings.
|
|
29
|
+
if (settings.updateTransactionRequestHook) {
|
|
30
|
+
const config = await settings.updateTransactionRequestHook(approvalRequest);
|
|
31
31
|
approvalRequest.gasLimit = config.gasLimit;
|
|
32
32
|
approvalRequest.gasPrice = config.gasPrice;
|
|
33
|
+
approvalRequest.maxFeePerGas = config.maxFeePerGas;
|
|
34
|
+
approvalRequest.maxPriorityFeePerGas = config.maxPriorityFeePerGas;
|
|
33
35
|
}
|
|
34
36
|
if (!approvalRequest.from) {
|
|
35
37
|
throw new Error('Missing Signer address');
|
package/dist/cjs/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/cjs/connectors.js
CHANGED
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getMulticallAddress = exports.getRpcProvider = exports.getRpcUrls = exports.getRpcUrl = void 0;
|
|
7
|
-
const
|
|
8
|
-
const types_1 = require("./types");
|
|
9
|
-
const ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
7
|
+
const providers_1 = require("@ethersproject/providers");
|
|
10
8
|
const helpers_1 = require("./helpers");
|
|
9
|
+
const ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
10
|
+
const types_1 = require("./types");
|
|
11
11
|
const errors_1 = require("./utils/errors");
|
|
12
12
|
// cached providers
|
|
13
13
|
const chainProviders = {};
|
|
@@ -41,17 +41,15 @@ const getRandomProvider = (providerList) => {
|
|
|
41
41
|
const getRpcProvider = async (chainId, archive = false) => {
|
|
42
42
|
if (archive && archiveRpcs[chainId]) {
|
|
43
43
|
// return archive PRC, but don't cache it
|
|
44
|
-
return new
|
|
45
|
-
new
|
|
44
|
+
return new providers_1.FallbackProvider([
|
|
45
|
+
new providers_1.StaticJsonRpcProvider(await (0, exports.getRpcUrl)(chainId, archive), chainId),
|
|
46
46
|
]);
|
|
47
47
|
}
|
|
48
|
-
if (!chainProviders[chainId]) {
|
|
48
|
+
if (!chainProviders[chainId]?.length) {
|
|
49
49
|
chainProviders[chainId] = [];
|
|
50
50
|
const urls = await (0, exports.getRpcUrls)(chainId, archive);
|
|
51
51
|
urls.forEach((url) => {
|
|
52
|
-
chainProviders[chainId].push(new
|
|
53
|
-
new ethers_1.providers.StaticJsonRpcProvider(url, chainId),
|
|
54
|
-
]));
|
|
52
|
+
chainProviders[chainId].push(new providers_1.FallbackProvider([new providers_1.StaticJsonRpcProvider(url, chainId)]));
|
|
55
53
|
});
|
|
56
54
|
}
|
|
57
55
|
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.
|
|
@@ -136,7 +136,7 @@ class StatusManager {
|
|
|
136
136
|
throw new Error("Couldn't find a step to update.");
|
|
137
137
|
}
|
|
138
138
|
this.route.steps[stepIndex] = Object.assign(this.route.steps[stepIndex], step);
|
|
139
|
-
this.settings.
|
|
139
|
+
this.settings.updateRouteHook(this.route);
|
|
140
140
|
this.internalUpdateRouteCallback(this.route);
|
|
141
141
|
return this.route.steps[stepIndex];
|
|
142
142
|
};
|
|
@@ -81,8 +81,8 @@ class StepExecutionManager {
|
|
|
81
81
|
if (!this.allowUserInteraction) {
|
|
82
82
|
return step.execution;
|
|
83
83
|
}
|
|
84
|
-
if (settings.
|
|
85
|
-
const customConfig = await settings.
|
|
84
|
+
if (settings.updateTransactionRequestHook) {
|
|
85
|
+
const customConfig = await settings.updateTransactionRequestHook(transactionRequest);
|
|
86
86
|
transactionRequest.gasLimit = customConfig.gasLimit;
|
|
87
87
|
transactionRequest.gasPrice = customConfig.gasPrice;
|
|
88
88
|
transactionRequest.maxPriorityFeePerGas =
|
|
@@ -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>;
|
|
@@ -11,7 +11,7 @@ const utils_1 = require("./utils");
|
|
|
11
11
|
* @param statusManager
|
|
12
12
|
* @param oldStep
|
|
13
13
|
* @param newStep
|
|
14
|
-
* @param
|
|
14
|
+
* @param settings
|
|
15
15
|
* @param allowUserInteraction
|
|
16
16
|
*/
|
|
17
17
|
const stepComparison = async (statusManager, oldStep, newStep, settings, allowUserInteraction) => {
|
|
@@ -19,15 +19,12 @@ const stepComparison = async (statusManager, oldStep, newStep, settings, allowUs
|
|
|
19
19
|
if ((0, utils_1.checkStepSlippageThreshold)(oldStep, newStep)) {
|
|
20
20
|
return statusManager.updateStepInRoute(newStep);
|
|
21
21
|
}
|
|
22
|
-
const acceptExchangeRateUpdateHook = settings.acceptExchangeRateUpdateHook ?? settings.acceptSlippageUpdateHook;
|
|
23
22
|
let allowStepUpdate;
|
|
24
23
|
if (allowUserInteraction) {
|
|
25
|
-
allowStepUpdate = await acceptExchangeRateUpdateHook({
|
|
24
|
+
allowStepUpdate = await settings.acceptExchangeRateUpdateHook({
|
|
26
25
|
oldToAmount: oldStep.estimate.toAmount,
|
|
27
26
|
newToAmount: newStep.estimate.toAmount,
|
|
28
27
|
toToken: newStep.action.toToken,
|
|
29
|
-
oldSlippage: oldStep.action.slippage,
|
|
30
|
-
newSlippage: newStep.action.slippage,
|
|
31
28
|
});
|
|
32
29
|
}
|
|
33
30
|
if (!allowStepUpdate) {
|
package/dist/cjs/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/cjs/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertQuoteToRoute = exports.checkPackageUpdates = exports.isSameToken = exports.getRandomNumber = exports.getEthereumPublicKeyHook = exports.getEthereumDecryptionHook = void 0;
|
|
3
|
+
exports.fetchTxErrorDetails = exports.convertQuoteToRoute = exports.checkPackageUpdates = exports.isSameToken = exports.getRandomNumber = exports.getEthereumPublicKeyHook = exports.getEthereumDecryptionHook = void 0;
|
|
4
4
|
const request_1 = require("./request");
|
|
5
5
|
const errors_1 = require("./utils/errors");
|
|
6
6
|
const version_1 = require("./version");
|
|
@@ -109,3 +109,8 @@ const convertQuoteToRoute = (step) => {
|
|
|
109
109
|
return route;
|
|
110
110
|
};
|
|
111
111
|
exports.convertQuoteToRoute = convertQuoteToRoute;
|
|
112
|
+
const fetchTxErrorDetails = async (txHash, chainId) => {
|
|
113
|
+
const response = await (0, request_1.request)(`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`);
|
|
114
|
+
return response;
|
|
115
|
+
};
|
|
116
|
+
exports.fetchTxErrorDetails = fetchTxErrorDetails;
|
|
@@ -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
|
}
|
|
@@ -3,9 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const types_1 = require("../types");
|
|
4
4
|
const DefaultExecutionSettings = {
|
|
5
5
|
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
|
|
6
|
-
|
|
6
|
+
updateRouteHook: () => { },
|
|
7
7
|
switchChainHook: () => Promise.resolve(undefined),
|
|
8
|
-
acceptSlippageUpdateHook: () => Promise.resolve(undefined),
|
|
9
8
|
acceptExchangeRateUpdateHook: () => Promise.resolve(undefined),
|
|
10
9
|
infiniteApproval: false,
|
|
11
10
|
executeInBackground: false,
|
package/dist/cjs/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 = {
|
|
@@ -8,6 +8,7 @@ const eth_rpc_errors_1 = require("eth-rpc-errors");
|
|
|
8
8
|
const ChainsService_1 = __importDefault(require("../services/ChainsService"));
|
|
9
9
|
const errors_1 = require("./errors");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
|
+
const helpers_1 = require("../helpers");
|
|
11
12
|
/**
|
|
12
13
|
* Available MetaMask error codes:
|
|
13
14
|
*
|
|
@@ -97,10 +98,23 @@ const parseError = async (e, step, process) => {
|
|
|
97
98
|
}
|
|
98
99
|
switch (e.code) {
|
|
99
100
|
case errors_1.EthersErrorType.CallExecption:
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const defaultErrorMessage = await (0, exports.getTransactionNotSentMessage)(step, process);
|
|
102
|
+
try {
|
|
103
|
+
if (!step?.action.fromChainId) {
|
|
104
|
+
throw new Error('Signer is not defined.');
|
|
105
|
+
}
|
|
106
|
+
const response = await (0, helpers_1.fetchTxErrorDetails)(e.transactionHash, step?.action.fromChainId);
|
|
107
|
+
const errorMessage = response?.error_message ?? e.reason;
|
|
108
|
+
const isAllowanceError = response?.error_message?.includes(errors_1.EthersErrorMessage.ERC20Allowance) || e.reason?.includes(errors_1.EthersErrorMessage.ERC20Allowance);
|
|
109
|
+
if (isAllowanceError) {
|
|
110
|
+
return new errors_1.TransactionError(errors_1.LifiErrorCode.AllowanceRequired, e.reason, errorMessage, e.stack);
|
|
111
|
+
}
|
|
112
|
+
// Error messages other than allowance error will be handled in catch block
|
|
113
|
+
throw new Error(e);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return new errors_1.ProviderError(errors_1.LifiErrorCode.TransactionFailed, e.reason, defaultErrorMessage, e.stack);
|
|
102
117
|
}
|
|
103
|
-
return new errors_1.ProviderError(errors_1.LifiErrorCode.TransactionFailed, e.reason, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
104
118
|
case errors_1.EthersErrorType.ActionRejected:
|
|
105
119
|
case errors_1.MetaMaskProviderErrorCode.userRejectedRequest:
|
|
106
120
|
return new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionRejected, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
|
|
@@ -136,11 +150,3 @@ const parseBackendError = async (e) => {
|
|
|
136
150
|
return new errors_1.ServerError(errors_1.ErrorMessage.Default, undefined, e.stack);
|
|
137
151
|
};
|
|
138
152
|
exports.parseBackendError = parseBackendError;
|
|
139
|
-
// const fetchTxErrorDetails = async (txHash: string, chainId: number) => {
|
|
140
|
-
// const response = await request<TenderlyResponse>(
|
|
141
|
-
// `https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`,
|
|
142
|
-
// undefined,
|
|
143
|
-
// 0
|
|
144
|
-
// )
|
|
145
|
-
// return response
|
|
146
|
-
// }
|
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.0-beta.
|
|
2
|
+
export declare const version = "2.0.0-beta.12";
|
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.
|
|
@@ -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,8 +75,8 @@ 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 =
|
|
@@ -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/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/parseError.js
CHANGED
|
@@ -2,6 +2,7 @@ import { errorCodes as MetaMaskErrorCodes, getMessageFromCode, } from 'eth-rpc-e
|
|
|
2
2
|
import ChainsService from '../services/ChainsService';
|
|
3
3
|
import { ErrorMessage, EthersErrorType, EthersErrorMessage, LifiError, LifiErrorCode, MetaMaskProviderErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
|
|
4
4
|
import { formatTokenAmountOnly } from './utils';
|
|
5
|
+
import { fetchTxErrorDetails } from '../helpers';
|
|
5
6
|
/**
|
|
6
7
|
* Available MetaMask error codes:
|
|
7
8
|
*
|
|
@@ -89,10 +90,23 @@ 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
|
-
return new ProviderError(LifiErrorCode.TransactionFailed, e.reason, await getTransactionNotSentMessage(step, process), e.stack);
|
|
96
110
|
case EthersErrorType.ActionRejected:
|
|
97
111
|
case MetaMaskProviderErrorCode.userRejectedRequest:
|
|
98
112
|
return new TransactionError(LifiErrorCode.TransactionRejected, e.message, await getTransactionNotSentMessage(step, process), e.stack);
|
|
@@ -126,11 +140,3 @@ export const parseBackendError = async (e) => {
|
|
|
126
140
|
}
|
|
127
141
|
return new ServerError(ErrorMessage.Default, undefined, e.stack);
|
|
128
142
|
};
|
|
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/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "2.0.0-beta.
|
|
2
|
+
export declare const version = "2.0.0-beta.12";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk';
|
|
2
|
-
export const version = '2.0.0-beta.
|
|
2
|
+
export const version = '2.0.0-beta.12';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.12",
|
|
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
|
-
"@mswjs/interceptors": "^0.22.
|
|
88
|
-
"@typescript-eslint/eslint-plugin": "^5.59.
|
|
89
|
-
"@typescript-eslint/parser": "^5.59.
|
|
90
|
-
"@vitest/coverage-c8": "^0.
|
|
85
|
+
"@commitlint/cli": "^17.6.3",
|
|
86
|
+
"@commitlint/config-conventional": "^17.6.3",
|
|
87
|
+
"@mswjs/interceptors": "^0.22.14",
|
|
88
|
+
"@typescript-eslint/eslint-plugin": "^5.59.5",
|
|
89
|
+
"@typescript-eslint/parser": "^5.59.5",
|
|
90
|
+
"@vitest/coverage-c8": "^0.31.0",
|
|
91
91
|
"cross-fetch": "^3.1.5",
|
|
92
|
-
"eslint": "^8.
|
|
92
|
+
"eslint": "^8.40.0",
|
|
93
93
|
"eslint-config-prettier": "^8.8.0",
|
|
94
94
|
"eslint-plugin-prettier": "^4.2.1",
|
|
95
95
|
"husky": "^8.0.3",
|
|
96
|
-
"lint-staged": "^13.2.
|
|
96
|
+
"lint-staged": "^13.2.2",
|
|
97
97
|
"msw": "1.0.1",
|
|
98
98
|
"npm-run-all": "^4.1.5",
|
|
99
99
|
"pinst": "^3.0.0",
|
|
100
100
|
"prettier": "^2.8.8",
|
|
101
101
|
"standard-version": "^9.5.0",
|
|
102
102
|
"typescript": "^5.0.4",
|
|
103
|
-
"vitest": "^0.
|
|
103
|
+
"vitest": "^0.31.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
|
}
|