@lifi/sdk-provider-ethereum 4.2.6 → 4.2.8
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/CHANGELOG.md +33 -0
- package/README.md +9 -0
- package/dist/cjs/EthereumProvider.js +5 -1
- package/dist/cjs/EthereumProvider.js.map +1 -1
- package/dist/cjs/actions/waitForBatchTransactionReceipt.d.ts +25 -1
- package/dist/cjs/actions/waitForBatchTransactionReceipt.js +55 -7
- package/dist/cjs/actions/waitForBatchTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/waitForRelayedTransactionReceipt.d.ts +13 -1
- package/dist/cjs/actions/waitForRelayedTransactionReceipt.js +19 -5
- package/dist/cjs/actions/waitForRelayedTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/waitForSafeTransactionExecution.js +2 -2
- package/dist/cjs/actions/waitForSafeTransactionExecution.js.map +1 -1
- package/dist/cjs/actions/waitForTransactionReceipt.js +2 -2
- package/dist/cjs/actions/waitForTransactionReceipt.js.map +1 -1
- package/dist/cjs/client/publicClient.js +14 -5
- package/dist/cjs/client/publicClient.js.map +1 -1
- package/dist/cjs/core/EthereumStepExecutor.js +1 -1
- package/dist/cjs/core/EthereumStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js +3 -0
- package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js +7 -3
- package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckAllowanceTask.js +5 -4
- package/dist/cjs/core/tasks/EthereumCheckAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumPrepareTransactionTask.js +10 -1
- package/dist/cjs/core/tasks/EthereumPrepareTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumRelayedSignAndExecuteTask.js +5 -2
- package/dist/cjs/core/tasks/EthereumRelayedSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumRelayedWaitForTransactionTask.js +10 -2
- package/dist/cjs/core/tasks/EthereumRelayedWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumResetAllowanceTask.js +2 -2
- package/dist/cjs/core/tasks/EthereumResetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js +2 -3
- package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumSignAndExecuteTask.js +1 -0
- package/dist/cjs/core/tasks/EthereumSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js +2 -0
- package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumWaitForTransactionTask.js +8 -1
- package/dist/cjs/core/tasks/EthereumWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.d.ts +6 -0
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js +15 -0
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.d.ts +17 -0
- package/dist/cjs/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.js +27 -0
- package/dist/cjs/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/resolveAllowanceSpender.d.ts +16 -0
- package/dist/cjs/core/tasks/helpers/resolveAllowanceSpender.js +21 -0
- package/dist/cjs/core/tasks/helpers/resolveAllowanceSpender.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/shouldCheckForAllowance.js +2 -1
- package/dist/cjs/core/tasks/helpers/shouldCheckForAllowance.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.d.ts +5 -1
- package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.js +8 -1
- package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/signTypedDataEntries.d.ts +6 -2
- package/dist/cjs/core/tasks/helpers/signTypedDataEntries.js +7 -2
- package/dist/cjs/core/tasks/helpers/signTypedDataEntries.js.map +1 -1
- package/dist/cjs/errors/parseEthereumErrors.js +10 -2
- package/dist/cjs/errors/parseEthereumErrors.js.map +1 -1
- package/dist/cjs/types.d.ts +6 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/EthereumProvider.d.ts.map +1 -1
- package/dist/esm/EthereumProvider.js +5 -1
- package/dist/esm/EthereumProvider.js.map +1 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.d.ts +25 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.d.ts.map +1 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.js +55 -7
- package/dist/esm/actions/waitForBatchTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/waitForRelayedTransactionReceipt.d.ts +13 -1
- package/dist/esm/actions/waitForRelayedTransactionReceipt.d.ts.map +1 -1
- package/dist/esm/actions/waitForRelayedTransactionReceipt.js +19 -5
- package/dist/esm/actions/waitForRelayedTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/waitForSafeTransactionExecution.js +2 -2
- package/dist/esm/actions/waitForSafeTransactionExecution.js.map +1 -1
- package/dist/esm/actions/waitForTransactionReceipt.js +2 -2
- package/dist/esm/actions/waitForTransactionReceipt.js.map +1 -1
- package/dist/esm/client/publicClient.d.ts.map +1 -1
- package/dist/esm/client/publicClient.js +14 -5
- package/dist/esm/client/publicClient.js.map +1 -1
- package/dist/esm/core/EthereumStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/EthereumStepExecutor.js +2 -2
- package/dist/esm/core/EthereumStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.js +4 -1
- package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js +7 -3
- package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumCheckAllowanceTask.js +5 -4
- package/dist/esm/core/tasks/EthereumCheckAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumPrepareTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumPrepareTransactionTask.js +12 -3
- package/dist/esm/core/tasks/EthereumPrepareTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.js +6 -3
- package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.js +10 -2
- package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumResetAllowanceTask.js +2 -2
- package/dist/esm/core/tasks/EthereumResetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumSetAllowanceTask.js +2 -3
- package/dist/esm/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumSignAndExecuteTask.js +2 -1
- package/dist/esm/core/tasks/EthereumSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js +3 -1
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumWaitForTransactionTask.js +9 -2
- package/dist/esm/core/tasks/EthereumWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.d.ts +6 -0
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js +15 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
- package/dist/esm/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.d.ts +17 -0
- package/dist/esm/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.js +26 -0
- package/dist/esm/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.js.map +1 -0
- package/dist/esm/core/tasks/helpers/resolveAllowanceSpender.d.ts +16 -0
- package/dist/esm/core/tasks/helpers/resolveAllowanceSpender.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/resolveAllowanceSpender.js +20 -0
- package/dist/esm/core/tasks/helpers/resolveAllowanceSpender.js.map +1 -0
- package/dist/esm/core/tasks/helpers/shouldCheckForAllowance.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/shouldCheckForAllowance.js +2 -1
- package/dist/esm/core/tasks/helpers/shouldCheckForAllowance.js.map +1 -1
- package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.d.ts +5 -1
- package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.js +8 -1
- package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.js.map +1 -1
- package/dist/esm/core/tasks/helpers/signTypedDataEntries.d.ts +6 -2
- package/dist/esm/core/tasks/helpers/signTypedDataEntries.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/signTypedDataEntries.js +7 -2
- package/dist/esm/core/tasks/helpers/signTypedDataEntries.js.map +1 -1
- package/dist/esm/errors/parseEthereumErrors.d.ts.map +1 -1
- package/dist/esm/errors/parseEthereumErrors.js +10 -2
- package/dist/esm/errors/parseEthereumErrors.js.map +1 -1
- package/dist/esm/types.d.ts +6 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -3
- package/src/EthereumProvider.ts +6 -1
- package/src/actions/waitForBatchTransactionReceipt.ts +119 -13
- package/src/actions/waitForRelayedTransactionReceipt.ts +45 -10
- package/src/actions/waitForSafeTransactionExecution.ts +6 -2
- package/src/actions/waitForTransactionReceipt.ts +6 -2
- package/src/client/publicClient.ts +20 -8
- package/src/core/EthereumStepExecutor.ts +8 -6
- package/src/core/tasks/EthereumBatchedSignAndExecuteTask.ts +11 -0
- package/src/core/tasks/EthereumBatchedWaitForTransactionTask.ts +17 -13
- package/src/core/tasks/EthereumCheckAllowanceTask.ts +5 -7
- package/src/core/tasks/EthereumPrepareTransactionTask.ts +47 -4
- package/src/core/tasks/EthereumRelayedSignAndExecuteTask.ts +22 -2
- package/src/core/tasks/EthereumRelayedWaitForTransactionTask.ts +40 -8
- package/src/core/tasks/EthereumResetAllowanceTask.ts +3 -6
- package/src/core/tasks/EthereumSetAllowanceTask.ts +4 -8
- package/src/core/tasks/EthereumSignAndExecuteTask.ts +5 -0
- package/src/core/tasks/EthereumStandardSignAndExecuteTask.ts +10 -0
- package/src/core/tasks/EthereumWaitForTransactionTask.ts +33 -2
- package/src/core/tasks/helpers/getEthereumExecutionStrategy.ts +28 -0
- package/src/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.ts +37 -0
- package/src/core/tasks/helpers/resolveAllowanceSpender.ts +24 -0
- package/src/core/tasks/helpers/shouldCheckForAllowance.ts +9 -5
- package/src/core/tasks/helpers/signHyperliquidTypedData.ts +9 -1
- package/src/core/tasks/helpers/signTypedDataEntries.ts +8 -2
- package/src/errors/parseEthereumErrors.ts +18 -10
- package/src/types.ts +6 -0
- package/src/version.ts +1 -1
|
@@ -2,12 +2,20 @@ import { updateActionWithReceipt } from "./helpers/updateActionWithReceipt.js";
|
|
|
2
2
|
import { waitForRelayedTransactionReceipt } from "../../actions/waitForRelayedTransactionReceipt.js";
|
|
3
3
|
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
4
4
|
//#region src/core/tasks/EthereumRelayedWaitForTransactionTask.ts
|
|
5
|
+
/** The same check as the SDK's internal `isAbortError`. */
|
|
6
|
+
const isAbortError = (error) => typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
|
|
5
7
|
var EthereumRelayedWaitForTransactionTask = class extends BaseStepExecutionTask {
|
|
6
8
|
async run(context) {
|
|
7
|
-
const { client, step, statusManager, fromChain, isBridgeExecution } = context;
|
|
9
|
+
const { client, step, statusManager, fromChain, isBridgeExecution, signal } = context;
|
|
8
10
|
const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
9
11
|
if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
|
|
10
|
-
|
|
12
|
+
let transactionReceipt;
|
|
13
|
+
try {
|
|
14
|
+
transactionReceipt = await waitForRelayedTransactionReceipt(client, action.taskId, step, void 0, signal);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (signal?.aborted && isAbortError(error)) return { status: "PAUSED" };
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
11
19
|
updateActionWithReceipt(statusManager, step, fromChain, transactionReceipt, action);
|
|
12
20
|
if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
|
|
13
21
|
return { status: "COMPLETED" };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumRelayedWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumRelayedWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Hash } from 'viem'\nimport { waitForRelayedTransactionReceipt } from '../../actions/waitForRelayedTransactionReceipt.js'\nimport type {
|
|
1
|
+
{"version":3,"file":"EthereumRelayedWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumRelayedWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Hash } from 'viem'\nimport { waitForRelayedTransactionReceipt } from '../../actions/waitForRelayedTransactionReceipt.js'\nimport type {\n EthereumStepExecutorContext,\n WalletCallReceipt,\n} from '../../types.js'\nimport { updateActionWithReceipt } from './helpers/updateActionWithReceipt.js'\n\n/** The same check as the SDK's internal `isAbortError`. */\nconst isAbortError = (error: unknown): boolean =>\n typeof error === 'object' &&\n error !== null &&\n 'name' in error &&\n error.name === 'AbortError'\n\nexport class EthereumRelayedWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signal,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n let transactionReceipt: WalletCallReceipt\n try {\n // The wait starts after the relay request, so it may take the signal of\n // `stopRouteExecution`.\n transactionReceipt = await waitForRelayedTransactionReceipt(\n client,\n action.taskId as Hash,\n step,\n undefined,\n signal\n )\n } catch (error) {\n // `stopRouteExecution` ended the wait; the outcome of the relayed\n // transaction is still unknown. Pause like a stopped step, with no\n // write: the stored action keeps its task id, and a resume waits for it\n // again.\n if (signal?.aborted && isAbortError(error)) {\n return { status: 'PAUSED' }\n }\n throw error\n }\n\n updateActionWithReceipt(\n statusManager,\n step,\n fromChain,\n transactionReceipt,\n action\n )\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;;AAeA,MAAM,gBAAgB,UACpB,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS;AAEjB,IAAa,wCAAb,cAA2D,sBAAsB;CAC/E,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,QACA,MACA,eACA,WACA,mBACA,WACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,IAAI;EACJ,IAAI;GAGF,qBAAqB,MAAM,iCACzB,QACA,OAAO,QACP,MACA,KAAA,GACA,MACF;EACF,SAAS,OAAO;GAKd,IAAI,QAAQ,WAAW,aAAa,KAAK,GACvC,OAAO,EAAE,QAAQ,SAAS;GAE5B,MAAM;EACR;EAEA,wBACE,eACA,MACA,WACA,oBACA,MACF;EAEA,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEthereumExecutionStrategy } from "./helpers/getEthereumExecutionStrategy.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveAllowanceSpender } from "./helpers/resolveAllowanceSpender.js";
|
|
3
3
|
import { resolveTransactionHash } from "../../actions/resolveTransactionHash.js";
|
|
4
4
|
import { setAllowance } from "../../actions/setAllowance.js";
|
|
5
5
|
import { waitForTransactionReceipt } from "../../actions/waitForTransactionReceipt.js";
|
|
@@ -26,7 +26,7 @@ var EthereumResetAllowanceTask = class extends BaseStepExecutionTask {
|
|
|
26
26
|
if (!allowUserInteraction) return { status: "PAUSED" };
|
|
27
27
|
const executionStrategy = await getEthereumExecutionStrategy(context);
|
|
28
28
|
const batchingSupported = executionStrategy === "batched";
|
|
29
|
-
const spenderAddress = await
|
|
29
|
+
const { spenderAddress } = await resolveAllowanceSpender(context, executionStrategy);
|
|
30
30
|
const updatedClient = await checkClient(step);
|
|
31
31
|
if (!updatedClient) return { status: "PAUSED" };
|
|
32
32
|
const resetResult = await setAllowance(client, updatedClient, step.action.fromToken.address, spenderAddress, 0n, executionOptions, batchingSupported);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumResetAllowanceTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumResetAllowanceTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { resolveTransactionHash } from '../../actions/resolveTransactionHash.js'\nimport { setAllowance } from '../../actions/setAllowance.js'\nimport { waitForTransactionReceipt } from '../../actions/waitForTransactionReceipt.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\nimport { getTxLink } from './helpers/getTxLink.js'\nimport {
|
|
1
|
+
{"version":3,"file":"EthereumResetAllowanceTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumResetAllowanceTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { resolveTransactionHash } from '../../actions/resolveTransactionHash.js'\nimport { setAllowance } from '../../actions/setAllowance.js'\nimport { waitForTransactionReceipt } from '../../actions/waitForTransactionReceipt.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\nimport { getTxLink } from './helpers/getTxLink.js'\nimport { resolveAllowanceSpender } from './helpers/resolveAllowanceSpender.js'\n\nexport class EthereumResetAllowanceTask extends BaseStepExecutionTask {\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n const { step, hasMatchingPermit, hasSufficientAllowance, hasAllowance } =\n context\n\n return (\n !hasMatchingPermit &&\n !hasSufficientAllowance &&\n !!step.estimate.approvalReset &&\n !!hasAllowance\n )\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n allowUserInteraction,\n checkClient,\n fromChain,\n executionOptions,\n client,\n calls: currentCalls,\n } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'RESET_ALLOWANCE',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n statusManager.updateAction(step, action.type, 'RESET_REQUIRED', {\n txHash: undefined,\n txLink: undefined,\n })\n\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n const executionStrategy = await getEthereumExecutionStrategy(context)\n const batchingSupported = executionStrategy === 'batched'\n const { spenderAddress } = await resolveAllowanceSpender(\n context,\n executionStrategy\n )\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n // Reset allowance to 0 if required\n const resetResult = await setAllowance(\n client,\n updatedClient,\n step.action.fromToken.address as Address,\n spenderAddress,\n 0n,\n executionOptions,\n batchingSupported\n )\n\n const calls = [...currentCalls]\n if (batchingSupported) {\n calls.push({\n to: step.action.fromToken.address as Address,\n data: resetResult,\n chainId: step.action.fromToken.chainId,\n })\n } else {\n const resolvedTxHash = await resolveTransactionHash(\n client,\n updatedClient,\n resetResult,\n fromChain.id\n )\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: resolvedTxHash,\n txLink: getTxLink(fromChain, resolvedTxHash),\n })\n\n const transactionReceipt = await waitForTransactionReceipt(client, {\n client: updatedClient,\n chainId: fromChain.id,\n txHash: resetResult as Address,\n onReplaced(response) {\n const newHash = response.transaction.hash\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: newHash,\n txLink: getTxLink(fromChain, newHash),\n })\n },\n })\n\n const finalHash = transactionReceipt?.transactionHash || resolvedTxHash\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: finalHash,\n txLink: getTxLink(fromChain, finalHash),\n })\n }\n\n statusManager.updateAction(step, action.type, 'DONE')\n\n return {\n status: 'COMPLETED',\n context: { calls, executionStrategy },\n }\n }\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,6BAAb,cAAgD,sBAAsB;CACpE,MAAe,UACb,SACkB;EAClB,MAAM,EAAE,MAAM,mBAAmB,wBAAwB,iBACvD;EAEF,OACE,CAAC,qBACD,CAAC,0BACD,CAAC,CAAC,KAAK,SAAS,iBAChB,CAAC,CAAC;CAEN;CAEA,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,eACA,sBACA,aACA,WACA,kBACA,QACA,OAAO,iBACL;EAEJ,MAAM,SAAS,cAAc,iBAAiB;GAC5C;GACA,MAAM;GACN,SAAS,KAAK,OAAO;GACrB,QAAQ;EACV,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,kBAAkB;GAC9D,QAAQ,KAAA;GACR,QAAQ,KAAA;EACV,CAAC;EAED,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,oBAAoB,MAAM,6BAA6B,OAAO;EACpE,MAAM,oBAAoB,sBAAsB;EAChD,MAAM,EAAE,mBAAmB,MAAM,wBAC/B,SACA,iBACF;EAEA,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAI5B,MAAM,cAAc,MAAM,aACxB,QACA,eACA,KAAK,OAAO,UAAU,SACtB,gBACA,IACA,kBACA,iBACF;EAEA,MAAM,QAAQ,CAAC,GAAG,YAAY;EAC9B,IAAI,mBACF,MAAM,KAAK;GACT,IAAI,KAAK,OAAO,UAAU;GAC1B,MAAM;GACN,SAAS,KAAK,OAAO,UAAU;EACjC,CAAC;OACI;GACL,MAAM,iBAAiB,MAAM,uBAC3B,QACA,eACA,aACA,UAAU,EACZ;GACA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;IACvD,QAAQ;IACR,QAAQ,UAAU,WAAW,cAAc;GAC7C,CAAC;GAeD,MAAM,aAAY,MAbe,0BAA0B,QAAQ;IACjE,QAAQ;IACR,SAAS,UAAU;IACnB,QAAQ;IACR,WAAW,UAAU;KACnB,MAAM,UAAU,SAAS,YAAY;KACrC,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;MACvD,QAAQ;MACR,QAAQ,UAAU,WAAW,OAAO;KACtC,CAAC;IACH;GACF,CAAC,EAAA,EAEqC,mBAAmB;GACzD,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;IACvD,QAAQ;IACR,QAAQ,UAAU,WAAW,SAAS;GACxC,CAAC;EACH;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAEpD,OAAO;GACL,QAAQ;GACR,SAAS;IAAE;IAAO;GAAkB;EACtC;CACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEthereumExecutionStrategy } from "./helpers/getEthereumExecutionStrategy.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveAllowanceSpender } from "./helpers/resolveAllowanceSpender.js";
|
|
3
3
|
import { resolveTransactionHash } from "../../actions/resolveTransactionHash.js";
|
|
4
4
|
import { setAllowance } from "../../actions/setAllowance.js";
|
|
5
5
|
import { waitForTransactionReceipt } from "../../actions/waitForTransactionReceipt.js";
|
|
@@ -26,9 +26,8 @@ var EthereumSetAllowanceTask = class extends BaseStepExecutionTask {
|
|
|
26
26
|
if (!allowUserInteraction) return { status: "PAUSED" };
|
|
27
27
|
const executionStrategy = await getEthereumExecutionStrategy(context);
|
|
28
28
|
const batchingSupported = executionStrategy === "batched";
|
|
29
|
-
const permit2Supported = await
|
|
29
|
+
const { permit2Supported, spenderAddress } = await resolveAllowanceSpender(context, executionStrategy);
|
|
30
30
|
const approveAmount = getApprovalAmount(context, permit2Supported);
|
|
31
|
-
const spenderAddress = permit2Supported ? fromChain.permit2 : step.estimate.approvalAddress;
|
|
32
31
|
const updatedClient = await checkClient(step);
|
|
33
32
|
if (!updatedClient) return { status: "PAUSED" };
|
|
34
33
|
const approveResult = await setAllowance(client, updatedClient, step.action.fromToken.address, spenderAddress, approveAmount, executionOptions, batchingSupported);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumSetAllowanceTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumSetAllowanceTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { resolveTransactionHash } from '../../actions/resolveTransactionHash.js'\nimport { setAllowance } from '../../actions/setAllowance.js'\nimport { waitForTransactionReceipt } from '../../actions/waitForTransactionReceipt.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getApprovalAmount } from './helpers/getApprovalAmount.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\nimport { getTxLink } from './helpers/getTxLink.js'\nimport {
|
|
1
|
+
{"version":3,"file":"EthereumSetAllowanceTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumSetAllowanceTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { resolveTransactionHash } from '../../actions/resolveTransactionHash.js'\nimport { setAllowance } from '../../actions/setAllowance.js'\nimport { waitForTransactionReceipt } from '../../actions/waitForTransactionReceipt.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getApprovalAmount } from './helpers/getApprovalAmount.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\nimport { getTxLink } from './helpers/getTxLink.js'\nimport { resolveAllowanceSpender } from './helpers/resolveAllowanceSpender.js'\n\nexport class EthereumSetAllowanceTask extends BaseStepExecutionTask {\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n return !context.hasMatchingPermit && !context.hasSufficientAllowance\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n statusManager,\n executionOptions,\n fromChain,\n allowUserInteraction,\n checkClient,\n calls: currentCalls,\n } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'SET_ALLOWANCE',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n // Clear the txHash and txLink from potential previous approval transaction\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED', {\n txHash: undefined,\n txLink: undefined,\n })\n\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n const executionStrategy = await getEthereumExecutionStrategy(context)\n const batchingSupported = executionStrategy === 'batched'\n // Check if chain has Permit2 contract deployed. Permit2 should not be available for atomic batch.\n const { permit2Supported, spenderAddress } = await resolveAllowanceSpender(\n context,\n executionStrategy\n )\n\n // Set new allowance\n const approveAmount = getApprovalAmount(context, permit2Supported)\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const approveResult = await setAllowance(\n client,\n updatedClient,\n step.action.fromToken.address as Address,\n spenderAddress,\n approveAmount,\n executionOptions,\n // We need to return the populated transaction when batching is supported\n // instead of executing transaction on-chain\n batchingSupported\n )\n\n const calls = [...currentCalls]\n if (batchingSupported) {\n calls.push({\n to: step.action.fromToken.address as Address,\n data: approveResult,\n chainId: step.action.fromToken.chainId,\n })\n\n statusManager.updateAction(step, action.type, 'DONE')\n } else {\n const resolvedTxHash = await resolveTransactionHash(\n client,\n updatedClient,\n approveResult,\n fromChain.id\n )\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: resolvedTxHash,\n txLink: getTxLink(fromChain, resolvedTxHash),\n })\n\n const transactionReceipt = await waitForTransactionReceipt(client, {\n client: updatedClient,\n chainId: fromChain.id,\n txHash: approveResult,\n onReplaced(response) {\n const newHash = response.transaction.hash\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: newHash,\n txLink: getTxLink(fromChain, newHash),\n })\n },\n })\n\n const finalHash = transactionReceipt?.transactionHash || resolvedTxHash\n statusManager.updateAction(step, action.type, 'DONE', {\n txHash: finalHash,\n txLink: getTxLink(fromChain, finalHash),\n })\n }\n\n return {\n status: 'COMPLETED',\n context: { calls, executionStrategy },\n }\n }\n}\n"],"mappings":";;;;;;;;;AAWA,IAAa,2BAAb,cAA8C,sBAAsB;CAClE,MAAe,UACb,SACkB;EAClB,OAAO,CAAC,QAAQ,qBAAqB,CAAC,QAAQ;CAChD;CAEA,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,QACA,eACA,kBACA,WACA,sBACA,aACA,OAAO,iBACL;EAEJ,MAAM,SAAS,cAAc,iBAAiB;GAC5C;GACA,MAAM;GACN,SAAS,KAAK,OAAO;GACrB,QAAQ;EACV,CAAC;EAGD,cAAc,aAAa,MAAM,OAAO,MAAM,mBAAmB;GAC/D,QAAQ,KAAA;GACR,QAAQ,KAAA;EACV,CAAC;EAED,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,oBAAoB,MAAM,6BAA6B,OAAO;EACpE,MAAM,oBAAoB,sBAAsB;EAEhD,MAAM,EAAE,kBAAkB,mBAAmB,MAAM,wBACjD,SACA,iBACF;EAGA,MAAM,gBAAgB,kBAAkB,SAAS,gBAAgB;EAEjE,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,gBAAgB,MAAM,aAC1B,QACA,eACA,KAAK,OAAO,UAAU,SACtB,gBACA,eACA,kBAGA,iBACF;EAEA,MAAM,QAAQ,CAAC,GAAG,YAAY;EAC9B,IAAI,mBAAmB;GACrB,MAAM,KAAK;IACT,IAAI,KAAK,OAAO,UAAU;IAC1B,MAAM;IACN,SAAS,KAAK,OAAO,UAAU;GACjC,CAAC;GAED,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EACtD,OAAO;GACL,MAAM,iBAAiB,MAAM,uBAC3B,QACA,eACA,eACA,UAAU,EACZ;GACA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;IACvD,QAAQ;IACR,QAAQ,UAAU,WAAW,cAAc;GAC7C,CAAC;GAeD,MAAM,aAAY,MAbe,0BAA0B,QAAQ;IACjE,QAAQ;IACR,SAAS,UAAU;IACnB,QAAQ;IACR,WAAW,UAAU;KACnB,MAAM,UAAU,SAAS,YAAY;KACrC,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;MACvD,QAAQ;MACR,QAAQ,UAAU,WAAW,OAAO;KACtC,CAAC;IACH;GACF,CAAC,EAAA,EAEqC,mBAAmB;GACzD,cAAc,aAAa,MAAM,OAAO,MAAM,QAAQ;IACpD,QAAQ;IACR,QAAQ,UAAU,WAAW,SAAS;GACxC,CAAC;EACH;EAEA,OAAO;GACL,QAAQ;GACR,SAAS;IAAE;IAAO;GAAkB;EACtC;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumSignAndExecuteTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EthereumSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumSignAndExecuteTask.ts"],"mappings":";;;qBAaa,mCAAmC;EAC9C,IAAU,SAAS,8BAA8B,QAAQ"}
|
|
@@ -2,13 +2,14 @@ import { getEthereumExecutionStrategy } from "./helpers/getEthereumExecutionStra
|
|
|
2
2
|
import { EthereumBatchedSignAndExecuteTask } from "./EthereumBatchedSignAndExecuteTask.js";
|
|
3
3
|
import { EthereumRelayedSignAndExecuteTask } from "./EthereumRelayedSignAndExecuteTask.js";
|
|
4
4
|
import { EthereumStandardSignAndExecuteTask } from "./EthereumStandardSignAndExecuteTask.js";
|
|
5
|
-
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
5
|
+
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError, assertNoOpenTransaction } from "@lifi/sdk";
|
|
6
6
|
//#region src/core/tasks/EthereumSignAndExecuteTask.ts
|
|
7
7
|
var EthereumSignAndExecuteTask = class extends BaseStepExecutionTask {
|
|
8
8
|
async run(context) {
|
|
9
9
|
const { step, statusManager, allowUserInteraction, transactionRequest, isBridgeExecution } = context;
|
|
10
10
|
const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
11
11
|
if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
|
|
12
|
+
assertNoOpenTransaction(action);
|
|
12
13
|
statusManager.updateAction(step, action.type, "ACTION_REQUIRED");
|
|
13
14
|
if (!allowUserInteraction) return { status: "PAUSED" };
|
|
14
15
|
const executionStrategy = await getEthereumExecutionStrategy(context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumSignAndExecuteTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { EthereumBatchedSignAndExecuteTask } from './EthereumBatchedSignAndExecuteTask.js'\nimport { EthereumRelayedSignAndExecuteTask } from './EthereumRelayedSignAndExecuteTask.js'\nimport { EthereumStandardSignAndExecuteTask } from './EthereumStandardSignAndExecuteTask.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\n\nexport class EthereumSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n allowUserInteraction,\n transactionRequest,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n const executionStrategy = await getEthereumExecutionStrategy(context)\n if (executionStrategy === 'batched' && transactionRequest) {\n return new EthereumBatchedSignAndExecuteTask().run(context)\n }\n if (executionStrategy === 'relayed') {\n return new EthereumRelayedSignAndExecuteTask().run(context)\n }\n return new EthereumStandardSignAndExecuteTask().run(context)\n }\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"EthereumSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { EthereumBatchedSignAndExecuteTask } from './EthereumBatchedSignAndExecuteTask.js'\nimport { EthereumRelayedSignAndExecuteTask } from './EthereumRelayedSignAndExecuteTask.js'\nimport { EthereumStandardSignAndExecuteTask } from './EthereumStandardSignAndExecuteTask.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\n\nexport class EthereumSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n allowUserInteraction,\n transactionRequest,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Defence in depth for every lane below: the selector never routes an open\n // transaction here, and signing again could execute the swap twice.\n assertNoOpenTransaction(action)\n\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n const executionStrategy = await getEthereumExecutionStrategy(context)\n if (executionStrategy === 'batched' && transactionRequest) {\n return new EthereumBatchedSignAndExecuteTask().run(context)\n }\n if (executionStrategy === 'relayed') {\n return new EthereumRelayedSignAndExecuteTask().run(context)\n }\n return new EthereumStandardSignAndExecuteTask().run(context)\n }\n}\n"],"mappings":";;;;;;AAaA,IAAa,6BAAb,cAAgD,sBAAsB;CACpE,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,eACA,sBACA,oBACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAKF,wBAAwB,MAAM;EAE9B,cAAc,aAAa,MAAM,OAAO,MAAM,iBAAiB;EAE/D,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,oBAAoB,MAAM,6BAA6B,OAAO;EACpE,IAAI,sBAAsB,aAAa,oBACrC,OAAO,IAAI,kCAAkC,CAAC,CAAC,IAAI,OAAO;EAE5D,IAAI,sBAAsB,WACxB,OAAO,IAAI,kCAAkC,CAAC,CAAC,IAAI,OAAO;EAE5D,OAAO,IAAI,mCAAmC,CAAC,CAAC,IAAI,OAAO;CAC7D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumStandardSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumStandardSignAndExecuteTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EthereumStandardSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumStandardSignAndExecuteTask.ts"],"mappings":";;;qBAsBa,2CAA2C;EACtD,IAAU,SAAS,8BAA8B,QAAQ"}
|
|
@@ -7,7 +7,7 @@ import { signPermit2Message } from "../../permits/signPermit2Message.js";
|
|
|
7
7
|
import { convertExtendedChain } from "../../utils/convertExtendedChain.js";
|
|
8
8
|
import { estimateTransactionRequest } from "./helpers/estimateTransactionRequest.js";
|
|
9
9
|
import { findSignedNativePermit } from "./helpers/findSignedNativePermit.js";
|
|
10
|
-
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
10
|
+
import { BaseStepExecutionTask, CLEARED_TRANSACTION_FIELDS, LiFiErrorCode, TransactionError, assertNoOpenTransaction } from "@lifi/sdk";
|
|
11
11
|
import { sendTransaction } from "viem/actions";
|
|
12
12
|
import { getAction } from "viem/utils";
|
|
13
13
|
//#region src/core/tasks/EthereumStandardSignAndExecuteTask.ts
|
|
@@ -44,6 +44,7 @@ var EthereumStandardSignAndExecuteTask = class extends BaseStepExecutionTask {
|
|
|
44
44
|
};
|
|
45
45
|
finalTransactionRequest = await estimateTransactionRequest(client, updatedClient, finalTransactionRequest);
|
|
46
46
|
}
|
|
47
|
+
assertNoOpenTransaction(statusManager.findAction(step, action.type));
|
|
47
48
|
const txHash = await getAction(updatedClient, sendTransaction, "sendTransaction")({
|
|
48
49
|
to: finalTransactionRequest.to,
|
|
49
50
|
account: updatedClient.account,
|
|
@@ -57,6 +58,7 @@ var EthereumStandardSignAndExecuteTask = class extends BaseStepExecutionTask {
|
|
|
57
58
|
});
|
|
58
59
|
const resolvedTxHash = await resolveTransactionHash(client, updatedClient, txHash, fromChain.id);
|
|
59
60
|
statusManager.updateAction(step, action.type, "PENDING", {
|
|
61
|
+
...CLEARED_TRANSACTION_FIELDS,
|
|
60
62
|
txHash: resolvedTxHash,
|
|
61
63
|
txLink: getTxLink(fromChain, resolvedTxHash),
|
|
62
64
|
txType: "standard",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumStandardSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumStandardSignAndExecuteTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Address, Hex, SendTransactionParameters } from 'viem'\nimport { sendTransaction } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { resolveTransactionHash } from '../../actions/resolveTransactionHash.js'\nimport { encodeNativePermitData } from '../../permits/encodeNativePermitData.js'\nimport { encodePermit2Data } from '../../permits/encodePermit2Data.js'\nimport { signPermit2Message } from '../../permits/signPermit2Message.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { convertExtendedChain } from '../../utils/convertExtendedChain.js'\nimport { estimateTransactionRequest } from './helpers/estimateTransactionRequest.js'\nimport { findSignedNativePermit } from './helpers/findSignedNativePermit.js'\nimport { getTxLink } from './helpers/getTxLink.js'\nimport { resolvePermit2Support } from './helpers/resolvePermit2Support.js'\n\nexport class EthereumStandardSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n fromChain,\n statusManager,\n checkClient,\n transactionRequest,\n allowUserInteraction,\n isBridgeExecution,\n } = context\n\n if (!transactionRequest) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction request is not found.'\n )\n }\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Make sure that the chain is still correct\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const signedNativePermitTypedData = findSignedNativePermit(context)\n // Resolved *after* the native-permit lookup, and short-circuited when one\n // is found: a matching permit always wins, so resolving the gate first\n // would spend an `eth_getCode` on a verdict this task never reads. The\n // ternary also makes the two routes explicitly exclusive.\n const permit2Supported = signedNativePermitTypedData\n ? false\n : await resolvePermit2Support(context, 'standard')\n if (signedNativePermitTypedData) {\n transactionRequest.data = encodeNativePermitData(\n step.action.fromToken.address as Address,\n BigInt(step.action.fromAmount),\n signedNativePermitTypedData.message.deadline,\n signedNativePermitTypedData.signature,\n transactionRequest.data as Hex\n )\n } else if (permit2Supported) {\n statusManager.updateAction(step, action.type, 'MESSAGE_REQUIRED')\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n const permit2Signature = await signPermit2Message(client, {\n client: updatedClient,\n chain: fromChain,\n tokenAddress: step.action.fromToken.address as Address,\n amount: BigInt(step.action.fromAmount),\n data: transactionRequest.data as Hex,\n })\n transactionRequest.data = encodePermit2Data(\n step.action.fromToken.address as Address,\n BigInt(step.action.fromAmount),\n permit2Signature.message.nonce,\n permit2Signature.message.deadline,\n transactionRequest.data as Hex,\n permit2Signature.signature\n )\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n }\n\n let finalTransactionRequest = transactionRequest\n if (signedNativePermitTypedData || permit2Supported) {\n // Target address should be the Permit2 proxy contract in case of native permit or Permit2\n finalTransactionRequest = {\n ...transactionRequest,\n to: fromChain.permit2Proxy as Address,\n }\n finalTransactionRequest = await estimateTransactionRequest(\n client,\n updatedClient,\n finalTransactionRequest\n )\n }\n\n const txHash = await getAction(\n updatedClient,\n sendTransaction,\n 'sendTransaction'\n )({\n to: finalTransactionRequest.to as Address,\n account: updatedClient.account!,\n data: finalTransactionRequest.data as Hex,\n value: finalTransactionRequest.value,\n gas: finalTransactionRequest.gas,\n gasPrice: finalTransactionRequest.gasPrice,\n maxFeePerGas: finalTransactionRequest.maxFeePerGas,\n maxPriorityFeePerGas: finalTransactionRequest.maxPriorityFeePerGas,\n chain: convertExtendedChain(fromChain),\n } as SendTransactionParameters)\n\n const resolvedTxHash = await resolveTransactionHash(\n client,\n updatedClient,\n txHash,\n fromChain.id\n )\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: resolvedTxHash,\n txLink: getTxLink(fromChain, resolvedTxHash),\n txType: 'standard',\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n context: {\n transactionRequest: finalTransactionRequest,\n },\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"EthereumStandardSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumStandardSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Address, Hex, SendTransactionParameters } from 'viem'\nimport { sendTransaction } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { resolveTransactionHash } from '../../actions/resolveTransactionHash.js'\nimport { encodeNativePermitData } from '../../permits/encodeNativePermitData.js'\nimport { encodePermit2Data } from '../../permits/encodePermit2Data.js'\nimport { signPermit2Message } from '../../permits/signPermit2Message.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { convertExtendedChain } from '../../utils/convertExtendedChain.js'\nimport { estimateTransactionRequest } from './helpers/estimateTransactionRequest.js'\nimport { findSignedNativePermit } from './helpers/findSignedNativePermit.js'\nimport { getTxLink } from './helpers/getTxLink.js'\nimport { resolvePermit2Support } from './helpers/resolvePermit2Support.js'\n\nexport class EthereumStandardSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n fromChain,\n statusManager,\n checkClient,\n transactionRequest,\n allowUserInteraction,\n isBridgeExecution,\n } = context\n\n if (!transactionRequest) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction request is not found.'\n )\n }\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Make sure that the chain is still correct\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const signedNativePermitTypedData = findSignedNativePermit(context)\n // Resolved *after* the native-permit lookup, and short-circuited when one\n // is found: a matching permit always wins, so resolving the gate first\n // would spend an `eth_getCode` on a verdict this task never reads. The\n // ternary also makes the two routes explicitly exclusive.\n const permit2Supported = signedNativePermitTypedData\n ? false\n : await resolvePermit2Support(context, 'standard')\n if (signedNativePermitTypedData) {\n transactionRequest.data = encodeNativePermitData(\n step.action.fromToken.address as Address,\n BigInt(step.action.fromAmount),\n signedNativePermitTypedData.message.deadline,\n signedNativePermitTypedData.signature,\n transactionRequest.data as Hex\n )\n } else if (permit2Supported) {\n statusManager.updateAction(step, action.type, 'MESSAGE_REQUIRED')\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n const permit2Signature = await signPermit2Message(client, {\n client: updatedClient,\n chain: fromChain,\n tokenAddress: step.action.fromToken.address as Address,\n amount: BigInt(step.action.fromAmount),\n data: transactionRequest.data as Hex,\n })\n transactionRequest.data = encodePermit2Data(\n step.action.fromToken.address as Address,\n BigInt(step.action.fromAmount),\n permit2Signature.message.nonce,\n permit2Signature.message.deadline,\n transactionRequest.data as Hex,\n permit2Signature.signature\n )\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n }\n\n let finalTransactionRequest = transactionRequest\n if (signedNativePermitTypedData || permit2Supported) {\n // Target address should be the Permit2 proxy contract in case of native permit or Permit2\n finalTransactionRequest = {\n ...transactionRequest,\n to: fromChain.permit2Proxy as Address,\n }\n finalTransactionRequest = await estimateTransactionRequest(\n client,\n updatedClient,\n finalTransactionRequest\n )\n }\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the awaits above\n // (strategy, chain switch, permit prompt, gas estimate).\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const txHash = await getAction(\n updatedClient,\n sendTransaction,\n 'sendTransaction'\n )({\n to: finalTransactionRequest.to as Address,\n account: updatedClient.account!,\n data: finalTransactionRequest.data as Hex,\n value: finalTransactionRequest.value,\n gas: finalTransactionRequest.gas,\n gasPrice: finalTransactionRequest.gasPrice,\n maxFeePerGas: finalTransactionRequest.maxFeePerGas,\n maxPriorityFeePerGas: finalTransactionRequest.maxPriorityFeePerGas,\n chain: convertExtendedChain(fromChain),\n } as SendTransactionParameters)\n\n const resolvedTxHash = await resolveTransactionHash(\n client,\n updatedClient,\n txHash,\n fromChain.id\n )\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n // A new transaction: nothing of the previous one may survive, least of\n // all its `txFinal` verdict.\n ...CLEARED_TRANSACTION_FIELDS,\n txHash: resolvedTxHash,\n txLink: getTxLink(fromChain, resolvedTxHash),\n txType: 'standard',\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n context: {\n transactionRequest: finalTransactionRequest,\n },\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,IAAa,qCAAb,cAAwD,sBAAsB;CAC5E,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,QACA,WACA,eACA,aACA,oBACA,sBACA,sBACE;EAEJ,IAAI,CAAC,oBACH,MAAM,IAAI,iBACR,cAAc,uBACd,kEACF;EAGF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAIF,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,8BAA8B,uBAAuB,OAAO;EAKlE,MAAM,mBAAmB,8BACrB,QACA,MAAM,sBAAsB,SAAS,UAAU;EACnD,IAAI,6BACF,mBAAmB,OAAO,uBACxB,KAAK,OAAO,UAAU,SACtB,OAAO,KAAK,OAAO,UAAU,GAC7B,4BAA4B,QAAQ,UACpC,4BAA4B,WAC5B,mBAAmB,IACrB;OACK,IAAI,kBAAkB;GAC3B,cAAc,aAAa,MAAM,OAAO,MAAM,kBAAkB;GAChE,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;GAE5B,MAAM,mBAAmB,MAAM,mBAAmB,QAAQ;IACxD,QAAQ;IACR,OAAO;IACP,cAAc,KAAK,OAAO,UAAU;IACpC,QAAQ,OAAO,KAAK,OAAO,UAAU;IACrC,MAAM,mBAAmB;GAC3B,CAAC;GACD,mBAAmB,OAAO,kBACxB,KAAK,OAAO,UAAU,SACtB,OAAO,KAAK,OAAO,UAAU,GAC7B,iBAAiB,QAAQ,OACzB,iBAAiB,QAAQ,UACzB,mBAAmB,MACnB,iBAAiB,SACnB;GACA,cAAc,aAAa,MAAM,OAAO,MAAM,iBAAiB;GAC/D,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAE9B;EAEA,IAAI,0BAA0B;EAC9B,IAAI,+BAA+B,kBAAkB;GAEnD,0BAA0B;IACxB,GAAG;IACH,IAAI,UAAU;GAChB;GACA,0BAA0B,MAAM,2BAC9B,QACA,eACA,uBACF;EACF;EAKA,wBAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,MAAM,SAAS,MAAM,UACnB,eACA,iBACA,iBACF,CAAC,CAAC;GACA,IAAI,wBAAwB;GAC5B,SAAS,cAAc;GACvB,MAAM,wBAAwB;GAC9B,OAAO,wBAAwB;GAC/B,KAAK,wBAAwB;GAC7B,UAAU,wBAAwB;GAClC,cAAc,wBAAwB;GACtC,sBAAsB,wBAAwB;GAC9C,OAAO,qBAAqB,SAAS;EACvC,CAA8B;EAE9B,MAAM,iBAAiB,MAAM,uBAC3B,QACA,eACA,QACA,UAAU,EACZ;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAGvD,GAAG;GACH,QAAQ;GACR,QAAQ,UAAU,WAAW,cAAc;GAC3C,QAAQ;GACR,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,OAAO;GACL,QAAQ;GACR,SAAS,EACP,oBAAoB,wBACtB;EACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumWaitForTransactionTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EthereumWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumWaitForTransactionTask.ts"],"mappings":";;;qBAkBa,uCAAuC;EAClD,IAAU,SAAS,8BAA8B,QAAQ"}
|
|
@@ -2,11 +2,18 @@ import { getEthereumExecutionStrategy } from "./helpers/getEthereumExecutionStra
|
|
|
2
2
|
import { EthereumBatchedWaitForTransactionTask } from "./EthereumBatchedWaitForTransactionTask.js";
|
|
3
3
|
import { EthereumRelayedWaitForTransactionTask } from "./EthereumRelayedWaitForTransactionTask.js";
|
|
4
4
|
import { EthereumStandardWaitForTransactionTask } from "./EthereumStandardWaitForTransactionTask.js";
|
|
5
|
-
import { BaseStepExecutionTask } from "@lifi/sdk";
|
|
5
|
+
import { BaseStepExecutionTask, hasOpenTransaction } from "@lifi/sdk";
|
|
6
6
|
//#region src/core/tasks/EthereumWaitForTransactionTask.ts
|
|
7
|
+
const TRANSACTION_METHOD_TYPES = [
|
|
8
|
+
"standard",
|
|
9
|
+
"batched",
|
|
10
|
+
"relayed"
|
|
11
|
+
];
|
|
7
12
|
var EthereumWaitForTransactionTask = class extends BaseStepExecutionTask {
|
|
8
13
|
async run(context) {
|
|
9
|
-
const
|
|
14
|
+
const { step, statusManager, isBridgeExecution } = context;
|
|
15
|
+
const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
16
|
+
const executionStrategy = (hasOpenTransaction(action) && action?.txType && TRANSACTION_METHOD_TYPES.includes(action.txType) ? action.txType : void 0) ?? await getEthereumExecutionStrategy(context);
|
|
10
17
|
if (executionStrategy === "batched") return new EthereumBatchedWaitForTransactionTask().run(context);
|
|
11
18
|
if (executionStrategy === "relayed") return new EthereumRelayedWaitForTransactionTask().run(context);
|
|
12
19
|
return new EthereumStandardWaitForTransactionTask().run(context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumWaitForTransactionTask.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"EthereumWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n hasOpenTransaction,\n type TaskResult,\n type TransactionMethodType,\n} from '@lifi/sdk'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { EthereumBatchedWaitForTransactionTask } from './EthereumBatchedWaitForTransactionTask.js'\nimport { EthereumRelayedWaitForTransactionTask } from './EthereumRelayedWaitForTransactionTask.js'\nimport { EthereumStandardWaitForTransactionTask } from './EthereumStandardWaitForTransactionTask.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\n\nconst TRANSACTION_METHOD_TYPES: readonly TransactionMethodType[] = [\n 'standard',\n 'batched',\n 'relayed',\n]\n\nexport class EthereumWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, isBridgeExecution } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n // The lane that sent the open transaction waits for it. The sign task\n // stores that lane in `txType`, and a resume keeps it. The step content\n // cannot always tell it again: a step that prepare sent to the relayer\n // only because it had no `transactionRequest` reads as a standard or a\n // batched step on resume. The guard skips a `txType` left on an action\n // without an open transaction. Routes stored without `txType` derive the\n // lane from the step.\n const storedStrategy =\n hasOpenTransaction(action) &&\n action?.txType &&\n TRANSACTION_METHOD_TYPES.includes(action.txType)\n ? action.txType\n : undefined\n const executionStrategy =\n storedStrategy ?? (await getEthereumExecutionStrategy(context))\n if (executionStrategy === 'batched') {\n return new EthereumBatchedWaitForTransactionTask().run(context)\n }\n if (executionStrategy === 'relayed') {\n return new EthereumRelayedWaitForTransactionTask().run(context)\n }\n return new EthereumStandardWaitForTransactionTask().run(context)\n }\n}\n"],"mappings":";;;;;;AAYA,MAAM,2BAA6D;CACjE;CACA;CACA;AACF;AAEA,IAAa,iCAAb,cAAoD,sBAAsB;CACxE,MAAM,IAAI,SAA2D;EACnE,MAAM,EAAE,MAAM,eAAe,sBAAsB;EAEnD,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAcA,MAAM,qBALJ,mBAAmB,MAAM,KACzB,QAAQ,UACR,yBAAyB,SAAS,OAAO,MAAM,IAC3C,OAAO,SACP,KAAA,MAEe,MAAM,6BAA6B,OAAO;EAC/D,IAAI,sBAAsB,WACxB,OAAO,IAAI,sCAAsC,CAAC,CAAC,IAAI,OAAO;EAEhE,IAAI,sBAAsB,WACxB,OAAO,IAAI,sCAAsC,CAAC,CAAC,IAAI,OAAO;EAEhE,OAAO,IAAI,uCAAuC,CAAC,CAAC,IAAI,OAAO;CACjE;AACF"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { EthereumStepExecutorContext } from "../../../types.js";
|
|
2
2
|
import { TransactionMethodType } from "@lifi/sdk";
|
|
3
3
|
//#region src/core/tasks/helpers/getEthereumExecutionStrategy.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Retry param set by `EthereumPrepareTransactionTask`: the strategy prepare
|
|
6
|
+
* established when the allowance work done for `batched` did not fit it. The
|
|
7
|
+
* replay starts in this strategy.
|
|
8
|
+
*/
|
|
9
|
+
export declare const STRATEGY_AFTER_PREPARE = "strategyAfterPrepare";
|
|
4
10
|
/**
|
|
5
11
|
* Determines the execution strategy: 'relayed', 'batched', or 'standard'.
|
|
6
12
|
* Falls back to 'standard' when EIP-5792 batching is unavailable,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEthereumExecutionStrategy.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/getEthereumExecutionStrategy.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getEthereumExecutionStrategy.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/getEthereumExecutionStrategy.ts"],"mappings":";;;;;;;;qBAUa;;;;;;;;;;;;wBA0BS,6BACpB,SAAS,6BACT,yBACC,QAAQ"}
|
|
@@ -2,6 +2,18 @@ import { isBatchingSupported } from "../../../actions/isBatchingSupported.js";
|
|
|
2
2
|
import { isPermit2AllowanceLane } from "../../../utils/getTypedDataLane.js";
|
|
3
3
|
//#region src/core/tasks/helpers/getEthereumExecutionStrategy.ts
|
|
4
4
|
/**
|
|
5
|
+
* Retry param set by `EthereumPrepareTransactionTask`: the strategy prepare
|
|
6
|
+
* established when the allowance work done for `batched` did not fit it. The
|
|
7
|
+
* replay starts in this strategy.
|
|
8
|
+
*/
|
|
9
|
+
const STRATEGY_AFTER_PREPARE = "strategyAfterPrepare";
|
|
10
|
+
const TRANSACTION_METHOD_TYPES = {
|
|
11
|
+
standard: true,
|
|
12
|
+
relayed: true,
|
|
13
|
+
batched: true
|
|
14
|
+
};
|
|
15
|
+
const isTransactionMethodType = (value) => typeof value === "string" && Object.hasOwn(TRANSACTION_METHOD_TYPES, value);
|
|
16
|
+
/**
|
|
5
17
|
* Determines the execution strategy: 'relayed', 'batched', or 'standard'.
|
|
6
18
|
* Falls back to 'standard' when EIP-5792 batching is unavailable,
|
|
7
19
|
* the wallet rejected the 7702 upgrade, or the tool doesn't support it.
|
|
@@ -15,6 +27,8 @@ import { isPermit2AllowanceLane } from "../../../utils/getTypedDataLane.js";
|
|
|
15
27
|
async function getEthereumExecutionStrategy(context, afterPrepare = false) {
|
|
16
28
|
const { step, checkClient, retryParams, client, fromChain, ethereumClient, executionStrategy: executionStrategyContext } = context;
|
|
17
29
|
if (!afterPrepare && executionStrategyContext) return executionStrategyContext;
|
|
30
|
+
const strategyAfterPrepare = retryParams?.[STRATEGY_AFTER_PREPARE];
|
|
31
|
+
if (!afterPrepare && isTransactionMethodType(strategyAfterPrepare)) return strategyAfterPrepare;
|
|
18
32
|
const atomicityNotReady = !!retryParams?.atomicityNotReady;
|
|
19
33
|
if (step.executionType === "message") return "relayed";
|
|
20
34
|
if (step.typedData?.length && !isPermit2AllowanceLane(step, fromChain)) return "relayed";
|
|
@@ -27,6 +41,6 @@ async function getEthereumExecutionStrategy(context, afterPrepare = false) {
|
|
|
27
41
|
}) ? "batched" : "standard";
|
|
28
42
|
}
|
|
29
43
|
//#endregion
|
|
30
|
-
export { getEthereumExecutionStrategy };
|
|
44
|
+
export { STRATEGY_AFTER_PREPARE, getEthereumExecutionStrategy };
|
|
31
45
|
|
|
32
46
|
//# sourceMappingURL=getEthereumExecutionStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEthereumExecutionStrategy.js","names":[],"sources":["../../../../../src/core/tasks/helpers/getEthereumExecutionStrategy.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport { isBatchingSupported } from '../../../actions/isBatchingSupported.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { isPermit2AllowanceLane } from '../../../utils/getTypedDataLane.js'\n\n/**\n * Determines the execution strategy: 'relayed', 'batched', or 'standard'.\n * Falls back to 'standard' when EIP-5792 batching is unavailable,\n * the wallet rejected the 7702 upgrade, or the tool doesn't support it.\n *\n * `afterPrepare` marks the single call from `EthereumPrepareTransactionTask`.\n * The step has just been re-quoted, so the cached verdict is stale and, for the\n * first time, the absence of a `transactionRequest` is final rather than merely\n * not-yet-known. Both effects come from that one fact, which is why they share\n * a parameter.\n */\nexport async function getEthereumExecutionStrategy(\n context: EthereumStepExecutorContext,\n afterPrepare: boolean = false\n): Promise<TransactionMethodType> {\n const {\n step,\n checkClient,\n retryParams,\n client,\n fromChain,\n ethereumClient,\n executionStrategy: executionStrategyContext,\n } = context\n\n if (!afterPrepare && executionStrategyContext) {\n return executionStrategyContext\n }\n\n const atomicityNotReady = !!retryParams?.atomicityNotReady\n // Declared by the backend. It is the only signal that reaches the allowance\n // tasks, which run before a `transactionRequest` can exist.\n if (step.executionType === 'message') {\n return 'relayed'\n }\n\n // Typed data the user does not sign for its own send: gasless, `Order`,\n // Hyperliquid. A Permit2 allowance is the one shape excluded, because its signer\n // and its sender are the same person.\n if (step.typedData?.length && !isPermit2AllowanceLane(step, fromChain)) {\n return 'relayed'\n }\n\n // After prepare, missing means never: the step carries typed data and the user\n // has nothing to send, so the relayer is the only lane that can execute it.\n // This is a derivation, not a guess — no other strategy can run such a step.\n //\n // Before prepare the same expression is unsound. A Permit2 allowance that will\n // receive its transaction from `/stepTransaction` is indistinguishable from\n // one that never will, and calling it relayed there costs the step its\n // EIP-5792 batching.\n if (afterPrepare && step.typedData?.length && !step.transactionRequest) {\n return 'relayed'\n }\n\n if (atomicityNotReady || step.tool === 'thorswap') {\n return 'standard'\n }\n\n const updatedClient = (await checkClient(step)) ?? ethereumClient\n const batchingSupported = await isBatchingSupported(client, {\n client: updatedClient,\n chainId: fromChain.id,\n })\n return batchingSupported ? 'batched' : 'standard'\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getEthereumExecutionStrategy.js","names":[],"sources":["../../../../../src/core/tasks/helpers/getEthereumExecutionStrategy.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport { isBatchingSupported } from '../../../actions/isBatchingSupported.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { isPermit2AllowanceLane } from '../../../utils/getTypedDataLane.js'\n\n/**\n * Retry param set by `EthereumPrepareTransactionTask`: the strategy prepare\n * established when the allowance work done for `batched` did not fit it. The\n * replay starts in this strategy.\n */\nexport const STRATEGY_AFTER_PREPARE = 'strategyAfterPrepare'\n\n// A `Record` over the union, so a new strategy fails to compile here instead of\n// being ignored by the replay.\nconst TRANSACTION_METHOD_TYPES: Record<TransactionMethodType, true> = {\n standard: true,\n relayed: true,\n batched: true,\n}\n\nconst isTransactionMethodType = (\n value: unknown\n): value is TransactionMethodType =>\n typeof value === 'string' && Object.hasOwn(TRANSACTION_METHOD_TYPES, value)\n\n/**\n * Determines the execution strategy: 'relayed', 'batched', or 'standard'.\n * Falls back to 'standard' when EIP-5792 batching is unavailable,\n * the wallet rejected the 7702 upgrade, or the tool doesn't support it.\n *\n * `afterPrepare` marks the single call from `EthereumPrepareTransactionTask`.\n * The step has just been re-quoted, so the cached verdict is stale and, for the\n * first time, the absence of a `transactionRequest` is final rather than merely\n * not-yet-known. Both effects come from that one fact, which is why they share\n * a parameter.\n */\nexport async function getEthereumExecutionStrategy(\n context: EthereumStepExecutorContext,\n afterPrepare: boolean = false\n): Promise<TransactionMethodType> {\n const {\n step,\n checkClient,\n retryParams,\n client,\n fromChain,\n ethereumClient,\n executionStrategy: executionStrategyContext,\n } = context\n\n if (!afterPrepare && executionStrategyContext) {\n return executionStrategyContext\n }\n\n // A replay starts in the strategy its first prepare established. Prepare\n // restored the step's typed data before the replay, so nothing on the step\n // shows that strategy yet.\n const strategyAfterPrepare = retryParams?.[STRATEGY_AFTER_PREPARE]\n if (!afterPrepare && isTransactionMethodType(strategyAfterPrepare)) {\n return strategyAfterPrepare\n }\n\n const atomicityNotReady = !!retryParams?.atomicityNotReady\n // Declared by the backend. It is the only signal that reaches the allowance\n // tasks, which run before a `transactionRequest` can exist.\n if (step.executionType === 'message') {\n return 'relayed'\n }\n\n // Typed data the user does not sign for its own send: gasless, `Order`,\n // Hyperliquid. A Permit2 allowance is the one shape excluded, because its signer\n // and its sender are the same person.\n if (step.typedData?.length && !isPermit2AllowanceLane(step, fromChain)) {\n return 'relayed'\n }\n\n // After prepare, missing means never: the step carries typed data and the user\n // has nothing to send, so the relayer is the only lane that can execute it.\n // This is a derivation, not a guess — no other strategy can run such a step.\n //\n // Before prepare the same expression is unsound. A Permit2 allowance that will\n // receive its transaction from `/stepTransaction` is indistinguishable from\n // one that never will, and calling it relayed there costs the step its\n // EIP-5792 batching.\n if (afterPrepare && step.typedData?.length && !step.transactionRequest) {\n return 'relayed'\n }\n\n if (atomicityNotReady || step.tool === 'thorswap') {\n return 'standard'\n }\n\n const updatedClient = (await checkClient(step)) ?? ethereumClient\n const batchingSupported = await isBatchingSupported(client, {\n client: updatedClient,\n chainId: fromChain.id,\n })\n return batchingSupported ? 'batched' : 'standard'\n}\n"],"mappings":";;;;;;;;AAUA,MAAa,yBAAyB;AAItC,MAAM,2BAAgE;CACpE,UAAU;CACV,SAAS;CACT,SAAS;AACX;AAEA,MAAM,2BACJ,UAEA,OAAO,UAAU,YAAY,OAAO,OAAO,0BAA0B,KAAK;;;;;;;;;;;;AAa5E,eAAsB,6BACpB,SACA,eAAwB,OACQ;CAChC,MAAM,EACJ,MACA,aACA,aACA,QACA,WACA,gBACA,mBAAmB,6BACjB;CAEJ,IAAI,CAAC,gBAAgB,0BACnB,OAAO;CAMT,MAAM,uBAAuB,cAAc;CAC3C,IAAI,CAAC,gBAAgB,wBAAwB,oBAAoB,GAC/D,OAAO;CAGT,MAAM,oBAAoB,CAAC,CAAC,aAAa;CAGzC,IAAI,KAAK,kBAAkB,WACzB,OAAO;CAMT,IAAI,KAAK,WAAW,UAAU,CAAC,uBAAuB,MAAM,SAAS,GACnE,OAAO;CAWT,IAAI,gBAAgB,KAAK,WAAW,UAAU,CAAC,KAAK,oBAClD,OAAO;CAGT,IAAI,qBAAqB,KAAK,SAAS,YACrC,OAAO;CAGT,MAAM,gBAAiB,MAAM,YAAY,IAAI,KAAM;CAKnD,OAAO,MAJyB,oBAAoB,QAAQ;EAC1D,QAAQ;EACR,SAAS,UAAU;CACrB,CAAC,IAC0B,YAAY;AACzC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EthereumStepExecutorContext } from "../../../types.js";
|
|
2
|
+
import { TransactionMethodType } from "@lifi/sdk";
|
|
3
|
+
//#region src/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether the allowance work done in `preparedFor` does not fit `needed`, the
|
|
6
|
+
* strategy prepare established. Two things can break:
|
|
7
|
+
* - Calls queued for a batch are sent only by the batched task.
|
|
8
|
+
* - The spender: `resolvePermit2Support` never picks Permit2 for `batched`, but
|
|
9
|
+
* can for the other strategies. An allowance that is sufficient for the wrong
|
|
10
|
+
* spender queues nothing, so the calls alone do not show it.
|
|
11
|
+
*
|
|
12
|
+
* The spender recorded by `EthereumCheckAllowanceTask` is compared, because
|
|
13
|
+
* prepare has already replaced the step with the re-quote.
|
|
14
|
+
*/
|
|
15
|
+
export declare const isAllowancePreparedForAnotherStrategy: (context: EthereumStepExecutorContext, preparedFor: TransactionMethodType, needed: TransactionMethodType) => Promise<boolean>;
|
|
16
|
+
//#endregion
|
|
17
|
+
//# sourceMappingURL=isAllowancePreparedForAnotherStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAllowancePreparedForAnotherStrategy.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.ts"],"mappings":";;;;;;;;;;;;;;qBAea,wCACX,SAAS,6BACT,aAAa,uBACb,QAAQ,0BACP"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { resolveAllowanceSpender } from "./resolveAllowanceSpender.js";
|
|
2
|
+
//#region src/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Whether the allowance work done in `preparedFor` does not fit `needed`, the
|
|
5
|
+
* strategy prepare established. Two things can break:
|
|
6
|
+
* - Calls queued for a batch are sent only by the batched task.
|
|
7
|
+
* - The spender: `resolvePermit2Support` never picks Permit2 for `batched`, but
|
|
8
|
+
* can for the other strategies. An allowance that is sufficient for the wrong
|
|
9
|
+
* spender queues nothing, so the calls alone do not show it.
|
|
10
|
+
*
|
|
11
|
+
* The spender recorded by `EthereumCheckAllowanceTask` is compared, because
|
|
12
|
+
* prepare has already replaced the step with the re-quote.
|
|
13
|
+
*/
|
|
14
|
+
const isAllowancePreparedForAnotherStrategy = async (context, preparedFor, needed) => {
|
|
15
|
+
if (preparedFor === needed) return false;
|
|
16
|
+
if (preparedFor === "batched" && context.calls.length) return true;
|
|
17
|
+
if (context.hasMatchingPermit) return false;
|
|
18
|
+
const { allowanceSpender } = context;
|
|
19
|
+
if (!allowanceSpender) return false;
|
|
20
|
+
const { spenderAddress } = await resolveAllowanceSpender(context, needed);
|
|
21
|
+
return allowanceSpender.toLowerCase() !== spenderAddress?.toLowerCase();
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { isAllowancePreparedForAnotherStrategy };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=isAllowancePreparedForAnotherStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAllowancePreparedForAnotherStrategy.js","names":[],"sources":["../../../../../src/core/tasks/helpers/isAllowancePreparedForAnotherStrategy.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { resolveAllowanceSpender } from './resolveAllowanceSpender.js'\n\n/**\n * Whether the allowance work done in `preparedFor` does not fit `needed`, the\n * strategy prepare established. Two things can break:\n * - Calls queued for a batch are sent only by the batched task.\n * - The spender: `resolvePermit2Support` never picks Permit2 for `batched`, but\n * can for the other strategies. An allowance that is sufficient for the wrong\n * spender queues nothing, so the calls alone do not show it.\n *\n * The spender recorded by `EthereumCheckAllowanceTask` is compared, because\n * prepare has already replaced the step with the re-quote.\n */\nexport const isAllowancePreparedForAnotherStrategy = async (\n context: EthereumStepExecutorContext,\n preparedFor: TransactionMethodType,\n needed: TransactionMethodType\n): Promise<boolean> => {\n if (preparedFor === needed) {\n return false\n }\n if (preparedFor === 'batched' && context.calls.length) {\n return true\n }\n // A signed native permit covers the allowance, and the re-quote carries it.\n if (context.hasMatchingPermit) {\n return false\n }\n const { allowanceSpender } = context\n if (!allowanceSpender) {\n return false\n }\n const { spenderAddress } = await resolveAllowanceSpender(context, needed)\n return allowanceSpender.toLowerCase() !== spenderAddress?.toLowerCase()\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAa,wCAAwC,OACnD,SACA,aACA,WACqB;CACrB,IAAI,gBAAgB,QAClB,OAAO;CAET,IAAI,gBAAgB,aAAa,QAAQ,MAAM,QAC7C,OAAO;CAGT,IAAI,QAAQ,mBACV,OAAO;CAET,MAAM,EAAE,qBAAqB;CAC7B,IAAI,CAAC,kBACH,OAAO;CAET,MAAM,EAAE,mBAAmB,MAAM,wBAAwB,SAAS,MAAM;CACxE,OAAO,iBAAiB,YAAY,MAAM,gBAAgB,YAAY;AACxE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EthereumStepExecutorContext } from "../../../types.js";
|
|
2
|
+
import { TransactionMethodType } from "@lifi/sdk";
|
|
3
|
+
import { Address } from "viem";
|
|
4
|
+
//#region src/core/tasks/helpers/resolveAllowanceSpender.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The spender the allowance tasks check and approve in `strategy`: canonical
|
|
7
|
+
* Permit2 when the step takes the Permit2 flow there, `approvalAddress`
|
|
8
|
+
* otherwise. Every allowance task and the prepare-time check use this one
|
|
9
|
+
* derivation, so they cannot disagree.
|
|
10
|
+
*/
|
|
11
|
+
export declare const resolveAllowanceSpender: (context: EthereumStepExecutorContext, strategy: TransactionMethodType) => Promise<{
|
|
12
|
+
permit2Supported: boolean;
|
|
13
|
+
spenderAddress: Address;
|
|
14
|
+
}>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//# sourceMappingURL=resolveAllowanceSpender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveAllowanceSpender.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/resolveAllowanceSpender.ts"],"mappings":";;;;;;;;;;qBAWa,0BACX,SAAS,6BACT,UAAU,0BACT;EAAU;EAA2B,gBAAgB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { resolvePermit2Support } from "./resolvePermit2Support.js";
|
|
2
|
+
//#region src/core/tasks/helpers/resolveAllowanceSpender.ts
|
|
3
|
+
/**
|
|
4
|
+
* The spender the allowance tasks check and approve in `strategy`: canonical
|
|
5
|
+
* Permit2 when the step takes the Permit2 flow there, `approvalAddress`
|
|
6
|
+
* otherwise. Every allowance task and the prepare-time check use this one
|
|
7
|
+
* derivation, so they cannot disagree.
|
|
8
|
+
*/
|
|
9
|
+
const resolveAllowanceSpender = async (context, strategy) => {
|
|
10
|
+
const permit2Supported = await resolvePermit2Support(context, strategy);
|
|
11
|
+
const { fromChain, step } = context;
|
|
12
|
+
return {
|
|
13
|
+
permit2Supported,
|
|
14
|
+
spenderAddress: permit2Supported ? fromChain.permit2 : step.estimate.approvalAddress
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { resolveAllowanceSpender };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=resolveAllowanceSpender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveAllowanceSpender.js","names":[],"sources":["../../../../../src/core/tasks/helpers/resolveAllowanceSpender.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { resolvePermit2Support } from './resolvePermit2Support.js'\n\n/**\n * The spender the allowance tasks check and approve in `strategy`: canonical\n * Permit2 when the step takes the Permit2 flow there, `approvalAddress`\n * otherwise. Every allowance task and the prepare-time check use this one\n * derivation, so they cannot disagree.\n */\nexport const resolveAllowanceSpender = async (\n context: EthereumStepExecutorContext,\n strategy: TransactionMethodType\n): Promise<{ permit2Supported: boolean; spenderAddress: Address }> => {\n const permit2Supported = await resolvePermit2Support(context, strategy)\n const { fromChain, step } = context\n return {\n permit2Supported,\n spenderAddress: (permit2Supported\n ? fromChain.permit2\n : step.estimate.approvalAddress) as Address,\n }\n}\n"],"mappings":";;;;;;;;AAWA,MAAa,0BAA0B,OACrC,SACA,aACoE;CACpE,MAAM,mBAAmB,MAAM,sBAAsB,SAAS,QAAQ;CACtE,MAAM,EAAE,WAAW,SAAS;CAC5B,OAAO;EACL;EACA,gBAAiB,mBACb,UAAU,UACV,KAAK,SAAS;CACpB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldCheckForAllowance.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/shouldCheckForAllowance.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"shouldCheckForAllowance.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/shouldCheckForAllowance.ts"],"mappings":";;qBAMa,0BACX,MAAM,kBACN,4BACA,4BACA,eAAe"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { hasOpenTransaction } from "@lifi/sdk";
|
|
1
2
|
//#region src/core/tasks/helpers/shouldCheckForAllowance.ts
|
|
2
3
|
const shouldCheckForAllowance = (step, isBridgeExecution, isFromNativeToken, statusManager) => {
|
|
3
4
|
const exchangeActionType = isBridgeExecution ? "CROSS_CHAIN" : "SWAP";
|
|
4
5
|
const swapOrBridgeAction = statusManager.findAction(step, exchangeActionType);
|
|
5
|
-
return !swapOrBridgeAction
|
|
6
|
+
return !hasOpenTransaction(swapOrBridgeAction) && !isFromNativeToken && !!step.estimate.approvalAddress && !step.estimate.skipApproval;
|
|
6
7
|
};
|
|
7
8
|
//#endregion
|
|
8
9
|
export { shouldCheckForAllowance };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldCheckForAllowance.js","names":[],"sources":["../../../../../src/core/tasks/helpers/shouldCheckForAllowance.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"shouldCheckForAllowance.js","names":[],"sources":["../../../../../src/core/tasks/helpers/shouldCheckForAllowance.ts"],"sourcesContent":["import {\n hasOpenTransaction,\n type LiFiStepExtended,\n type StatusManager,\n} from '@lifi/sdk'\n\nexport const shouldCheckForAllowance = (\n step: LiFiStepExtended,\n isBridgeExecution: boolean,\n isFromNativeToken: boolean,\n statusManager: StatusManager\n): boolean => {\n const exchangeActionType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n\n const swapOrBridgeAction = statusManager.findAction(step, exchangeActionType)\n\n return (\n // No swap/bridge transaction (hash, batch/relay id or stored bytes) that may\n // still land. A FAILED action with a final outcome does not count, so the\n // allowance is checked again before the new transaction.\n !hasOpenTransaction(swapOrBridgeAction) &&\n // Token is not native (address is not zero)\n !isFromNativeToken &&\n // Approval address is required for allowance checks, but may be null in special cases (e.g. direct transfers)\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval\n )\n}\n"],"mappings":";;AAMA,MAAa,2BACX,MACA,mBACA,mBACA,kBACY;CACZ,MAAM,qBAAqB,oBAAoB,gBAAgB;CAE/D,MAAM,qBAAqB,cAAc,WAAW,MAAM,kBAAkB;CAE5E,OAIE,CAAC,mBAAmB,kBAAkB,KAEtC,CAAC,qBAED,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS;AAEnB"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { EthereumStepExecutorContext } from "../../../types.js";
|
|
2
2
|
import { SignedTypedData, TypedData } from "@lifi/sdk";
|
|
3
3
|
//#region src/core/tasks/helpers/signHyperliquidTypedData.d.ts
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* `beforeSignature` runs right before each signature, the agent's included,
|
|
6
|
+
* after every await before it; it throws to stop the signing.
|
|
7
|
+
*/
|
|
8
|
+
export declare const signHyperliquidTypedData: (context: EthereumStepExecutorContext, allowanceTypedData: TypedData[], beforeSignature?: () => void) => Promise<SignedTypedData[] | undefined>;
|
|
5
9
|
//#endregion
|
|
6
10
|
//# sourceMappingURL=signHyperliquidTypedData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signHyperliquidTypedData.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signHyperliquidTypedData.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"signHyperliquidTypedData.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signHyperliquidTypedData.ts"],"mappings":";;;;;;;qBAiBa,2BACX,SAAS,6BACT,oBAAoB,aACpB,iCACC,QAAQ"}
|
|
@@ -5,7 +5,11 @@ import { getOrCreateAgentWallet } from "../../../hyperliquid/agentWallet.js";
|
|
|
5
5
|
import { signTypedData } from "viem/actions";
|
|
6
6
|
import { getAction } from "viem/utils";
|
|
7
7
|
//#region src/core/tasks/helpers/signHyperliquidTypedData.ts
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* `beforeSignature` runs right before each signature, the agent's included,
|
|
10
|
+
* after every await before it; it throws to stop the signing.
|
|
11
|
+
*/
|
|
12
|
+
const signHyperliquidTypedData = async (context, allowanceTypedData, beforeSignature) => {
|
|
9
13
|
const { step, fromChain, client, allowUserInteraction, checkClient, ethereumClient, getStorage } = context;
|
|
10
14
|
if (!allowUserInteraction) return;
|
|
11
15
|
const signedResults = [];
|
|
@@ -22,6 +26,7 @@ const signHyperliquidTypedData = async (context, allowanceTypedData) => {
|
|
|
22
26
|
};
|
|
23
27
|
const updatedClient = await checkClient(step, getDomainChainId(typedData.domain) || fromChain.id);
|
|
24
28
|
if (!updatedClient) return;
|
|
29
|
+
beforeSignature?.();
|
|
25
30
|
const signature = await getAction(updatedClient, signTypedData, "signTypedData")({
|
|
26
31
|
account: updatedClient.account,
|
|
27
32
|
primaryType: typedData.primaryType,
|
|
@@ -38,6 +43,7 @@ const signHyperliquidTypedData = async (context, allowanceTypedData) => {
|
|
|
38
43
|
} else if (isApproveBuilderFeeMessage(typedData)) {
|
|
39
44
|
const updatedClient = await checkClient(step, getDomainChainId(typedData.domain) || fromChain.id);
|
|
40
45
|
if (!updatedClient) return;
|
|
46
|
+
beforeSignature?.();
|
|
41
47
|
const signature = await getAction(updatedClient, signTypedData, "signTypedData")({
|
|
42
48
|
account: updatedClient.account,
|
|
43
49
|
primaryType: typedData.primaryType,
|
|
@@ -51,6 +57,7 @@ const signHyperliquidTypedData = async (context, allowanceTypedData) => {
|
|
|
51
57
|
signature
|
|
52
58
|
});
|
|
53
59
|
} else if (isHyperliquidOrderMessage(typedData)) {
|
|
60
|
+
beforeSignature?.();
|
|
54
61
|
const signature = await agentAccount.signTypedData({
|
|
55
62
|
domain: typedData.domain,
|
|
56
63
|
types: typedData.types,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signHyperliquidTypedData.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signHyperliquidTypedData.ts"],"sourcesContent":["import type { SignedTypedData, TypedData } from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getOrCreateAgentWallet } from '../../../hyperliquid/agentWallet.js'\nimport {\n isApproveAgentMessage,\n isApproveBuilderFeeMessage,\n isHyperliquidOrderMessage,\n} from '../../../hyperliquid/isHyperliquidAgentStep.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport const signHyperliquidTypedData = async (\n context: EthereumStepExecutorContext,\n allowanceTypedData: TypedData[]\n): Promise<SignedTypedData[] | undefined> => {\n const {\n step,\n fromChain,\n client,\n allowUserInteraction,\n checkClient,\n ethereumClient,\n getStorage,\n } = context\n\n if (!allowUserInteraction) {\n return\n }\n\n const signedResults: SignedTypedData[] = []\n const ownerAddress = ethereumClient.account!.address\n const storage = getStorage(client)\n\n const approveMessage = allowanceTypedData.find(isApproveAgentMessage)\n const existingAgentAddress = approveMessage?.message.agentAddress as\n | string\n | undefined\n\n const {\n account: agentAccount,\n needsApproval,\n expiresAt,\n } = await getOrCreateAgentWallet(storage, ownerAddress, existingAgentAddress)\n\n for (const typedData of allowanceTypedData) {\n if (isApproveAgentMessage(typedData)) {\n if (!needsApproval) {\n continue\n }\n\n const message = {\n ...typedData.message,\n agentAddress: agentAccount.address.toLowerCase(),\n agentName: `${typedData.message.agentName} valid_until ${expiresAt}`,\n }\n const typedDataChainId =\n getDomainChainId(typedData.domain) || fromChain.id\n\n const updatedClient = await checkClient(step, typedDataChainId)\n if (!updatedClient) {\n return\n }\n\n const signature = await getAction(\n updatedClient,\n signTypedData,\n 'signTypedData'\n )({\n account: updatedClient.account!,\n primaryType: typedData.primaryType,\n domain: typedData.domain,\n types: typedData.types,\n message,\n })\n assertValidSignature(signature)\n signedResults.push({ ...typedData, message, signature })\n } else if (isApproveBuilderFeeMessage(typedData)) {\n const typedDataChainId =\n getDomainChainId(typedData.domain) || fromChain.id\n\n const updatedClient = await checkClient(step, typedDataChainId)\n if (!updatedClient) {\n return\n }\n\n const signature = await getAction(\n updatedClient,\n signTypedData,\n 'signTypedData'\n )({\n account: updatedClient.account!,\n primaryType: typedData.primaryType,\n domain: typedData.domain,\n types: typedData.types,\n message: typedData.message,\n })\n assertValidSignature(signature)\n signedResults.push({ ...typedData, signature })\n } else if (isHyperliquidOrderMessage(typedData)) {\n const signature = await agentAccount.signTypedData({\n domain: typedData.domain,\n types: typedData.types,\n primaryType: typedData.primaryType,\n message: typedData.message,\n })\n signedResults.push({ ...typedData, signature })\n }\n }\n\n return signedResults\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"signHyperliquidTypedData.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signHyperliquidTypedData.ts"],"sourcesContent":["import type { SignedTypedData, TypedData } from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getOrCreateAgentWallet } from '../../../hyperliquid/agentWallet.js'\nimport {\n isApproveAgentMessage,\n isApproveBuilderFeeMessage,\n isHyperliquidOrderMessage,\n} from '../../../hyperliquid/isHyperliquidAgentStep.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\n/**\n * `beforeSignature` runs right before each signature, the agent's included,\n * after every await before it; it throws to stop the signing.\n */\nexport const signHyperliquidTypedData = async (\n context: EthereumStepExecutorContext,\n allowanceTypedData: TypedData[],\n beforeSignature?: () => void\n): Promise<SignedTypedData[] | undefined> => {\n const {\n step,\n fromChain,\n client,\n allowUserInteraction,\n checkClient,\n ethereumClient,\n getStorage,\n } = context\n\n if (!allowUserInteraction) {\n return\n }\n\n const signedResults: SignedTypedData[] = []\n const ownerAddress = ethereumClient.account!.address\n const storage = getStorage(client)\n\n const approveMessage = allowanceTypedData.find(isApproveAgentMessage)\n const existingAgentAddress = approveMessage?.message.agentAddress as\n | string\n | undefined\n\n const {\n account: agentAccount,\n needsApproval,\n expiresAt,\n } = await getOrCreateAgentWallet(storage, ownerAddress, existingAgentAddress)\n\n for (const typedData of allowanceTypedData) {\n if (isApproveAgentMessage(typedData)) {\n if (!needsApproval) {\n continue\n }\n\n const message = {\n ...typedData.message,\n agentAddress: agentAccount.address.toLowerCase(),\n agentName: `${typedData.message.agentName} valid_until ${expiresAt}`,\n }\n const typedDataChainId =\n getDomainChainId(typedData.domain) || fromChain.id\n\n const updatedClient = await checkClient(step, typedDataChainId)\n if (!updatedClient) {\n return\n }\n\n beforeSignature?.()\n const signature = await getAction(\n updatedClient,\n signTypedData,\n 'signTypedData'\n )({\n account: updatedClient.account!,\n primaryType: typedData.primaryType,\n domain: typedData.domain,\n types: typedData.types,\n message,\n })\n assertValidSignature(signature)\n signedResults.push({ ...typedData, message, signature })\n } else if (isApproveBuilderFeeMessage(typedData)) {\n const typedDataChainId =\n getDomainChainId(typedData.domain) || fromChain.id\n\n const updatedClient = await checkClient(step, typedDataChainId)\n if (!updatedClient) {\n return\n }\n\n beforeSignature?.()\n const signature = await getAction(\n updatedClient,\n signTypedData,\n 'signTypedData'\n )({\n account: updatedClient.account!,\n primaryType: typedData.primaryType,\n domain: typedData.domain,\n types: typedData.types,\n message: typedData.message,\n })\n assertValidSignature(signature)\n signedResults.push({ ...typedData, signature })\n } else if (isHyperliquidOrderMessage(typedData)) {\n beforeSignature?.()\n const signature = await agentAccount.signTypedData({\n domain: typedData.domain,\n types: typedData.types,\n primaryType: typedData.primaryType,\n message: typedData.message,\n })\n signedResults.push({ ...typedData, signature })\n }\n }\n\n return signedResults\n}\n"],"mappings":";;;;;;;;;;;AAiBA,MAAa,2BAA2B,OACtC,SACA,oBACA,oBAC2C;CAC3C,MAAM,EACJ,MACA,WACA,QACA,sBACA,aACA,gBACA,eACE;CAEJ,IAAI,CAAC,sBACH;CAGF,MAAM,gBAAmC,CAAC;CAC1C,MAAM,eAAe,eAAe,QAAS;CAC7C,MAAM,UAAU,WAAW,MAAM;CAGjC,MAAM,uBADiB,mBAAmB,KAAK,qBACL,CAAC,EAAE,QAAQ;CAIrD,MAAM,EACJ,SAAS,cACT,eACA,cACE,MAAM,uBAAuB,SAAS,cAAc,oBAAoB;CAE5E,KAAK,MAAM,aAAa,oBACtB,IAAI,sBAAsB,SAAS,GAAG;EACpC,IAAI,CAAC,eACH;EAGF,MAAM,UAAU;GACd,GAAG,UAAU;GACb,cAAc,aAAa,QAAQ,YAAY;GAC/C,WAAW,GAAG,UAAU,QAAQ,UAAU,eAAe;EAC3D;EAIA,MAAM,gBAAgB,MAAM,YAAY,MAFtC,iBAAiB,UAAU,MAAM,KAAK,UAAU,EAEY;EAC9D,IAAI,CAAC,eACH;EAGF,kBAAkB;EAClB,MAAM,YAAY,MAAM,UACtB,eACA,eACA,eACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB,aAAa,UAAU;GACvB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB;EACF,CAAC;EACD,qBAAqB,SAAS;EAC9B,cAAc,KAAK;GAAE,GAAG;GAAW;GAAS;EAAU,CAAC;CACzD,OAAO,IAAI,2BAA2B,SAAS,GAAG;EAIhD,MAAM,gBAAgB,MAAM,YAAY,MAFtC,iBAAiB,UAAU,MAAM,KAAK,UAAU,EAEY;EAC9D,IAAI,CAAC,eACH;EAGF,kBAAkB;EAClB,MAAM,YAAY,MAAM,UACtB,eACA,eACA,eACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB,aAAa,UAAU;GACvB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,SAAS,UAAU;EACrB,CAAC;EACD,qBAAqB,SAAS;EAC9B,cAAc,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAChD,OAAO,IAAI,0BAA0B,SAAS,GAAG;EAC/C,kBAAkB;EAClB,MAAM,YAAY,MAAM,aAAa,cAAc;GACjD,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,aAAa,UAAU;GACvB,SAAS,UAAU;EACrB,CAAC;EACD,cAAc,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAChD;CAGF,OAAO;AACT"}
|