@lifi/sdk-provider-ethereum 4.0.8 → 4.0.9
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 +12 -0
- package/dist/cjs/EthereumProvider.js +2 -1
- package/dist/cjs/EthereumProvider.js.map +1 -1
- package/dist/cjs/actions/checkPermitSupport.d.ts +3 -2
- package/dist/cjs/actions/checkPermitSupport.js +8 -3
- package/dist/cjs/actions/checkPermitSupport.js.map +1 -1
- package/dist/cjs/actions/getAccountCode.d.ts +8 -3
- package/dist/cjs/actions/getAccountCode.js +10 -4
- package/dist/cjs/actions/getAccountCode.js.map +1 -1
- package/dist/cjs/actions/getAllowance.js +7 -6
- package/dist/cjs/actions/getAllowance.js.map +1 -1
- package/dist/cjs/actions/getEthereumBalance.js.map +1 -1
- package/dist/cjs/actions/isBatchingSupported.js.map +1 -1
- package/dist/cjs/actions/isSafeSignature.js +2 -1
- package/dist/cjs/actions/isSafeSignature.js.map +1 -1
- package/dist/cjs/actions/resolveENSAddress.js +2 -1
- package/dist/cjs/actions/resolveENSAddress.js.map +1 -1
- package/dist/cjs/actions/resolveUNSAddress.js.map +1 -1
- package/dist/cjs/actions/setAllowance.js.map +1 -1
- package/dist/cjs/actions/waitForBatchTransactionReceipt.js +1 -1
- package/dist/cjs/actions/waitForBatchTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/waitForRelayedTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/waitForSafeTransactionExecution.js +3 -2
- package/dist/cjs/actions/waitForSafeTransactionExecution.js.map +1 -1
- package/dist/cjs/actions/waitForTransactionReceipt.js.map +1 -1
- package/dist/cjs/client/publicClient.js.map +1 -1
- package/dist/cjs/client/safeClient.js +1 -1
- package/dist/cjs/client/safeClient.js.map +1 -1
- package/dist/cjs/core/EthereumStepExecutor.js +2 -1
- package/dist/cjs/core/EthereumStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js +3 -2
- package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckAllowanceTask.js +3 -3
- package/dist/cjs/core/tasks/EthereumCheckAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckBalanceTask.js +3 -2
- package/dist/cjs/core/tasks/EthereumCheckBalanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckPermitsTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumNativePermitTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumPrepareTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumRelayedSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumRelayedWaitForTransactionTask.js +2 -1
- package/dist/cjs/core/tasks/EthereumRelayedWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumResetAllowanceTask.js +3 -3
- package/dist/cjs/core/tasks/EthereumResetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js +3 -3
- package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js +6 -5
- package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumStandardWaitForTransactionTask.js +3 -2
- package/dist/cjs/core/tasks/EthereumStandardWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js +2 -1
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/getUpdatedStep.js +3 -2
- package/dist/cjs/core/tasks/helpers/getUpdatedStep.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/resolvePermit2Support.d.ts +27 -0
- package/dist/cjs/core/tasks/helpers/resolvePermit2Support.js +47 -0
- package/dist/cjs/core/tasks/helpers/resolvePermit2Support.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/switchChain.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/updateActionWithReceipt.js.map +1 -1
- package/dist/cjs/errors/parseEthereumErrors.js +2 -1
- package/dist/cjs/errors/parseEthereumErrors.js.map +1 -1
- package/dist/cjs/hyperliquid/agentWallet.js +4 -3
- package/dist/cjs/hyperliquid/agentWallet.js.map +1 -1
- package/dist/cjs/permits/allowanceTransfer.js.map +1 -1
- package/dist/cjs/permits/canAccountUsePermit2.d.ts +24 -0
- package/dist/cjs/permits/canAccountUsePermit2.js +87 -0
- package/dist/cjs/permits/canAccountUsePermit2.js.map +1 -0
- package/dist/cjs/permits/encodeNativePermitData.js.map +1 -1
- package/dist/cjs/permits/encodePermit2Data.js.map +1 -1
- package/dist/cjs/permits/getNativePermit.js +3 -2
- package/dist/cjs/permits/getNativePermit.js.map +1 -1
- package/dist/cjs/permits/signPermit2Message.js.map +1 -1
- package/dist/cjs/permits/signatureTransfer.js.map +1 -1
- package/dist/cjs/types.d.ts +9 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/abi.js.map +1 -1
- package/dist/cjs/utils/getActionWithFallback.js +2 -1
- package/dist/cjs/utils/getActionWithFallback.js.map +1 -1
- package/dist/cjs/utils/isValidSignature.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.js +2 -1
- package/dist/esm/EthereumProvider.js.map +1 -1
- package/dist/esm/actions/checkPermitSupport.d.ts +3 -2
- package/dist/esm/actions/checkPermitSupport.d.ts.map +1 -1
- package/dist/esm/actions/checkPermitSupport.js +8 -3
- package/dist/esm/actions/checkPermitSupport.js.map +1 -1
- package/dist/esm/actions/getAccountCode.d.ts +8 -3
- package/dist/esm/actions/getAccountCode.d.ts.map +1 -1
- package/dist/esm/actions/getAccountCode.js +10 -4
- package/dist/esm/actions/getAccountCode.js.map +1 -1
- package/dist/esm/actions/getAllowance.js +7 -6
- package/dist/esm/actions/getAllowance.js.map +1 -1
- package/dist/esm/actions/isSafeSignature.js +2 -1
- package/dist/esm/actions/isSafeSignature.js.map +1 -1
- package/dist/esm/actions/resolveENSAddress.js +2 -1
- package/dist/esm/actions/resolveENSAddress.js.map +1 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.js +1 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/waitForSafeTransactionExecution.js +3 -2
- package/dist/esm/actions/waitForSafeTransactionExecution.js.map +1 -1
- package/dist/esm/client/safeClient.js +1 -1
- package/dist/esm/client/safeClient.js.map +1 -1
- package/dist/esm/core/EthereumStepExecutor.js +2 -1
- package/dist/esm/core/EthereumStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js +3 -2
- package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumCheckAllowanceTask.js +3 -3
- package/dist/esm/core/tasks/EthereumCheckAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumCheckBalanceTask.js +3 -2
- package/dist/esm/core/tasks/EthereumCheckBalanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.js +2 -1
- package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumResetAllowanceTask.js +3 -3
- package/dist/esm/core/tasks/EthereumResetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumSetAllowanceTask.js +3 -3
- package/dist/esm/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js +6 -5
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumStandardWaitForTransactionTask.js +3 -2
- package/dist/esm/core/tasks/EthereumStandardWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js +2 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
- package/dist/esm/core/tasks/helpers/getUpdatedStep.js +3 -2
- package/dist/esm/core/tasks/helpers/getUpdatedStep.js.map +1 -1
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.d.ts +27 -0
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.js +46 -0
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.js.map +1 -0
- package/dist/esm/errors/parseEthereumErrors.js +2 -1
- package/dist/esm/errors/parseEthereumErrors.js.map +1 -1
- package/dist/esm/hyperliquid/agentWallet.js +4 -3
- package/dist/esm/hyperliquid/agentWallet.js.map +1 -1
- package/dist/esm/permits/canAccountUsePermit2.d.ts +24 -0
- package/dist/esm/permits/canAccountUsePermit2.d.ts.map +1 -0
- package/dist/esm/permits/canAccountUsePermit2.js +86 -0
- package/dist/esm/permits/canAccountUsePermit2.js.map +1 -0
- package/dist/esm/permits/getNativePermit.js +3 -2
- package/dist/esm/permits/getNativePermit.js.map +1 -1
- package/dist/esm/types.d.ts +9 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/getActionWithFallback.js +2 -1
- package/dist/esm/utils/getActionWithFallback.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/actions/checkPermitSupport.ts +13 -4
- package/src/actions/getAccountCode.ts +14 -4
- package/src/core/tasks/EthereumCheckAllowanceTask.ts +4 -15
- package/src/core/tasks/EthereumResetAllowanceTask.ts +3 -8
- package/src/core/tasks/EthereumSetAllowanceTask.ts +3 -8
- package/src/core/tasks/EthereumStandardSignAndExecuteTask.ts +8 -10
- package/src/core/tasks/helpers/resolvePermit2Support.ts +76 -0
- package/src/permits/canAccountUsePermit2.ts +106 -0
- package/src/types.ts +9 -0
- package/src/version.ts +1 -1
- package/dist/cjs/core/tasks/helpers/isPermit2Supported.d.ts +0 -6
- package/dist/cjs/core/tasks/helpers/isPermit2Supported.js +0 -9
- package/dist/cjs/core/tasks/helpers/isPermit2Supported.js.map +0 -1
- package/dist/esm/core/tasks/helpers/isPermit2Supported.d.ts +0 -6
- package/dist/esm/core/tasks/helpers/isPermit2Supported.d.ts.map +0 -1
- package/dist/esm/core/tasks/helpers/isPermit2Supported.js +0 -8
- package/dist/esm/core/tasks/helpers/isPermit2Supported.js.map +0 -1
- package/src/core/tasks/helpers/isPermit2Supported.ts +0 -28
|
@@ -13,8 +13,9 @@ async function getEthereumExecutionStrategy(context, forceRecalculate = false) {
|
|
|
13
13
|
const atomicityNotReady = !!retryParams?.atomicityNotReady;
|
|
14
14
|
if (require_utils_isRelayerStep.isRelayerStep(step)) return "relayed";
|
|
15
15
|
if (atomicityNotReady || step.tool === "thorswap") return "standard";
|
|
16
|
+
const updatedClient = await checkClient(step) ?? ethereumClient;
|
|
16
17
|
return await require_actions_isBatchingSupported.isBatchingSupported(client, {
|
|
17
|
-
client:
|
|
18
|
+
client: updatedClient,
|
|
18
19
|
chainId: fromChain.id
|
|
19
20
|
}) ? "batched" : "standard";
|
|
20
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEthereumExecutionStrategy.js","names":["isRelayerStep","isBatchingSupported"],"sources":["../../../../../src/core/tasks/helpers/getEthereumExecutionStrategy.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport { isBatchingSupported } from '../../../actions/isBatchingSupported.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { isRelayerStep } from '../../../utils/isRelayerStep.js'\n\n/**\n * Determines the execution strategy: 'relayed', 'batched', or 'standard'.\n * Falls back to 'standard' when EIP-5792 batching is unavailable,\n * the wallet rejected the 7702 upgrade, or the tool doesn't support it.\n */\nexport async function getEthereumExecutionStrategy(\n context: EthereumStepExecutorContext,\n forceRecalculate: boolean = false\n): Promise<TransactionMethodType> {\n const {\n step,\n checkClient,\n retryParams,\n client,\n fromChain,\n ethereumClient,\n executionStrategy: executionStrategyContext,\n } = context\n\n if (!forceRecalculate && executionStrategyContext) {\n return executionStrategyContext\n }\n\n const atomicityNotReady = !!retryParams?.atomicityNotReady\n const isRelayer = isRelayerStep(step)\n if (isRelayer) {\n return 'relayed'\n }\n\n if (atomicityNotReady || step.tool === 'thorswap') {\n return 'standard'\n }\n\n const updatedClient = (await checkClient(step)) ?? ethereumClient\n const batchingSupported = await isBatchingSupported(client, {\n client: updatedClient,\n chainId: fromChain.id,\n })\n return batchingSupported ? 'batched' : 'standard'\n}\n"],"mappings":";;;;;;;;;AAUA,eAAsB,6BACpB,SACA,mBAA4B,OACI;CAChC,MAAM,EACJ,MACA,aACA,aACA,QACA,WACA,gBACA,mBAAmB,6BACjB;CAEJ,IAAI,CAAC,oBAAoB,0BACvB,OAAO;CAGT,MAAM,oBAAoB,CAAC,CAAC,aAAa;CAEzC,IADkBA,4BAAAA,cAAc,IACpB,GACV,OAAO;CAGT,IAAI,qBAAqB,KAAK,SAAS,YACrC,OAAO;
|
|
1
|
+
{"version":3,"file":"getEthereumExecutionStrategy.js","names":["isRelayerStep","isBatchingSupported"],"sources":["../../../../../src/core/tasks/helpers/getEthereumExecutionStrategy.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport { isBatchingSupported } from '../../../actions/isBatchingSupported.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { isRelayerStep } from '../../../utils/isRelayerStep.js'\n\n/**\n * Determines the execution strategy: 'relayed', 'batched', or 'standard'.\n * Falls back to 'standard' when EIP-5792 batching is unavailable,\n * the wallet rejected the 7702 upgrade, or the tool doesn't support it.\n */\nexport async function getEthereumExecutionStrategy(\n context: EthereumStepExecutorContext,\n forceRecalculate: boolean = false\n): Promise<TransactionMethodType> {\n const {\n step,\n checkClient,\n retryParams,\n client,\n fromChain,\n ethereumClient,\n executionStrategy: executionStrategyContext,\n } = context\n\n if (!forceRecalculate && executionStrategyContext) {\n return executionStrategyContext\n }\n\n const atomicityNotReady = !!retryParams?.atomicityNotReady\n const isRelayer = isRelayerStep(step)\n if (isRelayer) {\n return 'relayed'\n }\n\n if (atomicityNotReady || step.tool === 'thorswap') {\n return 'standard'\n }\n\n const updatedClient = (await checkClient(step)) ?? ethereumClient\n const batchingSupported = await isBatchingSupported(client, {\n client: updatedClient,\n chainId: fromChain.id,\n })\n return batchingSupported ? 'batched' : 'standard'\n}\n"],"mappings":";;;;;;;;;AAUA,eAAsB,6BACpB,SACA,mBAA4B,OACI;CAChC,MAAM,EACJ,MACA,aACA,aACA,QACA,WACA,gBACA,mBAAmB,6BACjB;CAEJ,IAAI,CAAC,oBAAoB,0BACvB,OAAO;CAGT,MAAM,oBAAoB,CAAC,CAAC,aAAa;CAEzC,IADkBA,4BAAAA,cAAc,IACpB,GACV,OAAO;CAGT,IAAI,qBAAqB,KAAK,SAAS,YACrC,OAAO;CAGT,MAAM,gBAAiB,MAAM,YAAY,IAAI,KAAM;CAKnD,OAAO,MAJyBC,oCAAAA,oBAAoB,QAAQ;EAC1D,QAAQ;EACR,SAAS,UAAU;CACrB,CAAC,IAC0B,YAAY;AACzC"}
|
|
@@ -90,10 +90,11 @@ const getRelayerUpdatedStep = async (client, step) => {
|
|
|
90
90
|
const getStandardUpdatedStep = async (client, step, signedTypedData) => {
|
|
91
91
|
const filteredSignedTypedData = signedTypedData?.filter((item) => item.signature);
|
|
92
92
|
const { typedData: _, ...restStep } = step;
|
|
93
|
-
|
|
93
|
+
const params = filteredSignedTypedData?.length ? {
|
|
94
94
|
...restStep,
|
|
95
95
|
typedData: filteredSignedTypedData
|
|
96
|
-
} : restStep
|
|
96
|
+
} : restStep;
|
|
97
|
+
return (0, _lifi_sdk.getStepTransaction)(client, params);
|
|
97
98
|
};
|
|
98
99
|
//#endregion
|
|
99
100
|
exports.getUpdatedStep = getUpdatedStep;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUpdatedStep.js","names":["isContractCallStep","isRelayerStep","isGaslessStep","TransactionError","LiFiErrorCode","PatcherMagicNumber"],"sources":["../../../../../src/core/tasks/helpers/getUpdatedStep.ts"],"sourcesContent":["import {\n convertQuoteToRoute,\n type ExecutionOptions,\n getContractCallsQuote,\n getRelayerQuote,\n getStepTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n patchContractCalls,\n type SDKClient,\n type SignedTypedData,\n TransactionError,\n} from '@lifi/sdk'\nimport { PatcherMagicNumber } from '../../../permits/constants.js'\nimport { isContractCallStep } from '../../../utils/isContractCallStep.js'\nimport { isGaslessStep } from '../../../utils/isGaslessStep.js'\nimport { isRelayerStep } from '../../../utils/isRelayerStep.js'\n\nexport const getUpdatedStep = async (\n client: SDKClient,\n step: LiFiStepExtended,\n executionOptions?: ExecutionOptions,\n signedTypedData?: SignedTypedData[]\n): Promise<LiFiStepExtended> => {\n if (isContractCallStep(step)) {\n return getContractCallUpdatedStep(client, step, executionOptions)\n }\n if (isRelayerStep(step) && isGaslessStep(step)) {\n return getRelayerUpdatedStep(client, step)\n }\n return getStandardUpdatedStep(client, step, signedTypedData)\n}\n\nconst getContractCallUpdatedStep = async (\n client: SDKClient,\n step: LiFiStepExtended,\n executionOptions?: ExecutionOptions\n): Promise<LiFiStepExtended> => {\n const contractCallsResult = await executionOptions?.getContractCalls?.({\n fromAddress: step.action.fromAddress!,\n fromAmount: BigInt(step.action.fromAmount),\n fromChainId: step.action.fromChainId,\n fromTokenAddress: step.action.fromToken.address,\n slippage: step.action.slippage,\n toAddress: step.action.toAddress,\n toAmount: BigInt(step.estimate.toAmount),\n toChainId: step.action.toChainId,\n toTokenAddress: step.action.toToken.address,\n })\n\n if (!contractCallsResult?.contractCalls?.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Contract calls are not found.'\n )\n }\n\n if (contractCallsResult.patcher) {\n const patchedContractCalls = await patchContractCalls(\n client,\n contractCallsResult.contractCalls.map((call) => ({\n chainId: step.action.toChainId,\n fromTokenAddress: call.fromTokenAddress,\n targetContractAddress: call.toContractAddress,\n callDataToPatch: call.toContractCallData,\n delegateCall: false,\n patches: [\n {\n amountToReplace: PatcherMagicNumber.toString(),\n },\n ],\n }))\n )\n\n contractCallsResult.contractCalls.forEach((call, index) => {\n call.toContractAddress = patchedContractCalls[index].target\n call.toContractCallData = patchedContractCalls[index].callData\n })\n }\n\n /**\n * Limitations of the retry logic for contract calls:\n * - denyBridges and denyExchanges are not supported\n * - allowBridges and allowExchanges are not supported\n * - fee is not supported\n * - toAmount is not supported\n */\n const contractCallQuote = await getContractCallsQuote(client, {\n fromAddress: step.action.fromAddress!,\n fromChain: step.action.fromChainId,\n fromToken: step.action.fromToken.address,\n fromAmount: step.action.fromAmount,\n toChain: step.action.toChainId,\n toToken: step.action.toToken.address,\n contractCalls: contractCallsResult.contractCalls,\n toFallbackAddress: step.action.toAddress,\n slippage: step.action.slippage,\n })\n\n contractCallQuote.action.toToken = step.action.toToken\n\n const customStep = contractCallQuote.includedSteps?.find(\n (s) => s.type === 'custom'\n )\n if (customStep && contractCallsResult?.contractTool) {\n const toolDetails = {\n key: contractCallsResult.contractTool.name,\n name: contractCallsResult.contractTool.name,\n logoURI: contractCallsResult.contractTool.logoURI,\n }\n customStep.toolDetails = toolDetails\n contractCallQuote.toolDetails = toolDetails\n }\n\n const route = convertQuoteToRoute(contractCallQuote, {\n adjustZeroOutputFromPreviousStep:\n executionOptions?.adjustZeroOutputFromPreviousStep,\n })\n\n return {\n ...route.steps[0],\n id: step.id,\n }\n}\n\nconst getRelayerUpdatedStep = async (\n client: SDKClient,\n step: LiFiStepExtended\n): Promise<LiFiStepExtended> => {\n const updatedRelayedStep = await getRelayerQuote(client, {\n fromChain: step.action.fromChainId,\n fromToken: step.action.fromToken.address,\n fromAddress: step.action.fromAddress!,\n fromAmount: step.action.fromAmount,\n toChain: step.action.toChainId,\n toToken: step.action.toToken.address,\n slippage: step.action.slippage,\n toAddress: step.action.toAddress,\n allowBridges: [step.tool],\n })\n return {\n ...updatedRelayedStep,\n id: step.id,\n }\n}\n\nconst getStandardUpdatedStep = async (\n client: SDKClient,\n step: LiFiStepExtended,\n signedTypedData?: SignedTypedData[]\n): Promise<LiFiStepExtended> => {\n const filteredSignedTypedData = signedTypedData?.filter(\n (item) => item.signature\n )\n const { typedData: _, ...restStep } = step\n const params = filteredSignedTypedData?.length\n ? { ...restStep, typedData: filteredSignedTypedData }\n : restStep\n return getStepTransaction(client, params)\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,iBAAiB,OAC5B,QACA,MACA,kBACA,oBAC8B;CAC9B,IAAIA,iCAAAA,mBAAmB,IAAI,GACzB,OAAO,2BAA2B,QAAQ,MAAM,gBAAgB;CAElE,IAAIC,4BAAAA,cAAc,IAAI,KAAKC,4BAAAA,cAAc,IAAI,GAC3C,OAAO,sBAAsB,QAAQ,IAAI;CAE3C,OAAO,uBAAuB,QAAQ,MAAM,eAAe;AAC7D;AAEA,MAAM,6BAA6B,OACjC,QACA,MACA,qBAC8B;CAC9B,MAAM,sBAAsB,MAAM,kBAAkB,mBAAmB;EACrE,aAAa,KAAK,OAAO;EACzB,YAAY,OAAO,KAAK,OAAO,UAAU;EACzC,aAAa,KAAK,OAAO;EACzB,kBAAkB,KAAK,OAAO,UAAU;EACxC,UAAU,KAAK,OAAO;EACtB,WAAW,KAAK,OAAO;EACvB,UAAU,OAAO,KAAK,SAAS,QAAQ;EACvC,WAAW,KAAK,OAAO;EACvB,gBAAgB,KAAK,OAAO,QAAQ;CACtC,CAAC;CAED,IAAI,CAAC,qBAAqB,eAAe,QACvC,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,8DACF;CAGF,IAAI,oBAAoB,SAAS;EAC/B,MAAM,uBAAuB,OAAA,
|
|
1
|
+
{"version":3,"file":"getUpdatedStep.js","names":["isContractCallStep","isRelayerStep","isGaslessStep","TransactionError","LiFiErrorCode","patchContractCalls","PatcherMagicNumber","getContractCallsQuote","convertQuoteToRoute","getRelayerQuote","getStepTransaction"],"sources":["../../../../../src/core/tasks/helpers/getUpdatedStep.ts"],"sourcesContent":["import {\n convertQuoteToRoute,\n type ExecutionOptions,\n getContractCallsQuote,\n getRelayerQuote,\n getStepTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n patchContractCalls,\n type SDKClient,\n type SignedTypedData,\n TransactionError,\n} from '@lifi/sdk'\nimport { PatcherMagicNumber } from '../../../permits/constants.js'\nimport { isContractCallStep } from '../../../utils/isContractCallStep.js'\nimport { isGaslessStep } from '../../../utils/isGaslessStep.js'\nimport { isRelayerStep } from '../../../utils/isRelayerStep.js'\n\nexport const getUpdatedStep = async (\n client: SDKClient,\n step: LiFiStepExtended,\n executionOptions?: ExecutionOptions,\n signedTypedData?: SignedTypedData[]\n): Promise<LiFiStepExtended> => {\n if (isContractCallStep(step)) {\n return getContractCallUpdatedStep(client, step, executionOptions)\n }\n if (isRelayerStep(step) && isGaslessStep(step)) {\n return getRelayerUpdatedStep(client, step)\n }\n return getStandardUpdatedStep(client, step, signedTypedData)\n}\n\nconst getContractCallUpdatedStep = async (\n client: SDKClient,\n step: LiFiStepExtended,\n executionOptions?: ExecutionOptions\n): Promise<LiFiStepExtended> => {\n const contractCallsResult = await executionOptions?.getContractCalls?.({\n fromAddress: step.action.fromAddress!,\n fromAmount: BigInt(step.action.fromAmount),\n fromChainId: step.action.fromChainId,\n fromTokenAddress: step.action.fromToken.address,\n slippage: step.action.slippage,\n toAddress: step.action.toAddress,\n toAmount: BigInt(step.estimate.toAmount),\n toChainId: step.action.toChainId,\n toTokenAddress: step.action.toToken.address,\n })\n\n if (!contractCallsResult?.contractCalls?.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Contract calls are not found.'\n )\n }\n\n if (contractCallsResult.patcher) {\n const patchedContractCalls = await patchContractCalls(\n client,\n contractCallsResult.contractCalls.map((call) => ({\n chainId: step.action.toChainId,\n fromTokenAddress: call.fromTokenAddress,\n targetContractAddress: call.toContractAddress,\n callDataToPatch: call.toContractCallData,\n delegateCall: false,\n patches: [\n {\n amountToReplace: PatcherMagicNumber.toString(),\n },\n ],\n }))\n )\n\n contractCallsResult.contractCalls.forEach((call, index) => {\n call.toContractAddress = patchedContractCalls[index].target\n call.toContractCallData = patchedContractCalls[index].callData\n })\n }\n\n /**\n * Limitations of the retry logic for contract calls:\n * - denyBridges and denyExchanges are not supported\n * - allowBridges and allowExchanges are not supported\n * - fee is not supported\n * - toAmount is not supported\n */\n const contractCallQuote = await getContractCallsQuote(client, {\n fromAddress: step.action.fromAddress!,\n fromChain: step.action.fromChainId,\n fromToken: step.action.fromToken.address,\n fromAmount: step.action.fromAmount,\n toChain: step.action.toChainId,\n toToken: step.action.toToken.address,\n contractCalls: contractCallsResult.contractCalls,\n toFallbackAddress: step.action.toAddress,\n slippage: step.action.slippage,\n })\n\n contractCallQuote.action.toToken = step.action.toToken\n\n const customStep = contractCallQuote.includedSteps?.find(\n (s) => s.type === 'custom'\n )\n if (customStep && contractCallsResult?.contractTool) {\n const toolDetails = {\n key: contractCallsResult.contractTool.name,\n name: contractCallsResult.contractTool.name,\n logoURI: contractCallsResult.contractTool.logoURI,\n }\n customStep.toolDetails = toolDetails\n contractCallQuote.toolDetails = toolDetails\n }\n\n const route = convertQuoteToRoute(contractCallQuote, {\n adjustZeroOutputFromPreviousStep:\n executionOptions?.adjustZeroOutputFromPreviousStep,\n })\n\n return {\n ...route.steps[0],\n id: step.id,\n }\n}\n\nconst getRelayerUpdatedStep = async (\n client: SDKClient,\n step: LiFiStepExtended\n): Promise<LiFiStepExtended> => {\n const updatedRelayedStep = await getRelayerQuote(client, {\n fromChain: step.action.fromChainId,\n fromToken: step.action.fromToken.address,\n fromAddress: step.action.fromAddress!,\n fromAmount: step.action.fromAmount,\n toChain: step.action.toChainId,\n toToken: step.action.toToken.address,\n slippage: step.action.slippage,\n toAddress: step.action.toAddress,\n allowBridges: [step.tool],\n })\n return {\n ...updatedRelayedStep,\n id: step.id,\n }\n}\n\nconst getStandardUpdatedStep = async (\n client: SDKClient,\n step: LiFiStepExtended,\n signedTypedData?: SignedTypedData[]\n): Promise<LiFiStepExtended> => {\n const filteredSignedTypedData = signedTypedData?.filter(\n (item) => item.signature\n )\n const { typedData: _, ...restStep } = step\n const params = filteredSignedTypedData?.length\n ? { ...restStep, typedData: filteredSignedTypedData }\n : restStep\n return getStepTransaction(client, params)\n}\n"],"mappings":";;;;;;;AAkBA,MAAa,iBAAiB,OAC5B,QACA,MACA,kBACA,oBAC8B;CAC9B,IAAIA,iCAAAA,mBAAmB,IAAI,GACzB,OAAO,2BAA2B,QAAQ,MAAM,gBAAgB;CAElE,IAAIC,4BAAAA,cAAc,IAAI,KAAKC,4BAAAA,cAAc,IAAI,GAC3C,OAAO,sBAAsB,QAAQ,IAAI;CAE3C,OAAO,uBAAuB,QAAQ,MAAM,eAAe;AAC7D;AAEA,MAAM,6BAA6B,OACjC,QACA,MACA,qBAC8B;CAC9B,MAAM,sBAAsB,MAAM,kBAAkB,mBAAmB;EACrE,aAAa,KAAK,OAAO;EACzB,YAAY,OAAO,KAAK,OAAO,UAAU;EACzC,aAAa,KAAK,OAAO;EACzB,kBAAkB,KAAK,OAAO,UAAU;EACxC,UAAU,KAAK,OAAO;EACtB,WAAW,KAAK,OAAO;EACvB,UAAU,OAAO,KAAK,SAAS,QAAQ;EACvC,WAAW,KAAK,OAAO;EACvB,gBAAgB,KAAK,OAAO,QAAQ;CACtC,CAAC;CAED,IAAI,CAAC,qBAAqB,eAAe,QACvC,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,8DACF;CAGF,IAAI,oBAAoB,SAAS;EAC/B,MAAM,uBAAuB,OAAA,GAAMC,UAAAA,mBAAAA,CACjC,QACA,oBAAoB,cAAc,KAAK,UAAU;GAC/C,SAAS,KAAK,OAAO;GACrB,kBAAkB,KAAK;GACvB,uBAAuB,KAAK;GAC5B,iBAAiB,KAAK;GACtB,cAAc;GACd,SAAS,CACP,EACE,iBAAiBC,0BAAAA,mBAAmB,SAAS,EAC/C,CACF;EACF,EAAE,CACJ;EAEA,oBAAoB,cAAc,SAAS,MAAM,UAAU;GACzD,KAAK,oBAAoB,qBAAqB,MAAM,CAAC;GACrD,KAAK,qBAAqB,qBAAqB,MAAM,CAAC;EACxD,CAAC;CACH;;;;;;;;CASA,MAAM,oBAAoB,OAAA,GAAMC,UAAAA,sBAAAA,CAAsB,QAAQ;EAC5D,aAAa,KAAK,OAAO;EACzB,WAAW,KAAK,OAAO;EACvB,WAAW,KAAK,OAAO,UAAU;EACjC,YAAY,KAAK,OAAO;EACxB,SAAS,KAAK,OAAO;EACrB,SAAS,KAAK,OAAO,QAAQ;EAC7B,eAAe,oBAAoB;EACnC,mBAAmB,KAAK,OAAO;EAC/B,UAAU,KAAK,OAAO;CACxB,CAAC;CAED,kBAAkB,OAAO,UAAU,KAAK,OAAO;CAE/C,MAAM,aAAa,kBAAkB,eAAe,MACjD,MAAM,EAAE,SAAS,QACpB;CACA,IAAI,cAAc,qBAAqB,cAAc;EACnD,MAAM,cAAc;GAClB,KAAK,oBAAoB,aAAa;GACtC,MAAM,oBAAoB,aAAa;GACvC,SAAS,oBAAoB,aAAa;EAC5C;EACA,WAAW,cAAc;EACzB,kBAAkB,cAAc;CAClC;CAOA,OAAO;EACL,IAAA,GANYC,UAAAA,oBAAAA,CAAoB,mBAAmB,EACnD,kCACE,kBAAkB,iCACtB,CAGS,CAAC,CAAC,MAAM;EACf,IAAI,KAAK;CACX;AACF;AAEA,MAAM,wBAAwB,OAC5B,QACA,SAC8B;CAY9B,OAAO;EACL,GAAG,OAAA,GAZ4BC,UAAAA,gBAAAA,CAAgB,QAAQ;GACvD,WAAW,KAAK,OAAO;GACvB,WAAW,KAAK,OAAO,UAAU;GACjC,aAAa,KAAK,OAAO;GACzB,YAAY,KAAK,OAAO;GACxB,SAAS,KAAK,OAAO;GACrB,SAAS,KAAK,OAAO,QAAQ;GAC7B,UAAU,KAAK,OAAO;GACtB,WAAW,KAAK,OAAO;GACvB,cAAc,CAAC,KAAK,IAAI;EAC1B,CAAC;EAGC,IAAI,KAAK;CACX;AACF;AAEA,MAAM,yBAAyB,OAC7B,QACA,MACA,oBAC8B;CAC9B,MAAM,0BAA0B,iBAAiB,QAC9C,SAAS,KAAK,SACjB;CACA,MAAM,EAAE,WAAW,GAAG,GAAG,aAAa;CACtC,MAAM,SAAS,yBAAyB,SACpC;EAAE,GAAG;EAAU,WAAW;CAAwB,IAClD;CACJ,QAAA,GAAOC,UAAAA,mBAAAA,CAAmB,QAAQ,MAAM;AAC1C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EthereumStepExecutorContext } from "../../../types.js";
|
|
2
|
+
import { TransactionMethodType } from "@lifi/sdk";
|
|
3
|
+
//#region src/core/tasks/helpers/resolvePermit2Support.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether this step should use the Permit2 signature flow.
|
|
6
|
+
*
|
|
7
|
+
* Beyond the step/chain checks, the `standard` strategy also probes the
|
|
8
|
+
* *signer*: code-bearing accounts send Permit2 down its EIP-1271 path, where
|
|
9
|
+
* acceptance is implementation-specific — see {@link canAccountUsePermit2}.
|
|
10
|
+
* Accounts that fail it fall back to approve + execute.
|
|
11
|
+
*
|
|
12
|
+
* Only `standard` consults the probe. `signPermit2Message` has one call site,
|
|
13
|
+
* `EthereumStandardSignAndExecuteTask`, so that is the only flow where the SDK
|
|
14
|
+
* produces the Permit2 signature itself. A relayed step has no approve +
|
|
15
|
+
* execute fallback, so a verdict cannot rescue a failing account and would
|
|
16
|
+
* break a working one — it must never move the spender off `fromChain.permit2`.
|
|
17
|
+
*
|
|
18
|
+
* The verdict is memoized on `context.permit2SignerSupported`, and a `false`
|
|
19
|
+
* stays sticky, a failed lookup included. `TaskPipeline` threads one context
|
|
20
|
+
* through every task, so a mid-run flip would let the allowance tasks approve
|
|
21
|
+
* one spender while the sign task routes to the other — turning a needless
|
|
22
|
+
* approval into a revert.
|
|
23
|
+
*/
|
|
24
|
+
declare const resolvePermit2Support: (context: EthereumStepExecutorContext, strategy: TransactionMethodType) => Promise<boolean>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { resolvePermit2Support };
|
|
27
|
+
//# sourceMappingURL=resolvePermit2Support.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_permits_canAccountUsePermit2 = require("../../../permits/canAccountUsePermit2.js");
|
|
3
|
+
//#region src/core/tasks/helpers/resolvePermit2Support.ts
|
|
4
|
+
/**
|
|
5
|
+
* Cheap, synchronous part of the gate: does the step/chain combination allow
|
|
6
|
+
* the Permit2 flow at all? Permit2 should not be available for atomic batch.
|
|
7
|
+
*/
|
|
8
|
+
const isPermit2SupportedForStep = (context, strategy) => {
|
|
9
|
+
const { step, fromChain, isFromNativeToken, disableMessageSigning } = context;
|
|
10
|
+
return !!fromChain.permit2 && !!fromChain.permit2Proxy && !isFromNativeToken && !disableMessageSigning && strategy !== "batched" && !!step.estimate.approvalAddress && !step.estimate.skipApproval && !step.estimate.skipPermit;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Whether this step should use the Permit2 signature flow.
|
|
14
|
+
*
|
|
15
|
+
* Beyond the step/chain checks, the `standard` strategy also probes the
|
|
16
|
+
* *signer*: code-bearing accounts send Permit2 down its EIP-1271 path, where
|
|
17
|
+
* acceptance is implementation-specific — see {@link canAccountUsePermit2}.
|
|
18
|
+
* Accounts that fail it fall back to approve + execute.
|
|
19
|
+
*
|
|
20
|
+
* Only `standard` consults the probe. `signPermit2Message` has one call site,
|
|
21
|
+
* `EthereumStandardSignAndExecuteTask`, so that is the only flow where the SDK
|
|
22
|
+
* produces the Permit2 signature itself. A relayed step has no approve +
|
|
23
|
+
* execute fallback, so a verdict cannot rescue a failing account and would
|
|
24
|
+
* break a working one — it must never move the spender off `fromChain.permit2`.
|
|
25
|
+
*
|
|
26
|
+
* The verdict is memoized on `context.permit2SignerSupported`, and a `false`
|
|
27
|
+
* stays sticky, a failed lookup included. `TaskPipeline` threads one context
|
|
28
|
+
* through every task, so a mid-run flip would let the allowance tasks approve
|
|
29
|
+
* one spender while the sign task routes to the other — turning a needless
|
|
30
|
+
* approval into a revert.
|
|
31
|
+
*/
|
|
32
|
+
const resolvePermit2Support = async (context, strategy) => {
|
|
33
|
+
if (!isPermit2SupportedForStep(context, strategy)) return false;
|
|
34
|
+
if (strategy !== "standard") return true;
|
|
35
|
+
const { client, step, fromChain, ethereumClient } = context;
|
|
36
|
+
const address = step.action.fromAddress ?? ethereumClient.account?.address;
|
|
37
|
+
if (!address) return false;
|
|
38
|
+
context.permit2SignerSupported ??= require_permits_canAccountUsePermit2.canAccountUsePermit2(client, {
|
|
39
|
+
chainId: fromChain.id,
|
|
40
|
+
address
|
|
41
|
+
});
|
|
42
|
+
return context.permit2SignerSupported;
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.resolvePermit2Support = resolvePermit2Support;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=resolvePermit2Support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePermit2Support.js","names":["canAccountUsePermit2"],"sources":["../../../../../src/core/tasks/helpers/resolvePermit2Support.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { canAccountUsePermit2 } from '../../../permits/canAccountUsePermit2.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\n\n/**\n * Cheap, synchronous part of the gate: does the step/chain combination allow\n * the Permit2 flow at all? Permit2 should not be available for atomic batch.\n */\nconst isPermit2SupportedForStep = (\n context: EthereumStepExecutorContext,\n strategy: TransactionMethodType\n): boolean => {\n const { step, fromChain, isFromNativeToken, disableMessageSigning } = context\n\n return (\n !!fromChain.permit2 &&\n !!fromChain.permit2Proxy &&\n !isFromNativeToken &&\n !disableMessageSigning &&\n strategy !== 'batched' &&\n // Approval address is not required for Permit2 per se, but we use it to skip allowance checks for direct transfers\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval &&\n !step.estimate.skipPermit\n )\n}\n\n/**\n * Whether this step should use the Permit2 signature flow.\n *\n * Beyond the step/chain checks, the `standard` strategy also probes the\n * *signer*: code-bearing accounts send Permit2 down its EIP-1271 path, where\n * acceptance is implementation-specific — see {@link canAccountUsePermit2}.\n * Accounts that fail it fall back to approve + execute.\n *\n * Only `standard` consults the probe. `signPermit2Message` has one call site,\n * `EthereumStandardSignAndExecuteTask`, so that is the only flow where the SDK\n * produces the Permit2 signature itself. A relayed step has no approve +\n * execute fallback, so a verdict cannot rescue a failing account and would\n * break a working one — it must never move the spender off `fromChain.permit2`.\n *\n * The verdict is memoized on `context.permit2SignerSupported`, and a `false`\n * stays sticky, a failed lookup included. `TaskPipeline` threads one context\n * through every task, so a mid-run flip would let the allowance tasks approve\n * one spender while the sign task routes to the other — turning a needless\n * approval into a revert.\n */\nexport const resolvePermit2Support = async (\n context: EthereumStepExecutorContext,\n strategy: TransactionMethodType\n): Promise<boolean> => {\n if (!isPermit2SupportedForStep(context, strategy)) {\n return false\n }\n\n // Only `standard` consults the probe; `batched` is excluded above.\n if (strategy !== 'standard') {\n return true\n }\n\n const { client, step, fromChain, ethereumClient } = context\n const address = (step.action.fromAddress ??\n ethereumClient.account?.address) as Address | undefined\n if (!address) {\n return false\n }\n\n // Caching the promise is safe: `canAccountUsePermit2` never rejects.\n context.permit2SignerSupported ??= canAccountUsePermit2(client, {\n chainId: fromChain.id,\n address,\n })\n\n return context.permit2SignerSupported\n}\n"],"mappings":";;;;;;;AASA,MAAM,6BACJ,SACA,aACY;CACZ,MAAM,EAAE,MAAM,WAAW,mBAAmB,0BAA0B;CAEtE,OACE,CAAC,CAAC,UAAU,WACZ,CAAC,CAAC,UAAU,gBACZ,CAAC,qBACD,CAAC,yBACD,aAAa,aAEb,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS,gBACf,CAAC,KAAK,SAAS;AAEnB;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,wBAAwB,OACnC,SACA,aACqB;CACrB,IAAI,CAAC,0BAA0B,SAAS,QAAQ,GAC9C,OAAO;CAIT,IAAI,aAAa,YACf,OAAO;CAGT,MAAM,EAAE,QAAQ,MAAM,WAAW,mBAAmB;CACpD,MAAM,UAAW,KAAK,OAAO,eAC3B,eAAe,SAAS;CAC1B,IAAI,CAAC,SACH,OAAO;CAIT,QAAQ,2BAA2BA,qCAAAA,qBAAqB,QAAQ;EAC9D,SAAS,UAAU;EACnB;CACF,CAAC;CAED,OAAO,QAAQ;AACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signHyperliquidTypedData.js","names":["isApproveAgentMessage","getOrCreateAgentWallet","getDomainChainId","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 intentTypedData: 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 = intentTypedData.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 intentTypedData) {\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":";;;;;;;;AAaA,MAAa,2BAA2B,OACtC,SACA,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,gBAAgB,KAAKA,2CAAAA,qBACF,CAAC,EAAE,QAAQ;CAIrD,MAAM,EACJ,SAAS,cACT,eACA,cACE,MAAMC,gCAAAA,uBAAuB,SAAS,cAAc,oBAAoB;CAE5E,KAAK,MAAM,aAAa,iBACtB,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,MAAM,YAAY,OAAA,
|
|
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 intentTypedData: 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 = intentTypedData.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 intentTypedData) {\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":";;;;;;;;AAaA,MAAa,2BAA2B,OACtC,SACA,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,gBAAgB,KAAKA,2CAAAA,qBACF,CAAC,EAAE,QAAQ;CAIrD,MAAM,EACJ,SAAS,cACT,eACA,cACE,MAAMC,gCAAAA,uBAAuB,SAAS,cAAc,oBAAoB;CAE5E,KAAK,MAAM,aAAa,iBACtB,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,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,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,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switchChain.js","names":["getChainId","ProviderError","LiFiErrorCode"],"sources":["../../../../../src/core/tasks/helpers/switchChain.ts"],"sourcesContent":["import { LiFiErrorCode, ProviderError } from '@lifi/sdk'\nimport type { Client, GetChainIdReturnType } from 'viem'\nimport { getChainId } from 'viem/actions'\nimport { getAction } from 'viem/utils'\n\n/**\n * This method checks whether the wallet client is configured for the correct chain.\n * If yes it returns the wallet clien.\n * If no and if user interaction is allowed it triggers the switchChain callback. If no user interaction is allowed it aborts.\n *\n * Account Type: local -\n * We need to create and return a new connector client from the switchChain callback in order to continue execution on a new chain.\n *\n * Account Type: json-rpc -\n * We can switch chain and return existing connector client from the switchChain callback in order to continue execution on a new chain.\n * @param client The client to switch the chain for\n * @param targetChainId The target chain id to switch to\n * @param allowUserInteraction Whether user interaction is allowed\n * @param switchChainCallback The callback to switch the chain\n * @returns New connector client\n */\nexport const switchChain = async (\n client: Client,\n targetChainId: number,\n allowUserInteraction: boolean,\n switchChainCallback?: (chainId: number) => Promise<Client | undefined>\n): Promise<Client | undefined> => {\n // if we are already on the correct chain we can proceed directly\n const currentChainId = (await getAction(\n client,\n getChainId,\n 'getChainId'\n )(undefined)) as GetChainIdReturnType\n if (currentChainId === targetChainId) {\n return client\n }\n\n if (!allowUserInteraction) {\n return\n }\n if (!switchChainCallback) {\n throw new ProviderError(\n LiFiErrorCode.ChainSwitchError,\n 'Chain switch hook is not provided.'\n )\n }\n const updatedClient = await switchChainCallback(targetChainId)\n let updatedChainId: number | undefined\n if (updatedClient) {\n updatedChainId = (await getAction(\n updatedClient,\n getChainId,\n 'getChainId'\n )(undefined)) as GetChainIdReturnType\n }\n if (updatedChainId !== targetChainId) {\n throw new ProviderError(\n LiFiErrorCode.ChainSwitchError,\n 'Chain switch required.'\n )\n }\n\n return updatedClient\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,cAAc,OACzB,QACA,eACA,sBACA,wBACgC;CAOhC,IAAI,OAAA,
|
|
1
|
+
{"version":3,"file":"switchChain.js","names":["getAction","getChainId","ProviderError","LiFiErrorCode"],"sources":["../../../../../src/core/tasks/helpers/switchChain.ts"],"sourcesContent":["import { LiFiErrorCode, ProviderError } from '@lifi/sdk'\nimport type { Client, GetChainIdReturnType } from 'viem'\nimport { getChainId } from 'viem/actions'\nimport { getAction } from 'viem/utils'\n\n/**\n * This method checks whether the wallet client is configured for the correct chain.\n * If yes it returns the wallet clien.\n * If no and if user interaction is allowed it triggers the switchChain callback. If no user interaction is allowed it aborts.\n *\n * Account Type: local -\n * We need to create and return a new connector client from the switchChain callback in order to continue execution on a new chain.\n *\n * Account Type: json-rpc -\n * We can switch chain and return existing connector client from the switchChain callback in order to continue execution on a new chain.\n * @param client The client to switch the chain for\n * @param targetChainId The target chain id to switch to\n * @param allowUserInteraction Whether user interaction is allowed\n * @param switchChainCallback The callback to switch the chain\n * @returns New connector client\n */\nexport const switchChain = async (\n client: Client,\n targetChainId: number,\n allowUserInteraction: boolean,\n switchChainCallback?: (chainId: number) => Promise<Client | undefined>\n): Promise<Client | undefined> => {\n // if we are already on the correct chain we can proceed directly\n const currentChainId = (await getAction(\n client,\n getChainId,\n 'getChainId'\n )(undefined)) as GetChainIdReturnType\n if (currentChainId === targetChainId) {\n return client\n }\n\n if (!allowUserInteraction) {\n return\n }\n if (!switchChainCallback) {\n throw new ProviderError(\n LiFiErrorCode.ChainSwitchError,\n 'Chain switch hook is not provided.'\n )\n }\n const updatedClient = await switchChainCallback(targetChainId)\n let updatedChainId: number | undefined\n if (updatedClient) {\n updatedChainId = (await getAction(\n updatedClient,\n getChainId,\n 'getChainId'\n )(undefined)) as GetChainIdReturnType\n }\n if (updatedChainId !== targetChainId) {\n throw new ProviderError(\n LiFiErrorCode.ChainSwitchError,\n 'Chain switch required.'\n )\n }\n\n return updatedClient\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,cAAc,OACzB,QACA,eACA,sBACA,wBACgC;CAOhC,IAAI,OAAA,GAL0BA,WAAAA,UAAAA,CAC5B,QACAC,aAAAA,YACA,YACF,CAAC,CAAC,KAAA,CAAS,MACY,eACrB,OAAO;CAGT,IAAI,CAAC,sBACH;CAEF,IAAI,CAAC,qBACH,MAAM,IAAIC,UAAAA,cACRC,UAAAA,cAAc,kBACd,oCACF;CAEF,MAAM,gBAAgB,MAAM,oBAAoB,aAAa;CAC7D,IAAI;CACJ,IAAI,eACF,iBAAkB,OAAA,GAAMH,WAAAA,UAAAA,CACtB,eACAC,aAAAA,YACA,YACF,CAAC,CAAC,KAAA,CAAS;CAEb,IAAI,mBAAmB,eACrB,MAAM,IAAIC,UAAAA,cACRC,UAAAA,cAAc,kBACd,wBACF;CAGF,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateActionWithReceipt.js","names":[],"sources":["../../../../../src/core/tasks/helpers/updateActionWithReceipt.ts"],"sourcesContent":["import type {\n ExecutionAction,\n ExtendedChain,\n LiFiStepExtended,\n StatusManager,\n} from '@lifi/sdk'\nimport type { TransactionReceipt } from 'viem'\nimport { isHex } from 'viem/utils'\nimport type { WalletCallReceipt } from '../../../types.js'\n\n/**\n * Update action to PENDING with txHash/txLink from a transaction receipt when the receipt hash differs from current action.\n * Returns the updated action or the same action if no update.\n */\nexport function updateActionWithReceipt(\n statusManager: StatusManager,\n step: LiFiStepExtended,\n fromChain: ExtendedChain,\n receipt: TransactionReceipt | WalletCallReceipt | undefined,\n action: ExecutionAction\n): ExecutionAction {\n // Update pending action if the transaction hash from the receipt is different.\n // This might happen if the transaction was replaced or we used taskId instead of txHash.\n if (!receipt?.transactionHash || receipt.transactionHash === action.txHash) {\n return action\n }\n // Validate if transaction hash is a valid hex string that can be used on-chain\n // Some custom integrations may return non-hex identifiers to support custom status tracking\n const txHash = isHex(receipt.transactionHash, { strict: true })\n ? receipt.transactionHash\n : undefined\n return statusManager.updateAction(step, action.type, 'PENDING', {\n txHash,\n txLink:\n (receipt as WalletCallReceipt).transactionLink ||\n (txHash\n ? `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`\n : undefined),\n })\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,wBACd,eACA,MACA,WACA,SACA,QACiB;CAGjB,IAAI,CAAC,SAAS,mBAAmB,QAAQ,oBAAoB,OAAO,QAClE,OAAO;CAIT,MAAM,UAAA,
|
|
1
|
+
{"version":3,"file":"updateActionWithReceipt.js","names":["isHex"],"sources":["../../../../../src/core/tasks/helpers/updateActionWithReceipt.ts"],"sourcesContent":["import type {\n ExecutionAction,\n ExtendedChain,\n LiFiStepExtended,\n StatusManager,\n} from '@lifi/sdk'\nimport type { TransactionReceipt } from 'viem'\nimport { isHex } from 'viem/utils'\nimport type { WalletCallReceipt } from '../../../types.js'\n\n/**\n * Update action to PENDING with txHash/txLink from a transaction receipt when the receipt hash differs from current action.\n * Returns the updated action or the same action if no update.\n */\nexport function updateActionWithReceipt(\n statusManager: StatusManager,\n step: LiFiStepExtended,\n fromChain: ExtendedChain,\n receipt: TransactionReceipt | WalletCallReceipt | undefined,\n action: ExecutionAction\n): ExecutionAction {\n // Update pending action if the transaction hash from the receipt is different.\n // This might happen if the transaction was replaced or we used taskId instead of txHash.\n if (!receipt?.transactionHash || receipt.transactionHash === action.txHash) {\n return action\n }\n // Validate if transaction hash is a valid hex string that can be used on-chain\n // Some custom integrations may return non-hex identifiers to support custom status tracking\n const txHash = isHex(receipt.transactionHash, { strict: true })\n ? receipt.transactionHash\n : undefined\n return statusManager.updateAction(step, action.type, 'PENDING', {\n txHash,\n txLink:\n (receipt as WalletCallReceipt).transactionLink ||\n (txHash\n ? `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`\n : undefined),\n })\n}\n"],"mappings":";;;;;;;AAcA,SAAgB,wBACd,eACA,MACA,WACA,SACA,QACiB;CAGjB,IAAI,CAAC,SAAS,mBAAmB,QAAQ,oBAAoB,OAAO,QAClE,OAAO;CAIT,MAAM,UAAA,GAASA,WAAAA,MAAAA,CAAM,QAAQ,iBAAiB,EAAE,QAAQ,KAAK,CAAC,IAC1D,QAAQ,kBACR,KAAA;CACJ,OAAO,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;EAC9D;EACA,QACG,QAA8B,oBAC9B,SACG,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,WAChD,KAAA;CACR,CAAC;AACH"}
|
|
@@ -9,7 +9,8 @@ const parseEthereumErrors = async (e, step, action, retryParams) => {
|
|
|
9
9
|
e.action = e.action ?? action;
|
|
10
10
|
return e;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
const baseError = await handleSpecificErrors(e, step, action);
|
|
13
|
+
return new _lifi_sdk.SDKError(baseError, step, action);
|
|
13
14
|
};
|
|
14
15
|
const handleSpecificErrors = async (e, step, action) => {
|
|
15
16
|
if (e.name === "UserRejectedRequestError" || e.cause?.name === "UserRejectedRequestError" || e.name === "UnknownBundleIdError") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.SignatureRejected, e.message, e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseEthereumErrors.js","names":["ExecuteStepRetryError","SDKError","TransactionError","LiFiErrorCode","ErrorMessage","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) &&\n !retryParams?.atomicityNotReady\n ) {\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;CAC9C,IACE,wCAAwC,CAAC,KACzC,CAAC,aAAa,mBAEd,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;
|
|
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) &&\n !retryParams?.atomicityNotReady\n ) {\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;CAC9C,IACE,wCAAwC,CAAC,KACzC,CAAC,aAAa,mBAEd,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"}
|
|
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
let viem_accounts = require("viem/accounts");
|
|
3
3
|
//#region src/hyperliquid/agentWallet.ts
|
|
4
4
|
const DEFAULT_STORAGE_KEY_PREFIX = "li.fi-sdk:hyperliquid:agent";
|
|
5
|
-
const DEFAULT_EXPIRATION_MS =
|
|
6
|
-
const EXPIRATION_BUFFER_MS =
|
|
5
|
+
const DEFAULT_EXPIRATION_MS = 6048e5;
|
|
6
|
+
const EXPIRATION_BUFFER_MS = 36e5;
|
|
7
7
|
const ENCRYPTION_SALT = "li.fi-sdk:agent-wallet-encryption";
|
|
8
8
|
function getStorageKey(ownerAddress, keyPrefix = DEFAULT_STORAGE_KEY_PREFIX) {
|
|
9
9
|
return `${keyPrefix}:${ownerAddress.toLowerCase()}`;
|
|
@@ -57,8 +57,9 @@ async function loadAgentWallet(storage, ownerAddress, keyPrefix) {
|
|
|
57
57
|
try {
|
|
58
58
|
const data = JSON.parse(raw);
|
|
59
59
|
const encryptionKey = await deriveKey(ownerAddress);
|
|
60
|
+
const privateKey = await decrypt(data.pkey, encryptionKey);
|
|
60
61
|
return {
|
|
61
|
-
account: (0, viem_accounts.privateKeyToAccount)(
|
|
62
|
+
account: (0, viem_accounts.privateKeyToAccount)(privateKey),
|
|
62
63
|
expiresAt: data.expiresAt
|
|
63
64
|
};
|
|
64
65
|
} catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentWallet.js","names":[],"sources":["../../../src/hyperliquid/agentWallet.ts"],"sourcesContent":["import type { SDKStorage } from '@lifi/sdk'\nimport type { Hex, LocalAccount } from 'viem'\nimport { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'\n\nconst DEFAULT_STORAGE_KEY_PREFIX = 'li.fi-sdk:hyperliquid:agent'\nconst DEFAULT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000 // 1 week\nconst EXPIRATION_BUFFER_MS = 60 * 60 * 1000 // 1 hour\n\n// Private keys are encrypted with AES-GCM using a key derived (PBKDF2) from\n// the owner's wallet address. This is obfuscation -- the wallet address is\n// public, so anyone who knows the scheme can derive the same key. It prevents\n// raw key exposure in storage but does not defend against a targeted attack.\nconst ENCRYPTION_SALT = 'li.fi-sdk:agent-wallet-encryption'\n\ninterface StoredAgentWallet {\n address: string\n pkey: string\n expiresAt: number\n}\n\nexport interface AgentWalletResult {\n account: LocalAccount\n needsApproval: boolean\n expiresAt: number\n}\n\nfunction getStorageKey(\n ownerAddress: string,\n keyPrefix = DEFAULT_STORAGE_KEY_PREFIX\n): string {\n return `${keyPrefix}:${ownerAddress.toLowerCase()}`\n}\n\nconst encoder = new TextEncoder()\nconst decoder = new TextDecoder()\n\nasync function deriveKey(ownerAddress: string): Promise<CryptoKey> {\n const keyMaterial = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(ownerAddress.toLowerCase()),\n 'PBKDF2',\n false,\n ['deriveKey']\n )\n return crypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: encoder.encode(ENCRYPTION_SALT),\n iterations: 100_000,\n hash: 'SHA-256',\n },\n keyMaterial,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt']\n )\n}\n\nasync function encrypt(plaintext: string, key: CryptoKey): Promise<string> {\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const ciphertext = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv },\n key,\n encoder.encode(plaintext)\n )\n const combined = new Uint8Array(iv.length + new Uint8Array(ciphertext).length)\n combined.set(iv)\n combined.set(new Uint8Array(ciphertext), iv.length)\n return btoa(String.fromCharCode(...combined))\n}\n\nasync function decrypt(encoded: string, key: CryptoKey): Promise<string> {\n const combined = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0))\n const iv = combined.slice(0, 12)\n const ciphertext = combined.slice(12)\n const plaintext = await crypto.subtle.decrypt(\n { name: 'AES-GCM', iv },\n key,\n ciphertext\n )\n return decoder.decode(plaintext)\n}\n\nasync function saveAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n accountAddress: string,\n privateKey: Hex,\n keyPrefix?: string\n): Promise<void> {\n const encryptionKey = await deriveKey(ownerAddress)\n const data: StoredAgentWallet = {\n address: accountAddress,\n pkey: await encrypt(privateKey, encryptionKey),\n expiresAt: Date.now() + DEFAULT_EXPIRATION_MS,\n }\n await storage.set(\n getStorageKey(ownerAddress, keyPrefix),\n JSON.stringify(data)\n )\n}\n\nasync function loadAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n keyPrefix?: string\n): Promise<{ account: LocalAccount; expiresAt: number } | null> {\n const raw = await storage.get(getStorageKey(ownerAddress, keyPrefix))\n if (!raw) {\n return null\n }\n try {\n const data: StoredAgentWallet = JSON.parse(raw)\n const encryptionKey = await deriveKey(ownerAddress)\n const privateKey = (await decrypt(data.pkey, encryptionKey)) as Hex\n return {\n account: privateKeyToAccount(privateKey),\n expiresAt: data.expiresAt,\n }\n } catch {\n return null\n }\n}\n\nexport async function getOrCreateAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n existingAgentAddress?: string,\n keyPrefix?: string\n): Promise<AgentWalletResult> {\n if (existingAgentAddress) {\n const existing = await loadAgentWallet(storage, ownerAddress, keyPrefix)\n if (\n existing?.account.address.toLowerCase() ===\n existingAgentAddress.toLowerCase() &&\n existing.expiresAt - Date.now() > EXPIRATION_BUFFER_MS\n ) {\n return {\n account: existing.account,\n needsApproval: false,\n expiresAt: existing.expiresAt,\n }\n }\n }\n\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n const expiresAt = Date.now() + DEFAULT_EXPIRATION_MS\n await saveAgentWallet(\n storage,\n ownerAddress,\n account.address,\n privateKey,\n keyPrefix\n )\n return { account, needsApproval: true, expiresAt }\n}\n"],"mappings":";;;AAIA,MAAM,6BAA6B;AACnC,MAAM,wBAAwB
|
|
1
|
+
{"version":3,"file":"agentWallet.js","names":["privateKeyToAccount","generatePrivateKey"],"sources":["../../../src/hyperliquid/agentWallet.ts"],"sourcesContent":["import type { SDKStorage } from '@lifi/sdk'\nimport type { Hex, LocalAccount } from 'viem'\nimport { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'\n\nconst DEFAULT_STORAGE_KEY_PREFIX = 'li.fi-sdk:hyperliquid:agent'\nconst DEFAULT_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000 // 1 week\nconst EXPIRATION_BUFFER_MS = 60 * 60 * 1000 // 1 hour\n\n// Private keys are encrypted with AES-GCM using a key derived (PBKDF2) from\n// the owner's wallet address. This is obfuscation -- the wallet address is\n// public, so anyone who knows the scheme can derive the same key. It prevents\n// raw key exposure in storage but does not defend against a targeted attack.\nconst ENCRYPTION_SALT = 'li.fi-sdk:agent-wallet-encryption'\n\ninterface StoredAgentWallet {\n address: string\n pkey: string\n expiresAt: number\n}\n\nexport interface AgentWalletResult {\n account: LocalAccount\n needsApproval: boolean\n expiresAt: number\n}\n\nfunction getStorageKey(\n ownerAddress: string,\n keyPrefix = DEFAULT_STORAGE_KEY_PREFIX\n): string {\n return `${keyPrefix}:${ownerAddress.toLowerCase()}`\n}\n\nconst encoder = new TextEncoder()\nconst decoder = new TextDecoder()\n\nasync function deriveKey(ownerAddress: string): Promise<CryptoKey> {\n const keyMaterial = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(ownerAddress.toLowerCase()),\n 'PBKDF2',\n false,\n ['deriveKey']\n )\n return crypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: encoder.encode(ENCRYPTION_SALT),\n iterations: 100_000,\n hash: 'SHA-256',\n },\n keyMaterial,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt']\n )\n}\n\nasync function encrypt(plaintext: string, key: CryptoKey): Promise<string> {\n const iv = crypto.getRandomValues(new Uint8Array(12))\n const ciphertext = await crypto.subtle.encrypt(\n { name: 'AES-GCM', iv },\n key,\n encoder.encode(plaintext)\n )\n const combined = new Uint8Array(iv.length + new Uint8Array(ciphertext).length)\n combined.set(iv)\n combined.set(new Uint8Array(ciphertext), iv.length)\n return btoa(String.fromCharCode(...combined))\n}\n\nasync function decrypt(encoded: string, key: CryptoKey): Promise<string> {\n const combined = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0))\n const iv = combined.slice(0, 12)\n const ciphertext = combined.slice(12)\n const plaintext = await crypto.subtle.decrypt(\n { name: 'AES-GCM', iv },\n key,\n ciphertext\n )\n return decoder.decode(plaintext)\n}\n\nasync function saveAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n accountAddress: string,\n privateKey: Hex,\n keyPrefix?: string\n): Promise<void> {\n const encryptionKey = await deriveKey(ownerAddress)\n const data: StoredAgentWallet = {\n address: accountAddress,\n pkey: await encrypt(privateKey, encryptionKey),\n expiresAt: Date.now() + DEFAULT_EXPIRATION_MS,\n }\n await storage.set(\n getStorageKey(ownerAddress, keyPrefix),\n JSON.stringify(data)\n )\n}\n\nasync function loadAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n keyPrefix?: string\n): Promise<{ account: LocalAccount; expiresAt: number } | null> {\n const raw = await storage.get(getStorageKey(ownerAddress, keyPrefix))\n if (!raw) {\n return null\n }\n try {\n const data: StoredAgentWallet = JSON.parse(raw)\n const encryptionKey = await deriveKey(ownerAddress)\n const privateKey = (await decrypt(data.pkey, encryptionKey)) as Hex\n return {\n account: privateKeyToAccount(privateKey),\n expiresAt: data.expiresAt,\n }\n } catch {\n return null\n }\n}\n\nexport async function getOrCreateAgentWallet(\n storage: SDKStorage,\n ownerAddress: string,\n existingAgentAddress?: string,\n keyPrefix?: string\n): Promise<AgentWalletResult> {\n if (existingAgentAddress) {\n const existing = await loadAgentWallet(storage, ownerAddress, keyPrefix)\n if (\n existing?.account.address.toLowerCase() ===\n existingAgentAddress.toLowerCase() &&\n existing.expiresAt - Date.now() > EXPIRATION_BUFFER_MS\n ) {\n return {\n account: existing.account,\n needsApproval: false,\n expiresAt: existing.expiresAt,\n }\n }\n }\n\n const privateKey = generatePrivateKey()\n const account = privateKeyToAccount(privateKey)\n const expiresAt = Date.now() + DEFAULT_EXPIRATION_MS\n await saveAgentWallet(\n storage,\n ownerAddress,\n account.address,\n privateKey,\n keyPrefix\n )\n return { account, needsApproval: true, expiresAt }\n}\n"],"mappings":";;;AAIA,MAAM,6BAA6B;AACnC,MAAM,wBAAwB;AAC9B,MAAM,uBAAuB;AAM7B,MAAM,kBAAkB;AAcxB,SAAS,cACP,cACA,YAAY,4BACJ;CACR,OAAO,GAAG,UAAU,GAAG,aAAa,YAAY;AAClD;AAEA,MAAM,UAAU,IAAI,YAAY;AAChC,MAAM,UAAU,IAAI,YAAY;AAEhC,eAAe,UAAU,cAA0C;CACjE,MAAM,cAAc,MAAM,OAAO,OAAO,UACtC,OACA,QAAQ,OAAO,aAAa,YAAY,CAAC,GACzC,UACA,OACA,CAAC,WAAW,CACd;CACA,OAAO,OAAO,OAAO,UACnB;EACE,MAAM;EACN,MAAM,QAAQ,OAAO,eAAe;EACpC,YAAY;EACZ,MAAM;CACR,GACA,aACA;EAAE,MAAM;EAAW,QAAQ;CAAI,GAC/B,OACA,CAAC,WAAW,SAAS,CACvB;AACF;AAEA,eAAe,QAAQ,WAAmB,KAAiC;CACzE,MAAM,KAAK,OAAO,gCAAgB,IAAI,WAAW,EAAE,CAAC;CACpD,MAAM,aAAa,MAAM,OAAO,OAAO,QACrC;EAAE,MAAM;EAAW;CAAG,GACtB,KACA,QAAQ,OAAO,SAAS,CAC1B;CACA,MAAM,WAAW,IAAI,WAAW,GAAG,SAAS,IAAI,WAAW,UAAU,CAAC,CAAC,MAAM;CAC7E,SAAS,IAAI,EAAE;CACf,SAAS,IAAI,IAAI,WAAW,UAAU,GAAG,GAAG,MAAM;CAClD,OAAO,KAAK,OAAO,aAAa,GAAG,QAAQ,CAAC;AAC9C;AAEA,eAAe,QAAQ,SAAiB,KAAiC;CACvE,MAAM,WAAW,WAAW,KAAK,KAAK,OAAO,IAAI,MAAM,EAAE,WAAW,CAAC,CAAC;CACtE,MAAM,KAAK,SAAS,MAAM,GAAG,EAAE;CAC/B,MAAM,aAAa,SAAS,MAAM,EAAE;CACpC,MAAM,YAAY,MAAM,OAAO,OAAO,QACpC;EAAE,MAAM;EAAW;CAAG,GACtB,KACA,UACF;CACA,OAAO,QAAQ,OAAO,SAAS;AACjC;AAEA,eAAe,gBACb,SACA,cACA,gBACA,YACA,WACe;CAEf,MAAM,OAA0B;EAC9B,SAAS;EACT,MAAM,MAAM,QAAQ,YAAY,MAHN,UAAU,YAAY,CAGH;EAC7C,WAAW,KAAK,IAAI,IAAI;CAC1B;CACA,MAAM,QAAQ,IACZ,cAAc,cAAc,SAAS,GACrC,KAAK,UAAU,IAAI,CACrB;AACF;AAEA,eAAe,gBACb,SACA,cACA,WAC8D;CAC9D,MAAM,MAAM,MAAM,QAAQ,IAAI,cAAc,cAAc,SAAS,CAAC;CACpE,IAAI,CAAC,KACH,OAAO;CAET,IAAI;EACF,MAAM,OAA0B,KAAK,MAAM,GAAG;EAC9C,MAAM,gBAAgB,MAAM,UAAU,YAAY;EAClD,MAAM,aAAc,MAAM,QAAQ,KAAK,MAAM,aAAa;EAC1D,OAAO;GACL,UAAA,GAASA,cAAAA,oBAAAA,CAAoB,UAAU;GACvC,WAAW,KAAK;EAClB;CACF,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,uBACpB,SACA,cACA,sBACA,WAC4B;CAC5B,IAAI,sBAAsB;EACxB,MAAM,WAAW,MAAM,gBAAgB,SAAS,cAAc,SAAS;EACvE,IACE,UAAU,QAAQ,QAAQ,YAAY,MACpC,qBAAqB,YAAY,KACnC,SAAS,YAAY,KAAK,IAAI,IAAI,sBAElC,OAAO;GACL,SAAS,SAAS;GAClB,eAAe;GACf,WAAW,SAAS;EACtB;CAEJ;CAEA,MAAM,cAAA,GAAaC,cAAAA,mBAAAA,CAAmB;CACtC,MAAM,WAAA,GAAUD,cAAAA,oBAAAA,CAAoB,UAAU;CAC9C,MAAM,YAAY,KAAK,IAAI,IAAI;CAC/B,MAAM,gBACJ,SACA,cACA,QAAQ,SACR,YACA,SACF;CACA,OAAO;EAAE;EAAS,eAAe;EAAM;CAAU;AACnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowanceTransfer.js","names":["MaxUint160","MaxUint48","MaxSigDeadline","permit2Domain"],"sources":["../../../src/permits/allowanceTransfer.ts"],"sourcesContent":["import {\n type Address,\n hashTypedData,\n type TypedData,\n type TypedDataDomain,\n} from 'viem'\nimport { MaxSigDeadline, MaxUint48, MaxUint160 } from './constants.js'\nimport { permit2Domain } from './domain.js'\nimport { invariant } from './invariant.js'\n\nexport const MaxAllowanceTransferAmount: bigint = MaxUint160\nexport const MaxAllowanceExpiration: bigint = MaxUint48\nexport const MaxOrderedNonce: bigint = MaxUint48\n\nexport interface PermitDetails {\n token: Address\n amount: bigint\n expiration: number\n nonce: number\n}\n\nexport interface PermitSingle {\n details: PermitDetails\n spender: Address\n sigDeadline: bigint\n}\n\nexport interface PermitBatch {\n details: PermitDetails[]\n spender: Address\n sigDeadline: bigint\n}\n\nexport type PermitSingleData = {\n domain: TypedDataDomain\n types: TypedData\n message: PermitSingle\n}\n\nexport type PermitBatchData = {\n domain: TypedDataDomain\n types: TypedData\n message: PermitBatch\n}\n\nconst PERMIT_DETAILS = [\n { name: 'token', type: 'address' },\n { name: 'amount', type: 'uint160' },\n { name: 'expiration', type: 'uint48' },\n { name: 'nonce', type: 'uint48' },\n] as const\n\nconst PERMIT_TYPES = {\n PermitDetails: PERMIT_DETAILS,\n PermitSingle: [\n { name: 'details', type: 'PermitDetails' },\n { name: 'spender', type: 'address' },\n { name: 'sigDeadline', type: 'uint256' },\n ],\n} as const\n\nconst PERMIT_BATCH_TYPES = {\n PermitDetails: PERMIT_DETAILS,\n PermitBatch: [\n { name: 'details', type: 'PermitDetails[]' },\n { name: 'spender', type: 'address' },\n { name: 'sigDeadline', type: 'uint256' },\n ],\n} as const\n\nfunction isPermit(permit: PermitSingle | PermitBatch): permit is PermitSingle {\n return !Array.isArray(permit.details)\n}\n\nexport function getPermitSingleData(\n permit: PermitSingle,\n permit2Address: Address,\n chainId: number\n): { domain: TypedDataDomain; message: PermitSingle } {\n invariant(MaxSigDeadline >= permit.sigDeadline, 'SIG_DEADLINE_OUT_OF_RANGE')\n\n const domain = permit2Domain(permit2Address, chainId)\n validatePermitDetails(permit.details)\n\n return {\n domain,\n message: permit,\n }\n}\n\nexport function getPermitBatchData(\n permit: PermitBatch,\n permit2Address: Address,\n chainId: number\n): { domain: TypedDataDomain; message: PermitBatch } {\n invariant(MaxSigDeadline >= permit.sigDeadline, 'SIG_DEADLINE_OUT_OF_RANGE')\n\n const domain = permit2Domain(permit2Address, chainId)\n permit.details.forEach(validatePermitDetails)\n\n return {\n domain,\n message: permit,\n }\n}\n\nexport function getPermitData(\n permit: PermitSingle | PermitBatch,\n permit2Address: Address,\n chainId: number\n): PermitSingleData | PermitBatchData {\n invariant(MaxSigDeadline >= permit.sigDeadline, 'SIG_DEADLINE_OUT_OF_RANGE')\n\n const domain = permit2Domain(permit2Address, chainId)\n if (isPermit(permit)) {\n validatePermitDetails(permit.details)\n return {\n domain,\n types: PERMIT_TYPES,\n message: permit,\n }\n }\n permit.details.forEach(validatePermitDetails)\n return {\n domain,\n types: PERMIT_BATCH_TYPES,\n message: permit,\n }\n}\n\nexport function hash(\n permit: PermitSingle | PermitBatch,\n permit2Address: Address,\n chainId: number\n): string {\n if (isPermit(permit)) {\n const { domain, message } = getPermitSingleData(\n permit,\n permit2Address,\n chainId\n )\n\n return hashTypedData({\n domain,\n types: PERMIT_TYPES,\n primaryType: 'PermitSingle',\n message: message,\n })\n }\n const { domain, message } = getPermitBatchData(\n permit,\n permit2Address,\n chainId\n )\n\n return hashTypedData({\n domain,\n types: PERMIT_BATCH_TYPES,\n primaryType: 'PermitBatch',\n message: message,\n })\n}\n\nfunction validatePermitDetails(details: PermitDetails) {\n invariant(MaxOrderedNonce >= details.nonce, 'NONCE_OUT_OF_RANGE')\n invariant(MaxAllowanceTransferAmount >= details.amount, 'AMOUNT_OUT_OF_RANGE')\n invariant(\n MaxAllowanceExpiration >= details.expiration,\n 'EXPIRATION_OUT_OF_RANGE'\n )\n}\n"],"mappings":";;;;;;AAUA,MAAa,6BAAqCA,0BAAAA;AAClD,MAAa,yBAAiCC,0BAAAA;AAC9C,MAAa,kBAA0BA,0BAAAA;AAiCvC,MAAM,iBAAiB;CACrB;EAAE,MAAM;EAAS,MAAM;CAAU;CACjC;EAAE,MAAM;EAAU,MAAM;CAAU;CAClC;EAAE,MAAM;EAAc,MAAM;CAAS;CACrC;EAAE,MAAM;EAAS,MAAM;CAAS;AAClC;AAEA,MAAM,eAAe;CACnB,eAAe;CACf,cAAc;EACZ;GAAE,MAAM;GAAW,MAAM;EAAgB;EACzC;GAAE,MAAM;GAAW,MAAM;EAAU;EACnC;GAAE,MAAM;GAAe,MAAM;EAAU;CACzC;AACF;AAEA,MAAM,qBAAqB;CACzB,eAAe;CACf,aAAa;EACX;GAAE,MAAM;GAAW,MAAM;EAAkB;EAC3C;GAAE,MAAM;GAAW,MAAM;EAAU;EACnC;GAAE,MAAM;GAAe,MAAM;EAAU;CACzC;AACF;AAEA,SAAS,SAAS,QAA4D;CAC5E,OAAO,CAAC,MAAM,QAAQ,OAAO,OAAO;AACtC;AAEA,SAAgB,oBACd,QACA,gBACA,SACoD;CACpD,0BAAA,UAAUC,0BAAAA,kBAAkB,OAAO,aAAa,2BAA2B;CAE3E,MAAM,SAASC,uBAAAA,cAAc,gBAAgB,OAAO;CACpD,sBAAsB,OAAO,OAAO;CAEpC,OAAO;EACL;EACA,SAAS;CACX;AACF;AAEA,SAAgB,mBACd,QACA,gBACA,SACmD;CACnD,0BAAA,UAAUD,0BAAAA,kBAAkB,OAAO,aAAa,2BAA2B;CAE3E,MAAM,SAASC,uBAAAA,cAAc,gBAAgB,OAAO;CACpD,OAAO,QAAQ,QAAQ,qBAAqB;CAE5C,OAAO;EACL;EACA,SAAS;CACX;AACF;AAEA,SAAgB,cACd,QACA,gBACA,SACoC;CACpC,0BAAA,UAAUD,0BAAAA,kBAAkB,OAAO,aAAa,2BAA2B;CAE3E,MAAM,SAASC,uBAAAA,cAAc,gBAAgB,OAAO;CACpD,IAAI,SAAS,MAAM,GAAG;EACpB,sBAAsB,OAAO,OAAO;EACpC,OAAO;GACL;GACA,OAAO;GACP,SAAS;EACX;CACF;CACA,OAAO,QAAQ,QAAQ,qBAAqB;CAC5C,OAAO;EACL;EACA,OAAO;EACP,SAAS;CACX;AACF;AAEA,SAAgB,KACd,QACA,gBACA,SACQ;CACR,IAAI,SAAS,MAAM,GAAG;EACpB,MAAM,EAAE,QAAQ,YAAY,oBAC1B,QACA,gBACA,OACF;EAEA,QAAA,
|
|
1
|
+
{"version":3,"file":"allowanceTransfer.js","names":["MaxUint160","MaxUint48","MaxSigDeadline","permit2Domain","hashTypedData"],"sources":["../../../src/permits/allowanceTransfer.ts"],"sourcesContent":["import {\n type Address,\n hashTypedData,\n type TypedData,\n type TypedDataDomain,\n} from 'viem'\nimport { MaxSigDeadline, MaxUint48, MaxUint160 } from './constants.js'\nimport { permit2Domain } from './domain.js'\nimport { invariant } from './invariant.js'\n\nexport const MaxAllowanceTransferAmount: bigint = MaxUint160\nexport const MaxAllowanceExpiration: bigint = MaxUint48\nexport const MaxOrderedNonce: bigint = MaxUint48\n\nexport interface PermitDetails {\n token: Address\n amount: bigint\n expiration: number\n nonce: number\n}\n\nexport interface PermitSingle {\n details: PermitDetails\n spender: Address\n sigDeadline: bigint\n}\n\nexport interface PermitBatch {\n details: PermitDetails[]\n spender: Address\n sigDeadline: bigint\n}\n\nexport type PermitSingleData = {\n domain: TypedDataDomain\n types: TypedData\n message: PermitSingle\n}\n\nexport type PermitBatchData = {\n domain: TypedDataDomain\n types: TypedData\n message: PermitBatch\n}\n\nconst PERMIT_DETAILS = [\n { name: 'token', type: 'address' },\n { name: 'amount', type: 'uint160' },\n { name: 'expiration', type: 'uint48' },\n { name: 'nonce', type: 'uint48' },\n] as const\n\nconst PERMIT_TYPES = {\n PermitDetails: PERMIT_DETAILS,\n PermitSingle: [\n { name: 'details', type: 'PermitDetails' },\n { name: 'spender', type: 'address' },\n { name: 'sigDeadline', type: 'uint256' },\n ],\n} as const\n\nconst PERMIT_BATCH_TYPES = {\n PermitDetails: PERMIT_DETAILS,\n PermitBatch: [\n { name: 'details', type: 'PermitDetails[]' },\n { name: 'spender', type: 'address' },\n { name: 'sigDeadline', type: 'uint256' },\n ],\n} as const\n\nfunction isPermit(permit: PermitSingle | PermitBatch): permit is PermitSingle {\n return !Array.isArray(permit.details)\n}\n\nexport function getPermitSingleData(\n permit: PermitSingle,\n permit2Address: Address,\n chainId: number\n): { domain: TypedDataDomain; message: PermitSingle } {\n invariant(MaxSigDeadline >= permit.sigDeadline, 'SIG_DEADLINE_OUT_OF_RANGE')\n\n const domain = permit2Domain(permit2Address, chainId)\n validatePermitDetails(permit.details)\n\n return {\n domain,\n message: permit,\n }\n}\n\nexport function getPermitBatchData(\n permit: PermitBatch,\n permit2Address: Address,\n chainId: number\n): { domain: TypedDataDomain; message: PermitBatch } {\n invariant(MaxSigDeadline >= permit.sigDeadline, 'SIG_DEADLINE_OUT_OF_RANGE')\n\n const domain = permit2Domain(permit2Address, chainId)\n permit.details.forEach(validatePermitDetails)\n\n return {\n domain,\n message: permit,\n }\n}\n\nexport function getPermitData(\n permit: PermitSingle | PermitBatch,\n permit2Address: Address,\n chainId: number\n): PermitSingleData | PermitBatchData {\n invariant(MaxSigDeadline >= permit.sigDeadline, 'SIG_DEADLINE_OUT_OF_RANGE')\n\n const domain = permit2Domain(permit2Address, chainId)\n if (isPermit(permit)) {\n validatePermitDetails(permit.details)\n return {\n domain,\n types: PERMIT_TYPES,\n message: permit,\n }\n }\n permit.details.forEach(validatePermitDetails)\n return {\n domain,\n types: PERMIT_BATCH_TYPES,\n message: permit,\n }\n}\n\nexport function hash(\n permit: PermitSingle | PermitBatch,\n permit2Address: Address,\n chainId: number\n): string {\n if (isPermit(permit)) {\n const { domain, message } = getPermitSingleData(\n permit,\n permit2Address,\n chainId\n )\n\n return hashTypedData({\n domain,\n types: PERMIT_TYPES,\n primaryType: 'PermitSingle',\n message: message,\n })\n }\n const { domain, message } = getPermitBatchData(\n permit,\n permit2Address,\n chainId\n )\n\n return hashTypedData({\n domain,\n types: PERMIT_BATCH_TYPES,\n primaryType: 'PermitBatch',\n message: message,\n })\n}\n\nfunction validatePermitDetails(details: PermitDetails) {\n invariant(MaxOrderedNonce >= details.nonce, 'NONCE_OUT_OF_RANGE')\n invariant(MaxAllowanceTransferAmount >= details.amount, 'AMOUNT_OUT_OF_RANGE')\n invariant(\n MaxAllowanceExpiration >= details.expiration,\n 'EXPIRATION_OUT_OF_RANGE'\n )\n}\n"],"mappings":";;;;;;AAUA,MAAa,6BAAqCA,0BAAAA;AAClD,MAAa,yBAAiCC,0BAAAA;AAC9C,MAAa,kBAA0BA,0BAAAA;AAiCvC,MAAM,iBAAiB;CACrB;EAAE,MAAM;EAAS,MAAM;CAAU;CACjC;EAAE,MAAM;EAAU,MAAM;CAAU;CAClC;EAAE,MAAM;EAAc,MAAM;CAAS;CACrC;EAAE,MAAM;EAAS,MAAM;CAAS;AAClC;AAEA,MAAM,eAAe;CACnB,eAAe;CACf,cAAc;EACZ;GAAE,MAAM;GAAW,MAAM;EAAgB;EACzC;GAAE,MAAM;GAAW,MAAM;EAAU;EACnC;GAAE,MAAM;GAAe,MAAM;EAAU;CACzC;AACF;AAEA,MAAM,qBAAqB;CACzB,eAAe;CACf,aAAa;EACX;GAAE,MAAM;GAAW,MAAM;EAAkB;EAC3C;GAAE,MAAM;GAAW,MAAM;EAAU;EACnC;GAAE,MAAM;GAAe,MAAM;EAAU;CACzC;AACF;AAEA,SAAS,SAAS,QAA4D;CAC5E,OAAO,CAAC,MAAM,QAAQ,OAAO,OAAO;AACtC;AAEA,SAAgB,oBACd,QACA,gBACA,SACoD;CACpD,0BAAA,UAAUC,0BAAAA,kBAAkB,OAAO,aAAa,2BAA2B;CAE3E,MAAM,SAASC,uBAAAA,cAAc,gBAAgB,OAAO;CACpD,sBAAsB,OAAO,OAAO;CAEpC,OAAO;EACL;EACA,SAAS;CACX;AACF;AAEA,SAAgB,mBACd,QACA,gBACA,SACmD;CACnD,0BAAA,UAAUD,0BAAAA,kBAAkB,OAAO,aAAa,2BAA2B;CAE3E,MAAM,SAASC,uBAAAA,cAAc,gBAAgB,OAAO;CACpD,OAAO,QAAQ,QAAQ,qBAAqB;CAE5C,OAAO;EACL;EACA,SAAS;CACX;AACF;AAEA,SAAgB,cACd,QACA,gBACA,SACoC;CACpC,0BAAA,UAAUD,0BAAAA,kBAAkB,OAAO,aAAa,2BAA2B;CAE3E,MAAM,SAASC,uBAAAA,cAAc,gBAAgB,OAAO;CACpD,IAAI,SAAS,MAAM,GAAG;EACpB,sBAAsB,OAAO,OAAO;EACpC,OAAO;GACL;GACA,OAAO;GACP,SAAS;EACX;CACF;CACA,OAAO,QAAQ,QAAQ,qBAAqB;CAC5C,OAAO;EACL;EACA,OAAO;EACP,SAAS;CACX;AACF;AAEA,SAAgB,KACd,QACA,gBACA,SACQ;CACR,IAAI,SAAS,MAAM,GAAG;EACpB,MAAM,EAAE,QAAQ,YAAY,oBAC1B,QACA,gBACA,OACF;EAEA,QAAA,GAAOC,KAAAA,cAAAA,CAAc;GACnB;GACA,OAAO;GACP,aAAa;GACJ;EACX,CAAC;CACH;CACA,MAAM,EAAE,QAAQ,YAAY,mBAC1B,QACA,gBACA,OACF;CAEA,QAAA,GAAOA,KAAAA,cAAAA,CAAc;EACnB;EACA,OAAO;EACP,aAAa;EACJ;CACX,CAAC;AACH;AAEA,SAAS,sBAAsB,SAAwB;CACrD,0BAAA,UAAU,mBAAmB,QAAQ,OAAO,oBAAoB;CAChE,0BAAA,UAAU,8BAA8B,QAAQ,QAAQ,qBAAqB;CAC7E,0BAAA,UACE,0BAA0B,QAAQ,YAClC,yBACF;AACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SDKClient } from "@lifi/sdk";
|
|
2
|
+
import { Address } from "viem";
|
|
3
|
+
//#region src/permits/canAccountUsePermit2.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether the account can produce a signature Uniswap Permit2 will accept.
|
|
6
|
+
*
|
|
7
|
+
* Permit2's `SignatureVerification.verify` branches on
|
|
8
|
+
* `claimedSigner.code.length`: no code → `ecrecover`, which every EOA satisfies;
|
|
9
|
+
* code → `owner.isValidSignature(...)`, so {@link acceptsRawEcdsaSignature}
|
|
10
|
+
* probes it. Checking code length alone would exclude EIP-7702 accounts that
|
|
11
|
+
* verify our signatures fine, costing those users a needless approval.
|
|
12
|
+
*
|
|
13
|
+
* `false` on RPC failure — approve + execute always works. Same for accounts
|
|
14
|
+
* that *revert* on a signer mismatch (strict 7702 delegates, Sequence): they
|
|
15
|
+
* would accept the real signature but fail the probe, and pay one exact-amount
|
|
16
|
+
* approval per step instead.
|
|
17
|
+
*/
|
|
18
|
+
declare const canAccountUsePermit2: (client: SDKClient, { chainId, address }: {
|
|
19
|
+
chainId: number;
|
|
20
|
+
address: Address;
|
|
21
|
+
}) => Promise<boolean>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { canAccountUsePermit2 };
|
|
24
|
+
//# sourceMappingURL=canAccountUsePermit2.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_client_publicClient = require("../client/publicClient.js");
|
|
3
|
+
const require_actions_getAccountCode = require("../actions/getAccountCode.js");
|
|
4
|
+
let viem = require("viem");
|
|
5
|
+
let viem_actions = require("viem/actions");
|
|
6
|
+
let viem_utils = require("viem/utils");
|
|
7
|
+
//#region src/permits/canAccountUsePermit2.ts
|
|
8
|
+
const ERC1271_ABI = [{
|
|
9
|
+
name: "isValidSignature",
|
|
10
|
+
type: "function",
|
|
11
|
+
stateMutability: "view",
|
|
12
|
+
inputs: [{ type: "bytes32" }, { type: "bytes" }],
|
|
13
|
+
outputs: [{ type: "bytes4" }]
|
|
14
|
+
}];
|
|
15
|
+
/**
|
|
16
|
+
* A real 65-byte signature over {@link PROBE_HASH} from the public key `0x01…01`,
|
|
17
|
+
* recovering to a third party — never the account under test. Throwaway probe
|
|
18
|
+
* value, not a credential.
|
|
19
|
+
*
|
|
20
|
+
* MUST stay recoverable. An unrecoverable signature makes implementations that
|
|
21
|
+
* revert (rather than return a failure value) look like they rejected the
|
|
22
|
+
* envelope, misclassifying accounts that would have accepted ours.
|
|
23
|
+
*/
|
|
24
|
+
const PROBE_HASH = `0x${"ab".repeat(32)}`;
|
|
25
|
+
const PROBE_SIGNATURE = "0x997c61aa10e2330c076d6ba7abca1e71703a8f039291db103a62e085c9b2cf0d3f7e31ec9028229acc83093fbb722fa700fd6e4ea15d584df1bf384eb0051e0d1c";
|
|
26
|
+
/**
|
|
27
|
+
* Asks a code-bearing account the same question Permit2 will: does it evaluate a
|
|
28
|
+
* plain 65-byte ECDSA signature, or reject it outright?
|
|
29
|
+
*
|
|
30
|
+
* - **Returns** → it recovered a signer and found a mismatch, so it will accept
|
|
31
|
+
* the real root-key signature (MetaMask's `EIP7702StatelessDeleGator`).
|
|
32
|
+
* - **Reverts** → it rejected the envelope before recovery and can't validate
|
|
33
|
+
* anything we produce (Alchemy's ERC-6900 `SemiModularAccount7702`).
|
|
34
|
+
*
|
|
35
|
+
* Keyed on revert-vs-return, never on the value returned: the probe signature
|
|
36
|
+
* recovers to a third party on purpose, so a correct implementation must return
|
|
37
|
+
* a *non*-magic value, and comparing against the magic value would reject every
|
|
38
|
+
* wallet this exists to accept. Accepted cost: an implementation that returns
|
|
39
|
+
* failure for *everything* is classified capable and still fails on-chain.
|
|
40
|
+
*/
|
|
41
|
+
const acceptsRawEcdsaSignature = async (client, chainId, address) => {
|
|
42
|
+
try {
|
|
43
|
+
const publicClient = await require_client_publicClient.getPublicClient(client, chainId);
|
|
44
|
+
const { data } = await (0, viem_utils.getAction)({
|
|
45
|
+
...publicClient,
|
|
46
|
+
ccipRead: false
|
|
47
|
+
}, viem_actions.call, "call")({
|
|
48
|
+
to: address,
|
|
49
|
+
data: (0, viem.encodeFunctionData)({
|
|
50
|
+
abi: ERC1271_ABI,
|
|
51
|
+
functionName: "isValidSignature",
|
|
52
|
+
args: [PROBE_HASH, PROBE_SIGNATURE]
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
return !!data && data.length >= 66;
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Whether the account can produce a signature Uniswap Permit2 will accept.
|
|
62
|
+
*
|
|
63
|
+
* Permit2's `SignatureVerification.verify` branches on
|
|
64
|
+
* `claimedSigner.code.length`: no code → `ecrecover`, which every EOA satisfies;
|
|
65
|
+
* code → `owner.isValidSignature(...)`, so {@link acceptsRawEcdsaSignature}
|
|
66
|
+
* probes it. Checking code length alone would exclude EIP-7702 accounts that
|
|
67
|
+
* verify our signatures fine, costing those users a needless approval.
|
|
68
|
+
*
|
|
69
|
+
* `false` on RPC failure — approve + execute always works. Same for accounts
|
|
70
|
+
* that *revert* on a signer mismatch (strict 7702 delegates, Sequence): they
|
|
71
|
+
* would accept the real signature but fail the probe, and pay one exact-amount
|
|
72
|
+
* approval per step instead.
|
|
73
|
+
*/
|
|
74
|
+
const canAccountUsePermit2 = async (client, { chainId, address }) => {
|
|
75
|
+
const code = await require_actions_getAccountCode.getAccountCode({
|
|
76
|
+
client,
|
|
77
|
+
chainId,
|
|
78
|
+
address
|
|
79
|
+
});
|
|
80
|
+
if (code === void 0) return false;
|
|
81
|
+
if (code === "0x") return true;
|
|
82
|
+
return acceptsRawEcdsaSignature(client, chainId, address);
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.canAccountUsePermit2 = canAccountUsePermit2;
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=canAccountUsePermit2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canAccountUsePermit2.js","names":["getPublicClient","getAction","call","encodeFunctionData","getAccountCode"],"sources":["../../../src/permits/canAccountUsePermit2.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport { type Address, encodeFunctionData, type Hex } from 'viem'\nimport { call } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getAccountCode } from '../actions/getAccountCode.js'\nimport { getPublicClient } from '../client/publicClient.js'\n\nconst ERC1271_ABI = [\n {\n name: 'isValidSignature',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ type: 'bytes32' }, { type: 'bytes' }],\n outputs: [{ type: 'bytes4' }],\n },\n] as const\n\n/**\n * A real 65-byte signature over {@link PROBE_HASH} from the public key `0x01…01`,\n * recovering to a third party — never the account under test. Throwaway probe\n * value, not a credential.\n *\n * MUST stay recoverable. An unrecoverable signature makes implementations that\n * revert (rather than return a failure value) look like they rejected the\n * envelope, misclassifying accounts that would have accepted ours.\n */\nconst PROBE_HASH = `0x${'ab'.repeat(32)}` as Hex\nconst PROBE_SIGNATURE =\n '0x997c61aa10e2330c076d6ba7abca1e71703a8f039291db103a62e085c9b2cf0d3f7e31ec9028229acc83093fbb722fa700fd6e4ea15d584df1bf384eb0051e0d1c' as Hex\n\n/**\n * Asks a code-bearing account the same question Permit2 will: does it evaluate a\n * plain 65-byte ECDSA signature, or reject it outright?\n *\n * - **Returns** → it recovered a signer and found a mismatch, so it will accept\n * the real root-key signature (MetaMask's `EIP7702StatelessDeleGator`).\n * - **Reverts** → it rejected the envelope before recovery and can't validate\n * anything we produce (Alchemy's ERC-6900 `SemiModularAccount7702`).\n *\n * Keyed on revert-vs-return, never on the value returned: the probe signature\n * recovers to a third party on purpose, so a correct implementation must return\n * a *non*-magic value, and comparing against the magic value would reject every\n * wallet this exists to accept. Accepted cost: an implementation that returns\n * failure for *everything* is classified capable and still fails on-chain.\n */\nconst acceptsRawEcdsaSignature = async (\n client: SDKClient,\n chainId: number,\n address: Address\n): Promise<boolean> => {\n try {\n const publicClient = await getPublicClient(client, chainId)\n const { data } = await getAction(\n // CCIP-Read off, or an `OffchainLookup` revert comes back as a return and\n // inverts the signal read below. viem gates it on the client, not the\n // call, so clone rather than disable it on the shared ENS-using client.\n // Relies on `getPublicClient` staying bare: add `publicActions` and\n // `getAction` prefers a decorated `client.call`, re-enabling CCIP-Read.\n { ...publicClient, ccipRead: false },\n call,\n 'call'\n )({\n to: address,\n data: encodeFunctionData({\n abi: ERC1271_ABI,\n functionName: 'isValidSignature',\n args: [PROBE_HASH, PROBE_SIGNATURE],\n }),\n })\n // A full 32-byte word (`0x` + 64 chars) or nothing: Permit2 compares against\n // a magic value, so anything shorter can only be a false positive.\n return !!data && data.length >= 66\n } catch {\n // Revert, or an RPC failure we can't tell apart from one. Either way we\n // must not promise Permit2 will work.\n return false\n }\n}\n\n/**\n * Whether the account can produce a signature Uniswap Permit2 will accept.\n *\n * Permit2's `SignatureVerification.verify` branches on\n * `claimedSigner.code.length`: no code → `ecrecover`, which every EOA satisfies;\n * code → `owner.isValidSignature(...)`, so {@link acceptsRawEcdsaSignature}\n * probes it. Checking code length alone would exclude EIP-7702 accounts that\n * verify our signatures fine, costing those users a needless approval.\n *\n * `false` on RPC failure — approve + execute always works. Same for accounts\n * that *revert* on a signer mismatch (strict 7702 delegates, Sequence): they\n * would accept the real signature but fail the probe, and pay one exact-amount\n * approval per step instead.\n */\nexport const canAccountUsePermit2 = async (\n client: SDKClient,\n { chainId, address }: { chainId: number; address: Address }\n): Promise<boolean> => {\n const code = await getAccountCode({ client, chainId, address })\n if (code === undefined) {\n return false\n }\n if (code === '0x') {\n return true\n }\n return acceptsRawEcdsaSignature(client, chainId, address)\n}\n"],"mappings":";;;;;;;AAOA,MAAM,cAAc,CAClB;CACE,MAAM;CACN,MAAM;CACN,iBAAiB;CACjB,QAAQ,CAAC,EAAE,MAAM,UAAU,GAAG,EAAE,MAAM,QAAQ,CAAC;CAC/C,SAAS,CAAC,EAAE,MAAM,SAAS,CAAC;AAC9B,CACF;;;;;;;;;;AAWA,MAAM,aAAa,KAAK,KAAK,OAAO,EAAE;AACtC,MAAM,kBACJ;;;;;;;;;;;;;;;;AAiBF,MAAM,2BAA2B,OAC/B,QACA,SACA,YACqB;CACrB,IAAI;EACF,MAAM,eAAe,MAAMA,4BAAAA,gBAAgB,QAAQ,OAAO;EAC1D,MAAM,EAAE,SAAS,OAAA,GAAMC,WAAAA,UAAAA,CAMrB;GAAE,GAAG;GAAc,UAAU;EAAM,GACnCC,aAAAA,MACA,MACF,CAAC,CAAC;GACA,IAAI;GACJ,OAAA,GAAMC,KAAAA,mBAAAA,CAAmB;IACvB,KAAK;IACL,cAAc;IACd,MAAM,CAAC,YAAY,eAAe;GACpC,CAAC;EACH,CAAC;EAGD,OAAO,CAAC,CAAC,QAAQ,KAAK,UAAU;CAClC,QAAQ;EAGN,OAAO;CACT;AACF;;;;;;;;;;;;;;;AAgBA,MAAa,uBAAuB,OAClC,QACA,EAAE,SAAS,cACU;CACrB,MAAM,OAAO,MAAMC,+BAAAA,eAAe;EAAE;EAAQ;EAAS;CAAQ,CAAC;CAC9D,IAAI,SAAS,KAAA,GACX,OAAO;CAET,IAAI,SAAS,MACX,OAAO;CAET,OAAO,yBAAyB,QAAQ,SAAS,OAAO;AAC1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encodeNativePermitData.js","names":["permit2ProxyAbi"],"sources":["../../../src/permits/encodeNativePermitData.ts"],"sourcesContent":["import type { Address, Hash, Hex } from 'viem'\nimport { encodeFunctionData, parseSignature } from 'viem'\nimport { permit2ProxyAbi } from '../utils/abi.js'\n\nexport const encodeNativePermitData = (\n tokenAddress: Address,\n amount: bigint,\n deadline: bigint,\n signature: Hash,\n transactionData: Hex\n): Hex => {\n const { v, r, s } = parseSignature(signature)\n const data = encodeFunctionData({\n abi: permit2ProxyAbi,\n functionName: 'callDiamondWithEIP2612Signature',\n args: [tokenAddress, amount, deadline, Number(v), r, s, transactionData],\n })\n return data\n}\n"],"mappings":";;;;AAIA,MAAa,0BACX,cACA,QACA,UACA,WACA,oBACQ;CACR,MAAM,EAAE,GAAG,GAAG,OAAA,
|
|
1
|
+
{"version":3,"file":"encodeNativePermitData.js","names":["parseSignature","encodeFunctionData","permit2ProxyAbi"],"sources":["../../../src/permits/encodeNativePermitData.ts"],"sourcesContent":["import type { Address, Hash, Hex } from 'viem'\nimport { encodeFunctionData, parseSignature } from 'viem'\nimport { permit2ProxyAbi } from '../utils/abi.js'\n\nexport const encodeNativePermitData = (\n tokenAddress: Address,\n amount: bigint,\n deadline: bigint,\n signature: Hash,\n transactionData: Hex\n): Hex => {\n const { v, r, s } = parseSignature(signature)\n const data = encodeFunctionData({\n abi: permit2ProxyAbi,\n functionName: 'callDiamondWithEIP2612Signature',\n args: [tokenAddress, amount, deadline, Number(v), r, s, transactionData],\n })\n return data\n}\n"],"mappings":";;;;AAIA,MAAa,0BACX,cACA,QACA,UACA,WACA,oBACQ;CACR,MAAM,EAAE,GAAG,GAAG,OAAA,GAAMA,KAAAA,eAAAA,CAAe,SAAS;CAM5C,QAAA,GALaC,KAAAA,mBAAAA,CAAmB;EAC9B,KAAKC,kBAAAA;EACL,cAAc;EACd,MAAM;GAAC;GAAc;GAAQ;GAAU,OAAO,CAAC;GAAG;GAAG;GAAG;EAAe;CACzE,CACU;AACZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encodePermit2Data.js","names":["permit2ProxyAbi"],"sources":["../../../src/permits/encodePermit2Data.ts"],"sourcesContent":["import type { Address, Hex } from 'viem'\nimport { encodeFunctionData, type Hash } from 'viem'\nimport { permit2ProxyAbi } from '../utils/abi.js'\n\nexport const encodePermit2Data = (\n tokenAddress: Address,\n amount: bigint,\n nonce: bigint,\n deadline: bigint,\n transactionData: Hex,\n signature: Hash,\n accountAddress?: Address,\n witness?: boolean\n): Hex => {\n if (witness && accountAddress) {\n const data = encodeFunctionData({\n abi: permit2ProxyAbi,\n functionName: 'callDiamondWithPermit2Witness',\n args: [\n transactionData,\n accountAddress,\n [[tokenAddress, amount], nonce, deadline],\n signature as Hex,\n ],\n })\n\n return data\n }\n\n const data = encodeFunctionData({\n abi: permit2ProxyAbi,\n functionName: 'callDiamondWithPermit2',\n args: [\n transactionData,\n [[tokenAddress, amount], nonce, deadline],\n signature as Hex,\n ],\n })\n\n return data\n}\n"],"mappings":";;;;AAIA,MAAa,qBACX,cACA,QACA,OACA,UACA,iBACA,WACA,gBACA,YACQ;CACR,IAAI,WAAW,gBAYb,QAAA,
|
|
1
|
+
{"version":3,"file":"encodePermit2Data.js","names":["encodeFunctionData","permit2ProxyAbi"],"sources":["../../../src/permits/encodePermit2Data.ts"],"sourcesContent":["import type { Address, Hex } from 'viem'\nimport { encodeFunctionData, type Hash } from 'viem'\nimport { permit2ProxyAbi } from '../utils/abi.js'\n\nexport const encodePermit2Data = (\n tokenAddress: Address,\n amount: bigint,\n nonce: bigint,\n deadline: bigint,\n transactionData: Hex,\n signature: Hash,\n accountAddress?: Address,\n witness?: boolean\n): Hex => {\n if (witness && accountAddress) {\n const data = encodeFunctionData({\n abi: permit2ProxyAbi,\n functionName: 'callDiamondWithPermit2Witness',\n args: [\n transactionData,\n accountAddress,\n [[tokenAddress, amount], nonce, deadline],\n signature as Hex,\n ],\n })\n\n return data\n }\n\n const data = encodeFunctionData({\n abi: permit2ProxyAbi,\n functionName: 'callDiamondWithPermit2',\n args: [\n transactionData,\n [[tokenAddress, amount], nonce, deadline],\n signature as Hex,\n ],\n })\n\n return data\n}\n"],"mappings":";;;;AAIA,MAAa,qBACX,cACA,QACA,OACA,UACA,iBACA,WACA,gBACA,YACQ;CACR,IAAI,WAAW,gBAYb,QAAA,GAXaA,KAAAA,mBAAAA,CAAmB;EAC9B,KAAKC,kBAAAA;EACL,cAAc;EACd,MAAM;GACJ;GACA;GACA;IAAC,CAAC,cAAc,MAAM;IAAG;IAAO;GAAQ;GACxC;EACF;CACF,CAEU;CAaZ,QAAA,GAVaD,KAAAA,mBAAAA,CAAmB;EAC9B,KAAKC,kBAAAA;EACL,cAAc;EACd,MAAM;GACJ;GACA;IAAC,CAAC,cAAc,MAAM;IAAG;IAAO;GAAQ;GACxC;EACF;CACF,CAEU;AACZ"}
|
|
@@ -10,7 +10,7 @@ let viem_actions = require("viem/actions");
|
|
|
10
10
|
function makeDomainSeparator({ name, version, chainId, verifyingContract, withSalt = false }) {
|
|
11
11
|
const nameHash = (0, viem.keccak256)((0, viem.toBytes)(name));
|
|
12
12
|
const versionHash = (0, viem.keccak256)((0, viem.toBytes)(version));
|
|
13
|
-
|
|
13
|
+
const encoded = withSalt ? (0, viem.encodeAbiParameters)((0, viem.parseAbiParameters)("bytes32, bytes32, bytes32, address, bytes32"), [
|
|
14
14
|
require_permits_constants.EIP712_DOMAIN_TYPEHASH_WITH_SALT,
|
|
15
15
|
nameHash,
|
|
16
16
|
versionHash,
|
|
@@ -22,7 +22,8 @@ function makeDomainSeparator({ name, version, chainId, verifyingContract, withSa
|
|
|
22
22
|
versionHash,
|
|
23
23
|
BigInt(chainId),
|
|
24
24
|
verifyingContract
|
|
25
|
-
])
|
|
25
|
+
]);
|
|
26
|
+
return (0, viem.keccak256)(encoded);
|
|
26
27
|
}
|
|
27
28
|
function validateDomainSeparator({ name, version, chainId, verifyingContract, domainSeparator }) {
|
|
28
29
|
if (!name || !domainSeparator) return {
|