@lifi/sdk 3.6.0 → 3.6.2-beta.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/package.json +3 -3
- package/src/_cjs/core/BaseStepExecutor.js +13 -38
- package/src/_cjs/core/BaseStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/EVMStepExecutor.js +329 -359
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/checkAllowance.js +18 -9
- package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
- package/src/_cjs/core/EVM/checkPermitSupport.js +2 -2
- package/src/_cjs/core/EVM/checkPermitSupport.js.map +1 -1
- package/src/_cjs/core/EVM/permits/allowanceTransfer.js +8 -8
- package/src/_cjs/core/EVM/permits/allowanceTransfer.js.map +1 -1
- package/src/_cjs/core/EVM/permits/getNativePermit.js +12 -10
- package/src/_cjs/core/EVM/permits/getNativePermit.js.map +1 -1
- package/src/_cjs/core/EVM/permits/signPermit2Message.js +27 -26
- package/src/_cjs/core/EVM/permits/signPermit2Message.js.map +1 -1
- package/src/_cjs/core/EVM/permits/signatureTransfer.js +8 -8
- package/src/_cjs/core/EVM/permits/signatureTransfer.js.map +1 -1
- package/src/_cjs/core/EVM/typeguards.js +5 -2
- package/src/_cjs/core/EVM/typeguards.js.map +1 -1
- package/src/_cjs/core/EVM/types.js.map +1 -1
- package/src/_cjs/core/Solana/KeypairWalletAdapter.js +8 -33
- package/src/_cjs/core/Solana/KeypairWalletAdapter.js.map +1 -1
- package/src/_cjs/core/Solana/SolanaStepExecutor.js +97 -112
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/StatusManager.js +103 -136
- package/src/_cjs/core/StatusManager.js.map +1 -1
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js +136 -151
- package/src/_cjs/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_cjs/core/prepareRestart.js +7 -1
- package/src/_cjs/core/prepareRestart.js.map +1 -1
- package/src/_cjs/errors/SDKError.js +5 -30
- package/src/_cjs/errors/SDKError.js.map +1 -1
- package/src/_cjs/errors/baseError.js +2 -12
- package/src/_cjs/errors/baseError.js.map +1 -1
- package/src/_cjs/errors/httpError.js +6 -36
- package/src/_cjs/errors/httpError.js.map +1 -1
- package/src/_cjs/index.js +3 -2
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/services/api.js +2 -4
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/utils/withDedupe.js +1 -6
- package/src/_cjs/utils/withDedupe.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_cjs/version.js.map +1 -1
- package/src/_esm/core/BaseStepExecutor.js +13 -38
- package/src/_esm/core/BaseStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +367 -397
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/checkAllowance.js +18 -9
- package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
- package/src/_esm/core/EVM/checkPermitSupport.js +2 -2
- package/src/_esm/core/EVM/checkPermitSupport.js.map +1 -1
- package/src/_esm/core/EVM/permits/allowanceTransfer.js +8 -8
- package/src/_esm/core/EVM/permits/allowanceTransfer.js.map +1 -1
- package/src/_esm/core/EVM/permits/getNativePermit.js +12 -10
- package/src/_esm/core/EVM/permits/getNativePermit.js.map +1 -1
- package/src/_esm/core/EVM/permits/signPermit2Message.js +29 -28
- package/src/_esm/core/EVM/permits/signPermit2Message.js.map +1 -1
- package/src/_esm/core/EVM/permits/signatureTransfer.js +8 -8
- package/src/_esm/core/EVM/permits/signatureTransfer.js.map +1 -1
- package/src/_esm/core/EVM/typeguards.js +4 -2
- package/src/_esm/core/EVM/typeguards.js.map +1 -1
- package/src/_esm/core/EVM/types.js.map +1 -1
- package/src/_esm/core/Solana/KeypairWalletAdapter.js +12 -37
- package/src/_esm/core/Solana/KeypairWalletAdapter.js.map +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js +105 -120
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/StatusManager.js +132 -165
- package/src/_esm/core/StatusManager.js.map +1 -1
- package/src/_esm/core/UTXO/UTXOStepExecutor.js +144 -159
- package/src/_esm/core/UTXO/UTXOStepExecutor.js.map +1 -1
- package/src/_esm/core/prepareRestart.js +10 -1
- package/src/_esm/core/prepareRestart.js.map +1 -1
- package/src/_esm/errors/SDKError.js +5 -30
- package/src/_esm/errors/SDKError.js.map +1 -1
- package/src/_esm/errors/baseError.js +2 -12
- package/src/_esm/errors/baseError.js.map +1 -1
- package/src/_esm/errors/httpError.js +6 -36
- package/src/_esm/errors/httpError.js.map +1 -1
- package/src/_esm/index.js +1 -1
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/services/api.js +2 -4
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/utils/withDedupe.js +1 -6
- package/src/_esm/utils/withDedupe.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_esm/version.js.map +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/EVM/checkAllowance.d.ts +2 -3
- package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
- package/src/_types/core/EVM/checkPermitSupport.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/allowanceTransfer.d.ts +4 -4
- package/src/_types/core/EVM/permits/allowanceTransfer.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/getNativePermit.d.ts +1 -2
- package/src/_types/core/EVM/permits/getNativePermit.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/signPermit2Message.d.ts +2 -11
- package/src/_types/core/EVM/permits/signPermit2Message.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/signatureTransfer.d.ts +2 -2
- package/src/_types/core/EVM/permits/signatureTransfer.d.ts.map +1 -1
- package/src/_types/core/EVM/permits/types.d.ts +3 -9
- package/src/_types/core/EVM/permits/types.d.ts.map +1 -1
- package/src/_types/core/EVM/typeguards.d.ts +6 -2
- package/src/_types/core/EVM/typeguards.d.ts.map +1 -1
- package/src/_types/core/EVM/types.d.ts +2 -5
- package/src/_types/core/EVM/types.d.ts.map +1 -1
- package/src/_types/core/StatusManager.d.ts.map +1 -1
- package/src/_types/core/prepareRestart.d.ts.map +1 -1
- package/src/_types/core/types.d.ts +2 -0
- package/src/_types/core/types.d.ts.map +1 -1
- package/src/_types/index.d.ts +1 -1
- package/src/_types/index.d.ts.map +1 -1
- package/src/_types/services/api.d.ts +2 -2
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/_types/version.d.ts.map +1 -1
- package/src/core/EVM/EVMStepExecutor.ts +39 -44
- package/src/core/EVM/checkAllowance.ts +28 -19
- package/src/core/EVM/checkPermitSupport.ts +14 -2
- package/src/core/EVM/permits/allowanceTransfer.ts +14 -10
- package/src/core/EVM/permits/getNativePermit.ts +13 -11
- package/src/core/EVM/permits/signPermit2Message.ts +43 -63
- package/src/core/EVM/permits/signatureTransfer.ts +10 -10
- package/src/core/EVM/permits/types.ts +3 -16
- package/src/core/EVM/typeguards.ts +14 -4
- package/src/core/EVM/types.ts +2 -6
- package/src/core/StatusManager.ts +5 -3
- package/src/core/prepareRestart.ts +14 -2
- package/src/core/types.ts +2 -0
- package/src/index.ts +1 -1
- package/src/services/api.ts +3 -6
- package/src/version.ts +1 -1
- package/src/_cjs/core/EVM/permits/signNativePermitMessage.js +0 -20
- package/src/_cjs/core/EVM/permits/signNativePermitMessage.js.map +0 -1
- package/src/_cjs/core/EVM/permits/utils.js +0 -31
- package/src/_cjs/core/EVM/permits/utils.js.map +0 -1
- package/src/_esm/core/EVM/permits/signNativePermitMessage.js +0 -16
- package/src/_esm/core/EVM/permits/signNativePermitMessage.js.map +0 -1
- package/src/_esm/core/EVM/permits/utils.js +0 -26
- package/src/_esm/core/EVM/permits/utils.js.map +0 -1
- package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts +0 -4
- package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts.map +0 -1
- package/src/_types/core/EVM/permits/utils.d.ts +0 -6
- package/src/_types/core/EVM/permits/utils.d.ts.map +0 -1
- package/src/core/EVM/permits/signNativePermitMessage.ts +0 -27
- package/src/core/EVM/permits/utils.ts +0 -40
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtendedChain, LiFiStep,
|
|
1
|
+
import type { ExtendedChain, LiFiStep, SignedTypedData } from '@lifi/types'
|
|
2
2
|
import type {
|
|
3
3
|
Address,
|
|
4
4
|
Client,
|
|
@@ -8,7 +8,12 @@ import type {
|
|
|
8
8
|
SendTransactionParameters,
|
|
9
9
|
TransactionReceipt,
|
|
10
10
|
} from 'viem'
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
estimateGas,
|
|
13
|
+
getAddresses,
|
|
14
|
+
sendTransaction,
|
|
15
|
+
signTypedData,
|
|
16
|
+
} from 'viem/actions'
|
|
12
17
|
import { sendCalls } from 'viem/experimental'
|
|
13
18
|
import { getAction } from 'viem/utils'
|
|
14
19
|
import { config } from '../../config.js'
|
|
@@ -35,11 +40,9 @@ import { parseEVMErrors } from './parseEVMErrors.js'
|
|
|
35
40
|
import { encodeNativePermitData } from './permits/encodeNativePermitData.js'
|
|
36
41
|
import { encodePermit2Data } from './permits/encodePermit2Data.js'
|
|
37
42
|
import { signPermit2Message } from './permits/signPermit2Message.js'
|
|
38
|
-
import type { NativePermitSignature } from './permits/types.js'
|
|
39
|
-
import { prettifyPermit2Data } from './permits/utils.js'
|
|
40
43
|
import { switchChain } from './switchChain.js'
|
|
41
44
|
import { isRelayerStep } from './typeguards.js'
|
|
42
|
-
import type { Call,
|
|
45
|
+
import type { Call, TransactionMethodType } from './types.js'
|
|
43
46
|
import { convertExtendedChain, getMaxPriorityFeePerGas } from './utils.js'
|
|
44
47
|
import {
|
|
45
48
|
type WalletCallReceipt,
|
|
@@ -244,7 +247,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
244
247
|
// Token is not native (address is not zero)
|
|
245
248
|
!isFromNativeToken
|
|
246
249
|
|
|
247
|
-
let
|
|
250
|
+
let signedNativePermitTypedData: SignedTypedData | undefined
|
|
248
251
|
if (checkForAllowance) {
|
|
249
252
|
// Check if token needs approval and get approval transaction or message data when available
|
|
250
253
|
const allowanceResult = await checkAllowance({
|
|
@@ -266,7 +269,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
266
269
|
}
|
|
267
270
|
}
|
|
268
271
|
if (allowanceResult.status === 'NATIVE_PERMIT') {
|
|
269
|
-
|
|
272
|
+
signedNativePermitTypedData = allowanceResult.data
|
|
270
273
|
}
|
|
271
274
|
if (
|
|
272
275
|
allowanceResult.status === 'ACTION_REQUIRED' &&
|
|
@@ -316,7 +319,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
316
319
|
}
|
|
317
320
|
|
|
318
321
|
const permitRequired =
|
|
319
|
-
!batchingSupported && !
|
|
322
|
+
!batchingSupported && !signedNativePermitTypedData && permit2Supported
|
|
320
323
|
process = this.statusManager.findOrCreateProcess({
|
|
321
324
|
step,
|
|
322
325
|
type: permitRequired ? 'PERMIT' : currentProcessType,
|
|
@@ -330,7 +333,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
330
333
|
// Create new transaction request
|
|
331
334
|
if (!step.transactionRequest) {
|
|
332
335
|
const { execution, ...stepBase } = step
|
|
333
|
-
let updatedStep: LiFiStep
|
|
336
|
+
let updatedStep: LiFiStep
|
|
334
337
|
if (isRelayerTransaction) {
|
|
335
338
|
const updatedRelayedStep = await getRelayerQuote({
|
|
336
339
|
fromChain: stepBase.action.fromChainId,
|
|
@@ -344,8 +347,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
344
347
|
allowBridges: [stepBase.tool],
|
|
345
348
|
})
|
|
346
349
|
updatedStep = {
|
|
347
|
-
...updatedRelayedStep
|
|
348
|
-
permits: updatedRelayedStep.permits,
|
|
350
|
+
...updatedRelayedStep,
|
|
349
351
|
id: stepBase.id,
|
|
350
352
|
}
|
|
351
353
|
} else {
|
|
@@ -447,8 +449,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
447
449
|
})) as Address
|
|
448
450
|
txType = 'batched'
|
|
449
451
|
} else if (isRelayerTransaction) {
|
|
450
|
-
const permitWitnessTransferFromData = step.
|
|
451
|
-
(p) => p.
|
|
452
|
+
const permitWitnessTransferFromData = step.typedData.find(
|
|
453
|
+
(p) => p.primaryType === 'PermitWitnessTransferFrom'
|
|
452
454
|
)
|
|
453
455
|
|
|
454
456
|
if (!permitWitnessTransferFromData) {
|
|
@@ -458,16 +460,16 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
458
460
|
)
|
|
459
461
|
}
|
|
460
462
|
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
463
|
+
const signature = await getAction(
|
|
464
|
+
this.client,
|
|
465
|
+
signTypedData,
|
|
466
|
+
'signTypedData'
|
|
467
|
+
)({
|
|
468
|
+
account: this.client.account!,
|
|
469
|
+
primaryType: permitWitnessTransferFromData.primaryType,
|
|
470
|
+
domain: permitWitnessTransferFromData.domain,
|
|
471
|
+
types: permitWitnessTransferFromData.types,
|
|
472
|
+
message: permitWitnessTransferFromData.message,
|
|
471
473
|
})
|
|
472
474
|
|
|
473
475
|
this.statusManager.updateProcess(step, process.type, 'DONE')
|
|
@@ -479,37 +481,30 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
479
481
|
chainId: fromChain.id,
|
|
480
482
|
})
|
|
481
483
|
|
|
482
|
-
const
|
|
484
|
+
const signedTypedData: SignedTypedData[] = [
|
|
483
485
|
{
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
signature: permit2Signature.signature,
|
|
486
|
+
...permitWitnessTransferFromData,
|
|
487
|
+
signature: signature,
|
|
487
488
|
},
|
|
488
489
|
]
|
|
489
490
|
// Add native permit if available as first element, order is important
|
|
490
|
-
if (
|
|
491
|
-
|
|
492
|
-
permitType: 'Permit',
|
|
493
|
-
permit: nativePermitSignature.values,
|
|
494
|
-
signature: nativePermitSignature.signature,
|
|
495
|
-
})
|
|
491
|
+
if (signedNativePermitTypedData) {
|
|
492
|
+
signedTypedData.unshift(signedNativePermitTypedData)
|
|
496
493
|
}
|
|
497
|
-
|
|
494
|
+
const { execution, ...stepBase } = step
|
|
498
495
|
const relayedTransaction = await relayTransaction({
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
permits: signedPermits,
|
|
502
|
-
callData: transactionRequest.data! as Hex,
|
|
496
|
+
...stepBase,
|
|
497
|
+
typedData: signedTypedData,
|
|
503
498
|
})
|
|
504
499
|
txHash = relayedTransaction.taskId as Hash
|
|
505
500
|
txType = 'relayed'
|
|
506
501
|
} else {
|
|
507
|
-
if (
|
|
502
|
+
if (signedNativePermitTypedData) {
|
|
508
503
|
transactionRequest.data = encodeNativePermitData(
|
|
509
504
|
step.action.fromToken.address as Address,
|
|
510
505
|
BigInt(step.action.fromAmount),
|
|
511
|
-
|
|
512
|
-
|
|
506
|
+
signedNativePermitTypedData.message.deadline,
|
|
507
|
+
signedNativePermitTypedData.signature,
|
|
513
508
|
transactionRequest.data as Hex
|
|
514
509
|
)
|
|
515
510
|
} else if (permit2Supported) {
|
|
@@ -531,14 +526,14 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
531
526
|
transactionRequest.data = encodePermit2Data(
|
|
532
527
|
step.action.fromToken.address as Address,
|
|
533
528
|
BigInt(step.action.fromAmount),
|
|
534
|
-
permit2Signature.
|
|
535
|
-
permit2Signature.
|
|
529
|
+
permit2Signature.message.nonce,
|
|
530
|
+
permit2Signature.message.deadline,
|
|
536
531
|
transactionRequest.data as Hex,
|
|
537
532
|
permit2Signature.signature
|
|
538
533
|
)
|
|
539
534
|
}
|
|
540
535
|
|
|
541
|
-
if (
|
|
536
|
+
if (signedNativePermitTypedData || permit2Supported) {
|
|
542
537
|
try {
|
|
543
538
|
// Target address should be the Permit2 proxy contract in case of native permit or Permit2
|
|
544
539
|
transactionRequest.to = fromChain.permit2Proxy
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import type { ExtendedChain, LiFiStep } from '@lifi/types'
|
|
1
|
+
import type { ExtendedChain, LiFiStep, SignedTypedData } from '@lifi/types'
|
|
2
2
|
import type { Address, Client, Hash } from 'viem'
|
|
3
|
+
import { signTypedData } from 'viem/actions'
|
|
4
|
+
import { getAction } from 'viem/utils'
|
|
3
5
|
import { MaxUint256 } from '../../constants.js'
|
|
4
6
|
import type { StatusManager } from '../StatusManager.js'
|
|
5
7
|
import type { ExecutionOptions, Process, ProcessType } from '../types.js'
|
|
6
8
|
import { getAllowance } from './getAllowance.js'
|
|
7
9
|
import { parseEVMErrors } from './parseEVMErrors.js'
|
|
8
10
|
import { getNativePermit } from './permits/getNativePermit.js'
|
|
9
|
-
import {
|
|
10
|
-
import type {
|
|
11
|
-
NativePermitData,
|
|
12
|
-
NativePermitSignature,
|
|
13
|
-
} from './permits/types.js'
|
|
14
|
-
import { prettifyNativePermitData } from './permits/utils.js'
|
|
11
|
+
import type { NativePermitData } from './permits/types.js'
|
|
15
12
|
import { setAllowance } from './setAllowance.js'
|
|
16
13
|
import { isRelayerStep } from './typeguards.js'
|
|
17
14
|
import type { Call } from './types.js'
|
|
@@ -38,7 +35,7 @@ export type AllowanceResult =
|
|
|
38
35
|
}
|
|
39
36
|
| {
|
|
40
37
|
status: 'NATIVE_PERMIT'
|
|
41
|
-
data:
|
|
38
|
+
data: SignedTypedData
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
export const checkAllowance = async ({
|
|
@@ -78,6 +75,7 @@ export const checkAllowance = async ({
|
|
|
78
75
|
const spenderAddress = permit2Supported
|
|
79
76
|
? chain.permit2
|
|
80
77
|
: step.estimate.approvalAddress
|
|
78
|
+
|
|
81
79
|
const fromAmount = BigInt(step.action.fromAmount)
|
|
82
80
|
|
|
83
81
|
const approved = await getAllowance(
|
|
@@ -97,17 +95,15 @@ export const checkAllowance = async ({
|
|
|
97
95
|
|
|
98
96
|
let nativePermitData: NativePermitData | undefined
|
|
99
97
|
if (isRelayerTransaction) {
|
|
100
|
-
|
|
101
|
-
(p) => p.
|
|
102
|
-
)
|
|
103
|
-
if (permitData) {
|
|
104
|
-
nativePermitData = prettifyNativePermitData(permitData)
|
|
105
|
-
}
|
|
98
|
+
nativePermitData = step.typedData.find(
|
|
99
|
+
(p) => p.primaryType === 'Permit'
|
|
100
|
+
) as NativePermitData
|
|
106
101
|
} else {
|
|
107
102
|
nativePermitData = await getNativePermit(
|
|
108
103
|
client,
|
|
109
|
-
chain,
|
|
104
|
+
chain.id,
|
|
110
105
|
step.action.fromToken.address as Address,
|
|
106
|
+
chain.permit2Proxy as Address,
|
|
111
107
|
fromAmount
|
|
112
108
|
)
|
|
113
109
|
}
|
|
@@ -123,12 +119,25 @@ export const checkAllowance = async ({
|
|
|
123
119
|
!!nativePermitData && !!chain.permit2Proxy && !batchingSupported
|
|
124
120
|
|
|
125
121
|
if (nativePermitSupported && nativePermitData) {
|
|
126
|
-
const
|
|
122
|
+
const signature = await getAction(
|
|
127
123
|
client,
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
signTypedData,
|
|
125
|
+
'signTypedData'
|
|
126
|
+
)({
|
|
127
|
+
account: client.account!,
|
|
128
|
+
domain: nativePermitData.domain,
|
|
129
|
+
types: nativePermitData.types,
|
|
130
|
+
primaryType: 'Permit',
|
|
131
|
+
message: nativePermitData.message,
|
|
132
|
+
})
|
|
130
133
|
statusManager.updateProcess(step, allowanceProcess.type, 'DONE')
|
|
131
|
-
return {
|
|
134
|
+
return {
|
|
135
|
+
status: 'NATIVE_PERMIT',
|
|
136
|
+
data: {
|
|
137
|
+
...nativePermitData,
|
|
138
|
+
signature,
|
|
139
|
+
},
|
|
140
|
+
}
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
// Set new allowance
|
|
@@ -49,10 +49,22 @@ export const checkPermitSupport = async ({
|
|
|
49
49
|
let nativePermit: NativePermitData | undefined
|
|
50
50
|
// Try with wallet client first, fallback to public client
|
|
51
51
|
try {
|
|
52
|
-
nativePermit = await getNativePermit(
|
|
52
|
+
nativePermit = await getNativePermit(
|
|
53
|
+
client,
|
|
54
|
+
chain.id,
|
|
55
|
+
tokenAddress,
|
|
56
|
+
chain.permit2Proxy as Address,
|
|
57
|
+
amount
|
|
58
|
+
)
|
|
53
59
|
} catch {
|
|
54
60
|
client = await getPublicClient(chain.id)
|
|
55
|
-
nativePermit = await getNativePermit(
|
|
61
|
+
nativePermit = await getNativePermit(
|
|
62
|
+
client,
|
|
63
|
+
chain.id,
|
|
64
|
+
tokenAddress,
|
|
65
|
+
chain.permit2Proxy as Address,
|
|
66
|
+
amount
|
|
67
|
+
)
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
let permit2Allowance: bigint | undefined
|
|
@@ -35,13 +35,13 @@ export interface PermitBatch {
|
|
|
35
35
|
export type PermitSingleData = {
|
|
36
36
|
domain: TypedDataDomain
|
|
37
37
|
types: TypedData
|
|
38
|
-
|
|
38
|
+
message: PermitSingle
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export type PermitBatchData = {
|
|
42
42
|
domain: TypedDataDomain
|
|
43
43
|
types: TypedData
|
|
44
|
-
|
|
44
|
+
message: PermitBatch
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const PERMIT_DETAILS = [
|
|
@@ -85,7 +85,7 @@ export function getPermitSingleData(
|
|
|
85
85
|
|
|
86
86
|
return {
|
|
87
87
|
domain,
|
|
88
|
-
|
|
88
|
+
message: permit,
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -101,7 +101,7 @@ export function getPermitBatchData(
|
|
|
101
101
|
|
|
102
102
|
return {
|
|
103
103
|
domain,
|
|
104
|
-
|
|
104
|
+
message: permit,
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -118,14 +118,14 @@ export function getPermitData(
|
|
|
118
118
|
return {
|
|
119
119
|
domain,
|
|
120
120
|
types: PERMIT_TYPES,
|
|
121
|
-
|
|
121
|
+
message: permit,
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
permit.details.forEach(validatePermitDetails)
|
|
125
125
|
return {
|
|
126
126
|
domain,
|
|
127
127
|
types: PERMIT_BATCH_TYPES,
|
|
128
|
-
|
|
128
|
+
message: permit,
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -135,7 +135,7 @@ export function hash(
|
|
|
135
135
|
chainId: number
|
|
136
136
|
): string {
|
|
137
137
|
if (isPermit(permit)) {
|
|
138
|
-
const { domain,
|
|
138
|
+
const { domain, message } = getPermitSingleData(
|
|
139
139
|
permit,
|
|
140
140
|
permit2Address,
|
|
141
141
|
chainId
|
|
@@ -145,16 +145,20 @@ export function hash(
|
|
|
145
145
|
domain,
|
|
146
146
|
types: PERMIT_TYPES,
|
|
147
147
|
primaryType: 'PermitSingle',
|
|
148
|
-
message:
|
|
148
|
+
message: message,
|
|
149
149
|
})
|
|
150
150
|
}
|
|
151
|
-
const { domain,
|
|
151
|
+
const { domain, message } = getPermitBatchData(
|
|
152
|
+
permit,
|
|
153
|
+
permit2Address,
|
|
154
|
+
chainId
|
|
155
|
+
)
|
|
152
156
|
|
|
153
157
|
return hashTypedData({
|
|
154
158
|
domain,
|
|
155
159
|
types: PERMIT_BATCH_TYPES,
|
|
156
160
|
primaryType: 'PermitBatch',
|
|
157
|
-
message:
|
|
161
|
+
message: message,
|
|
158
162
|
})
|
|
159
163
|
}
|
|
160
164
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ExtendedChain } from '@lifi/types'
|
|
2
1
|
import {
|
|
3
2
|
encodeAbiParameters,
|
|
4
3
|
keccak256,
|
|
@@ -145,12 +144,13 @@ function validateDomainSeparator({
|
|
|
145
144
|
*/
|
|
146
145
|
export const getNativePermit = async (
|
|
147
146
|
client: Client,
|
|
148
|
-
|
|
147
|
+
chainId: number,
|
|
149
148
|
tokenAddress: Address,
|
|
149
|
+
spenderAddress: Address,
|
|
150
150
|
amount: bigint
|
|
151
151
|
): Promise<NativePermitData | undefined> => {
|
|
152
152
|
try {
|
|
153
|
-
const multicallAddress = await getMulticallAddress(
|
|
153
|
+
const multicallAddress = await getMulticallAddress(chainId)
|
|
154
154
|
|
|
155
155
|
const contractCalls = [
|
|
156
156
|
{
|
|
@@ -197,7 +197,7 @@ export const getNativePermit = async (
|
|
|
197
197
|
const { isValid, domain } = validateDomainSeparator({
|
|
198
198
|
name: nameResult.result,
|
|
199
199
|
version: versionResult.result ?? '1',
|
|
200
|
-
chainId: BigInt(
|
|
200
|
+
chainId: BigInt(chainId),
|
|
201
201
|
verifyingContract: tokenAddress,
|
|
202
202
|
domainSeparator: domainSeparatorResult.result,
|
|
203
203
|
})
|
|
@@ -206,18 +206,19 @@ export const getNativePermit = async (
|
|
|
206
206
|
return undefined
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
const
|
|
209
|
+
const message = {
|
|
210
210
|
owner: client.account!.address,
|
|
211
|
-
spender:
|
|
211
|
+
spender: spenderAddress,
|
|
212
212
|
value: amount,
|
|
213
213
|
nonce: noncesResult.result,
|
|
214
214
|
deadline: BigInt(Math.floor(Date.now() / 1000) + 30 * 60), // 30 minutes
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
return {
|
|
218
|
+
primaryType: 'Permit',
|
|
218
219
|
domain,
|
|
219
220
|
types: eip2612Types,
|
|
220
|
-
|
|
221
|
+
message,
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
|
|
@@ -245,7 +246,7 @@ export const getNativePermit = async (
|
|
|
245
246
|
const { isValid, domain } = validateDomainSeparator({
|
|
246
247
|
name,
|
|
247
248
|
version,
|
|
248
|
-
chainId: BigInt(
|
|
249
|
+
chainId: BigInt(chainId),
|
|
249
250
|
verifyingContract: tokenAddress,
|
|
250
251
|
domainSeparator: domainSeparatorResult.value,
|
|
251
252
|
})
|
|
@@ -254,18 +255,19 @@ export const getNativePermit = async (
|
|
|
254
255
|
return undefined
|
|
255
256
|
}
|
|
256
257
|
|
|
257
|
-
const
|
|
258
|
+
const message = {
|
|
258
259
|
owner: client.account!.address,
|
|
259
|
-
spender:
|
|
260
|
+
spender: spenderAddress,
|
|
260
261
|
value: amount,
|
|
261
262
|
nonce: noncesResult.value,
|
|
262
263
|
deadline: BigInt(Math.floor(Date.now() / 1000) + 30 * 60), // 30 minutes
|
|
263
264
|
}
|
|
264
265
|
|
|
265
266
|
return {
|
|
267
|
+
primaryType: 'Permit',
|
|
266
268
|
domain,
|
|
267
269
|
types: eip2612Types,
|
|
268
|
-
|
|
270
|
+
message,
|
|
269
271
|
}
|
|
270
272
|
} catch {
|
|
271
273
|
return undefined
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import type { ExtendedChain } from '@lifi/types'
|
|
1
|
+
import type { ExtendedChain, SignedTypedData } from '@lifi/types'
|
|
2
2
|
import type { Address, Client, Hex } from 'viem'
|
|
3
3
|
import { keccak256 } from 'viem'
|
|
4
4
|
import { signTypedData } from 'viem/actions'
|
|
5
5
|
import { getAction } from 'viem/utils'
|
|
6
6
|
import { getPermitTransferFromValues } from './getPermitTransferFromValues.js'
|
|
7
|
-
import {
|
|
8
|
-
type PermitBatchTransferFrom,
|
|
9
|
-
type PermitBatchTransferFromData,
|
|
10
|
-
type PermitTransferFrom,
|
|
11
|
-
type PermitTransferFromData,
|
|
12
|
-
getPermitData,
|
|
13
|
-
} from './signatureTransfer.js'
|
|
14
|
-
import type { Permit2Signature } from './types.js'
|
|
7
|
+
import { getPermitData } from './signatureTransfer.js'
|
|
15
8
|
|
|
16
9
|
export interface SignPermit2MessageParams {
|
|
17
10
|
client: Client
|
|
@@ -22,59 +15,45 @@ export interface SignPermit2MessageParams {
|
|
|
22
15
|
witness?: boolean
|
|
23
16
|
}
|
|
24
17
|
|
|
25
|
-
export interface SignPermit2SingleParams extends SignPermit2MessageParams {
|
|
26
|
-
permitData?: PermitTransferFromData
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface SignPermit2BatchParams extends SignPermit2MessageParams {
|
|
30
|
-
permitData?: PermitBatchTransferFromData
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function signPermit2Message(
|
|
34
|
-
params: SignPermit2SingleParams
|
|
35
|
-
): Promise<Permit2Signature<PermitTransferFrom>>
|
|
36
|
-
export function signPermit2Message(
|
|
37
|
-
params: SignPermit2BatchParams
|
|
38
|
-
): Promise<Permit2Signature<PermitBatchTransferFrom>>
|
|
39
18
|
export async function signPermit2Message(
|
|
40
|
-
params:
|
|
41
|
-
): Promise<
|
|
42
|
-
const { client, chain, tokenAddress, amount, data,
|
|
43
|
-
params
|
|
19
|
+
params: SignPermit2MessageParams
|
|
20
|
+
): Promise<SignedTypedData> {
|
|
21
|
+
const { client, chain, tokenAddress, amount, data, witness } = params
|
|
44
22
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
amount
|
|
52
|
-
)
|
|
23
|
+
const permitTransferFrom = await getPermitTransferFromValues(
|
|
24
|
+
client,
|
|
25
|
+
chain,
|
|
26
|
+
tokenAddress,
|
|
27
|
+
amount
|
|
28
|
+
)
|
|
53
29
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
30
|
+
// Create witness data for the LI.FI call
|
|
31
|
+
const _witness = witness
|
|
32
|
+
? {
|
|
33
|
+
witness: {
|
|
34
|
+
diamondAddress: chain.diamondAddress as Address,
|
|
35
|
+
diamondCalldataHash: keccak256(data),
|
|
36
|
+
},
|
|
37
|
+
witnessTypeName: 'LiFiCall',
|
|
38
|
+
witnessType: {
|
|
39
|
+
LiFiCall: [
|
|
40
|
+
{ name: 'diamondAddress', type: 'address' },
|
|
41
|
+
{ name: 'diamondCalldataHash', type: 'bytes32' },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
: undefined
|
|
70
46
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
47
|
+
const permitData = getPermitData(
|
|
48
|
+
permitTransferFrom,
|
|
49
|
+
chain.permit2 as Address,
|
|
50
|
+
chain.id,
|
|
51
|
+
_witness
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const primaryType = witness
|
|
55
|
+
? 'PermitWitnessTransferFrom'
|
|
56
|
+
: 'PermitTransferFrom'
|
|
78
57
|
|
|
79
58
|
const signature = await getAction(
|
|
80
59
|
client,
|
|
@@ -82,14 +61,15 @@ export async function signPermit2Message(
|
|
|
82
61
|
'signTypedData'
|
|
83
62
|
)({
|
|
84
63
|
account: client.account!,
|
|
85
|
-
primaryType
|
|
86
|
-
domain:
|
|
87
|
-
types:
|
|
88
|
-
message:
|
|
64
|
+
primaryType,
|
|
65
|
+
domain: permitData.domain,
|
|
66
|
+
types: permitData.types,
|
|
67
|
+
message: permitData.message,
|
|
89
68
|
})
|
|
90
69
|
|
|
91
70
|
return {
|
|
71
|
+
...permitData,
|
|
72
|
+
primaryType,
|
|
92
73
|
signature,
|
|
93
|
-
values: _permitData.values,
|
|
94
74
|
}
|
|
95
75
|
}
|
|
@@ -36,13 +36,13 @@ export type PermitBatchTransferFrom = {
|
|
|
36
36
|
export type PermitTransferFromData = {
|
|
37
37
|
domain: TypedDataDomain
|
|
38
38
|
types: TypedData
|
|
39
|
-
|
|
39
|
+
message: PermitTransferFrom
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export type PermitBatchTransferFromData = {
|
|
43
43
|
domain: TypedDataDomain
|
|
44
44
|
types: TypedData
|
|
45
|
-
|
|
45
|
+
message: PermitBatchTransferFrom
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const TOKEN_PERMISSIONS = [
|
|
@@ -103,14 +103,14 @@ export function getPermitTransferData(
|
|
|
103
103
|
} as const)
|
|
104
104
|
: PERMIT_TRANSFER_FROM_TYPES
|
|
105
105
|
|
|
106
|
-
const
|
|
106
|
+
const message = witness
|
|
107
107
|
? Object.assign(permit, { witness: witness.witness })
|
|
108
108
|
: permit
|
|
109
109
|
|
|
110
110
|
return {
|
|
111
111
|
domain,
|
|
112
112
|
types,
|
|
113
|
-
|
|
113
|
+
message,
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -141,14 +141,14 @@ export function getPermitBatchTransferData(
|
|
|
141
141
|
}
|
|
142
142
|
: PERMIT_BATCH_TRANSFER_FROM_TYPES
|
|
143
143
|
|
|
144
|
-
const
|
|
144
|
+
const message = witness
|
|
145
145
|
? Object.assign(permit, { witness: witness.witness })
|
|
146
146
|
: permit
|
|
147
147
|
|
|
148
148
|
return {
|
|
149
149
|
domain,
|
|
150
150
|
types,
|
|
151
|
-
|
|
151
|
+
message,
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -185,7 +185,7 @@ export function hash<T extends PermitTransferFrom | PermitBatchTransferFrom>(
|
|
|
185
185
|
witness?: Witness
|
|
186
186
|
) {
|
|
187
187
|
if (isPermitTransferFrom(permit)) {
|
|
188
|
-
const { domain, types,
|
|
188
|
+
const { domain, types, message } = getPermitTransferData(
|
|
189
189
|
permit,
|
|
190
190
|
permit2Address,
|
|
191
191
|
chainId,
|
|
@@ -197,11 +197,11 @@ export function hash<T extends PermitTransferFrom | PermitBatchTransferFrom>(
|
|
|
197
197
|
types,
|
|
198
198
|
primaryType: witness ? 'PermitWitnessTransferFrom' : 'PermitTransferFrom',
|
|
199
199
|
message: {
|
|
200
|
-
...
|
|
200
|
+
...message,
|
|
201
201
|
},
|
|
202
202
|
})
|
|
203
203
|
}
|
|
204
|
-
const { domain, types,
|
|
204
|
+
const { domain, types, message } = getPermitBatchTransferData(
|
|
205
205
|
permit,
|
|
206
206
|
permit2Address,
|
|
207
207
|
chainId,
|
|
@@ -214,7 +214,7 @@ export function hash<T extends PermitTransferFrom | PermitBatchTransferFrom>(
|
|
|
214
214
|
primaryType: witness
|
|
215
215
|
? 'PermitBatchWitnessTransferFrom'
|
|
216
216
|
: 'PermitBatchTransferFrom',
|
|
217
|
-
message: { ...
|
|
217
|
+
message: { ...message },
|
|
218
218
|
})
|
|
219
219
|
}
|
|
220
220
|
|