@lifi/sdk-provider-ethereum 4.1.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +24 -8
- package/dist/cjs/core/EthereumStepExecutor.js +2 -0
- package/dist/cjs/core/EthereumStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckBalanceTask.d.ts +2 -2
- package/dist/cjs/core/tasks/EthereumCheckBalanceTask.js +6 -5
- package/dist/cjs/core/tasks/EthereumCheckBalanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckPermitsTask.js +11 -29
- package/dist/cjs/core/tasks/EthereumCheckPermitsTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumNativePermitTask.js +2 -0
- package/dist/cjs/core/tasks/EthereumNativePermitTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumPermit2AllowanceTask.d.ts +10 -0
- package/dist/cjs/core/tasks/EthereumPermit2AllowanceTask.js +33 -0
- package/dist/cjs/core/tasks/EthereumPermit2AllowanceTask.js.map +1 -0
- package/dist/cjs/core/tasks/EthereumPrepareTransactionTask.js +6 -4
- package/dist/cjs/core/tasks/EthereumPrepareTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumRelayedSignAndExecuteTask.js +14 -27
- package/dist/cjs/core/tasks/EthereumRelayedSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js +2 -3
- package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js +3 -4
- package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/findSignedNativePermit.d.ts +7 -0
- package/dist/cjs/core/tasks/helpers/findSignedNativePermit.js +15 -0
- package/dist/cjs/core/tasks/helpers/findSignedNativePermit.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/getApprovalAmount.d.ts +6 -0
- package/dist/cjs/core/tasks/helpers/getApprovalAmount.js +16 -0
- package/dist/cjs/core/tasks/helpers/getApprovalAmount.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.d.ts +7 -1
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js +12 -4
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/getUpdatedStep.d.ts +3 -2
- package/dist/cjs/core/tasks/helpers/getUpdatedStep.js +4 -4
- package/dist/cjs/core/tasks/helpers/getUpdatedStep.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/hasPermit2AllowanceInFlight.d.ts +8 -0
- package/dist/cjs/core/tasks/helpers/hasPermit2AllowanceInFlight.js +17 -0
- package/dist/cjs/core/tasks/helpers/hasPermit2AllowanceInFlight.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/isTypedDataAlreadySigned.d.ts +6 -0
- package/dist/cjs/core/tasks/helpers/isTypedDataAlreadySigned.js +29 -0
- package/dist/cjs/core/tasks/helpers/isTypedDataAlreadySigned.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/preservePermit2Allowances.d.ts +11 -0
- package/dist/cjs/core/tasks/helpers/preservePermit2Allowances.js +22 -0
- package/dist/cjs/core/tasks/helpers/preservePermit2Allowances.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/resolvePermit2Support.js +2 -1
- package/dist/cjs/core/tasks/helpers/resolvePermit2Support.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.d.ts +1 -1
- package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.js +3 -3
- package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/signTypedDataEntries.d.ts +13 -0
- package/dist/cjs/core/tasks/helpers/signTypedDataEntries.js +37 -0
- package/dist/cjs/core/tasks/helpers/signTypedDataEntries.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/utils/getTypedDataLane.d.ts +15 -0
- package/dist/cjs/utils/getTypedDataLane.js +33 -0
- package/dist/cjs/utils/getTypedDataLane.js.map +1 -0
- package/dist/cjs/utils/isGaslessStep.d.ts +3 -1
- package/dist/cjs/utils/isGaslessStep.js +7 -1
- package/dist/cjs/utils/isGaslessStep.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/core/EthereumStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/EthereumStepExecutor.js +2 -0
- package/dist/esm/core/EthereumStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/EthereumCheckBalanceTask.d.ts +2 -2
- package/dist/esm/core/tasks/EthereumCheckBalanceTask.js +6 -5
- package/dist/esm/core/tasks/EthereumCheckBalanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumCheckPermitsTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumCheckPermitsTask.js +11 -29
- package/dist/esm/core/tasks/EthereumCheckPermitsTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumNativePermitTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumNativePermitTask.js +2 -0
- package/dist/esm/core/tasks/EthereumNativePermitTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumPermit2AllowanceTask.d.ts +10 -0
- package/dist/esm/core/tasks/EthereumPermit2AllowanceTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/EthereumPermit2AllowanceTask.js +32 -0
- package/dist/esm/core/tasks/EthereumPermit2AllowanceTask.js.map +1 -0
- package/dist/esm/core/tasks/EthereumPrepareTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumPrepareTransactionTask.js +6 -4
- package/dist/esm/core/tasks/EthereumPrepareTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.js +14 -27
- package/dist/esm/core/tasks/EthereumRelayedSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumSetAllowanceTask.js +2 -3
- package/dist/esm/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js +3 -4
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/helpers/findSignedNativePermit.d.ts +7 -0
- package/dist/esm/core/tasks/helpers/findSignedNativePermit.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/findSignedNativePermit.js +14 -0
- package/dist/esm/core/tasks/helpers/findSignedNativePermit.js.map +1 -0
- package/dist/esm/core/tasks/helpers/getApprovalAmount.d.ts +6 -0
- package/dist/esm/core/tasks/helpers/getApprovalAmount.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/getApprovalAmount.js +15 -0
- package/dist/esm/core/tasks/helpers/getApprovalAmount.js.map +1 -0
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.d.ts +7 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js +12 -4
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
- package/dist/esm/core/tasks/helpers/getUpdatedStep.d.ts +3 -2
- package/dist/esm/core/tasks/helpers/getUpdatedStep.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/getUpdatedStep.js +4 -4
- package/dist/esm/core/tasks/helpers/getUpdatedStep.js.map +1 -1
- package/dist/esm/core/tasks/helpers/hasPermit2AllowanceInFlight.d.ts +8 -0
- package/dist/esm/core/tasks/helpers/hasPermit2AllowanceInFlight.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/hasPermit2AllowanceInFlight.js +15 -0
- package/dist/esm/core/tasks/helpers/hasPermit2AllowanceInFlight.js.map +1 -0
- package/dist/esm/core/tasks/helpers/isTypedDataAlreadySigned.d.ts +6 -0
- package/dist/esm/core/tasks/helpers/isTypedDataAlreadySigned.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/isTypedDataAlreadySigned.js +28 -0
- package/dist/esm/core/tasks/helpers/isTypedDataAlreadySigned.js.map +1 -0
- package/dist/esm/core/tasks/helpers/preservePermit2Allowances.d.ts +11 -0
- package/dist/esm/core/tasks/helpers/preservePermit2Allowances.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/preservePermit2Allowances.js +21 -0
- package/dist/esm/core/tasks/helpers/preservePermit2Allowances.js.map +1 -0
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.js +2 -1
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.js.map +1 -1
- package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.d.ts +1 -1
- package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.js +3 -3
- package/dist/esm/core/tasks/helpers/signHyperliquidTypedData.js.map +1 -1
- package/dist/esm/core/tasks/helpers/signTypedDataEntries.d.ts +13 -0
- package/dist/esm/core/tasks/helpers/signTypedDataEntries.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/signTypedDataEntries.js +36 -0
- package/dist/esm/core/tasks/helpers/signTypedDataEntries.js.map +1 -0
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +2 -3
- package/dist/esm/utils/getTypedDataLane.d.ts +15 -0
- package/dist/esm/utils/getTypedDataLane.d.ts.map +1 -0
- package/dist/esm/utils/getTypedDataLane.js +28 -0
- package/dist/esm/utils/getTypedDataLane.js.map +1 -0
- package/dist/esm/utils/isGaslessStep.d.ts +3 -1
- package/dist/esm/utils/isGaslessStep.d.ts.map +1 -1
- package/dist/esm/utils/isGaslessStep.js +7 -2
- package/dist/esm/utils/isGaslessStep.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -3
- package/src/core/EthereumStepExecutor.ts +2 -0
- package/src/core/tasks/EthereumCheckBalanceTask.ts +6 -7
- package/src/core/tasks/EthereumCheckPermitsTask.ts +31 -63
- package/src/core/tasks/EthereumNativePermitTask.ts +5 -0
- package/src/core/tasks/EthereumPermit2AllowanceTask.ts +53 -0
- package/src/core/tasks/EthereumPrepareTransactionTask.ts +11 -2
- package/src/core/tasks/EthereumRelayedSignAndExecuteTask.ts +25 -47
- package/src/core/tasks/EthereumSetAllowanceTask.ts +2 -3
- package/src/core/tasks/EthereumStandardSignAndExecuteTask.ts +2 -9
- package/src/core/tasks/helpers/findSignedNativePermit.ts +23 -0
- package/src/core/tasks/helpers/getApprovalAmount.ts +30 -0
- package/src/core/tasks/helpers/getEthereumExecutionStrategy.ts +31 -5
- package/src/core/tasks/helpers/getUpdatedStep.ts +7 -2
- package/src/core/tasks/helpers/hasPermit2AllowanceInFlight.ts +31 -0
- package/src/core/tasks/helpers/isTypedDataAlreadySigned.ts +56 -0
- package/src/core/tasks/helpers/preservePermit2Allowances.ts +44 -0
- package/src/core/tasks/helpers/resolvePermit2Support.ts +3 -1
- package/src/core/tasks/helpers/signHyperliquidTypedData.ts +3 -3
- package/src/core/tasks/helpers/signTypedDataEntries.ts +70 -0
- package/src/index.ts +0 -1
- package/src/utils/getTypedDataLane.ts +76 -0
- package/src/utils/isGaslessStep.ts +22 -9
- package/src/version.ts +1 -1
- package/dist/cjs/utils/isRelayerStep.d.ts +0 -6
- package/dist/cjs/utils/isRelayerStep.js +0 -9
- package/dist/cjs/utils/isRelayerStep.js.map +0 -1
- package/dist/esm/utils/isRelayerStep.d.ts +0 -6
- package/dist/esm/utils/isRelayerStep.d.ts.map +0 -1
- package/dist/esm/utils/isRelayerStep.js +0 -8
- package/dist/esm/utils/isRelayerStep.js.map +0 -1
- package/src/utils/isRelayerStep.ts +0 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isTypedDataAlreadySigned.js","names":[],"sources":["../../../../../src/core/tasks/helpers/isTypedDataAlreadySigned.ts"],"sourcesContent":["import type { SignedTypedData, TypedData } from '@lifi/sdk'\nimport { isValidSignature } from '../../../utils/isValidSignature.js'\n\n/** Whether `signedTypedData` already holds a signature for this exact entry. */\nexport function isTypedDataAlreadySigned(\n signedTypedData: SignedTypedData[],\n typedData: TypedData\n): boolean {\n // `Permit` stays with `isNativePermitValid`, which also checks the deadline,\n // the amount and the salt. Equality alone would drop those checks.\n if (typedData.primaryType === 'Permit') {\n return false\n }\n\n return signedTypedData.some(\n (signed) =>\n signed.primaryType === typedData.primaryType &&\n isValidSignature(signed.signature) &&\n isSameValue(signed.domain, typedData.domain) &&\n isSameValue(signed.message, typedData.message)\n )\n}\n\n/**\n * `domain` and `message` are decoded JSON, so compare them structurally: a\n * round trip through the API rebuilds the objects, and `JSON.stringify` both\n * depends on key order and throws on a `bigint`. Scalars compare by string\n * form, because `1`, `1n` and `'1'` are one EIP-712 value.\n */\nfunction isSameValue(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true\n }\n if (Array.isArray(a) || Array.isArray(b)) {\n return (\n Array.isArray(a) &&\n Array.isArray(b) &&\n a.length === b.length &&\n a.every((item, index) => isSameValue(item, b[index]))\n )\n }\n if (isRecord(a) && isRecord(b)) {\n const keys = Object.keys(a)\n return (\n keys.length === Object.keys(b).length &&\n keys.every((key) => key in b && isSameValue(a[key], b[key]))\n )\n }\n if (a == null || b == null) {\n return false\n }\n return String(a) === String(b)\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null\n"],"mappings":";;;AAIA,SAAgB,yBACd,iBACA,WACS;CAGT,IAAI,UAAU,gBAAgB,UAC5B,OAAO;CAGT,OAAO,gBAAgB,MACpB,WACC,OAAO,gBAAgB,UAAU,eACjC,iBAAiB,OAAO,SAAS,KACjC,YAAY,OAAO,QAAQ,UAAU,MAAM,KAC3C,YAAY,OAAO,SAAS,UAAU,OAAO,CACjD;AACF;;;;;;;AAQA,SAAS,YAAY,GAAY,GAAqB;CACpD,IAAI,MAAM,GACR,OAAO;CAET,IAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GACrC,OACE,MAAM,QAAQ,CAAC,KACf,MAAM,QAAQ,CAAC,KACf,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,MAAM,UAAU,YAAY,MAAM,EAAE,MAAM,CAAC;CAGxD,IAAI,SAAS,CAAC,KAAK,SAAS,CAAC,GAAG;EAC9B,MAAM,OAAO,OAAO,KAAK,CAAC;EAC1B,OACE,KAAK,WAAW,OAAO,KAAK,CAAC,CAAC,CAAC,UAC/B,KAAK,OAAO,QAAQ,OAAO,KAAK,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC;CAE/D;CACA,IAAI,KAAK,QAAQ,KAAK,MACpB,OAAO;CAET,OAAO,OAAO,CAAC,MAAM,OAAO,CAAC;AAC/B;AAEA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExtendedChain, LiFiStep, LiFiStepExtended, TypedData } from "@lifi/sdk";
|
|
2
|
+
//#region src/core/tasks/helpers/preservePermit2Allowances.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* `??` keeps the Permit2 allowance only when the answer omits `typedData`. An
|
|
5
|
+
* answer that carries entries of its own — native permits, or `[]` from a
|
|
6
|
+
* third-party backend — would drop it, and `signedTypedData` resets per
|
|
7
|
+
* `executeStep`, so a retry would let the Permit2 proxy hijack the calldata.
|
|
8
|
+
*/
|
|
9
|
+
export declare function preservePermit2Allowances(step: LiFiStepExtended | LiFiStep, updatedTypedData: TypedData[] | undefined, chain: ExtendedChain): TypedData[] | undefined;
|
|
10
|
+
//#endregion
|
|
11
|
+
//# sourceMappingURL=preservePermit2Allowances.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preservePermit2Allowances.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/preservePermit2Allowances.ts"],"mappings":";;;;;;;;wBAkBgB,0BACd,MAAM,mBAAmB,UACzB,kBAAkB,yBAClB,OAAO,gBACN"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getTypedDataInLane, getTypedDataLane, isPermit2AllowanceLane } from "../../../utils/getTypedDataLane.js";
|
|
2
|
+
//#region src/core/tasks/helpers/preservePermit2Allowances.ts
|
|
3
|
+
/**
|
|
4
|
+
* `??` keeps the Permit2 allowance only when the answer omits `typedData`. An
|
|
5
|
+
* answer that carries entries of its own — native permits, or `[]` from a
|
|
6
|
+
* third-party backend — would drop it, and `signedTypedData` resets per
|
|
7
|
+
* `executeStep`, so a retry would let the Permit2 proxy hijack the calldata.
|
|
8
|
+
*/
|
|
9
|
+
function preservePermit2Allowances(step, updatedTypedData, chain) {
|
|
10
|
+
if (!updatedTypedData) return step.typedData;
|
|
11
|
+
if (!isPermit2AllowanceLane(step, chain)) return updatedTypedData;
|
|
12
|
+
if (updatedTypedData.some((typedData) => {
|
|
13
|
+
const lane = getTypedDataLane(typedData, chain);
|
|
14
|
+
return lane === "permit2-allowance" || lane === "relayer-message";
|
|
15
|
+
})) return updatedTypedData;
|
|
16
|
+
return [...updatedTypedData, ...getTypedDataInLane(step, "permit2-allowance", chain)];
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { preservePermit2Allowances };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=preservePermit2Allowances.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preservePermit2Allowances.js","names":[],"sources":["../../../../../src/core/tasks/helpers/preservePermit2Allowances.ts"],"sourcesContent":["import type {\n ExtendedChain,\n LiFiStep,\n LiFiStepExtended,\n TypedData,\n} from '@lifi/sdk'\nimport {\n getTypedDataInLane,\n getTypedDataLane,\n isPermit2AllowanceLane,\n} from '../../../utils/getTypedDataLane.js'\n\n/**\n * `??` keeps the Permit2 allowance only when the answer omits `typedData`. An\n * answer that carries entries of its own — native permits, or `[]` from a\n * third-party backend — would drop it, and `signedTypedData` resets per\n * `executeStep`, so a retry would let the Permit2 proxy hijack the calldata.\n */\nexport function preservePermit2Allowances(\n step: LiFiStepExtended | LiFiStep,\n updatedTypedData: TypedData[] | undefined,\n chain: ExtendedChain\n): TypedData[] | undefined {\n if (!updatedTypedData) {\n return step.typedData\n }\n\n if (!isPermit2AllowanceLane(step, chain)) {\n return updatedTypedData\n }\n\n const answerDeclaresLane = updatedTypedData.some((typedData) => {\n const lane = getTypedDataLane(typedData, chain)\n return lane === 'permit2-allowance' || lane === 'relayer-message'\n })\n if (answerDeclaresLane) {\n return updatedTypedData\n }\n\n return [\n ...updatedTypedData,\n ...getTypedDataInLane(step, 'permit2-allowance', chain),\n ]\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,0BACd,MACA,kBACA,OACyB;CACzB,IAAI,CAAC,kBACH,OAAO,KAAK;CAGd,IAAI,CAAC,uBAAuB,MAAM,KAAK,GACrC,OAAO;CAOT,IAJ2B,iBAAiB,MAAM,cAAc;EAC9D,MAAM,OAAO,iBAAiB,WAAW,KAAK;EAC9C,OAAO,SAAS,uBAAuB,SAAS;CAClD,CACqB,GACnB,OAAO;CAGT,OAAO,CACL,GAAG,kBACH,GAAG,mBAAmB,MAAM,qBAAqB,KAAK,CACxD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePermit2Support.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/resolvePermit2Support.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"resolvePermit2Support.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/resolvePermit2Support.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;qBAkDa,wBACX,SAAS,6BACT,UAAU,0BACT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { canAccountUsePermit2 } from "../../../permits/canAccountUsePermit2.js";
|
|
2
|
+
import { isPermit2AllowanceLaneInFlight } from "./hasPermit2AllowanceInFlight.js";
|
|
2
3
|
//#region src/core/tasks/helpers/resolvePermit2Support.ts
|
|
3
4
|
/**
|
|
4
5
|
* Cheap, synchronous part of the gate: does the step/chain combination allow
|
|
@@ -6,7 +7,7 @@ import { canAccountUsePermit2 } from "../../../permits/canAccountUsePermit2.js";
|
|
|
6
7
|
*/
|
|
7
8
|
const isPermit2SupportedForStep = (context, strategy) => {
|
|
8
9
|
const { step, fromChain, isFromNativeToken, disableMessageSigning } = context;
|
|
9
|
-
return !!fromChain.permit2 && !!fromChain.permit2Proxy && !isFromNativeToken && !disableMessageSigning && strategy !== "batched" && !!step.estimate.approvalAddress && !step.estimate.skipApproval && !step.estimate.skipPermit;
|
|
10
|
+
return !!fromChain.permit2 && !!fromChain.permit2Proxy && !isFromNativeToken && !disableMessageSigning && strategy !== "batched" && !!step.estimate.approvalAddress && !step.estimate.skipApproval && !step.estimate.skipPermit && !isPermit2AllowanceLaneInFlight(context);
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Whether this step should use the Permit2 signature flow.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePermit2Support.js","names":[],"sources":["../../../../../src/core/tasks/helpers/resolvePermit2Support.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { canAccountUsePermit2 } from '../../../permits/canAccountUsePermit2.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\n\n/**\n * Cheap, synchronous part of the gate: does the step/chain combination allow\n * the Permit2 flow at all? Permit2 should not be available for atomic batch.\n */\nconst isPermit2SupportedForStep = (\n context: EthereumStepExecutorContext,\n strategy: TransactionMethodType\n): boolean => {\n const { step, fromChain, isFromNativeToken, disableMessageSigning } = context\n\n return (\n !!fromChain.permit2 &&\n !!fromChain.permit2Proxy &&\n !isFromNativeToken &&\n !disableMessageSigning &&\n strategy !== 'batched' &&\n // Approval address is not required for Permit2 per se, but we use it to skip allowance checks for direct transfers\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval &&\n !step.estimate.skipPermit\n )\n}\n\n/**\n * Whether this step should use the Permit2 signature flow.\n *\n * Beyond the step/chain checks, the `standard` strategy also probes the\n * *signer*: code-bearing accounts send Permit2 down its EIP-1271 path, where\n * acceptance is implementation-specific — see {@link canAccountUsePermit2}.\n * Accounts that fail it fall back to approve + execute.\n *\n * Only `standard` consults the probe. `signPermit2Message` has one call site,\n * `EthereumStandardSignAndExecuteTask`, so that is the only flow where the SDK\n * produces the Permit2 signature itself. A relayed step has no approve +\n * execute fallback, so a verdict cannot rescue a failing account and would\n * break a working one — it must never move the spender off `fromChain.permit2`.\n *\n * The verdict is memoized on `context.permit2SignerSupported`, and a `false`\n * stays sticky, a failed lookup included. `TaskPipeline` threads one context\n * through every task, so a mid-run flip would let the allowance tasks approve\n * one spender while the sign task routes to the other — turning a needless\n * approval into a revert.\n */\nexport const resolvePermit2Support = async (\n context: EthereumStepExecutorContext,\n strategy: TransactionMethodType\n): Promise<boolean> => {\n if (!isPermit2SupportedForStep(context, strategy)) {\n return false\n }\n\n // Only `standard` consults the probe; `batched` is excluded above.\n if (strategy !== 'standard') {\n return true\n }\n\n const { client, step, fromChain, ethereumClient } = context\n const address = (step.action.fromAddress ??\n ethereumClient.account?.address) as Address | undefined\n if (!address) {\n return false\n }\n\n // Caching the promise is safe: `canAccountUsePermit2` never rejects.\n context.permit2SignerSupported ??= canAccountUsePermit2(client, {\n chainId: fromChain.id,\n address,\n })\n\n return context.permit2SignerSupported\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolvePermit2Support.js","names":[],"sources":["../../../../../src/core/tasks/helpers/resolvePermit2Support.ts"],"sourcesContent":["import type { TransactionMethodType } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { canAccountUsePermit2 } from '../../../permits/canAccountUsePermit2.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { isPermit2AllowanceLaneInFlight } from './hasPermit2AllowanceInFlight.js'\n\n/**\n * Cheap, synchronous part of the gate: does the step/chain combination allow\n * the Permit2 flow at all? Permit2 should not be available for atomic batch.\n */\nconst isPermit2SupportedForStep = (\n context: EthereumStepExecutorContext,\n strategy: TransactionMethodType\n): boolean => {\n const { step, fromChain, isFromNativeToken, disableMessageSigning } = context\n\n return (\n !!fromChain.permit2 &&\n !!fromChain.permit2Proxy &&\n !isFromNativeToken &&\n !disableMessageSigning &&\n strategy !== 'batched' &&\n // Approval address is not required for Permit2 per se, but we use it to skip allowance checks for direct transfers\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval &&\n !step.estimate.skipPermit &&\n !isPermit2AllowanceLaneInFlight(context)\n )\n}\n\n/**\n * Whether this step should use the Permit2 signature flow.\n *\n * Beyond the step/chain checks, the `standard` strategy also probes the\n * *signer*: code-bearing accounts send Permit2 down its EIP-1271 path, where\n * acceptance is implementation-specific — see {@link canAccountUsePermit2}.\n * Accounts that fail it fall back to approve + execute.\n *\n * Only `standard` consults the probe. `signPermit2Message` has one call site,\n * `EthereumStandardSignAndExecuteTask`, so that is the only flow where the SDK\n * produces the Permit2 signature itself. A relayed step has no approve +\n * execute fallback, so a verdict cannot rescue a failing account and would\n * break a working one — it must never move the spender off `fromChain.permit2`.\n *\n * The verdict is memoized on `context.permit2SignerSupported`, and a `false`\n * stays sticky, a failed lookup included. `TaskPipeline` threads one context\n * through every task, so a mid-run flip would let the allowance tasks approve\n * one spender while the sign task routes to the other — turning a needless\n * approval into a revert.\n */\nexport const resolvePermit2Support = async (\n context: EthereumStepExecutorContext,\n strategy: TransactionMethodType\n): Promise<boolean> => {\n if (!isPermit2SupportedForStep(context, strategy)) {\n return false\n }\n\n // Only `standard` consults the probe; `batched` is excluded above.\n if (strategy !== 'standard') {\n return true\n }\n\n const { client, step, fromChain, ethereumClient } = context\n const address = (step.action.fromAddress ??\n ethereumClient.account?.address) as Address | undefined\n if (!address) {\n return false\n }\n\n // Caching the promise is safe: `canAccountUsePermit2` never rejects.\n context.permit2SignerSupported ??= canAccountUsePermit2(client, {\n chainId: fromChain.id,\n address,\n })\n\n return context.permit2SignerSupported\n}\n"],"mappings":";;;;;;;AAUA,MAAM,6BACJ,SACA,aACY;CACZ,MAAM,EAAE,MAAM,WAAW,mBAAmB,0BAA0B;CAEtE,OACE,CAAC,CAAC,UAAU,WACZ,CAAC,CAAC,UAAU,gBACZ,CAAC,qBACD,CAAC,yBACD,aAAa,aAEb,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS,gBACf,CAAC,KAAK,SAAS,cACf,CAAC,+BAA+B,OAAO;AAE3C;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,wBAAwB,OACnC,SACA,aACqB;CACrB,IAAI,CAAC,0BAA0B,SAAS,QAAQ,GAC9C,OAAO;CAIT,IAAI,aAAa,YACf,OAAO;CAGT,MAAM,EAAE,QAAQ,MAAM,WAAW,mBAAmB;CACpD,MAAM,UAAW,KAAK,OAAO,eAC3B,eAAe,SAAS;CAC1B,IAAI,CAAC,SACH,OAAO;CAIT,QAAQ,2BAA2B,qBAAqB,QAAQ;EAC9D,SAAS,UAAU;EACnB;CACF,CAAC;CAED,OAAO,QAAQ;AACjB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EthereumStepExecutorContext } from "../../../types.js";
|
|
2
2
|
import { SignedTypedData, TypedData } from "@lifi/sdk";
|
|
3
3
|
//#region src/core/tasks/helpers/signHyperliquidTypedData.d.ts
|
|
4
|
-
export declare const signHyperliquidTypedData: (context: EthereumStepExecutorContext,
|
|
4
|
+
export declare const signHyperliquidTypedData: (context: EthereumStepExecutorContext, allowanceTypedData: TypedData[]) => Promise<SignedTypedData[] | undefined>;
|
|
5
5
|
//#endregion
|
|
6
6
|
//# sourceMappingURL=signHyperliquidTypedData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signHyperliquidTypedData.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signHyperliquidTypedData.ts"],"mappings":";;;qBAaa,2BACX,SAAS,6BACT,
|
|
1
|
+
{"version":3,"file":"signHyperliquidTypedData.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signHyperliquidTypedData.ts"],"mappings":";;;qBAaa,2BACX,SAAS,6BACT,oBAAoB,gBACnB,QAAQ"}
|
|
@@ -5,15 +5,15 @@ import { getOrCreateAgentWallet } from "../../../hyperliquid/agentWallet.js";
|
|
|
5
5
|
import { signTypedData } from "viem/actions";
|
|
6
6
|
import { getAction } from "viem/utils";
|
|
7
7
|
//#region src/core/tasks/helpers/signHyperliquidTypedData.ts
|
|
8
|
-
const signHyperliquidTypedData = async (context,
|
|
8
|
+
const signHyperliquidTypedData = async (context, allowanceTypedData) => {
|
|
9
9
|
const { step, fromChain, client, allowUserInteraction, checkClient, ethereumClient, getStorage } = context;
|
|
10
10
|
if (!allowUserInteraction) return;
|
|
11
11
|
const signedResults = [];
|
|
12
12
|
const ownerAddress = ethereumClient.account.address;
|
|
13
13
|
const storage = getStorage(client);
|
|
14
|
-
const existingAgentAddress =
|
|
14
|
+
const existingAgentAddress = allowanceTypedData.find(isApproveAgentMessage)?.message.agentAddress;
|
|
15
15
|
const { account: agentAccount, needsApproval, expiresAt } = await getOrCreateAgentWallet(storage, ownerAddress, existingAgentAddress);
|
|
16
|
-
for (const typedData of
|
|
16
|
+
for (const typedData of allowanceTypedData) if (isApproveAgentMessage(typedData)) {
|
|
17
17
|
if (!needsApproval) continue;
|
|
18
18
|
const message = {
|
|
19
19
|
...typedData.message,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signHyperliquidTypedData.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signHyperliquidTypedData.ts"],"sourcesContent":["import type { SignedTypedData, TypedData } from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getOrCreateAgentWallet } from '../../../hyperliquid/agentWallet.js'\nimport {\n isApproveAgentMessage,\n isApproveBuilderFeeMessage,\n isHyperliquidOrderMessage,\n} from '../../../hyperliquid/isHyperliquidAgentStep.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport const signHyperliquidTypedData = async (\n context: EthereumStepExecutorContext,\n
|
|
1
|
+
{"version":3,"file":"signHyperliquidTypedData.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signHyperliquidTypedData.ts"],"sourcesContent":["import type { SignedTypedData, TypedData } from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getOrCreateAgentWallet } from '../../../hyperliquid/agentWallet.js'\nimport {\n isApproveAgentMessage,\n isApproveBuilderFeeMessage,\n isHyperliquidOrderMessage,\n} from '../../../hyperliquid/isHyperliquidAgentStep.js'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport const signHyperliquidTypedData = async (\n context: EthereumStepExecutorContext,\n allowanceTypedData: TypedData[]\n): Promise<SignedTypedData[] | undefined> => {\n const {\n step,\n fromChain,\n client,\n allowUserInteraction,\n checkClient,\n ethereumClient,\n getStorage,\n } = context\n\n if (!allowUserInteraction) {\n return\n }\n\n const signedResults: SignedTypedData[] = []\n const ownerAddress = ethereumClient.account!.address\n const storage = getStorage(client)\n\n const approveMessage = allowanceTypedData.find(isApproveAgentMessage)\n const existingAgentAddress = approveMessage?.message.agentAddress as\n | string\n | undefined\n\n const {\n account: agentAccount,\n needsApproval,\n expiresAt,\n } = await getOrCreateAgentWallet(storage, ownerAddress, existingAgentAddress)\n\n for (const typedData of allowanceTypedData) {\n if (isApproveAgentMessage(typedData)) {\n if (!needsApproval) {\n continue\n }\n\n const message = {\n ...typedData.message,\n agentAddress: agentAccount.address.toLowerCase(),\n agentName: `${typedData.message.agentName} valid_until ${expiresAt}`,\n }\n const typedDataChainId =\n getDomainChainId(typedData.domain) || fromChain.id\n\n const updatedClient = await checkClient(step, typedDataChainId)\n if (!updatedClient) {\n return\n }\n\n const signature = await getAction(\n updatedClient,\n signTypedData,\n 'signTypedData'\n )({\n account: updatedClient.account!,\n primaryType: typedData.primaryType,\n domain: typedData.domain,\n types: typedData.types,\n message,\n })\n assertValidSignature(signature)\n signedResults.push({ ...typedData, message, signature })\n } else if (isApproveBuilderFeeMessage(typedData)) {\n const typedDataChainId =\n getDomainChainId(typedData.domain) || fromChain.id\n\n const updatedClient = await checkClient(step, typedDataChainId)\n if (!updatedClient) {\n return\n }\n\n const signature = await getAction(\n updatedClient,\n signTypedData,\n 'signTypedData'\n )({\n account: updatedClient.account!,\n primaryType: typedData.primaryType,\n domain: typedData.domain,\n types: typedData.types,\n message: typedData.message,\n })\n assertValidSignature(signature)\n signedResults.push({ ...typedData, signature })\n } else if (isHyperliquidOrderMessage(typedData)) {\n const signature = await agentAccount.signTypedData({\n domain: typedData.domain,\n types: typedData.types,\n primaryType: typedData.primaryType,\n message: typedData.message,\n })\n signedResults.push({ ...typedData, signature })\n }\n }\n\n return signedResults\n}\n"],"mappings":";;;;;;;AAaA,MAAa,2BAA2B,OACtC,SACA,uBAC2C;CAC3C,MAAM,EACJ,MACA,WACA,QACA,sBACA,aACA,gBACA,eACE;CAEJ,IAAI,CAAC,sBACH;CAGF,MAAM,gBAAmC,CAAC;CAC1C,MAAM,eAAe,eAAe,QAAS;CAC7C,MAAM,UAAU,WAAW,MAAM;CAGjC,MAAM,uBADiB,mBAAmB,KAAK,qBACL,CAAC,EAAE,QAAQ;CAIrD,MAAM,EACJ,SAAS,cACT,eACA,cACE,MAAM,uBAAuB,SAAS,cAAc,oBAAoB;CAE5E,KAAK,MAAM,aAAa,oBACtB,IAAI,sBAAsB,SAAS,GAAG;EACpC,IAAI,CAAC,eACH;EAGF,MAAM,UAAU;GACd,GAAG,UAAU;GACb,cAAc,aAAa,QAAQ,YAAY;GAC/C,WAAW,GAAG,UAAU,QAAQ,UAAU,eAAe;EAC3D;EAIA,MAAM,gBAAgB,MAAM,YAAY,MAFtC,iBAAiB,UAAU,MAAM,KAAK,UAAU,EAEY;EAC9D,IAAI,CAAC,eACH;EAGF,MAAM,YAAY,MAAM,UACtB,eACA,eACA,eACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB,aAAa,UAAU;GACvB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB;EACF,CAAC;EACD,qBAAqB,SAAS;EAC9B,cAAc,KAAK;GAAE,GAAG;GAAW;GAAS;EAAU,CAAC;CACzD,OAAO,IAAI,2BAA2B,SAAS,GAAG;EAIhD,MAAM,gBAAgB,MAAM,YAAY,MAFtC,iBAAiB,UAAU,MAAM,KAAK,UAAU,EAEY;EAC9D,IAAI,CAAC,eACH;EAGF,MAAM,YAAY,MAAM,UACtB,eACA,eACA,eACF,CAAC,CAAC;GACA,SAAS,cAAc;GACvB,aAAa,UAAU;GACvB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,SAAS,UAAU;EACrB,CAAC;EACD,qBAAqB,SAAS;EAC9B,cAAc,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAChD,OAAO,IAAI,0BAA0B,SAAS,GAAG;EAC/C,MAAM,YAAY,MAAM,aAAa,cAAc;GACjD,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,aAAa,UAAU;GACvB,SAAS,UAAU;EACrB,CAAC;EACD,cAAc,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAChD;CAGF,OAAO;AACT"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EthereumStepExecutorContext } from "../../../types.js";
|
|
2
|
+
import { ExecutionActionStatus, ExecutionActionType, SignedTypedData, TypedData } from "@lifi/sdk";
|
|
3
|
+
//#region src/core/tasks/helpers/signTypedDataEntries.d.ts
|
|
4
|
+
export type SignTypedDataEntriesResult = {
|
|
5
|
+
status: "PAUSED";
|
|
6
|
+
} | {
|
|
7
|
+
status: "COMPLETED";
|
|
8
|
+
signedTypedData: SignedTypedData[];
|
|
9
|
+
};
|
|
10
|
+
/** Signs the entries in order, switching chains per entry, and appends the signatures. */
|
|
11
|
+
export declare function signTypedDataEntries(context: EthereumStepExecutorContext, entries: TypedData[], actionType: ExecutionActionType, actionStatus?: ExecutionActionStatus): Promise<SignTypedDataEntriesResult>;
|
|
12
|
+
//#endregion
|
|
13
|
+
//# sourceMappingURL=signTypedDataEntries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signTypedDataEntries.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"mappings":";;;YAYY;EACN;;EACA;EAAqB,iBAAiB;;;wBAGtB,qBACpB,SAAS,6BACT,SAAS,aACT,YAAY,qBACZ,eAAc,wBACb,QAAQ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getDomainChainId } from "../../../utils/getDomainChainId.js";
|
|
2
|
+
import { assertValidSignature } from "../../../utils/isValidSignature.js";
|
|
3
|
+
import { signTypedData } from "viem/actions";
|
|
4
|
+
import { getAction } from "viem/utils";
|
|
5
|
+
//#region src/core/tasks/helpers/signTypedDataEntries.ts
|
|
6
|
+
/** Signs the entries in order, switching chains per entry, and appends the signatures. */
|
|
7
|
+
async function signTypedDataEntries(context, entries, actionType, actionStatus = "ACTION_REQUIRED") {
|
|
8
|
+
const { step, statusManager, allowUserInteraction, checkClient, signedTypedData: currentSignedTypedData } = context;
|
|
9
|
+
const signedTypedData = [...currentSignedTypedData];
|
|
10
|
+
if (entries.length) statusManager.updateAction(step, actionType, actionStatus);
|
|
11
|
+
for (const typedData of entries) {
|
|
12
|
+
if (!allowUserInteraction) return { status: "PAUSED" };
|
|
13
|
+
const client = await checkClient(step, getDomainChainId(typedData.domain) || step.action.fromChainId);
|
|
14
|
+
if (!client) return { status: "PAUSED" };
|
|
15
|
+
const signature = await getAction(client, signTypedData, "signTypedData")({
|
|
16
|
+
account: client.account,
|
|
17
|
+
domain: typedData.domain,
|
|
18
|
+
types: typedData.types,
|
|
19
|
+
primaryType: typedData.primaryType,
|
|
20
|
+
message: typedData.message
|
|
21
|
+
});
|
|
22
|
+
assertValidSignature(signature);
|
|
23
|
+
signedTypedData.push({
|
|
24
|
+
...typedData,
|
|
25
|
+
signature
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
status: "COMPLETED",
|
|
30
|
+
signedTypedData
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { signTypedDataEntries };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=signTypedDataEntries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signTypedDataEntries.js","names":[],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"sourcesContent":["import type {\n ExecutionActionStatus,\n ExecutionActionType,\n SignedTypedData,\n TypedData,\n} from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport type SignTypedDataEntriesResult =\n | { status: 'PAUSED' }\n | { status: 'COMPLETED'; signedTypedData: SignedTypedData[] }\n\n/** Signs the entries in order, switching chains per entry, and appends the signatures. */\nexport async function signTypedDataEntries(\n context: EthereumStepExecutorContext,\n entries: TypedData[],\n actionType: ExecutionActionType,\n actionStatus: ExecutionActionStatus = 'ACTION_REQUIRED'\n): Promise<SignTypedDataEntriesResult> {\n const {\n step,\n statusManager,\n allowUserInteraction,\n checkClient,\n signedTypedData: currentSignedTypedData,\n } = context\n\n const signedTypedData = [...currentSignedTypedData]\n\n // Announced once for the round, not once per entry. Relay-from-Hyperliquid\n // carries two messages, and main told the consumer `MESSAGE_REQUIRED` once.\n if (entries.length) {\n statusManager.updateAction(step, actionType, actionStatus)\n }\n\n for (const typedData of entries) {\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n const typedDataChainId =\n getDomainChainId(typedData.domain) || step.action.fromChainId\n\n const client = await checkClient(step, typedDataChainId)\n if (!client) {\n return { status: 'PAUSED' }\n }\n\n const signature = await getAction(\n client,\n signTypedData,\n 'signTypedData'\n )({\n account: client.account!,\n domain: typedData.domain,\n types: typedData.types,\n primaryType: typedData.primaryType,\n message: typedData.message,\n })\n assertValidSignature(signature)\n\n signedTypedData.push({ ...typedData, signature })\n }\n\n return { status: 'COMPLETED', signedTypedData }\n}\n"],"mappings":";;;;;;AAiBA,eAAsB,qBACpB,SACA,SACA,YACA,eAAsC,mBACD;CACrC,MAAM,EACJ,MACA,eACA,sBACA,aACA,iBAAiB,2BACf;CAEJ,MAAM,kBAAkB,CAAC,GAAG,sBAAsB;CAIlD,IAAI,QAAQ,QACV,cAAc,aAAa,MAAM,YAAY,YAAY;CAG3D,KAAK,MAAM,aAAa,SAAS;EAC/B,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAM5B,MAAM,SAAS,MAAM,YAAY,MAF/B,iBAAiB,UAAU,MAAM,KAAK,KAAK,OAAO,WAEG;EACvD,IAAI,CAAC,QACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,YAAY,MAAM,UACtB,QACA,eACA,eACF,CAAC,CAAC;GACA,SAAS,OAAO;GAChB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,aAAa,UAAU;GACvB,SAAS,UAAU;EACrB,CAAC;EACD,qBAAqB,SAAS;EAE9B,gBAAgB,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAClD;CAEA,OAAO;EAAE,QAAQ;EAAa;CAAgB;AAChD"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -12,6 +12,5 @@ import { convertExtendedChain } from "./utils/convertExtendedChain.js";
|
|
|
12
12
|
import { isContractCallStep } from "./utils/isContractCallStep.js";
|
|
13
13
|
import { isExtendedChain } from "./utils/isExtendedChain.js";
|
|
14
14
|
import { isGaslessStep } from "./utils/isGaslessStep.js";
|
|
15
|
-
import { isRelayerStep } from "./utils/isRelayerStep.js";
|
|
16
15
|
import { isZeroAddress } from "./utils/isZeroAddress.js";
|
|
17
|
-
export { EthereumProvider, type EthereumProviderOptions, type EthereumSDKProvider, PatcherMagicNumber, type WalletCallReceipt, checkPermitSupport, convertExtendedChain, getNativePermit, getTokenAllowance, getTokenAllowanceMulticall, isBatchingSupported, isContractCallStep, isDelegationDesignatorCode, isEthereumProvider, isExtendedChain, isGaslessStep, isHyperliquidAgentStep, isHyperliquidOrderMessage,
|
|
16
|
+
export { EthereumProvider, type EthereumProviderOptions, type EthereumSDKProvider, PatcherMagicNumber, type WalletCallReceipt, checkPermitSupport, convertExtendedChain, getNativePermit, getTokenAllowance, getTokenAllowanceMulticall, isBatchingSupported, isContractCallStep, isDelegationDesignatorCode, isEthereumProvider, isExtendedChain, isGaslessStep, isHyperliquidAgentStep, isHyperliquidOrderMessage, isZeroAddress, revokeTokenApproval, setAllowance, setTokenAllowance };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { isZeroAddress } from "./utils/isZeroAddress.js";
|
|
2
2
|
import { getTokenAllowance, getTokenAllowanceMulticall } from "./actions/getAllowance.js";
|
|
3
3
|
import { isBatchingSupported } from "./actions/isBatchingSupported.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isGaslessStep } from "./utils/isGaslessStep.js";
|
|
5
5
|
import { isDelegationDesignatorCode } from "./permits/isDelegationDesignatorCode.js";
|
|
6
6
|
import { PatcherMagicNumber } from "./permits/constants.js";
|
|
7
7
|
import { getNativePermit } from "./permits/getNativePermit.js";
|
|
8
8
|
import { isContractCallStep } from "./utils/isContractCallStep.js";
|
|
9
|
-
import { isGaslessStep } from "./utils/isGaslessStep.js";
|
|
10
9
|
import { isEthereumProvider } from "./types.js";
|
|
11
10
|
import { revokeTokenApproval, setAllowance, setTokenAllowance } from "./actions/setAllowance.js";
|
|
12
11
|
import { isHyperliquidAgentStep, isHyperliquidOrderMessage } from "./hyperliquid/isHyperliquidAgentStep.js";
|
|
@@ -14,4 +13,4 @@ import { convertExtendedChain } from "./utils/convertExtendedChain.js";
|
|
|
14
13
|
import { EthereumProvider } from "./EthereumProvider.js";
|
|
15
14
|
import { checkPermitSupport } from "./actions/checkPermitSupport.js";
|
|
16
15
|
import { isExtendedChain } from "./utils/isExtendedChain.js";
|
|
17
|
-
export { EthereumProvider, PatcherMagicNumber, checkPermitSupport, convertExtendedChain, getNativePermit, getTokenAllowance, getTokenAllowanceMulticall, isBatchingSupported, isContractCallStep, isDelegationDesignatorCode, isEthereumProvider, isExtendedChain, isGaslessStep, isHyperliquidAgentStep, isHyperliquidOrderMessage,
|
|
16
|
+
export { EthereumProvider, PatcherMagicNumber, checkPermitSupport, convertExtendedChain, getNativePermit, getTokenAllowance, getTokenAllowanceMulticall, isBatchingSupported, isContractCallStep, isDelegationDesignatorCode, isEthereumProvider, isExtendedChain, isGaslessStep, isHyperliquidAgentStep, isHyperliquidOrderMessage, isZeroAddress, revokeTokenApproval, setAllowance, setTokenAllowance };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ExtendedChain, LiFiStep, LiFiStepExtended, TypedData } from "@lifi/sdk";
|
|
2
|
+
//#region src/utils/getTypedDataLane.d.ts
|
|
3
|
+
/** Which execution lane one `step.typedData` entry belongs to. */
|
|
4
|
+
export type TypedDataLane = "native-permit" | "permit2-allowance" | "relayer-message";
|
|
5
|
+
export declare function getTypedDataLane(typedData: TypedData, chain: ExtendedChain): TypedDataLane;
|
|
6
|
+
/** Whether the step carries a Permit2 allowance the SDK signs for a caller's own spender. */
|
|
7
|
+
export declare function hasPermit2Allowance(step: LiFiStepExtended | LiFiStep, chain: ExtendedChain): boolean;
|
|
8
|
+
/** The step's typed-data entries that belong to `lane`. */
|
|
9
|
+
export declare function getTypedDataInLane(step: LiFiStepExtended | LiFiStep, lane: TypedDataLane, chain: ExtendedChain): TypedData[];
|
|
10
|
+
/** Whether the step still carries typed data a relayer must sign and submit. */
|
|
11
|
+
export declare function hasRelayerMessage(step: LiFiStepExtended | LiFiStep, chain: ExtendedChain): boolean;
|
|
12
|
+
/** Whether the step carries a Permit2 allowance and nothing a relayer must sign. */
|
|
13
|
+
export declare function isPermit2AllowanceLane(step: LiFiStepExtended | LiFiStep, chain: ExtendedChain): boolean;
|
|
14
|
+
//#endregion
|
|
15
|
+
//# sourceMappingURL=getTypedDataLane.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTypedDataLane.d.ts","names":[],"sources":["../../../src/utils/getTypedDataLane.ts"],"mappings":";;;YASY;wBAQI,iBACd,WAAW,WACX,OAAO,gBACN;;wBAiBa,oBACd,MAAM,mBAAmB,UACzB,OAAO;;wBAQO,mBACd,MAAM,mBAAmB,UACzB,MAAM,eACN,OAAO,gBACN;;wBASa,kBACd,MAAM,mBAAmB,UACzB,OAAO;;wBAQO,uBACd,MAAM,mBAAmB,UACzB,OAAO"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isGaslessTypedData } from "./isGaslessStep.js";
|
|
2
|
+
//#region src/utils/getTypedDataLane.ts
|
|
3
|
+
function getTypedDataLane(typedData, chain) {
|
|
4
|
+
if (typedData.primaryType === "Permit") return "native-permit";
|
|
5
|
+
if (isGaslessTypedData(typedData, chain)) return "relayer-message";
|
|
6
|
+
if (typedData.primaryType === "PermitSingle") return "permit2-allowance";
|
|
7
|
+
return "relayer-message";
|
|
8
|
+
}
|
|
9
|
+
/** Whether the step carries a Permit2 allowance the SDK signs for a caller's own spender. */
|
|
10
|
+
function hasPermit2Allowance(step, chain) {
|
|
11
|
+
return !!step.typedData?.some((typedData) => getTypedDataLane(typedData, chain) === "permit2-allowance");
|
|
12
|
+
}
|
|
13
|
+
/** The step's typed-data entries that belong to `lane`. */
|
|
14
|
+
function getTypedDataInLane(step, lane, chain) {
|
|
15
|
+
return step.typedData?.filter((typedData) => getTypedDataLane(typedData, chain) === lane) ?? [];
|
|
16
|
+
}
|
|
17
|
+
/** Whether the step still carries typed data a relayer must sign and submit. */
|
|
18
|
+
function hasRelayerMessage(step, chain) {
|
|
19
|
+
return !!step.typedData?.some((typedData) => getTypedDataLane(typedData, chain) === "relayer-message");
|
|
20
|
+
}
|
|
21
|
+
/** Whether the step carries a Permit2 allowance and nothing a relayer must sign. */
|
|
22
|
+
function isPermit2AllowanceLane(step, chain) {
|
|
23
|
+
return hasPermit2Allowance(step, chain) && !hasRelayerMessage(step, chain);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { getTypedDataInLane, getTypedDataLane, hasPermit2Allowance, hasRelayerMessage, isPermit2AllowanceLane };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=getTypedDataLane.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTypedDataLane.js","names":[],"sources":["../../../src/utils/getTypedDataLane.ts"],"sourcesContent":["import type {\n ExtendedChain,\n LiFiStep,\n LiFiStepExtended,\n TypedData,\n} from '@lifi/sdk'\nimport { isGaslessTypedData } from './isGaslessStep.js'\n\n/** Which execution lane one `step.typedData` entry belongs to. */\nexport type TypedDataLane =\n | 'native-permit'\n | 'permit2-allowance'\n | 'relayer-message'\n\n// `chain` is required, and nothing else enforces it: `chain?` compiles and\n// every test still passes, but a relayer message then classifies as\n// `permit2-allowance` and gets signed inline. Do NOT relax it.\nexport function getTypedDataLane(\n typedData: TypedData,\n chain: ExtendedChain\n): TypedDataLane {\n // A native `Permit` is classified BEFORE the gasless rule: LI.FI's relayer\n // signs a permit whose spender is `chain.permit2`, and calling that a relayer\n // message makes a gasless step ask the user to fund an approval.\n if (typedData.primaryType === 'Permit') {\n return 'native-permit'\n }\n if (isGaslessTypedData(typedData, chain)) {\n return 'relayer-message'\n }\n if (typedData.primaryType === 'PermitSingle') {\n return 'permit2-allowance'\n }\n return 'relayer-message'\n}\n\n/** Whether the step carries a Permit2 allowance the SDK signs for a caller's own spender. */\nexport function hasPermit2Allowance(\n step: LiFiStepExtended | LiFiStep,\n chain: ExtendedChain\n): boolean {\n return !!step.typedData?.some(\n (typedData) => getTypedDataLane(typedData, chain) === 'permit2-allowance'\n )\n}\n\n/** The step's typed-data entries that belong to `lane`. */\nexport function getTypedDataInLane(\n step: LiFiStepExtended | LiFiStep,\n lane: TypedDataLane,\n chain: ExtendedChain\n): TypedData[] {\n return (\n step.typedData?.filter(\n (typedData) => getTypedDataLane(typedData, chain) === lane\n ) ?? []\n )\n}\n\n/** Whether the step still carries typed data a relayer must sign and submit. */\nexport function hasRelayerMessage(\n step: LiFiStepExtended | LiFiStep,\n chain: ExtendedChain\n): boolean {\n return !!step.typedData?.some(\n (typedData) => getTypedDataLane(typedData, chain) === 'relayer-message'\n )\n}\n\n/** Whether the step carries a Permit2 allowance and nothing a relayer must sign. */\nexport function isPermit2AllowanceLane(\n step: LiFiStepExtended | LiFiStep,\n chain: ExtendedChain\n): boolean {\n return hasPermit2Allowance(step, chain) && !hasRelayerMessage(step, chain)\n}\n"],"mappings":";;AAiBA,SAAgB,iBACd,WACA,OACe;CAIf,IAAI,UAAU,gBAAgB,UAC5B,OAAO;CAET,IAAI,mBAAmB,WAAW,KAAK,GACrC,OAAO;CAET,IAAI,UAAU,gBAAgB,gBAC5B,OAAO;CAET,OAAO;AACT;;AAGA,SAAgB,oBACd,MACA,OACS;CACT,OAAO,CAAC,CAAC,KAAK,WAAW,MACtB,cAAc,iBAAiB,WAAW,KAAK,MAAM,mBACxD;AACF;;AAGA,SAAgB,mBACd,MACA,MACA,OACa;CACb,OACE,KAAK,WAAW,QACb,cAAc,iBAAiB,WAAW,KAAK,MAAM,IACxD,KAAK,CAAC;AAEV;;AAGA,SAAgB,kBACd,MACA,OACS;CACT,OAAO,CAAC,CAAC,KAAK,WAAW,MACtB,cAAc,iBAAiB,WAAW,KAAK,MAAM,iBACxD;AACF;;AAGA,SAAgB,uBACd,MACA,OACS;CACT,OAAO,oBAAoB,MAAM,KAAK,KAAK,CAAC,kBAAkB,MAAM,KAAK;AAC3E"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { RelayerStep } from "../types.js";
|
|
2
|
-
import { ExtendedChain, LiFiStep, LiFiStepExtended } from "@lifi/sdk";
|
|
2
|
+
import { ExtendedChain, LiFiStep, LiFiStepExtended, TypedData } from "@lifi/sdk";
|
|
3
3
|
//#region src/utils/isGaslessStep.d.ts
|
|
4
|
+
/** Whether one typed-data entry is one a relayer must sign and submit. */
|
|
5
|
+
export declare function isGaslessTypedData(typedData: TypedData, chain?: ExtendedChain): boolean;
|
|
4
6
|
export declare function isGaslessStep(step: LiFiStepExtended | LiFiStep, chain?: ExtendedChain): step is RelayerStep;
|
|
5
7
|
//#endregion
|
|
6
8
|
//# sourceMappingURL=isGaslessStep.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isGaslessStep.d.ts","names":[],"sources":["../../../src/utils/isGaslessStep.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"isGaslessStep.d.ts","names":[],"sources":["../../../src/utils/isGaslessStep.ts"],"mappings":";;;;wBASgB,mBACd,WAAW,WACX,QAAQ;wBAWM,cACd,MAAM,mBAAmB,UACzB,QAAQ,gBACP,QAAQ"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
//#region src/utils/isGaslessStep.ts
|
|
2
|
+
/** Whether one typed-data entry is one a relayer must sign and submit. */
|
|
3
|
+
function isGaslessTypedData(typedData, chain) {
|
|
4
|
+
const spender = typedData.message?.spender;
|
|
5
|
+
return typedData.primaryType === "PermitWitnessTransferFrom" || !!chain?.permit2 && typeof spender === "string" && spender.toLowerCase() === chain.permit2.toLowerCase();
|
|
6
|
+
}
|
|
2
7
|
function isGaslessStep(step, chain) {
|
|
3
|
-
return !!step.typedData?.some((
|
|
8
|
+
return !!step.typedData?.some((typedData) => isGaslessTypedData(typedData, chain));
|
|
4
9
|
}
|
|
5
10
|
//#endregion
|
|
6
|
-
export { isGaslessStep };
|
|
11
|
+
export { isGaslessStep, isGaslessTypedData };
|
|
7
12
|
|
|
8
13
|
//# sourceMappingURL=isGaslessStep.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isGaslessStep.js","names":[],"sources":["../../../src/utils/isGaslessStep.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"isGaslessStep.js","names":[],"sources":["../../../src/utils/isGaslessStep.ts"],"sourcesContent":["import type {\n ExtendedChain,\n LiFiStep,\n LiFiStepExtended,\n TypedData,\n} from '@lifi/sdk'\nimport type { RelayerStep } from '../types.js'\n\n/** Whether one typed-data entry is one a relayer must sign and submit. */\nexport function isGaslessTypedData(\n typedData: TypedData,\n chain?: ExtendedChain\n): boolean {\n const spender = typedData.message?.spender\n return (\n typedData.primaryType === 'PermitWitnessTransferFrom' ||\n (!!chain?.permit2 &&\n typeof spender === 'string' &&\n spender.toLowerCase() === chain.permit2.toLowerCase())\n )\n}\n\nexport function isGaslessStep(\n step: LiFiStepExtended | LiFiStep,\n chain?: ExtendedChain\n): step is RelayerStep {\n return !!step.typedData?.some((typedData) =>\n isGaslessTypedData(typedData, chain)\n )\n}\n"],"mappings":";;AASA,SAAgB,mBACd,WACA,OACS;CACT,MAAM,UAAU,UAAU,SAAS;CACnC,OACE,UAAU,gBAAgB,+BACzB,CAAC,CAAC,OAAO,WACR,OAAO,YAAY,YACnB,QAAQ,YAAY,MAAM,MAAM,QAAQ,YAAY;AAE1D;AAEA,SAAgB,cACd,MACA,OACqB;CACrB,OAAO,CAAC,CAAC,KAAK,WAAW,MAAM,cAC7B,mBAAmB,WAAW,KAAK,CACrC;AACF"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.1
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.2.1'\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.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "LI.FI Ethereum SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "4.
|
|
32
|
-
"viem": "^2.56.
|
|
31
|
+
"@lifi/sdk": "4.8.1",
|
|
32
|
+
"viem": "^2.56.8"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
@@ -24,6 +24,7 @@ import { EthereumCheckAllowanceTask } from './tasks/EthereumCheckAllowanceTask.j
|
|
|
24
24
|
import { EthereumCheckBalanceTask } from './tasks/EthereumCheckBalanceTask.js'
|
|
25
25
|
import { EthereumCheckPermitsTask } from './tasks/EthereumCheckPermitsTask.js'
|
|
26
26
|
import { EthereumNativePermitTask } from './tasks/EthereumNativePermitTask.js'
|
|
27
|
+
import { EthereumPermit2AllowanceTask } from './tasks/EthereumPermit2AllowanceTask.js'
|
|
27
28
|
import { EthereumPrepareTransactionTask } from './tasks/EthereumPrepareTransactionTask.js'
|
|
28
29
|
import { EthereumResetAllowanceTask } from './tasks/EthereumResetAllowanceTask.js'
|
|
29
30
|
import { EthereumSetAllowanceTask } from './tasks/EthereumSetAllowanceTask.js'
|
|
@@ -143,6 +144,7 @@ export class EthereumStepExecutor extends BaseStepExecutor {
|
|
|
143
144
|
new EthereumResetAllowanceTask(),
|
|
144
145
|
new EthereumSetAllowanceTask(),
|
|
145
146
|
new EthereumCheckBalanceTask(),
|
|
147
|
+
new EthereumPermit2AllowanceTask(),
|
|
146
148
|
new EthereumPrepareTransactionTask(),
|
|
147
149
|
new EthereumSignAndExecuteTask(),
|
|
148
150
|
new EthereumWaitForTransactionTask(),
|
|
@@ -3,13 +3,13 @@ import type { Address } from 'viem'
|
|
|
3
3
|
import { getAccountCode } from '../../actions/getAccountCode.js'
|
|
4
4
|
import { isSmartContractWalletCode } from '../../actions/isSmartContractWallet.js'
|
|
5
5
|
import type { EthereumStepExecutorContext } from '../../types.js'
|
|
6
|
-
import {
|
|
6
|
+
import { isPermit2AllowanceLane } from '../../utils/getTypedDataLane.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Skips the outer-tx gas check for steps where the wallet doesn't fund it:
|
|
10
10
|
* smart-contract wallets (Safe Apps, 4337, 7579, …) where the
|
|
11
|
-
* executor / bundler / paymaster pays, and
|
|
12
|
-
* and non-included native fees are still verified.
|
|
11
|
+
* executor / bundler / paymaster pays, and typed-data steps the user does not
|
|
12
|
+
* fund. Source amount and non-included native fees are still verified.
|
|
13
13
|
*
|
|
14
14
|
* Skip-bias is intentional: a wrong skip is caught by the wallet rejecting
|
|
15
15
|
* the tx; a wrong enforce blocks a tx that would have succeeded.
|
|
@@ -18,11 +18,10 @@ export class EthereumCheckBalanceTask extends CheckBalanceTask {
|
|
|
18
18
|
protected override async getCheckBalanceOptions(
|
|
19
19
|
context: EthereumStepExecutorContext
|
|
20
20
|
): Promise<CheckBalanceOptions> {
|
|
21
|
-
const { client, step } = context
|
|
21
|
+
const { client, step, fromChain } = context
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (isRelayerStep(step)) {
|
|
23
|
+
const userFundsTransaction = isPermit2AllowanceLane(step, fromChain)
|
|
24
|
+
if (step.typedData?.length && !userFundsTransaction) {
|
|
26
25
|
return { walletPaysGas: false }
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -1,35 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseStepExecutionTask,
|
|
3
|
-
type SignedTypedData,
|
|
4
|
-
type TaskResult,
|
|
5
|
-
} from '@lifi/sdk'
|
|
6
|
-
import { signTypedData } from 'viem/actions'
|
|
7
|
-
import { getAction } from 'viem/utils'
|
|
1
|
+
import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'
|
|
8
2
|
import type { EthereumStepExecutorContext } from '../../types.js'
|
|
9
3
|
import { getDomainChainId } from '../../utils/getDomainChainId.js'
|
|
10
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getTypedDataInLane,
|
|
6
|
+
getTypedDataLane,
|
|
7
|
+
isPermit2AllowanceLane,
|
|
8
|
+
} from '../../utils/getTypedDataLane.js'
|
|
9
|
+
import { signTypedDataEntries } from './helpers/signTypedDataEntries.js'
|
|
11
10
|
|
|
12
11
|
export class EthereumCheckPermitsTask extends BaseStepExecutionTask {
|
|
13
12
|
override async shouldRun(
|
|
14
13
|
context: EthereumStepExecutorContext
|
|
15
14
|
): Promise<boolean> {
|
|
16
|
-
const { step, disableMessageSigning } = context
|
|
15
|
+
const { step, fromChain, disableMessageSigning } = context
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
(
|
|
17
|
+
return (
|
|
18
|
+
!!step.typedData?.some(
|
|
19
|
+
(typedData) =>
|
|
20
|
+
getTypedDataLane(typedData, fromChain) === 'native-permit'
|
|
21
|
+
) && !disableMessageSigning
|
|
20
22
|
)
|
|
21
|
-
|
|
22
|
-
return !!permitTypedData?.length && !disableMessageSigning
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async run(context: EthereumStepExecutorContext): Promise<TaskResult> {
|
|
26
|
-
const {
|
|
27
|
-
step,
|
|
28
|
-
statusManager,
|
|
29
|
-
allowUserInteraction,
|
|
30
|
-
checkClient,
|
|
31
|
-
signedTypedData: currentSignedTypedData,
|
|
32
|
-
} = context
|
|
26
|
+
const { step, fromChain, statusManager } = context
|
|
33
27
|
|
|
34
28
|
const action = statusManager.initializeAction({
|
|
35
29
|
step,
|
|
@@ -38,59 +32,33 @@ export class EthereumCheckPermitsTask extends BaseStepExecutionTask {
|
|
|
38
32
|
status: 'STARTED',
|
|
39
33
|
})
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
const permitTypedData =
|
|
43
|
-
step.typedData?.filter(
|
|
44
|
-
(typedData) => typedData.primaryType === 'Permit'
|
|
45
|
-
) ?? []
|
|
46
|
-
|
|
47
|
-
const signedTypedData = [...currentSignedTypedData]
|
|
48
|
-
for (const typedData of permitTypedData) {
|
|
49
|
-
statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')
|
|
35
|
+
const permitTypedData = getTypedDataInLane(step, 'native-permit', fromChain)
|
|
50
36
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// Switch to the permit's chain if needed
|
|
59
|
-
const permitClient = await checkClient(step, typedDataChainId)
|
|
60
|
-
if (!permitClient) {
|
|
61
|
-
return { status: 'PAUSED' }
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const signature = await getAction(
|
|
65
|
-
permitClient,
|
|
66
|
-
signTypedData,
|
|
67
|
-
'signTypedData'
|
|
68
|
-
)({
|
|
69
|
-
account: permitClient.account!,
|
|
70
|
-
domain: typedData.domain,
|
|
71
|
-
types: typedData.types,
|
|
72
|
-
primaryType: typedData.primaryType,
|
|
73
|
-
message: typedData.message,
|
|
74
|
-
})
|
|
75
|
-
assertValidSignature(signature)
|
|
76
|
-
const signedPermit: SignedTypedData = {
|
|
77
|
-
...typedData,
|
|
78
|
-
signature,
|
|
79
|
-
}
|
|
80
|
-
signedTypedData.push(signedPermit)
|
|
37
|
+
const result = await signTypedDataEntries(
|
|
38
|
+
context,
|
|
39
|
+
permitTypedData,
|
|
40
|
+
action.type
|
|
41
|
+
)
|
|
42
|
+
if (result.status === 'PAUSED') {
|
|
43
|
+
return { status: 'PAUSED' }
|
|
81
44
|
}
|
|
45
|
+
const { signedTypedData } = result
|
|
82
46
|
|
|
83
|
-
// Check if there's a signed permit for the source transaction chain
|
|
84
47
|
const matchingPermit = signedTypedData.find(
|
|
85
|
-
(
|
|
86
|
-
|
|
48
|
+
(entry) =>
|
|
49
|
+
entry.primaryType === 'Permit' &&
|
|
50
|
+
getDomainChainId(entry.domain) === step.action.fromChainId
|
|
87
51
|
)
|
|
88
52
|
|
|
89
53
|
statusManager.updateAction(step, action.type, 'DONE')
|
|
90
54
|
|
|
91
55
|
return {
|
|
92
56
|
status: 'COMPLETED',
|
|
93
|
-
context: {
|
|
57
|
+
context: {
|
|
58
|
+
signedTypedData,
|
|
59
|
+
hasMatchingPermit:
|
|
60
|
+
!!matchingPermit && !isPermit2AllowanceLane(step, fromChain),
|
|
61
|
+
},
|
|
94
62
|
}
|
|
95
63
|
}
|
|
96
64
|
}
|
|
@@ -10,6 +10,7 @@ import { getNativePermit } from '../../permits/getNativePermit.js'
|
|
|
10
10
|
import { isNativePermitValid } from '../../permits/isNativePermitValid.js'
|
|
11
11
|
import type { EthereumStepExecutorContext } from '../../types.js'
|
|
12
12
|
import { getActionWithFallback } from '../../utils/getActionWithFallback.js'
|
|
13
|
+
import { isPermit2AllowanceLane } from '../../utils/getTypedDataLane.js'
|
|
13
14
|
import { isValidSignature } from '../../utils/isValidSignature.js'
|
|
14
15
|
import { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'
|
|
15
16
|
|
|
@@ -29,6 +30,10 @@ export class EthereumNativePermitTask extends BaseStepExecutionTask {
|
|
|
29
30
|
return false
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
if (isPermit2AllowanceLane(step, fromChain)) {
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
const executionStrategy = await getEthereumExecutionStrategy(context)
|
|
33
38
|
const batchingSupported = executionStrategy === 'batched'
|
|
34
39
|
// Check if proxy contract is available and message signing is not disabled, also not available for atomic batch
|