@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.
Files changed (145) hide show
  1. package/package.json +3 -3
  2. package/src/_cjs/core/BaseStepExecutor.js +13 -38
  3. package/src/_cjs/core/BaseStepExecutor.js.map +1 -1
  4. package/src/_cjs/core/EVM/EVMStepExecutor.js +329 -359
  5. package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
  6. package/src/_cjs/core/EVM/checkAllowance.js +18 -9
  7. package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
  8. package/src/_cjs/core/EVM/checkPermitSupport.js +2 -2
  9. package/src/_cjs/core/EVM/checkPermitSupport.js.map +1 -1
  10. package/src/_cjs/core/EVM/permits/allowanceTransfer.js +8 -8
  11. package/src/_cjs/core/EVM/permits/allowanceTransfer.js.map +1 -1
  12. package/src/_cjs/core/EVM/permits/getNativePermit.js +12 -10
  13. package/src/_cjs/core/EVM/permits/getNativePermit.js.map +1 -1
  14. package/src/_cjs/core/EVM/permits/signPermit2Message.js +27 -26
  15. package/src/_cjs/core/EVM/permits/signPermit2Message.js.map +1 -1
  16. package/src/_cjs/core/EVM/permits/signatureTransfer.js +8 -8
  17. package/src/_cjs/core/EVM/permits/signatureTransfer.js.map +1 -1
  18. package/src/_cjs/core/EVM/typeguards.js +5 -2
  19. package/src/_cjs/core/EVM/typeguards.js.map +1 -1
  20. package/src/_cjs/core/EVM/types.js.map +1 -1
  21. package/src/_cjs/core/Solana/KeypairWalletAdapter.js +8 -33
  22. package/src/_cjs/core/Solana/KeypairWalletAdapter.js.map +1 -1
  23. package/src/_cjs/core/Solana/SolanaStepExecutor.js +97 -112
  24. package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
  25. package/src/_cjs/core/StatusManager.js +103 -136
  26. package/src/_cjs/core/StatusManager.js.map +1 -1
  27. package/src/_cjs/core/UTXO/UTXOStepExecutor.js +136 -151
  28. package/src/_cjs/core/UTXO/UTXOStepExecutor.js.map +1 -1
  29. package/src/_cjs/core/prepareRestart.js +7 -1
  30. package/src/_cjs/core/prepareRestart.js.map +1 -1
  31. package/src/_cjs/errors/SDKError.js +5 -30
  32. package/src/_cjs/errors/SDKError.js.map +1 -1
  33. package/src/_cjs/errors/baseError.js +2 -12
  34. package/src/_cjs/errors/baseError.js.map +1 -1
  35. package/src/_cjs/errors/httpError.js +6 -36
  36. package/src/_cjs/errors/httpError.js.map +1 -1
  37. package/src/_cjs/index.js +3 -2
  38. package/src/_cjs/index.js.map +1 -1
  39. package/src/_cjs/services/api.js +2 -4
  40. package/src/_cjs/services/api.js.map +1 -1
  41. package/src/_cjs/utils/withDedupe.js +1 -6
  42. package/src/_cjs/utils/withDedupe.js.map +1 -1
  43. package/src/_cjs/version.js +1 -1
  44. package/src/_cjs/version.js.map +1 -1
  45. package/src/_esm/core/BaseStepExecutor.js +13 -38
  46. package/src/_esm/core/BaseStepExecutor.js.map +1 -1
  47. package/src/_esm/core/EVM/EVMStepExecutor.js +367 -397
  48. package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
  49. package/src/_esm/core/EVM/checkAllowance.js +18 -9
  50. package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
  51. package/src/_esm/core/EVM/checkPermitSupport.js +2 -2
  52. package/src/_esm/core/EVM/checkPermitSupport.js.map +1 -1
  53. package/src/_esm/core/EVM/permits/allowanceTransfer.js +8 -8
  54. package/src/_esm/core/EVM/permits/allowanceTransfer.js.map +1 -1
  55. package/src/_esm/core/EVM/permits/getNativePermit.js +12 -10
  56. package/src/_esm/core/EVM/permits/getNativePermit.js.map +1 -1
  57. package/src/_esm/core/EVM/permits/signPermit2Message.js +29 -28
  58. package/src/_esm/core/EVM/permits/signPermit2Message.js.map +1 -1
  59. package/src/_esm/core/EVM/permits/signatureTransfer.js +8 -8
  60. package/src/_esm/core/EVM/permits/signatureTransfer.js.map +1 -1
  61. package/src/_esm/core/EVM/typeguards.js +4 -2
  62. package/src/_esm/core/EVM/typeguards.js.map +1 -1
  63. package/src/_esm/core/EVM/types.js.map +1 -1
  64. package/src/_esm/core/Solana/KeypairWalletAdapter.js +12 -37
  65. package/src/_esm/core/Solana/KeypairWalletAdapter.js.map +1 -1
  66. package/src/_esm/core/Solana/SolanaStepExecutor.js +105 -120
  67. package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
  68. package/src/_esm/core/StatusManager.js +132 -165
  69. package/src/_esm/core/StatusManager.js.map +1 -1
  70. package/src/_esm/core/UTXO/UTXOStepExecutor.js +144 -159
  71. package/src/_esm/core/UTXO/UTXOStepExecutor.js.map +1 -1
  72. package/src/_esm/core/prepareRestart.js +10 -1
  73. package/src/_esm/core/prepareRestart.js.map +1 -1
  74. package/src/_esm/errors/SDKError.js +5 -30
  75. package/src/_esm/errors/SDKError.js.map +1 -1
  76. package/src/_esm/errors/baseError.js +2 -12
  77. package/src/_esm/errors/baseError.js.map +1 -1
  78. package/src/_esm/errors/httpError.js +6 -36
  79. package/src/_esm/errors/httpError.js.map +1 -1
  80. package/src/_esm/index.js +1 -1
  81. package/src/_esm/index.js.map +1 -1
  82. package/src/_esm/services/api.js +2 -4
  83. package/src/_esm/services/api.js.map +1 -1
  84. package/src/_esm/utils/withDedupe.js +1 -6
  85. package/src/_esm/utils/withDedupe.js.map +1 -1
  86. package/src/_esm/version.js +1 -1
  87. package/src/_esm/version.js.map +1 -1
  88. package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
  89. package/src/_types/core/EVM/checkAllowance.d.ts +2 -3
  90. package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
  91. package/src/_types/core/EVM/checkPermitSupport.d.ts.map +1 -1
  92. package/src/_types/core/EVM/permits/allowanceTransfer.d.ts +4 -4
  93. package/src/_types/core/EVM/permits/allowanceTransfer.d.ts.map +1 -1
  94. package/src/_types/core/EVM/permits/getNativePermit.d.ts +1 -2
  95. package/src/_types/core/EVM/permits/getNativePermit.d.ts.map +1 -1
  96. package/src/_types/core/EVM/permits/signPermit2Message.d.ts +2 -11
  97. package/src/_types/core/EVM/permits/signPermit2Message.d.ts.map +1 -1
  98. package/src/_types/core/EVM/permits/signatureTransfer.d.ts +2 -2
  99. package/src/_types/core/EVM/permits/signatureTransfer.d.ts.map +1 -1
  100. package/src/_types/core/EVM/permits/types.d.ts +3 -9
  101. package/src/_types/core/EVM/permits/types.d.ts.map +1 -1
  102. package/src/_types/core/EVM/typeguards.d.ts +6 -2
  103. package/src/_types/core/EVM/typeguards.d.ts.map +1 -1
  104. package/src/_types/core/EVM/types.d.ts +2 -5
  105. package/src/_types/core/EVM/types.d.ts.map +1 -1
  106. package/src/_types/core/StatusManager.d.ts.map +1 -1
  107. package/src/_types/core/prepareRestart.d.ts.map +1 -1
  108. package/src/_types/core/types.d.ts +2 -0
  109. package/src/_types/core/types.d.ts.map +1 -1
  110. package/src/_types/index.d.ts +1 -1
  111. package/src/_types/index.d.ts.map +1 -1
  112. package/src/_types/services/api.d.ts +2 -2
  113. package/src/_types/services/api.d.ts.map +1 -1
  114. package/src/_types/version.d.ts +1 -1
  115. package/src/_types/version.d.ts.map +1 -1
  116. package/src/core/EVM/EVMStepExecutor.ts +39 -44
  117. package/src/core/EVM/checkAllowance.ts +28 -19
  118. package/src/core/EVM/checkPermitSupport.ts +14 -2
  119. package/src/core/EVM/permits/allowanceTransfer.ts +14 -10
  120. package/src/core/EVM/permits/getNativePermit.ts +13 -11
  121. package/src/core/EVM/permits/signPermit2Message.ts +43 -63
  122. package/src/core/EVM/permits/signatureTransfer.ts +10 -10
  123. package/src/core/EVM/permits/types.ts +3 -16
  124. package/src/core/EVM/typeguards.ts +14 -4
  125. package/src/core/EVM/types.ts +2 -6
  126. package/src/core/StatusManager.ts +5 -3
  127. package/src/core/prepareRestart.ts +14 -2
  128. package/src/core/types.ts +2 -0
  129. package/src/index.ts +1 -1
  130. package/src/services/api.ts +3 -6
  131. package/src/version.ts +1 -1
  132. package/src/_cjs/core/EVM/permits/signNativePermitMessage.js +0 -20
  133. package/src/_cjs/core/EVM/permits/signNativePermitMessage.js.map +0 -1
  134. package/src/_cjs/core/EVM/permits/utils.js +0 -31
  135. package/src/_cjs/core/EVM/permits/utils.js.map +0 -1
  136. package/src/_esm/core/EVM/permits/signNativePermitMessage.js +0 -16
  137. package/src/_esm/core/EVM/permits/signNativePermitMessage.js.map +0 -1
  138. package/src/_esm/core/EVM/permits/utils.js +0 -26
  139. package/src/_esm/core/EVM/permits/utils.js.map +0 -1
  140. package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts +0 -4
  141. package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts.map +0 -1
  142. package/src/_types/core/EVM/permits/utils.d.ts +0 -6
  143. package/src/_types/core/EVM/permits/utils.d.ts.map +0 -1
  144. package/src/core/EVM/permits/signNativePermitMessage.ts +0 -27
  145. package/src/core/EVM/permits/utils.ts +0 -40
@@ -1,4 +1,4 @@
1
- import type { ExtendedChain, LiFiStep, SignedPermit } from '@lifi/types'
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 { estimateGas, getAddresses, sendTransaction } from 'viem/actions'
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, EVMPermitStep, TransactionMethodType } from './types.js'
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 nativePermitSignature: NativePermitSignature | undefined
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
- nativePermitSignature = allowanceResult.data
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 && !nativePermitSignature && permit2Supported
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 | EVMPermitStep
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.quote,
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.permits.find(
451
- (p) => p.permitType === 'PermitWitnessTransferFrom'
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 permit2Signature = await signPermit2Message({
462
- client: this.client,
463
- chain: fromChain,
464
- tokenAddress: step.action.fromToken.address as Address,
465
- amount: BigInt(step.action.fromAmount),
466
- data: transactionRequest.data as Hex,
467
- permitData: prettifyPermit2Data(
468
- permitWitnessTransferFromData.permitData
469
- ),
470
- witness: true,
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 signedPermits: SignedPermit[] = [
484
+ const signedTypedData: SignedTypedData[] = [
483
485
  {
484
- permitType: 'PermitWitnessTransferFrom',
485
- permit: permit2Signature.values,
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 (nativePermitSignature) {
491
- signedPermits.unshift({
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
- tokenOwner: this.client.account!.address,
500
- chainId: fromChain.id,
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 (nativePermitSignature) {
502
+ if (signedNativePermitTypedData) {
508
503
  transactionRequest.data = encodeNativePermitData(
509
504
  step.action.fromToken.address as Address,
510
505
  BigInt(step.action.fromAmount),
511
- nativePermitSignature.values.deadline,
512
- nativePermitSignature.signature,
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.values.nonce,
535
- permit2Signature.values.deadline,
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 (nativePermitSignature || permit2Supported) {
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 { signNativePermitMessage } from './permits/signNativePermitMessage.js'
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: NativePermitSignature
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
- const permitData = step.permits.find(
101
- (p) => p.permitType === 'Permit'
102
- )?.permitData
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 nativePermitSignature = await signNativePermitMessage(
122
+ const signature = await getAction(
127
123
  client,
128
- nativePermitData
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 { status: 'NATIVE_PERMIT', data: nativePermitSignature }
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(client, chain, tokenAddress, amount)
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(client, chain, tokenAddress, amount)
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
- values: PermitSingle
38
+ message: PermitSingle
39
39
  }
40
40
 
41
41
  export type PermitBatchData = {
42
42
  domain: TypedDataDomain
43
43
  types: TypedData
44
- values: PermitBatch
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
- values: permit,
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
- values: permit,
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
- values: permit,
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
- values: permit,
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, values } = getPermitSingleData(
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: values,
148
+ message: message,
149
149
  })
150
150
  }
151
- const { domain, values } = getPermitBatchData(permit, permit2Address, chainId)
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: values,
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
- chain: ExtendedChain,
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(chain.id)
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(chain.id),
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 values = {
209
+ const message = {
210
210
  owner: client.account!.address,
211
- spender: chain.permit2Proxy as Address,
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
- values,
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(chain.id),
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 values = {
258
+ const message = {
258
259
  owner: client.account!.address,
259
- spender: chain.permit2Proxy as Address,
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
- values,
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: SignPermit2SingleParams | SignPermit2BatchParams
41
- ): Promise<Permit2Signature<PermitTransferFrom | PermitBatchTransferFrom>> {
42
- const { client, chain, tokenAddress, amount, data, permitData, witness } =
43
- params
19
+ params: SignPermit2MessageParams
20
+ ): Promise<SignedTypedData> {
21
+ const { client, chain, tokenAddress, amount, data, witness } = params
44
22
 
45
- let _permitData = permitData
46
- if (!_permitData) {
47
- const permitTransferFrom = await getPermitTransferFromValues(
48
- client,
49
- chain,
50
- tokenAddress,
51
- amount
52
- )
23
+ const permitTransferFrom = await getPermitTransferFromValues(
24
+ client,
25
+ chain,
26
+ tokenAddress,
27
+ amount
28
+ )
53
29
 
54
- // Create witness data for the LI.FI call
55
- const _witness = witness
56
- ? {
57
- witness: {
58
- diamondAddress: chain.diamondAddress as Address,
59
- diamondCalldataHash: keccak256(data),
60
- },
61
- witnessTypeName: 'LiFiCall',
62
- witnessType: {
63
- LiFiCall: [
64
- { name: 'diamondAddress', type: 'address' },
65
- { name: 'diamondCalldataHash', type: 'bytes32' },
66
- ],
67
- },
68
- }
69
- : undefined
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
- _permitData = getPermitData(
72
- permitTransferFrom,
73
- chain.permit2 as Address,
74
- chain.id,
75
- _witness
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: witness ? 'PermitWitnessTransferFrom' : 'PermitTransferFrom',
86
- domain: _permitData.domain,
87
- types: _permitData.types,
88
- message: _permitData.values,
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
- values: PermitTransferFrom
39
+ message: PermitTransferFrom
40
40
  }
41
41
 
42
42
  export type PermitBatchTransferFromData = {
43
43
  domain: TypedDataDomain
44
44
  types: TypedData
45
- values: PermitBatchTransferFrom
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 values = witness
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
- values,
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 values = witness
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
- values,
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, values } = getPermitTransferData(
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
- ...values,
200
+ ...message,
201
201
  },
202
202
  })
203
203
  }
204
- const { domain, types, values } = getPermitBatchTransferData(
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: { ...values },
217
+ message: { ...message },
218
218
  })
219
219
  }
220
220