@lifi/sdk 2.0.0-beta.8 → 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.
- package/dist/LiFi.d.ts +9 -9
- package/dist/LiFi.js +11 -11
- package/dist/allowance/checkAllowance.js +18 -2
- package/dist/allowance/utils.d.ts +2 -1
- package/dist/allowance/utils.js +7 -2
- package/dist/cjs/LiFi.d.ts +9 -9
- package/dist/cjs/LiFi.js +12 -13
- package/dist/cjs/allowance/checkAllowance.js +18 -2
- package/dist/cjs/allowance/utils.d.ts +2 -1
- package/dist/cjs/allowance/utils.js +7 -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 +22 -0
- 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/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 +47 -8
- package/dist/cjs/utils/errors.d.ts +22 -1
- package/dist/cjs/utils/errors.js +28 -4
- package/dist/cjs/utils/parseError.js +31 -12
- 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 +22 -0
- package/dist/execution/StepExecutor.js +13 -5
- 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 +47 -8
- package/dist/utils/errors.d.ts +22 -1
- package/dist/utils/errors.js +24 -0
- package/dist/utils/parseError.js +32 -13
- 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
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
|
-
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
1
|
import BigNumber from 'bignumber.js';
|
|
3
2
|
import { constants } from 'ethers';
|
|
4
3
|
import { getApproved, setApproval } from '../allowance/utils';
|
|
@@ -17,7 +16,24 @@ export const checkAllowance = async (signer, step, statusManager, settings, chai
|
|
|
17
16
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
18
17
|
}
|
|
19
18
|
else {
|
|
20
|
-
const
|
|
19
|
+
const approvalRequest = {
|
|
20
|
+
from: step.action.fromToken.address,
|
|
21
|
+
to: step.estimate.approvalAddress,
|
|
22
|
+
};
|
|
23
|
+
if (settings.updateTransactionRequestHook) {
|
|
24
|
+
const config = await settings.updateTransactionRequestHook(approvalRequest);
|
|
25
|
+
approvalRequest.gasLimit = config.gasLimit;
|
|
26
|
+
approvalRequest.gasPrice = config.gasPrice;
|
|
27
|
+
approvalRequest.maxFeePerGas = config.maxFeePerGas;
|
|
28
|
+
approvalRequest.maxPriorityFeePerGas = config.maxPriorityFeePerGas;
|
|
29
|
+
}
|
|
30
|
+
if (!approvalRequest.from) {
|
|
31
|
+
throw new Error('Missing Signer address');
|
|
32
|
+
}
|
|
33
|
+
if (!approvalRequest.to) {
|
|
34
|
+
throw new Error('Missing ERC20 contract address');
|
|
35
|
+
}
|
|
36
|
+
const approved = await getApproved(signer, approvalRequest.from, approvalRequest.to, approvalRequest);
|
|
21
37
|
if (new BigNumber(step.action.fromAmount).gt(approved)) {
|
|
22
38
|
if (!allowUserInteraction) {
|
|
23
39
|
return;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { ChainId, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { ContractTransaction, Signer } from 'ethers';
|
|
4
5
|
import { RevokeTokenData } from '../types';
|
|
5
|
-
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string) => Promise<BigNumber>;
|
|
6
|
+
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string, transactionRequest?: TransactionRequest) => Promise<BigNumber>;
|
|
6
7
|
export declare const setApproval: (signer: Signer, tokenAddress: string, contractAddress: string, amount: string) => Promise<ContractTransaction>;
|
|
7
8
|
export declare const getAllowanceViaMulticall: (signer: Signer, chainId: ChainId, tokenData: RevokeTokenData[]) => Promise<{
|
|
8
9
|
token: Token;
|
package/dist/allowance/utils.js
CHANGED
|
@@ -4,11 +4,16 @@ import ChainsService from '../services/ChainsService';
|
|
|
4
4
|
import { ERC20_ABI } from '../types';
|
|
5
5
|
import { ServerError } from '../utils/errors';
|
|
6
6
|
import { fetchDataUsingMulticall } from '../utils/multicall';
|
|
7
|
-
export const getApproved = async (signer, tokenAddress, contractAddress) => {
|
|
7
|
+
export const getApproved = async (signer, tokenAddress, contractAddress, transactionRequest) => {
|
|
8
8
|
const signerAddress = await signer.getAddress();
|
|
9
9
|
const erc20 = new Contract(tokenAddress, ERC20_ABI, signer);
|
|
10
10
|
try {
|
|
11
|
-
const approved = await erc20.allowance(signerAddress, contractAddress
|
|
11
|
+
const approved = await erc20.allowance(signerAddress, contractAddress, {
|
|
12
|
+
gasLimit: transactionRequest?.gasLimit,
|
|
13
|
+
gasPrice: transactionRequest?.gasPrice,
|
|
14
|
+
maxFeePerGas: transactionRequest?.maxFeePerGas,
|
|
15
|
+
maxPriorityFeePerGas: transactionRequest?.maxPriorityFeePerGas,
|
|
16
|
+
});
|
|
12
17
|
return new BigNumber(approved.toString());
|
|
13
18
|
}
|
|
14
19
|
catch (e) {
|
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;
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.checkAllowance = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
8
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
8
|
const ethers_1 = require("ethers");
|
|
10
9
|
const utils_1 = require("../allowance/utils");
|
|
@@ -23,7 +22,24 @@ const checkAllowance = async (signer, step, statusManager, settings, chain, allo
|
|
|
23
22
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
26
|
-
const
|
|
25
|
+
const approvalRequest = {
|
|
26
|
+
from: step.action.fromToken.address,
|
|
27
|
+
to: step.estimate.approvalAddress,
|
|
28
|
+
};
|
|
29
|
+
if (settings.updateTransactionRequestHook) {
|
|
30
|
+
const config = await settings.updateTransactionRequestHook(approvalRequest);
|
|
31
|
+
approvalRequest.gasLimit = config.gasLimit;
|
|
32
|
+
approvalRequest.gasPrice = config.gasPrice;
|
|
33
|
+
approvalRequest.maxFeePerGas = config.maxFeePerGas;
|
|
34
|
+
approvalRequest.maxPriorityFeePerGas = config.maxPriorityFeePerGas;
|
|
35
|
+
}
|
|
36
|
+
if (!approvalRequest.from) {
|
|
37
|
+
throw new Error('Missing Signer address');
|
|
38
|
+
}
|
|
39
|
+
if (!approvalRequest.to) {
|
|
40
|
+
throw new Error('Missing ERC20 contract address');
|
|
41
|
+
}
|
|
42
|
+
const approved = await (0, utils_1.getApproved)(signer, approvalRequest.from, approvalRequest.to, approvalRequest);
|
|
27
43
|
if (new bignumber_js_1.default(step.action.fromAmount).gt(approved)) {
|
|
28
44
|
if (!allowUserInteraction) {
|
|
29
45
|
return;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { ChainId, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { ContractTransaction, Signer } from 'ethers';
|
|
4
5
|
import { RevokeTokenData } from '../types';
|
|
5
|
-
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string) => Promise<BigNumber>;
|
|
6
|
+
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string, transactionRequest?: TransactionRequest) => Promise<BigNumber>;
|
|
6
7
|
export declare const setApproval: (signer: Signer, tokenAddress: string, contractAddress: string, amount: string) => Promise<ContractTransaction>;
|
|
7
8
|
export declare const getAllowanceViaMulticall: (signer: Signer, chainId: ChainId, tokenData: RevokeTokenData[]) => Promise<{
|
|
8
9
|
token: Token;
|
|
@@ -10,11 +10,16 @@ const ChainsService_1 = __importDefault(require("../services/ChainsService"));
|
|
|
10
10
|
const types_1 = require("../types");
|
|
11
11
|
const errors_1 = require("../utils/errors");
|
|
12
12
|
const multicall_1 = require("../utils/multicall");
|
|
13
|
-
const getApproved = async (signer, tokenAddress, contractAddress) => {
|
|
13
|
+
const getApproved = async (signer, tokenAddress, contractAddress, transactionRequest) => {
|
|
14
14
|
const signerAddress = await signer.getAddress();
|
|
15
15
|
const erc20 = new ethers_1.Contract(tokenAddress, types_1.ERC20_ABI, signer);
|
|
16
16
|
try {
|
|
17
|
-
const approved = await erc20.allowance(signerAddress, contractAddress
|
|
17
|
+
const approved = await erc20.allowance(signerAddress, contractAddress, {
|
|
18
|
+
gasLimit: transactionRequest?.gasLimit,
|
|
19
|
+
gasPrice: transactionRequest?.gasPrice,
|
|
20
|
+
maxFeePerGas: transactionRequest?.maxFeePerGas,
|
|
21
|
+
maxPriorityFeePerGas: transactionRequest?.maxPriorityFeePerGas,
|
|
22
|
+
});
|
|
18
23
|
return new bignumber_js_1.default(approved.toString());
|
|
19
24
|
}
|
|
20
25
|
catch (e) {
|
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.
|
|
@@ -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.
|
|
139
|
+
this.settings.updateRouteHook(this.route);
|
|
140
140
|
this.internalUpdateRouteCallback(this.route);
|
|
141
141
|
return this.route.steps[stepIndex];
|
|
142
142
|
};
|
|
@@ -81,6 +81,28 @@ class StepExecutionManager {
|
|
|
81
81
|
if (!this.allowUserInteraction) {
|
|
82
82
|
return step.execution;
|
|
83
83
|
}
|
|
84
|
+
if (settings.updateTransactionRequestHook) {
|
|
85
|
+
const customConfig = await settings.updateTransactionRequestHook(transactionRequest);
|
|
86
|
+
transactionRequest.gasLimit = customConfig.gasLimit;
|
|
87
|
+
transactionRequest.gasPrice = customConfig.gasPrice;
|
|
88
|
+
transactionRequest.maxPriorityFeePerGas =
|
|
89
|
+
customConfig.maxPriorityFeePerGas;
|
|
90
|
+
transactionRequest.maxFeePerGas = customConfig.maxFeePerGas;
|
|
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
|
+
}
|
|
84
106
|
// Submit the transaction
|
|
85
107
|
transaction = await signer.sendTransaction(transactionRequest);
|
|
86
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
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;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { LifiStep, Route, RouteOptions, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { Signer } from 'ethers';
|
|
@@ -22,7 +23,8 @@ export interface ExecutionParams {
|
|
|
22
23
|
statusManager: StatusManager;
|
|
23
24
|
settings: InternalExecutionSettings;
|
|
24
25
|
}
|
|
25
|
-
export type
|
|
26
|
+
export type UpdateRouteHook = (updatedRoute: Route) => void;
|
|
27
|
+
export type TransactionRequestUpdateHook = (updatedTxRequest: TransactionRequest) => Promise<TransactionRequest>;
|
|
26
28
|
export type Config = {
|
|
27
29
|
apiUrl: string;
|
|
28
30
|
rpcs: Record<ChainId, string[]>;
|
|
@@ -67,16 +69,13 @@ export interface RouteExecutionData {
|
|
|
67
69
|
}
|
|
68
70
|
export type ExecutionSettings = Partial<InternalExecutionSettings>;
|
|
69
71
|
export interface InternalExecutionSettings {
|
|
70
|
-
updateCallback: CallbackFunction;
|
|
71
|
-
switchChainHook: SwitchChainHook;
|
|
72
|
-
acceptSlippageUpdateHook: AcceptSlippageUpdateHook;
|
|
73
72
|
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook;
|
|
74
|
-
|
|
73
|
+
switchChainHook: SwitchChainHook;
|
|
74
|
+
updateRouteHook: UpdateRouteHook;
|
|
75
|
+
updateTransactionRequestHook?: TransactionRequestUpdateHook;
|
|
75
76
|
executeInBackground: boolean;
|
|
77
|
+
infiniteApproval: boolean;
|
|
76
78
|
}
|
|
77
|
-
export type EnforcedObjectProperties<T> = T & {
|
|
78
|
-
[P in keyof T]-?: T[P];
|
|
79
|
-
};
|
|
80
79
|
export type RouteExecutionDictionary = Partial<Record<string, RouteExecutionData>>;
|
|
81
80
|
export type RouteExecutionPromiseDictionary = Partial<Record<string, Promise<Route>>>;
|
|
82
81
|
export type RevokeTokenData = {
|
|
@@ -88,3 +87,43 @@ export interface InteractionSettings {
|
|
|
88
87
|
allowUpdates?: boolean;
|
|
89
88
|
stopExecution?: boolean;
|
|
90
89
|
}
|
|
90
|
+
export interface TenderlyResponse {
|
|
91
|
+
hash: string;
|
|
92
|
+
block_hash: string;
|
|
93
|
+
block_number: number;
|
|
94
|
+
from: string;
|
|
95
|
+
gas: number;
|
|
96
|
+
gas_price: number;
|
|
97
|
+
gas_fee_cap: number;
|
|
98
|
+
gas_tip_cap: number;
|
|
99
|
+
cumulative_gas_used: number;
|
|
100
|
+
gas_used: number;
|
|
101
|
+
effective_gas_price: number;
|
|
102
|
+
input: string;
|
|
103
|
+
nonce: number;
|
|
104
|
+
to: string;
|
|
105
|
+
index: number;
|
|
106
|
+
value: string;
|
|
107
|
+
access_list: any;
|
|
108
|
+
status: boolean;
|
|
109
|
+
addresses: string[];
|
|
110
|
+
contract_ids: string[];
|
|
111
|
+
network_id: string;
|
|
112
|
+
timestamp: string;
|
|
113
|
+
function_selector: string;
|
|
114
|
+
l1_block_number: number;
|
|
115
|
+
l1_timestamp: number;
|
|
116
|
+
deposit_tx: boolean;
|
|
117
|
+
system_tx: boolean;
|
|
118
|
+
mint: number;
|
|
119
|
+
sig: Signature;
|
|
120
|
+
error_message: string;
|
|
121
|
+
method: string;
|
|
122
|
+
decoded_input: any;
|
|
123
|
+
call_trace: any;
|
|
124
|
+
}
|
|
125
|
+
export interface Signature {
|
|
126
|
+
v: string;
|
|
127
|
+
r: string;
|
|
128
|
+
s: string;
|
|
129
|
+
}
|