@lifi/sdk-provider-ethereum 4.1.0 → 4.2.0
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 +25 -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,37 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_getDomainChainId = require("../../../utils/getDomainChainId.js");
|
|
3
|
+
const require_utils_isValidSignature = require("../../../utils/isValidSignature.js");
|
|
4
|
+
let viem_actions = require("viem/actions");
|
|
5
|
+
let viem_utils = require("viem/utils");
|
|
6
|
+
//#region src/core/tasks/helpers/signTypedDataEntries.ts
|
|
7
|
+
/** Signs the entries in order, switching chains per entry, and appends the signatures. */
|
|
8
|
+
async function signTypedDataEntries(context, entries, actionType, actionStatus = "ACTION_REQUIRED") {
|
|
9
|
+
const { step, statusManager, allowUserInteraction, checkClient, signedTypedData: currentSignedTypedData } = context;
|
|
10
|
+
const signedTypedData = [...currentSignedTypedData];
|
|
11
|
+
if (entries.length) statusManager.updateAction(step, actionType, actionStatus);
|
|
12
|
+
for (const typedData of entries) {
|
|
13
|
+
if (!allowUserInteraction) return { status: "PAUSED" };
|
|
14
|
+
const client = await checkClient(step, require_utils_getDomainChainId.getDomainChainId(typedData.domain) || step.action.fromChainId);
|
|
15
|
+
if (!client) return { status: "PAUSED" };
|
|
16
|
+
const signature = await (0, viem_utils.getAction)(client, viem_actions.signTypedData, "signTypedData")({
|
|
17
|
+
account: client.account,
|
|
18
|
+
domain: typedData.domain,
|
|
19
|
+
types: typedData.types,
|
|
20
|
+
primaryType: typedData.primaryType,
|
|
21
|
+
message: typedData.message
|
|
22
|
+
});
|
|
23
|
+
require_utils_isValidSignature.assertValidSignature(signature);
|
|
24
|
+
signedTypedData.push({
|
|
25
|
+
...typedData,
|
|
26
|
+
signature
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
status: "COMPLETED",
|
|
31
|
+
signedTypedData
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.signTypedDataEntries = signTypedDataEntries;
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=signTypedDataEntries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signTypedDataEntries.js","names":["getDomainChainId","getAction","signTypedData"],"sources":["../../../../../src/core/tasks/helpers/signTypedDataEntries.ts"],"sourcesContent":["import type {\n ExecutionActionStatus,\n ExecutionActionType,\n SignedTypedData,\n TypedData,\n} from '@lifi/sdk'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport type { EthereumStepExecutorContext } from '../../../types.js'\nimport { getDomainChainId } from '../../../utils/getDomainChainId.js'\nimport { assertValidSignature } from '../../../utils/isValidSignature.js'\n\nexport type SignTypedDataEntriesResult =\n | { status: 'PAUSED' }\n | { status: 'COMPLETED'; signedTypedData: SignedTypedData[] }\n\n/** 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/BA,+BAAAA,iBAAiB,UAAU,MAAM,KAAK,KAAK,OAAO,WAEG;EACvD,IAAI,CAAC,QACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,MAAM,YAAY,OAAA,GAAMC,WAAAA,UAAAA,CACtB,QACAC,aAAAA,eACA,eACF,CAAC,CAAC;GACA,SAAS,OAAO;GAChB,QAAQ,UAAU;GAClB,OAAO,UAAU;GACjB,aAAa,UAAU;GACvB,SAAS,UAAU;EACrB,CAAC;EACD,+BAAA,qBAAqB,SAAS;EAE9B,gBAAgB,KAAK;GAAE,GAAG;GAAW;EAAU,CAAC;CAClD;CAEA,OAAO;EAAE,QAAQ;EAAa;CAAgB;AAChD"}
|
package/dist/cjs/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/cjs/index.js
CHANGED
|
@@ -2,12 +2,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_utils_isZeroAddress = require("./utils/isZeroAddress.js");
|
|
3
3
|
const require_actions_getAllowance = require("./actions/getAllowance.js");
|
|
4
4
|
const require_actions_isBatchingSupported = require("./actions/isBatchingSupported.js");
|
|
5
|
-
const
|
|
5
|
+
const require_utils_isGaslessStep = require("./utils/isGaslessStep.js");
|
|
6
6
|
const require_permits_isDelegationDesignatorCode = require("./permits/isDelegationDesignatorCode.js");
|
|
7
7
|
const require_permits_constants = require("./permits/constants.js");
|
|
8
8
|
const require_permits_getNativePermit = require("./permits/getNativePermit.js");
|
|
9
9
|
const require_utils_isContractCallStep = require("./utils/isContractCallStep.js");
|
|
10
|
-
const require_utils_isGaslessStep = require("./utils/isGaslessStep.js");
|
|
11
10
|
const require_types = require("./types.js");
|
|
12
11
|
const require_actions_setAllowance = require("./actions/setAllowance.js");
|
|
13
12
|
const require_hyperliquid_isHyperliquidAgentStep = require("./hyperliquid/isHyperliquidAgentStep.js");
|
|
@@ -30,7 +29,6 @@ exports.isExtendedChain = require_utils_isExtendedChain.isExtendedChain;
|
|
|
30
29
|
exports.isGaslessStep = require_utils_isGaslessStep.isGaslessStep;
|
|
31
30
|
exports.isHyperliquidAgentStep = require_hyperliquid_isHyperliquidAgentStep.isHyperliquidAgentStep;
|
|
32
31
|
exports.isHyperliquidOrderMessage = require_hyperliquid_isHyperliquidAgentStep.isHyperliquidOrderMessage;
|
|
33
|
-
exports.isRelayerStep = require_utils_isRelayerStep.isRelayerStep;
|
|
34
32
|
exports.isZeroAddress = require_utils_isZeroAddress.isZeroAddress;
|
|
35
33
|
exports.revokeTokenApproval = require_actions_setAllowance.revokeTokenApproval;
|
|
36
34
|
exports.setAllowance = require_actions_setAllowance.setAllowance;
|
|
@@ -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,33 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_isGaslessStep = require("./isGaslessStep.js");
|
|
3
|
+
//#region src/utils/getTypedDataLane.ts
|
|
4
|
+
function getTypedDataLane(typedData, chain) {
|
|
5
|
+
if (typedData.primaryType === "Permit") return "native-permit";
|
|
6
|
+
if (require_utils_isGaslessStep.isGaslessTypedData(typedData, chain)) return "relayer-message";
|
|
7
|
+
if (typedData.primaryType === "PermitSingle") return "permit2-allowance";
|
|
8
|
+
return "relayer-message";
|
|
9
|
+
}
|
|
10
|
+
/** Whether the step carries a Permit2 allowance the SDK signs for a caller's own spender. */
|
|
11
|
+
function hasPermit2Allowance(step, chain) {
|
|
12
|
+
return !!step.typedData?.some((typedData) => getTypedDataLane(typedData, chain) === "permit2-allowance");
|
|
13
|
+
}
|
|
14
|
+
/** The step's typed-data entries that belong to `lane`. */
|
|
15
|
+
function getTypedDataInLane(step, lane, chain) {
|
|
16
|
+
return step.typedData?.filter((typedData) => getTypedDataLane(typedData, chain) === lane) ?? [];
|
|
17
|
+
}
|
|
18
|
+
/** Whether the step still carries typed data a relayer must sign and submit. */
|
|
19
|
+
function hasRelayerMessage(step, chain) {
|
|
20
|
+
return !!step.typedData?.some((typedData) => getTypedDataLane(typedData, chain) === "relayer-message");
|
|
21
|
+
}
|
|
22
|
+
/** Whether the step carries a Permit2 allowance and nothing a relayer must sign. */
|
|
23
|
+
function isPermit2AllowanceLane(step, chain) {
|
|
24
|
+
return hasPermit2Allowance(step, chain) && !hasRelayerMessage(step, chain);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.getTypedDataInLane = getTypedDataInLane;
|
|
28
|
+
exports.getTypedDataLane = getTypedDataLane;
|
|
29
|
+
exports.hasPermit2Allowance = hasPermit2Allowance;
|
|
30
|
+
exports.hasRelayerMessage = hasRelayerMessage;
|
|
31
|
+
exports.isPermit2AllowanceLane = isPermit2AllowanceLane;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=getTypedDataLane.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTypedDataLane.js","names":["isGaslessTypedData"],"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,IAAIA,4BAAAA,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,9 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/utils/isGaslessStep.ts
|
|
3
|
+
/** Whether one typed-data entry is one a relayer must sign and submit. */
|
|
4
|
+
function isGaslessTypedData(typedData, chain) {
|
|
5
|
+
const spender = typedData.message?.spender;
|
|
6
|
+
return typedData.primaryType === "PermitWitnessTransferFrom" || !!chain?.permit2 && typeof spender === "string" && spender.toLowerCase() === chain.permit2.toLowerCase();
|
|
7
|
+
}
|
|
3
8
|
function isGaslessStep(step, chain) {
|
|
4
|
-
return !!step.typedData?.some((
|
|
9
|
+
return !!step.typedData?.some((typedData) => isGaslessTypedData(typedData, chain));
|
|
5
10
|
}
|
|
6
11
|
//#endregion
|
|
7
12
|
exports.isGaslessStep = isGaslessStep;
|
|
13
|
+
exports.isGaslessTypedData = isGaslessTypedData;
|
|
8
14
|
|
|
9
15
|
//# 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/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/version.ts
|
|
3
3
|
const name = "@lifi/sdk-provider-ethereum";
|
|
4
|
-
const version = "4.
|
|
4
|
+
const version = "4.2.0";
|
|
5
5
|
//#endregion
|
|
6
6
|
exports.name = name;
|
|
7
7
|
exports.version = version;
|
package/dist/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-ethereum'\nexport const version = '4.2.0'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumStepExecutor.d.ts","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"EthereumStepExecutor.d.ts","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"mappings":";;;;UAoCU,oCAAoC;EAC5C,QAAQ;EACR,eAAe,oBAAoB,QAAQ;EAC3C;;qBAGW,6BAA6B;UAChC;UACA;UACA;UACA;EAER,YAAY,SAAS;UAOb;WAOC,cACP,OAAO,OACP,OAAO,kBACP,SAAS,iBACT,cAAc,2BACb,QAAQ,WAAW;EAItB,cACE,MAAM,kBACN,2BACC,QAAQ;WAgCF,gBACP,aAAa,4BACZ,QAAQ;WA0BF,iBACP,SAAS,gCACR"}
|
|
@@ -4,6 +4,7 @@ import { EthereumCheckAllowanceTask } from "./tasks/EthereumCheckAllowanceTask.j
|
|
|
4
4
|
import { EthereumCheckBalanceTask } from "./tasks/EthereumCheckBalanceTask.js";
|
|
5
5
|
import { EthereumCheckPermitsTask } from "./tasks/EthereumCheckPermitsTask.js";
|
|
6
6
|
import { EthereumNativePermitTask } from "./tasks/EthereumNativePermitTask.js";
|
|
7
|
+
import { EthereumPermit2AllowanceTask } from "./tasks/EthereumPermit2AllowanceTask.js";
|
|
7
8
|
import { EthereumPrepareTransactionTask } from "./tasks/EthereumPrepareTransactionTask.js";
|
|
8
9
|
import { EthereumResetAllowanceTask } from "./tasks/EthereumResetAllowanceTask.js";
|
|
9
10
|
import { EthereumSetAllowanceTask } from "./tasks/EthereumSetAllowanceTask.js";
|
|
@@ -64,6 +65,7 @@ var EthereumStepExecutor = class extends BaseStepExecutor {
|
|
|
64
65
|
new EthereumResetAllowanceTask(),
|
|
65
66
|
new EthereumSetAllowanceTask(),
|
|
66
67
|
new EthereumCheckBalanceTask(),
|
|
68
|
+
new EthereumPermit2AllowanceTask(),
|
|
67
69
|
new EthereumPrepareTransactionTask(),
|
|
68
70
|
new EthereumSignAndExecuteTask(),
|
|
69
71
|
new EthereumWaitForTransactionTask(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumStepExecutor.js","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n createDefaultStorage,\n type ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKClient,\n type SDKError,\n type SDKStorage,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Client, GetAddressesReturnType } from 'viem'\nimport { getAddresses } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { parseEthereumErrors } from '../errors/parseEthereumErrors.js'\nimport type { EthereumStepExecutorContext } from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { EthereumCheckAllowanceTask } from './tasks/EthereumCheckAllowanceTask.js'\nimport { EthereumCheckBalanceTask } from './tasks/EthereumCheckBalanceTask.js'\nimport { EthereumCheckPermitsTask } from './tasks/EthereumCheckPermitsTask.js'\nimport { EthereumNativePermitTask } from './tasks/EthereumNativePermitTask.js'\nimport { EthereumPrepareTransactionTask } from './tasks/EthereumPrepareTransactionTask.js'\nimport { EthereumResetAllowanceTask } from './tasks/EthereumResetAllowanceTask.js'\nimport { EthereumSetAllowanceTask } from './tasks/EthereumSetAllowanceTask.js'\nimport { EthereumSignAndExecuteTask } from './tasks/EthereumSignAndExecuteTask.js'\nimport { EthereumWaitForTransactionStatusTask } from './tasks/EthereumWaitForTransactionStatusTask.js'\nimport { EthereumWaitForTransactionTask } from './tasks/EthereumWaitForTransactionTask.js'\nimport { shouldCheckForAllowance } from './tasks/helpers/shouldCheckForAllowance.js'\nimport { switchChain } from './tasks/helpers/switchChain.js'\n\ninterface EthereumStepExecutorOptions extends StepExecutorOptions {\n client: Client\n switchChain?: (chainId: number) => Promise<Client | undefined>\n disableMessageSigning?: boolean\n}\n\nexport class EthereumStepExecutor extends BaseStepExecutor {\n private client: Client\n private switchChain?: (chainId: number) => Promise<Client | undefined>\n private storage?: SDKStorage\n private disableMessageSigning?: boolean\n\n constructor(options: EthereumStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.switchChain = options.switchChain\n this.disableMessageSigning = options.disableMessageSigning\n }\n\n private getStorage = (client: SDKClient): SDKStorage => {\n if (!this.storage) {\n this.storage = client.config.storage ?? createDefaultStorage()\n }\n return this.storage\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n ): Promise<SDKError | ExecuteStepRetryError> =>\n parseEthereumErrors(error, step, action, retryParams)\n\n // Ensure that we are using the right chain and wallet when executing transactions.\n checkClient = async (\n step: LiFiStepExtended,\n targetChainId?: number\n ): Promise<Client | undefined> => {\n const updatedClient = await switchChain(\n this.client,\n targetChainId ?? step.action.fromChainId,\n this.allowUserInteraction,\n this.switchChain\n )\n if (updatedClient) {\n this.client = updatedClient\n }\n\n // Prevent execution of the quote by wallet different from the one which requested the quote\n let accountAddress = this.client.account?.address\n if (!accountAddress) {\n const accountAddresses = (await getAction(\n this.client,\n getAddresses,\n 'getAddresses'\n )(undefined)) as GetAddressesReturnType\n accountAddress = accountAddresses?.[0]\n }\n if (\n accountAddress?.toLowerCase() !== step.action.fromAddress?.toLowerCase()\n ) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n return updatedClient\n }\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<EthereumStepExecutorContext> => {\n const { step, fromChain } = baseContext\n\n const isFromNativeToken =\n fromChain.nativeToken.address === step.action.fromToken.address &&\n isZeroAddress(step.action.fromToken.address)\n\n // Check if message signing is disabled - useful for smart contract wallets\n // We also disable message signing for custom steps\n const disableMessageSigning =\n !!this.disableMessageSigning || step.type !== 'lifi'\n\n return {\n ...baseContext,\n isFromNativeToken,\n disableMessageSigning,\n ethereumClient: this.client,\n checkClient: this.checkClient,\n getStorage: this.getStorage,\n // Signed typed data for native permits and other messages\n signedTypedData: [],\n // Calls for atomic batch transactions (EIP-5792)\n calls: [],\n }\n }\n\n override createPipeline = (\n context: EthereumStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution, isFromNativeToken } = context\n\n const tasks = [\n new EthereumCheckPermitsTask(),\n new EthereumCheckAllowanceTask(),\n new EthereumNativePermitTask(),\n new EthereumResetAllowanceTask(),\n new EthereumSetAllowanceTask(),\n new EthereumCheckBalanceTask(),\n new EthereumPrepareTransactionTask(),\n new EthereumSignAndExecuteTask(),\n new EthereumWaitForTransactionTask(),\n new EthereumWaitForTransactionStatusTask(),\n ]\n\n const doCheckAllowance = shouldCheckForAllowance(\n step,\n isBridgeExecution,\n isFromNativeToken,\n this.statusManager\n )\n\n let taskName: string\n if (doCheckAllowance) {\n taskName = EthereumCheckPermitsTask.name\n } else {\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n taskName =\n swapOrBridgeAction?.txHash || swapOrBridgeAction?.taskId\n ? swapOrBridgeAction?.status === 'DONE'\n ? EthereumWaitForTransactionStatusTask.name\n : EthereumWaitForTransactionTask.name\n : EthereumCheckBalanceTask.name\n }\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EthereumStepExecutor.js","names":[],"sources":["../../../src/core/EthereumStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n createDefaultStorage,\n type ExecuteStepRetryError,\n type ExecuteStepRetryParams,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKClient,\n type SDKError,\n type SDKStorage,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Client, GetAddressesReturnType } from 'viem'\nimport { getAddresses } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { parseEthereumErrors } from '../errors/parseEthereumErrors.js'\nimport type { EthereumStepExecutorContext } from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { EthereumCheckAllowanceTask } from './tasks/EthereumCheckAllowanceTask.js'\nimport { EthereumCheckBalanceTask } from './tasks/EthereumCheckBalanceTask.js'\nimport { EthereumCheckPermitsTask } from './tasks/EthereumCheckPermitsTask.js'\nimport { EthereumNativePermitTask } from './tasks/EthereumNativePermitTask.js'\nimport { EthereumPermit2AllowanceTask } from './tasks/EthereumPermit2AllowanceTask.js'\nimport { EthereumPrepareTransactionTask } from './tasks/EthereumPrepareTransactionTask.js'\nimport { EthereumResetAllowanceTask } from './tasks/EthereumResetAllowanceTask.js'\nimport { EthereumSetAllowanceTask } from './tasks/EthereumSetAllowanceTask.js'\nimport { EthereumSignAndExecuteTask } from './tasks/EthereumSignAndExecuteTask.js'\nimport { EthereumWaitForTransactionStatusTask } from './tasks/EthereumWaitForTransactionStatusTask.js'\nimport { EthereumWaitForTransactionTask } from './tasks/EthereumWaitForTransactionTask.js'\nimport { shouldCheckForAllowance } from './tasks/helpers/shouldCheckForAllowance.js'\nimport { switchChain } from './tasks/helpers/switchChain.js'\n\ninterface EthereumStepExecutorOptions extends StepExecutorOptions {\n client: Client\n switchChain?: (chainId: number) => Promise<Client | undefined>\n disableMessageSigning?: boolean\n}\n\nexport class EthereumStepExecutor extends BaseStepExecutor {\n private client: Client\n private switchChain?: (chainId: number) => Promise<Client | undefined>\n private storage?: SDKStorage\n private disableMessageSigning?: boolean\n\n constructor(options: EthereumStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.switchChain = options.switchChain\n this.disableMessageSigning = options.disableMessageSigning\n }\n\n private getStorage = (client: SDKClient): SDKStorage => {\n if (!this.storage) {\n this.storage = client.config.storage ?? createDefaultStorage()\n }\n return this.storage\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction,\n retryParams?: ExecuteStepRetryParams\n ): Promise<SDKError | ExecuteStepRetryError> =>\n parseEthereumErrors(error, step, action, retryParams)\n\n // Ensure that we are using the right chain and wallet when executing transactions.\n checkClient = async (\n step: LiFiStepExtended,\n targetChainId?: number\n ): Promise<Client | undefined> => {\n const updatedClient = await switchChain(\n this.client,\n targetChainId ?? step.action.fromChainId,\n this.allowUserInteraction,\n this.switchChain\n )\n if (updatedClient) {\n this.client = updatedClient\n }\n\n // Prevent execution of the quote by wallet different from the one which requested the quote\n let accountAddress = this.client.account?.address\n if (!accountAddress) {\n const accountAddresses = (await getAction(\n this.client,\n getAddresses,\n 'getAddresses'\n )(undefined)) as GetAddressesReturnType\n accountAddress = accountAddresses?.[0]\n }\n if (\n accountAddress?.toLowerCase() !== step.action.fromAddress?.toLowerCase()\n ) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n return updatedClient\n }\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<EthereumStepExecutorContext> => {\n const { step, fromChain } = baseContext\n\n const isFromNativeToken =\n fromChain.nativeToken.address === step.action.fromToken.address &&\n isZeroAddress(step.action.fromToken.address)\n\n // Check if message signing is disabled - useful for smart contract wallets\n // We also disable message signing for custom steps\n const disableMessageSigning =\n !!this.disableMessageSigning || step.type !== 'lifi'\n\n return {\n ...baseContext,\n isFromNativeToken,\n disableMessageSigning,\n ethereumClient: this.client,\n checkClient: this.checkClient,\n getStorage: this.getStorage,\n // Signed typed data for native permits and other messages\n signedTypedData: [],\n // Calls for atomic batch transactions (EIP-5792)\n calls: [],\n }\n }\n\n override createPipeline = (\n context: EthereumStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution, isFromNativeToken } = context\n\n const tasks = [\n new EthereumCheckPermitsTask(),\n new EthereumCheckAllowanceTask(),\n new EthereumNativePermitTask(),\n new EthereumResetAllowanceTask(),\n new EthereumSetAllowanceTask(),\n new EthereumCheckBalanceTask(),\n new EthereumPermit2AllowanceTask(),\n new EthereumPrepareTransactionTask(),\n new EthereumSignAndExecuteTask(),\n new EthereumWaitForTransactionTask(),\n new EthereumWaitForTransactionStatusTask(),\n ]\n\n const doCheckAllowance = shouldCheckForAllowance(\n step,\n isBridgeExecution,\n isFromNativeToken,\n this.statusManager\n )\n\n let taskName: string\n if (doCheckAllowance) {\n taskName = EthereumCheckPermitsTask.name\n } else {\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n taskName =\n swapOrBridgeAction?.txHash || swapOrBridgeAction?.taskId\n ? swapOrBridgeAction?.status === 'DONE'\n ? EthereumWaitForTransactionStatusTask.name\n : EthereumWaitForTransactionTask.name\n : EthereumCheckBalanceTask.name\n }\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0CA,IAAa,uBAAb,cAA0C,iBAAiB;CACzD;CACA;CACA;CACA;CAEA,YAAY,SAAsC;EAChD,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,cAAc,QAAQ;EAC3B,KAAK,wBAAwB,QAAQ;CACvC;CAEA,cAAsB,WAAkC;EACtD,IAAI,CAAC,KAAK,SACR,KAAK,UAAU,OAAO,OAAO,WAAW,qBAAqB;EAE/D,OAAO,KAAK;CACd;CAEA,eACE,OACA,MACA,QACA,gBAEA,oBAAoB,OAAO,MAAM,QAAQ,WAAW;CAGtD,cAAc,OACZ,MACA,kBACgC;EAChC,MAAM,gBAAgB,MAAM,YAC1B,KAAK,QACL,iBAAiB,KAAK,OAAO,aAC7B,KAAK,sBACL,KAAK,WACP;EACA,IAAI,eACF,KAAK,SAAS;EAIhB,IAAI,iBAAiB,KAAK,OAAO,SAAS;EAC1C,IAAI,CAAC,gBAMH,kBAAiB,MALe,UAC9B,KAAK,QACL,cACA,cACF,CAAC,CAAC,KAAA,CAAS,EAAA,GACyB;EAEtC,IACE,gBAAgB,YAAY,MAAM,KAAK,OAAO,aAAa,YAAY,GAEvE,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;EAEF,OAAO;CACT;CAEA,gBAAyB,OACvB,gBACyC;EACzC,MAAM,EAAE,MAAM,cAAc;EAE5B,MAAM,oBACJ,UAAU,YAAY,YAAY,KAAK,OAAO,UAAU,WACxD,cAAc,KAAK,OAAO,UAAU,OAAO;EAI7C,MAAM,wBACJ,CAAC,CAAC,KAAK,yBAAyB,KAAK,SAAS;EAEhD,OAAO;GACL,GAAG;GACH;GACA;GACA,gBAAgB,KAAK;GACrB,aAAa,KAAK;GAClB,YAAY,KAAK;GAEjB,iBAAiB,CAAC;GAElB,OAAO,CAAC;EACV;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,mBAAmB,sBAAsB;EAEvD,MAAM,QAAQ;GACZ,IAAI,yBAAyB;GAC7B,IAAI,2BAA2B;GAC/B,IAAI,yBAAyB;GAC7B,IAAI,2BAA2B;GAC/B,IAAI,yBAAyB;GAC7B,IAAI,yBAAyB;GAC7B,IAAI,6BAA6B;GACjC,IAAI,+BAA+B;GACnC,IAAI,2BAA2B;GAC/B,IAAI,+BAA+B;GACnC,IAAI,qCAAqC;EAC3C;EAEA,MAAM,mBAAmB,wBACvB,MACA,mBACA,mBACA,KAAK,aACP;EAEA,IAAI;EACJ,IAAI,kBACF,WAAW,yBAAyB;OAC/B;GACL,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;GACA,WACE,oBAAoB,UAAU,oBAAoB,SAC9C,oBAAoB,WAAW,SAC7B,qCAAqC,OACrC,+BAA+B,OACjC,yBAAyB;EACjC;EAEA,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,QACtC;EAEA,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
|
|
@@ -4,8 +4,8 @@ import { CheckBalanceOptions, CheckBalanceTask } from "@lifi/sdk";
|
|
|
4
4
|
/**
|
|
5
5
|
* Skips the outer-tx gas check for steps where the wallet doesn't fund it:
|
|
6
6
|
* smart-contract wallets (Safe Apps, 4337, 7579, …) where the
|
|
7
|
-
* executor / bundler / paymaster pays, and
|
|
8
|
-
* and non-included native fees are still verified.
|
|
7
|
+
* executor / bundler / paymaster pays, and typed-data steps the user does not
|
|
8
|
+
* fund. Source amount and non-included native fees are still verified.
|
|
9
9
|
*
|
|
10
10
|
* Skip-bias is intentional: a wrong skip is caught by the wallet rejecting
|
|
11
11
|
* the tx; a wrong enforce blocks a tx that would have succeeded.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPermit2AllowanceLane } from "../../utils/getTypedDataLane.js";
|
|
2
2
|
import { getAccountCode } from "../../actions/getAccountCode.js";
|
|
3
3
|
import { isSmartContractWalletCode } from "../../actions/isSmartContractWallet.js";
|
|
4
4
|
import { CheckBalanceTask } from "@lifi/sdk";
|
|
@@ -6,16 +6,17 @@ import { CheckBalanceTask } from "@lifi/sdk";
|
|
|
6
6
|
/**
|
|
7
7
|
* Skips the outer-tx gas check for steps where the wallet doesn't fund it:
|
|
8
8
|
* smart-contract wallets (Safe Apps, 4337, 7579, …) where the
|
|
9
|
-
* executor / bundler / paymaster pays, and
|
|
10
|
-
* and non-included native fees are still verified.
|
|
9
|
+
* executor / bundler / paymaster pays, and typed-data steps the user does not
|
|
10
|
+
* fund. Source amount and non-included native fees are still verified.
|
|
11
11
|
*
|
|
12
12
|
* Skip-bias is intentional: a wrong skip is caught by the wallet rejecting
|
|
13
13
|
* the tx; a wrong enforce blocks a tx that would have succeeded.
|
|
14
14
|
*/
|
|
15
15
|
var EthereumCheckBalanceTask = class extends CheckBalanceTask {
|
|
16
16
|
async getCheckBalanceOptions(context) {
|
|
17
|
-
const { client, step } = context;
|
|
18
|
-
|
|
17
|
+
const { client, step, fromChain } = context;
|
|
18
|
+
const userFundsTransaction = isPermit2AllowanceLane(step, fromChain);
|
|
19
|
+
if (step.typedData?.length && !userFundsTransaction) return { walletPaysGas: false };
|
|
19
20
|
const fromAddress = step.action.fromAddress;
|
|
20
21
|
if (!fromAddress) return {};
|
|
21
22
|
const code = await getAccountCode({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumCheckBalanceTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumCheckBalanceTask.ts"],"sourcesContent":["import { type CheckBalanceOptions, CheckBalanceTask } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { getAccountCode } from '../../actions/getAccountCode.js'\nimport { isSmartContractWalletCode } from '../../actions/isSmartContractWallet.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport {
|
|
1
|
+
{"version":3,"file":"EthereumCheckBalanceTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumCheckBalanceTask.ts"],"sourcesContent":["import { type CheckBalanceOptions, CheckBalanceTask } from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { getAccountCode } from '../../actions/getAccountCode.js'\nimport { isSmartContractWalletCode } from '../../actions/isSmartContractWallet.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { isPermit2AllowanceLane } from '../../utils/getTypedDataLane.js'\n\n/**\n * Skips the outer-tx gas check for steps where the wallet doesn't fund it:\n * smart-contract wallets (Safe Apps, 4337, 7579, …) where the\n * executor / bundler / paymaster pays, and typed-data steps the user does not\n * fund. Source amount and non-included native fees are still verified.\n *\n * Skip-bias is intentional: a wrong skip is caught by the wallet rejecting\n * the tx; a wrong enforce blocks a tx that would have succeeded.\n */\nexport class EthereumCheckBalanceTask extends CheckBalanceTask {\n protected override async getCheckBalanceOptions(\n context: EthereumStepExecutorContext\n ): Promise<CheckBalanceOptions> {\n const { client, step, fromChain } = context\n\n const userFundsTransaction = isPermit2AllowanceLane(step, fromChain)\n if (step.typedData?.length && !userFundsTransaction) {\n return { walletPaysGas: false }\n }\n\n // Funding wallet (NOT signer) — for Safe Apps these usually match, but\n // the balance question is about the funder. Compare with\n // `canAccountUseNativePermits`, which uses the signer.\n const fromAddress = step.action.fromAddress as Address | undefined\n if (!fromAddress) {\n return {}\n }\n\n // `step.action.fromChainId` (NOT wallet's connected chain) so cross-\n // chain / post-chain-switch flows query the chain that executes the step.\n const code = await getAccountCode({\n client,\n chainId: step.action.fromChainId,\n address: fromAddress,\n })\n\n // `code === undefined` on RPC failure → falls through to \"treat as EOA\"\n // since `isSmartContractWalletCode(undefined)` is `false` (conservative:\n // strict gas check stays on, today's behavior).\n return { walletPaysGas: !isSmartContractWalletCode(code) }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,IAAa,2BAAb,cAA8C,iBAAiB;CAC7D,MAAyB,uBACvB,SAC8B;EAC9B,MAAM,EAAE,QAAQ,MAAM,cAAc;EAEpC,MAAM,uBAAuB,uBAAuB,MAAM,SAAS;EACnE,IAAI,KAAK,WAAW,UAAU,CAAC,sBAC7B,OAAO,EAAE,eAAe,MAAM;EAMhC,MAAM,cAAc,KAAK,OAAO;EAChC,IAAI,CAAC,aACH,OAAO,CAAC;EAKV,MAAM,OAAO,MAAM,eAAe;GAChC;GACA,SAAS,KAAK,OAAO;GACrB,SAAS;EACX,CAAC;EAKD,OAAO,EAAE,eAAe,CAAC,0BAA0B,IAAI,EAAE;CAC3D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumCheckPermitsTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumCheckPermitsTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EthereumCheckPermitsTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumCheckPermitsTask.ts"],"mappings":";;;qBAUa,iCAAiC;WAC7B,UACb,SAAS,8BACR;EAWH,IAAU,SAAS,8BAA8B,QAAQ"}
|
|
@@ -1,50 +1,32 @@
|
|
|
1
|
+
import { getTypedDataInLane, getTypedDataLane, isPermit2AllowanceLane } from "../../utils/getTypedDataLane.js";
|
|
1
2
|
import { getDomainChainId } from "../../utils/getDomainChainId.js";
|
|
2
|
-
import {
|
|
3
|
+
import { signTypedDataEntries } from "./helpers/signTypedDataEntries.js";
|
|
3
4
|
import { BaseStepExecutionTask } from "@lifi/sdk";
|
|
4
|
-
import { signTypedData } from "viem/actions";
|
|
5
|
-
import { getAction } from "viem/utils";
|
|
6
5
|
//#region src/core/tasks/EthereumCheckPermitsTask.ts
|
|
7
6
|
var EthereumCheckPermitsTask = class extends BaseStepExecutionTask {
|
|
8
7
|
async shouldRun(context) {
|
|
9
|
-
const { step, disableMessageSigning } = context;
|
|
10
|
-
return !!
|
|
8
|
+
const { step, fromChain, disableMessageSigning } = context;
|
|
9
|
+
return !!step.typedData?.some((typedData) => getTypedDataLane(typedData, fromChain) === "native-permit") && !disableMessageSigning;
|
|
11
10
|
}
|
|
12
11
|
async run(context) {
|
|
13
|
-
const { step,
|
|
12
|
+
const { step, fromChain, statusManager } = context;
|
|
14
13
|
const action = statusManager.initializeAction({
|
|
15
14
|
step,
|
|
16
15
|
type: "PERMIT",
|
|
17
16
|
chainId: step.action.fromChainId,
|
|
18
17
|
status: "STARTED"
|
|
19
18
|
});
|
|
20
|
-
const permitTypedData = step
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const permitClient = await checkClient(step, getDomainChainId(typedData.domain) || step.action.fromChainId);
|
|
26
|
-
if (!permitClient) return { status: "PAUSED" };
|
|
27
|
-
const signature = await getAction(permitClient, signTypedData, "signTypedData")({
|
|
28
|
-
account: permitClient.account,
|
|
29
|
-
domain: typedData.domain,
|
|
30
|
-
types: typedData.types,
|
|
31
|
-
primaryType: typedData.primaryType,
|
|
32
|
-
message: typedData.message
|
|
33
|
-
});
|
|
34
|
-
assertValidSignature(signature);
|
|
35
|
-
const signedPermit = {
|
|
36
|
-
...typedData,
|
|
37
|
-
signature
|
|
38
|
-
};
|
|
39
|
-
signedTypedData.push(signedPermit);
|
|
40
|
-
}
|
|
41
|
-
const matchingPermit = signedTypedData.find((signedTypedData) => getDomainChainId(signedTypedData.domain) === step.action.fromChainId);
|
|
19
|
+
const permitTypedData = getTypedDataInLane(step, "native-permit", fromChain);
|
|
20
|
+
const result = await signTypedDataEntries(context, permitTypedData, action.type);
|
|
21
|
+
if (result.status === "PAUSED") return { status: "PAUSED" };
|
|
22
|
+
const { signedTypedData } = result;
|
|
23
|
+
const matchingPermit = signedTypedData.find((entry) => entry.primaryType === "Permit" && getDomainChainId(entry.domain) === step.action.fromChainId);
|
|
42
24
|
statusManager.updateAction(step, action.type, "DONE");
|
|
43
25
|
return {
|
|
44
26
|
status: "COMPLETED",
|
|
45
27
|
context: {
|
|
46
28
|
signedTypedData,
|
|
47
|
-
hasMatchingPermit: !!matchingPermit
|
|
29
|
+
hasMatchingPermit: !!matchingPermit && !isPermit2AllowanceLane(step, fromChain)
|
|
48
30
|
}
|
|
49
31
|
};
|
|
50
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumCheckPermitsTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumCheckPermitsTask.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"EthereumCheckPermitsTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumCheckPermitsTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getDomainChainId } from '../../utils/getDomainChainId.js'\nimport {\n getTypedDataInLane,\n getTypedDataLane,\n isPermit2AllowanceLane,\n} from '../../utils/getTypedDataLane.js'\nimport { signTypedDataEntries } from './helpers/signTypedDataEntries.js'\n\nexport class EthereumCheckPermitsTask extends BaseStepExecutionTask {\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n const { step, fromChain, disableMessageSigning } = context\n\n return (\n !!step.typedData?.some(\n (typedData) =>\n getTypedDataLane(typedData, fromChain) === 'native-permit'\n ) && !disableMessageSigning\n )\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const { step, fromChain, statusManager } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'PERMIT',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n const permitTypedData = getTypedDataInLane(step, 'native-permit', fromChain)\n\n const result = await signTypedDataEntries(\n context,\n permitTypedData,\n action.type\n )\n if (result.status === 'PAUSED') {\n return { status: 'PAUSED' }\n }\n const { signedTypedData } = result\n\n const matchingPermit = signedTypedData.find(\n (entry) =>\n entry.primaryType === 'Permit' &&\n getDomainChainId(entry.domain) === step.action.fromChainId\n )\n\n statusManager.updateAction(step, action.type, 'DONE')\n\n return {\n status: 'COMPLETED',\n context: {\n signedTypedData,\n hasMatchingPermit:\n !!matchingPermit && !isPermit2AllowanceLane(step, fromChain),\n },\n }\n }\n}\n"],"mappings":";;;;;AAUA,IAAa,2BAAb,cAA8C,sBAAsB;CAClE,MAAe,UACb,SACkB;EAClB,MAAM,EAAE,MAAM,WAAW,0BAA0B;EAEnD,OACE,CAAC,CAAC,KAAK,WAAW,MACf,cACC,iBAAiB,WAAW,SAAS,MAAM,eAC/C,KAAK,CAAC;CAEV;CAEA,MAAM,IAAI,SAA2D;EACnE,MAAM,EAAE,MAAM,WAAW,kBAAkB;EAE3C,MAAM,SAAS,cAAc,iBAAiB;GAC5C;GACA,MAAM;GACN,SAAS,KAAK,OAAO;GACrB,QAAQ;EACV,CAAC;EAED,MAAM,kBAAkB,mBAAmB,MAAM,iBAAiB,SAAS;EAE3E,MAAM,SAAS,MAAM,qBACnB,SACA,iBACA,OAAO,IACT;EACA,IAAI,OAAO,WAAW,UACpB,OAAO,EAAE,QAAQ,SAAS;EAE5B,MAAM,EAAE,oBAAoB;EAE5B,MAAM,iBAAiB,gBAAgB,MACpC,UACC,MAAM,gBAAgB,YACtB,iBAAiB,MAAM,MAAM,MAAM,KAAK,OAAO,WACnD;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAEpD,OAAO;GACL,QAAQ;GACR,SAAS;IACP;IACA,mBACE,CAAC,CAAC,kBAAkB,CAAC,uBAAuB,MAAM,SAAS;GAC/D;EACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumNativePermitTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumNativePermitTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EthereumNativePermitTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumNativePermitTask.ts"],"mappings":";;;qBAgBa,iCAAiC;WAC7B,UACb,SAAS,8BACR;EA4BH,IAAU,SAAS,8BAA8B,QAAQ"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getActionWithFallback } from "../../utils/getActionWithFallback.js";
|
|
2
|
+
import { isPermit2AllowanceLane } from "../../utils/getTypedDataLane.js";
|
|
2
3
|
import { getEthereumExecutionStrategy } from "./helpers/getEthereumExecutionStrategy.js";
|
|
3
4
|
import { isValidSignature } from "../../utils/isValidSignature.js";
|
|
4
5
|
import { getNativePermit } from "../../permits/getNativePermit.js";
|
|
@@ -11,6 +12,7 @@ var EthereumNativePermitTask = class extends BaseStepExecutionTask {
|
|
|
11
12
|
async shouldRun(context) {
|
|
12
13
|
const { step, fromChain, hasMatchingPermit, hasSufficientAllowance, disableMessageSigning } = context;
|
|
13
14
|
if (hasMatchingPermit || hasSufficientAllowance) return false;
|
|
15
|
+
if (isPermit2AllowanceLane(step, fromChain)) return false;
|
|
14
16
|
const batchingSupported = await getEthereumExecutionStrategy(context) === "batched";
|
|
15
17
|
return !!fromChain.permit2Proxy && !batchingSupported && !disableMessageSigning && !step.estimate.skipPermit;
|
|
16
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumNativePermitTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumNativePermitTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type SignedTypedData,\n type TaskResult,\n} from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getNativePermit } from '../../permits/getNativePermit.js'\nimport { isNativePermitValid } from '../../permits/isNativePermitValid.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getActionWithFallback } from '../../utils/getActionWithFallback.js'\nimport { isValidSignature } from '../../utils/isValidSignature.js'\nimport { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'\n\nexport class EthereumNativePermitTask extends BaseStepExecutionTask {\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n const {\n step,\n fromChain,\n hasMatchingPermit,\n hasSufficientAllowance,\n disableMessageSigning,\n } = context\n\n if (hasMatchingPermit || hasSufficientAllowance) {\n return false\n }\n\n const executionStrategy = await getEthereumExecutionStrategy(context)\n const batchingSupported = executionStrategy === 'batched'\n // Check if proxy contract is available and message signing is not disabled, also not available for atomic batch\n const isNativePermitAvailable =\n !!fromChain.permit2Proxy &&\n !batchingSupported &&\n !disableMessageSigning &&\n !step.estimate.skipPermit\n return isNativePermitAvailable\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n fromChain,\n statusManager,\n allowUserInteraction,\n checkClient,\n signedTypedData: currentSignedTypedData,\n } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'NATIVE_PERMIT',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n const updatedClient = await checkClient(step)\n if (!updatedClient) {\n return { status: 'PAUSED' }\n }\n\n const fromAmount = BigInt(step.action.fromAmount)\n\n const nativePermitData = await getActionWithFallback(\n client,\n updatedClient,\n getNativePermit,\n 'getNativePermit',\n {\n client,\n viemClient: updatedClient,\n chainId: fromChain.id,\n tokenAddress: step.action.fromToken.address as Address,\n spenderAddress: fromChain.permit2Proxy as Address,\n amount: fromAmount,\n 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":"
|
|
1
|
+
{"version":3,"file":"EthereumNativePermitTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumNativePermitTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type SignedTypedData,\n type TaskResult,\n} from '@lifi/sdk'\nimport type { Address } from 'viem'\nimport { signTypedData } from 'viem/actions'\nimport { getAction } from 'viem/utils'\nimport { getNativePermit } from '../../permits/getNativePermit.js'\nimport { isNativePermitValid } from '../../permits/isNativePermitValid.js'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport { getActionWithFallback } from '../../utils/getActionWithFallback.js'\nimport { isPermit2AllowanceLane } from '../../utils/getTypedDataLane.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 if (isPermit2AllowanceLane(step, fromChain)) {\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":";;;;;;;;;;AAgBA,IAAa,2BAAb,cAA8C,sBAAsB;CAClE,MAAe,UACb,SACkB;EAClB,MAAM,EACJ,MACA,WACA,mBACA,wBACA,0BACE;EAEJ,IAAI,qBAAqB,wBACvB,OAAO;EAGT,IAAI,uBAAuB,MAAM,SAAS,GACxC,OAAO;EAIT,MAAM,oBAAoB,MADM,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,MAAM,sBAC7B,QACA,eACA,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,oBACpD,oBAAoB,iBAAiB,gBAAgB,CAG5B,GAAG;GAC5B,cAAc,aAAa,MAAM,OAAO,MAAM,iBAAiB;GAE/D,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;GAI5B,MAAM,YAAY,MAAM,UACtB,eACA,eACA,eACF,CAAC,CAAC;IACA,SAAS,cAAc;IACvB,QAAQ,iBAAiB;IACzB,OAAO,iBAAiB;IACxB,aAAa,iBAAiB;IAC9B,SAAS,iBAAiB;GAC5B,CAAC;GAKD,IAAI,CAAC,iBAAiB,SAAS,GAAG;IAChC,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;IACpD,OAAO,EAAE,QAAQ,YAAY;GAC/B;GAGA,MAAM,eAAgC;IACpC,GAAG;IACH;GACF;GACA,gBAAgB,KAAK,YAAY;EACnC;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAEpD,OAAO;GACL,QAAQ;GACR,SAAS;IAAE;IAAiB,mBAAmB;GAAK;EACtD;CACF;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EthereumStepExecutorContext } from "../../types.js";
|
|
2
|
+
import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
|
|
3
|
+
//#region src/core/tasks/EthereumPermit2AllowanceTask.d.ts
|
|
4
|
+
/** Signs the Permit2 allowances a caller attached to its own step, before prepare. */
|
|
5
|
+
export declare class EthereumPermit2AllowanceTask extends BaseStepExecutionTask {
|
|
6
|
+
override shouldRun(context: EthereumStepExecutorContext): Promise<boolean>;
|
|
7
|
+
run(context: EthereumStepExecutorContext): Promise<TaskResult>;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//# sourceMappingURL=EthereumPermit2AllowanceTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EthereumPermit2AllowanceTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumPermit2AllowanceTask.ts"],"mappings":";;;;qBASa,qCAAqC;WACjC,UACb,SAAS,8BACR;EAMH,IAAU,SAAS,8BAA8B,QAAQ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getTypedDataInLane, isPermit2AllowanceLane } from "../../utils/getTypedDataLane.js";
|
|
2
|
+
import { signTypedDataEntries } from "./helpers/signTypedDataEntries.js";
|
|
3
|
+
import { BaseStepExecutionTask } from "@lifi/sdk";
|
|
4
|
+
//#region src/core/tasks/EthereumPermit2AllowanceTask.ts
|
|
5
|
+
/** Signs the Permit2 allowances a caller attached to its own step, before prepare. */
|
|
6
|
+
var EthereumPermit2AllowanceTask = class extends BaseStepExecutionTask {
|
|
7
|
+
async shouldRun(context) {
|
|
8
|
+
const { step, fromChain, disableMessageSigning } = context;
|
|
9
|
+
return isPermit2AllowanceLane(step, fromChain) && !disableMessageSigning;
|
|
10
|
+
}
|
|
11
|
+
async run(context) {
|
|
12
|
+
const { step, fromChain, statusManager } = context;
|
|
13
|
+
const action = statusManager.initializeAction({
|
|
14
|
+
step,
|
|
15
|
+
type: "PERMIT",
|
|
16
|
+
chainId: step.action.fromChainId,
|
|
17
|
+
status: "STARTED"
|
|
18
|
+
});
|
|
19
|
+
const allowanceTypedData = getTypedDataInLane(step, "permit2-allowance", fromChain);
|
|
20
|
+
const result = await signTypedDataEntries(context, allowanceTypedData, action.type);
|
|
21
|
+
if (result.status === "PAUSED") return { status: "PAUSED" };
|
|
22
|
+
statusManager.updateAction(step, action.type, "DONE");
|
|
23
|
+
return {
|
|
24
|
+
status: "COMPLETED",
|
|
25
|
+
context: { signedTypedData: result.signedTypedData }
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { EthereumPermit2AllowanceTask };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=EthereumPermit2AllowanceTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EthereumPermit2AllowanceTask.js","names":[],"sources":["../../../../src/core/tasks/EthereumPermit2AllowanceTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'\nimport type { EthereumStepExecutorContext } from '../../types.js'\nimport {\n getTypedDataInLane,\n isPermit2AllowanceLane,\n} from '../../utils/getTypedDataLane.js'\nimport { signTypedDataEntries } from './helpers/signTypedDataEntries.js'\n\n/** Signs the Permit2 allowances a caller attached to its own step, before prepare. */\nexport class EthereumPermit2AllowanceTask extends BaseStepExecutionTask {\n override async shouldRun(\n context: EthereumStepExecutorContext\n ): Promise<boolean> {\n const { step, fromChain, disableMessageSigning } = context\n\n return isPermit2AllowanceLane(step, fromChain) && !disableMessageSigning\n }\n\n async run(context: EthereumStepExecutorContext): Promise<TaskResult> {\n const { step, fromChain, statusManager } = context\n\n const action = statusManager.initializeAction({\n step,\n type: 'PERMIT',\n chainId: step.action.fromChainId,\n status: 'STARTED',\n })\n\n const allowanceTypedData = getTypedDataInLane(\n step,\n 'permit2-allowance',\n fromChain\n )\n\n // `ACTION_REQUIRED`, not `MESSAGE_REQUIRED`: the widget maps no `PERMIT`\n // text for it. Pinned by `emits exactly STARTED, ACTION_REQUIRED and DONE`.\n const result = await signTypedDataEntries(\n context,\n allowanceTypedData,\n action.type\n )\n if (result.status === 'PAUSED') {\n return { status: 'PAUSED' }\n }\n\n statusManager.updateAction(step, action.type, 'DONE')\n\n return {\n status: 'COMPLETED',\n context: { signedTypedData: result.signedTypedData },\n }\n }\n}\n"],"mappings":";;;;;AASA,IAAa,+BAAb,cAAkD,sBAAsB;CACtE,MAAe,UACb,SACkB;EAClB,MAAM,EAAE,MAAM,WAAW,0BAA0B;EAEnD,OAAO,uBAAuB,MAAM,SAAS,KAAK,CAAC;CACrD;CAEA,MAAM,IAAI,SAA2D;EACnE,MAAM,EAAE,MAAM,WAAW,kBAAkB;EAE3C,MAAM,SAAS,cAAc,iBAAiB;GAC5C;GACA,MAAM;GACN,SAAS,KAAK,OAAO;GACrB,QAAQ;EACV,CAAC;EAED,MAAM,qBAAqB,mBACzB,MACA,qBACA,SACF;EAIA,MAAM,SAAS,MAAM,qBACnB,SACA,oBACA,OAAO,IACT;EACA,IAAI,OAAO,WAAW,UACpB,OAAO,EAAE,QAAQ,SAAS;EAG5B,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAEpD,OAAO;GACL,QAAQ;GACR,SAAS,EAAE,iBAAiB,OAAO,gBAAgB;EACrD;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumPrepareTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumPrepareTransactionTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EthereumPrepareTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/EthereumPrepareTransactionTask.ts"],"mappings":";;;qBAca,uCAAuC;EAClD,IAAU,SAAS,8BAA8B,QAAQ"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { getEthereumExecutionStrategy } from "./helpers/getEthereumExecutionStrategy.js";
|
|
2
2
|
import { getMaxPriorityFeePerGas } from "../../actions/getMaxPriorityFeePerGas.js";
|
|
3
3
|
import { getUpdatedStep } from "./helpers/getUpdatedStep.js";
|
|
4
|
+
import { preservePermit2Allowances } from "./helpers/preservePermit2Allowances.js";
|
|
4
5
|
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError, stepComparison } from "@lifi/sdk";
|
|
5
6
|
//#region src/core/tasks/EthereumPrepareTransactionTask.ts
|
|
6
7
|
var EthereumPrepareTransactionTask = class extends BaseStepExecutionTask {
|
|
7
8
|
async run(context) {
|
|
8
|
-
const { step, client, executionOptions, statusManager, allowUserInteraction, checkClient, isBridgeExecution, signedTypedData, ethereumClient } = context;
|
|
9
|
+
const { step, client, executionOptions, statusManager, allowUserInteraction, checkClient, isBridgeExecution, signedTypedData, ethereumClient, fromChain } = context;
|
|
9
10
|
if (!statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP")) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
|
|
10
|
-
const updatedStep = await getUpdatedStep(client, step, executionOptions, signedTypedData);
|
|
11
|
+
const updatedStep = await getUpdatedStep(client, step, fromChain, executionOptions, signedTypedData);
|
|
11
12
|
const comparedStep = await stepComparison(statusManager, step, updatedStep, allowUserInteraction, executionOptions);
|
|
13
|
+
const answeredTypedData = updatedStep.typedData ?? step.typedData;
|
|
12
14
|
Object.assign(step, {
|
|
13
15
|
...comparedStep,
|
|
14
16
|
execution: step.execution,
|
|
15
|
-
typedData: updatedStep.typedData
|
|
17
|
+
typedData: preservePermit2Allowances(step, updatedStep.typedData, fromChain)
|
|
16
18
|
});
|
|
17
|
-
if (!step.transactionRequest && !
|
|
19
|
+
if (!step.transactionRequest && !answeredTypedData?.length) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Transaction request is not found.");
|
|
18
20
|
let transactionRequest;
|
|
19
21
|
if (step.transactionRequest) {
|
|
20
22
|
let maxPriorityFeePerGas;
|