@lifi/sdk-provider-ethereum 4.0.7 → 4.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/EthereumProvider.js +2 -1
- package/dist/cjs/EthereumProvider.js.map +1 -1
- package/dist/cjs/actions/checkPermitSupport.d.ts +3 -2
- package/dist/cjs/actions/checkPermitSupport.js +8 -3
- package/dist/cjs/actions/checkPermitSupport.js.map +1 -1
- package/dist/cjs/actions/getAccountCode.d.ts +8 -3
- package/dist/cjs/actions/getAccountCode.js +10 -4
- package/dist/cjs/actions/getAccountCode.js.map +1 -1
- package/dist/cjs/actions/getAllowance.js +7 -6
- package/dist/cjs/actions/getAllowance.js.map +1 -1
- package/dist/cjs/actions/getEthereumBalance.js.map +1 -1
- package/dist/cjs/actions/isBatchingSupported.js.map +1 -1
- package/dist/cjs/actions/isSafeSignature.js +2 -1
- package/dist/cjs/actions/isSafeSignature.js.map +1 -1
- package/dist/cjs/actions/resolveENSAddress.js +2 -1
- package/dist/cjs/actions/resolveENSAddress.js.map +1 -1
- package/dist/cjs/actions/resolveUNSAddress.js.map +1 -1
- package/dist/cjs/actions/setAllowance.js.map +1 -1
- package/dist/cjs/actions/waitForBatchTransactionReceipt.js +1 -1
- package/dist/cjs/actions/waitForBatchTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/waitForRelayedTransactionReceipt.js.map +1 -1
- package/dist/cjs/actions/waitForSafeTransactionExecution.js +3 -2
- package/dist/cjs/actions/waitForSafeTransactionExecution.js.map +1 -1
- package/dist/cjs/actions/waitForTransactionReceipt.js.map +1 -1
- package/dist/cjs/client/publicClient.js.map +1 -1
- package/dist/cjs/client/safeClient.js +1 -1
- package/dist/cjs/client/safeClient.js.map +1 -1
- package/dist/cjs/core/EthereumStepExecutor.js +2 -1
- package/dist/cjs/core/EthereumStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js +3 -2
- package/dist/cjs/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckAllowanceTask.js +3 -3
- package/dist/cjs/core/tasks/EthereumCheckAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckBalanceTask.js +3 -2
- package/dist/cjs/core/tasks/EthereumCheckBalanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumCheckPermitsTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumNativePermitTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumPrepareTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumRelayedSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumRelayedWaitForTransactionTask.js +2 -1
- package/dist/cjs/core/tasks/EthereumRelayedWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumResetAllowanceTask.js +3 -3
- package/dist/cjs/core/tasks/EthereumResetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js +3 -3
- package/dist/cjs/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js +6 -5
- package/dist/cjs/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumStandardWaitForTransactionTask.js +3 -2
- package/dist/cjs/core/tasks/EthereumStandardWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/EthereumWaitForTransactionStatusTask.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js +2 -1
- package/dist/cjs/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/getUpdatedStep.js +3 -2
- package/dist/cjs/core/tasks/helpers/getUpdatedStep.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/resolvePermit2Support.d.ts +27 -0
- package/dist/cjs/core/tasks/helpers/resolvePermit2Support.js +47 -0
- package/dist/cjs/core/tasks/helpers/resolvePermit2Support.js.map +1 -0
- package/dist/cjs/core/tasks/helpers/signHyperliquidTypedData.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/switchChain.js.map +1 -1
- package/dist/cjs/core/tasks/helpers/updateActionWithReceipt.js.map +1 -1
- package/dist/cjs/errors/parseEthereumErrors.js +2 -1
- package/dist/cjs/errors/parseEthereumErrors.js.map +1 -1
- package/dist/cjs/hyperliquid/agentWallet.js +4 -3
- package/dist/cjs/hyperliquid/agentWallet.js.map +1 -1
- package/dist/cjs/permits/allowanceTransfer.js.map +1 -1
- package/dist/cjs/permits/canAccountUsePermit2.d.ts +24 -0
- package/dist/cjs/permits/canAccountUsePermit2.js +87 -0
- package/dist/cjs/permits/canAccountUsePermit2.js.map +1 -0
- package/dist/cjs/permits/encodeNativePermitData.js.map +1 -1
- package/dist/cjs/permits/encodePermit2Data.js.map +1 -1
- package/dist/cjs/permits/getNativePermit.js +3 -2
- package/dist/cjs/permits/getNativePermit.js.map +1 -1
- package/dist/cjs/permits/signPermit2Message.js.map +1 -1
- package/dist/cjs/permits/signatureTransfer.js.map +1 -1
- package/dist/cjs/types.d.ts +9 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/abi.js.map +1 -1
- package/dist/cjs/utils/getActionWithFallback.js +2 -1
- package/dist/cjs/utils/getActionWithFallback.js.map +1 -1
- package/dist/cjs/utils/isValidSignature.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/EthereumProvider.js +2 -1
- package/dist/esm/EthereumProvider.js.map +1 -1
- package/dist/esm/actions/checkPermitSupport.d.ts +3 -2
- package/dist/esm/actions/checkPermitSupport.d.ts.map +1 -1
- package/dist/esm/actions/checkPermitSupport.js +8 -3
- package/dist/esm/actions/checkPermitSupport.js.map +1 -1
- package/dist/esm/actions/getAccountCode.d.ts +8 -3
- package/dist/esm/actions/getAccountCode.d.ts.map +1 -1
- package/dist/esm/actions/getAccountCode.js +10 -4
- package/dist/esm/actions/getAccountCode.js.map +1 -1
- package/dist/esm/actions/getAllowance.js +7 -6
- package/dist/esm/actions/getAllowance.js.map +1 -1
- package/dist/esm/actions/isSafeSignature.js +2 -1
- package/dist/esm/actions/isSafeSignature.js.map +1 -1
- package/dist/esm/actions/resolveENSAddress.js +2 -1
- package/dist/esm/actions/resolveENSAddress.js.map +1 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.js +1 -1
- package/dist/esm/actions/waitForBatchTransactionReceipt.js.map +1 -1
- package/dist/esm/actions/waitForSafeTransactionExecution.js +3 -2
- package/dist/esm/actions/waitForSafeTransactionExecution.js.map +1 -1
- package/dist/esm/client/safeClient.js +1 -1
- package/dist/esm/client/safeClient.js.map +1 -1
- package/dist/esm/core/EthereumStepExecutor.js +2 -1
- package/dist/esm/core/EthereumStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js +3 -2
- package/dist/esm/core/tasks/EthereumBatchedWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumCheckAllowanceTask.js +3 -3
- package/dist/esm/core/tasks/EthereumCheckAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumCheckBalanceTask.js +3 -2
- package/dist/esm/core/tasks/EthereumCheckBalanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.js +2 -1
- package/dist/esm/core/tasks/EthereumRelayedWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumResetAllowanceTask.js +3 -3
- package/dist/esm/core/tasks/EthereumResetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumSetAllowanceTask.js +3 -3
- package/dist/esm/core/tasks/EthereumSetAllowanceTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js +6 -5
- package/dist/esm/core/tasks/EthereumStandardSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumStandardWaitForTransactionTask.js +3 -2
- package/dist/esm/core/tasks/EthereumStandardWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/EthereumWaitForTransactionStatusTask.js.map +1 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js +2 -1
- package/dist/esm/core/tasks/helpers/getEthereumExecutionStrategy.js.map +1 -1
- package/dist/esm/core/tasks/helpers/getUpdatedStep.js +3 -2
- package/dist/esm/core/tasks/helpers/getUpdatedStep.js.map +1 -1
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.d.ts +27 -0
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.js +46 -0
- package/dist/esm/core/tasks/helpers/resolvePermit2Support.js.map +1 -0
- package/dist/esm/errors/parseEthereumErrors.js +2 -1
- package/dist/esm/errors/parseEthereumErrors.js.map +1 -1
- package/dist/esm/hyperliquid/agentWallet.js +4 -3
- package/dist/esm/hyperliquid/agentWallet.js.map +1 -1
- package/dist/esm/permits/canAccountUsePermit2.d.ts +24 -0
- package/dist/esm/permits/canAccountUsePermit2.d.ts.map +1 -0
- package/dist/esm/permits/canAccountUsePermit2.js +86 -0
- package/dist/esm/permits/canAccountUsePermit2.js.map +1 -0
- package/dist/esm/permits/getNativePermit.js +3 -2
- package/dist/esm/permits/getNativePermit.js.map +1 -1
- package/dist/esm/types.d.ts +9 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/getActionWithFallback.js +2 -1
- package/dist/esm/utils/getActionWithFallback.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -3
- package/src/actions/checkPermitSupport.ts +13 -4
- package/src/actions/getAccountCode.ts +14 -4
- package/src/core/tasks/EthereumCheckAllowanceTask.ts +4 -15
- package/src/core/tasks/EthereumResetAllowanceTask.ts +3 -8
- package/src/core/tasks/EthereumSetAllowanceTask.ts +3 -8
- package/src/core/tasks/EthereumStandardSignAndExecuteTask.ts +8 -10
- package/src/core/tasks/helpers/resolvePermit2Support.ts +76 -0
- package/src/permits/canAccountUsePermit2.ts +106 -0
- package/src/types.ts +9 -0
- package/src/version.ts +1 -1
- package/dist/cjs/core/tasks/helpers/isPermit2Supported.d.ts +0 -6
- package/dist/cjs/core/tasks/helpers/isPermit2Supported.js +0 -9
- package/dist/cjs/core/tasks/helpers/isPermit2Supported.js.map +0 -1
- package/dist/esm/core/tasks/helpers/isPermit2Supported.d.ts +0 -6
- package/dist/esm/core/tasks/helpers/isPermit2Supported.d.ts.map +0 -1
- package/dist/esm/core/tasks/helpers/isPermit2Supported.js +0 -8
- package/dist/esm/core/tasks/helpers/isPermit2Supported.js.map +0 -1
- package/src/core/tasks/helpers/isPermit2Supported.ts +0 -28
|
@@ -3,7 +3,7 @@ import type { Address } from 'viem'
|
|
|
3
3
|
import { getAllowance } from '../../actions/getAllowance.js'
|
|
4
4
|
import type { EthereumStepExecutorContext } from '../../types.js'
|
|
5
5
|
import { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'
|
|
6
|
-
import {
|
|
6
|
+
import { resolvePermit2Support } from './helpers/resolvePermit2Support.js'
|
|
7
7
|
|
|
8
8
|
export class EthereumCheckAllowanceTask extends BaseStepExecutionTask {
|
|
9
9
|
override async shouldRun(
|
|
@@ -13,15 +13,7 @@ export class EthereumCheckAllowanceTask extends BaseStepExecutionTask {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async run(context: EthereumStepExecutorContext): Promise<TaskResult> {
|
|
16
|
-
const {
|
|
17
|
-
step,
|
|
18
|
-
checkClient,
|
|
19
|
-
fromChain,
|
|
20
|
-
client,
|
|
21
|
-
statusManager,
|
|
22
|
-
isFromNativeToken,
|
|
23
|
-
disableMessageSigning,
|
|
24
|
-
} = context
|
|
16
|
+
const { step, checkClient, fromChain, client, statusManager } = context
|
|
25
17
|
|
|
26
18
|
// Start new allowance check
|
|
27
19
|
const action = statusManager.initializeAction({
|
|
@@ -32,11 +24,8 @@ export class EthereumCheckAllowanceTask extends BaseStepExecutionTask {
|
|
|
32
24
|
})
|
|
33
25
|
|
|
34
26
|
const executionStrategy = await getEthereumExecutionStrategy(context)
|
|
35
|
-
const permit2Supported =
|
|
36
|
-
|
|
37
|
-
fromChain,
|
|
38
|
-
isFromNativeToken,
|
|
39
|
-
disableMessageSigning,
|
|
27
|
+
const permit2Supported = await resolvePermit2Support(
|
|
28
|
+
context,
|
|
40
29
|
executionStrategy
|
|
41
30
|
)
|
|
42
31
|
const spenderAddress = permit2Supported
|
|
@@ -6,7 +6,7 @@ import { waitForTransactionReceipt } from '../../actions/waitForTransactionRecei
|
|
|
6
6
|
import type { EthereumStepExecutorContext } from '../../types.js'
|
|
7
7
|
import { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'
|
|
8
8
|
import { getTxLink } from './helpers/getTxLink.js'
|
|
9
|
-
import {
|
|
9
|
+
import { resolvePermit2Support } from './helpers/resolvePermit2Support.js'
|
|
10
10
|
|
|
11
11
|
export class EthereumResetAllowanceTask extends BaseStepExecutionTask {
|
|
12
12
|
override async shouldRun(
|
|
@@ -30,11 +30,9 @@ export class EthereumResetAllowanceTask extends BaseStepExecutionTask {
|
|
|
30
30
|
allowUserInteraction,
|
|
31
31
|
checkClient,
|
|
32
32
|
fromChain,
|
|
33
|
-
isFromNativeToken,
|
|
34
33
|
executionOptions,
|
|
35
34
|
client,
|
|
36
35
|
calls: currentCalls,
|
|
37
|
-
disableMessageSigning,
|
|
38
36
|
} = context
|
|
39
37
|
|
|
40
38
|
const action = statusManager.initializeAction({
|
|
@@ -55,11 +53,8 @@ export class EthereumResetAllowanceTask extends BaseStepExecutionTask {
|
|
|
55
53
|
|
|
56
54
|
const executionStrategy = await getEthereumExecutionStrategy(context)
|
|
57
55
|
const batchingSupported = executionStrategy === 'batched'
|
|
58
|
-
const permit2Supported =
|
|
59
|
-
|
|
60
|
-
fromChain,
|
|
61
|
-
isFromNativeToken,
|
|
62
|
-
disableMessageSigning,
|
|
56
|
+
const permit2Supported = await resolvePermit2Support(
|
|
57
|
+
context,
|
|
63
58
|
executionStrategy
|
|
64
59
|
)
|
|
65
60
|
const spenderAddress = permit2Supported
|
|
@@ -7,7 +7,7 @@ import { MaxUint256 } from '../../permits/constants.js'
|
|
|
7
7
|
import type { EthereumStepExecutorContext } from '../../types.js'
|
|
8
8
|
import { getEthereumExecutionStrategy } from './helpers/getEthereumExecutionStrategy.js'
|
|
9
9
|
import { getTxLink } from './helpers/getTxLink.js'
|
|
10
|
-
import {
|
|
10
|
+
import { resolvePermit2Support } from './helpers/resolvePermit2Support.js'
|
|
11
11
|
|
|
12
12
|
export class EthereumSetAllowanceTask extends BaseStepExecutionTask {
|
|
13
13
|
override async shouldRun(
|
|
@@ -23,11 +23,9 @@ export class EthereumSetAllowanceTask extends BaseStepExecutionTask {
|
|
|
23
23
|
statusManager,
|
|
24
24
|
executionOptions,
|
|
25
25
|
fromChain,
|
|
26
|
-
isFromNativeToken,
|
|
27
26
|
allowUserInteraction,
|
|
28
27
|
checkClient,
|
|
29
28
|
calls: currentCalls,
|
|
30
|
-
disableMessageSigning,
|
|
31
29
|
} = context
|
|
32
30
|
|
|
33
31
|
const action = statusManager.initializeAction({
|
|
@@ -49,11 +47,8 @@ export class EthereumSetAllowanceTask extends BaseStepExecutionTask {
|
|
|
49
47
|
|
|
50
48
|
const executionStrategy = await getEthereumExecutionStrategy(context)
|
|
51
49
|
const batchingSupported = executionStrategy === 'batched'
|
|
52
|
-
const permit2Supported =
|
|
53
|
-
|
|
54
|
-
fromChain,
|
|
55
|
-
isFromNativeToken,
|
|
56
|
-
disableMessageSigning,
|
|
50
|
+
const permit2Supported = await resolvePermit2Support(
|
|
51
|
+
context,
|
|
57
52
|
executionStrategy
|
|
58
53
|
)
|
|
59
54
|
|
|
@@ -17,7 +17,7 @@ import { getDomainChainId } from '../../utils/getDomainChainId.js'
|
|
|
17
17
|
import { isValidSignature } from '../../utils/isValidSignature.js'
|
|
18
18
|
import { estimateTransactionRequest } from './helpers/estimateTransactionRequest.js'
|
|
19
19
|
import { getTxLink } from './helpers/getTxLink.js'
|
|
20
|
-
import {
|
|
20
|
+
import { resolvePermit2Support } from './helpers/resolvePermit2Support.js'
|
|
21
21
|
|
|
22
22
|
export class EthereumStandardSignAndExecuteTask extends BaseStepExecutionTask {
|
|
23
23
|
async run(context: EthereumStepExecutorContext): Promise<TaskResult> {
|
|
@@ -26,13 +26,11 @@ export class EthereumStandardSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
26
26
|
client,
|
|
27
27
|
fromChain,
|
|
28
28
|
statusManager,
|
|
29
|
-
isFromNativeToken,
|
|
30
29
|
checkClient,
|
|
31
30
|
transactionRequest,
|
|
32
31
|
signedTypedData,
|
|
33
32
|
allowUserInteraction,
|
|
34
33
|
isBridgeExecution,
|
|
35
|
-
disableMessageSigning,
|
|
36
34
|
} = context
|
|
37
35
|
|
|
38
36
|
if (!transactionRequest) {
|
|
@@ -59,19 +57,19 @@ export class EthereumStandardSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
59
57
|
return { status: 'PAUSED' }
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
const permit2Supported = isPermit2Supported(
|
|
63
|
-
step,
|
|
64
|
-
fromChain,
|
|
65
|
-
isFromNativeToken,
|
|
66
|
-
disableMessageSigning,
|
|
67
|
-
'standard'
|
|
68
|
-
)
|
|
69
60
|
const signedNativePermitTypedData = signedTypedData.find(
|
|
70
61
|
(p) =>
|
|
71
62
|
p.primaryType === 'Permit' &&
|
|
72
63
|
getDomainChainId(p.domain) === fromChain.id &&
|
|
73
64
|
isValidSignature(p.signature)
|
|
74
65
|
)
|
|
66
|
+
// Resolved *after* the native-permit lookup, and short-circuited when one
|
|
67
|
+
// is found: a matching permit always wins, so resolving the gate first
|
|
68
|
+
// would spend an `eth_getCode` on a verdict this task never reads. The
|
|
69
|
+
// ternary also makes the two routes explicitly exclusive.
|
|
70
|
+
const permit2Supported = signedNativePermitTypedData
|
|
71
|
+
? false
|
|
72
|
+
: await resolvePermit2Support(context, 'standard')
|
|
75
73
|
if (signedNativePermitTypedData) {
|
|
76
74
|
transactionRequest.data = encodeNativePermitData(
|
|
77
75
|
step.action.fromToken.address as Address,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { TransactionMethodType } from '@lifi/sdk'
|
|
2
|
+
import type { Address } from 'viem'
|
|
3
|
+
import { canAccountUsePermit2 } from '../../../permits/canAccountUsePermit2.js'
|
|
4
|
+
import type { EthereumStepExecutorContext } from '../../../types.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Cheap, synchronous part of the gate: does the step/chain combination allow
|
|
8
|
+
* the Permit2 flow at all? Permit2 should not be available for atomic batch.
|
|
9
|
+
*/
|
|
10
|
+
const isPermit2SupportedForStep = (
|
|
11
|
+
context: EthereumStepExecutorContext,
|
|
12
|
+
strategy: TransactionMethodType
|
|
13
|
+
): boolean => {
|
|
14
|
+
const { step, fromChain, isFromNativeToken, disableMessageSigning } = context
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
!!fromChain.permit2 &&
|
|
18
|
+
!!fromChain.permit2Proxy &&
|
|
19
|
+
!isFromNativeToken &&
|
|
20
|
+
!disableMessageSigning &&
|
|
21
|
+
strategy !== 'batched' &&
|
|
22
|
+
// Approval address is not required for Permit2 per se, but we use it to skip allowance checks for direct transfers
|
|
23
|
+
!!step.estimate.approvalAddress &&
|
|
24
|
+
!step.estimate.skipApproval &&
|
|
25
|
+
!step.estimate.skipPermit
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether this step should use the Permit2 signature flow.
|
|
31
|
+
*
|
|
32
|
+
* Beyond the step/chain checks, the `standard` strategy also probes the
|
|
33
|
+
* *signer*: code-bearing accounts send Permit2 down its EIP-1271 path, where
|
|
34
|
+
* acceptance is implementation-specific — see {@link canAccountUsePermit2}.
|
|
35
|
+
* Accounts that fail it fall back to approve + execute.
|
|
36
|
+
*
|
|
37
|
+
* Only `standard` consults the probe. `signPermit2Message` has one call site,
|
|
38
|
+
* `EthereumStandardSignAndExecuteTask`, so that is the only flow where the SDK
|
|
39
|
+
* produces the Permit2 signature itself. A relayed step has no approve +
|
|
40
|
+
* execute fallback, so a verdict cannot rescue a failing account and would
|
|
41
|
+
* break a working one — it must never move the spender off `fromChain.permit2`.
|
|
42
|
+
*
|
|
43
|
+
* The verdict is memoized on `context.permit2SignerSupported`, and a `false`
|
|
44
|
+
* stays sticky, a failed lookup included. `TaskPipeline` threads one context
|
|
45
|
+
* through every task, so a mid-run flip would let the allowance tasks approve
|
|
46
|
+
* one spender while the sign task routes to the other — turning a needless
|
|
47
|
+
* approval into a revert.
|
|
48
|
+
*/
|
|
49
|
+
export const resolvePermit2Support = async (
|
|
50
|
+
context: EthereumStepExecutorContext,
|
|
51
|
+
strategy: TransactionMethodType
|
|
52
|
+
): Promise<boolean> => {
|
|
53
|
+
if (!isPermit2SupportedForStep(context, strategy)) {
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Only `standard` consults the probe; `batched` is excluded above.
|
|
58
|
+
if (strategy !== 'standard') {
|
|
59
|
+
return true
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { client, step, fromChain, ethereumClient } = context
|
|
63
|
+
const address = (step.action.fromAddress ??
|
|
64
|
+
ethereumClient.account?.address) as Address | undefined
|
|
65
|
+
if (!address) {
|
|
66
|
+
return false
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Caching the promise is safe: `canAccountUsePermit2` never rejects.
|
|
70
|
+
context.permit2SignerSupported ??= canAccountUsePermit2(client, {
|
|
71
|
+
chainId: fromChain.id,
|
|
72
|
+
address,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
return context.permit2SignerSupported
|
|
76
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { SDKClient } from '@lifi/sdk'
|
|
2
|
+
import { type Address, encodeFunctionData, type Hex } from 'viem'
|
|
3
|
+
import { call } from 'viem/actions'
|
|
4
|
+
import { getAction } from 'viem/utils'
|
|
5
|
+
import { getAccountCode } from '../actions/getAccountCode.js'
|
|
6
|
+
import { getPublicClient } from '../client/publicClient.js'
|
|
7
|
+
|
|
8
|
+
const ERC1271_ABI = [
|
|
9
|
+
{
|
|
10
|
+
name: 'isValidSignature',
|
|
11
|
+
type: 'function',
|
|
12
|
+
stateMutability: 'view',
|
|
13
|
+
inputs: [{ type: 'bytes32' }, { type: 'bytes' }],
|
|
14
|
+
outputs: [{ type: 'bytes4' }],
|
|
15
|
+
},
|
|
16
|
+
] as const
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A real 65-byte signature over {@link PROBE_HASH} from the public key `0x01…01`,
|
|
20
|
+
* recovering to a third party — never the account under test. Throwaway probe
|
|
21
|
+
* value, not a credential.
|
|
22
|
+
*
|
|
23
|
+
* MUST stay recoverable. An unrecoverable signature makes implementations that
|
|
24
|
+
* revert (rather than return a failure value) look like they rejected the
|
|
25
|
+
* envelope, misclassifying accounts that would have accepted ours.
|
|
26
|
+
*/
|
|
27
|
+
const PROBE_HASH = `0x${'ab'.repeat(32)}` as Hex
|
|
28
|
+
const PROBE_SIGNATURE =
|
|
29
|
+
'0x997c61aa10e2330c076d6ba7abca1e71703a8f039291db103a62e085c9b2cf0d3f7e31ec9028229acc83093fbb722fa700fd6e4ea15d584df1bf384eb0051e0d1c' as Hex
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Asks a code-bearing account the same question Permit2 will: does it evaluate a
|
|
33
|
+
* plain 65-byte ECDSA signature, or reject it outright?
|
|
34
|
+
*
|
|
35
|
+
* - **Returns** → it recovered a signer and found a mismatch, so it will accept
|
|
36
|
+
* the real root-key signature (MetaMask's `EIP7702StatelessDeleGator`).
|
|
37
|
+
* - **Reverts** → it rejected the envelope before recovery and can't validate
|
|
38
|
+
* anything we produce (Alchemy's ERC-6900 `SemiModularAccount7702`).
|
|
39
|
+
*
|
|
40
|
+
* Keyed on revert-vs-return, never on the value returned: the probe signature
|
|
41
|
+
* recovers to a third party on purpose, so a correct implementation must return
|
|
42
|
+
* a *non*-magic value, and comparing against the magic value would reject every
|
|
43
|
+
* wallet this exists to accept. Accepted cost: an implementation that returns
|
|
44
|
+
* failure for *everything* is classified capable and still fails on-chain.
|
|
45
|
+
*/
|
|
46
|
+
const acceptsRawEcdsaSignature = async (
|
|
47
|
+
client: SDKClient,
|
|
48
|
+
chainId: number,
|
|
49
|
+
address: Address
|
|
50
|
+
): Promise<boolean> => {
|
|
51
|
+
try {
|
|
52
|
+
const publicClient = await getPublicClient(client, chainId)
|
|
53
|
+
const { data } = await getAction(
|
|
54
|
+
// CCIP-Read off, or an `OffchainLookup` revert comes back as a return and
|
|
55
|
+
// inverts the signal read below. viem gates it on the client, not the
|
|
56
|
+
// call, so clone rather than disable it on the shared ENS-using client.
|
|
57
|
+
// Relies on `getPublicClient` staying bare: add `publicActions` and
|
|
58
|
+
// `getAction` prefers a decorated `client.call`, re-enabling CCIP-Read.
|
|
59
|
+
{ ...publicClient, ccipRead: false },
|
|
60
|
+
call,
|
|
61
|
+
'call'
|
|
62
|
+
)({
|
|
63
|
+
to: address,
|
|
64
|
+
data: encodeFunctionData({
|
|
65
|
+
abi: ERC1271_ABI,
|
|
66
|
+
functionName: 'isValidSignature',
|
|
67
|
+
args: [PROBE_HASH, PROBE_SIGNATURE],
|
|
68
|
+
}),
|
|
69
|
+
})
|
|
70
|
+
// A full 32-byte word (`0x` + 64 chars) or nothing: Permit2 compares against
|
|
71
|
+
// a magic value, so anything shorter can only be a false positive.
|
|
72
|
+
return !!data && data.length >= 66
|
|
73
|
+
} catch {
|
|
74
|
+
// Revert, or an RPC failure we can't tell apart from one. Either way we
|
|
75
|
+
// must not promise Permit2 will work.
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Whether the account can produce a signature Uniswap Permit2 will accept.
|
|
82
|
+
*
|
|
83
|
+
* Permit2's `SignatureVerification.verify` branches on
|
|
84
|
+
* `claimedSigner.code.length`: no code → `ecrecover`, which every EOA satisfies;
|
|
85
|
+
* code → `owner.isValidSignature(...)`, so {@link acceptsRawEcdsaSignature}
|
|
86
|
+
* probes it. Checking code length alone would exclude EIP-7702 accounts that
|
|
87
|
+
* verify our signatures fine, costing those users a needless approval.
|
|
88
|
+
*
|
|
89
|
+
* `false` on RPC failure — approve + execute always works. Same for accounts
|
|
90
|
+
* that *revert* on a signer mismatch (strict 7702 delegates, Sequence): they
|
|
91
|
+
* would accept the real signature but fail the probe, and pay one exact-amount
|
|
92
|
+
* approval per step instead.
|
|
93
|
+
*/
|
|
94
|
+
export const canAccountUsePermit2 = async (
|
|
95
|
+
client: SDKClient,
|
|
96
|
+
{ chainId, address }: { chainId: number; address: Address }
|
|
97
|
+
): Promise<boolean> => {
|
|
98
|
+
const code = await getAccountCode({ client, chainId, address })
|
|
99
|
+
if (code === undefined) {
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
102
|
+
if (code === '0x') {
|
|
103
|
+
return true
|
|
104
|
+
}
|
|
105
|
+
return acceptsRawEcdsaSignature(client, chainId, address)
|
|
106
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -36,6 +36,15 @@ export interface EthereumTaskContext {
|
|
|
36
36
|
hasMatchingPermit?: boolean
|
|
37
37
|
hasAllowance?: boolean
|
|
38
38
|
hasSufficientAllowance?: boolean
|
|
39
|
+
/**
|
|
40
|
+
* Whether the signer can produce a Permit2-verifiable signature — the
|
|
41
|
+
* in-flight or settled lookup, memoized per execution by
|
|
42
|
+
* `resolvePermit2Support` so the allowance tasks and the sign-and-execute task
|
|
43
|
+
* can't disagree. Deliberately the promise and not a `boolean`: that would
|
|
44
|
+
* be a tri-state (unresolved / yes / no) whose `false` case is
|
|
45
|
+
* indistinguishable from "not looked up yet" under a truthiness check.
|
|
46
|
+
*/
|
|
47
|
+
permit2SignerSupported?: Promise<boolean>
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
export interface EthereumStepExecutorContext
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-ethereum'
|
|
2
|
-
export const version = '4.0.
|
|
2
|
+
export const version = '4.0.9'
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ExtendedChain, LiFiStepExtended, TransactionMethodType } from "@lifi/sdk";
|
|
2
|
-
//#region src/core/tasks/helpers/isPermit2Supported.d.ts
|
|
3
|
-
declare const isPermit2Supported: (step: LiFiStepExtended, fromChain: ExtendedChain, isFromNativeToken: boolean, disableMessageSigning: boolean, strategy: TransactionMethodType) => boolean;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { isPermit2Supported };
|
|
6
|
-
//# sourceMappingURL=isPermit2Supported.d.ts.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/core/tasks/helpers/isPermit2Supported.ts
|
|
3
|
-
const isPermit2Supported = (step, fromChain, isFromNativeToken, disableMessageSigning, strategy) => {
|
|
4
|
-
return !!fromChain.permit2 && !!fromChain.permit2Proxy && !isFromNativeToken && !disableMessageSigning && strategy !== "batched" && !!step.estimate.approvalAddress && !step.estimate.skipApproval && !step.estimate.skipPermit;
|
|
5
|
-
};
|
|
6
|
-
//#endregion
|
|
7
|
-
exports.isPermit2Supported = isPermit2Supported;
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=isPermit2Supported.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isPermit2Supported.js","names":[],"sources":["../../../../../src/core/tasks/helpers/isPermit2Supported.ts"],"sourcesContent":["import type {\n ExtendedChain,\n LiFiStepExtended,\n TransactionMethodType,\n} from '@lifi/sdk'\n\n/* Check if chain has Permit2 contract deployed.\n * Permit2 should not be available for atomic batch.\n */\nexport const isPermit2Supported = (\n step: LiFiStepExtended,\n fromChain: ExtendedChain,\n isFromNativeToken: boolean,\n disableMessageSigning: boolean,\n strategy: TransactionMethodType\n): boolean => {\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"],"mappings":";;AASA,MAAa,sBACX,MACA,WACA,mBACA,uBACA,aACY;CACZ,OACE,CAAC,CAAC,UAAU,WACZ,CAAC,CAAC,UAAU,gBACZ,CAAC,qBACD,CAAC,yBACD,aAAa,aAEb,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS,gBACf,CAAC,KAAK,SAAS;AAEnB"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ExtendedChain, LiFiStepExtended, TransactionMethodType } from "@lifi/sdk";
|
|
2
|
-
//#region src/core/tasks/helpers/isPermit2Supported.d.ts
|
|
3
|
-
declare const isPermit2Supported: (step: LiFiStepExtended, fromChain: ExtendedChain, isFromNativeToken: boolean, disableMessageSigning: boolean, strategy: TransactionMethodType) => boolean;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { isPermit2Supported };
|
|
6
|
-
//# sourceMappingURL=isPermit2Supported.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isPermit2Supported.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/isPermit2Supported.ts"],"mappings":";;cASa,qBACX,MAAM,kBACN,WAAW,eACX,4BACA,gCACA,UAAU"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region src/core/tasks/helpers/isPermit2Supported.ts
|
|
2
|
-
const isPermit2Supported = (step, fromChain, isFromNativeToken, disableMessageSigning, strategy) => {
|
|
3
|
-
return !!fromChain.permit2 && !!fromChain.permit2Proxy && !isFromNativeToken && !disableMessageSigning && strategy !== "batched" && !!step.estimate.approvalAddress && !step.estimate.skipApproval && !step.estimate.skipPermit;
|
|
4
|
-
};
|
|
5
|
-
//#endregion
|
|
6
|
-
export { isPermit2Supported };
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=isPermit2Supported.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isPermit2Supported.js","names":[],"sources":["../../../../../src/core/tasks/helpers/isPermit2Supported.ts"],"sourcesContent":["import type {\n ExtendedChain,\n LiFiStepExtended,\n TransactionMethodType,\n} from '@lifi/sdk'\n\n/* Check if chain has Permit2 contract deployed.\n * Permit2 should not be available for atomic batch.\n */\nexport const isPermit2Supported = (\n step: LiFiStepExtended,\n fromChain: ExtendedChain,\n isFromNativeToken: boolean,\n disableMessageSigning: boolean,\n strategy: TransactionMethodType\n): boolean => {\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"],"mappings":";AASA,MAAa,sBACX,MACA,WACA,mBACA,uBACA,aACY;CACZ,OACE,CAAC,CAAC,UAAU,WACZ,CAAC,CAAC,UAAU,gBACZ,CAAC,qBACD,CAAC,yBACD,aAAa,aAEb,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS,gBACf,CAAC,KAAK,SAAS;AAEnB"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ExtendedChain,
|
|
3
|
-
LiFiStepExtended,
|
|
4
|
-
TransactionMethodType,
|
|
5
|
-
} from '@lifi/sdk'
|
|
6
|
-
|
|
7
|
-
/* Check if chain has Permit2 contract deployed.
|
|
8
|
-
* Permit2 should not be available for atomic batch.
|
|
9
|
-
*/
|
|
10
|
-
export const isPermit2Supported = (
|
|
11
|
-
step: LiFiStepExtended,
|
|
12
|
-
fromChain: ExtendedChain,
|
|
13
|
-
isFromNativeToken: boolean,
|
|
14
|
-
disableMessageSigning: boolean,
|
|
15
|
-
strategy: TransactionMethodType
|
|
16
|
-
): boolean => {
|
|
17
|
-
return (
|
|
18
|
-
!!fromChain.permit2 &&
|
|
19
|
-
!!fromChain.permit2Proxy &&
|
|
20
|
-
!isFromNativeToken &&
|
|
21
|
-
!disableMessageSigning &&
|
|
22
|
-
strategy !== 'batched' &&
|
|
23
|
-
// Approval address is not required for Permit2 per se, but we use it to skip allowance checks for direct transfers
|
|
24
|
-
!!step.estimate.approvalAddress &&
|
|
25
|
-
!step.estimate.skipApproval &&
|
|
26
|
-
!step.estimate.skipPermit
|
|
27
|
-
)
|
|
28
|
-
}
|