@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
|
@@ -6,7 +6,11 @@ const require_hyperliquid_agentWallet = require("../../../hyperliquid/agentWalle
|
|
|
6
6
|
let viem_actions = require("viem/actions");
|
|
7
7
|
let viem_utils = require("viem/utils");
|
|
8
8
|
//#region src/core/tasks/helpers/signHyperliquidTypedData.ts
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* `beforeSignature` runs right before each signature, the agent's included,
|
|
11
|
+
* after every await before it; it throws to stop the signing.
|
|
12
|
+
*/
|
|
13
|
+
const signHyperliquidTypedData = async (context, allowanceTypedData, beforeSignature) => {
|
|
10
14
|
const { step, fromChain, client, allowUserInteraction, checkClient, ethereumClient, getStorage } = context;
|
|
11
15
|
if (!allowUserInteraction) return;
|
|
12
16
|
const signedResults = [];
|
|
@@ -23,6 +27,7 @@ const signHyperliquidTypedData = async (context, allowanceTypedData) => {
|
|
|
23
27
|
};
|
|
24
28
|
const updatedClient = await checkClient(step, require_utils_getDomainChainId.getDomainChainId(typedData.domain) || fromChain.id);
|
|
25
29
|
if (!updatedClient) return;
|
|
30
|
+
beforeSignature?.();
|
|
26
31
|
const signature = await (0, viem_utils.getAction)(updatedClient, viem_actions.signTypedData, "signTypedData")({
|
|
27
32
|
account: updatedClient.account,
|
|
28
33
|
primaryType: typedData.primaryType,
|
|
@@ -39,6 +44,7 @@ const signHyperliquidTypedData = async (context, allowanceTypedData) => {
|
|
|
39
44
|
} else if (require_hyperliquid_isHyperliquidAgentStep.isApproveBuilderFeeMessage(typedData)) {
|
|
40
45
|
const updatedClient = await checkClient(step, require_utils_getDomainChainId.getDomainChainId(typedData.domain) || fromChain.id);
|
|
41
46
|
if (!updatedClient) return;
|
|
47
|
+
beforeSignature?.();
|
|
42
48
|
const signature = await (0, viem_utils.getAction)(updatedClient, viem_actions.signTypedData, "signTypedData")({
|
|
43
49
|
account: updatedClient.account,
|
|
44
50
|
primaryType: typedData.primaryType,
|
|
@@ -52,6 +58,7 @@ const signHyperliquidTypedData = async (context, allowanceTypedData) => {
|
|
|
52
58
|
signature
|
|
53
59
|
});
|
|
54
60
|
} else if (require_hyperliquid_isHyperliquidAgentStep.isHyperliquidOrderMessage(typedData)) {
|
|
61
|
+
beforeSignature?.();
|
|
55
62
|
const signature = await agentAccount.signTypedData({
|
|
56
63
|
domain: typedData.domain,
|
|
57
64
|
types: typedData.types,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signHyperliquidTypedData.js","names":["isApproveAgentMessage","getOrCreateAgentWallet","getDomainChainId","getAction","signTypedData","isApproveBuilderFeeMessage","isHyperliquidOrderMessage"],"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":["isApproveAgentMessage","getOrCreateAgentWallet","getDomainChainId","getAction","signTypedData","isApproveBuilderFeeMessage","isHyperliquidOrderMessage"],"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,KAAKA,2CAAAA,qBACL,CAAC,EAAE,QAAQ;CAIrD,MAAM,EACJ,SAAS,cACT,eACA,cACE,MAAMC,gCAAAA,uBAAuB,SAAS,cAAc,oBAAoB;CAE5E,KAAK,MAAM,aAAa,oBACtB,IAAID,2CAAAA,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,MAFtCE,+BAAAA,iBAAiB,UAAU,MAAM,KAAK,UAAU,EAEY;EAC9D,IAAI,CAAC,eACH;EAGF,kBAAkB;EAClB,MAAM,YAAY,OAAA,GAAMC,WAAAA,UAAAA,CACtB,eACAC,aAAAA,eACA,eACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB,aAAa,UAAU;GACvB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB;EACF,CAAC;EACD,+BAAA,qBAAqB,SAAS;EAC9B,cAAc,KAAK;GAAE,GAAG;GAAW;GAAS;EAAU,CAAC;CACzD,OAAO,IAAIC,2CAAAA,2BAA2B,SAAS,GAAG;EAIhD,MAAM,gBAAgB,MAAM,YAAY,MAFtCH,+BAAAA,iBAAiB,UAAU,MAAM,KAAK,UAAU,EAEY;EAC9D,IAAI,CAAC,eACH;EAGF,kBAAkB;EAClB,MAAM,YAAY,OAAA,GAAMC,WAAAA,UAAAA,CACtB,eACAC,aAAAA,eACA,eACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB,aAAa,UAAU;GACvB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,SAAS,UAAU;EACrB,CAAC;EACD,+BAAA,qBAAqB,SAAS;EAC9B,cAAc,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAChD,OAAO,IAAIE,2CAAAA,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
|
|
@@ -4,8 +4,12 @@ const require_utils_isValidSignature = require("../../../utils/isValidSignature.
|
|
|
4
4
|
let viem_actions = require("viem/actions");
|
|
5
5
|
let viem_utils = require("viem/utils");
|
|
6
6
|
//#region src/core/tasks/helpers/signTypedDataEntries.ts
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Signs the entries in order, switching chains per entry, and appends the
|
|
9
|
+
* signatures. `beforeSignature` runs right before each wallet call, after the
|
|
10
|
+
* chain switch; it throws to stop the signing.
|
|
11
|
+
*/
|
|
12
|
+
async function signTypedDataEntries(context, entries, actionType, actionStatus = "ACTION_REQUIRED", beforeSignature) {
|
|
9
13
|
const { step, statusManager, allowUserInteraction, checkClient, signedTypedData: currentSignedTypedData } = context;
|
|
10
14
|
const signedTypedData = [...currentSignedTypedData];
|
|
11
15
|
if (entries.length) statusManager.updateAction(step, actionType, actionStatus);
|
|
@@ -13,6 +17,7 @@ async function signTypedDataEntries(context, entries, actionType, actionStatus =
|
|
|
13
17
|
if (!allowUserInteraction) return { status: "PAUSED" };
|
|
14
18
|
const client = await checkClient(step, require_utils_getDomainChainId.getDomainChainId(typedData.domain) || step.action.fromChainId);
|
|
15
19
|
if (!client) return { status: "PAUSED" };
|
|
20
|
+
beforeSignature?.();
|
|
16
21
|
const signature = await (0, viem_utils.getAction)(client, viem_actions.signTypedData, "signTypedData")({
|
|
17
22
|
account: client.account,
|
|
18
23
|
domain: typedData.domain,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signTypedDataEntries.js","names":["getDomainChainId","getAction","signTypedData"],"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":["getDomainChainId","getAction","signTypedData"],"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/BA,+BAAAA,iBAAiB,UAAU,MAAM,KAAK,KAAK,OAAO,WAEG;EACvD,IAAI,CAAC,QACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,kBAAkB;EAClB,MAAM,YAAY,OAAA,GAAMC,WAAAA,UAAAA,CACtB,QACAC,aAAAA,eACA,eACF,CAAC,CAAC;GACA,SAAS,OAAO;GAChB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,aAAa,UAAU;GACvB,SAAS,UAAU;EACrB,CAAC;EACD,+BAAA,qBAAqB,SAAS;EAE9B,gBAAgB,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAClD;CAEA,OAAO;EAAE,QAAQ;EAAa;CAAgB;AAChD"}
|
|
@@ -3,7 +3,8 @@ let _lifi_sdk = require("@lifi/sdk");
|
|
|
3
3
|
let viem = require("viem");
|
|
4
4
|
//#region src/errors/parseEthereumErrors.ts
|
|
5
5
|
const parseEthereumErrors = async (e, step, action, retryParams) => {
|
|
6
|
-
if (
|
|
6
|
+
if (e instanceof _lifi_sdk.ExecuteStepRetryError) return e;
|
|
7
|
+
if (isAtomicReadyWalletRejectedUpgradeError(e) && !retryParams) return new _lifi_sdk.ExecuteStepRetryError("Wallet rejected 7702 upgrade based on the EIP-5792 capabilities; retry with atomicityNotReady", { atomicityNotReady: true }, e);
|
|
7
8
|
if (e instanceof _lifi_sdk.SDKError) {
|
|
8
9
|
e.step = e.step ?? step;
|
|
9
10
|
e.action = e.action ?? action;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseEthereumErrors.js","names":["ExecuteStepRetryError","SDKError","TransactionError","LiFiErrorCode","ErrorMessage","fetchTxErrorDetails","BaseError","UnknownError","AtomicReadyWalletRejectedUpgradeError"],"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":["ExecuteStepRetryError","SDKError","TransactionError","LiFiErrorCode","ErrorMessage","fetchTxErrorDetails","BaseError","UnknownError","AtomicReadyWalletRejectedUpgradeError"],"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,aAAaA,UAAAA,uBACf,OAAO;CAKT,IAAI,wCAAwC,CAAC,KAAK,CAAC,aACjD,OAAO,IAAIA,UAAAA,sBACT,iGACA,EAAE,mBAAmB,KAAK,GAC1B,CACF;CAGF,IAAI,aAAaC,UAAAA,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,MAAM,qBAAqB,GAAG,MAAM,MAAM;CAE5D,OAAO,IAAIA,UAAAA,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,IAAIC,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;CAS3E,IACE,EAAE,OAAO,SAAS,SAEjB,EAAE,SAAS,+BACV,EAAE,OAAO,SAAS,SAAS,UAAU,GAEvC,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;;;;;;;;;CAU3E,IAAI,EAAE,OAAO,SAAS,QACpB,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,qBAAqB,EAAE,SAAS,CAAC;;;;CAM7E,IACE,EAAE,SAAS,8BACX,EAAE,OAAO,SAAS,8BAClB,EAAE,OAAO,OAAO,SAAS,4BAEzB,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,iBAAiB,EAAE,SAAS,CAAC;CAGzE,IACE,QACA,QAAQ,UACR,EAAE,SAASA,UAAAA,cAAc,qBACzB,EAAE,YAAYC,UAAAA,aAAa,qBAOL;QAAA,OAAA,GALCC,UAAAA,oBAAAA,CACrB,OAAO,QACP,KAAK,OAAO,WACd,EAAA,EAE2D,cAAA,EAEzC,YAAY,CAAC,CAAC,SAAS,YAAY,GACnD,OAAO,IAAIH,UAAAA,iBACTC,UAAAA,cAAc,eACdC,UAAAA,aAAa,aACb,CACF;CAAA;CAIJ,IAAI,aAAaE,UAAAA,WACf,OAAO;CAGT,OAAO,IAAIC,UAAAA,aAAa,EAAE,WAAWH,UAAAA,aAAa,cAAc,CAAC;AACnE;AAEA,MAAa,2CAA2C,MAAoB;CAC1E,IAAI,EAAE,OAAO,SAASI,KAAAA,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/cjs/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/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["ChainType"],"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":["ChainType"],"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,SAASA,UAAAA,UAAU;AACrC"}
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/version.ts
|
|
3
3
|
const name = "@lifi/sdk-provider-ethereum";
|
|
4
|
-
const version = "4.2.
|
|
4
|
+
const version = "4.2.7";
|
|
5
5
|
//#endregion
|
|
6
6
|
exports.name = name;
|
|
7
7
|
exports.version = version;
|
package/dist/cjs/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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumProvider.d.ts","names":[],"sources":["../../src/EthereumProvider.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"EthereumProvider.d.ts","names":[],"sources":["../../src/EthereumProvider.ts"],"mappings":";;wBAiBgB,iBACd,UAAU,0BACT"}
|
|
@@ -8,6 +8,10 @@ import { isAddress } from "viem";
|
|
|
8
8
|
function isEthereumTokenAddress(address) {
|
|
9
9
|
return isAddress(address, { strict: false });
|
|
10
10
|
}
|
|
11
|
+
/** viem reads a second argument as options, so a chain ID must not reach it. */
|
|
12
|
+
function isEthereumAddress(address) {
|
|
13
|
+
return isAddress(address);
|
|
14
|
+
}
|
|
11
15
|
function EthereumProvider(options) {
|
|
12
16
|
const _options = options ?? {};
|
|
13
17
|
return {
|
|
@@ -17,7 +21,7 @@ function EthereumProvider(options) {
|
|
|
17
21
|
get options() {
|
|
18
22
|
return _options;
|
|
19
23
|
},
|
|
20
|
-
isAddress,
|
|
24
|
+
isAddress: isEthereumAddress,
|
|
21
25
|
isTokenAddress: isEthereumTokenAddress,
|
|
22
26
|
resolveAddress: resolveEthereumAddress,
|
|
23
27
|
getBalance: getEthereumBalance,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumProvider.js","names":[],"sources":["../../src/EthereumProvider.ts"],"sourcesContent":["import { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { isAddress } from 'viem'\nimport { getEthereumBalance } from './actions/getEthereumBalance.js'\nimport { resolveEthereumAddress } from './actions/resolveEthereumAddress.js'\nimport { EthereumStepExecutor } from './core/EthereumStepExecutor.js'\nimport type { EthereumProviderOptions, EthereumSDKProvider } from './types.js'\n\n/** The wallet format without the checksum: a pasted address keeps its case. */\nfunction isEthereumTokenAddress(address: string): boolean {\n return isAddress(address, { strict: false })\n}\n\nexport function EthereumProvider(\n options?: EthereumProviderOptions\n): EthereumSDKProvider {\n const _options: EthereumProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.EVM\n },\n get options() {\n return _options\n },\n isAddress,\n isTokenAddress: isEthereumTokenAddress,\n resolveAddress: resolveEthereumAddress,\n getBalance: getEthereumBalance,\n getWalletClient: _options.getWalletClient,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<EthereumStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new EthereumStepExecutor({\n client: walletClient,\n switchChain: _options.switchChain,\n disableMessageSigning: _options.disableMessageSigning,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: EthereumProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;AAQA,SAAS,uBAAuB,SAA0B;CACxD,OAAO,UAAU,SAAS,EAAE,QAAQ,MAAM,CAAC;AAC7C;AAEA,SAAgB,iBACd,SACqB;CACrB,MAAM,WAAoC,WAAW,CAAC;CACtD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;EACnB;EACA,IAAI,UAAU;GACZ,OAAO;EACT;EACA;
|
|
1
|
+
{"version":3,"file":"EthereumProvider.js","names":[],"sources":["../../src/EthereumProvider.ts"],"sourcesContent":["import { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { isAddress } from 'viem'\nimport { getEthereumBalance } from './actions/getEthereumBalance.js'\nimport { resolveEthereumAddress } from './actions/resolveEthereumAddress.js'\nimport { EthereumStepExecutor } from './core/EthereumStepExecutor.js'\nimport type { EthereumProviderOptions, EthereumSDKProvider } from './types.js'\n\n/** The wallet format without the checksum: a pasted address keeps its case. */\nfunction isEthereumTokenAddress(address: string): boolean {\n return isAddress(address, { strict: false })\n}\n\n/** viem reads a second argument as options, so a chain ID must not reach it. */\nfunction isEthereumAddress(address: string): boolean {\n return isAddress(address)\n}\n\nexport function EthereumProvider(\n options?: EthereumProviderOptions\n): EthereumSDKProvider {\n const _options: EthereumProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.EVM\n },\n get options() {\n return _options\n },\n isAddress: isEthereumAddress,\n isTokenAddress: isEthereumTokenAddress,\n resolveAddress: resolveEthereumAddress,\n getBalance: getEthereumBalance,\n getWalletClient: _options.getWalletClient,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<EthereumStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new EthereumStepExecutor({\n client: walletClient,\n switchChain: _options.switchChain,\n disableMessageSigning: _options.disableMessageSigning,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: EthereumProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;AAQA,SAAS,uBAAuB,SAA0B;CACxD,OAAO,UAAU,SAAS,EAAE,QAAQ,MAAM,CAAC;AAC7C;;AAGA,SAAS,kBAAkB,SAA0B;CACnD,OAAO,UAAU,OAAO;AAC1B;AAEA,SAAgB,iBACd,SACqB;CACrB,MAAM,WAAoC,WAAW,CAAC;CACtD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;EACnB;EACA,IAAI,UAAU;GACZ,OAAO;EACT;EACA,WAAW;EACX,gBAAgB;EAChB,gBAAgB;EAChB,YAAY;EACZ,iBAAiB,SAAS;EAC1B,MAAM,gBACJ,SAC+B;GAC/B,IAAI,CAAC,SAAS,iBACZ,MAAM,IAAI,MAAM,yBAAyB;GAG3C,MAAM,eAAe,MAAM,SAAS,gBAAgB;GAYpD,OAAO,IAVc,qBAAqB;IACxC,QAAQ;IACR,aAAa,SAAS;IACtB,uBAAuB,SAAS;IAChC,SAAS,QAAQ;IACjB,kBAAkB,EAChB,GAAG,QAAQ,iBACb;GACF,CAEc;EAChB;EACA,WAAW,SAAkC;GAC3C,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -8,7 +8,11 @@ const waitForBatchTransactionReceipt = async (client, batchHash, onFailed) => {
|
|
|
8
8
|
timeout: 864e5
|
|
9
9
|
});
|
|
10
10
|
if (result.status === "success") {
|
|
11
|
-
if (
|
|
11
|
+
if (result.receipts?.some((receipt) => receipt.status === "reverted")) {
|
|
12
|
+
onFailed?.(result);
|
|
13
|
+
throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction was reverted.", void 0, { final: true });
|
|
14
|
+
}
|
|
15
|
+
if (!result.receipts?.length || !result.receipts.every((receipt) => receipt.transactionHash)) {
|
|
12
16
|
onFailed?.(result);
|
|
13
17
|
throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction was reverted.");
|
|
14
18
|
}
|
|
@@ -16,9 +20,10 @@ const waitForBatchTransactionReceipt = async (client, batchHash, onFailed) => {
|
|
|
16
20
|
}
|
|
17
21
|
if (result.statusCode >= 400 && result.statusCode < 500) {
|
|
18
22
|
onFailed?.(result);
|
|
19
|
-
throw new TransactionError(LiFiErrorCode.TransactionCanceled, "Transaction was canceled.");
|
|
23
|
+
throw new TransactionError(LiFiErrorCode.TransactionCanceled, "Transaction was canceled.", void 0, { final: true });
|
|
20
24
|
}
|
|
21
25
|
onFailed?.(result);
|
|
26
|
+
if (result.statusCode === 500) throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction failed.", void 0, { final: true });
|
|
22
27
|
throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction failed.");
|
|
23
28
|
};
|
|
24
29
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForBatchTransactionReceipt.js","names":[],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport type { Client, Hash } from 'viem'\nimport { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { WalletCallReceipt } from '../types.js'\n\nexport const waitForBatchTransactionReceipt = async (\n client: Client,\n batchHash: Hash,\n onFailed?: (result: GetCallsStatusReturnType) => void\n): Promise<WalletCallReceipt> => {\n const result = await getAction(\n client,\n waitForCallsStatus,\n 'waitForCallsStatus'\n )({\n id: batchHash,\n timeout: 3_600_000 * 24,\n })\n\n if (result.status === 'success') {\n if (
|
|
1
|
+
{"version":3,"file":"waitForBatchTransactionReceipt.js","names":[],"sources":["../../../src/actions/waitForBatchTransactionReceipt.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport type { Client, Hash } from 'viem'\nimport { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { WalletCallReceipt } from '../types.js'\n\nexport const waitForBatchTransactionReceipt = async (\n client: Client,\n batchHash: Hash,\n onFailed?: (result: GetCallsStatusReturnType) => void\n): Promise<WalletCallReceipt> => {\n const result = await getAction(\n client,\n waitForCallsStatus,\n 'waitForCallsStatus'\n )({\n id: batchHash,\n timeout: 3_600_000 * 24,\n })\n\n if (result.status === 'success') {\n if (result.receipts?.some((receipt) => receipt.status === 'reverted')) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.',\n undefined,\n { final: true }\n )\n }\n // The wallet reports the batch as executed, but without a complete set of\n // receipts we cannot prove the outcome: it stays unknown.\n if (\n !result.receipts?.length ||\n !result.receipts.every((receipt) => receipt.transactionHash)\n ) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.'\n )\n }\n const transactionReceipt = result.receipts.at(-1)!\n return transactionReceipt\n }\n if (result.statusCode >= 400 && result.statusCode < 500) {\n onFailed?.(result)\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Transaction was canceled.',\n undefined,\n { final: true }\n )\n }\n onFailed?.(result)\n // Only 500 (reverted completely) is final. Some calls of a partial batch\n // (600) may be onchain, and other codes are undefined: the outcome is unknown.\n if (result.statusCode === 500) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.',\n undefined,\n { final: true }\n )\n }\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction failed.'\n )\n}\n"],"mappings":";;;;AAMA,MAAa,iCAAiC,OAC5C,QACA,WACA,aAC+B;CAC/B,MAAM,SAAS,MAAM,UACnB,QACA,oBACA,oBACF,CAAC,CAAC;EACA,IAAI;EACJ,SAAS;CACX,CAAC;CAED,IAAI,OAAO,WAAW,WAAW;EAC/B,IAAI,OAAO,UAAU,MAAM,YAAY,QAAQ,WAAW,UAAU,GAAG;GACrE,WAAW,MAAM;GACjB,MAAM,IAAI,iBACR,cAAc,mBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;EACF;EAGA,IACE,CAAC,OAAO,UAAU,UAClB,CAAC,OAAO,SAAS,OAAO,YAAY,QAAQ,eAAe,GAC3D;GACA,WAAW,MAAM;GACjB,MAAM,IAAI,iBACR,cAAc,mBACd,2BACF;EACF;EAEA,OAD2B,OAAO,SAAS,GAAG,EACtB;CAC1B;CACA,IAAI,OAAO,cAAc,OAAO,OAAO,aAAa,KAAK;EACvD,WAAW,MAAM;EACjB,MAAM,IAAI,iBACR,cAAc,qBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CACF;CACA,WAAW,MAAM;CAGjB,IAAI,OAAO,eAAe,KACxB,MAAM,IAAI,iBACR,cAAc,mBACd,uBACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CAEF,MAAM,IAAI,iBACR,cAAc,mBACd,qBACF;AACF"}
|
|
@@ -2,6 +2,18 @@ import { WalletCallReceipt as WalletCallReceipt$1 } from "../types.js";
|
|
|
2
2
|
import { LiFiStep, SDKClient } from "@lifi/sdk";
|
|
3
3
|
import { Hash } from "viem";
|
|
4
4
|
//#region src/actions/waitForRelayedTransactionReceipt.d.ts
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Polls the relayer until the relayed transaction is done or has failed.
|
|
7
|
+
*
|
|
8
|
+
* @param client - {@link SDKClient}
|
|
9
|
+
* @param taskId - The relayer task id.
|
|
10
|
+
* @param step - The step the task belongs to.
|
|
11
|
+
* @param timeout - How long to wait for a result in milliseconds. Defaults to 24 hours.
|
|
12
|
+
* @param signal - Ends the wait: no status request starts after it aborts, and the request in flight and the sleep end at once.
|
|
13
|
+
* @returns The receipt of the relayed transaction.
|
|
14
|
+
* @throws {TransactionError} If the transaction failed, was not found, or no result arrived before the timeout. Only the failed transaction is a final outcome.
|
|
15
|
+
* @throws The abort reason of `signal` once it aborts.
|
|
16
|
+
*/
|
|
17
|
+
export declare const waitForRelayedTransactionReceipt: (client: SDKClient, taskId: Hash, step: LiFiStep, timeout?: number, signal?: AbortSignal) => Promise<WalletCallReceipt$1>;
|
|
6
18
|
//#endregion
|
|
7
19
|
//# sourceMappingURL=waitForRelayedTransactionReceipt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForRelayedTransactionReceipt.d.ts","names":["WalletCallReceipt"],"sources":["../../../src/actions/waitForRelayedTransactionReceipt.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"waitForRelayedTransactionReceipt.d.ts","names":["WalletCallReceipt"],"sources":["../../../src/actions/waitForRelayedTransactionReceipt.ts"],"mappings":";;;;;;;;;;;;;;;;qBAyBa,mCACX,QAAQ,WACR,QAAQ,MACR,MAAM,UACN,kBACA,SAAS,gBACR,QAAQA"}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { LiFiErrorCode, TransactionError, getRelayedTransactionStatus, waitForResult } from "@lifi/sdk";
|
|
2
2
|
//#region src/actions/waitForRelayedTransactionReceipt.ts
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Polls the relayer until the relayed transaction is done or has failed.
|
|
5
|
+
*
|
|
6
|
+
* @param client - {@link SDKClient}
|
|
7
|
+
* @param taskId - The relayer task id.
|
|
8
|
+
* @param step - The step the task belongs to.
|
|
9
|
+
* @param timeout - How long to wait for a result in milliseconds. Defaults to 24 hours.
|
|
10
|
+
* @param signal - Ends the wait: no status request starts after it aborts, and the request in flight and the sleep end at once.
|
|
11
|
+
* @returns The receipt of the relayed transaction.
|
|
12
|
+
* @throws {TransactionError} If the transaction failed, was not found, or no result arrived before the timeout. Only the failed transaction is a final outcome.
|
|
13
|
+
* @throws The abort reason of `signal` once it aborts.
|
|
14
|
+
*/
|
|
15
|
+
const waitForRelayedTransactionReceipt = async (client, taskId, step, timeout = 864e5, signal) => {
|
|
16
|
+
const startTime = Date.now();
|
|
4
17
|
return waitForResult(async () => {
|
|
18
|
+
if (Date.now() - startTime > timeout) throw new TransactionError(LiFiErrorCode.TransactionFailed, "Relayed transaction timed out waiting for a result.");
|
|
5
19
|
const result = await getRelayedTransactionStatus(client, {
|
|
6
20
|
taskId,
|
|
7
21
|
fromChain: step.action.fromChainId,
|
|
8
22
|
toChain: step.action.toChainId,
|
|
9
23
|
...step.tool !== "custom" && { bridge: step.tool }
|
|
10
|
-
}).catch((e) => {
|
|
11
|
-
if (process.env.NODE_ENV === "development") console.debug("Fetching status from relayer failed.", e);
|
|
24
|
+
}, { signal }).catch((e) => {
|
|
25
|
+
if (process.env.NODE_ENV === "development" && !signal?.aborted) console.debug("Fetching status from relayer failed.", e);
|
|
12
26
|
});
|
|
13
27
|
switch (result?.status) {
|
|
14
28
|
case "PENDING": return;
|
|
@@ -21,12 +35,12 @@ const waitForRelayedTransactionReceipt = async (client, taskId, step) => {
|
|
|
21
35
|
transactionLink: sending?.txLink
|
|
22
36
|
};
|
|
23
37
|
}
|
|
24
|
-
case "FAILED": throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction was reverted.");
|
|
38
|
+
case "FAILED": throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction was reverted.", void 0, { final: true });
|
|
25
39
|
default: throw new TransactionError(LiFiErrorCode.TransactionNotFound, "Transaction not found.");
|
|
26
40
|
}
|
|
27
41
|
}, 5e3, 3, (_, error) => {
|
|
28
42
|
return !(error instanceof TransactionError && error.code === LiFiErrorCode.TransactionFailed);
|
|
29
|
-
});
|
|
43
|
+
}, signal);
|
|
30
44
|
};
|
|
31
45
|
//#endregion
|
|
32
46
|
export { waitForRelayedTransactionReceipt };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForRelayedTransactionReceipt.js","names":[],"sources":["../../../src/actions/waitForRelayedTransactionReceipt.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport {\n type ExtendedTransactionInfo,\n type FullStatusData,\n getRelayedTransactionStatus,\n LiFiErrorCode,\n type LiFiStep,\n TransactionError,\n waitForResult,\n} from '@lifi/sdk'\nimport type { Hash } from 'viem'\nimport type { WalletCallReceipt } from '../types.js'\n\nexport const waitForRelayedTransactionReceipt = async (\n client: SDKClient,\n taskId: Hash,\n step: LiFiStep\n): Promise<WalletCallReceipt> => {\n return waitForResult(\n async () => {\n const result = await getRelayedTransactionStatus(client
|
|
1
|
+
{"version":3,"file":"waitForRelayedTransactionReceipt.js","names":[],"sources":["../../../src/actions/waitForRelayedTransactionReceipt.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport {\n type ExtendedTransactionInfo,\n type FullStatusData,\n getRelayedTransactionStatus,\n LiFiErrorCode,\n type LiFiStep,\n TransactionError,\n waitForResult,\n} from '@lifi/sdk'\nimport type { Hash } from 'viem'\nimport type { WalletCallReceipt } from '../types.js'\n\n/**\n * Polls the relayer until the relayed transaction is done or has failed.\n *\n * @param client - {@link SDKClient}\n * @param taskId - The relayer task id.\n * @param step - The step the task belongs to.\n * @param timeout - How long to wait for a result in milliseconds. Defaults to 24 hours.\n * @param signal - Ends the wait: no status request starts after it aborts, and the request in flight and the sleep end at once.\n * @returns The receipt of the relayed transaction.\n * @throws {TransactionError} If the transaction failed, was not found, or no result arrived before the timeout. Only the failed transaction is a final outcome.\n * @throws The abort reason of `signal` once it aborts.\n */\nexport const waitForRelayedTransactionReceipt = async (\n client: SDKClient,\n taskId: Hash,\n step: LiFiStep,\n timeout: number = 3_600_000 * 24,\n signal?: AbortSignal\n): Promise<WalletCallReceipt> => {\n const startTime = Date.now()\n return waitForResult(\n async () => {\n // Without this check, a task that stays PENDING is polled forever:\n // PENDING is not an error, so the retry limit does not apply.\n // TransactionFailed is not retried, so this ends the poll. Not final:\n // the relayer may still execute the task, so the action keeps its task\n // id and a resume waits for it again instead of signing a new one.\n if (Date.now() - startTime > timeout) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Relayed transaction timed out waiting for a result.'\n )\n }\n\n const result = await getRelayedTransactionStatus(\n client,\n {\n taskId,\n fromChain: step.action.fromChainId,\n toChain: step.action.toChainId,\n ...(step.tool !== 'custom' && { bridge: step.tool }),\n },\n { signal }\n ).catch((e) => {\n // A request that the abort ended is no failure of the relayer.\n if (process.env.NODE_ENV === 'development' && !signal?.aborted) {\n console.debug('Fetching status from relayer failed.', e)\n }\n return undefined\n })\n\n switch (result?.status) {\n case 'PENDING':\n return undefined\n case 'DONE': {\n const sending: ExtendedTransactionInfo | undefined =\n (result?.transactionStatus?.sending as ExtendedTransactionInfo) ||\n ((result as unknown as FullStatusData)\n ?.sending as ExtendedTransactionInfo)\n return {\n status: 'success',\n gasUsed: sending?.gasUsed,\n transactionHash: result?.metadata.txHash || sending?.txHash,\n transactionLink: sending?.txLink,\n } as unknown as WalletCallReceipt\n }\n case 'FAILED':\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.',\n undefined,\n { final: true }\n )\n default:\n throw new TransactionError(\n LiFiErrorCode.TransactionNotFound,\n 'Transaction not found.'\n )\n }\n },\n 5000,\n 3,\n (_, error) => {\n return !(\n error instanceof TransactionError &&\n error.code === LiFiErrorCode.TransactionFailed\n )\n },\n signal\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAa,mCAAmC,OAC9C,QACA,QACA,MACA,UAAkB,OAClB,WAC+B;CAC/B,MAAM,YAAY,KAAK,IAAI;CAC3B,OAAO,cACL,YAAY;EAMV,IAAI,KAAK,IAAI,IAAI,YAAY,SAC3B,MAAM,IAAI,iBACR,cAAc,mBACd,qDACF;EAGF,MAAM,SAAS,MAAM,4BACnB,QACA;GACE;GACA,WAAW,KAAK,OAAO;GACvB,SAAS,KAAK,OAAO;GACrB,GAAI,KAAK,SAAS,YAAY,EAAE,QAAQ,KAAK,KAAK;EACpD,GACA,EAAE,OAAO,CACX,CAAC,CAAC,OAAO,MAAM;GAEb,IAAI,QAAQ,IAAI,aAAa,iBAAiB,CAAC,QAAQ,SACrD,QAAQ,MAAM,wCAAwC,CAAC;EAG3D,CAAC;EAED,QAAQ,QAAQ,QAAhB;GACE,KAAK,WACH;GACF,KAAK,QAAQ;IACX,MAAM,UACH,QAAQ,mBAAmB,WAC1B,QACE;IACN,OAAO;KACL,QAAQ;KACR,SAAS,SAAS;KAClB,iBAAiB,QAAQ,SAAS,UAAU,SAAS;KACrD,iBAAiB,SAAS;IAC5B;GACF;GACA,KAAK,UACH,MAAM,IAAI,iBACR,cAAc,mBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;GACF,SACE,MAAM,IAAI,iBACR,cAAc,qBACd,wBACF;EACJ;CACF,GACA,KACA,IACC,GAAG,UAAU;EACZ,OAAO,EACL,iBAAiB,oBACjB,MAAM,SAAS,cAAc;CAEjC,GACA,MACF;AACF"}
|
|
@@ -34,13 +34,13 @@ async function waitForSafeTransactionExecution(client, { chainId, safeAddress, s
|
|
|
34
34
|
}
|
|
35
35
|
const tx = await safeClient.getTransaction(safeTxHash);
|
|
36
36
|
if (tx.isExecuted) {
|
|
37
|
-
if (!tx.isSuccessful) throw new TransactionError(LiFiErrorCode.TransactionFailed, "Safe transaction failed.");
|
|
37
|
+
if (!tx.isSuccessful) throw new TransactionError(LiFiErrorCode.TransactionFailed, "Safe transaction failed.", void 0, { final: true });
|
|
38
38
|
if (!tx.transactionHash) throw new TransactionError(LiFiErrorCode.TransactionFailed, "Safe transaction executed but no transaction hash returned.");
|
|
39
39
|
return tx.transactionHash;
|
|
40
40
|
}
|
|
41
41
|
if (pollCount % 3 === 0) {
|
|
42
42
|
const { results } = await safeClient.getTransactions(safeAddress);
|
|
43
|
-
if (results.find((t) => t.isExecuted && Number(t.nonce) >= originalNonce && t.safeTxHash !== safeTxHash)) throw new TransactionError(LiFiErrorCode.TransactionCanceled, "Safe transaction was replaced by another transaction.");
|
|
43
|
+
if (results.find((t) => t.isExecuted && Number(t.nonce) >= originalNonce && t.safeTxHash !== safeTxHash)) throw new TransactionError(LiFiErrorCode.TransactionCanceled, "Safe transaction was replaced by another transaction.", void 0, { final: true });
|
|
44
44
|
}
|
|
45
45
|
}, (poll) => Math.min(basePollingInterval + poll * 2e3, 3e4), Number.MAX_SAFE_INTEGER, (_attempts, error) => !(error instanceof TransactionError));
|
|
46
46
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForSafeTransactionExecution.js","names":[],"sources":["../../../src/actions/waitForSafeTransactionExecution.ts"],"sourcesContent":["import {\n LiFiErrorCode,\n type SDKClient,\n TransactionError,\n waitForResult,\n} from '@lifi/sdk'\nimport type { Address, Hash } from 'viem'\nimport { getSafeClient } from '../client/safeClient.js'\nimport { getSafeApiKey } from '../utils/getSafeApiKey.js'\n\nexport interface WaitForSafeTransactionExecutionProps {\n chainId: number\n safeAddress: Address\n signature: string\n pollingInterval?: number\n timeout?: number\n}\n\n/**\n * Polls the Safe Transaction Service until the transaction matching the given signature\n * is executed, then resolves with the on-chain transaction hash.\n *\n * @param client - {@link SDKClient}\n * @param props - {@link WaitForSafeTransactionExecutionProps}\n * @returns The on-chain transaction hash once the Safe transaction is executed.\n * @throws {TransactionError} If the transaction fails, is replaced, or polling times out.\n */\nexport async function waitForSafeTransactionExecution(\n client: SDKClient,\n {\n chainId,\n safeAddress,\n signature,\n pollingInterval,\n timeout: timeoutMs,\n }: WaitForSafeTransactionExecutionProps\n): Promise<Hash> {\n const basePollingInterval = pollingInterval ?? 10_000\n const timeout = timeoutMs ?? 3_600_000 * 24 // 24 hours default\n const safeApiKey = getSafeApiKey(client)\n const safeClient = getSafeClient(chainId, safeApiKey)\n let safeTxHash: Hash | undefined\n let originalNonce: number | undefined\n let pollCount = 0\n const normalizedSignature = signature.toLowerCase()\n const startTime = Date.now()\n\n try {\n return await waitForResult<Hash>(\n async () => {\n pollCount++\n\n if (Date.now() - startTime > timeout) {\n throw new Error('Safe transaction polling timed out')\n }\n\n // Resolve signature to safeTxHash\n if (!safeTxHash) {\n const { results } = await safeClient.getTransactions(safeAddress)\n\n const match = results.find((tx) =>\n tx.confirmations?.some(\n (c) => c.signature?.toLowerCase() === normalizedSignature\n )\n )\n if (!match) {\n return undefined\n }\n safeTxHash = match.safeTxHash as Hash\n originalNonce = Number(match.nonce)\n }\n\n // single-tx lookup for execution status\n const tx = await safeClient.getTransaction(safeTxHash)\n\n if (tx.isExecuted) {\n if (!tx.isSuccessful) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Safe transaction failed.'\n )\n }\n if (!tx.transactionHash) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Safe transaction executed but no transaction hash returned.'\n )\n }\n return tx.transactionHash as Hash\n }\n\n // Check for replacement every 3rd poll\n if (pollCount % 3 === 0) {\n const { results } = await safeClient.getTransactions(safeAddress)\n const replaced = results.find(\n (t) =>\n t.isExecuted &&\n Number(t.nonce) >= originalNonce! &&\n t.safeTxHash !== safeTxHash\n )\n if (replaced) {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Safe transaction was replaced by another transaction.'\n )\n }\n }\n\n return undefined\n },\n // Dynamic backoff: 10s → 30s, increasing by 2s each poll\n (poll) => Math.min(basePollingInterval + poll * 2_000, 30_000),\n Number.MAX_SAFE_INTEGER,\n (_attempts, error) => !(error instanceof TransactionError)\n )\n } catch (error) {\n if (error instanceof TransactionError) {\n throw error\n }\n // Timeout or maxRetries exhausted\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Safe transaction timed out waiting for execution.'\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,eAAsB,gCACpB,QACA,EACE,SACA,aACA,WACA,iBACA,SAAS,aAEI;CACf,MAAM,sBAAsB,mBAAmB;CAC/C,MAAM,UAAU,aAAa;CAC7B,MAAM,aAAa,cAAc,MAAM;CACvC,MAAM,aAAa,cAAc,SAAS,UAAU;CACpD,IAAI;CACJ,IAAI;CACJ,IAAI,YAAY;CAChB,MAAM,sBAAsB,UAAU,YAAY;CAClD,MAAM,YAAY,KAAK,IAAI;CAE3B,IAAI;EACF,OAAO,MAAM,cACX,YAAY;GACV;GAEA,IAAI,KAAK,IAAI,IAAI,YAAY,SAC3B,MAAM,IAAI,MAAM,oCAAoC;GAItD,IAAI,CAAC,YAAY;IACf,MAAM,EAAE,YAAY,MAAM,WAAW,gBAAgB,WAAW;IAEhE,MAAM,QAAQ,QAAQ,MAAM,OAC1B,GAAG,eAAe,MACf,MAAM,EAAE,WAAW,YAAY,MAAM,mBACxC,CACF;IACA,IAAI,CAAC,OACH;IAEF,aAAa,MAAM;IACnB,gBAAgB,OAAO,MAAM,KAAK;GACpC;GAGA,MAAM,KAAK,MAAM,WAAW,eAAe,UAAU;GAErD,IAAI,GAAG,YAAY;IACjB,IAAI,CAAC,GAAG,cACN,MAAM,IAAI,iBACR,cAAc,mBACd,
|
|
1
|
+
{"version":3,"file":"waitForSafeTransactionExecution.js","names":[],"sources":["../../../src/actions/waitForSafeTransactionExecution.ts"],"sourcesContent":["import {\n LiFiErrorCode,\n type SDKClient,\n TransactionError,\n waitForResult,\n} from '@lifi/sdk'\nimport type { Address, Hash } from 'viem'\nimport { getSafeClient } from '../client/safeClient.js'\nimport { getSafeApiKey } from '../utils/getSafeApiKey.js'\n\nexport interface WaitForSafeTransactionExecutionProps {\n chainId: number\n safeAddress: Address\n signature: string\n pollingInterval?: number\n timeout?: number\n}\n\n/**\n * Polls the Safe Transaction Service until the transaction matching the given signature\n * is executed, then resolves with the on-chain transaction hash.\n *\n * @param client - {@link SDKClient}\n * @param props - {@link WaitForSafeTransactionExecutionProps}\n * @returns The on-chain transaction hash once the Safe transaction is executed.\n * @throws {TransactionError} If the transaction fails, is replaced, or polling times out.\n */\nexport async function waitForSafeTransactionExecution(\n client: SDKClient,\n {\n chainId,\n safeAddress,\n signature,\n pollingInterval,\n timeout: timeoutMs,\n }: WaitForSafeTransactionExecutionProps\n): Promise<Hash> {\n const basePollingInterval = pollingInterval ?? 10_000\n const timeout = timeoutMs ?? 3_600_000 * 24 // 24 hours default\n const safeApiKey = getSafeApiKey(client)\n const safeClient = getSafeClient(chainId, safeApiKey)\n let safeTxHash: Hash | undefined\n let originalNonce: number | undefined\n let pollCount = 0\n const normalizedSignature = signature.toLowerCase()\n const startTime = Date.now()\n\n try {\n return await waitForResult<Hash>(\n async () => {\n pollCount++\n\n if (Date.now() - startTime > timeout) {\n throw new Error('Safe transaction polling timed out')\n }\n\n // Resolve signature to safeTxHash\n if (!safeTxHash) {\n const { results } = await safeClient.getTransactions(safeAddress)\n\n const match = results.find((tx) =>\n tx.confirmations?.some(\n (c) => c.signature?.toLowerCase() === normalizedSignature\n )\n )\n if (!match) {\n return undefined\n }\n safeTxHash = match.safeTxHash as Hash\n originalNonce = Number(match.nonce)\n }\n\n // single-tx lookup for execution status\n const tx = await safeClient.getTransaction(safeTxHash)\n\n if (tx.isExecuted) {\n if (!tx.isSuccessful) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Safe transaction failed.',\n undefined,\n { final: true }\n )\n }\n if (!tx.transactionHash) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Safe transaction executed but no transaction hash returned.'\n )\n }\n return tx.transactionHash as Hash\n }\n\n // Check for replacement every 3rd poll\n if (pollCount % 3 === 0) {\n const { results } = await safeClient.getTransactions(safeAddress)\n const replaced = results.find(\n (t) =>\n t.isExecuted &&\n Number(t.nonce) >= originalNonce! &&\n t.safeTxHash !== safeTxHash\n )\n if (replaced) {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Safe transaction was replaced by another transaction.',\n undefined,\n { final: true }\n )\n }\n }\n\n return undefined\n },\n // Dynamic backoff: 10s → 30s, increasing by 2s each poll\n (poll) => Math.min(basePollingInterval + poll * 2_000, 30_000),\n Number.MAX_SAFE_INTEGER,\n (_attempts, error) => !(error instanceof TransactionError)\n )\n } catch (error) {\n if (error instanceof TransactionError) {\n throw error\n }\n // Timeout or maxRetries exhausted\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Safe transaction timed out waiting for execution.'\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,eAAsB,gCACpB,QACA,EACE,SACA,aACA,WACA,iBACA,SAAS,aAEI;CACf,MAAM,sBAAsB,mBAAmB;CAC/C,MAAM,UAAU,aAAa;CAC7B,MAAM,aAAa,cAAc,MAAM;CACvC,MAAM,aAAa,cAAc,SAAS,UAAU;CACpD,IAAI;CACJ,IAAI;CACJ,IAAI,YAAY;CAChB,MAAM,sBAAsB,UAAU,YAAY;CAClD,MAAM,YAAY,KAAK,IAAI;CAE3B,IAAI;EACF,OAAO,MAAM,cACX,YAAY;GACV;GAEA,IAAI,KAAK,IAAI,IAAI,YAAY,SAC3B,MAAM,IAAI,MAAM,oCAAoC;GAItD,IAAI,CAAC,YAAY;IACf,MAAM,EAAE,YAAY,MAAM,WAAW,gBAAgB,WAAW;IAEhE,MAAM,QAAQ,QAAQ,MAAM,OAC1B,GAAG,eAAe,MACf,MAAM,EAAE,WAAW,YAAY,MAAM,mBACxC,CACF;IACA,IAAI,CAAC,OACH;IAEF,aAAa,MAAM;IACnB,gBAAgB,OAAO,MAAM,KAAK;GACpC;GAGA,MAAM,KAAK,MAAM,WAAW,eAAe,UAAU;GAErD,IAAI,GAAG,YAAY;IACjB,IAAI,CAAC,GAAG,cACN,MAAM,IAAI,iBACR,cAAc,mBACd,4BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;IAEF,IAAI,CAAC,GAAG,iBACN,MAAM,IAAI,iBACR,cAAc,mBACd,6DACF;IAEF,OAAO,GAAG;GACZ;GAGA,IAAI,YAAY,MAAM,GAAG;IACvB,MAAM,EAAE,YAAY,MAAM,WAAW,gBAAgB,WAAW;IAOhE,IANiB,QAAQ,MACtB,MACC,EAAE,cACF,OAAO,EAAE,KAAK,KAAK,iBACnB,EAAE,eAAe,UAEV,GACT,MAAM,IAAI,iBACR,cAAc,qBACd,yDACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;GAEJ;EAGF,IAEC,SAAS,KAAK,IAAI,sBAAsB,OAAO,KAAO,GAAM,GAC7D,OAAO,mBACN,WAAW,UAAU,EAAE,iBAAiB,iBAC3C;CACF,SAAS,OAAO;EACd,IAAI,iBAAiB,kBACnB,MAAM;EAGR,MAAM,IAAI,iBACR,cAAc,mBACd,mDACF;CACF;AACF"}
|
|
@@ -9,8 +9,8 @@ async function waitForTransactionReceipt(client, { client: viemClient, chainId,
|
|
|
9
9
|
transactionReceipt = result.transactionReceipt;
|
|
10
10
|
replacementReason = result.replacementReason;
|
|
11
11
|
}
|
|
12
|
-
if (transactionReceipt?.status === "reverted") throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction was reverted.");
|
|
13
|
-
if (replacementReason === "cancelled" || replacementReason === "replaced") throw new TransactionError(LiFiErrorCode.TransactionCanceled, "Transaction was canceled or replaced.");
|
|
12
|
+
if (transactionReceipt?.status === "reverted") throw new TransactionError(LiFiErrorCode.TransactionFailed, "Transaction was reverted.", void 0, { final: true });
|
|
13
|
+
if (replacementReason === "cancelled" || replacementReason === "replaced") throw new TransactionError(LiFiErrorCode.TransactionCanceled, "Transaction was canceled or replaced.", void 0, { final: true });
|
|
14
14
|
return transactionReceipt;
|
|
15
15
|
}
|
|
16
16
|
async function waitForReceipt(client, txHash, onReplaced) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForTransactionReceipt.js","names":["waitForTransactionReceiptInternal"],"sources":["../../../src/actions/waitForTransactionReceipt.ts"],"sourcesContent":["import {\n type ChainId,\n LiFiErrorCode,\n type SDKClient,\n TransactionError,\n} from '@lifi/sdk'\nimport type {\n Chain,\n Client,\n Hash,\n ReplacementReason,\n ReplacementReturnType,\n TransactionReceipt,\n} from 'viem'\nimport { waitForTransactionReceipt as waitForTransactionReceiptInternal } from 'viem/actions'\nimport { getPublicClient } from '../client/publicClient.js'\n\ninterface WaitForTransactionReceiptProps {\n client: Client\n chainId: ChainId\n txHash: Hash\n onReplaced?: (response: ReplacementReturnType<Chain | undefined>) => void\n}\n\nexport async function waitForTransactionReceipt(\n client: SDKClient,\n {\n client: viemClient,\n chainId,\n txHash,\n onReplaced,\n }: WaitForTransactionReceiptProps\n): Promise<TransactionReceipt | undefined> {\n let { transactionReceipt, replacementReason } = await waitForReceipt(\n viemClient,\n txHash,\n onReplaced\n )\n\n if (!transactionReceipt?.status) {\n const publicClient = await getPublicClient(client, chainId)\n const result = await waitForReceipt(publicClient, txHash, onReplaced)\n transactionReceipt = result.transactionReceipt\n replacementReason = result.replacementReason\n }\n\n if (transactionReceipt?.status === 'reverted') {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.'\n )\n }\n // We should only allow repriced transaction to continue the execution.\n // Cancelled and replaced transactions should be treated as failed.\n if (replacementReason === 'cancelled' || replacementReason === 'replaced') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Transaction was canceled or replaced.'\n )\n }\n\n return transactionReceipt\n}\n\nasync function waitForReceipt(\n client: Client,\n txHash: Hash,\n onReplaced?: (response: ReplacementReturnType<Chain | undefined>) => void\n): Promise<{\n transactionReceipt?: TransactionReceipt\n replacementReason?: ReplacementReason\n}> {\n let replacementReason: ReplacementReason | undefined\n let transactionReceipt: TransactionReceipt | undefined\n\n try {\n transactionReceipt = await waitForTransactionReceiptInternal(client, {\n hash: txHash,\n onReplaced: (response) => {\n replacementReason = response.reason\n onReplaced?.(response)\n },\n })\n } catch {\n // We can ignore errors from waitForTransactionReceipt as we have a status check fallback\n }\n\n return { transactionReceipt, replacementReason }\n}\n"],"mappings":";;;;AAwBA,eAAsB,0BACpB,QACA,EACE,QAAQ,YACR,SACA,QACA,cAEuC;CACzC,IAAI,EAAE,oBAAoB,sBAAsB,MAAM,eACpD,YACA,QACA,UACF;CAEA,IAAI,CAAC,oBAAoB,QAAQ;EAE/B,MAAM,SAAS,MAAM,eAAe,MADT,gBAAgB,QAAQ,OAAO,GACR,QAAQ,UAAU;EACpE,qBAAqB,OAAO;EAC5B,oBAAoB,OAAO;CAC7B;CAEA,IAAI,oBAAoB,WAAW,YACjC,MAAM,IAAI,iBACR,cAAc,mBACd,
|
|
1
|
+
{"version":3,"file":"waitForTransactionReceipt.js","names":["waitForTransactionReceiptInternal"],"sources":["../../../src/actions/waitForTransactionReceipt.ts"],"sourcesContent":["import {\n type ChainId,\n LiFiErrorCode,\n type SDKClient,\n TransactionError,\n} from '@lifi/sdk'\nimport type {\n Chain,\n Client,\n Hash,\n ReplacementReason,\n ReplacementReturnType,\n TransactionReceipt,\n} from 'viem'\nimport { waitForTransactionReceipt as waitForTransactionReceiptInternal } from 'viem/actions'\nimport { getPublicClient } from '../client/publicClient.js'\n\ninterface WaitForTransactionReceiptProps {\n client: Client\n chainId: ChainId\n txHash: Hash\n onReplaced?: (response: ReplacementReturnType<Chain | undefined>) => void\n}\n\nexport async function waitForTransactionReceipt(\n client: SDKClient,\n {\n client: viemClient,\n chainId,\n txHash,\n onReplaced,\n }: WaitForTransactionReceiptProps\n): Promise<TransactionReceipt | undefined> {\n let { transactionReceipt, replacementReason } = await waitForReceipt(\n viemClient,\n txHash,\n onReplaced\n )\n\n if (!transactionReceipt?.status) {\n const publicClient = await getPublicClient(client, chainId)\n const result = await waitForReceipt(publicClient, txHash, onReplaced)\n transactionReceipt = result.transactionReceipt\n replacementReason = result.replacementReason\n }\n\n if (transactionReceipt?.status === 'reverted') {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n 'Transaction was reverted.',\n undefined,\n { final: true }\n )\n }\n // We should only allow repriced transaction to continue the execution.\n // Cancelled and replaced transactions should be treated as failed.\n if (replacementReason === 'cancelled' || replacementReason === 'replaced') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'Transaction was canceled or replaced.',\n undefined,\n { final: true }\n )\n }\n\n return transactionReceipt\n}\n\nasync function waitForReceipt(\n client: Client,\n txHash: Hash,\n onReplaced?: (response: ReplacementReturnType<Chain | undefined>) => void\n): Promise<{\n transactionReceipt?: TransactionReceipt\n replacementReason?: ReplacementReason\n}> {\n let replacementReason: ReplacementReason | undefined\n let transactionReceipt: TransactionReceipt | undefined\n\n try {\n transactionReceipt = await waitForTransactionReceiptInternal(client, {\n hash: txHash,\n onReplaced: (response) => {\n replacementReason = response.reason\n onReplaced?.(response)\n },\n })\n } catch {\n // We can ignore errors from waitForTransactionReceipt as we have a status check fallback\n }\n\n return { transactionReceipt, replacementReason }\n}\n"],"mappings":";;;;AAwBA,eAAsB,0BACpB,QACA,EACE,QAAQ,YACR,SACA,QACA,cAEuC;CACzC,IAAI,EAAE,oBAAoB,sBAAsB,MAAM,eACpD,YACA,QACA,UACF;CAEA,IAAI,CAAC,oBAAoB,QAAQ;EAE/B,MAAM,SAAS,MAAM,eAAe,MADT,gBAAgB,QAAQ,OAAO,GACR,QAAQ,UAAU;EACpE,qBAAqB,OAAO;EAC5B,oBAAoB,OAAO;CAC7B;CAEA,IAAI,oBAAoB,WAAW,YACjC,MAAM,IAAI,iBACR,cAAc,mBACd,6BACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CAIF,IAAI,sBAAsB,eAAe,sBAAsB,YAC7D,MAAM,IAAI,iBACR,cAAc,qBACd,yCACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;CAGF,OAAO;AACT;AAEA,eAAe,eACb,QACA,QACA,YAIC;CACD,IAAI;CACJ,IAAI;CAEJ,IAAI;EACF,qBAAqB,MAAMA,4BAAkC,QAAQ;GACnE,MAAM;GACN,aAAa,aAAa;IACxB,oBAAoB,SAAS;IAC7B,aAAa,QAAQ;GACvB;EACF,CAAC;CACH,QAAQ,CAER;CAEA,OAAO;EAAE;EAAoB;CAAkB;AACjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClient.d.ts","names":[],"sources":["../../../src/client/publicClient.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"publicClient.d.ts","names":[],"sources":["../../../src/client/publicClient.ts"],"mappings":";;;;;;;;;qBAkBa,kBACX,QAAQ,WACR,oBACC,QAAQ"}
|
|
@@ -3,15 +3,25 @@ import { ChainId, ChainType } from "@lifi/sdk";
|
|
|
3
3
|
import { createClient, fallback, http, webSocket } from "viem";
|
|
4
4
|
import { mainnet } from "viem/chains";
|
|
5
5
|
//#region src/client/publicClient.ts
|
|
6
|
-
const publicClients =
|
|
6
|
+
const publicClients = /* @__PURE__ */ new Map();
|
|
7
7
|
/**
|
|
8
8
|
* Get an instance of a provider for a specific chain
|
|
9
9
|
* @param client - The SDK client
|
|
10
10
|
* @param chainId - Id of the chain the provider is for
|
|
11
11
|
* @returns The public client for the given chain
|
|
12
12
|
*/
|
|
13
|
-
const getPublicClient =
|
|
14
|
-
|
|
13
|
+
const getPublicClient = (client, chainId) => {
|
|
14
|
+
let publicClient = publicClients.get(chainId);
|
|
15
|
+
if (!publicClient) {
|
|
16
|
+
publicClient = buildPublicClient(client, chainId).catch((error) => {
|
|
17
|
+
publicClients.delete(chainId);
|
|
18
|
+
throw error;
|
|
19
|
+
});
|
|
20
|
+
publicClients.set(chainId, publicClient);
|
|
21
|
+
}
|
|
22
|
+
return publicClient;
|
|
23
|
+
};
|
|
24
|
+
const buildPublicClient = async (client, chainId) => {
|
|
15
25
|
const fallbackTransports = (await client.getRpcUrlsByChainId(chainId)).map((url) => url.startsWith("wss") ? webSocket(url) : http(url, { batch: { batchSize: 64 } }));
|
|
16
26
|
const _chain = await client.getChainById(chainId);
|
|
17
27
|
const chain = {
|
|
@@ -35,12 +45,11 @@ const getPublicClient = async (client, chainId) => {
|
|
|
35
45
|
};
|
|
36
46
|
}
|
|
37
47
|
const provider = client.getProvider(ChainType.EVM);
|
|
38
|
-
|
|
48
|
+
return createClient({
|
|
39
49
|
chain,
|
|
40
50
|
transport: fallback(fallbackTransports, provider?.options?.fallbackTransportConfig),
|
|
41
51
|
batch: { multicall: true }
|
|
42
52
|
});
|
|
43
|
-
return publicClients[chainId];
|
|
44
53
|
};
|
|
45
54
|
//#endregion
|
|
46
55
|
export { getPublicClient };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClient.js","names":[],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import { ChainId, ChainType, type SDKClient } from '@lifi/sdk'\nimport type { Client } from 'viem'\nimport { type Address, createClient, fallback, http, webSocket } from 'viem'\nimport { type Chain, mainnet } from 'viem/chains'\nimport { UNS_PROXY_READER_ADDRESSES } from '../actions/constants.js'\nimport type { EthereumSDKProvider } from '../types.js'\n\n//
|
|
1
|
+
{"version":3,"file":"publicClient.js","names":[],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import { ChainId, ChainType, type SDKClient } from '@lifi/sdk'\nimport type { Client } from 'viem'\nimport { type Address, createClient, fallback, http, webSocket } from 'viem'\nimport { type Chain, mainnet } from 'viem/chains'\nimport { UNS_PROXY_READER_ADDRESSES } from '../actions/constants.js'\nimport type { EthereumSDKProvider } from '../types.js'\n\n// One client per chain. The cache holds the build promise, not the client,\n// so concurrent first calls share one build: each extra client would keep\n// its own fallback ranking loop running.\nconst publicClients = new Map<number, Promise<Client>>()\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getPublicClient = (\n client: SDKClient,\n chainId: number\n): Promise<Client> => {\n let publicClient = publicClients.get(chainId)\n if (!publicClient) {\n // A failed build is removed, so the next call builds again.\n publicClient = buildPublicClient(client, chainId).catch((error) => {\n publicClients.delete(chainId)\n throw error\n })\n publicClients.set(chainId, publicClient)\n }\n return publicClient\n}\n\nconst buildPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<Client> => {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n url.startsWith('wss')\n ? webSocket(url)\n : http(url, {\n batch: {\n batchSize: 64,\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n // Add ENS contracts\n if (chain.id === ChainId.ETH) {\n chain.contracts = {\n ...mainnet.contracts,\n ...chain.contracts,\n }\n }\n\n // Add UNS contracts for supported chains\n if (chain.id === ChainId.ETH || chain.id === ChainId.POL) {\n const unsProxyAddress = UNS_PROXY_READER_ADDRESSES[chain.id]\n\n chain.contracts = {\n ...chain.contracts,\n unsProxyReader: { address: unsProxyAddress as Address },\n }\n }\n\n const provider = client.getProvider(ChainType.EVM) as\n | EthereumSDKProvider\n | undefined\n return createClient({\n chain: chain,\n transport: fallback(\n fallbackTransports,\n provider?.options?.fallbackTransportConfig\n ),\n batch: {\n multicall: true,\n },\n })\n}\n"],"mappings":";;;;;AAUA,MAAM,gCAAgB,IAAI,IAA6B;;;;;;;AAQvD,MAAa,mBACX,QACA,YACoB;CACpB,IAAI,eAAe,cAAc,IAAI,OAAO;CAC5C,IAAI,CAAC,cAAc;EAEjB,eAAe,kBAAkB,QAAQ,OAAO,CAAC,CAAC,OAAO,UAAU;GACjE,cAAc,OAAO,OAAO;GAC5B,MAAM;EACR,CAAC;EACD,cAAc,IAAI,SAAS,YAAY;CACzC;CACA,OAAO;AACT;AAEA,MAAM,oBAAoB,OACxB,QACA,YACoB;CAEpB,MAAM,sBAAqB,MADR,OAAO,oBAAoB,OAAO,EAAA,CACrB,KAAK,QACnC,IAAI,WAAW,KAAK,IAChB,UAAU,GAAG,IACb,KAAK,KAAK,EACR,OAAO,EACL,WAAW,GACb,EACF,CAAC,CACP;CACA,MAAM,SAAS,MAAM,OAAO,aAAa,OAAO;CAChD,MAAM,QAAe;EACnB,GAAG;EACH,GAAG,OAAO;EACV,MAAM,OAAO,SAAS;EACtB,SAAS;GACP,SAAS,EAAE,MAAM,OAAO,SAAS,QAAQ;GACzC,QAAQ,EAAE,MAAM,OAAO,SAAS,QAAQ;EAC1C;CACF;CAEA,IAAI,MAAM,OAAO,QAAQ,KACvB,MAAM,YAAY;EAChB,GAAG,QAAQ;EACX,GAAG,MAAM;CACX;CAIF,IAAI,MAAM,OAAO,QAAQ,OAAO,MAAM,OAAO,QAAQ,KAAK;EACxD,MAAM,kBAAkB,2BAA2B,MAAM;EAEzD,MAAM,YAAY;GAChB,GAAG,MAAM;GACT,gBAAgB,EAAE,SAAS,gBAA2B;EACxD;CACF;CAEA,MAAM,WAAW,OAAO,YAAY,UAAU,GAAG;CAGjD,OAAO,aAAa;EACX;EACP,WAAW,SACT,oBACA,UAAU,SAAS,uBACrB;EACA,OAAO,EACL,WAAW,KACb;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumStepExecutor.d.ts","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"EthereumStepExecutor.d.ts","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"mappings":";;;;UAqCU,oCAAoC;EAC5C,QAAQ;EACR,eAAe,oBAAoB,QAAQ;EAC3C;;qBAGW,6BAA6B;UAChC;UACA;UACA;UACA;EAER,YAAY,SAAS;UAOb;WAOC,cACP,OAAO,OACP,OAAO,kBACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;EAItB,cACE,MAAM,kBACN,2BACC,QAAQ;WAgCF,gBACP,aAAa,4BACZ,QAAQ;WA0BF,iBACP,SAAS,gCACR"}
|
|
@@ -13,7 +13,7 @@ import { EthereumWaitForTransactionStatusTask } from "./tasks/EthereumWaitForTra
|
|
|
13
13
|
import { EthereumWaitForTransactionTask } from "./tasks/EthereumWaitForTransactionTask.js";
|
|
14
14
|
import { shouldCheckForAllowance } from "./tasks/helpers/shouldCheckForAllowance.js";
|
|
15
15
|
import { switchChain } from "./tasks/helpers/switchChain.js";
|
|
16
|
-
import { BaseStepExecutor, LiFiErrorCode, TaskPipeline, TransactionError, createDefaultStorage } from "@lifi/sdk";
|
|
16
|
+
import { BaseStepExecutor, LiFiErrorCode, TaskPipeline, TransactionError, createDefaultStorage, hasOpenTransaction } from "@lifi/sdk";
|
|
17
17
|
import { getAddresses } from "viem/actions";
|
|
18
18
|
import { getAction } from "viem/utils";
|
|
19
19
|
//#region src/core/EthereumStepExecutor.ts
|
|
@@ -72,13 +72,14 @@ var EthereumStepExecutor = class extends BaseStepExecutor {
|
|
|
72
72
|
new EthereumWaitForTransactionStatusTask()
|
|
73
73
|
];
|
|
74
74
|
const doCheckAllowance = shouldCheckForAllowance(step, isBridgeExecution, isFromNativeToken, this.statusManager);
|
|
75
|
-
let
|
|
76
|
-
if (doCheckAllowance)
|
|
75
|
+
let firstTask;
|
|
76
|
+
if (doCheckAllowance) firstTask = EthereumCheckPermitsTask;
|
|
77
77
|
else {
|
|
78
78
|
const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
79
|
-
|
|
79
|
+
firstTask = hasOpenTransaction(swapOrBridgeAction) ? swapOrBridgeAction?.status === "DONE" ? EthereumWaitForTransactionStatusTask : EthereumWaitForTransactionTask : EthereumCheckBalanceTask;
|
|
80
80
|
}
|
|
81
|
-
const firstTaskIndex = tasks.findIndex((task) => task.constructor
|
|
81
|
+
const firstTaskIndex = tasks.findIndex((task) => task.constructor === firstTask);
|
|
82
|
+
if (firstTaskIndex === -1) throw new TransactionError(LiFiErrorCode.InternalError, "EthereumStepExecutor.createPipeline: first task not found");
|
|
82
83
|
const tasksToRun = tasks.slice(firstTaskIndex);
|
|
83
84
|
return new TaskPipeline(tasksToRun);
|
|
84
85
|
};
|