@lifi/sdk-provider-ethereum 4.0.12 → 4.0.14

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/actions/checkPermitSupport.js +2 -1
  3. package/dist/cjs/actions/checkPermitSupport.js.map +1 -1
  4. package/dist/cjs/core/tasks/EthereumNativePermitTask.js +2 -1
  5. package/dist/cjs/core/tasks/EthereumNativePermitTask.js.map +1 -1
  6. package/dist/cjs/permits/acceptsRawEcdsaSignature.d.ts +18 -0
  7. package/dist/cjs/permits/acceptsRawEcdsaSignature.js +58 -0
  8. package/dist/cjs/permits/acceptsRawEcdsaSignature.js.map +1 -0
  9. package/dist/cjs/permits/canAccountUseNativePermits.d.ts +28 -6
  10. package/dist/cjs/permits/canAccountUseNativePermits.js +30 -10
  11. package/dist/cjs/permits/canAccountUseNativePermits.js.map +1 -1
  12. package/dist/cjs/permits/canAccountUsePermit2.js +2 -57
  13. package/dist/cjs/permits/canAccountUsePermit2.js.map +1 -1
  14. package/dist/cjs/permits/getNativePermit.d.ts +7 -1
  15. package/dist/cjs/permits/getNativePermit.js +12 -9
  16. package/dist/cjs/permits/getNativePermit.js.map +1 -1
  17. package/dist/cjs/version.d.ts +1 -1
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/cjs/version.js.map +1 -1
  20. package/dist/esm/actions/checkPermitSupport.js +2 -1
  21. package/dist/esm/actions/checkPermitSupport.js.map +1 -1
  22. package/dist/esm/core/tasks/EthereumNativePermitTask.js +2 -1
  23. package/dist/esm/core/tasks/EthereumNativePermitTask.js.map +1 -1
  24. package/dist/esm/permits/acceptsRawEcdsaSignature.d.ts +18 -0
  25. package/dist/esm/permits/acceptsRawEcdsaSignature.d.ts.map +1 -0
  26. package/dist/esm/permits/acceptsRawEcdsaSignature.js +57 -0
  27. package/dist/esm/permits/acceptsRawEcdsaSignature.js.map +1 -0
  28. package/dist/esm/permits/canAccountUseNativePermits.d.ts +28 -6
  29. package/dist/esm/permits/canAccountUseNativePermits.d.ts.map +1 -1
  30. package/dist/esm/permits/canAccountUseNativePermits.js +30 -10
  31. package/dist/esm/permits/canAccountUseNativePermits.js.map +1 -1
  32. package/dist/esm/permits/canAccountUsePermit2.d.ts.map +1 -1
  33. package/dist/esm/permits/canAccountUsePermit2.js +1 -56
  34. package/dist/esm/permits/canAccountUsePermit2.js.map +1 -1
  35. package/dist/esm/permits/getNativePermit.d.ts +7 -1
  36. package/dist/esm/permits/getNativePermit.d.ts.map +1 -1
  37. package/dist/esm/permits/getNativePermit.js +12 -9
  38. package/dist/esm/permits/getNativePermit.js.map +1 -1
  39. package/dist/esm/version.d.ts +1 -1
  40. package/dist/esm/version.js +1 -1
  41. package/dist/esm/version.js.map +1 -1
  42. package/package.json +3 -3
  43. package/src/actions/checkPermitSupport.ts +8 -2
  44. package/src/core/tasks/EthereumNativePermitTask.ts +1 -0
  45. package/src/permits/acceptsRawEcdsaSignature.ts +73 -0
  46. package/src/permits/canAccountUseNativePermits.ts +38 -18
  47. package/src/permits/canAccountUsePermit2.ts +2 -76
  48. package/src/permits/getNativePermit.ts +23 -9
  49. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"checkPermitSupport.js","names":[],"sources":["../../../src/actions/checkPermitSupport.ts"],"sourcesContent":["import { ChainType, type ExtendedChain, type SDKClient } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { getPublicClient } from '../client/publicClient.js'\nimport { canAccountUsePermit2 } from '../permits/canAccountUsePermit2.js'\nimport { getNativePermit } from '../permits/getNativePermit.js'\nimport type { EthereumSDKProvider } from '../types.js'\nimport { getActionWithFallback } from '../utils/getActionWithFallback.js'\nimport { getAllowance } from './getAllowance.js'\n\ntype PermitSupport = {\n /** Whether the token supports EIP-2612 native permits */\n nativePermitSupported: boolean\n /** Whether Permit2 is available and has sufficient allowance */\n permit2AllowanceSufficient: boolean\n}\n\n/**\n * Checks what permit types are *usable* for a token on a specific chain.\n * Checks in order:\n * 1. Native permit (EIP-2612) support\n * 2. Permit2 — deployed on the chain, signable by the owner (see\n * `canAccountUsePermit2`), and allowance sufficient\n *\n * @param client - The SDK client\n * @param chain - The chain to check permit support on\n * @param tokenAddress - The token address to check\n * @param ownerAddress - The address that would sign the permit\n * @param amount - The amount to check allowance against for Permit2\n * @returns Object indicating which permit types are supported\n */\nexport const checkPermitSupport = async (\n client: SDKClient,\n {\n chain,\n tokenAddress,\n ownerAddress,\n amount,\n }: {\n chain: ExtendedChain\n tokenAddress: Address\n ownerAddress: Address\n amount: bigint\n }\n): Promise<PermitSupport> => {\n const provider = client.getProvider(ChainType.EVM) as\n | EthereumSDKProvider\n | undefined\n let viemClient = await provider?.getWalletClient?.()\n\n if (!viemClient) {\n viemClient = await getPublicClient(client, chain.id)\n }\n\n const nativePermit = await getActionWithFallback(\n client,\n viemClient,\n getNativePermit,\n 'getNativePermit',\n {\n client,\n viemClient,\n chainId: chain.id,\n tokenAddress,\n spenderAddress: chain.permit2Proxy as Address,\n amount,\n }\n )\n\n let permit2Allowance: bigint | undefined\n // Only read the allowance if the owner can sign for it: Permit2 may reject a\n // code-bearing account via EIP-1271, making any allowance unusable.\n if (\n chain.permit2 &&\n (await canAccountUsePermit2(client, {\n chainId: chain.id,\n address: ownerAddress,\n }))\n ) {\n permit2Allowance = await getAllowance(\n client,\n viemClient,\n tokenAddress,\n ownerAddress,\n chain.permit2 as Address\n )\n }\n\n return {\n nativePermitSupported: !!nativePermit,\n permit2AllowanceSufficient:\n !!permit2Allowance && permit2Allowance >= amount,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,qBAAqB,OAChC,QACA,EACE,OACA,cACA,cACA,aAOyB;CAI3B,IAAI,aAAa,MAHA,OAAO,YAAY,UAAU,GAGhB,CAAC,EAAE,kBAAkB;CAEnD,IAAI,CAAC,YACH,aAAa,MAAM,gBAAgB,QAAQ,MAAM,EAAE;CAGrD,MAAM,eAAe,MAAM,sBACzB,QACA,YACA,iBACA,mBACA;EACE;EACA;EACA,SAAS,MAAM;EACf;EACA,gBAAgB,MAAM;EACtB;CACF,CACF;CAEA,IAAI;CAGJ,IACE,MAAM,WACL,MAAM,qBAAqB,QAAQ;EAClC,SAAS,MAAM;EACf,SAAS;CACX,CAAC,GAED,mBAAmB,MAAM,aACvB,QACA,YACA,cACA,cACA,MAAM,OACR;CAGF,OAAO;EACL,uBAAuB,CAAC,CAAC;EACzB,4BACE,CAAC,CAAC,oBAAoB,oBAAoB;CAC9C;AACF"}
1
+ {"version":3,"file":"checkPermitSupport.js","names":[],"sources":["../../../src/actions/checkPermitSupport.ts"],"sourcesContent":["import { ChainType, type ExtendedChain, type SDKClient } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { getPublicClient } from '../client/publicClient.js'\nimport { canAccountUsePermit2 } from '../permits/canAccountUsePermit2.js'\nimport { getNativePermit } from '../permits/getNativePermit.js'\nimport type { EthereumSDKProvider } from '../types.js'\nimport { getActionWithFallback } from '../utils/getActionWithFallback.js'\nimport { getAllowance } from './getAllowance.js'\n\ntype PermitSupport = {\n /** Whether the token supports EIP-2612 native permits */\n nativePermitSupported: boolean\n /** Whether Permit2 is available and has sufficient allowance */\n permit2AllowanceSufficient: boolean\n}\n\n/**\n * Checks what permit types are *usable* for a token on a specific chain.\n * Checks in order:\n * 1. Native permit (EIP-2612) support\n * 2. Permit2 — deployed on the chain, signable by the owner (see\n * `canAccountUsePermit2`), and allowance sufficient\n *\n * @param client - The SDK client\n * @param chain - The chain to check permit support on\n * @param tokenAddress - The token address to check\n * @param ownerAddress - The address that would sign the permit\n * @param amount - The amount to check allowance against for Permit2\n * @returns Object indicating which permit types are supported\n */\nexport const checkPermitSupport = async (\n client: SDKClient,\n {\n chain,\n tokenAddress,\n ownerAddress,\n amount,\n }: {\n chain: ExtendedChain\n tokenAddress: Address\n ownerAddress: Address\n amount: bigint\n }\n): Promise<PermitSupport> => {\n const provider = client.getProvider(ChainType.EVM) as\n | EthereumSDKProvider\n | undefined\n let viemClient = await provider?.getWalletClient?.()\n\n if (!viemClient) {\n viemClient = await getPublicClient(client, chain.id)\n }\n\n const nativePermit = await getActionWithFallback(\n client,\n viemClient,\n getNativePermit,\n 'getNativePermit',\n {\n client,\n viemClient,\n chainId: chain.id,\n tokenAddress,\n spenderAddress: chain.permit2Proxy as Address,\n amount,\n ownerAddress,\n }\n )\n\n let permit2Allowance: bigint | undefined\n // Only read the allowance if the owner can sign for it: Permit2 may reject an\n // account with code via EIP-1271, making any allowance unusable.\n //\n // An EIP-7702 owner is probed twice here, once per gate. The two run\n // sequentially, so `withDedupe` would not collapse them, and caching the\n // verdict would defeat the deliberate freshness of `getAccountCode`. Two\n // `eth_call`s on an already multi-RPC action is the cheaper trade.\n if (\n chain.permit2 &&\n (await canAccountUsePermit2(client, {\n chainId: chain.id,\n address: ownerAddress,\n }))\n ) {\n permit2Allowance = await getAllowance(\n client,\n viemClient,\n tokenAddress,\n ownerAddress,\n chain.permit2 as Address\n )\n }\n\n return {\n nativePermitSupported: !!nativePermit,\n permit2AllowanceSufficient:\n !!permit2Allowance && permit2Allowance >= amount,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,qBAAqB,OAChC,QACA,EACE,OACA,cACA,cACA,aAOyB;CAI3B,IAAI,aAAa,MAHA,OAAO,YAAY,UAAU,GAGhB,CAAC,EAAE,kBAAkB;CAEnD,IAAI,CAAC,YACH,aAAa,MAAM,gBAAgB,QAAQ,MAAM,EAAE;CAGrD,MAAM,eAAe,MAAM,sBACzB,QACA,YACA,iBACA,mBACA;EACE;EACA;EACA,SAAS,MAAM;EACf;EACA,gBAAgB,MAAM;EACtB;EACA;CACF,CACF;CAEA,IAAI;CAQJ,IACE,MAAM,WACL,MAAM,qBAAqB,QAAQ;EAClC,SAAS,MAAM;EACf,SAAS;CACX,CAAC,GAED,mBAAmB,MAAM,aACvB,QACA,YACA,cACA,cACA,MAAM,OACR;CAGF,OAAO;EACL,uBAAuB,CAAC,CAAC;EACzB,4BACE,CAAC,CAAC,oBAAoB,oBAAoB;CAC9C;AACF"}
@@ -31,7 +31,8 @@ var EthereumNativePermitTask = class extends BaseStepExecutionTask {
31
31
  chainId: fromChain.id,
32
32
  tokenAddress: step.action.fromToken.address,
33
33
  spenderAddress: fromChain.permit2Proxy,
34
- amount: fromAmount
34
+ amount: fromAmount,
35
+ ownerAddress: updatedClient.account.address
35
36
  });
36
37
  if (!nativePermitData) {
37
38
  statusManager.updateAction(step, action.type, "DONE");
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumNativePermitTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumNativePermitTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type SignedTypedData,\n type TaskResult,\n} from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getNativePermit } from '../../permits/getNativePermit.js'\nimport { isNativePermitValid } from '../../permits/isNativePermitValid.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getActionWithFallback } from '../../utils/getActionWithFallback.js'\nimport { isValidSignature } from '../../utils/isValidSignature.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\n\nexport class EthereumNativePermitTask extends BaseStepExecutionTask {\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n const {\n step,\n fromChain,\n hasMatchingPermit,\n hasSufficientAllowance,\n disableMessageSigning,\n } = context\n\n if (hasMatchingPermit || hasSufficientAllowance) {\n return false\n }\n\n const executionStrategy = await getEthereumExecutionStrategy(context)\n const batchingSupported = executionStrategy === 'batched'\n // Check if proxy contract is available and message signing is not disabled, also not available for atomic batch\n const isNativePermitAvailable =\n !!fromChain.permit2Proxy &&\n !batchingSupported &&\n !disableMessageSigning &&\n !step.estimate.skipPermit\n return isNativePermitAvailable\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n fromChain,\n statusManager,\n allowUserInteraction,\n checkClient,\n signedTypedData: currentSignedTypedData,\n } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'NATIVE_PERMIT',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const fromAmount = BigInt(step.action.fromAmount)\n\n const nativePermitData = await getActionWithFallback(\n client,\n updatedClient,\n getNativePermit,\n 'getNativePermit',\n {\n client,\n viemClient: updatedClient,\n chainId: fromChain.id,\n tokenAddress: step.action.fromToken.address as Address,\n spenderAddress: fromChain.permit2Proxy as Address,\n amount: fromAmount,\n }\n )\n\n if (!nativePermitData) {\n statusManager.updateAction(step, action.type, 'DONE')\n return { status: 'COMPLETED' }\n }\n\n const signedTypedData = [...currentSignedTypedData]\n\n // Check if we already have a valid permit for this chain and requirements\n const signedTypedDataForChain = signedTypedData.find((signedTypedData) =>\n isNativePermitValid(signedTypedData, nativePermitData)\n )\n\n if (!signedTypedDataForChain) {\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n // Sign the permit\n const signature = await getAction(\n updatedClient,\n signTypedData,\n 'signTypedData'\n )({\n account: updatedClient.account!,\n domain: nativePermitData.domain,\n types: nativePermitData.types,\n primaryType: nativePermitData.primaryType,\n message: nativePermitData.message,\n })\n\n // Some wallets resolve signTypedData with a nullish or empty value\n // instead of rejecting — skip the permit and fall back to the\n // Permit2/standard approval flow\n if (!isValidSignature(signature)) {\n statusManager.updateAction(step, action.type, 'DONE')\n return { status: 'COMPLETED' }\n }\n\n // Add the new permit to the signed permits array\n const signedPermit: SignedTypedData = {\n ...nativePermitData,\n signature,\n }\n signedTypedData.push(signedPermit)\n }\n\n statusManager.updateAction(step, action.type, 'DONE')\n\n return {\n status: 'COMPLETED',\n context: { signedTypedData, hasMatchingPermit: true },\n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,aAAa,iBAAiB;IAC9B,SAAS,iBAAiB;GAC5B,CAAC;GAKD,IAAI,CAAC,iBAAiB,SAAS,GAAG;IAChC,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;IACpD,OAAO,EAAE,QAAQ,YAAY;GAC/B;GAGA,MAAM,eAAgC;IACpC,GAAG;IACH;GACF;GACA,gBAAgB,KAAK,YAAY;EACnC;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAEpD,OAAO;GACL,QAAQ;GACR,SAAS;IAAE;IAAiB,mBAAmB;GAAK;EACtD;CACF;AACF"}
1
+ {"version":3,"file":"EthereumNativePermitTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumNativePermitTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type SignedTypedData,\n type TaskResult,\n} from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getNativePermit } from '../../permits/getNativePermit.js'\nimport { isNativePermitValid } from '../../permits/isNativePermitValid.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getActionWithFallback } from '../../utils/getActionWithFallback.js'\nimport { isValidSignature } from '../../utils/isValidSignature.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\n\nexport class EthereumNativePermitTask extends BaseStepExecutionTask {\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n const {\n step,\n fromChain,\n hasMatchingPermit,\n hasSufficientAllowance,\n disableMessageSigning,\n } = context\n\n if (hasMatchingPermit || hasSufficientAllowance) {\n return false\n }\n\n const executionStrategy = await getEthereumExecutionStrategy(context)\n const batchingSupported = executionStrategy === 'batched'\n // Check if proxy contract is available and message signing is not disabled, also not available for atomic batch\n const isNativePermitAvailable =\n !!fromChain.permit2Proxy &&\n !batchingSupported &&\n !disableMessageSigning &&\n !step.estimate.skipPermit\n return isNativePermitAvailable\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n fromChain,\n statusManager,\n allowUserInteraction,\n checkClient,\n signedTypedData: currentSignedTypedData,\n } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'NATIVE_PERMIT',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const fromAmount = BigInt(step.action.fromAmount)\n\n const nativePermitData = await getActionWithFallback(\n client,\n updatedClient,\n getNativePermit,\n 'getNativePermit',\n {\n client,\n viemClient: updatedClient,\n chainId: fromChain.id,\n tokenAddress: step.action.fromToken.address as Address,\n spenderAddress: fromChain.permit2Proxy as Address,\n amount: fromAmount,\n ownerAddress: updatedClient.account!.address,\n }\n )\n\n if (!nativePermitData) {\n statusManager.updateAction(step, action.type, 'DONE')\n return { status: 'COMPLETED' }\n }\n\n const signedTypedData = [...currentSignedTypedData]\n\n // Check if we already have a valid permit for this chain and requirements\n const signedTypedDataForChain = signedTypedData.find((signedTypedData) =>\n isNativePermitValid(signedTypedData, nativePermitData)\n )\n\n if (!signedTypedDataForChain) {\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n // Sign the permit\n const signature = await getAction(\n updatedClient,\n signTypedData,\n 'signTypedData'\n )({\n account: updatedClient.account!,\n domain: nativePermitData.domain,\n types: nativePermitData.types,\n primaryType: nativePermitData.primaryType,\n message: nativePermitData.message,\n })\n\n // Some wallets resolve signTypedData with a nullish or empty value\n // instead of rejecting — skip the permit and fall back to the\n // Permit2/standard approval flow\n if (!isValidSignature(signature)) {\n statusManager.updateAction(step, action.type, 'DONE')\n return { status: 'COMPLETED' }\n }\n\n // Add the new permit to the signed permits array\n const signedPermit: SignedTypedData = {\n ...nativePermitData,\n signature,\n }\n signedTypedData.push(signedPermit)\n }\n\n statusManager.updateAction(step, action.type, 'DONE')\n\n return {\n status: 'COMPLETED',\n context: { signed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IACvB,QAAQ,iBAAiB;IACzB,OAAO,iBAAiB;IACxB,aAAa,iBAAiB;IAC9B,SAAS,iBAAiB;GAC5B,CAAC;GAKD,IAAI,CAAC,iBAAiB,SAAS,GAAG;IAChC,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;IACpD,OAAO,EAAE,QAAQ,YAAY;GAC/B;GAGA,MAAM,eAAgC;IACpC,GAAG;IACH;GACF;GACA,gBAAgB,KAAK,YAAY;EACnC;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAEpD,OAAO;GACL,QAAQ;GACR,SAAS;IAAE;IAAiB,mBAAmB;GAAK;EACtD;CACF;AACF"}
@@ -0,0 +1,18 @@
1
+ import { SDKClient } from "@lifi/sdk";
2
+ import { Address } from "viem";
3
+ //#region src/permits/acceptsRawEcdsaSignature.d.ts
4
+ /**
5
+ * Asks an account with code whether it evaluates a plain 65-byte ECDSA
6
+ * signature: a return means it recovered a signer and merely found a mismatch,
7
+ * so the real root-key signature will verify, while a revert means it rejected
8
+ * the envelope and nothing we produce will. Keyed on revert-vs-return, never on
9
+ * the value — the probe signature recovers to a third party on purpose, so a
10
+ * correct implementation returns a *non*-magic value, and comparing against the
11
+ * magic value would reject every wallet this exists to accept. Only call it for
12
+ * accounts that have code; a code-less address returns empty data and would read
13
+ * as incapable.
14
+ */
15
+ declare const acceptsRawEcdsaSignature: (client: SDKClient, chainId: number, address: Address) => Promise<boolean>;
16
+ //#endregion
17
+ export { acceptsRawEcdsaSignature };
18
+ //# sourceMappingURL=acceptsRawEcdsaSignature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acceptsRawEcdsaSignature.d.ts","names":[],"sources":["../../../src/permits/acceptsRawEcdsaSignature.ts"],"mappings":";;;;;;;;;;;;;;cAwCa,2BACX,QAAQ,WACR,iBACA,SAAS,YACR"}
@@ -0,0 +1,57 @@
1
+ import { getPublicClient } from "../client/publicClient.js";
2
+ import { encodeFunctionData } from "viem";
3
+ import { call } from "viem/actions";
4
+ import { getAction } from "viem/utils";
5
+ //#region src/permits/acceptsRawEcdsaSignature.ts
6
+ const ERC1271_ABI = [{
7
+ name: "isValidSignature",
8
+ type: "function",
9
+ stateMutability: "view",
10
+ inputs: [{ type: "bytes32" }, { type: "bytes" }],
11
+ outputs: [{ type: "bytes4" }]
12
+ }];
13
+ /**
14
+ * A real 65-byte signature over {@link PROBE_HASH} from the public key `0x01…01`,
15
+ * recovering to a third party — never the account under test. Throwaway probe
16
+ * value, not a credential.
17
+ *
18
+ * MUST stay recoverable. An unrecoverable signature makes implementations that
19
+ * revert (rather than return a failure value) look like they rejected the
20
+ * envelope, misclassifying accounts that would have accepted ours.
21
+ */
22
+ const PROBE_HASH = `0x${"ab".repeat(32)}`;
23
+ const PROBE_SIGNATURE = "0x997c61aa10e2330c076d6ba7abca1e71703a8f039291db103a62e085c9b2cf0d3f7e31ec9028229acc83093fbb722fa700fd6e4ea15d584df1bf384eb0051e0d1c";
24
+ /**
25
+ * Asks an account with code whether it evaluates a plain 65-byte ECDSA
26
+ * signature: a return means it recovered a signer and merely found a mismatch,
27
+ * so the real root-key signature will verify, while a revert means it rejected
28
+ * the envelope and nothing we produce will. Keyed on revert-vs-return, never on
29
+ * the value — the probe signature recovers to a third party on purpose, so a
30
+ * correct implementation returns a *non*-magic value, and comparing against the
31
+ * magic value would reject every wallet this exists to accept. Only call it for
32
+ * accounts that have code; a code-less address returns empty data and would read
33
+ * as incapable.
34
+ */
35
+ const acceptsRawEcdsaSignature = async (client, chainId, address) => {
36
+ try {
37
+ const publicClient = await getPublicClient(client, chainId);
38
+ const { data } = await getAction({
39
+ ...publicClient,
40
+ ccipRead: false
41
+ }, call, "call")({
42
+ to: address,
43
+ data: encodeFunctionData({
44
+ abi: ERC1271_ABI,
45
+ functionName: "isValidSignature",
46
+ args: [PROBE_HASH, PROBE_SIGNATURE]
47
+ })
48
+ });
49
+ return !!data && data.length >= 66;
50
+ } catch {
51
+ return false;
52
+ }
53
+ };
54
+ //#endregion
55
+ export { acceptsRawEcdsaSignature };
56
+
57
+ //# sourceMappingURL=acceptsRawEcdsaSignature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acceptsRawEcdsaSignature.js","names":[],"sources":["../../../src/permits/acceptsRawEcdsaSignature.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 { 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 an account with code whether it evaluates a plain 65-byte ECDSA\n * signature: a return means it recovered a signer and merely found a mismatch,\n * so the real root-key signature will verify, while a revert means it rejected\n * the envelope and nothing we produce will. Keyed on revert-vs-return, never on\n * the value — the probe signature recovers to a third party on purpose, so a\n * correct implementation returns a *non*-magic value, and comparing against the\n * magic value would reject every wallet this exists to accept. Only call it for\n * accounts that have code; a code-less address returns empty data and would read\n * as incapable.\n */\nexport const 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: verifiers compare 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 the signature will verify.\n return false\n }\n}\n"],"mappings":";;;;;AAMA,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;;;;;;;;;;;;AAaF,MAAa,2BAA2B,OACtC,QACA,SACA,YACqB;CACrB,IAAI;EACF,MAAM,eAAe,MAAM,gBAAgB,QAAQ,OAAO;EAC1D,MAAM,EAAE,SAAS,MAAM,UAMrB;GAAE,GAAG;GAAc,UAAU;EAAM,GACnC,MACA,MACF,CAAC,CAAC;GACA,IAAI;GACJ,MAAM,mBAAmB;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"}
@@ -1,13 +1,35 @@
1
1
  import { SDKClient } from "@lifi/sdk";
2
- import { Client } from "viem";
2
+ import { Address } from "viem";
3
3
  //#region src/permits/canAccountUseNativePermits.d.ts
4
4
  /**
5
- * Whether the account can use native EIP-2612 permits — true for EOAs and
6
- * EIP-7702 delegated EOAs (both produce ECDSA signatures), false for
7
- * smart-contract wallets. Conservatively false on missing chain id or RPC
8
- * failure ("if unsure, don't use permits").
5
+ * Whether the account can produce a signature an EIP-2612 `permit` will accept.
6
+ *
7
+ * Signing ECDSA is not the question — verification is. Tokens whose `permit`
8
+ * routes through a `SignatureChecker` branch on `owner.code.length` exactly as
9
+ * Permit2 does, so an owner with code takes the EIP-1271 path where strict
10
+ * delegates reject a bare signature (Circle's `FiatTokenV2_2`, i.e. USDC), hence
11
+ * the {@link acceptsRawEcdsaSignature} probe for EIP-7702 delegates.
12
+ *
13
+ * Other contract accounts stay blocked on shape alone and are never probed.
14
+ * `encodeNativePermitData` splits the signature with `parseSignature`, so this
15
+ * path needs 65 ECDSA bytes — which a 7702 delegate signing with its root key
16
+ * always produces, and a contract wallet generally does not. Probing them would
17
+ * admit any implementation that *returns* a failure value rather than reverting,
18
+ * skip the approval, then throw after the user had already signed.
19
+ *
20
+ * The probe describes the account while the verifier lives in the token, so a
21
+ * strict delegate spending a plain-`ecrecover` token is refused a permit it
22
+ * could have used — an approval rather than a revert, and the token's path is
23
+ * not reliably introspectable. `false` on RPC failure.
24
+ *
25
+ * Takes the chain and owner explicitly, mirroring {@link canAccountUsePermit2}:
26
+ * reading them off a wallet client silently reported "no native permit" for
27
+ * every caller that falls back to a public client.
9
28
  */
10
- declare const canAccountUseNativePermits: (client: SDKClient, viemClient: Client) => Promise<boolean>;
29
+ declare const canAccountUseNativePermits: (client: SDKClient, { chainId, address }: {
30
+ chainId: number;
31
+ address: Address;
32
+ }) => Promise<boolean>;
11
33
  //#endregion
12
34
  export { canAccountUseNativePermits };
13
35
  //# sourceMappingURL=canAccountUseNativePermits.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"canAccountUseNativePermits.d.ts","names":[],"sources":["../../../src/permits/canAccountUseNativePermits.ts"],"mappings":";;;;;;;;;cAWa,6BACX,QAAQ,WACR,YAAY,WACX"}
1
+ {"version":3,"file":"canAccountUseNativePermits.d.ts","names":[],"sources":["../../../src/permits/canAccountUseNativePermits.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+Ba,6BACX,QAAQ,aACN,SAAS;EAAa;EAAiB,SAAS;MACjD"}
@@ -1,22 +1,42 @@
1
1
  import { getAccountCode } from "../actions/getAccountCode.js";
2
- import { isSmartContractWalletCode } from "../actions/isSmartContractWallet.js";
2
+ import { acceptsRawEcdsaSignature } from "./acceptsRawEcdsaSignature.js";
3
+ import { isDelegationDesignatorCode } from "./isDelegationDesignatorCode.js";
3
4
  //#region src/permits/canAccountUseNativePermits.ts
4
5
  /**
5
- * Whether the account can use native EIP-2612 permits — true for EOAs and
6
- * EIP-7702 delegated EOAs (both produce ECDSA signatures), false for
7
- * smart-contract wallets. Conservatively false on missing chain id or RPC
8
- * failure ("if unsure, don't use permits").
6
+ * Whether the account can produce a signature an EIP-2612 `permit` will accept.
7
+ *
8
+ * Signing ECDSA is not the question — verification is. Tokens whose `permit`
9
+ * routes through a `SignatureChecker` branch on `owner.code.length` exactly as
10
+ * Permit2 does, so an owner with code takes the EIP-1271 path where strict
11
+ * delegates reject a bare signature (Circle's `FiatTokenV2_2`, i.e. USDC), hence
12
+ * the {@link acceptsRawEcdsaSignature} probe for EIP-7702 delegates.
13
+ *
14
+ * Other contract accounts stay blocked on shape alone and are never probed.
15
+ * `encodeNativePermitData` splits the signature with `parseSignature`, so this
16
+ * path needs 65 ECDSA bytes — which a 7702 delegate signing with its root key
17
+ * always produces, and a contract wallet generally does not. Probing them would
18
+ * admit any implementation that *returns* a failure value rather than reverting,
19
+ * skip the approval, then throw after the user had already signed.
20
+ *
21
+ * The probe describes the account while the verifier lives in the token, so a
22
+ * strict delegate spending a plain-`ecrecover` token is refused a permit it
23
+ * could have used — an approval rather than a revert, and the token's path is
24
+ * not reliably introspectable. `false` on RPC failure.
25
+ *
26
+ * Takes the chain and owner explicitly, mirroring {@link canAccountUsePermit2}:
27
+ * reading them off a wallet client silently reported "no native permit" for
28
+ * every caller that falls back to a public client.
9
29
  */
10
- const canAccountUseNativePermits = async (client, viemClient) => {
11
- const chainId = viemClient.chain?.id;
12
- if (chainId === void 0) return false;
30
+ const canAccountUseNativePermits = async (client, { chainId, address }) => {
13
31
  const code = await getAccountCode({
14
32
  client,
15
33
  chainId,
16
- address: viemClient.account.address
34
+ address
17
35
  });
18
36
  if (code === void 0) return false;
19
- return !isSmartContractWalletCode(code);
37
+ if (code === "0x") return true;
38
+ if (!isDelegationDesignatorCode(code)) return false;
39
+ return acceptsRawEcdsaSignature(client, chainId, address);
20
40
  };
21
41
  //#endregion
22
42
  export { canAccountUseNativePermits };
@@ -1 +1 @@
1
- {"version":3,"file":"canAccountUseNativePermits.js","names":[],"sources":["../../../src/permits/canAccountUseNativePermits.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport type { Client } from 'viem'\nimport { getAccountCode } from '../actions/getAccountCode.js'\nimport { isSmartContractWalletCode } from '../actions/isSmartContractWallet.js'\n\n/**\n * Whether the account can use native EIP-2612 permits — true for EOAs and\n * EIP-7702 delegated EOAs (both produce ECDSA signatures), false for\n * smart-contract wallets. Conservatively false on missing chain id or RPC\n * failure (\"if unsure, don't use permits\").\n */\nexport const canAccountUseNativePermits = async (\n client: SDKClient,\n viemClient: Client\n): Promise<boolean> => {\n const chainId = viemClient.chain?.id\n if (chainId === undefined) {\n return false\n }\n const code = await getAccountCode({\n client,\n chainId,\n address: viemClient.account!.address,\n })\n // Load-bearing: without this guard, `!isSmartContractWalletCode(undefined)`\n // would flip RPC failure from \"no permits\" to \"use permits\" (regression).\n if (code === undefined) {\n return false\n }\n return !isSmartContractWalletCode(code)\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,6BAA6B,OACxC,QACA,eACqB;CACrB,MAAM,UAAU,WAAW,OAAO;CAClC,IAAI,YAAY,KAAA,GACd,OAAO;CAET,MAAM,OAAO,MAAM,eAAe;EAChC;EACA;EACA,SAAS,WAAW,QAAS;CAC/B,CAAC;CAGD,IAAI,SAAS,KAAA,GACX,OAAO;CAET,OAAO,CAAC,0BAA0B,IAAI;AACxC"}
1
+ {"version":3,"file":"canAccountUseNativePermits.js","names":[],"sources":["../../../src/permits/canAccountUseNativePermits.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { getAccountCode } from '../actions/getAccountCode.js'\nimport { acceptsRawEcdsaSignature } from './acceptsRawEcdsaSignature.js'\nimport { isDelegationDesignatorCode } from './isDelegationDesignatorCode.js'\n\n/**\n * Whether the account can produce a signature an EIP-2612 `permit` will accept.\n *\n * Signing ECDSA is not the question — verification is. Tokens whose `permit`\n * routes through a `SignatureChecker` branch on `owner.code.length` exactly as\n * Permit2 does, so an owner with code takes the EIP-1271 path where strict\n * delegates reject a bare signature (Circle's `FiatTokenV2_2`, i.e. USDC), hence\n * the {@link acceptsRawEcdsaSignature} probe for EIP-7702 delegates.\n *\n * Other contract accounts stay blocked on shape alone and are never probed.\n * `encodeNativePermitData` splits the signature with `parseSignature`, so this\n * path needs 65 ECDSA bytes — which a 7702 delegate signing with its root key\n * always produces, and a contract wallet generally does not. Probing them would\n * admit any implementation that *returns* a failure value rather than reverting,\n * skip the approval, then throw after the user had already signed.\n *\n * The probe describes the account while the verifier lives in the token, so a\n * strict delegate spending a plain-`ecrecover` token is refused a permit it\n * could have used — an approval rather than a revert, and the token's path is\n * not reliably introspectable. `false` on RPC failure.\n *\n * Takes the chain and owner explicitly, mirroring {@link canAccountUsePermit2}:\n * reading them off a wallet client silently reported \"no native permit\" for\n * every caller that falls back to a public client.\n */\nexport const canAccountUseNativePermits = async (\n client: SDKClient,\n { chainId, address }: { chainId: number; address: Address }\n): Promise<boolean> => {\n const code = await getAccountCode({ client, chainId, address })\n // `undefined` means the lookup failed, not \"no code\" — `getAccountCode`\n // normalizes an empty result to `'0x'` precisely so these stay distinct.\n if (code === undefined) {\n return false\n }\n if (code === '0x') {\n return true\n }\n // Shape first: only 7702 delegates reach the probe. See the note above on\n // `parseSignature` — deliberately narrower than the Permit2 gate.\n if (!isDelegationDesignatorCode(code)) {\n return false\n }\n return acceptsRawEcdsaSignature(client, chainId, address)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,6BAA6B,OACxC,QACA,EAAE,SAAS,cACU;CACrB,MAAM,OAAO,MAAM,eAAe;EAAE;EAAQ;EAAS;CAAQ,CAAC;CAG9D,IAAI,SAAS,KAAA,GACX,OAAO;CAET,IAAI,SAAS,MACX,OAAO;CAIT,IAAI,CAAC,2BAA2B,IAAI,GAClC,OAAO;CAET,OAAO,yBAAyB,QAAQ,SAAS,OAAO;AAC1D"}
@@ -1 +1 @@
1
- {"version":3,"file":"canAccountUsePermit2.d.ts","names":[],"sources":["../../../src/permits/canAccountUsePermit2.ts"],"mappings":";;;;;;;;;;;;;;;;;cA6Fa,uBACX,QAAQ,aACN,SAAS;EAAa;EAAiB,SAAS;MACjD"}
1
+ {"version":3,"file":"canAccountUsePermit2.d.ts","names":[],"sources":["../../../src/permits/canAccountUsePermit2.ts"],"mappings":";;;;;;;;;;;;;;;;;cAmBa,uBACX,QAAQ,aACN,SAAS;EAAa;EAAiB,SAAS;MACjD"}
@@ -1,61 +1,6 @@
1
- import { getPublicClient } from "../client/publicClient.js";
2
1
  import { getAccountCode } from "../actions/getAccountCode.js";
3
- import { encodeFunctionData } from "viem";
4
- import { call } from "viem/actions";
5
- import { getAction } from "viem/utils";
2
+ import { acceptsRawEcdsaSignature } from "./acceptsRawEcdsaSignature.js";
6
3
  //#region src/permits/canAccountUsePermit2.ts
7
- const ERC1271_ABI = [{
8
- name: "isValidSignature",
9
- type: "function",
10
- stateMutability: "view",
11
- inputs: [{ type: "bytes32" }, { type: "bytes" }],
12
- outputs: [{ type: "bytes4" }]
13
- }];
14
- /**
15
- * A real 65-byte signature over {@link PROBE_HASH} from the public key `0x01…01`,
16
- * recovering to a third party — never the account under test. Throwaway probe
17
- * value, not a credential.
18
- *
19
- * MUST stay recoverable. An unrecoverable signature makes implementations that
20
- * revert (rather than return a failure value) look like they rejected the
21
- * envelope, misclassifying accounts that would have accepted ours.
22
- */
23
- const PROBE_HASH = `0x${"ab".repeat(32)}`;
24
- const PROBE_SIGNATURE = "0x997c61aa10e2330c076d6ba7abca1e71703a8f039291db103a62e085c9b2cf0d3f7e31ec9028229acc83093fbb722fa700fd6e4ea15d584df1bf384eb0051e0d1c";
25
- /**
26
- * Asks a code-bearing account the same question Permit2 will: does it evaluate a
27
- * plain 65-byte ECDSA signature, or reject it outright?
28
- *
29
- * - **Returns** → it recovered a signer and found a mismatch, so it will accept
30
- * the real root-key signature (MetaMask's `EIP7702StatelessDeleGator`).
31
- * - **Reverts** → it rejected the envelope before recovery and can't validate
32
- * anything we produce (Alchemy's ERC-6900 `SemiModularAccount7702`).
33
- *
34
- * Keyed on revert-vs-return, never on the value returned: the probe signature
35
- * recovers to a third party on purpose, so a correct implementation must return
36
- * a *non*-magic value, and comparing against the magic value would reject every
37
- * wallet this exists to accept. Accepted cost: an implementation that returns
38
- * failure for *everything* is classified capable and still fails on-chain.
39
- */
40
- const acceptsRawEcdsaSignature = async (client, chainId, address) => {
41
- try {
42
- const publicClient = await getPublicClient(client, chainId);
43
- const { data } = await getAction({
44
- ...publicClient,
45
- ccipRead: false
46
- }, call, "call")({
47
- to: address,
48
- data: encodeFunctionData({
49
- abi: ERC1271_ABI,
50
- functionName: "isValidSignature",
51
- args: [PROBE_HASH, PROBE_SIGNATURE]
52
- })
53
- });
54
- return !!data && data.length >= 66;
55
- } catch {
56
- return false;
57
- }
58
- };
59
4
  /**
60
5
  * Whether the account can produce a signature Uniswap Permit2 will accept.
61
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"canAccountUsePermit2.js","names":[],"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,MAAM,gBAAgB,QAAQ,OAAO;EAC1D,MAAM,EAAE,SAAS,MAAM,UAMrB;GAAE,GAAG;GAAc,UAAU;EAAM,GACnC,MACA,MACF,CAAC,CAAC;GACA,IAAI;GACJ,MAAM,mBAAmB;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,MAAM,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
+ {"version":3,"file":"canAccountUsePermit2.js","names":[],"sources":["../../../src/permits/canAccountUsePermit2.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { getAccountCode } from '../actions/getAccountCode.js'\nimport { acceptsRawEcdsaSignature } from './acceptsRawEcdsaSignature.js'\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":";;;;;;;;;;;;;;;;;AAmBA,MAAa,uBAAuB,OAClC,QACA,EAAE,SAAS,cACU;CACrB,MAAM,OAAO,MAAM,eAAe;EAAE;EAAQ;EAAS;CAAQ,CAAC;CAC9D,IAAI,SAAS,KAAA,GACX,OAAO;CAET,IAAI,SAAS,MACX,OAAO;CAET,OAAO,yBAAyB,QAAQ,SAAS,OAAO;AAC1D"}
@@ -9,6 +9,12 @@ type GetNativePermitParams = {
9
9
  tokenAddress: Address;
10
10
  spenderAddress: Address;
11
11
  amount: bigint;
12
+ /**
13
+ * The address that will sign the permit. Passed explicitly rather than read
14
+ * off `viemClient.account`, which is absent whenever a caller falls back to a
15
+ * public client (`checkPermitSupport` does) — that used to throw here.
16
+ */
17
+ ownerAddress: Address;
12
18
  };
13
19
  /**
14
20
  * Retrieves native permit data (EIP-2612) for a token on a specific chain
@@ -19,7 +25,7 @@ type GetNativePermitParams = {
19
25
  * @param tokenAddress - The address of the token to check for permit support
20
26
  * @returns {Promise<NativePermitData>} Object containing permit data including name, version, nonce and support status
21
27
  */
22
- declare const getNativePermit: (viemClient: Client, { client, chainId, tokenAddress, spenderAddress, amount }: GetNativePermitParams) => Promise<NativePermitData | undefined>;
28
+ declare const getNativePermit: (viemClient: Client, { client, chainId, tokenAddress, spenderAddress, amount, ownerAddress }: GetNativePermitParams) => Promise<NativePermitData | undefined>;
23
29
  //#endregion
24
30
  export { getNativePermit };
25
31
  //# sourceMappingURL=getNativePermit.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getNativePermit.d.ts","names":[],"sources":["../../../src/permits/getNativePermit.ts"],"mappings":";;;;KAwBK;EACH,QAAQ;EACR,YAAY;EACZ;EACA,cAAc;EACd,gBAAgB;EAChB;;;;;;;;;;;cA2bW,kBACX,YAAY,UAEV,QACA,SACA,cACA,gBACA,UACC,0BACF,QAAQ"}
1
+ {"version":3,"file":"getNativePermit.d.ts","names":[],"sources":["../../../src/permits/getNativePermit.ts"],"mappings":";;;;KAwBK;EACH,QAAQ;EACR,YAAY;EACZ;EACA,cAAc;EACd,gBAAgB;EAChB;;;;;;EAMA,cAAc;;;;;;;;;;;cA8bH,kBACX,YAAY,UAEV,QACA,SACA,cACA,gBACA,QACA,gBACC,0BACF,QAAQ"}
@@ -66,7 +66,7 @@ function validateDomainSeparator({ name, version, chainId, verifyingContract, do
66
66
  * @param tokenAddress - The token contract address
67
67
  * @returns Contract data if EIP-5267 is supported, undefined otherwise
68
68
  */
69
- const getEIP712DomainData = async (client, viemClient, chainId, tokenAddress) => {
69
+ const getEIP712DomainData = async (client, viemClient, chainId, tokenAddress, ownerAddress) => {
70
70
  try {
71
71
  const multicallAddress = await getMulticallAddress(client, chainId);
72
72
  const contractCalls = [{
@@ -77,7 +77,7 @@ const getEIP712DomainData = async (client, viemClient, chainId, tokenAddress) =>
77
77
  address: tokenAddress,
78
78
  abi: eip2612Abi,
79
79
  functionName: "nonces",
80
- args: [viemClient.account.address]
80
+ args: [ownerAddress]
81
81
  }];
82
82
  if (multicallAddress) try {
83
83
  const [eip712DomainResult, noncesResult] = await getActionWithFallback(client, viemClient, multicall, "multicall", {
@@ -130,9 +130,9 @@ const getEIP712DomainData = async (client, viemClient, chainId, tokenAddress) =>
130
130
  return;
131
131
  }
132
132
  };
133
- const getContractData = async (client, viemClient, chainId, tokenAddress) => {
133
+ const getContractData = async (client, viemClient, chainId, tokenAddress, ownerAddress) => {
134
134
  try {
135
- const eip5267Data = await getEIP712DomainData(client, viemClient, chainId, tokenAddress);
135
+ const eip5267Data = await getEIP712DomainData(client, viemClient, chainId, tokenAddress, ownerAddress);
136
136
  if (eip5267Data) return eip5267Data;
137
137
  const multicallAddress = await getMulticallAddress(client, chainId);
138
138
  const contractCalls = [
@@ -155,7 +155,7 @@ const getContractData = async (client, viemClient, chainId, tokenAddress) => {
155
155
  address: tokenAddress,
156
156
  abi: eip2612Abi,
157
157
  functionName: "nonces",
158
- args: [viemClient.account.address]
158
+ args: [ownerAddress]
159
159
  },
160
160
  {
161
161
  address: tokenAddress,
@@ -217,14 +217,17 @@ const getContractData = async (client, viemClient, chainId, tokenAddress) => {
217
217
  * @param tokenAddress - The address of the token to check for permit support
218
218
  * @returns {Promise<NativePermitData>} Object containing permit data including name, version, nonce and support status
219
219
  */
220
- const getNativePermit = async (viemClient, { client, chainId, tokenAddress, spenderAddress, amount }) => {
221
- if (!await canAccountUseNativePermits(client, viemClient)) return;
222
- const contractData = await getContractData(client, viemClient, chainId, tokenAddress);
220
+ const getNativePermit = async (viemClient, { client, chainId, tokenAddress, spenderAddress, amount, ownerAddress }) => {
221
+ if (!await canAccountUseNativePermits(client, {
222
+ chainId,
223
+ address: ownerAddress
224
+ })) return;
225
+ const contractData = await getContractData(client, viemClient, chainId, tokenAddress, ownerAddress);
223
226
  if (!contractData) return;
224
227
  if (contractData.permitTypehash === "0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb") return;
225
228
  const deadline = BigInt(Math.floor(Date.now() / 1e3) + 1800).toString();
226
229
  const message = {
227
- owner: viemClient.account.address,
230
+ owner: ownerAddress,
228
231
  spender: spenderAddress,
229
232
  value: amount.toString(),
230
233
  nonce: contractData.nonce.toString(),
@@ -1 +1 @@
1
- {"version":3,"file":"getNativePermit.js","names":[],"sources":["../../../src/permits/getNativePermit.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport type { Address, Client, Hex, TypedDataDomain } from 'viem'\nimport {\n encodeAbiParameters,\n keccak256,\n pad,\n parseAbiParameters,\n toBytes,\n toHex,\n zeroHash,\n} from 'viem'\nimport { multicall, readContract } from 'viem/actions'\nimport { getMulticallAddress } from '../actions/getMulticallAddress.js'\nimport { eip2612Abi } from '../utils/abi.js'\nimport { getActionWithFallback } from '../utils/getActionWithFallback.js'\nimport { canAccountUseNativePermits } from './canAccountUseNativePermits.js'\nimport {\n DAI_LIKE_PERMIT_TYPEHASH,\n EIP712_DOMAIN_TYPEHASH,\n EIP712_DOMAIN_TYPEHASH_WITH_SALT,\n eip2612Types,\n} from './constants.js'\nimport type { NativePermitData } from './types.js'\n\ntype GetNativePermitParams = {\n client: SDKClient\n viemClient: Client\n chainId: number\n tokenAddress: Address\n spenderAddress: Address\n amount: bigint\n}\n\nfunction makeDomainSeparator({\n name,\n version,\n chainId,\n verifyingContract,\n withSalt = false,\n}: {\n name: string\n version: string\n chainId: number\n verifyingContract: Address\n withSalt?: boolean\n}): Hex {\n const nameHash = keccak256(toBytes(name))\n const versionHash = keccak256(toBytes(version))\n\n const encoded = withSalt\n ? encodeAbiParameters(\n parseAbiParameters('bytes32, bytes32, bytes32, address, bytes32'),\n [\n EIP712_DOMAIN_TYPEHASH_WITH_SALT,\n nameHash,\n versionHash,\n verifyingContract,\n pad(toHex(chainId), { size: 32 }),\n ]\n )\n : encodeAbiParameters(\n parseAbiParameters('bytes32, bytes32, bytes32, uint256, address'),\n [\n EIP712_DOMAIN_TYPEHASH,\n nameHash,\n versionHash,\n BigInt(chainId),\n verifyingContract,\n ]\n )\n\n return keccak256(encoded)\n}\n\nfunction validateDomainSeparator({\n name,\n version,\n chainId,\n verifyingContract,\n domainSeparator,\n}: {\n name: string\n version: string\n chainId: number\n verifyingContract: Address\n domainSeparator: Hex\n}): { isValid: boolean; domain: TypedDataDomain } {\n if (!name || !domainSeparator) {\n return {\n isValid: false,\n domain: {},\n }\n }\n\n for (const withSalt of [false, true]) {\n const computedDS = makeDomainSeparator({\n name,\n version,\n chainId,\n verifyingContract,\n withSalt,\n })\n if (domainSeparator.toLowerCase() === computedDS.toLowerCase()) {\n return {\n isValid: true,\n domain: withSalt\n ? {\n name,\n version,\n verifyingContract,\n salt: pad(toHex(chainId), { size: 32 }),\n }\n : {\n name,\n version,\n chainId,\n verifyingContract,\n },\n }\n }\n }\n\n return {\n isValid: false,\n domain: {},\n }\n}\n\n/**\n * Attempts to retrieve contract data using EIP-5267 eip712Domain() function\n * @link https://eips.ethereum.org/EIPS/eip-5267\n * @param client - The SDK client\n * @param viemClient - The Viem client instance\n * @param chainId - The chain ID\n * @param tokenAddress - The token contract address\n * @returns Contract data if EIP-5267 is supported, undefined otherwise\n */\nconst getEIP712DomainData = async (\n client: SDKClient,\n viemClient: Client,\n chainId: number,\n tokenAddress: Address\n) => {\n try {\n const multicallAddress = await getMulticallAddress(client, chainId)\n\n const contractCalls = [\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'eip712Domain',\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'nonces',\n args: [viemClient.account!.address],\n },\n ] as const\n\n if (multicallAddress) {\n try {\n const [eip712DomainResult, noncesResult] = await getActionWithFallback(\n client,\n viemClient,\n multicall,\n 'multicall',\n {\n contracts: contractCalls,\n multicallAddress,\n }\n )\n\n if (\n eip712DomainResult.status !== 'success' ||\n noncesResult.status !== 'success' ||\n !eip712DomainResult.result ||\n noncesResult.result === undefined\n ) {\n // Fall back to individual calls if multicall fails\n throw new Error('EIP-5267 multicall failed')\n }\n\n const [, name, version, tokenChainId, verifyingContract, salt] =\n eip712DomainResult.result as [\n Hex,\n string,\n string,\n bigint,\n Address,\n Hex,\n bigint[],\n ]\n\n if (\n Number(tokenChainId) !== chainId ||\n verifyingContract.toLowerCase() !== tokenAddress.toLowerCase()\n ) {\n return undefined\n }\n\n // Build domain object directly from EIP-5267 data\n // Use the actual salt value returned by EIP-5267 - this is the canonical salt that the contract uses\n const hasSalt = salt !== zeroHash\n const domain = hasSalt\n ? {\n name,\n version,\n verifyingContract: tokenAddress,\n salt,\n }\n : {\n name,\n version,\n chainId,\n verifyingContract: tokenAddress,\n }\n\n return {\n name,\n version,\n domain,\n permitTypehash: undefined, // EIP-5267 doesn't provide permit typehash directly\n nonce: noncesResult.result,\n }\n } catch {\n // Fall through to individual calls\n }\n }\n\n // Fallback to individual contract calls\n const [eip712DomainResult, noncesResult] = (await Promise.allSettled(\n contractCalls.map((call) =>\n getActionWithFallback(\n client,\n viemClient,\n readContract,\n 'readContract',\n call\n )\n )\n )) as [\n PromiseSettledResult<\n [Hex, string, string, bigint, Address, Hex, bigint[]]\n >,\n PromiseSettledResult<bigint>,\n ]\n\n if (\n eip712DomainResult.status !== 'fulfilled' ||\n noncesResult.status !== 'fulfilled'\n ) {\n return undefined\n }\n\n const [, name, version, tokenChainId, verifyingContract, salt] =\n eip712DomainResult.value\n\n if (\n Number(tokenChainId) !== chainId ||\n verifyingContract.toLowerCase() !== tokenAddress.toLowerCase()\n ) {\n return undefined\n }\n\n // Build domain object directly from EIP-5267 data\n // Use the actual salt value returned by EIP-5267 - this is the canonical salt that the contract uses\n const hasSalt = salt !== zeroHash\n const domain = hasSalt\n ? {\n name,\n version,\n verifyingContract: tokenAddress,\n salt,\n }\n : {\n name,\n version,\n chainId,\n verifyingContract: tokenAddress,\n }\n\n return {\n name,\n version,\n domain,\n permitTypehash: undefined, // EIP-5267 doesn't provide permit typehash directly\n nonce: noncesResult.value,\n }\n } catch {\n return undefined\n }\n}\n\nconst getContractData = async (\n client: SDKClient,\n viemClient: Client,\n chainId: number,\n tokenAddress: Address\n) => {\n try {\n // First try EIP-5267 approach - returns domain object directly\n const eip5267Data = await getEIP712DomainData(\n client,\n viemClient,\n chainId,\n tokenAddress\n )\n if (eip5267Data) {\n return eip5267Data\n }\n\n // Fallback to legacy approach - validates and returns domain object\n const multicallAddress = await getMulticallAddress(client, chainId)\n\n const contractCalls = [\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'name',\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'DOMAIN_SEPARATOR',\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'PERMIT_TYPEHASH',\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'nonces',\n args: [viemClient.account!.address],\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'version',\n },\n ] as const\n\n if (multicallAddress) {\n try {\n const [\n nameResult,\n domainSeparatorResult,\n permitTypehashResult,\n noncesResult,\n versionResult,\n ] = await getActionWithFallback(\n client,\n viemClient,\n multicall,\n 'multicall',\n {\n contracts: contractCalls,\n multicallAddress,\n }\n )\n\n if (\n nameResult.status !== 'success' ||\n domainSeparatorResult.status !== 'success' ||\n noncesResult.status !== 'success' ||\n !nameResult.result ||\n !domainSeparatorResult.result ||\n noncesResult.result === undefined\n ) {\n // Fall back to individual calls if multicall fails\n throw new Error('Multicall failed')\n }\n\n // Validate domain separator and create domain object\n const { isValid, domain } = validateDomainSeparator({\n name: nameResult.result as string,\n version: (versionResult.result ?? '1') as string,\n chainId,\n verifyingContract: tokenAddress,\n domainSeparator: domainSeparatorResult.result as Hex,\n })\n\n if (!isValid) {\n return undefined\n }\n\n return {\n name: nameResult.result as string,\n domain,\n permitTypehash: permitTypehashResult.result as Hex,\n nonce: noncesResult.result as bigint,\n version: (versionResult.result ?? '1') as string,\n }\n } catch {\n // Fall through to individual calls\n }\n }\n\n const [\n nameResult,\n domainSeparatorResult,\n permitTypehashResult,\n noncesResult,\n versionResult,\n ] = (await Promise.allSettled(\n contractCalls.map((call) =>\n getActionWithFallback(\n client,\n viemClient,\n readContract,\n 'readContract',\n call\n )\n )\n )) as [\n PromiseSettledResult<string>,\n PromiseSettledResult<Hex>,\n PromiseSettledResult<Hex>,\n PromiseSettledResult<bigint>,\n PromiseSettledResult<string>,\n ]\n\n if (\n nameResult.status !== 'fulfilled' ||\n domainSeparatorResult.status !== 'fulfilled' ||\n noncesResult.status !== 'fulfilled'\n ) {\n return undefined\n }\n\n const name = nameResult.value\n const version =\n versionResult.status === 'fulfilled' ? versionResult.value : '1'\n\n // Validate domain separator and create domain object\n const { isValid, domain } = validateDomainSeparator({\n name,\n version,\n chainId,\n verifyingContract: tokenAddress,\n domainSeparator: domainSeparatorResult.value,\n })\n\n if (!isValid) {\n return undefined\n }\n\n return {\n name,\n domain,\n permitTypehash:\n permitTypehashResult.status === 'fulfilled'\n ? permitTypehashResult.value\n : undefined,\n nonce: noncesResult.value,\n version,\n }\n } catch {\n return undefined\n }\n}\n\n/**\n * Retrieves native permit data (EIP-2612) for a token on a specific chain\n * @link https://eips.ethereum.org/EIPS/eip-2612\n @param client - The SDK client\n * @param viemClient - The Viem client instance\n * @param chain - The extended chain object containing chain details\n * @param tokenAddress - The address of the token to check for permit support\n * @returns {Promise<NativePermitData>} Object containing permit data including name, version, nonce and support status\n */\nexport const getNativePermit = async (\n viemClient: Client,\n {\n client,\n chainId,\n tokenAddress,\n spenderAddress,\n amount,\n }: GetNativePermitParams\n): Promise<NativePermitData | undefined> => {\n // Check if the account can use native permits (EOA or EIP-7702 delegated account)\n const canUsePermits = await canAccountUseNativePermits(client, viemClient)\n if (!canUsePermits) {\n return undefined\n }\n\n const contractData = await getContractData(\n client,\n viemClient,\n chainId,\n tokenAddress\n )\n if (!contractData) {\n return undefined\n }\n\n // We don't support DAI-like permits yet (e.g. DAI on Ethereum)\n // https://eips.ethereum.org/EIPS/eip-2612#backwards-compatibility\n if (contractData.permitTypehash === DAI_LIKE_PERMIT_TYPEHASH) {\n return undefined\n }\n\n const deadline = BigInt(Math.floor(Date.now() / 1000) + 30 * 60).toString() // 30 minutes\n\n const message = {\n owner: viemClient.account!.address,\n spender: spenderAddress,\n value: amount.toString(),\n nonce: contractData.nonce!.toString(),\n deadline,\n }\n\n return {\n primaryType: 'Permit',\n domain: contractData.domain,\n types: eip2612Types,\n message,\n }\n}\n"],"mappings":";;;;;;;;AAiCA,SAAS,oBAAoB,EAC3B,MACA,SACA,SACA,mBACA,WAAW,SAOL;CACN,MAAM,WAAW,UAAU,QAAQ,IAAI,CAAC;CACxC,MAAM,cAAc,UAAU,QAAQ,OAAO,CAAC;CAE9C,MAAM,UAAU,WACZ,oBACE,mBAAmB,6CAA6C,GAChE;EACE;EACA;EACA;EACA;EACA,IAAI,MAAM,OAAO,GAAG,EAAE,MAAM,GAAG,CAAC;CAClC,CACF,IACA,oBACE,mBAAm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E7D;GAoBF,OAAO;IACL;IACA;IACA,QAlBc,SAAS,WAErB;KACE;KACA;KACA,mBAAmB;KACnB;IACF,IACA;KACE;KACA;KACA;KACA,mBAAmB;IACrB;IAMF,gBAAgB,KAAA;IAChB,OAAO,aAAa;GACtB;EACF,QAAQ,CAER;EAIF,MAAM,CAAC,oBAAoB,gBAAiB,MAAM,QAAQ,WACxD,cAAc,KAAK,SACjB,sBACE,QACA,YACA,cACA,gBACA,IACF,CACF,CACF;EAOA,IACE,mBAAmB,WAAW,eAC9B,aAAa,WAAW,aAExB;EAGF,MAAM,GAAG,MAAM,SAAS,cAAc,mBAAmB,QACvD,mBAAmB;EAErB,IACE,OAAO,YAAY,MAAM,WACzB,kBAAkB,YAAY,MAAM,aAAa,YAAY,GAE7D;EAoBF,OAAO;GACL;GACA;GACA,QAlBc,SAAS,WAErB;IACE;IACA;IACA,mBAAmB;IACnB;GACF,IACA;IACE;IACA;IACA;IACA,mBAAmB;GACrB;GAMF,gBAAgB,KAAA;GAChB,OAAO,aAAa;EACtB;CACF,QAAQ;EACN;CACF;AACF;AAEA,MAAM,kBAAkB,OACtB,QACA,YACA,SACA,iBACG;CACH,IAAI;EAEF,MAAM,cAAc,MAAM,oBACxB,QACA,YACA,SACA,YACF;EACA,IAAI,aACF,OAAO;EAIT,MAAM,mBAAmB,MAAM,oBAAoB,QAAQ,OAAO;EAElE,MAAM,gBAAgB;GACpB;IACE,SAAS;IACT,KAAK;IACL,cAAc;GAChB;GACA;IACE,SAAS;IACT,KAAK;IACL,cAAc;GAChB;GACA;IACE,SAAS;IACT,KAAK;IACL,cAAc;GAChB;GACA;IACE,SAAS;IACT,KAAK;IACL,cAAc;IACd,MAAM,CAAC,WAAW,QAAS,OAAO;GACpC;GACA;IACE,SAAS;IACT,KAAK;IACL,cAAc;GAChB;EACF;EAEA,IAAI,kBACF,IAAI;GACF,MAAM,CACJ,YACA,uBACA,sBACA,cACA,iBACE,MAAM,sBACR,QACA,YACA,WACA,aACA;IACE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O,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI,IAAO,CAAC,CAAC,SAAS;CAE1E,MAAM,UAAU;EACd,OAAO,WAAW,QAAS;EAC3B,SAAS;EACT,OAAO,OAAO,SAAS;EACvB,OAAO,aAAa,MAAO,SAAS;EACpC;CACF;CAEA,OAAO;EACL,aAAa;EACb,QAAQ,aAAa;EACrB,OAAO;EACP;CACF;AACF"}
1
+ {"version":3,"file":"getNativePermit.js","names":[],"sources":["../../../src/permits/getNativePermit.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport type { Address, Client, Hex, TypedDataDomain } from 'viem'\nimport {\n encodeAbiParameters,\n keccak256,\n pad,\n parseAbiParameters,\n toBytes,\n toHex,\n zeroHash,\n} from 'viem'\nimport { multicall, readContract } from 'viem/actions'\nimport { getMulticallAddress } from '../actions/getMulticallAddress.js'\nimport { eip2612Abi } from '../utils/abi.js'\nimport { getActionWithFallback } from '../utils/getActionWithFallback.js'\nimport { canAccountUseNativePermits } from './canAccountUseNativePermits.js'\nimport {\n DAI_LIKE_PERMIT_TYPEHASH,\n EIP712_DOMAIN_TYPEHASH,\n EIP712_DOMAIN_TYPEHASH_WITH_SALT,\n eip2612Types,\n} from './constants.js'\nimport type { NativePermitData } from './types.js'\n\ntype GetNativePermitParams = {\n client: SDKClient\n viemClient: Client\n chainId: number\n tokenAddress: Address\n spenderAddress: Address\n amount: bigint\n /**\n * The address that will sign the permit. Passed explicitly rather than read\n * off `viemClient.account`, which is absent whenever a caller falls back to a\n * public client (`checkPermitSupport` does) — that used to throw here.\n */\n ownerAddress: Address\n}\n\nfunction makeDomainSeparator({\n name,\n version,\n chainId,\n verifyingContract,\n withSalt = false,\n}: {\n name: string\n version: string\n chainId: number\n verifyingContract: Address\n withSalt?: boolean\n}): Hex {\n const nameHash = keccak256(toBytes(name))\n const versionHash = keccak256(toBytes(version))\n\n const encoded = withSalt\n ? encodeAbiParameters(\n parseAbiParameters('bytes32, bytes32, bytes32, address, bytes32'),\n [\n EIP712_DOMAIN_TYPEHASH_WITH_SALT,\n nameHash,\n versionHash,\n verifyingContract,\n pad(toHex(chainId), { size: 32 }),\n ]\n )\n : encodeAbiParameters(\n parseAbiParameters('bytes32, bytes32, bytes32, uint256, address'),\n [\n EIP712_DOMAIN_TYPEHASH,\n nameHash,\n versionHash,\n BigInt(chainId),\n verifyingContract,\n ]\n )\n\n return keccak256(encoded)\n}\n\nfunction validateDomainSeparator({\n name,\n version,\n chainId,\n verifyingContract,\n domainSeparator,\n}: {\n name: string\n version: string\n chainId: number\n verifyingContract: Address\n domainSeparator: Hex\n}): { isValid: boolean; domain: TypedDataDomain } {\n if (!name || !domainSeparator) {\n return {\n isValid: false,\n domain: {},\n }\n }\n\n for (const withSalt of [false, true]) {\n const computedDS = makeDomainSeparator({\n name,\n version,\n chainId,\n verifyingContract,\n withSalt,\n })\n if (domainSeparator.toLowerCase() === computedDS.toLowerCase()) {\n return {\n isValid: true,\n domain: withSalt\n ? {\n name,\n version,\n verifyingContract,\n salt: pad(toHex(chainId), { size: 32 }),\n }\n : {\n name,\n version,\n chainId,\n verifyingContract,\n },\n }\n }\n }\n\n return {\n isValid: false,\n domain: {},\n }\n}\n\n/**\n * Attempts to retrieve contract data using EIP-5267 eip712Domain() function\n * @link https://eips.ethereum.org/EIPS/eip-5267\n * @param client - The SDK client\n * @param viemClient - The Viem client instance\n * @param chainId - The chain ID\n * @param tokenAddress - The token contract address\n * @returns Contract data if EIP-5267 is supported, undefined otherwise\n */\nconst getEIP712DomainData = async (\n client: SDKClient,\n viemClient: Client,\n chainId: number,\n tokenAddress: Address,\n ownerAddress: Address\n) => {\n try {\n const multicallAddress = await getMulticallAddress(client, chainId)\n\n const contractCalls = [\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'eip712Domain',\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'nonces',\n args: [ownerAddress],\n },\n ] as const\n\n if (multicallAddress) {\n try {\n const [eip712DomainResult, noncesResult] = await getActionWithFallback(\n client,\n viemClient,\n multicall,\n 'multicall',\n {\n contracts: contractCalls,\n multicallAddress,\n }\n )\n\n if (\n eip712DomainResult.status !== 'success' ||\n noncesResult.status !== 'success' ||\n !eip712DomainResult.result ||\n noncesResult.result === undefined\n ) {\n // Fall back to individual calls if multicall fails\n throw new Error('EIP-5267 multicall failed')\n }\n\n const [, name, version, tokenChainId, verifyingContract, salt] =\n eip712DomainResult.result as [\n Hex,\n string,\n string,\n bigint,\n Address,\n Hex,\n bigint[],\n ]\n\n if (\n Number(tokenChainId) !== chainId ||\n verifyingContract.toLowerCase() !== tokenAddress.toLowerCase()\n ) {\n return undefined\n }\n\n // Build domain object directly from EIP-5267 data\n // Use the actual salt value returned by EIP-5267 - this is the canonical salt that the contract uses\n const hasSalt = salt !== zeroHash\n const domain = hasSalt\n ? {\n name,\n version,\n verifyingContract: tokenAddress,\n salt,\n }\n : {\n name,\n version,\n chainId,\n verifyingContract: tokenAddress,\n }\n\n return {\n name,\n version,\n domain,\n permitTypehash: undefined, // EIP-5267 doesn't provide permit typehash directly\n nonce: noncesResult.result,\n }\n } catch {\n // Fall through to individual calls\n }\n }\n\n // Fallback to individual contract calls\n const [eip712DomainResult, noncesResult] = (await Promise.allSettled(\n contractCalls.map((call) =>\n getActionWithFallback(\n client,\n viemClient,\n readContract,\n 'readContract',\n call\n )\n )\n )) as [\n PromiseSettledResult<\n [Hex, string, string, bigint, Address, Hex, bigint[]]\n >,\n PromiseSettledResult<bigint>,\n ]\n\n if (\n eip712DomainResult.status !== 'fulfilled' ||\n noncesResult.status !== 'fulfilled'\n ) {\n return undefined\n }\n\n const [, name, version, tokenChainId, verifyingContract, salt] =\n eip712DomainResult.value\n\n if (\n Number(tokenChainId) !== chainId ||\n verifyingContract.toLowerCase() !== tokenAddress.toLowerCase()\n ) {\n return undefined\n }\n\n // Build domain object directly from EIP-5267 data\n // Use the actual salt value returned by EIP-5267 - this is the canonical salt that the contract uses\n const hasSalt = salt !== zeroHash\n const domain = hasSalt\n ? {\n name,\n version,\n verifyingContract: tokenAddress,\n salt,\n }\n : {\n name,\n version,\n chainId,\n verifyingContract: tokenAddress,\n }\n\n return {\n name,\n version,\n domain,\n permitTypehash: undefined, // EIP-5267 doesn't provide permit typehash directly\n nonce: noncesResult.value,\n }\n } catch {\n return undefined\n }\n}\n\nconst getContractData = async (\n client: SDKClient,\n viemClient: Client,\n chainId: number,\n tokenAddress: Address,\n ownerAddress: Address\n) => {\n try {\n // First try EIP-5267 approach - returns domain object directly\n const eip5267Data = await getEIP712DomainData(\n client,\n viemClient,\n chainId,\n tokenAddress,\n ownerAddress\n )\n if (eip5267Data) {\n return eip5267Data\n }\n\n // Fallback to legacy approach - validates and returns domain object\n const multicallAddress = await getMulticallAddress(client, chainId)\n\n const contractCalls = [\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'name',\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'DOMAIN_SEPARATOR',\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'PERMIT_TYPEHASH',\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'nonces',\n args: [ownerAddress],\n },\n {\n address: tokenAddress,\n abi: eip2612Abi,\n functionName: 'version',\n },\n ] as const\n\n if (multicallAddress) {\n try {\n const [\n nameResult,\n domainSeparatorResult,\n permitTypehashResult,\n noncesResult,\n versionResult,\n ] = await getActionWithFallback(\n client,\n viemClient,\n multicall,\n 'multicall',\n {\n contracts: contractCalls,\n multicallAddress,\n }\n )\n\n if (\n nameResult.status !== 'success' ||\n domainSeparatorResult.status !== 'success' ||\n noncesResult.status !== 'success' ||\n !nameResult.result ||\n !domainSeparatorResult.result ||\n noncesResult.result === undefined\n ) {\n // Fall back to individual calls if multicall fails\n throw new Error('Multicall failed')\n }\n\n // Validate domain separator and create domain object\n const { isValid, domain } = validateDomainSeparator({\n name: nameResult.result as string,\n version: (versionResult.result ?? '1') as string,\n chainId,\n verifyingContract: tokenAddress,\n domainSeparator: domainSeparatorResult.result as Hex,\n })\n\n if (!isValid) {\n return undefined\n }\n\n return {\n name: nameResult.result as string,\n domain,\n permitTypehash: permitTypehashResult.result as Hex,\n nonce: noncesResult.result as bigint,\n version: (versionResult.result ?? '1') as string,\n }\n } catch {\n // Fall through to individual calls\n }\n }\n\n const [\n nameResult,\n domainSeparatorResult,\n permitTypehashResult,\n noncesResult,\n versionResult,\n ] = (await Promise.allSettled(\n contractCalls.map((call) =>\n getActionWithFallback(\n client,\n viemClient,\n readContract,\n 'readContract',\n call\n )\n )\n )) as [\n PromiseSettledResult<string>,\n PromiseSettledResult<Hex>,\n PromiseSettledResult<Hex>,\n PromiseSettledResult<bigint>,\n PromiseSettledResult<string>,\n ]\n\n if (\n nameResult.status !== 'fulfilled' ||\n domainSeparatorResult.status !== 'fulfilled' ||\n noncesResult.status !== 'fulfilled'\n ) {\n return undefined\n }\n\n const name = nameResult.value\n const version =\n versionResult.status === 'fulfilled' ? versionResult.value : '1'\n\n // Validate domain separator and create domain object\n const { isValid, domain } = validateDomainSeparator({\n name,\n version,\n chainId,\n verifyingContract: tokenAddress,\n domainSeparator: domainSeparatorResult.value,\n })\n\n if (!isValid) {\n return undefined\n }\n\n return {\n name,\n domain,\n permitTypehash:\n permitTypehashResult.status === 'fulfilled'\n ? permitTypehashResult.value\n : undefined,\n nonce: noncesResult.value,\n version,\n }\n } catch {\n return undefined\n }\n}\n\n/**\n * Retrieves native permit data (EIP-2612) for a token on a specific chain\n * @link https://eips.ethereum.org/EIPS/eip-2612\n @param client - The SDK client\n * @param viemClient - The Viem client instance\n * @param chain - The extended chain object containing chain details\n * @param tokenAddress - The address of the token to check for permit support\n * @returns {Promise<NativePermitData>} Object containing permit data including name, version, nonce and support status\n */\nexport const getNativePermit = async (\n viemClient: Client,\n {\n client,\n chainId,\n tokenAddress,\n spenderAddress,\n amount,\n ownerAddress,\n }: GetNativePermitParams\n): Promise<NativePermitData | undefined> => {\n // Check that the account can produce a signature the token will accept\n const canUsePermits = await canAccountUseNativePermits(client, {\n chainId,\n address: ownerAddress,\n })\n if (!canUsePermits) {\n return undefined\n }\n\n const contractData = await getContractData(\n client,\n viemClient,\n chainId,\n tokenAddress,\n ownerAddress\n )\n if (!contractData) {\n return undefined\n }\n\n // We don't support DAI-like permits yet (e.g. DAI on Ethereum)\n // https://eips.ethereum.org/EIPS/eip-2612#backwards-compatibility\n if (contractData.permitTypehash === DAI_LIKE_PERMIT_TYPEHASH) {\n return undefined\n }\n\n const deadline = BigInt(Math.floor(Date.now() / 1000) + 30 * 60).toString() // 30 minutes\n\n const message = {\n owner: ownerAddress,\n spender: spenderAddress,\n value: amount.toString(),\n nonce: contractData.nonce!.toString(),\n deadline,\n }\n\n return {\n primaryType: 'Permit',\n domain: contractData.domain,\n types: eip2612Types,\n message,\n }\n}\n"],"mappings":";;;;;;;;AAuCA,SAAS,oBAAoB,EAC3B,MACA,SACA,SACA,mBACA,WAAW,SAOL;CACN,MAAM,WAAW,UAAU,QAAQ,IAAI,CAAC;CACxC,MAAM,cAAc,UAAU,QAAQ,OAAO,CAAC;CAE9C,MAAM,UAAU,WACZ,oBACE,mBAAmB,6CAA6C,GAChE;EACE;EACA;EACA;EACA;EACA,IAAI,MAAM,OAAO,GAAG,EAAE,MAAM,GAAG,CAAC;CAClC,CACF,IACA,oBACE,mBAAmB,6CAA6C,GAChE;EACE;EACA;EACA;EACA,OAAO,OAAO;EACd;CACF,CACF;CAEJ,OAAO,UAAU,OAAO;AAC1B;AAEA,SAAS,wBAAwB,EAC/B,MACA,SACA,SACA,mBACA,mBAOgD;CAChD,IAAI,CAAC,QAAQ,CAAC,iBACZ,OAAO;EACL,SAAS;EACT,QAAQ,CAAC;CACX;CAGF,KAAK,MAAM,YAAY,CAAC,OAAO,IAAI,GAAG;EACpC,MAAM,aAAa,oBAAoB;GACrC;GACA;GACA;GACA;GACA;EACF,CAAC;EACD,IAAI,gBAAgB,YAAY,MAAM,WAAW,YAAY,GAC3D,O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AO,aAAa;IACpB,SAAU,cAAc,UAAU;GACpC;EACF,QAAQ,CAER;EAGF,MAAM,CACJ,YACA,uBACA,sBACA,cACA,iBACG,MAAM,QAAQ,WACjB,cAAc,KAAK,SACjB,sBACE,QACA,YACA,cACA,gBACA,IACF,CACF,CACF;EAQA,IACE,WAAW,WAAW,eACtB,sBAAsB,WAAW,eACjC,aAAa,WAAW,aAExB;EAGF,MAAM,OAAO,WAAW;EACxB,MAAM,UACJ,cAAc,WAAW,cAAc,cAAc,QAAQ;EAG/D,MAAM,EAAE,SAAS,WAAW,wBAAwB;GAClD;GACA;GACA;GACA,mBAAmB;GACnB,iBAAiB,sBAAsB;EACzC,CAAC;EAED,IAAI,CAAC,SACH;EAGF,OAAO;GACL;GACA;GACA,gBACE,qBAAqB,WAAW,cAC5B,qBAAqB,QACrB,KAAA;GACN,OAAO,aAAa;GACpB;EACF;CACF,QAAQ;EACN;CACF;AACF;;;;;;;;;;AAWA,MAAa,kBAAkB,OAC7B,YACA,EACE,QACA,SACA,cACA,gBACA,QACA,mBAEwC;CAM1C,IAAI,CAAC,MAJuB,2BAA2B,QAAQ;EAC7D;EACA,SAAS;CACX,CAAC,GAEC;CAGF,MAAM,eAAe,MAAM,gBACzB,QACA,YACA,SACA,cACA,YACF;CACA,IAAI,CAAC,cACH;CAKF,IAAI,aAAa,mBAAA,sEACf;CAGF,MAAM,WAAW,OAAO,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI,IAAO,CAAC,CAAC,SAAS;CAE1E,MAAM,UAAU;EACd,OAAO;EACP,SAAS;EACT,OAAO,OAAO,SAAS;EACvB,OAAO,aAAa,MAAO,SAAS;EACpC;CACF;CAEA,OAAO;EACL,aAAa;EACb,QAAQ,aAAa;EACrB,OAAO;EACP;CACF;AACF"}
@@ -1,6 +1,6 @@
1
1
  //#region src/version.d.ts
2
2
  declare const name = "@lifi/sdk-provider-ethereum";
3
- declare const version = "4.0.12";
3
+ declare const version = "4.0.14";
4
4
  //#endregion
5
5
  export { name, version };
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk-provider-ethereum";
3
- const version = "4.0.12";
3
+ const version = "4.0.14";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.0.12'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.0.14'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk-provider-ethereum",
3
- "version": "4.0.12",
3
+ "version": "4.0.14",
4
4
  "description": "LI.FI Ethereum SDK Provider for Any-to-Any Cross-Chain-Swap",
5
5
  "homepage": "https://github.com/lifinance/sdk",
6
6
  "bugs": {
@@ -28,8 +28,8 @@
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "dependencies": {
31
- "@lifi/sdk": "4.6.0",
32
- "viem": "^2.55.19"
31
+ "@lifi/sdk": "4.6.1",
32
+ "viem": "^2.56.3"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
@@ -63,12 +63,18 @@ export const checkPermitSupport = async (
63
63
  tokenAddress,
64
64
  spenderAddress: chain.permit2Proxy as Address,
65
65
  amount,
66
+ ownerAddress,
66
67
  }
67
68
  )
68
69
 
69
70
  let permit2Allowance: bigint | undefined
70
- // Only read the allowance if the owner can sign for it: Permit2 may reject a
71
- // code-bearing account via EIP-1271, making any allowance unusable.
71
+ // Only read the allowance if the owner can sign for it: Permit2 may reject an
72
+ // account with code via EIP-1271, making any allowance unusable.
73
+ //
74
+ // An EIP-7702 owner is probed twice here, once per gate. The two run
75
+ // sequentially, so `withDedupe` would not collapse them, and caching the
76
+ // verdict would defeat the deliberate freshness of `getAccountCode`. Two
77
+ // `eth_call`s on an already multi-RPC action is the cheaper trade.
72
78
  if (
73
79
  chain.permit2 &&
74
80
  (await canAccountUsePermit2(client, {
@@ -77,6 +77,7 @@ export class EthereumNativePermitTask extends BaseStepExecutionTask {
77
77
  tokenAddress: step.action.fromToken.address as Address,
78
78
  spenderAddress: fromChain.permit2Proxy as Address,
79
79
  amount: fromAmount,
80
+ ownerAddress: updatedClient.account!.address,
80
81
  }
81
82
  )
82
83