@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/utils/utils.js
CHANGED
|
@@ -1,69 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isNativeTokenAddress = exports.isZeroAddress = exports.
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const connectors_1 = require("../connectors");
|
|
10
|
-
const sleep = (mills) => {
|
|
3
|
+
exports.isNativeTokenAddress = exports.isZeroAddress = exports.repeatUntilDone = exports.wait = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const wait = (ms) => {
|
|
11
6
|
return new Promise((resolve) => {
|
|
12
|
-
setTimeout(resolve,
|
|
7
|
+
setTimeout(resolve, ms);
|
|
13
8
|
});
|
|
14
9
|
};
|
|
15
|
-
exports.
|
|
16
|
-
const personalizeStep = async (signer, step) => {
|
|
17
|
-
if (step.action.toAddress && step.action.fromAddress) {
|
|
18
|
-
return step;
|
|
19
|
-
}
|
|
20
|
-
const address = await signer.getAddress();
|
|
21
|
-
const fromAddress = step.action.fromAddress || address;
|
|
22
|
-
const toAddress = step.action.toAddress || address;
|
|
23
|
-
return {
|
|
24
|
-
...step,
|
|
25
|
-
action: {
|
|
26
|
-
...step.action,
|
|
27
|
-
fromAddress,
|
|
28
|
-
toAddress,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
exports.personalizeStep = personalizeStep;
|
|
33
|
-
const splitListIntoChunks = (list, chunkSize) => list.reduce((resultList, item, index) => {
|
|
34
|
-
const chunkIndex = Math.floor(index / chunkSize);
|
|
35
|
-
if (!resultList[chunkIndex]) {
|
|
36
|
-
resultList[chunkIndex] = []; // start a new chunk
|
|
37
|
-
}
|
|
38
|
-
resultList[chunkIndex].push(item);
|
|
39
|
-
return resultList;
|
|
40
|
-
}, []);
|
|
41
|
-
exports.splitListIntoChunks = splitListIntoChunks;
|
|
42
|
-
const formatTokenAmountOnly = (token, amount) => {
|
|
43
|
-
if (!amount) {
|
|
44
|
-
return '0.0';
|
|
45
|
-
}
|
|
46
|
-
let floated;
|
|
47
|
-
if (typeof amount === 'string') {
|
|
48
|
-
if (amount === '0') {
|
|
49
|
-
return '0.0';
|
|
50
|
-
}
|
|
51
|
-
floated = new bignumber_js_1.default(amount).shiftedBy(-token.decimals);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
floated = amount;
|
|
55
|
-
if (floated.isZero()) {
|
|
56
|
-
return '0.0';
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// show at least 4 decimal places and at least two non-zero digests
|
|
60
|
-
let decimalPlaces = 3;
|
|
61
|
-
while (floated.lt(1 / 10 ** decimalPlaces)) {
|
|
62
|
-
decimalPlaces++;
|
|
63
|
-
}
|
|
64
|
-
return floated.toFixed(decimalPlaces + 1, 1);
|
|
65
|
-
};
|
|
66
|
-
exports.formatTokenAmountOnly = formatTokenAmountOnly;
|
|
10
|
+
exports.wait = wait;
|
|
67
11
|
/**
|
|
68
12
|
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
69
13
|
* @param toRepeat The function that should be repeated
|
|
@@ -75,35 +19,22 @@ const repeatUntilDone = async (toRepeat, timeout = 5000) => {
|
|
|
75
19
|
while (!result) {
|
|
76
20
|
result = await toRepeat();
|
|
77
21
|
if (!result) {
|
|
78
|
-
await (0, exports.
|
|
22
|
+
await (0, exports.wait)(timeout);
|
|
79
23
|
}
|
|
80
24
|
}
|
|
81
25
|
return result;
|
|
82
26
|
};
|
|
83
27
|
exports.repeatUntilDone = repeatUntilDone;
|
|
84
|
-
/**
|
|
85
|
-
* Loads a transaction receipt using the rpc for the given chain id
|
|
86
|
-
* @param chainId The chain id where the transaction should be loaded from
|
|
87
|
-
* @param txHash The hash of the transaction
|
|
88
|
-
* @returns TransactionReceipt
|
|
89
|
-
*/
|
|
90
|
-
const loadTransactionReceipt = async (chainId, txHash) => {
|
|
91
|
-
const rpc = await (0, connectors_1.getRpcProvider)(chainId);
|
|
92
|
-
const tx = await rpc.getTransaction(txHash);
|
|
93
|
-
return tx.wait();
|
|
94
|
-
};
|
|
95
|
-
exports.loadTransactionReceipt = loadTransactionReceipt;
|
|
96
28
|
const isZeroAddress = (address) => {
|
|
97
|
-
if (address ===
|
|
98
|
-
address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
|
|
29
|
+
if (address === constants_1.AddressZero || address === constants_1.AlternativeAddressZero) {
|
|
99
30
|
return true;
|
|
100
31
|
}
|
|
101
32
|
return false;
|
|
102
33
|
};
|
|
103
34
|
exports.isZeroAddress = isZeroAddress;
|
|
104
35
|
const isNativeTokenAddress = (address) => {
|
|
105
|
-
if (address ===
|
|
106
|
-
address ===
|
|
36
|
+
if (address === constants_1.AddressZero ||
|
|
37
|
+
address === constants_1.AlternativeAddressZero ||
|
|
107
38
|
// CELO native token
|
|
108
39
|
address === '0x471ece3750da237f93b8e339c536989b8978a438') {
|
|
109
40
|
return true;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk";
|
|
2
|
-
export declare const version = "
|
|
2
|
+
export declare const version = "3.0.0-alpha.2";
|
package/dist/cjs/version.js
CHANGED
package/dist/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/connectors.js
CHANGED
|
@@ -1,53 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
2
|
+
import * as chains from 'viem/chains'; // TODO: optimize using BE chains
|
|
3
3
|
import ConfigService from './services/ConfigService';
|
|
4
|
-
import { ChainId } from './types';
|
|
5
4
|
import { ServerError } from './utils/errors';
|
|
6
5
|
// cached providers
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
[ChainId.ETH]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/eth/mainnet/archive',
|
|
11
|
-
[ChainId.BSC]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/bsc/mainnet/archive',
|
|
12
|
-
[ChainId.POL]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/polygon/mainnet/archive',
|
|
13
|
-
[ChainId.FTM]: 'https://speedy-nodes-nyc.moralis.io/5ed6053dc39eba789ff466c9/fantom/mainnet',
|
|
6
|
+
const publicClients = {};
|
|
7
|
+
export const getChainById = (chainId) => {
|
|
8
|
+
return Object.values(chains).find((chain) => chain.id === chainId);
|
|
14
9
|
};
|
|
15
10
|
// RPC Urls
|
|
16
|
-
export const getRpcUrl = async (chainId
|
|
17
|
-
const rpcUrls = await getRpcUrls(chainId
|
|
11
|
+
export const getRpcUrl = async (chainId) => {
|
|
12
|
+
const rpcUrls = await getRpcUrls(chainId);
|
|
18
13
|
return rpcUrls[0];
|
|
19
14
|
};
|
|
20
|
-
export const getRpcUrls = async (chainId
|
|
21
|
-
if (archive && archiveRpcs[chainId]) {
|
|
22
|
-
return [archiveRpcs[chainId]];
|
|
23
|
-
}
|
|
15
|
+
export const getRpcUrls = async (chainId) => {
|
|
24
16
|
const configService = ConfigService.getInstance();
|
|
25
17
|
const config = await configService.getConfigAsync();
|
|
26
18
|
return config.rpcs[chainId];
|
|
27
19
|
};
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
new StaticJsonRpcProvider(await getRpcUrl(chainId, archive), chainId),
|
|
38
|
-
]);
|
|
39
|
-
}
|
|
40
|
-
if (!chainProviders[chainId]?.length) {
|
|
41
|
-
chainProviders[chainId] = [];
|
|
42
|
-
const urls = await getRpcUrls(chainId, archive);
|
|
43
|
-
urls.forEach((url) => {
|
|
44
|
-
chainProviders[chainId].push(new FallbackProvider([new StaticJsonRpcProvider(url, chainId)]));
|
|
20
|
+
export const getPublicClient = async (chainId) => {
|
|
21
|
+
if (!publicClients[chainId]) {
|
|
22
|
+
const urls = await getRpcUrls(chainId);
|
|
23
|
+
const fallbackTransports = urls.map((url) => http(url, {
|
|
24
|
+
batch: true,
|
|
25
|
+
}));
|
|
26
|
+
publicClients[chainId] = createPublicClient({
|
|
27
|
+
chain: getChainById(chainId),
|
|
28
|
+
transport: fallback(fallbackTransports),
|
|
45
29
|
});
|
|
46
30
|
}
|
|
47
|
-
if (!
|
|
31
|
+
if (!publicClients[chainId]) {
|
|
48
32
|
throw new ServerError(`Unable to configure provider for chain ${chainId}`);
|
|
49
33
|
}
|
|
50
|
-
return
|
|
34
|
+
return publicClients[chainId];
|
|
51
35
|
};
|
|
52
36
|
// Multicall
|
|
53
37
|
export const getMulticallAddress = async (chainId) => {
|
|
@@ -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,6 @@
|
|
|
1
|
+
export const AddressZero = '0x0000000000000000000000000000000000000000';
|
|
2
|
+
export const AlternativeAddressZero = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
3
|
+
/**
|
|
4
|
+
* Cronos require bigger multicall chunks than default 1024 (1 KB)
|
|
5
|
+
*/
|
|
6
|
+
export const 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
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import ConfigService from '../services/ConfigService';
|
|
2
2
|
import { ValidationError } from '../utils/errors';
|
|
3
|
-
import { handlePreRestart } from '../utils/preRestart';
|
|
4
3
|
import { StatusManager } from './StatusManager';
|
|
5
4
|
import { StepExecutor } from './StepExecutor';
|
|
5
|
+
import { prepareRestart } from './prepareRestart';
|
|
6
6
|
export class RouteExecutionManager {
|
|
7
7
|
constructor(configUpdate) {
|
|
8
8
|
this.executionDictionary = {};
|
|
9
9
|
this.executionPromiseDictionary = {};
|
|
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
|
-
this.executeRoute = async (
|
|
18
|
+
this.executeRoute = async (walletClient, route, settings) => {
|
|
19
19
|
// Deep clone to prevent side effects
|
|
20
20
|
const clonedRoute = structuredClone(route);
|
|
21
21
|
let executionPromise = this.executionPromiseDictionary[clonedRoute.id];
|
|
@@ -23,19 +23,19 @@ export class RouteExecutionManager {
|
|
|
23
23
|
if (executionPromise) {
|
|
24
24
|
return executionPromise;
|
|
25
25
|
}
|
|
26
|
-
executionPromise = this.executeSteps(
|
|
26
|
+
executionPromise = this.executeSteps(walletClient, clonedRoute, settings);
|
|
27
27
|
this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
|
|
28
28
|
return executionPromise;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @
|
|
36
|
-
* @throws {
|
|
32
|
+
* @param walletClient - The walletClient required to send the transactions.
|
|
33
|
+
* @param route - The route that is to be executed. Cannot be an active route.
|
|
34
|
+
* @param settings - An object containing settings and callbacks.
|
|
35
|
+
* @returns The executed route.
|
|
36
|
+
* @throws {LiFiError} Throws a LiFiError if the execution fails.
|
|
37
37
|
*/
|
|
38
|
-
this.resumeRoute = async (
|
|
38
|
+
this.resumeRoute = async (walletClient, route, settings) => {
|
|
39
39
|
// Deep clone to prevent side effects
|
|
40
40
|
const clonedRoute = structuredClone(route);
|
|
41
41
|
const execution = this.executionDictionary[clonedRoute.id];
|
|
@@ -50,12 +50,12 @@ export class RouteExecutionManager {
|
|
|
50
50
|
return executionPromise ?? clonedRoute;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
await
|
|
54
|
-
const executionPromise = this.executeSteps(
|
|
53
|
+
await prepareRestart(clonedRoute, walletClient);
|
|
54
|
+
const executionPromise = this.executeSteps(walletClient, clonedRoute, settings);
|
|
55
55
|
this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
|
|
56
56
|
return executionPromise;
|
|
57
57
|
};
|
|
58
|
-
this.executeSteps = async (
|
|
58
|
+
this.executeSteps = async (walletClient, route, settings) => {
|
|
59
59
|
const config = this.configService.getConfig();
|
|
60
60
|
const execution = {
|
|
61
61
|
route,
|
|
@@ -91,7 +91,7 @@ export class RouteExecutionManager {
|
|
|
91
91
|
execution.executors.push(stepExecutor);
|
|
92
92
|
// Check if we want to execute this step in the background
|
|
93
93
|
this.updateRouteExecution(route, execution.settings);
|
|
94
|
-
const executedStep = await stepExecutor.executeStep(
|
|
94
|
+
const executedStep = await stepExecutor.executeStep(walletClient, step);
|
|
95
95
|
// We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
|
|
96
96
|
if (executedStep.execution?.status !== 'DONE') {
|
|
97
97
|
this.stopExecution(route);
|
|
@@ -112,8 +112,8 @@ export class RouteExecutionManager {
|
|
|
112
112
|
};
|
|
113
113
|
/**
|
|
114
114
|
* Updates route execution to background or foreground state.
|
|
115
|
-
* @param
|
|
116
|
-
* @param
|
|
115
|
+
* @param route - A route that is currently in execution.
|
|
116
|
+
* @param settings - An object with execution settings.
|
|
117
117
|
*/
|
|
118
118
|
this.updateRouteExecution = (route, settings) => {
|
|
119
119
|
const execution = this.executionDictionary[route.id];
|
|
@@ -134,8 +134,8 @@ export class RouteExecutionManager {
|
|
|
134
134
|
};
|
|
135
135
|
/**
|
|
136
136
|
* Update the ExecutionSettings for an active route.
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
137
|
+
* @param settings - An object with execution settings.
|
|
138
|
+
* @param route - The active route that gets the new execution settings.
|
|
139
139
|
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
140
140
|
*/
|
|
141
141
|
this.updateExecutionSettings = (settings, route) => {
|
|
@@ -149,28 +149,10 @@ export class RouteExecutionManager {
|
|
|
149
149
|
...settings,
|
|
150
150
|
};
|
|
151
151
|
};
|
|
152
|
-
/**
|
|
153
|
-
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
154
|
-
* @param {Route} route - A route that is currently in execution.
|
|
155
|
-
* @deprecated use updateRouteExecution instead.
|
|
156
|
-
*/
|
|
157
|
-
this.moveExecutionToBackground = (route) => {
|
|
158
|
-
const execution = this.executionDictionary[route.id];
|
|
159
|
-
if (!execution) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
for (const executor of execution.executors) {
|
|
163
|
-
executor.setInteraction({ allowInteraction: false, allowUpdates: true });
|
|
164
|
-
}
|
|
165
|
-
execution.settings = {
|
|
166
|
-
...execution.settings,
|
|
167
|
-
executeInBackground: true,
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
152
|
/**
|
|
171
153
|
* Stops the execution of an active route.
|
|
172
|
-
* @param
|
|
173
|
-
* @
|
|
154
|
+
* @param route - A route that is currently in execution.
|
|
155
|
+
* @returns The stopped route.
|
|
174
156
|
*/
|
|
175
157
|
this.stopExecution = (route) => {
|
|
176
158
|
const execution = this.executionDictionary[route.id];
|
|
@@ -189,7 +171,7 @@ export class RouteExecutionManager {
|
|
|
189
171
|
};
|
|
190
172
|
/**
|
|
191
173
|
* Get the list of active routes.
|
|
192
|
-
* @
|
|
174
|
+
* @returns A list of routes.
|
|
193
175
|
*/
|
|
194
176
|
this.getActiveRoutes = () => {
|
|
195
177
|
return Object.values(this.executionDictionary)
|
|
@@ -198,8 +180,8 @@ export class RouteExecutionManager {
|
|
|
198
180
|
};
|
|
199
181
|
/**
|
|
200
182
|
* Return the current route information for given route. The route has to be active.
|
|
201
|
-
* @param
|
|
202
|
-
* @
|
|
183
|
+
* @param route - A route object.
|
|
184
|
+
* @returns The updated route.
|
|
203
185
|
*/
|
|
204
186
|
this.getActiveRoute = (route) => {
|
|
205
187
|
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;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { emptyExecution
|
|
1
|
+
import { emptyExecution } from '../types';
|
|
2
2
|
import { getProcessMessage } from './utils';
|
|
3
3
|
/**
|
|
4
4
|
* Manages status updates of a route and provides various functions for tracking processes
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @
|
|
5
|
+
* @param {Route} route The route this StatusManger belongs to.
|
|
6
|
+
* @param {InternalExecutionSettings} settings The ExecutionSettings for this route.
|
|
7
|
+
* @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
|
|
8
|
+
* @returns {StatusManager} An instance of StatusManager.
|
|
9
9
|
*/
|
|
10
10
|
export class StatusManager {
|
|
11
11
|
constructor(route, settings, internalUpdateRouteCallback) {
|
|
12
12
|
this.shouldUpdate = true;
|
|
13
13
|
/**
|
|
14
14
|
* Initializes the execution object of a Step.
|
|
15
|
-
* @param
|
|
16
|
-
* @
|
|
15
|
+
* @param step The current step in execution
|
|
16
|
+
* @returns The initialized execution object for this step and a function to update this step
|
|
17
17
|
*/
|
|
18
18
|
this.initExecutionObject = (step) => {
|
|
19
19
|
const currentExecution = step.execution || structuredClone(emptyExecution);
|
|
@@ -31,10 +31,10 @@ export class StatusManager {
|
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
33
|
* Create and push a new process into the execution.
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @
|
|
34
|
+
* @param step The step that should contain the new process.
|
|
35
|
+
* @param type Type of the process. Used to identify already existing processes.
|
|
36
|
+
* @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
37
|
+
* @returns Returns process.
|
|
38
38
|
*/
|
|
39
39
|
this.findOrCreateProcess = (step, type, status) => {
|
|
40
40
|
if (!step.execution?.process) {
|
|
@@ -60,11 +60,11 @@ export class StatusManager {
|
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
62
|
* Update a process object.
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
65
|
-
* @param
|
|
66
|
-
* @param
|
|
67
|
-
* @
|
|
63
|
+
* @param step The step where the process should be updated
|
|
64
|
+
* @param type The process type to update
|
|
65
|
+
* @param status The status the process gets.
|
|
66
|
+
* @param [params] Additional parameters to append to the process.
|
|
67
|
+
* @returns The update process
|
|
68
68
|
*/
|
|
69
69
|
this.updateProcess = (step, type, status, params) => {
|
|
70
70
|
if (!step.execution) {
|
|
@@ -112,9 +112,8 @@ export class StatusManager {
|
|
|
112
112
|
};
|
|
113
113
|
/**
|
|
114
114
|
* Remove a process from the execution
|
|
115
|
-
* @param
|
|
116
|
-
* @param
|
|
117
|
-
* @return {void}
|
|
115
|
+
* @param step The step where the process should be removed from
|
|
116
|
+
* @param type The process type to remove
|
|
118
117
|
*/
|
|
119
118
|
this.removeProcess = (step, type) => {
|
|
120
119
|
if (!step.execution) {
|
|
@@ -143,10 +142,10 @@ export class StatusManager {
|
|
|
143
142
|
}
|
|
144
143
|
/**
|
|
145
144
|
* Updates the execution object of a Step.
|
|
146
|
-
* @param
|
|
147
|
-
* @param
|
|
148
|
-
* @param
|
|
149
|
-
* @
|
|
145
|
+
* @param step The current step in execution
|
|
146
|
+
* @param status The status for the execution
|
|
147
|
+
* @param receipt Optional. Information about received tokens
|
|
148
|
+
* @returns The step with the updated execution object
|
|
150
149
|
*/
|
|
151
150
|
updateExecution(step, status, receipt) {
|
|
152
151
|
if (!step.execution) {
|