@lifi/sdk 2.0.0-beta.9 → 2.0.0

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.
Files changed (57) hide show
  1. package/dist/LiFi.d.ts +9 -9
  2. package/dist/LiFi.js +11 -11
  3. package/dist/allowance/checkAllowance.js +4 -2
  4. package/dist/cjs/LiFi.d.ts +9 -9
  5. package/dist/cjs/LiFi.js +12 -13
  6. package/dist/cjs/allowance/checkAllowance.js +4 -2
  7. package/dist/cjs/connectors.d.ts +1 -1
  8. package/dist/cjs/connectors.js +7 -9
  9. package/dist/cjs/execution/RouteExecutionManager.d.ts +1 -1
  10. package/dist/cjs/execution/RouteExecutionManager.js +1 -1
  11. package/dist/cjs/execution/StatusManager.js +1 -1
  12. package/dist/cjs/execution/StepExecutionManager.js +16 -2
  13. package/dist/cjs/execution/StepExecutor.js +13 -5
  14. package/dist/cjs/execution/stepComparison.d.ts +1 -1
  15. package/dist/cjs/execution/stepComparison.js +2 -5
  16. package/dist/cjs/helpers.d.ts +2 -0
  17. package/dist/cjs/helpers.js +6 -1
  18. package/dist/cjs/services/ApiService.d.ts +1 -1
  19. package/dist/cjs/services/ConfigService.d.ts +1 -1
  20. package/dist/cjs/services/ConfigService.js +1 -2
  21. package/dist/cjs/typeguards.d.ts +2 -2
  22. package/dist/cjs/types/internal.types.d.ts +6 -10
  23. package/dist/cjs/utils/errors.d.ts +4 -2
  24. package/dist/cjs/utils/errors.js +9 -7
  25. package/dist/cjs/utils/parseError.js +19 -11
  26. package/dist/cjs/utils/preRestart.d.ts +2 -1
  27. package/dist/cjs/utils/preRestart.js +24 -3
  28. package/dist/cjs/version.d.ts +1 -1
  29. package/dist/cjs/version.js +1 -1
  30. package/dist/connectors.d.ts +1 -1
  31. package/dist/connectors.js +7 -9
  32. package/dist/execution/RouteExecutionManager.d.ts +1 -1
  33. package/dist/execution/RouteExecutionManager.js +1 -1
  34. package/dist/execution/StatusManager.js +1 -1
  35. package/dist/execution/StepExecutionManager.js +16 -2
  36. package/dist/execution/StepExecutor.js +13 -5
  37. package/dist/execution/stepComparison.d.ts +1 -1
  38. package/dist/execution/stepComparison.js +2 -5
  39. package/dist/helpers.d.ts +2 -0
  40. package/dist/helpers.js +4 -0
  41. package/dist/services/ApiService.d.ts +1 -1
  42. package/dist/services/ConfigService.d.ts +1 -1
  43. package/dist/services/ConfigService.js +1 -2
  44. package/dist/typeguards.d.ts +2 -2
  45. package/dist/types/internal.types.d.ts +6 -10
  46. package/dist/utils/errors.d.ts +4 -2
  47. package/dist/utils/errors.js +3 -1
  48. package/dist/utils/parseError.js +20 -12
  49. package/dist/utils/preRestart.d.ts +2 -1
  50. package/dist/utils/preRestart.js +24 -3
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.js +1 -1
  53. package/package.json +15 -15
  54. package/dist/cjs/services/ApiService.unit.handlers.d.ts +0 -1
  55. package/dist/cjs/services/ApiService.unit.handlers.js +0 -50
  56. package/dist/services/ApiService.unit.handlers.d.ts +0 -1
  57. package/dist/services/ApiService.unit.handlers.js +0 -44
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?: 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 cahin
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 cahin
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?.disableVersionCheck);
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.updateTransactionRequest) {
24
- const config = await settings.updateTransactionRequest(approvalRequest);
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');
@@ -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?: 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 cahin
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.getConnections = exports.LiFi = void 0;
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 cahin
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?.disableVersionCheck);
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.updateTransactionRequest) {
30
- const config = await settings.updateTransactionRequest(approvalRequest);
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');
@@ -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>;
@@ -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 ethers_1 = require("ethers");
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 ethers_1.providers.FallbackProvider([
45
- new ethers_1.providers.StaticJsonRpcProvider(await (0, exports.getRpcUrl)(chainId, archive), chainId),
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 ethers_1.providers.FallbackProvider([
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?: ConfigUpdate);
9
+ constructor(configUpdate: ConfigUpdate);
10
10
  /**
11
11
  * Execute a route.
12
12
  * @param {Signer} signer - The signer required to send the transactions.
@@ -56,7 +56,7 @@ class RouteExecutionManager {
56
56
  return executionPromise ?? clonedRoute;
57
57
  }
58
58
  }
59
- (0, preRestart_1.handlePreRestart)(clonedRoute);
59
+ await (0, preRestart_1.handlePreRestart)(clonedRoute, signer);
60
60
  const executionPromise = this.executeSteps(signer, clonedRoute, settings);
61
61
  this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
62
62
  return executionPromise;
@@ -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.updateCallback(this.route);
139
+ this.settings.updateRouteHook(this.route);
140
140
  this.internalUpdateRouteCallback(this.route);
141
141
  return this.route.steps[stepIndex];
142
142
  };
@@ -81,14 +81,28 @@ class StepExecutionManager {
81
81
  if (!this.allowUserInteraction) {
82
82
  return step.execution;
83
83
  }
84
- if (settings.updateTransactionRequest) {
85
- const customConfig = await settings.updateTransactionRequest(transactionRequest);
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 =
89
89
  customConfig.maxPriorityFeePerGas;
90
90
  transactionRequest.maxFeePerGas = customConfig.maxFeePerGas;
91
91
  }
92
+ else {
93
+ try {
94
+ const estimatedGasLimit = await signer.estimateGas(transactionRequest);
95
+ if (estimatedGasLimit) {
96
+ transactionRequest.gasLimit = `${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`;
97
+ }
98
+ // Fetch latest gasPrice from provider and use it
99
+ const gasPrice = await signer.getGasPrice();
100
+ if (gasPrice) {
101
+ transactionRequest.gasPrice = gasPrice;
102
+ }
103
+ }
104
+ catch (error) { }
105
+ }
92
106
  // Submit the transaction
93
107
  transaction = await signer.sendTransaction(transactionRequest);
94
108
  // STEP 4: Wait for the transaction
@@ -31,12 +31,20 @@ class StepExecutor {
31
31
  };
32
32
  this.executeStep = async (signer, step) => {
33
33
  // Make sure that the chain is still correct
34
- const updatedSigner = await (0, switchChain_1.switchChain)(signer, this.statusManager, step, this.settings.switchChainHook, this.allowUserInteraction);
35
- if (!updatedSigner) {
36
- // Chain switch was not successful, stop execution here
37
- return step;
34
+ // Find if it's bridging and the step is waiting for a transaction on the receiving chain
35
+ const recievingChainProcess = step.execution?.process.find((process) => process.type === 'RECEIVING_CHAIN');
36
+ // If the step is waiting for a transaction on the receiving chain, we do not switch the chain
37
+ // All changes are already done from the source chain
38
+ // Return the step
39
+ if (recievingChainProcess?.substatus !== 'WAIT_DESTINATION_TRANSACTION' ||
40
+ !recievingChainProcess) {
41
+ const updatedSigner = await (0, switchChain_1.switchChain)(signer, this.statusManager, step, this.settings.switchChainHook, this.allowUserInteraction);
42
+ if (!updatedSigner) {
43
+ // Chain switch was not successful, stop execution here
44
+ return step;
45
+ }
46
+ signer = updatedSigner;
38
47
  }
39
- signer = updatedSigner;
40
48
  const parameters = {
41
49
  signer,
42
50
  step,
@@ -8,7 +8,7 @@ import { InternalExecutionSettings, LifiStep } from '../types';
8
8
  * @param statusManager
9
9
  * @param oldStep
10
10
  * @param newStep
11
- * @param acceptSlippageUpdateHook
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 acceptSlippageUpdateHook
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) {
@@ -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>;
@@ -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: ChainKey | ChainId, token: string, options?: RequestOptions | undefined) => Promise<Token>;
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
- updateCallback: () => { },
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,
@@ -1,4 +1,4 @@
1
- import { LifiStep, RoutesRequest, Token } from './types';
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: Token) => token is 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 CallbackFunction = (updatedRoute: Route) => void;
27
- export type TxRequestCallbackFunction = (updatedTxRequest: TransactionRequest) => Promise<TransactionRequest>;
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
- infiniteApproval: boolean;
73
+ switchChainHook: SwitchChainHook;
74
+ updateRouteHook: UpdateRouteHook;
75
+ updateTransactionRequestHook?: TransactionRequestUpdateHook;
77
76
  executeInBackground: boolean;
78
- updateTransactionRequest?: TxRequestCallbackFunction;
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 = {
@@ -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
- ActionRejected = "ACTION_REJECTED"
32
+ InsufficientFunds = "INSUFFICIENT_FUNDS"
31
33
  }
32
34
  export declare enum EthersErrorMessage {
33
35
  ERC20Allowance = "ERC20: transfer amount exceeds allowance",
@@ -29,12 +29,14 @@ var LifiErrorCode;
29
29
  LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected";
30
30
  LifiErrorCode[LifiErrorCode["BalanceError"] = 1013] = "BalanceError";
31
31
  LifiErrorCode[LifiErrorCode["AllowanceRequired"] = 1014] = "AllowanceRequired";
32
- })(LifiErrorCode = exports.LifiErrorCode || (exports.LifiErrorCode = {}));
32
+ LifiErrorCode[LifiErrorCode["InsufficientFunds"] = 1015] = "InsufficientFunds";
33
+ })(LifiErrorCode || (exports.LifiErrorCode = LifiErrorCode = {}));
33
34
  var EthersErrorType;
34
35
  (function (EthersErrorType) {
35
- EthersErrorType["CallExecption"] = "CALL_EXCEPTION";
36
36
  EthersErrorType["ActionRejected"] = "ACTION_REJECTED";
37
- })(EthersErrorType = exports.EthersErrorType || (exports.EthersErrorType = {}));
37
+ EthersErrorType["CallExecption"] = "CALL_EXCEPTION";
38
+ EthersErrorType["InsufficientFunds"] = "INSUFFICIENT_FUNDS";
39
+ })(EthersErrorType || (exports.EthersErrorType = EthersErrorType = {}));
38
40
  var EthersErrorMessage;
39
41
  (function (EthersErrorMessage) {
40
42
  EthersErrorMessage["ERC20Allowance"] = "ERC20: transfer amount exceeds allowance";
@@ -42,7 +44,7 @@ var EthersErrorMessage;
42
44
  EthersErrorMessage["OutOfGas"] = "out of gas";
43
45
  EthersErrorMessage["Underpriced"] = "underpriced";
44
46
  EthersErrorMessage["LowReplacementFee"] = "replacement fee too low";
45
- })(EthersErrorMessage = exports.EthersErrorMessage || (exports.EthersErrorMessage = {}));
47
+ })(EthersErrorMessage || (exports.EthersErrorMessage = EthersErrorMessage = {}));
46
48
  var ErrorMessage;
47
49
  (function (ErrorMessage) {
48
50
  ErrorMessage["UnknownError"] = "Unknown error occurred.";
@@ -50,7 +52,7 @@ var ErrorMessage;
50
52
  ErrorMessage["GasLimitLow"] = "Gas limit is too low.";
51
53
  ErrorMessage["TransactionUnderpriced"] = "Transaction is underpriced.";
52
54
  ErrorMessage["Default"] = "Something went wrong.";
53
- })(ErrorMessage = exports.ErrorMessage || (exports.ErrorMessage = {}));
55
+ })(ErrorMessage || (exports.ErrorMessage = ErrorMessage = {}));
54
56
  var MetaMaskRPCErrorCode;
55
57
  (function (MetaMaskRPCErrorCode) {
56
58
  MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["invalidInput"] = -32000] = "invalidInput";
@@ -64,7 +66,7 @@ var MetaMaskRPCErrorCode;
64
66
  MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["methodNotFound"] = -32601] = "methodNotFound";
65
67
  MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["invalidParams"] = -32602] = "invalidParams";
66
68
  MetaMaskRPCErrorCode[MetaMaskRPCErrorCode["internal"] = -32603] = "internal";
67
- })(MetaMaskRPCErrorCode = exports.MetaMaskRPCErrorCode || (exports.MetaMaskRPCErrorCode = {}));
69
+ })(MetaMaskRPCErrorCode || (exports.MetaMaskRPCErrorCode = MetaMaskRPCErrorCode = {}));
68
70
  var MetaMaskProviderErrorCode;
69
71
  (function (MetaMaskProviderErrorCode) {
70
72
  MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["userRejectedRequest"] = 4001] = "userRejectedRequest";
@@ -72,7 +74,7 @@ var MetaMaskProviderErrorCode;
72
74
  MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["unsupportedMethod"] = 4200] = "unsupportedMethod";
73
75
  MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["disconnected"] = 4900] = "disconnected";
74
76
  MetaMaskProviderErrorCode[MetaMaskProviderErrorCode["chainDisconnected"] = 4901] = "chainDisconnected";
75
- })(MetaMaskProviderErrorCode = exports.MetaMaskProviderErrorCode || (exports.MetaMaskProviderErrorCode = {}));
77
+ })(MetaMaskProviderErrorCode || (exports.MetaMaskProviderErrorCode = MetaMaskProviderErrorCode = {}));
76
78
  class LifiError extends Error {
77
79
  constructor(type, code, message, htmlMessage, stack) {
78
80
  super(message);
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseBackendError = exports.parseError = exports.getTransactionFailedMessage = exports.getTransactionNotSentMessage = void 0;
7
7
  const eth_rpc_errors_1 = require("eth-rpc-errors");
8
+ const helpers_1 = require("../helpers");
8
9
  const ChainsService_1 = __importDefault(require("../services/ChainsService"));
9
10
  const errors_1 = require("./errors");
10
11
  const utils_1 = require("./utils");
@@ -97,10 +98,25 @@ const parseError = async (e, step, process) => {
97
98
  }
98
99
  switch (e.code) {
99
100
  case errors_1.EthersErrorType.CallExecption:
100
- if (e.reason?.includes?.includes(errors_1.EthersErrorMessage.ERC20Allowance)) {
101
- return new errors_1.TransactionError(errors_1.LifiErrorCode.AllowanceRequired, e.reason, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
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);
118
+ case errors_1.EthersErrorType.InsufficientFunds:
119
+ return new errors_1.TransactionError(errors_1.LifiErrorCode.InsufficientFunds, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
104
120
  case errors_1.EthersErrorType.ActionRejected:
105
121
  case errors_1.MetaMaskProviderErrorCode.userRejectedRequest:
106
122
  return new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionRejected, e.message, await (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
@@ -136,11 +152,3 @@ const parseBackendError = async (e) => {
136
152
  return new errors_1.ServerError(errors_1.ErrorMessage.Default, undefined, e.stack);
137
153
  };
138
154
  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
- // }
@@ -1,2 +1,3 @@
1
+ import { Signer } from 'ethers';
1
2
  import { Route } from '../types';
2
- export declare const handlePreRestart: (route: Route) => void;
3
+ export declare const handlePreRestart: (route: Route, signer: Signer) => Promise<void>;