@lifi/sdk 3.6.0 → 3.6.2-beta.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/package.json +3 -3
- package/src/_cjs/core/BaseStepExecutor.js +13 -38
- package/src/_cjs/core/BaseStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/EVMStepExecutor.js +329 -359
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/checkAllowance.js +18 -9
- package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
- package/src/_cjs/core/EVM/checkPermitSupport.js +2 -2
- package/src/_cjs/core/EVM/checkPermitSupport.js.map +1 -1
- package/src/_cjs/core/EVM/permits/allowanceTransfer.js +8 -8
- package/src/_cjs/core/EVM/permits/allowanceTransfer.js.map +1 -1
- package/src/_cjs/core/EVM/permits/getNativePermit.js +12 -10
- package/src/_cjs/core/EVM/permits/getNativePermit.js.map +1 -1
- package/src/_cjs/core/EVM/permits/signPermit2Message.js +27 -26
- package/src/_cjs/core/EVM/permits/signPermit2Message.js.map +1 -1
- package/src/_cjs/core/EVM/permits/signatureTransfer.js +8 -8
- package/src/_cjs/core/EVM/permits/signatureTransfer.js.map +1 -1
- package/src/_cjs/core/EVM/typeguards.js +5 -2
- package/src/_cjs/core/EVM/typeguards.js.map +1 -1
- package/src/_cjs/core/EVM/types.js.map +1 -1
- package/src/_cjs/core/Solana/KeypairWalletAdapter.js +8 -33
- package/src/_cjs/core/Solana/KeypairWalletAdapter.js.map +1 -1
- package/src/_cjs/core/Solana/SolanaStepExecutor.js +97 -112
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/StatusManager.js +103 -136
- package/src/_cjs/core/StatusManager.js.map +1 -1
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js +136 -151
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_cjs/core/prepareRestart.js +7 -1
- package/src/_cjs/core/prepareRestart.js.map +1 -1
- package/src/_cjs/errors/SDKError.js +5 -30
- package/src/_cjs/errors/SDKError.js.map +1 -1
- package/src/_cjs/errors/baseError.js +2 -12
- package/src/_cjs/errors/baseError.js.map +1 -1
- package/src/_cjs/errors/httpError.js +6 -36
- package/src/_cjs/errors/httpError.js.map +1 -1
- package/src/_cjs/index.js +3 -2
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/services/api.js +2 -4
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/utils/withDedupe.js +1 -6
- package/src/_cjs/utils/withDedupe.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_cjs/version.js.map +1 -1
- package/src/_esm/core/BaseStepExecutor.js +13 -38
- package/src/_esm/core/BaseStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +367 -397
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/checkAllowance.js +18 -9
- package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
- package/src/_esm/core/EVM/checkPermitSupport.js +2 -2
- package/src/_esm/core/EVM/checkPermitSupport.js.map +1 -1
- package/src/_esm/core/EVM/permits/allowanceTransfer.js +8 -8
- package/src/_esm/core/EVM/permits/allowanceTransfer.js.map +1 -1
- package/src/_esm/core/EVM/permits/getNativePermit.js +12 -10
- package/src/_esm/core/EVM/permits/getNativePermit.js.map +1 -1
- package/src/_esm/core/EVM/permits/signPermit2Message.js +29 -28
- package/src/_esm/core/EVM/permits/signPermit2Message.js.map +1 -1
- package/src/_esm/core/EVM/permits/signatureTransfer.js +8 -8
- package/src/_esm/core/EVM/permits/signatureTransfer.js.map +1 -1
- package/src/_esm/core/EVM/typeguards.js +4 -2
- package/src/_esm/core/EVM/typeguards.js.map +1 -1
- package/src/_esm/core/EVM/types.js.map +1 -1
- package/src/_esm/core/Solana/KeypairWalletAdapter.js +12 -37
- package/src/_esm/core/Solana/KeypairWalletAdapter.js.map +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js +105 -120
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/StatusManager.js +132 -165
- package/src/_esm/core/StatusManager.js.map +1 -1
- package/src/_esm/core/UTXO/UTXOStepExecutor.js +144 -159
- package/src/_esm/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_esm/core/prepareRestart.js +10 -1
- package/src/_esm/core/prepareRestart.js.map +1 -1
- package/src/_esm/errors/SDKError.js +5 -30
- package/src/_esm/errors/SDKError.js.map +1 -1
- package/src/_esm/errors/baseError.js +2 -12
- package/src/_esm/errors/baseError.js.map +1 -1
- package/src/_esm/errors/httpError.js +6 -36
- package/src/_esm/errors/httpError.js.map +1 -1
- package/src/_esm/index.js +1 -1
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/services/api.js +2 -4
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/utils/withDedupe.js +1 -6
- package/src/_esm/utils/withDedupe.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_esm/version.js.map +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/EVM/checkAllowance.d.ts +2 -3
- package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
- package/src/_types/core/EVM/checkPermitSupport.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/allowanceTransfer.d.ts +4 -4
- package/src/_types/core/EVM/permits/allowanceTransfer.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/getNativePermit.d.ts +1 -2
- package/src/_types/core/EVM/permits/getNativePermit.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/signPermit2Message.d.ts +2 -11
- package/src/_types/core/EVM/permits/signPermit2Message.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/signatureTransfer.d.ts +2 -2
- package/src/_types/core/EVM/permits/signatureTransfer.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/types.d.ts +3 -9
- package/src/_types/core/EVM/permits/types.d.ts.map +1 -1
- package/src/_types/core/EVM/typeguards.d.ts +6 -2
- package/src/_types/core/EVM/typeguards.d.ts.map +1 -1
- package/src/_types/core/EVM/types.d.ts +2 -5
- package/src/_types/core/EVM/types.d.ts.map +1 -1
- package/src/_types/core/StatusManager.d.ts.map +1 -1
- package/src/_types/core/prepareRestart.d.ts.map +1 -1
- package/src/_types/core/types.d.ts +2 -0
- package/src/_types/core/types.d.ts.map +1 -1
- package/src/_types/index.d.ts +1 -1
- package/src/_types/index.d.ts.map +1 -1
- package/src/_types/services/api.d.ts +2 -2
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/_types/version.d.ts.map +1 -1
- package/src/core/EVM/EVMStepExecutor.ts +39 -44
- package/src/core/EVM/checkAllowance.ts +28 -19
- package/src/core/EVM/checkPermitSupport.ts +14 -2
- package/src/core/EVM/permits/allowanceTransfer.ts +14 -10
- package/src/core/EVM/permits/getNativePermit.ts +13 -11
- package/src/core/EVM/permits/signPermit2Message.ts +43 -63
- package/src/core/EVM/permits/signatureTransfer.ts +10 -10
- package/src/core/EVM/permits/types.ts +3 -16
- package/src/core/EVM/typeguards.ts +14 -4
- package/src/core/EVM/types.ts +2 -6
- package/src/core/StatusManager.ts +5 -3
- package/src/core/prepareRestart.ts +14 -2
- package/src/core/types.ts +2 -0
- package/src/index.ts +1 -1
- package/src/services/api.ts +3 -6
- package/src/version.ts +1 -1
- package/src/_cjs/core/EVM/permits/signNativePermitMessage.js +0 -20
- package/src/_cjs/core/EVM/permits/signNativePermitMessage.js.map +0 -1
- package/src/_cjs/core/EVM/permits/utils.js +0 -31
- package/src/_cjs/core/EVM/permits/utils.js.map +0 -1
- package/src/_esm/core/EVM/permits/signNativePermitMessage.js +0 -16
- package/src/_esm/core/EVM/permits/signNativePermitMessage.js.map +0 -1
- package/src/_esm/core/EVM/permits/utils.js +0 -26
- package/src/_esm/core/EVM/permits/utils.js.map +0 -1
- package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts +0 -4
- package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts.map +0 -1
- package/src/_types/core/EVM/permits/utils.d.ts +0 -6
- package/src/_types/core/EVM/permits/utils.d.ts.map +0 -1
- package/src/core/EVM/permits/signNativePermitMessage.ts +0 -27
- package/src/core/EVM/permits/utils.ts +0 -40
|
@@ -13,132 +13,117 @@ import { callSolanaWithRetry } from './connection.js';
|
|
|
13
13
|
import { parseSolanaErrors } from './parseSolanaErrors.js';
|
|
14
14
|
import { sendAndConfirmTransaction } from './sendAndConfirmTransaction.js';
|
|
15
15
|
export class SolanaStepExecutor extends BaseStepExecutor {
|
|
16
|
+
walletAdapter;
|
|
16
17
|
constructor(options) {
|
|
17
18
|
super(options);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
this.walletAdapter = options.walletAdapter;
|
|
20
|
+
}
|
|
21
|
+
checkWalletAdapter = (step) => {
|
|
22
|
+
// Prevent execution of the quote by wallet different from the one which requested the quote
|
|
23
|
+
if (this.walletAdapter.publicKey.toString() !== step.action.fromAddress) {
|
|
24
|
+
throw new TransactionError(LiFiErrorCode.WalletChangedDuringExecution, 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.');
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
executeStep = async (step) => {
|
|
28
|
+
step.execution = this.statusManager.initExecutionObject(step);
|
|
29
|
+
const fromChain = await config.getChainById(step.action.fromChainId);
|
|
30
|
+
const toChain = await config.getChainById(step.action.toChainId);
|
|
31
|
+
const isBridgeExecution = fromChain.id !== toChain.id;
|
|
32
|
+
const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP';
|
|
33
|
+
let process = this.statusManager.findOrCreateProcess({
|
|
34
|
+
step,
|
|
35
|
+
type: currentProcessType,
|
|
36
|
+
chainId: fromChain.id,
|
|
23
37
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
if (
|
|
31
|
-
|
|
38
|
+
if (process.status !== 'DONE') {
|
|
39
|
+
try {
|
|
40
|
+
process = this.statusManager.updateProcess(step, process.type, 'STARTED');
|
|
41
|
+
// Check balance
|
|
42
|
+
await checkBalance(this.walletAdapter.publicKey.toString(), step);
|
|
43
|
+
// Create new transaction
|
|
44
|
+
if (!step.transactionRequest) {
|
|
45
|
+
const { execution, ...stepBase } = step;
|
|
46
|
+
const updatedStep = await getStepTransaction(stepBase);
|
|
47
|
+
const comparedStep = await stepComparison(this.statusManager, step, updatedStep, this.allowUserInteraction, this.executionOptions);
|
|
48
|
+
Object.assign(step, {
|
|
49
|
+
...comparedStep,
|
|
50
|
+
execution: step.execution,
|
|
51
|
+
});
|
|
32
52
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
if (!step.transactionRequest?.data) {
|
|
54
|
+
throw new TransactionError(LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
55
|
+
}
|
|
56
|
+
process = this.statusManager.updateProcess(step, process.type, 'ACTION_REQUIRED');
|
|
57
|
+
if (!this.allowUserInteraction) {
|
|
58
|
+
return step;
|
|
59
|
+
}
|
|
60
|
+
let transactionRequest = {
|
|
61
|
+
data: step.transactionRequest.data,
|
|
62
|
+
};
|
|
63
|
+
if (this.executionOptions?.updateTransactionRequestHook) {
|
|
64
|
+
const customizedTransactionRequest = await this.executionOptions.updateTransactionRequestHook({
|
|
65
|
+
requestType: 'transaction',
|
|
66
|
+
...transactionRequest,
|
|
67
|
+
});
|
|
68
|
+
transactionRequest = {
|
|
69
|
+
...transactionRequest,
|
|
70
|
+
...customizedTransactionRequest,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (!transactionRequest.data) {
|
|
74
|
+
throw new TransactionError(LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
75
|
+
}
|
|
76
|
+
const versionedTransaction = VersionedTransaction.deserialize(base64ToUint8Array(transactionRequest.data));
|
|
77
|
+
this.checkWalletAdapter(step);
|
|
78
|
+
// We give users 2 minutes to sign the transaction or it should be considered expired
|
|
79
|
+
const signedTx = await withTimeout(() => this.walletAdapter.signTransaction(versionedTransaction), {
|
|
80
|
+
// https://solana.com/docs/advanced/confirmation#transaction-expiration
|
|
81
|
+
// Use 2 minutes to account for fluctuations
|
|
82
|
+
timeout: 120_000,
|
|
83
|
+
errorInstance: new TransactionError(LiFiErrorCode.TransactionExpired, 'Transaction has expired: blockhash is no longer recent enough.'),
|
|
49
84
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (this.executionOptions?.updateTransactionRequestHook) {
|
|
76
|
-
const customizedTransactionRequest = await this.executionOptions.updateTransactionRequestHook({
|
|
77
|
-
requestType: 'transaction',
|
|
78
|
-
...transactionRequest,
|
|
79
|
-
});
|
|
80
|
-
transactionRequest = {
|
|
81
|
-
...transactionRequest,
|
|
82
|
-
...customizedTransactionRequest,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
if (!transactionRequest.data) {
|
|
86
|
-
throw new TransactionError(LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
87
|
-
}
|
|
88
|
-
const versionedTransaction = VersionedTransaction.deserialize(base64ToUint8Array(transactionRequest.data));
|
|
89
|
-
this.checkWalletAdapter(step);
|
|
90
|
-
// We give users 2 minutes to sign the transaction or it should be considered expired
|
|
91
|
-
const signedTx = await withTimeout(() => this.walletAdapter.signTransaction(versionedTransaction), {
|
|
92
|
-
// https://solana.com/docs/advanced/confirmation#transaction-expiration
|
|
93
|
-
// Use 2 minutes to account for fluctuations
|
|
94
|
-
timeout: 120_000,
|
|
95
|
-
errorInstance: new TransactionError(LiFiErrorCode.TransactionExpired, 'Transaction has expired: blockhash is no longer recent enough.'),
|
|
96
|
-
});
|
|
97
|
-
process = this.statusManager.updateProcess(step, process.type, 'PENDING');
|
|
98
|
-
const simulationResult = await callSolanaWithRetry((connection) => connection.simulateTransaction(signedTx, {
|
|
99
|
-
commitment: 'confirmed',
|
|
100
|
-
replaceRecentBlockhash: true,
|
|
101
|
-
}));
|
|
102
|
-
if (simulationResult.value.err) {
|
|
103
|
-
throw new TransactionError(LiFiErrorCode.TransactionSimulationFailed, 'Transaction simulation failed');
|
|
104
|
-
}
|
|
105
|
-
const confirmedTx = await sendAndConfirmTransaction(signedTx);
|
|
106
|
-
if (!confirmedTx.signatureResult) {
|
|
107
|
-
throw new TransactionError(LiFiErrorCode.TransactionExpired, 'Transaction has expired: The block height has exceeded the maximum allowed limit.');
|
|
108
|
-
}
|
|
109
|
-
if (confirmedTx.signatureResult.err) {
|
|
110
|
-
const reason = typeof confirmedTx.signatureResult.err === 'object'
|
|
111
|
-
? JSON.stringify(confirmedTx.signatureResult.err)
|
|
112
|
-
: confirmedTx.signatureResult.err;
|
|
113
|
-
throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${reason}`);
|
|
114
|
-
}
|
|
115
|
-
// Transaction has been confirmed and we can update the process
|
|
116
|
-
process = this.statusManager.updateProcess(step, process.type, 'PENDING', {
|
|
117
|
-
txHash: confirmedTx.txSignature,
|
|
118
|
-
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${confirmedTx.txSignature}`,
|
|
119
|
-
});
|
|
120
|
-
if (isBridgeExecution) {
|
|
121
|
-
process = this.statusManager.updateProcess(step, process.type, 'DONE');
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
const error = await parseSolanaErrors(e, step, process);
|
|
126
|
-
process = this.statusManager.updateProcess(step, process.type, 'FAILED', {
|
|
127
|
-
error: {
|
|
128
|
-
message: error.cause.message,
|
|
129
|
-
code: error.code,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
this.statusManager.updateExecution(step, 'FAILED');
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
85
|
+
process = this.statusManager.updateProcess(step, process.type, 'PENDING');
|
|
86
|
+
const simulationResult = await callSolanaWithRetry((connection) => connection.simulateTransaction(signedTx, {
|
|
87
|
+
commitment: 'confirmed',
|
|
88
|
+
replaceRecentBlockhash: true,
|
|
89
|
+
}));
|
|
90
|
+
if (simulationResult.value.err) {
|
|
91
|
+
throw new TransactionError(LiFiErrorCode.TransactionSimulationFailed, 'Transaction simulation failed');
|
|
92
|
+
}
|
|
93
|
+
const confirmedTx = await sendAndConfirmTransaction(signedTx);
|
|
94
|
+
if (!confirmedTx.signatureResult) {
|
|
95
|
+
throw new TransactionError(LiFiErrorCode.TransactionExpired, 'Transaction has expired: The block height has exceeded the maximum allowed limit.');
|
|
96
|
+
}
|
|
97
|
+
if (confirmedTx.signatureResult.err) {
|
|
98
|
+
const reason = typeof confirmedTx.signatureResult.err === 'object'
|
|
99
|
+
? JSON.stringify(confirmedTx.signatureResult.err)
|
|
100
|
+
: confirmedTx.signatureResult.err;
|
|
101
|
+
throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${reason}`);
|
|
102
|
+
}
|
|
103
|
+
// Transaction has been confirmed and we can update the process
|
|
104
|
+
process = this.statusManager.updateProcess(step, process.type, 'PENDING', {
|
|
105
|
+
txHash: confirmedTx.txSignature,
|
|
106
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${confirmedTx.txSignature}`,
|
|
107
|
+
});
|
|
108
|
+
if (isBridgeExecution) {
|
|
109
|
+
process = this.statusManager.updateProcess(step, process.type, 'DONE');
|
|
135
110
|
}
|
|
136
|
-
await waitForDestinationChainTransaction(step, process, fromChain, toChain, this.statusManager);
|
|
137
|
-
// DONE
|
|
138
|
-
return step;
|
|
139
111
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
112
|
+
catch (e) {
|
|
113
|
+
const error = await parseSolanaErrors(e, step, process);
|
|
114
|
+
process = this.statusManager.updateProcess(step, process.type, 'FAILED', {
|
|
115
|
+
error: {
|
|
116
|
+
message: error.cause.message,
|
|
117
|
+
code: error.code,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
this.statusManager.updateExecution(step, 'FAILED');
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
await waitForDestinationChainTransaction(step, process, fromChain, toChain, this.statusManager);
|
|
125
|
+
// DONE
|
|
126
|
+
return step;
|
|
127
|
+
};
|
|
143
128
|
}
|
|
144
129
|
//# sourceMappingURL=SolanaStepExecutor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaStepExecutor.js","sourceRoot":"","sources":["../../../core/Solana/SolanaStepExecutor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AACtE,OAAO,EAAE,gBAAg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wBACL,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;wBAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;qBACjB;iBACF,CACF,CAAA;gBACD,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;gBAClD,MAAM,KAAK,CAAA;YACb,CAAC;QACH,CAAC;QAED,MAAM,kCAAkC,CACtC,IAAI,EACJ,OAAO,EACP,SAAS,EACT,OAAO,EACP,IAAI,CAAC,aAAa,CACnB,CAAA;QAED,OAAO;QACP,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;CACF"}
|
|
@@ -6,174 +6,33 @@ import { getProcessMessage } from './processMessages.js';
|
|
|
6
6
|
* @returns {StatusManager} An instance of StatusManager.
|
|
7
7
|
*/
|
|
8
8
|
export class StatusManager {
|
|
9
|
+
routeId;
|
|
10
|
+
shouldUpdate = true;
|
|
9
11
|
constructor(routeId) {
|
|
10
|
-
Object.defineProperty(this, "routeId", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value: void 0
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(this, "shouldUpdate", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true,
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Initializes the execution object of a Step.
|
|
24
|
-
* @param step The current step in execution
|
|
25
|
-
* @returns The initialized execution object for this step and a function to update this step
|
|
26
|
-
*/
|
|
27
|
-
Object.defineProperty(this, "initExecutionObject", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: (step) => {
|
|
32
|
-
if (!step.execution) {
|
|
33
|
-
step.execution = {
|
|
34
|
-
status: 'PENDING',
|
|
35
|
-
process: [],
|
|
36
|
-
};
|
|
37
|
-
this.updateStepInRoute(step);
|
|
38
|
-
}
|
|
39
|
-
// Change status to PENDING after resuming from FAILED
|
|
40
|
-
if (step.execution.status === 'FAILED') {
|
|
41
|
-
step.execution.status = 'PENDING';
|
|
42
|
-
this.updateStepInRoute(step);
|
|
43
|
-
}
|
|
44
|
-
return step.execution;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
/**
|
|
48
|
-
* Create and push a new process into the execution.
|
|
49
|
-
* @param step The step that should contain the new process.
|
|
50
|
-
* @param type Type of the process. Used to identify already existing processes.
|
|
51
|
-
* @param chainId Chain Id of the process.
|
|
52
|
-
* @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
53
|
-
* @returns Returns process.
|
|
54
|
-
*/
|
|
55
|
-
Object.defineProperty(this, "findOrCreateProcess", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: ({ step, type, chainId, status, }) => {
|
|
60
|
-
const process = this.findProcess(step, type, status);
|
|
61
|
-
if (process) {
|
|
62
|
-
return process;
|
|
63
|
-
}
|
|
64
|
-
const newProcess = {
|
|
65
|
-
type: type,
|
|
66
|
-
startedAt: Date.now(),
|
|
67
|
-
message: getProcessMessage(type, status ?? 'STARTED'),
|
|
68
|
-
status: status ?? 'STARTED',
|
|
69
|
-
chainId: chainId,
|
|
70
|
-
};
|
|
71
|
-
step.execution.process.push(newProcess);
|
|
72
|
-
this.updateStepInRoute(step);
|
|
73
|
-
return newProcess;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
/**
|
|
77
|
-
* Update a process object.
|
|
78
|
-
* @param step The step where the process should be updated
|
|
79
|
-
* @param type The process type to update
|
|
80
|
-
* @param status The status the process gets.
|
|
81
|
-
* @param [params] Additional parameters to append to the process.
|
|
82
|
-
* @returns The update process
|
|
83
|
-
*/
|
|
84
|
-
Object.defineProperty(this, "updateProcess", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
configurable: true,
|
|
87
|
-
writable: true,
|
|
88
|
-
value: (step, type, status, params) => {
|
|
89
|
-
if (!step.execution) {
|
|
90
|
-
throw new Error("Can't update an empty step execution.");
|
|
91
|
-
}
|
|
92
|
-
const currentProcess = this.findProcess(step, type);
|
|
93
|
-
if (!currentProcess) {
|
|
94
|
-
throw new Error("Can't find a process for the given type.");
|
|
95
|
-
}
|
|
96
|
-
switch (status) {
|
|
97
|
-
case 'STARTED':
|
|
98
|
-
currentProcess.startedAt = Date.now();
|
|
99
|
-
break;
|
|
100
|
-
case 'CANCELLED':
|
|
101
|
-
currentProcess.doneAt = Date.now();
|
|
102
|
-
break;
|
|
103
|
-
case 'FAILED':
|
|
104
|
-
currentProcess.doneAt = Date.now();
|
|
105
|
-
step.execution.status = 'FAILED';
|
|
106
|
-
break;
|
|
107
|
-
case 'DONE':
|
|
108
|
-
currentProcess.doneAt = Date.now();
|
|
109
|
-
break;
|
|
110
|
-
case 'PENDING':
|
|
111
|
-
step.execution.status = 'PENDING';
|
|
112
|
-
break;
|
|
113
|
-
case 'ACTION_REQUIRED':
|
|
114
|
-
step.execution.status = 'ACTION_REQUIRED';
|
|
115
|
-
break;
|
|
116
|
-
default:
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
currentProcess.status = status;
|
|
120
|
-
currentProcess.message = getProcessMessage(type, status);
|
|
121
|
-
// set extra parameters or overwritte the standard params set in the switch statement
|
|
122
|
-
if (params) {
|
|
123
|
-
for (const [key, value] of Object.entries(params)) {
|
|
124
|
-
currentProcess[key] = value;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// Sort processes, the ones with DONE status go first
|
|
128
|
-
step.execution.process = [
|
|
129
|
-
...step.execution.process.filter((process) => process.status === 'DONE'),
|
|
130
|
-
...step.execution.process.filter((process) => process.status !== 'DONE'),
|
|
131
|
-
];
|
|
132
|
-
this.updateStepInRoute(step); // updates the step in the route
|
|
133
|
-
return currentProcess;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
/**
|
|
137
|
-
* Remove a process from the execution
|
|
138
|
-
* @param step The step where the process should be removed from
|
|
139
|
-
* @param type The process type to remove
|
|
140
|
-
*/
|
|
141
|
-
Object.defineProperty(this, "removeProcess", {
|
|
142
|
-
enumerable: true,
|
|
143
|
-
configurable: true,
|
|
144
|
-
writable: true,
|
|
145
|
-
value: (step, type) => {
|
|
146
|
-
if (!step.execution) {
|
|
147
|
-
throw new Error("Execution hasn't been initialized.");
|
|
148
|
-
}
|
|
149
|
-
const index = step.execution.process.findIndex((p) => p.type === type);
|
|
150
|
-
step.execution.process.splice(index, 1);
|
|
151
|
-
this.updateStepInRoute(step);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
Object.defineProperty(this, "updateStepInRoute", {
|
|
155
|
-
enumerable: true,
|
|
156
|
-
configurable: true,
|
|
157
|
-
writable: true,
|
|
158
|
-
value: (step) => {
|
|
159
|
-
if (!this.shouldUpdate) {
|
|
160
|
-
return step;
|
|
161
|
-
}
|
|
162
|
-
const data = executionState.get(this.routeId);
|
|
163
|
-
if (!data) {
|
|
164
|
-
throw new Error('Execution data not found.');
|
|
165
|
-
}
|
|
166
|
-
const stepIndex = data.route.steps.findIndex((routeStep) => routeStep.id === step.id);
|
|
167
|
-
if (stepIndex === -1) {
|
|
168
|
-
throw new Error("Couldn't find a step to update.");
|
|
169
|
-
}
|
|
170
|
-
data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step };
|
|
171
|
-
data.executionOptions?.updateRouteHook?.(data.route);
|
|
172
|
-
return data.route.steps[stepIndex];
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
12
|
this.routeId = routeId;
|
|
176
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Initializes the execution object of a Step.
|
|
16
|
+
* @param step The current step in execution
|
|
17
|
+
* @returns The initialized execution object for this step and a function to update this step
|
|
18
|
+
*/
|
|
19
|
+
initExecutionObject = (step) => {
|
|
20
|
+
if (!step.execution) {
|
|
21
|
+
step.execution = {
|
|
22
|
+
status: 'PENDING',
|
|
23
|
+
process: [],
|
|
24
|
+
startedAt: Date.now(),
|
|
25
|
+
};
|
|
26
|
+
this.updateStepInRoute(step);
|
|
27
|
+
}
|
|
28
|
+
// Change status to PENDING after resuming from FAILED
|
|
29
|
+
if (step.execution.status === 'FAILED') {
|
|
30
|
+
step.execution.startedAt = Date.now();
|
|
31
|
+
step.execution.status = 'PENDING';
|
|
32
|
+
this.updateStepInRoute(step);
|
|
33
|
+
}
|
|
34
|
+
return step.execution;
|
|
35
|
+
};
|
|
177
36
|
/**
|
|
178
37
|
* Updates the execution object of a Step.
|
|
179
38
|
* @param step The current step in execution
|
|
@@ -186,6 +45,9 @@ export class StatusManager {
|
|
|
186
45
|
throw Error("Can't update empty execution.");
|
|
187
46
|
}
|
|
188
47
|
step.execution.status = status;
|
|
48
|
+
if (status === 'DONE') {
|
|
49
|
+
step.execution.doneAt = Date.now();
|
|
50
|
+
}
|
|
189
51
|
if (execution) {
|
|
190
52
|
step.execution = {
|
|
191
53
|
...step.execution,
|
|
@@ -213,6 +75,111 @@ export class StatusManager {
|
|
|
213
75
|
}
|
|
214
76
|
return process;
|
|
215
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Create and push a new process into the execution.
|
|
80
|
+
* @param step The step that should contain the new process.
|
|
81
|
+
* @param type Type of the process. Used to identify already existing processes.
|
|
82
|
+
* @param chainId Chain Id of the process.
|
|
83
|
+
* @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
|
|
84
|
+
* @returns Returns process.
|
|
85
|
+
*/
|
|
86
|
+
findOrCreateProcess = ({ step, type, chainId, status, }) => {
|
|
87
|
+
const process = this.findProcess(step, type, status);
|
|
88
|
+
if (process) {
|
|
89
|
+
return process;
|
|
90
|
+
}
|
|
91
|
+
const newProcess = {
|
|
92
|
+
type: type,
|
|
93
|
+
startedAt: Date.now(),
|
|
94
|
+
message: getProcessMessage(type, status ?? 'STARTED'),
|
|
95
|
+
status: status ?? 'STARTED',
|
|
96
|
+
chainId: chainId,
|
|
97
|
+
};
|
|
98
|
+
step.execution.process.push(newProcess);
|
|
99
|
+
this.updateStepInRoute(step);
|
|
100
|
+
return newProcess;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Update a process object.
|
|
104
|
+
* @param step The step where the process should be updated
|
|
105
|
+
* @param type The process type to update
|
|
106
|
+
* @param status The status the process gets.
|
|
107
|
+
* @param [params] Additional parameters to append to the process.
|
|
108
|
+
* @returns The update process
|
|
109
|
+
*/
|
|
110
|
+
updateProcess = (step, type, status, params) => {
|
|
111
|
+
if (!step.execution) {
|
|
112
|
+
throw new Error("Can't update an empty step execution.");
|
|
113
|
+
}
|
|
114
|
+
const currentProcess = this.findProcess(step, type);
|
|
115
|
+
if (!currentProcess) {
|
|
116
|
+
throw new Error("Can't find a process for the given type.");
|
|
117
|
+
}
|
|
118
|
+
switch (status) {
|
|
119
|
+
case 'CANCELLED':
|
|
120
|
+
currentProcess.doneAt = Date.now();
|
|
121
|
+
break;
|
|
122
|
+
case 'FAILED':
|
|
123
|
+
currentProcess.doneAt = Date.now();
|
|
124
|
+
step.execution.status = 'FAILED';
|
|
125
|
+
break;
|
|
126
|
+
case 'DONE':
|
|
127
|
+
currentProcess.doneAt = Date.now();
|
|
128
|
+
break;
|
|
129
|
+
case 'PENDING':
|
|
130
|
+
step.execution.status = 'PENDING';
|
|
131
|
+
break;
|
|
132
|
+
case 'ACTION_REQUIRED':
|
|
133
|
+
step.execution.status = 'ACTION_REQUIRED';
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
currentProcess.status = status;
|
|
139
|
+
currentProcess.message = getProcessMessage(type, status);
|
|
140
|
+
// set extra parameters or overwritte the standard params set in the switch statement
|
|
141
|
+
if (params) {
|
|
142
|
+
for (const [key, value] of Object.entries(params)) {
|
|
143
|
+
currentProcess[key] = value;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Sort processes, the ones with DONE status go first
|
|
147
|
+
step.execution.process = [
|
|
148
|
+
...step.execution.process.filter((process) => process.status === 'DONE'),
|
|
149
|
+
...step.execution.process.filter((process) => process.status !== 'DONE'),
|
|
150
|
+
];
|
|
151
|
+
this.updateStepInRoute(step); // updates the step in the route
|
|
152
|
+
return currentProcess;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Remove a process from the execution
|
|
156
|
+
* @param step The step where the process should be removed from
|
|
157
|
+
* @param type The process type to remove
|
|
158
|
+
*/
|
|
159
|
+
removeProcess = (step, type) => {
|
|
160
|
+
if (!step.execution) {
|
|
161
|
+
throw new Error("Execution hasn't been initialized.");
|
|
162
|
+
}
|
|
163
|
+
const index = step.execution.process.findIndex((p) => p.type === type);
|
|
164
|
+
step.execution.process.splice(index, 1);
|
|
165
|
+
this.updateStepInRoute(step);
|
|
166
|
+
};
|
|
167
|
+
updateStepInRoute = (step) => {
|
|
168
|
+
if (!this.shouldUpdate) {
|
|
169
|
+
return step;
|
|
170
|
+
}
|
|
171
|
+
const data = executionState.get(this.routeId);
|
|
172
|
+
if (!data) {
|
|
173
|
+
throw new Error('Execution data not found.');
|
|
174
|
+
}
|
|
175
|
+
const stepIndex = data.route.steps.findIndex((routeStep) => routeStep.id === step.id);
|
|
176
|
+
if (stepIndex === -1) {
|
|
177
|
+
throw new Error("Couldn't find a step to update.");
|
|
178
|
+
}
|
|
179
|
+
data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step };
|
|
180
|
+
data.executionOptions?.updateRouteHook?.(data.route);
|
|
181
|
+
return data.route.steps[stepIndex];
|
|
182
|
+
};
|
|
216
183
|
allowUpdates(value) {
|
|
217
184
|
this.shouldUpdate = value;
|
|
218
185
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatusManager.js","sourceRoot":"","sources":["../../core/StatusManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,M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