@lifi/sdk 2.2.3 → 3.0.0-alpha.2
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 +69 -62
- package/dist/LiFi.js +71 -60
- package/dist/allowance/getAllowance.d.ts +6 -0
- package/dist/allowance/getAllowance.js +78 -0
- package/dist/allowance/index.d.ts +3 -2
- package/dist/allowance/index.js +3 -2
- package/dist/allowance/setAllowance.d.ts +5 -0
- package/dist/allowance/setAllowance.js +50 -0
- package/dist/allowance/types.d.ts +27 -0
- package/dist/allowance/types.js +1 -0
- package/dist/balance/getBalance.d.ts +2 -0
- package/dist/balance/getBalance.js +93 -0
- package/dist/balance/getTokenBalance.d.ts +2 -2
- package/dist/balance/getTokenBalance.js +4 -4
- package/dist/balance/index.d.ts +1 -12
- package/dist/balance/index.js +1 -9
- package/dist/cjs/LiFi.d.ts +69 -62
- package/dist/cjs/LiFi.js +69 -58
- package/dist/cjs/allowance/getAllowance.d.ts +6 -0
- package/dist/cjs/allowance/getAllowance.js +85 -0
- package/dist/cjs/allowance/index.d.ts +3 -2
- package/dist/cjs/allowance/index.js +3 -2
- package/dist/cjs/allowance/setAllowance.d.ts +5 -0
- package/dist/cjs/allowance/setAllowance.js +56 -0
- package/dist/cjs/allowance/types.d.ts +27 -0
- package/dist/cjs/allowance/types.js +2 -0
- package/dist/cjs/balance/getBalance.d.ts +2 -0
- package/dist/cjs/balance/getBalance.js +97 -0
- package/dist/cjs/balance/getTokenBalance.d.ts +2 -2
- package/dist/cjs/balance/getTokenBalance.js +6 -9
- package/dist/cjs/balance/index.d.ts +1 -12
- package/dist/cjs/balance/index.js +1 -9
- package/dist/cjs/connectors.d.ts +7 -5
- package/dist/cjs/connectors.js +45 -37
- package/dist/cjs/constants.d.ts +6 -0
- package/dist/cjs/constants.js +9 -0
- package/dist/cjs/execution/RouteExecutionManager.d.ts +24 -30
- package/dist/cjs/execution/RouteExecutionManager.js +27 -45
- package/dist/cjs/execution/StatusManager.d.ts +22 -23
- package/dist/cjs/execution/StatusManager.js +21 -22
- package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
- package/dist/cjs/execution/StepExecutionManager.js +118 -125
- package/dist/cjs/execution/StepExecutor.d.ts +4 -4
- package/dist/cjs/execution/StepExecutor.js +6 -6
- package/dist/cjs/execution/checkAllowance.d.ts +4 -0
- package/dist/cjs/execution/checkAllowance.js +77 -0
- package/dist/cjs/execution/checkBalance.d.ts +2 -0
- package/dist/cjs/execution/checkBalance.js +42 -0
- package/dist/cjs/execution/multisig.d.ts +4 -3
- package/dist/cjs/execution/multisig.js +9 -11
- package/dist/cjs/execution/prepareRestart.d.ts +3 -0
- package/dist/cjs/execution/prepareRestart.js +65 -0
- package/dist/cjs/execution/stepComparison.d.ts +3 -3
- package/dist/cjs/execution/stepComparison.js +2 -2
- package/dist/cjs/execution/switchChain.d.ts +13 -8
- package/dist/cjs/execution/switchChain.js +16 -11
- package/dist/cjs/execution/utils.d.ts +9 -3
- package/dist/cjs/execution/utils.js +19 -66
- package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -0
- package/dist/cjs/execution/waitForReceivingTransaction.js +58 -0
- package/dist/cjs/helpers.d.ts +7 -17
- package/dist/cjs/helpers.js +6 -38
- package/dist/cjs/request.js +1 -1
- package/dist/cjs/services/ApiService.d.ts +2 -2
- package/dist/cjs/services/ApiService.js +4 -2
- package/dist/cjs/services/ChainsService.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 +1 -1
- package/dist/cjs/types/abi.d.ts +5 -0
- package/dist/cjs/types/abi.js +45 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/index.js +3 -3
- package/dist/cjs/types/internal.types.d.ts +24 -31
- package/dist/cjs/utils/errors.d.ts +15 -14
- package/dist/cjs/utils/errors.js +38 -37
- package/dist/cjs/utils/getMaxPriorityFeePerGas.d.ts +2 -0
- package/dist/cjs/utils/getMaxPriorityFeePerGas.js +22 -0
- package/dist/cjs/utils/index.d.ts +5 -0
- package/dist/cjs/utils/index.js +21 -0
- package/dist/cjs/utils/median.d.ts +1 -0
- package/dist/cjs/utils/median.js +15 -0
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/utils/parseError.js +41 -38
- package/dist/cjs/utils/utils.d.ts +1 -16
- package/dist/cjs/utils/utils.js +9 -78
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +7 -5
- package/dist/connectors.js +19 -35
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +6 -0
- package/dist/execution/RouteExecutionManager.d.ts +24 -30
- package/dist/execution/RouteExecutionManager.js +27 -45
- package/dist/execution/StatusManager.d.ts +22 -23
- package/dist/execution/StatusManager.js +22 -23
- package/dist/execution/StepExecutionManager.d.ts +3 -3
- package/dist/execution/StepExecutionManager.js +116 -123
- package/dist/execution/StepExecutor.d.ts +4 -4
- package/dist/execution/StepExecutor.js +6 -6
- package/dist/execution/checkAllowance.d.ts +4 -0
- package/dist/execution/checkAllowance.js +73 -0
- package/dist/execution/checkBalance.d.ts +2 -0
- package/dist/execution/checkBalance.js +38 -0
- package/dist/execution/multisig.d.ts +4 -3
- package/dist/execution/multisig.js +10 -12
- package/dist/execution/prepareRestart.d.ts +3 -0
- package/dist/execution/prepareRestart.js +61 -0
- package/dist/execution/stepComparison.d.ts +3 -3
- package/dist/execution/stepComparison.js +3 -3
- package/dist/execution/switchChain.d.ts +13 -8
- package/dist/execution/switchChain.js +17 -12
- package/dist/execution/utils.d.ts +9 -3
- package/dist/execution/utils.js +18 -61
- package/dist/execution/waitForReceivingTransaction.d.ts +3 -0
- package/dist/execution/waitForReceivingTransaction.js +51 -0
- package/dist/helpers.d.ts +7 -17
- package/dist/helpers.js +5 -34
- package/dist/request.js +2 -2
- package/dist/services/ApiService.d.ts +2 -2
- package/dist/services/ApiService.js +4 -2
- package/dist/services/ChainsService.d.ts +1 -1
- package/dist/services/ConfigService.d.ts +1 -1
- package/dist/services/ConfigService.js +2 -3
- package/dist/typeguards.d.ts +1 -1
- package/dist/types/abi.d.ts +5 -0
- package/dist/types/abi.js +42 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +2 -2
- package/dist/types/internal.types.d.ts +24 -31
- package/dist/utils/errors.d.ts +15 -14
- package/dist/utils/errors.js +36 -35
- package/dist/utils/getMaxPriorityFeePerGas.d.ts +2 -0
- package/dist/utils/getMaxPriorityFeePerGas.js +18 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/median.d.ts +1 -0
- package/dist/utils/median.js +11 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/parseError.js +42 -39
- package/dist/utils/utils.d.ts +1 -16
- package/dist/utils/utils.js +7 -69
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +43 -40
- package/dist/allowance/checkAllowance.d.ts +0 -4
- package/dist/allowance/checkAllowance.js +0 -96
- package/dist/allowance/tokenApproval.d.ts +0 -22
- package/dist/allowance/tokenApproval.js +0 -59
- package/dist/allowance/utils.d.ts +0 -15
- package/dist/allowance/utils.js +0 -77
- package/dist/balance/checkBalance.d.ts +0 -3
- package/dist/balance/checkBalance.js +0 -38
- package/dist/balance/utils.d.ts +0 -6
- package/dist/balance/utils.js +0 -143
- package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
- package/dist/cjs/allowance/checkAllowance.js +0 -103
- package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
- package/dist/cjs/allowance/tokenApproval.js +0 -69
- package/dist/cjs/allowance/utils.d.ts +0 -15
- package/dist/cjs/allowance/utils.js +0 -87
- package/dist/cjs/balance/checkBalance.d.ts +0 -3
- package/dist/cjs/balance/checkBalance.js +0 -45
- package/dist/cjs/balance/utils.d.ts +0 -6
- package/dist/cjs/balance/utils.js +0 -150
- package/dist/cjs/types/ERC20.d.ts +0 -22
- package/dist/cjs/types/ERC20.js +0 -53
- package/dist/cjs/utils/getProvider.d.ts +0 -3
- package/dist/cjs/utils/getProvider.js +0 -11
- package/dist/cjs/utils/multicall.d.ts +0 -10
- package/dist/cjs/utils/multicall.js +0 -68
- package/dist/cjs/utils/multicallAbi.json +0 -313
- package/dist/cjs/utils/preRestart.d.ts +0 -3
- package/dist/cjs/utils/preRestart.js +0 -56
- package/dist/types/ERC20.d.ts +0 -22
- package/dist/types/ERC20.js +0 -50
- package/dist/utils/getProvider.d.ts +0 -3
- package/dist/utils/getProvider.js +0 -7
- package/dist/utils/multicall.d.ts +0 -10
- package/dist/utils/multicall.js +0 -61
- package/dist/utils/multicallAbi.json +0 -313
- package/dist/utils/preRestart.d.ts +0 -3
- package/dist/utils/preRestart.js +0 -52
package/dist/cjs/connectors.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
1
|
+
import type { PublicClient } from 'viem';
|
|
2
|
+
import type { Chain } from 'viem/chains';
|
|
3
|
+
import type { ChainId } from './types';
|
|
4
|
+
export declare const getChainById: (chainId: ChainId) => Chain | undefined;
|
|
5
|
+
export declare const getRpcUrl: (chainId: ChainId) => Promise<string>;
|
|
6
|
+
export declare const getRpcUrls: (chainId: ChainId) => Promise<string[]>;
|
|
7
|
+
export declare const getPublicClient: (chainId: number) => Promise<PublicClient>;
|
|
6
8
|
export declare const getMulticallAddress: (chainId: ChainId) => Promise<string | undefined>;
|
package/dist/cjs/connectors.js
CHANGED
|
@@ -1,63 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getMulticallAddress = exports.
|
|
7
|
-
const
|
|
8
|
-
const
|
|
29
|
+
exports.getMulticallAddress = exports.getPublicClient = exports.getRpcUrls = exports.getRpcUrl = exports.getChainById = void 0;
|
|
30
|
+
const viem_1 = require("viem");
|
|
31
|
+
const chains = __importStar(require("viem/chains")); // TODO: optimize using BE chains
|
|
9
32
|
const ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
10
|
-
const types_1 = require("./types");
|
|
11
33
|
const errors_1 = require("./utils/errors");
|
|
12
34
|
// cached providers
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[types_1.ChainId.ETH]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/eth/mainnet/archive',
|
|
17
|
-
[types_1.ChainId.BSC]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/bsc/mainnet/archive',
|
|
18
|
-
[types_1.ChainId.POL]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/polygon/mainnet/archive',
|
|
19
|
-
[types_1.ChainId.FTM]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/fantom/mainnet',
|
|
35
|
+
const publicClients = {};
|
|
36
|
+
const getChainById = (chainId) => {
|
|
37
|
+
return Object.values(chains).find((chain) => chain.id === chainId);
|
|
20
38
|
};
|
|
39
|
+
exports.getChainById = getChainById;
|
|
21
40
|
// RPC Urls
|
|
22
|
-
const getRpcUrl = async (chainId
|
|
23
|
-
const rpcUrls = await (0, exports.getRpcUrls)(chainId
|
|
41
|
+
const getRpcUrl = async (chainId) => {
|
|
42
|
+
const rpcUrls = await (0, exports.getRpcUrls)(chainId);
|
|
24
43
|
return rpcUrls[0];
|
|
25
44
|
};
|
|
26
45
|
exports.getRpcUrl = getRpcUrl;
|
|
27
|
-
const getRpcUrls = async (chainId
|
|
28
|
-
if (archive && archiveRpcs[chainId]) {
|
|
29
|
-
return [archiveRpcs[chainId]];
|
|
30
|
-
}
|
|
46
|
+
const getRpcUrls = async (chainId) => {
|
|
31
47
|
const configService = ConfigService_1.default.getInstance();
|
|
32
48
|
const config = await configService.getConfigAsync();
|
|
33
49
|
return config.rpcs[chainId];
|
|
34
50
|
};
|
|
35
51
|
exports.getRpcUrls = getRpcUrls;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
new providers_1.StaticJsonRpcProvider(await (0, exports.getRpcUrl)(chainId, archive), chainId),
|
|
46
|
-
]);
|
|
47
|
-
}
|
|
48
|
-
if (!chainProviders[chainId]?.length) {
|
|
49
|
-
chainProviders[chainId] = [];
|
|
50
|
-
const urls = await (0, exports.getRpcUrls)(chainId, archive);
|
|
51
|
-
urls.forEach((url) => {
|
|
52
|
-
chainProviders[chainId].push(new providers_1.FallbackProvider([new providers_1.StaticJsonRpcProvider(url, chainId)]));
|
|
52
|
+
const getPublicClient = async (chainId) => {
|
|
53
|
+
if (!publicClients[chainId]) {
|
|
54
|
+
const urls = await (0, exports.getRpcUrls)(chainId);
|
|
55
|
+
const fallbackTransports = urls.map((url) => (0, viem_1.http)(url, {
|
|
56
|
+
batch: true,
|
|
57
|
+
}));
|
|
58
|
+
publicClients[chainId] = (0, viem_1.createPublicClient)({
|
|
59
|
+
chain: (0, exports.getChainById)(chainId),
|
|
60
|
+
transport: (0, viem_1.fallback)(fallbackTransports),
|
|
53
61
|
});
|
|
54
62
|
}
|
|
55
|
-
if (!
|
|
63
|
+
if (!publicClients[chainId]) {
|
|
56
64
|
throw new errors_1.ServerError(`Unable to configure provider for chain ${chainId}`);
|
|
57
65
|
}
|
|
58
|
-
return
|
|
66
|
+
return publicClients[chainId];
|
|
59
67
|
};
|
|
60
|
-
exports.
|
|
68
|
+
exports.getPublicClient = getPublicClient;
|
|
61
69
|
// Multicall
|
|
62
70
|
const getMulticallAddress = async (chainId) => {
|
|
63
71
|
const configService = ConfigService_1.default.getInstance();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const AddressZero = "0x0000000000000000000000000000000000000000";
|
|
2
|
+
export declare const AlternativeAddressZero = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
3
|
+
/**
|
|
4
|
+
* Cronos require bigger multicall chunks than default 1024 (1 KB)
|
|
5
|
+
*/
|
|
6
|
+
export declare const MulticallBatchSize = 16384;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MulticallBatchSize = exports.AlternativeAddressZero = exports.AddressZero = void 0;
|
|
4
|
+
exports.AddressZero = '0x0000000000000000000000000000000000000000';
|
|
5
|
+
exports.AlternativeAddressZero = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
6
|
+
/**
|
|
7
|
+
* Cronos require bigger multicall chunks than default 1024 (1 KB)
|
|
8
|
+
*/
|
|
9
|
+
exports.MulticallBatchSize = 16384; // 16 Kilobytes (KB)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Route } from '@lifi/types';
|
|
2
|
-
import {
|
|
1
|
+
import type { Route } from '@lifi/types';
|
|
2
|
+
import type { WalletClient } from 'viem';
|
|
3
3
|
import ConfigService from '../services/ConfigService';
|
|
4
|
-
import { ConfigUpdate, ExecutionSettings } from '../types';
|
|
4
|
+
import type { ConfigUpdate, ExecutionSettings } from '../types';
|
|
5
5
|
export declare class RouteExecutionManager {
|
|
6
6
|
private executionDictionary;
|
|
7
7
|
private executionPromiseDictionary;
|
|
@@ -9,57 +9,51 @@ export declare class RouteExecutionManager {
|
|
|
9
9
|
constructor(configUpdate: ConfigUpdate);
|
|
10
10
|
/**
|
|
11
11
|
* Execute a route.
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @
|
|
16
|
-
* @throws {
|
|
12
|
+
* @param walletClient - The walletClient required to send the transactions.
|
|
13
|
+
* @param route - The route that should be executed. Cannot be an active route.
|
|
14
|
+
* @param settings - An object containing settings and callbacks.
|
|
15
|
+
* @returns The executed route.
|
|
16
|
+
* @throws {LiFiError} Throws a LiFiError if the execution fails.
|
|
17
17
|
*/
|
|
18
|
-
executeRoute: (
|
|
18
|
+
executeRoute: (walletClient: WalletClient, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
19
19
|
/**
|
|
20
20
|
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @
|
|
25
|
-
* @throws {
|
|
21
|
+
* @param walletClient - The walletClient required to send the transactions.
|
|
22
|
+
* @param route - The route that is to be executed. Cannot be an active route.
|
|
23
|
+
* @param settings - An object containing settings and callbacks.
|
|
24
|
+
* @returns The executed route.
|
|
25
|
+
* @throws {LiFiError} Throws a LiFiError if the execution fails.
|
|
26
26
|
*/
|
|
27
|
-
resumeRoute: (
|
|
27
|
+
resumeRoute: (walletClient: WalletClient, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
28
28
|
private executeSteps;
|
|
29
29
|
/**
|
|
30
30
|
* Updates route execution to background or foreground state.
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
31
|
+
* @param route - A route that is currently in execution.
|
|
32
|
+
* @param settings - An object with execution settings.
|
|
33
33
|
*/
|
|
34
34
|
updateRouteExecution: (route: Route, settings: Pick<ExecutionSettings, 'executeInBackground'>) => void;
|
|
35
35
|
/**
|
|
36
36
|
* Update the ExecutionSettings for an active route.
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
37
|
+
* @param settings - An object with execution settings.
|
|
38
|
+
* @param route - The active route that gets the new execution settings.
|
|
39
39
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
40
40
|
*/
|
|
41
41
|
updateExecutionSettings: (settings: ExecutionSettings, route: Route) => void;
|
|
42
|
-
/**
|
|
43
|
-
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
44
|
-
* @param {Route} route - A route that is currently in execution.
|
|
45
|
-
* @deprecated use updateRouteExecution instead.
|
|
46
|
-
*/
|
|
47
|
-
moveExecutionToBackground: (route: Route) => void;
|
|
48
42
|
/**
|
|
49
43
|
* Stops the execution of an active route.
|
|
50
|
-
* @param
|
|
51
|
-
* @
|
|
44
|
+
* @param route - A route that is currently in execution.
|
|
45
|
+
* @returns The stopped route.
|
|
52
46
|
*/
|
|
53
47
|
stopExecution: (route: Route) => Route;
|
|
54
48
|
/**
|
|
55
49
|
* Get the list of active routes.
|
|
56
|
-
* @
|
|
50
|
+
* @returns A list of routes.
|
|
57
51
|
*/
|
|
58
52
|
getActiveRoutes: () => Route[];
|
|
59
53
|
/**
|
|
60
54
|
* Return the current route information for given route. The route has to be active.
|
|
61
|
-
* @param
|
|
62
|
-
* @
|
|
55
|
+
* @param route - A route object.
|
|
56
|
+
* @returns The updated route.
|
|
63
57
|
*/
|
|
64
58
|
getActiveRoute: (route: Route) => Route | undefined;
|
|
65
59
|
}
|
|
@@ -6,22 +6,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.RouteExecutionManager = void 0;
|
|
7
7
|
const ConfigService_1 = __importDefault(require("../services/ConfigService"));
|
|
8
8
|
const errors_1 = require("../utils/errors");
|
|
9
|
-
const preRestart_1 = require("../utils/preRestart");
|
|
10
9
|
const StatusManager_1 = require("./StatusManager");
|
|
11
10
|
const StepExecutor_1 = require("./StepExecutor");
|
|
11
|
+
const prepareRestart_1 = require("./prepareRestart");
|
|
12
12
|
class RouteExecutionManager {
|
|
13
13
|
constructor(configUpdate) {
|
|
14
14
|
this.executionDictionary = {};
|
|
15
15
|
this.executionPromiseDictionary = {};
|
|
16
16
|
/**
|
|
17
17
|
* Execute a route.
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @
|
|
22
|
-
* @throws {
|
|
18
|
+
* @param walletClient - The walletClient required to send the transactions.
|
|
19
|
+
* @param route - The route that should be executed. Cannot be an active route.
|
|
20
|
+
* @param settings - An object containing settings and callbacks.
|
|
21
|
+
* @returns The executed route.
|
|
22
|
+
* @throws {LiFiError} Throws a LiFiError if the execution fails.
|
|
23
23
|
*/
|
|
24
|
-
this.executeRoute = async (
|
|
24
|
+
this.executeRoute = async (walletClient, route, settings) => {
|
|
25
25
|
// Deep clone to prevent side effects
|
|
26
26
|
const clonedRoute = structuredClone(route);
|
|
27
27
|
let executionPromise = this.executionPromiseDictionary[clonedRoute.id];
|
|
@@ -29,19 +29,19 @@ class RouteExecutionManager {
|
|
|
29
29
|
if (executionPromise) {
|
|
30
30
|
return executionPromise;
|
|
31
31
|
}
|
|
32
|
-
executionPromise = this.executeSteps(
|
|
32
|
+
executionPromise = this.executeSteps(walletClient, clonedRoute, settings);
|
|
33
33
|
this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
|
|
34
34
|
return executionPromise;
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @
|
|
42
|
-
* @throws {
|
|
38
|
+
* @param walletClient - The walletClient required to send the transactions.
|
|
39
|
+
* @param route - The route that is to be executed. Cannot be an active route.
|
|
40
|
+
* @param settings - An object containing settings and callbacks.
|
|
41
|
+
* @returns The executed route.
|
|
42
|
+
* @throws {LiFiError} Throws a LiFiError if the execution fails.
|
|
43
43
|
*/
|
|
44
|
-
this.resumeRoute = async (
|
|
44
|
+
this.resumeRoute = async (walletClient, route, settings) => {
|
|
45
45
|
// Deep clone to prevent side effects
|
|
46
46
|
const clonedRoute = structuredClone(route);
|
|
47
47
|
const execution = this.executionDictionary[clonedRoute.id];
|
|
@@ -56,12 +56,12 @@ class RouteExecutionManager {
|
|
|
56
56
|
return executionPromise ?? clonedRoute;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
await (0,
|
|
60
|
-
const executionPromise = this.executeSteps(
|
|
59
|
+
await (0, prepareRestart_1.prepareRestart)(clonedRoute, walletClient);
|
|
60
|
+
const executionPromise = this.executeSteps(walletClient, clonedRoute, settings);
|
|
61
61
|
this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
|
|
62
62
|
return executionPromise;
|
|
63
63
|
};
|
|
64
|
-
this.executeSteps = async (
|
|
64
|
+
this.executeSteps = async (walletClient, route, settings) => {
|
|
65
65
|
const config = this.configService.getConfig();
|
|
66
66
|
const execution = {
|
|
67
67
|
route,
|
|
@@ -97,7 +97,7 @@ class RouteExecutionManager {
|
|
|
97
97
|
execution.executors.push(stepExecutor);
|
|
98
98
|
// Check if we want to execute this step in the background
|
|
99
99
|
this.updateRouteExecution(route, execution.settings);
|
|
100
|
-
const executedStep = await stepExecutor.executeStep(
|
|
100
|
+
const executedStep = await stepExecutor.executeStep(walletClient, step);
|
|
101
101
|
// We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
|
|
102
102
|
if (executedStep.execution?.status !== 'DONE') {
|
|
103
103
|
this.stopExecution(route);
|
|
@@ -118,8 +118,8 @@ class RouteExecutionManager {
|
|
|
118
118
|
};
|
|
119
119
|
/**
|
|
120
120
|
* Updates route execution to background or foreground state.
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
121
|
+
* @param route - A route that is currently in execution.
|
|
122
|
+
* @param settings - An object with execution settings.
|
|
123
123
|
*/
|
|
124
124
|
this.updateRouteExecution = (route, settings) => {
|
|
125
125
|
const execution = this.executionDictionary[route.id];
|
|
@@ -140,8 +140,8 @@ class RouteExecutionManager {
|
|
|
140
140
|
};
|
|
141
141
|
/**
|
|
142
142
|
* Update the ExecutionSettings for an active route.
|
|
143
|
-
* @param
|
|
144
|
-
* @param
|
|
143
|
+
* @param settings - An object with execution settings.
|
|
144
|
+
* @param route - The active route that gets the new execution settings.
|
|
145
145
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
146
146
|
*/
|
|
147
147
|
this.updateExecutionSettings = (settings, route) => {
|
|
@@ -155,28 +155,10 @@ class RouteExecutionManager {
|
|
|
155
155
|
...settings,
|
|
156
156
|
};
|
|
157
157
|
};
|
|
158
|
-
/**
|
|
159
|
-
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
160
|
-
* @param {Route} route - A route that is currently in execution.
|
|
161
|
-
* @deprecated use updateRouteExecution instead.
|
|
162
|
-
*/
|
|
163
|
-
this.moveExecutionToBackground = (route) => {
|
|
164
|
-
const execution = this.executionDictionary[route.id];
|
|
165
|
-
if (!execution) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
for (const executor of execution.executors) {
|
|
169
|
-
executor.setInteraction({ allowInteraction: false, allowUpdates: true });
|
|
170
|
-
}
|
|
171
|
-
execution.settings = {
|
|
172
|
-
...execution.settings,
|
|
173
|
-
executeInBackground: true,
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
158
|
/**
|
|
177
159
|
* Stops the execution of an active route.
|
|
178
|
-
* @param
|
|
179
|
-
* @
|
|
160
|
+
* @param route - A route that is currently in execution.
|
|
161
|
+
* @returns The stopped route.
|
|
180
162
|
*/
|
|
181
163
|
this.stopExecution = (route) => {
|
|
182
164
|
const execution = this.executionDictionary[route.id];
|
|
@@ -195,7 +177,7 @@ class RouteExecutionManager {
|
|
|
195
177
|
};
|
|
196
178
|
/**
|
|
197
179
|
* Get the list of active routes.
|
|
198
|
-
* @
|
|
180
|
+
* @returns A list of routes.
|
|
199
181
|
*/
|
|
200
182
|
this.getActiveRoutes = () => {
|
|
201
183
|
return Object.values(this.executionDictionary)
|
|
@@ -204,8 +186,8 @@ class RouteExecutionManager {
|
|
|
204
186
|
};
|
|
205
187
|
/**
|
|
206
188
|
* Return the current route information for given route. The route has to be active.
|
|
207
|
-
* @param
|
|
208
|
-
* @
|
|
189
|
+
* @param route - A route object.
|
|
190
|
+
* @returns The updated route.
|
|
209
191
|
*/
|
|
210
192
|
this.getActiveRoute = (route) => {
|
|
211
193
|
return this.executionDictionary[route.id]?.route;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Execution, InternalExecutionSettings, LifiStep, Process, ProcessType, Route, Status, Token } from '../types';
|
|
1
|
+
import type { Execution, InternalExecutionSettings, LifiStep, Process, ProcessType, Route, Status, Token } from '../types';
|
|
2
2
|
interface Receipt {
|
|
3
3
|
fromAmount?: string;
|
|
4
4
|
toAmount?: string;
|
|
@@ -13,10 +13,10 @@ type InternalUpdateRouteCallback = (route: Route) => void;
|
|
|
13
13
|
type OptionalParameters = Partial<Pick<Process, 'doneAt' | 'failedAt' | 'txHash' | 'txLink' | 'error' | 'substatus' | 'substatusMessage' | 'multisigTxHash'>>;
|
|
14
14
|
/**
|
|
15
15
|
* Manages status updates of a route and provides various functions for tracking processes
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @
|
|
16
|
+
* @param {Route} route The route this StatusManger belongs to.
|
|
17
|
+
* @param {InternalExecutionSettings} settings The ExecutionSettings for this route.
|
|
18
|
+
* @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
|
|
19
|
+
* @returns {StatusManager} An instance of StatusManager.
|
|
20
20
|
*/
|
|
21
21
|
export declare class StatusManager {
|
|
22
22
|
private readonly route;
|
|
@@ -26,40 +26,39 @@ export declare class StatusManager {
|
|
|
26
26
|
constructor(route: Route, settings: InternalExecutionSettings, internalUpdateRouteCallback: InternalUpdateRouteCallback);
|
|
27
27
|
/**
|
|
28
28
|
* Initializes the execution object of a Step.
|
|
29
|
-
* @param
|
|
30
|
-
* @
|
|
29
|
+
* @param step The current step in execution
|
|
30
|
+
* @returns The initialized execution object for this step and a function to update this step
|
|
31
31
|
*/
|
|
32
32
|
initExecutionObject: (step: LifiStep) => Execution;
|
|
33
33
|
/**
|
|
34
34
|
* Updates the execution object of a Step.
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @
|
|
35
|
+
* @param step The current step in execution
|
|
36
|
+
* @param status The status for the execution
|
|
37
|
+
* @param receipt Optional. Information about received tokens
|
|
38
|
+
* @returns The step with the updated execution object
|
|
39
39
|
*/
|
|
40
40
|
updateExecution(step: LifiStep, status: Status, receipt?: Receipt): LifiStep;
|
|
41
41
|
/**
|
|
42
42
|
* Create and push a new process into the execution.
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @
|
|
43
|
+
* @param step The step that should contain the new process.
|
|
44
|
+
* @param type Type of the process. Used to identify already existing processes.
|
|
45
|
+
* @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
46
|
+
* @returns Returns process.
|
|
47
47
|
*/
|
|
48
48
|
findOrCreateProcess: (step: LifiStep, type: ProcessType, status?: Status) => Process;
|
|
49
49
|
/**
|
|
50
50
|
* Update a process object.
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @
|
|
51
|
+
* @param step The step where the process should be updated
|
|
52
|
+
* @param type The process type to update
|
|
53
|
+
* @param status The status the process gets.
|
|
54
|
+
* @param [params] Additional parameters to append to the process.
|
|
55
|
+
* @returns The update process
|
|
56
56
|
*/
|
|
57
57
|
updateProcess: (step: LifiStep, type: ProcessType, status: Status, params?: OptionalParameters) => Process;
|
|
58
58
|
/**
|
|
59
59
|
* Remove a process from the execution
|
|
60
|
-
* @param
|
|
61
|
-
* @param
|
|
62
|
-
* @return {void}
|
|
60
|
+
* @param step The step where the process should be removed from
|
|
61
|
+
* @param type The process type to remove
|
|
63
62
|
*/
|
|
64
63
|
removeProcess: (step: LifiStep, type: ProcessType) => void;
|
|
65
64
|
updateStepInRoute: (step: LifiStep) => LifiStep;
|
|
@@ -5,18 +5,18 @@ const types_1 = require("../types");
|
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
/**
|
|
7
7
|
* Manages status updates of a route and provides various functions for tracking processes
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
8
|
+
* @param {Route} route The route this StatusManger belongs to.
|
|
9
|
+
* @param {InternalExecutionSettings} settings The ExecutionSettings for this route.
|
|
10
|
+
* @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
|
|
11
|
+
* @returns {StatusManager} An instance of StatusManager.
|
|
12
12
|
*/
|
|
13
13
|
class StatusManager {
|
|
14
14
|
constructor(route, settings, internalUpdateRouteCallback) {
|
|
15
15
|
this.shouldUpdate = true;
|
|
16
16
|
/**
|
|
17
17
|
* Initializes the execution object of a Step.
|
|
18
|
-
* @param
|
|
19
|
-
* @
|
|
18
|
+
* @param step The current step in execution
|
|
19
|
+
* @returns The initialized execution object for this step and a function to update this step
|
|
20
20
|
*/
|
|
21
21
|
this.initExecutionObject = (step) => {
|
|
22
22
|
const currentExecution = step.execution || structuredClone(types_1.emptyExecution);
|
|
@@ -34,10 +34,10 @@ class StatusManager {
|
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Create and push a new process into the execution.
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @
|
|
37
|
+
* @param step The step that should contain the new process.
|
|
38
|
+
* @param type Type of the process. Used to identify already existing processes.
|
|
39
|
+
* @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
40
|
+
* @returns Returns process.
|
|
41
41
|
*/
|
|
42
42
|
this.findOrCreateProcess = (step, type, status) => {
|
|
43
43
|
if (!step.execution?.process) {
|
|
@@ -63,11 +63,11 @@ class StatusManager {
|
|
|
63
63
|
};
|
|
64
64
|
/**
|
|
65
65
|
* Update a process object.
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @
|
|
66
|
+
* @param step The step where the process should be updated
|
|
67
|
+
* @param type The process type to update
|
|
68
|
+
* @param status The status the process gets.
|
|
69
|
+
* @param [params] Additional parameters to append to the process.
|
|
70
|
+
* @returns The update process
|
|
71
71
|
*/
|
|
72
72
|
this.updateProcess = (step, type, status, params) => {
|
|
73
73
|
if (!step.execution) {
|
|
@@ -115,9 +115,8 @@ class StatusManager {
|
|
|
115
115
|
};
|
|
116
116
|
/**
|
|
117
117
|
* Remove a process from the execution
|
|
118
|
-
* @param
|
|
119
|
-
* @param
|
|
120
|
-
* @return {void}
|
|
118
|
+
* @param step The step where the process should be removed from
|
|
119
|
+
* @param type The process type to remove
|
|
121
120
|
*/
|
|
122
121
|
this.removeProcess = (step, type) => {
|
|
123
122
|
if (!step.execution) {
|
|
@@ -146,10 +145,10 @@ class StatusManager {
|
|
|
146
145
|
}
|
|
147
146
|
/**
|
|
148
147
|
* Updates the execution object of a Step.
|
|
149
|
-
* @param
|
|
150
|
-
* @param
|
|
151
|
-
* @param
|
|
152
|
-
* @
|
|
148
|
+
* @param step The current step in execution
|
|
149
|
+
* @param status The status for the execution
|
|
150
|
+
* @param receipt Optional. Information about received tokens
|
|
151
|
+
* @returns The step with the updated execution object
|
|
153
152
|
*/
|
|
154
153
|
updateExecution(step, status, receipt) {
|
|
155
154
|
if (!step.execution) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Execution } from '@lifi/types';
|
|
2
|
-
import { ExecutionParams } from '../types';
|
|
1
|
+
import type { Execution } from '@lifi/types';
|
|
2
|
+
import type { ExecutionParams } from '../types';
|
|
3
3
|
export declare class StepExecutionManager {
|
|
4
4
|
allowUserInteraction: boolean;
|
|
5
5
|
allowInteraction: (value: boolean) => void;
|
|
6
|
-
execute: ({
|
|
6
|
+
execute: ({ walletClient, step, statusManager, settings, }: ExecutionParams) => Promise<Execution>;
|
|
7
7
|
}
|