@lifi/sdk-provider-ethereum 4.0.11 → 4.0.13

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 +17 -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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @lifi/sdk-provider-ethereum
2
2
 
3
+ ## 4.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - [#459](https://github.com/lifinance/sdk/pull/459) [`954bc4b`](https://github.com/lifinance/sdk/commit/954bc4bda013b470102041810daf95cb4f9181a1) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependencies: `@lifi/types` to 18.4.0, `viem` to 2.56.0, `@mysten/sui` to 2.27.0.
8
+
9
+ - [#452](https://github.com/lifinance/sdk/pull/452) [`7cca666`](https://github.com/lifinance/sdk/commit/7cca666e20d14118d09a2f8141a77efcb42c465a) Thanks [@chmanie](https://github.com/chmanie)! - Fix native EIP-2612 permits failing for EIP-7702 delegated accounts. Tokens whose `permit` verifies through a `SignatureChecker` — Circle's USDC among them — branch on `owner.code.length` just as Permit2 does, so a delegated owner is verified via EIP-1271 and strict delegates reject the bare ECDSA signature with `EIP2612: invalid signature`. Delegated accounts are now probed with the same `isValidSignature` check already used for Permit2, rather than passed on the grounds that they can sign ECDSA. Other contract accounts remain excluded on shape, as before.
10
+ - Updated dependencies [[`954bc4b`](https://github.com/lifinance/sdk/commit/954bc4bda013b470102041810daf95cb4f9181a1)]:
11
+ - @lifi/sdk@4.6.1
12
+
13
+ ## 4.0.12
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`b5ace9d`](https://github.com/lifinance/sdk/commit/b5ace9d9a2a0267ae4231b42035b55a0e1def72e)]:
18
+ - @lifi/sdk@4.6.0
19
+
3
20
  ## 4.0.11
4
21
 
5
22
  ### Patch Changes
@@ -29,7 +29,8 @@ const checkPermitSupport = async (client, { chain, tokenAddress, ownerAddress, a
29
29
  chainId: chain.id,
30
30
  tokenAddress,
31
31
  spenderAddress: chain.permit2Proxy,
32
- amount
32
+ amount,
33
+ ownerAddress
33
34
  });
34
35
  let permit2Allowance;
35
36
  if (chain.permit2 && await require_permits_canAccountUsePermit2.canAccountUsePermit2(client, {
@@ -1 +1 @@
1
- {"version":3,"file":"checkPermitSupport.js","names":["ChainType","getPublicClient","getActionWithFallback","getNativePermit","canAccountUsePermit2","getAllowance"],"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,YAAYA,UAAAA,UAAU,GAGhB,CAAC,EAAE,kBAAkB;CAEnD,IAAI,CAAC,YACH,aAAa,MAAMC,4BAAAA,gBAAgB,QAAQ,MAAM,EAAE;CAGrD,MAAM,eAAe,MAAMC,oCAAAA,sBACzB,QACA,YACAC,gCAAAA,iBACA,mBACA;EACE;EACA;EACA,SAAS,MAAM;EACf;EACA,gBAAgB,MAAM;EACtB;CACF,CACF;CAEA,IAAI;CAGJ,IACE,MAAM,WACL,MAAMC,qCAAAA,qBAAqB,QAAQ;EAClC,SAAS,MAAM;EACf,SAAS;CACX,CAAC,GAED,mBAAmB,MAAMC,6BAAAA,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":["ChainType","getPublicClient","getActionWithFallback","getNativePermit","canAccountUsePermit2","getAllowance"],"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,YAAYA,UAAAA,UAAU,GAGhB,CAAC,EAAE,kBAAkB;CAEnD,IAAI,CAAC,YACH,aAAa,MAAMC,4BAAAA,gBAAgB,QAAQ,MAAM,EAAE;CAGrD,MAAM,eAAe,MAAMC,oCAAAA,sBACzB,QACA,YACAC,gCAAAA,iBACA,mBACA;EACE;EACA;EACA,SAAS,MAAM;EACf;EACA,gBAAgB,MAAM;EACtB;EACA;CACF,CACF;CAEA,IAAI;CAQJ,IACE,MAAM,WACL,MAAMC,qCAAAA,qBAAqB,QAAQ;EAClC,SAAS,MAAM;EACf,SAAS;CACX,CAAC,GAED,mBAAmB,MAAMC,6BAAAA,aACvB,QACA,YACA,cACA,cACA,MAAM,OACR;CAGF,OAAO;EACL,uBAAuB,CAAC,CAAC;EACzB,4BACE,CAAC,CAAC,oBAAoB,oBAAoB;CAC9C;AACF"}
@@ -32,7 +32,8 @@ var EthereumNativePermitTask = class extends _lifi_sdk.BaseStepExecutionTask {
32
32
  chainId: fromChain.id,
33
33
  tokenAddress: step.action.fromToken.address,
34
34
  spenderAddress: fromChain.permit2Proxy,
35
- amount: fromAmount
35
+ amount: fromAmount,
36
+ ownerAddress: updatedClient.account.address
36
37
  });
37
38
  if (!nativePermitData) {
38
39
  statusManager.updateAction(step, action.type, "DONE");
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumNativePermitTask.js","names":["BaseStepExecutionTask","getEthereumExecutionStrategy","getActionWithFallback","getNativePermit","isNativePermitValid","getAction","signTypedData","isValidSignature"],"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 }\n }\n}\n"],"mappings":";;;;;;;;;;AAeA,IAAa,2BAAb,cAA8CA,UAAAA,sBAAsB;CAClE,MAAe,UACb,SACkB;EAClB,MAAM,EACJ,MACA,WACA,mBACA,wBACA,0BACE;EAEJ,IAAI,qBAAqB,wBACvB,OAAO;EAIT,MAAM,oBAAoB,MADMC,wDAAAA,6BAA6B,OAAO,MACpB;EAOhD,OAJE,CAAC,CAAC,UAAU,gBACZ,CAAC,qBACD,CAAC,yBACD,CAAC,KAAK,SAAS;CAEnB;CAEA,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,QACA,WACA,eACA,sBACA,aACA,iBAAiB,2BACf;EAEJ,MAAM,SAAS,cAAc,iBAAiB;GAC5C;GACA,MAAM;GACN,SAAS,KAAK,OAAO;GACrB,QAAQ;EACV,CAAC;EAED,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,aAAa,OAAO,KAAK,OAAO,UAAU;EAEhD,MAAM,mBAAmB,MAAMC,oCAAAA,sBAC7B,QACA,eACAC,gCAAAA,iBACA,mBACA;GACE;GACA,YAAY;GACZ,SAAS,UAAU;GACnB,cAAc,KAAK,OAAO,UAAU;GACpC,gBAAgB,UAAU;GAC1B,QAAQ;EACV,CACF;EAEA,IAAI,CAAC,kBAAkB;GACrB,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;GACpD,OAAO,EAAE,QAAQ,YAAY;EAC/B;EAEA,MAAM,kBAAkB,CAAC,GAAG,sBAAsB;EAOlD,IAAI,CAJ4B,gBAAgB,MAAM,oBACpDC,oCAAAA,oBAAoB,iBAAiB,gBAAgB,CAG5B,GAAG;GAC5B,cAAc,aAAa,MAAM,OAAO,MAAM,iBAAiB;GAE/D,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;GAI5B,MAAM,YAAY,OAAA,GAAMC,WAAAA,UAAAA,CACtB,eACAC,aAAAA,eACA,eACF,CAAC,CAAC;IACA,SAAS,cAAc;IACvB,QAAQ,iBAAiB;IACzB,OAAO,iBAAiB;IACxB,aAAa,iBAAiB;IAC9B,SAAS,iBAAiB;GAC5B,CAAC;GAKD,IAAI,CAACC,+BAAAA,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":["BaseStepExecutionTask","getEthereumExecutionStrategy","getActionWithFallback","getNativePermit","isNativePermitValid","getAction","signTypedData","isValidSignature"],"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: { signedTypedData, hasMatchingPermit: true },\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAeA,IAAa,2BAAb,cAA8CA,UAAAA,sBAAsB;CAClE,MAAe,UACb,SACkB;EAClB,MAAM,EACJ,MACA,WACA,mBACA,wBACA,0BACE;EAEJ,IAAI,qBAAqB,wBACvB,OAAO;EAIT,MAAM,oBAAoB,MADMC,wDAAAA,6BAA6B,OAAO,MACpB;EAOhD,OAJE,CAAC,CAAC,UAAU,gBACZ,CAAC,qBACD,CAAC,yBACD,CAAC,KAAK,SAAS;CAEnB;CAEA,MAAM,IAAI,SAA2D;EACnE,MAAM,EACJ,MACA,QACA,WACA,eACA,sBACA,aACA,iBAAiB,2BACf;EAEJ,MAAM,SAAS,cAAc,iBAAiB;GAC5C;GACA,MAAM;GACN,SAAS,KAAK,OAAO;GACrB,QAAQ;EACV,CAAC;EAED,MAAM,gBAAgB,MAAM,YAAY,IAAI;EAC5C,IAAI,CAAC,eACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,aAAa,OAAO,KAAK,OAAO,UAAU;EAEhD,MAAM,mBAAmB,MAAMC,oCAAAA,sBAC7B,QACA,eACAC,gCAAAA,iBACA,mBACA;GACE;GACA,YAAY;GACZ,SAAS,UAAU;GACnB,cAAc,KAAK,OAAO,UAAU;GACpC,gBAAgB,UAAU;GAC1B,QAAQ;GACR,cAAc,cAAc,QAAS;EACvC,CACF;EAEA,IAAI,CAAC,kBAAkB;GACrB,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;GACpD,OAAO,EAAE,QAAQ,YAAY;EAC/B;EAEA,MAAM,kBAAkB,CAAC,GAAG,sBAAsB;EAOlD,IAAI,CAJ4B,gBAAgB,MAAM,oBACpDC,oCAAAA,oBAAoB,iBAAiB,gBAAgB,CAG5B,GAAG;GAC5B,cAAc,aAAa,MAAM,OAAO,MAAM,iBAAiB;GAE/D,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;GAI5B,MAAM,YAAY,OAAA,GAAMC,WAAAA,UAAAA,CACtB,eACAC,aAAAA,eACA,eACF,CAAC,CAAC;IACA,SAAS,cAAc;IACvB,QAAQ,iBAAiB;IACzB,OAAO,iBAAiB;IACxB,aAAa,iBAAiB;IAC9B,SAAS,iBAAiB;GAC5B,CAAC;GAKD,IAAI,CAACC,+BAAAA,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,58 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_client_publicClient = require("../client/publicClient.js");
3
+ let viem = require("viem");
4
+ let viem_actions = require("viem/actions");
5
+ let viem_utils = require("viem/utils");
6
+ //#region src/permits/acceptsRawEcdsaSignature.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 an account with code whether it evaluates a plain 65-byte ECDSA
27
+ * signature: a return means it recovered a signer and merely found a mismatch,
28
+ * so the real root-key signature will verify, while a revert means it rejected
29
+ * the envelope and nothing we produce will. Keyed on revert-vs-return, never on
30
+ * the value — the probe signature recovers to a third party on purpose, so a
31
+ * correct implementation returns a *non*-magic value, and comparing against the
32
+ * magic value would reject every wallet this exists to accept. Only call it for
33
+ * accounts that have code; a code-less address returns empty data and would read
34
+ * as incapable.
35
+ */
36
+ const acceptsRawEcdsaSignature = async (client, chainId, address) => {
37
+ try {
38
+ const publicClient = await require_client_publicClient.getPublicClient(client, chainId);
39
+ const { data } = await (0, viem_utils.getAction)({
40
+ ...publicClient,
41
+ ccipRead: false
42
+ }, viem_actions.call, "call")({
43
+ to: address,
44
+ data: (0, viem.encodeFunctionData)({
45
+ abi: ERC1271_ABI,
46
+ functionName: "isValidSignature",
47
+ args: [PROBE_HASH, PROBE_SIGNATURE]
48
+ })
49
+ });
50
+ return !!data && data.length >= 66;
51
+ } catch {
52
+ return false;
53
+ }
54
+ };
55
+ //#endregion
56
+ exports.acceptsRawEcdsaSignature = acceptsRawEcdsaSignature;
57
+
58
+ //# sourceMappingURL=acceptsRawEcdsaSignature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acceptsRawEcdsaSignature.js","names":["getPublicClient","getAction","call","encodeFunctionData"],"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,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"}
@@ -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,23 +1,43 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_actions_getAccountCode = require("../actions/getAccountCode.js");
3
- const require_actions_isSmartContractWallet = require("../actions/isSmartContractWallet.js");
3
+ const require_permits_acceptsRawEcdsaSignature = require("./acceptsRawEcdsaSignature.js");
4
+ const require_permits_isDelegationDesignatorCode = require("./isDelegationDesignatorCode.js");
4
5
  //#region src/permits/canAccountUseNativePermits.ts
5
6
  /**
6
- * Whether the account can use native EIP-2612 permits — true for EOAs and
7
- * EIP-7702 delegated EOAs (both produce ECDSA signatures), false for
8
- * smart-contract wallets. Conservatively false on missing chain id or RPC
9
- * failure ("if unsure, don't use permits").
7
+ * Whether the account can produce a signature an EIP-2612 `permit` will accept.
8
+ *
9
+ * Signing ECDSA is not the question — verification is. Tokens whose `permit`
10
+ * routes through a `SignatureChecker` branch on `owner.code.length` exactly as
11
+ * Permit2 does, so an owner with code takes the EIP-1271 path where strict
12
+ * delegates reject a bare signature (Circle's `FiatTokenV2_2`, i.e. USDC), hence
13
+ * the {@link acceptsRawEcdsaSignature} probe for EIP-7702 delegates.
14
+ *
15
+ * Other contract accounts stay blocked on shape alone and are never probed.
16
+ * `encodeNativePermitData` splits the signature with `parseSignature`, so this
17
+ * path needs 65 ECDSA bytes — which a 7702 delegate signing with its root key
18
+ * always produces, and a contract wallet generally does not. Probing them would
19
+ * admit any implementation that *returns* a failure value rather than reverting,
20
+ * skip the approval, then throw after the user had already signed.
21
+ *
22
+ * The probe describes the account while the verifier lives in the token, so a
23
+ * strict delegate spending a plain-`ecrecover` token is refused a permit it
24
+ * could have used — an approval rather than a revert, and the token's path is
25
+ * not reliably introspectable. `false` on RPC failure.
26
+ *
27
+ * Takes the chain and owner explicitly, mirroring {@link canAccountUsePermit2}:
28
+ * reading them off a wallet client silently reported "no native permit" for
29
+ * every caller that falls back to a public client.
10
30
  */
11
- const canAccountUseNativePermits = async (client, viemClient) => {
12
- const chainId = viemClient.chain?.id;
13
- if (chainId === void 0) return false;
31
+ const canAccountUseNativePermits = async (client, { chainId, address }) => {
14
32
  const code = await require_actions_getAccountCode.getAccountCode({
15
33
  client,
16
34
  chainId,
17
- address: viemClient.account.address
35
+ address
18
36
  });
19
37
  if (code === void 0) return false;
20
- return !require_actions_isSmartContractWallet.isSmartContractWalletCode(code);
38
+ if (code === "0x") return true;
39
+ if (!require_permits_isDelegationDesignatorCode.isDelegationDesignatorCode(code)) return false;
40
+ return require_permits_acceptsRawEcdsaSignature.acceptsRawEcdsaSignature(client, chainId, address);
21
41
  };
22
42
  //#endregion
23
43
  exports.canAccountUseNativePermits = canAccountUseNativePermits;
@@ -1 +1 @@
1
- {"version":3,"file":"canAccountUseNativePermits.js","names":["getAccountCode","isSmartContractWalletCode"],"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,MAAMA,+BAAAA,eAAe;EAChC;EACA;EACA,SAAS,WAAW,QAAS;CAC/B,CAAC;CAGD,IAAI,SAAS,KAAA,GACX,OAAO;CAET,OAAO,CAACC,sCAAAA,0BAA0B,IAAI;AACxC"}
1
+ {"version":3,"file":"canAccountUseNativePermits.js","names":["getAccountCode","isDelegationDesignatorCode","acceptsRawEcdsaSignature"],"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,MAAMA,+BAAAA,eAAe;EAAE;EAAQ;EAAS;CAAQ,CAAC;CAG9D,IAAI,SAAS,KAAA,GACX,OAAO;CAET,IAAI,SAAS,MACX,OAAO;CAIT,IAAI,CAACC,2CAAAA,2BAA2B,IAAI,GAClC,OAAO;CAET,OAAOC,yCAAAA,yBAAyB,QAAQ,SAAS,OAAO;AAC1D"}
@@ -1,62 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_client_publicClient = require("../client/publicClient.js");
3
2
  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");
3
+ const require_permits_acceptsRawEcdsaSignature = require("./acceptsRawEcdsaSignature.js");
7
4
  //#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
5
  /**
61
6
  * Whether the account can produce a signature Uniswap Permit2 will accept.
62
7
  *
@@ -79,7 +24,7 @@ const canAccountUsePermit2 = async (client, { chainId, address }) => {
79
24
  });
80
25
  if (code === void 0) return false;
81
26
  if (code === "0x") return true;
82
- return acceptsRawEcdsaSignature(client, chainId, address);
27
+ return require_permits_acceptsRawEcdsaSignature.acceptsRawEcdsaSignature(client, chainId, address);
83
28
  };
84
29
  //#endregion
85
30
  exports.canAccountUsePermit2 = canAccountUsePermit2;
@@ -1 +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
+ {"version":3,"file":"canAccountUsePermit2.js","names":["getAccountCode","acceptsRawEcdsaSignature"],"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,MAAMA,+BAAAA,eAAe;EAAE;EAAQ;EAAS;CAAQ,CAAC;CAC9D,IAAI,SAAS,KAAA,GACX,OAAO;CAET,IAAI,SAAS,MACX,OAAO;CAET,OAAOC,yCAAAA,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
@@ -67,7 +67,7 @@ function validateDomainSeparator({ name, version, chainId, verifyingContract, do
67
67
  * @param tokenAddress - The token contract address
68
68
  * @returns Contract data if EIP-5267 is supported, undefined otherwise
69
69
  */
70
- const getEIP712DomainData = async (client, viemClient, chainId, tokenAddress) => {
70
+ const getEIP712DomainData = async (client, viemClient, chainId, tokenAddress, ownerAddress) => {
71
71
  try {
72
72
  const multicallAddress = await require_actions_getMulticallAddress.getMulticallAddress(client, chainId);
73
73
  const contractCalls = [{
@@ -78,7 +78,7 @@ const getEIP712DomainData = async (client, viemClient, chainId, tokenAddress) =>
78
78
  address: tokenAddress,
79
79
  abi: require_utils_abi.eip2612Abi,
80
80
  functionName: "nonces",
81
- args: [viemClient.account.address]
81
+ args: [ownerAddress]
82
82
  }];
83
83
  if (multicallAddress) try {
84
84
  const [eip712DomainResult, noncesResult] = await require_utils_getActionWithFallback.getActionWithFallback(client, viemClient, viem_actions.multicall, "multicall", {
@@ -131,9 +131,9 @@ const getEIP712DomainData = async (client, viemClient, chainId, tokenAddress) =>
131
131
  return;
132
132
  }
133
133
  };
134
- const getContractData = async (client, viemClient, chainId, tokenAddress) => {
134
+ const getContractData = async (client, viemClient, chainId, tokenAddress, ownerAddress) => {
135
135
  try {
136
- const eip5267Data = await getEIP712DomainData(client, viemClient, chainId, tokenAddress);
136
+ const eip5267Data = await getEIP712DomainData(client, viemClient, chainId, tokenAddress, ownerAddress);
137
137
  if (eip5267Data) return eip5267Data;
138
138
  const multicallAddress = await require_actions_getMulticallAddress.getMulticallAddress(client, chainId);
139
139
  const contractCalls = [
@@ -156,7 +156,7 @@ const getContractData = async (client, viemClient, chainId, tokenAddress) => {
156
156
  address: tokenAddress,
157
157
  abi: require_utils_abi.eip2612Abi,
158
158
  functionName: "nonces",
159
- args: [viemClient.account.address]
159
+ args: [ownerAddress]
160
160
  },
161
161
  {
162
162
  address: tokenAddress,
@@ -218,14 +218,17 @@ const getContractData = async (client, viemClient, chainId, tokenAddress) => {
218
218
  * @param tokenAddress - The address of the token to check for permit support
219
219
  * @returns {Promise<NativePermitData>} Object containing permit data including name, version, nonce and support status
220
220
  */
221
- const getNativePermit = async (viemClient, { client, chainId, tokenAddress, spenderAddress, amount }) => {
222
- if (!await require_permits_canAccountUseNativePermits.canAccountUseNativePermits(client, viemClient)) return;
223
- const contractData = await getContractData(client, viemClient, chainId, tokenAddress);
221
+ const getNativePermit = async (viemClient, { client, chainId, tokenAddress, spenderAddress, amount, ownerAddress }) => {
222
+ if (!await require_permits_canAccountUseNativePermits.canAccountUseNativePermits(client, {
223
+ chainId,
224
+ address: ownerAddress
225
+ })) return;
226
+ const contractData = await getContractData(client, viemClient, chainId, tokenAddress, ownerAddress);
224
227
  if (!contractData) return;
225
228
  if (contractData.permitTypehash === "0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb") return;
226
229
  const deadline = BigInt(Math.floor(Date.now() / 1e3) + 1800).toString();
227
230
  const message = {
228
- owner: viemClient.account.address,
231
+ owner: ownerAddress,
229
232
  spender: spenderAddress,
230
233
  value: amount.toString(),
231
234
  nonce: contractData.nonce.toString(),
@@ -1 +1 @@
1
- {"version":3,"file":"getNativePermit.js","names":["keccak256","toBytes","encodeAbiParameters","parseAbiParameters","EIP712_DOMAIN_TYPEHASH_WITH_SALT","pad","toHex","EIP712_DOMAIN_TYPEHASH","getMulticallAddress","eip2612Abi","getActionWithFallback","multicall","zeroHash","readContract","canAccountUseNativePermits","eip2612Types"],"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,YAAA,GAAWA,KAAAA,UAAAA,EAAAA,GAAUC,KAAAA,QAAAA,CAAQ,IAAI,CAAC;CACxC,MAAM,eAAA,GAAcD,KAAAA,UAAAA,EAAAA,GAAUC,KAAAA,QAAAA,CAAQ,OAAO,CAAC;CAE9C,MAAM,UAAU,YAAA,GACZC,KAAAA,oBAAAA,EAAAA,GACEC,KAAAA,mBAAAA,CAAmB,6CAA6C,GAChE;EACEC,0BAAAA;EACA;EACA;EACA;GACAC,GAAAA,KAAAA,IAAAA,EAAAA,GAAIC,KAAAA,MAAAA,CAAM,OAAO,GAAG,EAAE,MAAM,GAAG,CAAC;CAClC,CACF,KAAA,GACAJ,KAAAA,oBAAAA,EAAAA,GACEC,KAAAA,mBAAAA,CAAmB,6CAA6C,GAChE;EACEI,0BAAAA;EACA;EACA;EACA,OAAO,OAAO;EACd;CACF,CACF;CAEJ,QAAA,GAAOP,KAAAA,UAAAA,CAAU,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,OAAO;GACL,SAAS;GACT,QAAQ,WACJ;IACE;IACA;IACA;IACA,OAA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,aAAa;EACrB,OAAOC,0BAAAA;EACP;CACF;AACF"}
1
+ {"version":3,"file":"getNativePermit.js","names":["keccak256","toBytes","encodeAbiParameters","parseAbiParameters","EIP712_DOMAIN_TYPEHASH_WITH_SALT","pad","toHex","EIP712_DOMAIN_TYPEHASH","getMulticallAddress","eip2612Abi","getActionWithFallback","multicall","zeroHash","readContract","canAccountUseNativePermits","eip2612Types"],"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,YAAA,GAAWA,KAAAA,UAAAA,EAAAA,GAAUC,KAAAA,QAAAA,CAAQ,IAAI,CAAC;CACxC,MAAM,eAAA,GAAcD,KAAAA,UAAAA,EAAAA,GAAUC,KAAAA,QAAAA,CAAQ,OAAO,CAAC;CAE9C,MAAM,UAAU,YAAA,GACZC,KAAAA,oBAAAA,EAAAA,GACEC,KAAAA,mBAAAA,CAAmB,6CAA6C,GAChE;EACEC,0BAAAA;EACA;EACA;EACA;GACAC,GAAAA,KAAAA,IAAAA,EAAAA,GAAIC,KAAAA,MAAAA,CAAM,OAAO,GAAG,EAAE,MAAM,GAAG,CAAC;CAClC,CACF,KAAA,GACAJ,KAAAA,oBAAAA,EAAAA,GACEC,KAAAA,mBAAAA,CAAmB,6CAA6C,GAChE;EACEI,0BAAAA;EACA;EACA;EACA,OAAO,OAAO;EACd;CACF,CACF;CAEJ,QAAA,GAAOP,KAAAA,UAAAA,CAAU,OAAO;AAC1B;AAEA,SAAS,wBAAwB,EAC/B,MACA,SACA,SACA,mBACA,mBAOgD;CAChD,IAAI,CA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,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,OAAOC,0BAAAA;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.11";
3
+ declare const version = "4.0.13";
4
4
  //#endregion
5
5
  export { name, version };
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/version.ts
3
3
  const name = "@lifi/sdk-provider-ethereum";
4
- const version = "4.0.11";
4
+ const version = "4.0.13";
5
5
  //#endregion
6
6
  exports.name = name;
7
7
  exports.version = version;
@@ -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.11'\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.13'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
@@ -28,7 +28,8 @@ const checkPermitSupport = async (client, { chain, tokenAddress, ownerAddress, a
28
28
  chainId: chain.id,
29
29
  tokenAddress,
30
30
  spenderAddress: chain.permit2Proxy,
31
- amount
31
+ amount,
32
+ ownerAddress
32
33
  });
33
34
  let permit2Allowance;
34
35
  if (chain.permit2 && await canAccountUsePermit2(client, {