@lifi/sdk-provider-ethereum 4.2.5 → 4.2.7
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 +21 -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.js +7 -2
- 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 +5 -4
- package/dist/cjs/core/EthereumStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js +2 -0
- package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.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 +2 -1
- 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.js +7 -2
- 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 +6 -5
- 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 +3 -1
- package/dist/esm/core/tasks/EthereumBatchedSignAndExecuteTask.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 +2 -1
- 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 +25 -3
- 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 +23 -9
- package/src/core/tasks/EthereumBatchedSignAndExecuteTask.ts +10 -0
- 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 +8 -4
- package/src/types.ts +6 -0
- package/src/version.ts +1 -1
|
@@ -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"}
|
|
@@ -7,7 +7,11 @@ export type SignTypedDataEntriesResult = {
|
|
|
7
7
|
status: "COMPLETED";
|
|
8
8
|
signedTypedData: SignedTypedData[];
|
|
9
9
|
};
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Signs the entries in order, switching chains per entry, and appends the
|
|
12
|
+
* signatures. `beforeSignature` runs right before each wallet call, after the
|
|
13
|
+
* chain switch; it throws to stop the signing.
|
|
14
|
+
*/
|
|
15
|
+
export declare function signTypedDataEntries(context: EthereumStepExecutorContext, entries: TypedData[], actionType: ExecutionActionType, actionStatus?: ExecutionActionStatus, beforeSignature?: () => void): Promise<SignTypedDataEntriesResult>;
|
|
12
16
|
//#endregion
|
|
13
17
|
//# sourceMappingURL=signTypedDataEntries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signTypedDataEntries.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"mappings":";;;YAYY;EACN;;EACA;EAAqB,iBAAiB
|
|
1
|
+
{"version":3,"file":"signTypedDataEntries.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"mappings":";;;YAYY;EACN;;EACA;EAAqB,iBAAiB;;;;;;;wBAOtB,qBACpB,SAAS,6BACT,SAAS,aACT,YAAY,qBACZ,eAAc,uBACd,+BACC,QAAQ"}
|
|
@@ -3,8 +3,12 @@ import { assertValidSignature } from "../../../utils/isValidSignature.js";
|
|
|
3
3
|
import { signTypedData } from "viem/actions";
|
|
4
4
|
import { getAction } from "viem/utils";
|
|
5
5
|
//#region src/core/tasks/helpers/signTypedDataEntries.ts
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Signs the entries in order, switching chains per entry, and appends the
|
|
8
|
+
* signatures. `beforeSignature` runs right before each wallet call, after the
|
|
9
|
+
* chain switch; it throws to stop the signing.
|
|
10
|
+
*/
|
|
11
|
+
async function signTypedDataEntries(context, entries, actionType, actionStatus = "ACTION_REQUIRED", beforeSignature) {
|
|
8
12
|
const { step, statusManager, allowUserInteraction, checkClient, signedTypedData: currentSignedTypedData } = context;
|
|
9
13
|
const signedTypedData = [...currentSignedTypedData];
|
|
10
14
|
if (entries.length) statusManager.updateAction(step, actionType, actionStatus);
|
|
@@ -12,6 +16,7 @@ async function signTypedDataEntries(context, entries, actionType, actionStatus =
|
|
|
12
16
|
if (!allowUserInteraction) return { status: "PAUSED" };
|
|
13
17
|
const client = await checkClient(step, getDomainChainId(typedData.domain) || step.action.fromChainId);
|
|
14
18
|
if (!client) return { status: "PAUSED" };
|
|
19
|
+
beforeSignature?.();
|
|
15
20
|
const signature = await getAction(client, signTypedData, "signTypedData")({
|
|
16
21
|
account: client.account,
|
|
17
22
|
domain: typedData.domain,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signTypedDataEntries.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"sourcesContent":["import type {\n ExecutionActionStatus,\n ExecutionActionType,\n SignedTypedData,\n TypedData,\n} from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport type SignTypedDataEntriesResult =\n | { status: 'PAUSED' }\n | { status: 'COMPLETED'; signedTypedData: SignedTypedData[] }\n\n
|
|
1
|
+
{"version":3,"file":"signTypedDataEntries.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"sourcesContent":["import type {\n ExecutionActionStatus,\n ExecutionActionType,\n SignedTypedData,\n TypedData,\n} from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport type SignTypedDataEntriesResult =\n | { status: 'PAUSED' }\n | { status: 'COMPLETED'; signedTypedData: SignedTypedData[] }\n\n/**\n * Signs the entries in order, switching chains per entry, and appends the\n * signatures. `beforeSignature` runs right before each wallet call, after the\n * chain switch; it throws to stop the signing.\n */\nexport async function signTypedDataEntries(\n context: EthereumStepExecutorContext,\n entries: TypedData[],\n actionType: ExecutionActionType,\n actionStatus: ExecutionActionStatus = 'ACTION_REQUIRED',\n beforeSignature?: () => void\n): Promise<SignTypedDataEntriesResult> {\n const {\n step,\n statusManager,\n allowUserInteraction,\n checkClient,\n signedTypedData: currentSignedTypedData,\n } = context\n\n const signedTypedData = [...currentSignedTypedData]\n\n // Announced once for the round, not once per entry. Relay-from-Hyperliquid\n // carries two messages, and main told the consumer `MESSAGE_REQUIRED` once.\n if (entries.length) {\n statusManager.updateAction(step, actionType, actionStatus)\n }\n\n for (const typedData of entries) {\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n const typedDataChainId =\n getDomainChainId(typedData.domain) || step.action.fromChainId\n\n const client = await checkClient(step, typedDataChainId)\n if (!client) {\n return { status: 'PAUSED' }\n }\n\n beforeSignature?.()\n const signature = await getAction(\n client,\n signTypedData,\n 'signTypedData'\n )({\n account: client.account!,\n domain: typedData.domain,\n types: typedData.types,\n primaryType: typedData.primaryType,\n message: typedData.message,\n })\n assertValidSignature(signature)\n\n signedTypedData.push({ ...typedData, signature })\n }\n\n return { status: 'COMPLETED', signedTypedData }\n}\n"],"mappings":";;;;;;;;;;AAqBA,eAAsB,qBACpB,SACA,SACA,YACA,eAAsC,mBACtC,iBACqC;CACrC,MAAM,EACJ,MACA,eACA,sBACA,aACA,iBAAiB,2BACf;CAEJ,MAAM,kBAAkB,CAAC,GAAG,sBAAsB;CAIlD,IAAI,QAAQ,QACV,cAAc,aAAa,MAAM,YAAY,YAAY;CAG3D,KAAK,MAAM,aAAa,SAAS;EAC/B,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAM5B,MAAM,SAAS,MAAM,YAAY,MAF/B,iBAAiB,UAAU,MAAM,KAAK,KAAK,OAAO,WAEG;EACvD,IAAI,CAAC,QACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,kBAAkB;EAClB,MAAM,YAAY,MAAM,UACtB,QACA,eACA,eACF,CAAC,CAAC;GACA,SAAS,OAAO;GAChB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,aAAa,UAAU;GACvB,SAAS,UAAU;EACrB,CAAC;EACD,qBAAqB,SAAS;EAE9B,gBAAgB,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAClD;CAEA,OAAO;EAAE,QAAQ;EAAa;CAAgB;AAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseEthereumErrors.d.ts","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"mappings":";;qBAea,sBACX,GAAG,OACH,OAAO,UACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;
|
|
1
|
+
{"version":3,"file":"parseEthereumErrors.d.ts","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"mappings":";;qBAea,sBACX,GAAG,OACH,OAAO,UACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;qBA8GT,0CAA2C"}
|
|
@@ -2,7 +2,8 @@ import { BaseError, ErrorMessage, ExecuteStepRetryError, LiFiErrorCode, SDKError
|
|
|
2
2
|
import { AtomicReadyWalletRejectedUpgradeError } from "viem";
|
|
3
3
|
//#region src/errors/parseEthereumErrors.ts
|
|
4
4
|
const parseEthereumErrors = async (e, step, action, retryParams) => {
|
|
5
|
-
if (
|
|
5
|
+
if (e instanceof ExecuteStepRetryError) return e;
|
|
6
|
+
if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) return new ExecuteStepRetryError("Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady", { atomicityNotReady: true }, e);
|
|
6
7
|
if (e instanceof SDKError) {
|
|
7
8
|
e.step = e.step ?? step;
|
|
8
9
|
e.action = e.action ?? action;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseEthereumErrors.js","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n fetchTxErrorDetails,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\nimport { AtomicReadyWalletRejectedUpgradeError } from 'viem'\n\nexport const parseEthereumErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n): Promise<SDKError | ExecuteStepRetryError> => {\n if (\n isAtomicReadyWalletRejectedUpgradeError(e)
|
|
1
|
+
{"version":3,"file":"parseEthereumErrors.js","names":[],"sources":["../../../src/errors/parseEthereumErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n fetchTxErrorDetails,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\nimport { AtomicReadyWalletRejectedUpgradeError } from 'viem'\n\nexport const parseEthereumErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n): Promise<SDKError | ExecuteStepRetryError> => {\n // A task raised it to request a replay; it is not an error to classify.\n if (e instanceof ExecuteStepRetryError) {\n return e\n }\n\n // `executeRoute` replays a step only once, so only the first attempt asks for\n // this retry.\n if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) {\n return new ExecuteStepRetryError(\n 'Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady',\n { atomicityNotReady: true },\n e\n )\n }\n\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = await handleSpecificErrors(e, step, action)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = async (\n e: any,\n step?: LiFiStep,\n action?: ExecutionAction\n) => {\n if (\n e.name === 'UserRejectedRequestError' ||\n e.cause?.name === 'UserRejectedRequestError' ||\n /**\n * This error is specific to MetaMask and thrown when the user rejects the signature of the native token transfer, at that point, the bundle id is unknown.\n * @see https://github.com/MetaMask/metamask-extension/blob/main/app/scripts/lib/transaction/eip5792.ts#L141-L146\n */\n e.name === 'UnknownBundleIdError'\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * Safe Wallet via WalletConnect returns -32000 code when user rejects the signature\n * {\n * code: -32000,\n * message: 'User rejected transaction',\n * }\n */\n if (\n e.cause?.code === -32000 ||\n // Safe doesn't return proper code, but the error details includes 'rejected'\n (e.name === 'TransactionExecutionError' &&\n e.cause?.details?.includes('rejected'))\n ) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n /**\n * Some wallets reject transactions sometimes with this code because of internal and JSON-RPC errors, e.g.:\n * {\n * \"code\": -32603,\n * \"message\": \"Pop up window failed to open\",\n * \"docUrl\": \"https://docs.cloud.coinbase.com/wallet-sdk/docs/errors\"\n * }\n */\n if (e.cause?.code === -32603) {\n return new TransactionError(LiFiErrorCode.TransactionRejected, e.message, e)\n }\n\n /**\n * This error is specific to Smart Accounts and thrown when the user doesn't have enough gas to pay for the transaction.\n */\n if (\n e.name === 'InsufficientPrefundError' ||\n e.cause?.name === 'InsufficientPrefundError' ||\n e.cause?.cause?.name === 'InsufficientPrefundError'\n ) {\n return new TransactionError(LiFiErrorCode.InsufficientGas, e.message, e)\n }\n\n if (\n step &&\n action?.txHash &&\n e.code === LiFiErrorCode.TransactionFailed &&\n e.message === ErrorMessage.TransactionReverted\n ) {\n const response = await fetchTxErrorDetails(\n action.txHash,\n step.action.fromChainId\n )\n\n const errorMessage = (response as Record<string, string>)?.error_message\n\n if (errorMessage?.toLowerCase().includes('out of gas')) {\n return new TransactionError(\n LiFiErrorCode.GasLimitError,\n ErrorMessage.GasLimitLow,\n e\n )\n }\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n\nexport const isAtomicReadyWalletRejectedUpgradeError = (e: any): boolean => {\n if (e.cause?.code === AtomicReadyWalletRejectedUpgradeError.code) {\n return true\n }\n\n const details = e.cause?.details?.toLowerCase()\n const isTransactionError =\n e.name === 'TransactionExecutionError' ||\n e.cause?.name === 'TransactionExecutionError'\n const hasRejectedUpgrade =\n details?.includes('rejected') && details?.includes('upgrade')\n const has7702ErrorCode = details?.includes('7702')\n\n return isTransactionError && (hasRejectedUpgrade || has7702ErrorCode)\n}\n"],"mappings":";;;AAeA,MAAa,sBAAsB,OACjC,GACA,MACA,QACA,gBAC8C;CAE9C,IAAI,aAAa,uBACf,OAAO;CAKT,IAAI,wCAAwC,CAAC,KAAK,CAAC,aACjD,OAAO,IAAI,sBACT,iGACA,EAAE,mBAAmB,KAAK,GAC1B,CACF;CAGF,IAAI,aAAa,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,MAAM,qBAAqB,GAAG,MAAM,MAAM;CAE5D,OAAO,IAAI,SAAS,WAAW,MAAM,MAAM;AAC7C;AAEA,MAAM,uBAAuB,OAC3B,GACA,MACA,WACG;CACH,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,8BAKlB,EAAE,SAAS,wBAEX,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;CAS3E,IACE,EAAE,OAAO,SAAS,SAEjB,EAAE,SAAS,+BACV,EAAE,OAAO,SAAS,SAAS,UAAU,GAEvC,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;;CAU3E,IAAI,EAAE,OAAO,SAAS,QACpB,OAAO,IAAI,iBAAiB,cAAc,qBAAqB,EAAE,SAAS,CAAC;;;;CAM7E,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,8BAClB,EAAE,OAAO,OAAO,SAAS,4BAEzB,OAAO,IAAI,iBAAiB,cAAc,iBAAiB,EAAE,SAAS,CAAC;CAGzE,IACE,QACA,QAAQ,UACR,EAAE,SAAS,cAAc,qBACzB,EAAE,YAAY,aAAa,qBAOL;QAAA,MALC,oBACrB,OAAO,QACP,KAAK,OAAO,WACd,EAAA,EAE2D,cAAA,EAEzC,YAAY,CAAC,CAAC,SAAS,YAAY,GACnD,OAAO,IAAI,iBACT,cAAc,eACd,aAAa,aACb,CACF;CAAA;CAIJ,IAAI,aAAa,WACf,OAAO;CAGT,OAAO,IAAI,aAAa,EAAE,WAAW,aAAa,cAAc,CAAC;AACnE;AAEA,MAAa,2CAA2C,MAAoB;CAC1E,IAAI,EAAE,OAAO,SAAS,sCAAsC,MAC1D,OAAO;CAGT,MAAM,UAAU,EAAE,OAAO,SAAS,YAAY;CAC9C,MAAM,qBACJ,EAAE,SAAS,+BACX,EAAE,OAAO,SAAS;CACpB,MAAM,qBACJ,SAAS,SAAS,UAAU,KAAK,SAAS,SAAS,SAAS;CAC9D,MAAM,mBAAmB,SAAS,SAAS,MAAM;CAEjD,OAAO,uBAAuB,sBAAsB;AACtD"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -17,6 +17,12 @@ export interface EthereumTaskContext {
|
|
|
17
17
|
hasMatchingPermit?: boolean;
|
|
18
18
|
hasAllowance?: boolean;
|
|
19
19
|
hasSufficientAllowance?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The spender `EthereumCheckAllowanceTask` checked the allowance against. The
|
|
22
|
+
* other allowance tasks approve the same one. Prepare compares it with the
|
|
23
|
+
* spender of the strategy it establishes.
|
|
24
|
+
*/
|
|
25
|
+
allowanceSpender?: Address;
|
|
20
26
|
/**
|
|
21
27
|
* Whether the signer can produce a Permit2-verifiable signature — the
|
|
22
28
|
* in-flight or settled lookup, memoized per execution by
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":["_WalletCallReceipt"],"sources":["../../src/types.ts"],"mappings":";;;iBAqBiB;EACf,wBAAwB,QAAQ;EAChC,eAAe,oBAAoB,QAAQ;EAC3C,0BAA0B;EAC1B;EACA;;iBAGe;EACf;EACA,qBAAqB;EACrB,oBAAoB;EACpB,OAAO;EACP,iBAAiB;EACjB;EACA;EACA;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":["_WalletCallReceipt"],"sources":["../../src/types.ts"],"mappings":";;;iBAqBiB;EACf,wBAAwB,QAAQ;EAChC,eAAe,oBAAoB,QAAQ;EAC3C,0BAA0B;EAC1B;EACA;;iBAGe;EACf;EACA,qBAAqB;EACrB,oBAAoB;EACpB,OAAO;EACP,iBAAiB;EACjB;EACA;EACA;;;;;;EAMA,mBAAmB;;;;;;;;;EASnB,yBAAyB;;iBAGV,oCACP,qBACN;EACF;EACA,gBAAgB;EAChB,cACE,MAAM,kBACN,2BACG,QAAQ;EACb,eAAe,oBAAoB,QAAQ;EAC3C,aAAa,QAAQ,cAAc;;EAEnC,cAAc;;iBAGC,4BAA4B;EAC3C,SAAS;EACT,WAAW,SAAS;EACpB,oBAAoB,QAAQ;;wBAGd,mBACd,UAAU,cACT,YAAY;YAIH;EACV,OAAO;EACP;;YAGU;EACV,OAAO;EACP;;YAGU;EACV,OAAO;EACP;EACA;;iBAGe;EACf,cAAc;EACd,OAAO;EACP;EACA;;iBAGe;EACf,cAAc;EACd,OAAO;EACP;;YAGU;EACV,IAAI;EACJ,OAAO;EACP;EACA;;YAGU,oBAAoBA;EAI9B;;YAGU,eAAe,mBAAmB;EAC5C,WAAW,aAAa,mBAAmB"}
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import {\n type BaseToken,\n ChainType,\n type LiFiStep,\n type LiFiStepExtended,\n type SDKClient,\n type SDKProvider,\n type SDKStorage,\n type SignedTypedData,\n type StepExecutorContext,\n type TransactionMethodType,\n type TransactionParameters,\n} from '@lifi/sdk'\nimport type {\n WalletCallReceipt as _WalletCallReceipt,\n Address,\n Client,\n FallbackTransportConfig,\n Hex,\n} from 'viem'\n\nexport interface EthereumProviderOptions {\n getWalletClient?: () => Promise<Client>\n switchChain?: (chainId: number) => Promise<Client | undefined>\n fallbackTransportConfig?: FallbackTransportConfig\n safeApiKey?: string\n disableMessageSigning?: boolean\n}\n\nexport interface EthereumTaskContext {\n disableMessageSigning: boolean\n transactionRequest?: TransactionParameters\n executionStrategy?: TransactionMethodType\n calls: Call[]\n signedTypedData: SignedTypedData[]\n hasMatchingPermit?: boolean\n hasAllowance?: boolean\n hasSufficientAllowance?: boolean\n /**\n * Whether the signer can produce a Permit2-verifiable signature — the\n * in-flight or settled lookup, memoized per execution by\n * `resolvePermit2Support` so the allowance tasks and the sign-and-execute task\n * can't disagree. Deliberately the promise and not a `boolean`: that would\n * be a tri-state (unresolved / yes / no) whose `false` case is\n * indistinguishable from \"not looked up yet\" under a truthiness check.\n */\n permit2SignerSupported?: Promise<boolean>\n}\n\nexport interface EthereumStepExecutorContext\n extends StepExecutorContext,\n EthereumTaskContext {\n isFromNativeToken: boolean\n ethereumClient: Client\n checkClient: (\n step: LiFiStepExtended,\n targetChainId?: number\n ) => Promise<Client | undefined>\n switchChain?: (chainId: number) => Promise<Client | undefined>\n getStorage: (client: SDKClient) => SDKStorage\n /** Params passed when retrying executeStep (e.g. atomicityNotReady for 7702). */\n retryParams?: Record<string, unknown>\n}\n\nexport interface EthereumSDKProvider extends SDKProvider {\n options: EthereumProviderOptions\n setOptions(options: EthereumProviderOptions): void\n getWalletClient?(): Promise<Client>\n}\n\nexport function isEthereumProvider(\n provider: SDKProvider\n): provider is EthereumSDKProvider {\n return provider.type === ChainType.EVM\n}\n\nexport type TokenSpender = {\n token: BaseToken\n spenderAddress: string\n}\n\nexport type TokenAllowance = {\n token: BaseToken\n allowance?: bigint\n}\n\nexport type TokenSpenderAllowance = {\n token: BaseToken\n spenderAddress: string\n allowance?: bigint\n}\n\nexport interface ApproveTokenRequest {\n walletClient: Client\n token: BaseToken\n spenderAddress: string\n amount: bigint\n}\n\nexport interface RevokeApprovalRequest {\n walletClient: Client\n token: BaseToken\n spenderAddress: string\n}\n\nexport type Call = {\n to: Address\n data?: Hex\n value?: bigint\n chainId?: number\n}\n\nexport type WalletCallReceipt = _WalletCallReceipt<\n bigint,\n 'success' | 'reverted'\n> & {\n transactionLink?: string\n}\n\nexport type RelayerStep = (LiFiStepExtended | LiFiStep) & {\n typedData: NonNullable<(LiFiStepExtended | LiFiStep)['typedData']>\n}\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import {\n type BaseToken,\n ChainType,\n type LiFiStep,\n type LiFiStepExtended,\n type SDKClient,\n type SDKProvider,\n type SDKStorage,\n type SignedTypedData,\n type StepExecutorContext,\n type TransactionMethodType,\n type TransactionParameters,\n} from '@lifi/sdk'\nimport type {\n WalletCallReceipt as _WalletCallReceipt,\n Address,\n Client,\n FallbackTransportConfig,\n Hex,\n} from 'viem'\n\nexport interface EthereumProviderOptions {\n getWalletClient?: () => Promise<Client>\n switchChain?: (chainId: number) => Promise<Client | undefined>\n fallbackTransportConfig?: FallbackTransportConfig\n safeApiKey?: string\n disableMessageSigning?: boolean\n}\n\nexport interface EthereumTaskContext {\n disableMessageSigning: boolean\n transactionRequest?: TransactionParameters\n executionStrategy?: TransactionMethodType\n calls: Call[]\n signedTypedData: SignedTypedData[]\n hasMatchingPermit?: boolean\n hasAllowance?: boolean\n hasSufficientAllowance?: boolean\n /**\n * The spender `EthereumCheckAllowanceTask` checked the allowance against. The\n * other allowance tasks approve the same one. Prepare compares it with the\n * spender of the strategy it establishes.\n */\n allowanceSpender?: Address\n /**\n * Whether the signer can produce a Permit2-verifiable signature — the\n * in-flight or settled lookup, memoized per execution by\n * `resolvePermit2Support` so the allowance tasks and the sign-and-execute task\n * can't disagree. Deliberately the promise and not a `boolean`: that would\n * be a tri-state (unresolved / yes / no) whose `false` case is\n * indistinguishable from \"not looked up yet\" under a truthiness check.\n */\n permit2SignerSupported?: Promise<boolean>\n}\n\nexport interface EthereumStepExecutorContext\n extends StepExecutorContext,\n EthereumTaskContext {\n isFromNativeToken: boolean\n ethereumClient: Client\n checkClient: (\n step: LiFiStepExtended,\n targetChainId?: number\n ) => Promise<Client | undefined>\n switchChain?: (chainId: number) => Promise<Client | undefined>\n getStorage: (client: SDKClient) => SDKStorage\n /** Params passed when retrying executeStep (e.g. atomicityNotReady for 7702). */\n retryParams?: Record<string, unknown>\n}\n\nexport interface EthereumSDKProvider extends SDKProvider {\n options: EthereumProviderOptions\n setOptions(options: EthereumProviderOptions): void\n getWalletClient?(): Promise<Client>\n}\n\nexport function isEthereumProvider(\n provider: SDKProvider\n): provider is EthereumSDKProvider {\n return provider.type === ChainType.EVM\n}\n\nexport type TokenSpender = {\n token: BaseToken\n spenderAddress: string\n}\n\nexport type TokenAllowance = {\n token: BaseToken\n allowance?: bigint\n}\n\nexport type TokenSpenderAllowance = {\n token: BaseToken\n spenderAddress: string\n allowance?: bigint\n}\n\nexport interface ApproveTokenRequest {\n walletClient: Client\n token: BaseToken\n spenderAddress: string\n amount: bigint\n}\n\nexport interface RevokeApprovalRequest {\n walletClient: Client\n token: BaseToken\n spenderAddress: string\n}\n\nexport type Call = {\n to: Address\n data?: Hex\n value?: bigint\n chainId?: number\n}\n\nexport type WalletCallReceipt = _WalletCallReceipt<\n bigint,\n 'success' | 'reverted'\n> & {\n transactionLink?: string\n}\n\nexport type RelayerStep = (LiFiStepExtended | LiFiStep) & {\n typedData: NonNullable<(LiFiStepExtended | LiFiStep)['typedData']>\n}\n"],"mappings":";;AA4EA,SAAgB,mBACd,UACiC;CACjC,OAAO,SAAS,SAAS,UAAU;AACrC"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.2.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.2.7'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-ethereum",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.7",
|
|
4
4
|
"description": "LI.FI Ethereum SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "4.
|
|
32
|
-
"viem": "^2.57.
|
|
31
|
+
"@lifi/sdk": "4.11.0",
|
|
32
|
+
"viem": "^2.57.3"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
package/src/EthereumProvider.ts
CHANGED
|
@@ -10,6 +10,11 @@ function isEthereumTokenAddress(address: string): boolean {
|
|
|
10
10
|
return isAddress(address, { strict: false })
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/** viem reads a second argument as options, so a chain ID must not reach it. */
|
|
14
|
+
function isEthereumAddress(address: string): boolean {
|
|
15
|
+
return isAddress(address)
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
export function EthereumProvider(
|
|
14
19
|
options?: EthereumProviderOptions
|
|
15
20
|
): EthereumSDKProvider {
|
|
@@ -21,7 +26,7 @@ export function EthereumProvider(
|
|
|
21
26
|
get options() {
|
|
22
27
|
return _options
|
|
23
28
|
},
|
|
24
|
-
isAddress,
|
|
29
|
+
isAddress: isEthereumAddress,
|
|
25
30
|
isTokenAddress: isEthereumTokenAddress,
|
|
26
31
|
resolveAddress: resolveEthereumAddress,
|
|
27
32
|
getBalance: getEthereumBalance,
|
|
@@ -19,10 +19,20 @@ export const waitForBatchTransactionReceipt = async (
|
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
if (result.status === 'success') {
|
|
22
|
+
if (result.receipts?.some((receipt) => receipt.status === 'reverted')) {
|
|
23
|
+
onFailed?.(result)
|
|
24
|
+
throw new TransactionError(
|
|
25
|
+
LiFiErrorCode.TransactionFailed,
|
|
26
|
+
'Transaction was reverted.',
|
|
27
|
+
undefined,
|
|
28
|
+
{ final: true }
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
// The wallet reports the batch as executed, but without a complete set of
|
|
32
|
+
// receipts we cannot prove the outcome: it stays unknown.
|
|
22
33
|
if (
|
|
23
34
|
!result.receipts?.length ||
|
|
24
|
-
!result.receipts.every((receipt) => receipt.transactionHash)
|
|
25
|
-
result.receipts.some((receipt) => receipt.status === 'reverted')
|
|
35
|
+
!result.receipts.every((receipt) => receipt.transactionHash)
|
|
26
36
|
) {
|
|
27
37
|
onFailed?.(result)
|
|
28
38
|
throw new TransactionError(
|
|
@@ -37,10 +47,22 @@ export const waitForBatchTransactionReceipt = async (
|
|
|
37
47
|
onFailed?.(result)
|
|
38
48
|
throw new TransactionError(
|
|
39
49
|
LiFiErrorCode.TransactionCanceled,
|
|
40
|
-
'Transaction was canceled.'
|
|
50
|
+
'Transaction was canceled.',
|
|
51
|
+
undefined,
|
|
52
|
+
{ final: true }
|
|
41
53
|
)
|
|
42
54
|
}
|
|
43
55
|
onFailed?.(result)
|
|
56
|
+
// Only 500 (reverted completely) is final. Some calls of a partial batch
|
|
57
|
+
// (600) may be onchain, and other codes are undefined: the outcome is unknown.
|
|
58
|
+
if (result.statusCode === 500) {
|
|
59
|
+
throw new TransactionError(
|
|
60
|
+
LiFiErrorCode.TransactionFailed,
|
|
61
|
+
'Transaction failed.',
|
|
62
|
+
undefined,
|
|
63
|
+
{ final: true }
|
|
64
|
+
)
|
|
65
|
+
}
|
|
44
66
|
throw new TransactionError(
|
|
45
67
|
LiFiErrorCode.TransactionFailed,
|
|
46
68
|
'Transaction failed.'
|