@lifi/sdk 3.6.0-beta.5 → 3.6.0-beta.7

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 (261) hide show
  1. package/package.json +3 -3
  2. package/src/_cjs/config.js +3 -0
  3. package/src/_cjs/config.js.map +1 -1
  4. package/src/_cjs/core/EVM/EVM.js +4 -0
  5. package/src/_cjs/core/EVM/EVM.js.map +1 -1
  6. package/src/_cjs/core/EVM/EVMStepExecutor.js +138 -111
  7. package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
  8. package/src/_cjs/core/EVM/checkAllowance.js +34 -5
  9. package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
  10. package/src/_cjs/core/EVM/checkPermitSupport.js +33 -0
  11. package/src/_cjs/core/EVM/checkPermitSupport.js.map +1 -0
  12. package/src/_cjs/core/EVM/parseEVMErrors.js +3 -0
  13. package/src/_cjs/core/EVM/parseEVMErrors.js.map +1 -1
  14. package/src/_cjs/core/EVM/{permit2 → permits}/allowanceTransfer.js.map +1 -1
  15. package/src/_cjs/core/EVM/{permit2 → permits}/constants.js.map +1 -1
  16. package/src/_cjs/core/EVM/{permit2 → permits}/domain.js.map +1 -1
  17. package/src/_cjs/core/EVM/permits/encodeNativePermitData.js +16 -0
  18. package/src/_cjs/core/EVM/permits/encodeNativePermitData.js.map +1 -0
  19. package/src/_cjs/core/EVM/permits/encodePermit2Data.js +32 -0
  20. package/src/_cjs/core/EVM/permits/encodePermit2Data.js.map +1 -0
  21. package/src/_cjs/core/EVM/{getNativePermit.js → permits/getNativePermit.js} +30 -21
  22. package/src/_cjs/core/EVM/permits/getNativePermit.js.map +1 -0
  23. package/src/_cjs/core/EVM/permits/getPermitTransferFromValues.js +24 -0
  24. package/src/_cjs/core/EVM/permits/getPermitTransferFromValues.js.map +1 -0
  25. package/src/_cjs/core/EVM/permits/signNativePermitMessage.js +20 -0
  26. package/src/_cjs/core/EVM/permits/signNativePermitMessage.js.map +1 -0
  27. package/src/_cjs/core/EVM/permits/signPermit2Message.js +43 -0
  28. package/src/_cjs/core/EVM/permits/signPermit2Message.js.map +1 -0
  29. package/src/_cjs/core/EVM/permits/signatureTransfer.js.map +1 -0
  30. package/src/_cjs/core/EVM/permits/types.js +3 -0
  31. package/src/_cjs/core/EVM/permits/types.js.map +1 -0
  32. package/src/_cjs/core/EVM/permits/utils.js +31 -0
  33. package/src/_cjs/core/EVM/permits/utils.js.map +1 -0
  34. package/src/_cjs/core/EVM/publicClient.js +32 -33
  35. package/src/_cjs/core/EVM/publicClient.js.map +1 -1
  36. package/src/_cjs/core/EVM/typeguards.js +1 -1
  37. package/src/_cjs/core/EVM/typeguards.js.map +1 -1
  38. package/src/_cjs/core/EVM/types.js.map +1 -1
  39. package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js +3 -2
  40. package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js.map +1 -1
  41. package/src/_cjs/core/EVM/waitForRelayedTransactionReceipt.js +4 -4
  42. package/src/_cjs/core/EVM/waitForRelayedTransactionReceipt.js.map +1 -1
  43. package/src/_cjs/core/Solana/SolanaStepExecutor.js +1 -0
  44. package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
  45. package/src/_cjs/core/UTXO/getUTXOBalance.js +1 -3
  46. package/src/_cjs/core/UTXO/getUTXOBalance.js.map +1 -1
  47. package/src/_cjs/core/UTXO/getUTXOPublicClient.js +19 -2
  48. package/src/_cjs/core/UTXO/getUTXOPublicClient.js.map +1 -1
  49. package/src/_cjs/core/checkBalance.js +2 -1
  50. package/src/_cjs/core/checkBalance.js.map +1 -1
  51. package/src/_cjs/core/prepareRestart.js +1 -1
  52. package/src/_cjs/core/prepareRestart.js.map +1 -1
  53. package/src/_cjs/core/utils.js +2 -1
  54. package/src/_cjs/core/utils.js.map +1 -1
  55. package/src/_cjs/errors/constants.js +1 -0
  56. package/src/_cjs/errors/constants.js.map +1 -1
  57. package/src/_cjs/services/api.js +18 -6
  58. package/src/_cjs/services/api.js.map +1 -1
  59. package/src/_cjs/version.js +1 -1
  60. package/src/_esm/config.js +3 -0
  61. package/src/_esm/config.js.map +1 -1
  62. package/src/_esm/core/EVM/EVM.js +4 -0
  63. package/src/_esm/core/EVM/EVM.js.map +1 -1
  64. package/src/_esm/core/EVM/EVMStepExecutor.js +142 -123
  65. package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
  66. package/src/_esm/core/EVM/checkAllowance.js +35 -5
  67. package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
  68. package/src/_esm/core/EVM/checkPermitSupport.js +43 -0
  69. package/src/_esm/core/EVM/checkPermitSupport.js.map +1 -0
  70. package/src/_esm/core/EVM/parseEVMErrors.js +9 -0
  71. package/src/_esm/core/EVM/parseEVMErrors.js.map +1 -1
  72. package/src/_esm/core/EVM/{permit2 → permits}/allowanceTransfer.js.map +1 -1
  73. package/src/_esm/core/EVM/{permit2 → permits}/constants.js.map +1 -1
  74. package/src/_esm/core/EVM/{permit2 → permits}/domain.js.map +1 -1
  75. package/src/_esm/core/EVM/permits/encodeNativePermitData.js +12 -0
  76. package/src/_esm/core/EVM/permits/encodeNativePermitData.js.map +1 -0
  77. package/src/_esm/core/EVM/permits/encodePermit2Data.js +28 -0
  78. package/src/_esm/core/EVM/permits/encodePermit2Data.js.map +1 -0
  79. package/src/_esm/core/EVM/{getNativePermit.js → permits/getNativePermit.js} +30 -21
  80. package/src/_esm/core/EVM/permits/getNativePermit.js.map +1 -0
  81. package/src/_esm/core/EVM/permits/getPermitTransferFromValues.js +20 -0
  82. package/src/_esm/core/EVM/permits/getPermitTransferFromValues.js.map +1 -0
  83. package/src/_esm/core/EVM/permits/signNativePermitMessage.js +16 -0
  84. package/src/_esm/core/EVM/permits/signNativePermitMessage.js.map +1 -0
  85. package/src/_esm/core/EVM/permits/signPermit2Message.js +41 -0
  86. package/src/_esm/core/EVM/permits/signPermit2Message.js.map +1 -0
  87. package/src/_esm/core/EVM/{permit2 → permits}/signatureTransfer.js +0 -2
  88. package/src/_esm/core/EVM/{permit2 → permits}/signatureTransfer.js.map +1 -1
  89. package/src/_esm/core/EVM/permits/types.js +2 -0
  90. package/src/_esm/core/EVM/permits/types.js.map +1 -0
  91. package/src/_esm/core/EVM/permits/utils.js +26 -0
  92. package/src/_esm/core/EVM/permits/utils.js.map +1 -0
  93. package/src/_esm/core/EVM/publicClient.js +34 -35
  94. package/src/_esm/core/EVM/publicClient.js.map +1 -1
  95. package/src/_esm/core/EVM/typeguards.js +1 -1
  96. package/src/_esm/core/EVM/typeguards.js.map +1 -1
  97. package/src/_esm/core/EVM/types.js.map +1 -1
  98. package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js +5 -2
  99. package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js.map +1 -1
  100. package/src/_esm/core/EVM/waitForRelayedTransactionReceipt.js +4 -4
  101. package/src/_esm/core/EVM/waitForRelayedTransactionReceipt.js.map +1 -1
  102. package/src/_esm/core/Solana/SolanaStepExecutor.js +1 -0
  103. package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
  104. package/src/_esm/core/UTXO/getUTXOBalance.js +1 -3
  105. package/src/_esm/core/UTXO/getUTXOBalance.js.map +1 -1
  106. package/src/_esm/core/UTXO/getUTXOPublicClient.js +20 -3
  107. package/src/_esm/core/UTXO/getUTXOPublicClient.js.map +1 -1
  108. package/src/_esm/core/checkBalance.js +2 -1
  109. package/src/_esm/core/checkBalance.js.map +1 -1
  110. package/src/_esm/core/prepareRestart.js +1 -1
  111. package/src/_esm/core/prepareRestart.js.map +1 -1
  112. package/src/_esm/core/utils.js +2 -1
  113. package/src/_esm/core/utils.js.map +1 -1
  114. package/src/_esm/errors/constants.js +1 -0
  115. package/src/_esm/errors/constants.js.map +1 -1
  116. package/src/_esm/services/api.js +18 -6
  117. package/src/_esm/services/api.js.map +1 -1
  118. package/src/_esm/version.js +1 -1
  119. package/src/_types/config.d.ts +2 -1
  120. package/src/_types/config.d.ts.map +1 -1
  121. package/src/_types/core/BaseStepExecutor.d.ts.map +1 -1
  122. package/src/_types/core/EVM/EVM.d.ts.map +1 -1
  123. package/src/_types/core/EVM/EVMStepExecutor.d.ts +4 -10
  124. package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
  125. package/src/_types/core/EVM/checkAllowance.d.ts +13 -2
  126. package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
  127. package/src/_types/core/EVM/checkPermitSupport.d.ts +27 -0
  128. package/src/_types/core/EVM/checkPermitSupport.d.ts.map +1 -0
  129. package/src/_types/core/EVM/getAllowance.d.ts.map +1 -1
  130. package/src/_types/core/EVM/getENSAddress.d.ts.map +1 -1
  131. package/src/_types/core/EVM/getEVMBalance.d.ts.map +1 -1
  132. package/src/_types/core/EVM/parseEVMErrors.d.ts.map +1 -1
  133. package/src/_types/core/EVM/{permit2 → permits}/allowanceTransfer.d.ts.map +1 -1
  134. package/src/_types/core/EVM/{permit2 → permits}/constants.d.ts.map +1 -1
  135. package/src/_types/core/EVM/permits/domain.d.ts +3 -0
  136. package/src/_types/core/EVM/permits/domain.d.ts.map +1 -0
  137. package/src/_types/core/EVM/permits/encodeNativePermitData.d.ts +3 -0
  138. package/src/_types/core/EVM/permits/encodeNativePermitData.d.ts.map +1 -0
  139. package/src/_types/core/EVM/permits/encodePermit2Data.d.ts +4 -0
  140. package/src/_types/core/EVM/permits/encodePermit2Data.d.ts.map +1 -0
  141. package/src/_types/core/EVM/{getNativePermit.d.ts → permits/getNativePermit.d.ts} +2 -9
  142. package/src/_types/core/EVM/permits/getNativePermit.d.ts.map +1 -0
  143. package/src/_types/core/EVM/permits/getPermitTransferFromValues.d.ts +5 -0
  144. package/src/_types/core/EVM/permits/getPermitTransferFromValues.d.ts.map +1 -0
  145. package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts +4 -0
  146. package/src/_types/core/EVM/permits/signNativePermitMessage.d.ts.map +1 -0
  147. package/src/_types/core/EVM/permits/signPermit2Message.d.ts +21 -0
  148. package/src/_types/core/EVM/permits/signPermit2Message.d.ts.map +1 -0
  149. package/src/_types/core/EVM/{permit2 → permits}/signatureTransfer.d.ts +15 -16
  150. package/src/_types/core/EVM/permits/signatureTransfer.d.ts.map +1 -0
  151. package/src/_types/core/EVM/permits/types.d.ts +24 -0
  152. package/src/_types/core/EVM/permits/types.d.ts.map +1 -0
  153. package/src/_types/core/EVM/permits/utils.d.ts +6 -0
  154. package/src/_types/core/EVM/permits/utils.d.ts.map +1 -0
  155. package/src/_types/core/EVM/publicClient.d.ts.map +1 -1
  156. package/src/_types/core/EVM/setAllowance.d.ts.map +1 -1
  157. package/src/_types/core/EVM/switchChain.d.ts.map +1 -1
  158. package/src/_types/core/EVM/typeguards.d.ts +2 -1
  159. package/src/_types/core/EVM/typeguards.d.ts.map +1 -1
  160. package/src/_types/core/EVM/types.d.ts +13 -7
  161. package/src/_types/core/EVM/types.d.ts.map +1 -1
  162. package/src/_types/core/EVM/utils.d.ts.map +1 -1
  163. package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts.map +1 -1
  164. package/src/_types/core/EVM/waitForRelayedTransactionReceipt.d.ts.map +1 -1
  165. package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
  166. package/src/_types/core/Solana/getSNSAddress.d.ts.map +1 -1
  167. package/src/_types/core/Solana/getSolanaBalance.d.ts.map +1 -1
  168. package/src/_types/core/Solana/parseSolanaErrors.d.ts.map +1 -1
  169. package/src/_types/core/StatusManager.d.ts.map +1 -1
  170. package/src/_types/core/UTXO/UTXOStepExecutor.d.ts.map +1 -1
  171. package/src/_types/core/UTXO/getUTXOBalance.d.ts.map +1 -1
  172. package/src/_types/core/UTXO/getUTXOPublicClient.d.ts +2 -3
  173. package/src/_types/core/UTXO/getUTXOPublicClient.d.ts.map +1 -1
  174. package/src/_types/core/UTXO/parseUTXOErrors.d.ts.map +1 -1
  175. package/src/_types/core/checkBalance.d.ts.map +1 -1
  176. package/src/_types/core/execution.d.ts.map +1 -1
  177. package/src/_types/core/prepareRestart.d.ts.map +1 -1
  178. package/src/_types/core/provider.d.ts.map +1 -1
  179. package/src/_types/core/rpc.d.ts.map +1 -1
  180. package/src/_types/core/stepComparison.d.ts.map +1 -1
  181. package/src/_types/core/utils.d.ts.map +1 -1
  182. package/src/_types/errors/constants.d.ts +2 -1
  183. package/src/_types/errors/constants.d.ts.map +1 -1
  184. package/src/_types/errors/utils/baseErrorRootCause.d.ts.map +1 -1
  185. package/src/_types/errors/utils/rootCause.d.ts.map +1 -1
  186. package/src/_types/request.d.ts.map +1 -1
  187. package/src/_types/services/api.d.ts +4 -47
  188. package/src/_types/services/api.d.ts.map +1 -1
  189. package/src/_types/services/balance.d.ts.map +1 -1
  190. package/src/_types/services/getNameServiceAddress.d.ts.map +1 -1
  191. package/src/_types/typeguards.d.ts.map +1 -1
  192. package/src/_types/utils/checkPackageUpdates.d.ts.map +1 -1
  193. package/src/_types/utils/convertQuoteToRoute.d.ts.map +1 -1
  194. package/src/_types/utils/fetchTxErrorDetails.d.ts.map +1 -1
  195. package/src/_types/utils/getTransactionMessage.d.ts.map +1 -1
  196. package/src/_types/utils/isZeroAddress.d.ts.map +1 -1
  197. package/src/_types/utils/median.d.ts.map +1 -1
  198. package/src/_types/utils/waitForResult.d.ts.map +1 -1
  199. package/src/_types/version.d.ts +1 -1
  200. package/src/config.ts +4 -1
  201. package/src/core/EVM/EVM.ts +4 -0
  202. package/src/core/EVM/EVMStepExecutor.ts +188 -148
  203. package/src/core/EVM/checkAllowance.ts +69 -6
  204. package/src/core/EVM/checkPermitSupport.ts +74 -0
  205. package/src/core/EVM/parseEVMErrors.ts +9 -0
  206. package/src/core/EVM/{permit2 → permits}/domain.ts +1 -7
  207. package/src/core/EVM/permits/encodeNativePermitData.ts +19 -0
  208. package/src/core/EVM/permits/encodePermit2Data.ts +41 -0
  209. package/src/core/EVM/{getNativePermit.ts → permits/getNativePermit.ts} +37 -31
  210. package/src/core/EVM/permits/getPermitTransferFromValues.ts +29 -0
  211. package/src/core/EVM/permits/signNativePermitMessage.ts +27 -0
  212. package/src/core/EVM/permits/signPermit2Message.ts +95 -0
  213. package/src/core/EVM/{permit2 → permits}/signatureTransfer.ts +19 -7
  214. package/src/core/EVM/permits/types.ts +33 -0
  215. package/src/core/EVM/permits/utils.ts +40 -0
  216. package/src/core/EVM/publicClient.ts +41 -38
  217. package/src/core/EVM/typeguards.ts +5 -2
  218. package/src/core/EVM/types.ts +15 -10
  219. package/src/core/EVM/waitForBatchTransactionReceipt.ts +7 -2
  220. package/src/core/EVM/waitForRelayedTransactionReceipt.ts +4 -4
  221. package/src/core/Solana/SolanaStepExecutor.ts +1 -0
  222. package/src/core/UTXO/getUTXOBalance.ts +1 -3
  223. package/src/core/UTXO/getUTXOPublicClient.ts +24 -7
  224. package/src/core/checkBalance.ts +2 -1
  225. package/src/core/prepareRestart.ts +1 -1
  226. package/src/core/utils.ts +3 -1
  227. package/src/errors/constants.ts +1 -0
  228. package/src/services/api.ts +62 -66
  229. package/src/version.ts +1 -1
  230. package/src/_cjs/core/EVM/getNativePermit.js.map +0 -1
  231. package/src/_cjs/core/EVM/permit2/signatureTransfer.js.map +0 -1
  232. package/src/_cjs/core/EVM/signPermitMessage.js +0 -163
  233. package/src/_cjs/core/EVM/signPermitMessage.js.map +0 -1
  234. package/src/_cjs/core/UTXO/getUTXOAPIPublicClient.js +0 -48
  235. package/src/_cjs/core/UTXO/getUTXOAPIPublicClient.js.map +0 -1
  236. package/src/_esm/core/EVM/getNativePermit.js.map +0 -1
  237. package/src/_esm/core/EVM/signPermitMessage.js +0 -157
  238. package/src/_esm/core/EVM/signPermitMessage.js.map +0 -1
  239. package/src/_esm/core/UTXO/getUTXOAPIPublicClient.js +0 -50
  240. package/src/_esm/core/UTXO/getUTXOAPIPublicClient.js.map +0 -1
  241. package/src/_types/core/EVM/getNativePermit.d.ts.map +0 -1
  242. package/src/_types/core/EVM/permit2/domain.d.ts +0 -8
  243. package/src/_types/core/EVM/permit2/domain.d.ts.map +0 -1
  244. package/src/_types/core/EVM/permit2/signatureTransfer.d.ts.map +0 -1
  245. package/src/_types/core/EVM/signPermitMessage.d.ts +0 -25
  246. package/src/_types/core/EVM/signPermitMessage.d.ts.map +0 -1
  247. package/src/_types/core/UTXO/getUTXOAPIPublicClient.d.ts +0 -10
  248. package/src/_types/core/UTXO/getUTXOAPIPublicClient.d.ts.map +0 -1
  249. package/src/core/EVM/signPermitMessage.ts +0 -273
  250. package/src/core/UTXO/getUTXOAPIPublicClient.ts +0 -71
  251. /package/src/_cjs/core/EVM/{permit2 → permits}/allowanceTransfer.js +0 -0
  252. /package/src/_cjs/core/EVM/{permit2 → permits}/constants.js +0 -0
  253. /package/src/_cjs/core/EVM/{permit2 → permits}/domain.js +0 -0
  254. /package/src/_cjs/core/EVM/{permit2 → permits}/signatureTransfer.js +0 -0
  255. /package/src/_esm/core/EVM/{permit2 → permits}/allowanceTransfer.js +0 -0
  256. /package/src/_esm/core/EVM/{permit2 → permits}/constants.js +0 -0
  257. /package/src/_esm/core/EVM/{permit2 → permits}/domain.js +0 -0
  258. /package/src/_types/core/EVM/{permit2 → permits}/allowanceTransfer.d.ts +0 -0
  259. /package/src/_types/core/EVM/{permit2 → permits}/constants.d.ts +0 -0
  260. /package/src/core/EVM/{permit2 → permits}/allowanceTransfer.ts +0 -0
  261. /package/src/core/EVM/{permit2 → permits}/constants.ts +0 -0
@@ -1,4 +1,4 @@
1
- import type { ExtendedChain, LiFiStep } from '@lifi/types'
1
+ import type { ExtendedChain, LiFiStep, SignedPermit } from '@lifi/types'
2
2
  import type {
3
3
  Address,
4
4
  Client,
@@ -31,11 +31,15 @@ import type {
31
31
  } from '../types.js'
32
32
  import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction.js'
33
33
  import { checkAllowance } from './checkAllowance.js'
34
- import { getNativePermit } from './getNativePermit.js'
35
34
  import { parseEVMErrors } from './parseEVMErrors.js'
36
- import { type PermitSignature, signPermitMessage } from './signPermitMessage.js'
35
+ import { encodeNativePermitData } from './permits/encodeNativePermitData.js'
36
+ import { encodePermit2Data } from './permits/encodePermit2Data.js'
37
+ import { signPermit2Message } from './permits/signPermit2Message.js'
38
+ import type { NativePermitSignature } from './permits/types.js'
39
+ import { prettifyPermit2Data } from './permits/utils.js'
37
40
  import { switchChain } from './switchChain.js'
38
41
  import { isRelayerStep } from './typeguards.js'
42
+ import type { Call, EVMPermitStep, TransactionMethodType } from './types.js'
39
43
  import { convertExtendedChain, getMaxPriorityFeePerGas } from './utils.js'
40
44
  import {
41
45
  type WalletCallReceipt,
@@ -44,13 +48,6 @@ import {
44
48
  import { waitForRelayedTransactionReceipt } from './waitForRelayedTransactionReceipt.js'
45
49
  import { waitForTransactionReceipt } from './waitForTransactionReceipt.js'
46
50
 
47
- export type Call = {
48
- data?: Hex
49
- to?: Address
50
- value?: bigint
51
- chainId?: number
52
- }
53
-
54
51
  export interface EVMStepExecutorOptions extends StepExecutorOptions {
55
52
  client: Client
56
53
  }
@@ -123,8 +120,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
123
120
  process,
124
121
  fromChain,
125
122
  toChain,
126
- atomicBatchSupported,
127
- isRelayerTransaction,
123
+ txType,
128
124
  txHash,
129
125
  isBridgeExecution,
130
126
  }: {
@@ -132,32 +128,34 @@ export class EVMStepExecutor extends BaseStepExecutor {
132
128
  process: Process
133
129
  fromChain: ExtendedChain
134
130
  toChain: ExtendedChain
135
- atomicBatchSupported: boolean
136
- isRelayerTransaction: boolean
131
+ txType: TransactionMethodType
137
132
  txHash: Hash
138
133
  isBridgeExecution: boolean
139
134
  }) => {
140
135
  let transactionReceipt: TransactionReceipt | WalletCallReceipt | undefined
141
136
 
142
- if (atomicBatchSupported) {
143
- transactionReceipt = await waitForBatchTransactionReceipt(
144
- this.client,
145
- txHash
146
- )
147
- } else if (isRelayerTransaction) {
148
- transactionReceipt = await waitForRelayedTransactionReceipt(txHash)
149
- } else {
150
- transactionReceipt = await waitForTransactionReceipt({
151
- client: this.client,
152
- chainId: fromChain.id,
153
- txHash,
154
- onReplaced: (response) => {
155
- this.statusManager.updateProcess(step, process.type, 'PENDING', {
156
- txHash: response.transaction.hash,
157
- txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.hash}`,
158
- })
159
- },
160
- })
137
+ switch (txType) {
138
+ case 'batched':
139
+ transactionReceipt = await waitForBatchTransactionReceipt(
140
+ this.client,
141
+ txHash
142
+ )
143
+ break
144
+ case 'relayed':
145
+ transactionReceipt = await waitForRelayedTransactionReceipt(txHash)
146
+ break
147
+ default:
148
+ transactionReceipt = await waitForTransactionReceipt({
149
+ client: this.client,
150
+ chainId: fromChain.id,
151
+ txHash,
152
+ onReplaced: (response) => {
153
+ this.statusManager.updateProcess(step, process.type, 'PENDING', {
154
+ txHash: response.transaction.hash,
155
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.hash}`,
156
+ })
157
+ },
158
+ })
161
159
  }
162
160
 
163
161
  // Update pending process if the transaction hash from the receipt is different.
@@ -241,44 +239,23 @@ export class EVMStepExecutor extends BaseStepExecutor {
241
239
  // Check if step requires permit signature and will be used with relayer service
242
240
  const isRelayerTransaction = isRelayerStep(step)
243
241
 
244
- // Check if token requires approval
245
- // Native tokens (like ETH) don't need approval since they're not ERC20 tokens
246
- // We should support different permit types:
247
- // 1. Native permits (EIP-2612)
248
- // 2. Permit2 - Universal permit implementation by Uniswap (limited to certain chains)
249
- // 3. Standard ERC20 approval
250
- const nativePermit = await getNativePermit(
251
- this.client,
252
- fromChain,
253
- step.action.fromToken.address as Address
254
- )
255
- // Check if proxy contract is available and token supports native permits, not available for atomic batch
256
- const nativePermitSupported =
257
- nativePermit.supported &&
258
- !!fromChain.permit2Proxy &&
259
- !atomicBatchSupported &&
260
- !isRelayerTransaction && // TODO: remove once we support ERC-2771
261
- !isFromNativeToken
262
242
  // Check if chain has Permit2 contract deployed. Permit2 should not be available for atomic batch.
263
243
  const permit2Supported =
264
244
  !!fromChain.permit2 &&
265
245
  !!fromChain.permit2Proxy &&
266
246
  !atomicBatchSupported &&
267
247
  !isFromNativeToken
268
- // Token supports either native permits or Permit2
269
- const permitSupported = permit2Supported || nativePermitSupported
270
248
 
271
249
  const checkForAllowance =
272
- // No existing swap/bridgetransaction is pending
250
+ // No existing swap/bridge transaction is pending
273
251
  !existingProcess?.txHash &&
274
252
  // Token is not native (address is not zero)
275
- !isFromNativeToken &&
276
- // Token doesn't support native permits
277
- !nativePermitSupported
253
+ !isFromNativeToken
278
254
 
255
+ let nativePermitSignature: NativePermitSignature | undefined
279
256
  if (checkForAllowance) {
280
257
  // Check if token needs approval and get approval transaction or message data when available
281
- const data = await checkAllowance({
258
+ const allowanceResult = await checkAllowance({
282
259
  client: this.client,
283
260
  chain: fromChain,
284
261
  step,
@@ -289,17 +266,22 @@ export class EVMStepExecutor extends BaseStepExecutor {
289
266
  permit2Supported,
290
267
  })
291
268
 
292
- if (data) {
269
+ if (allowanceResult.status === 'BATCH_APPROVAL') {
293
270
  // Create approval transaction call
294
271
  // No value needed since we're only approving ERC20 tokens
295
272
  if (atomicBatchSupported) {
296
- calls.push({
297
- chainId: step.action.fromToken.chainId,
298
- to: step.action.fromToken.address as Address,
299
- data,
300
- })
273
+ calls.push(allowanceResult.data)
301
274
  }
302
275
  }
276
+ if (allowanceResult.status === 'NATIVE_PERMIT') {
277
+ nativePermitSignature = allowanceResult.data
278
+ }
279
+ if (
280
+ allowanceResult.status === 'ACTION_REQUIRED' &&
281
+ !this.allowUserInteraction
282
+ ) {
283
+ return step
284
+ }
303
285
  }
304
286
 
305
287
  let process = this.statusManager.findProcess(step, currentProcessType)
@@ -326,14 +308,14 @@ export class EVMStepExecutor extends BaseStepExecutor {
326
308
 
327
309
  // Wait for exiting transaction
328
310
  const txHash = process.txHash as Hash
311
+ const txType = process.txType as TransactionMethodType
329
312
 
330
313
  await this.waitForTransaction({
331
314
  step,
332
315
  process,
333
316
  fromChain,
334
317
  toChain,
335
- atomicBatchSupported,
336
- isRelayerTransaction,
318
+ txType,
337
319
  txHash,
338
320
  isBridgeExecution,
339
321
  })
@@ -341,10 +323,13 @@ export class EVMStepExecutor extends BaseStepExecutor {
341
323
  return step
342
324
  }
343
325
 
326
+ const permitRequired =
327
+ !atomicBatchSupported && !nativePermitSignature && permit2Supported
344
328
  process = this.statusManager.findOrCreateProcess({
345
329
  step,
346
- type: permitSupported ? 'PERMIT' : currentProcessType,
330
+ type: permitRequired ? 'PERMIT' : currentProcessType,
347
331
  status: 'STARTED',
332
+ chainId: fromChain.id,
348
333
  })
349
334
 
350
335
  // Check balance
@@ -353,7 +338,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
353
338
  // Create new transaction request
354
339
  if (!step.transactionRequest) {
355
340
  const { execution, ...stepBase } = step
356
- let updatedStep: LiFiStep
341
+ let updatedStep: LiFiStep | EVMPermitStep
357
342
  if (isRelayerTransaction) {
358
343
  const updatedRelayedStep = await getRelayerQuote({
359
344
  fromChain: stepBase.action.fromChainId,
@@ -367,8 +352,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
367
352
  allowBridges: [stepBase.tool],
368
353
  })
369
354
  updatedStep = {
370
- ...updatedRelayedStep.data.quote.step,
371
- ...updatedRelayedStep.data.quote,
355
+ ...updatedRelayedStep.quote,
356
+ permits: updatedRelayedStep.permits,
372
357
  id: stepBase.id,
373
358
  }
374
359
  } else {
@@ -448,7 +433,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
448
433
  }
449
434
 
450
435
  let txHash: Hash
451
- let isTransactionRelayed = false
436
+ let txType: TransactionMethodType = 'standard'
452
437
 
453
438
  if (atomicBatchSupported) {
454
439
  const transferCall: Call = {
@@ -468,100 +453,156 @@ export class EVMStepExecutor extends BaseStepExecutor {
468
453
  account: this.client.account!,
469
454
  calls,
470
455
  })) as Address
456
+ txType = 'batched'
457
+ } else if (isRelayerTransaction) {
458
+ const permitWitnessTransferFromData = step.permits.find(
459
+ (p) => p.permitType === 'PermitWitnessTransferFrom'
460
+ )
461
+
462
+ if (!permitWitnessTransferFromData) {
463
+ throw new TransactionError(
464
+ LiFiErrorCode.TransactionUnprepared,
465
+ 'Unable to prepare transaction. Permit data for transfer is not found.'
466
+ )
467
+ }
468
+
469
+ const permit2Signature = await signPermit2Message({
470
+ client: this.client,
471
+ chain: fromChain,
472
+ tokenAddress: step.action.fromToken.address as Address,
473
+ amount: BigInt(step.action.fromAmount),
474
+ data: transactionRequest.data as Hex,
475
+ permitData: prettifyPermit2Data(
476
+ permitWitnessTransferFromData.permitData
477
+ ),
478
+ witness: true,
479
+ })
480
+
481
+ this.statusManager.updateProcess(step, process.type, 'DONE')
482
+
483
+ process = this.statusManager.findOrCreateProcess({
484
+ step,
485
+ type: currentProcessType,
486
+ status: 'PENDING',
487
+ chainId: fromChain.id,
488
+ })
489
+
490
+ const signedPermits: SignedPermit[] = [
491
+ {
492
+ permitType: 'PermitWitnessTransferFrom',
493
+ permit: permit2Signature.values,
494
+ signature: permit2Signature.signature,
495
+ },
496
+ ]
497
+ // Add native permit if available as first element, order is important
498
+ if (nativePermitSignature) {
499
+ signedPermits.unshift({
500
+ permitType: 'Permit',
501
+ permit: nativePermitSignature.values,
502
+ signature: nativePermitSignature.signature,
503
+ })
504
+ }
505
+
506
+ const relayedTransaction = await relayTransaction({
507
+ tokenOwner: this.client.account!.address,
508
+ chainId: fromChain.id,
509
+ permits: signedPermits,
510
+ callData: transactionRequest.data! as Hex,
511
+ })
512
+ txHash = relayedTransaction.taskId as Hash
513
+ txType = 'relayed'
471
514
  } else {
472
- let permitSignature: PermitSignature | undefined
473
- if (permitSupported) {
474
- permitSignature = await signPermitMessage(this.client, {
475
- transactionRequest,
515
+ if (nativePermitSignature) {
516
+ transactionRequest.data = encodeNativePermitData(
517
+ step.action.fromToken.address as Address,
518
+ BigInt(step.action.fromAmount),
519
+ nativePermitSignature.values.deadline,
520
+ nativePermitSignature.signature,
521
+ transactionRequest.data as Hex
522
+ )
523
+ } else if (permit2Supported) {
524
+ const permit2Signature = await signPermit2Message({
525
+ client: this.client,
476
526
  chain: fromChain,
477
527
  tokenAddress: step.action.fromToken.address as Address,
478
528
  amount: BigInt(step.action.fromAmount),
479
- nativePermit,
480
- permitData: isRelayerTransaction ? step.permitData : undefined,
481
- useWitness: isRelayerTransaction,
529
+ data: transactionRequest.data as Hex,
482
530
  })
483
- transactionRequest.to = fromChain.permit2Proxy
484
531
  this.statusManager.updateProcess(step, process.type, 'DONE')
485
- }
486
- if (isRelayerTransaction && permitSignature) {
532
+
487
533
  process = this.statusManager.findOrCreateProcess({
488
534
  step,
489
535
  type: currentProcessType,
490
536
  status: 'PENDING',
491
- })
492
- const relayedTransaction = await relayTransaction({
493
- tokenOwner: this.client.account!.address,
494
537
  chainId: fromChain.id,
495
- permit: step.permit,
496
- witness: step.witness,
497
- signedPermitData: permitSignature.signature,
498
- callData: transactionRequest.data!,
499
538
  })
500
- txHash = relayedTransaction.data.taskId
501
- isTransactionRelayed = true
502
- } else {
503
- process = this.statusManager.findOrCreateProcess({
504
- step,
505
- type: currentProcessType,
506
- status: 'STARTED',
507
- })
508
- if (permitSignature) {
509
- // If we have a permit signature, we need to use updated data
510
- transactionRequest.data = permitSignature.data
511
- try {
512
- // Try to re-estimate the gas due to additional Permit data
513
- const estimatedGas = await estimateGas(this.client, {
514
- account: this.client.account!,
515
- to: transactionRequest.to as Address,
516
- data: transactionRequest.data as Hex,
517
- value: transactionRequest.value,
518
- })
519
- transactionRequest.gas =
520
- transactionRequest.gas && transactionRequest.gas > estimatedGas
521
- ? transactionRequest.gas
522
- : estimatedGas
523
- } catch {
524
- // Let the wallet estimate the gas in case of failure
525
- transactionRequest.gas = undefined
526
- }
527
- }
528
- process = this.statusManager.updateProcess(
529
- step,
530
- process.type,
531
- 'ACTION_REQUIRED'
539
+ transactionRequest.data = encodePermit2Data(
540
+ step.action.fromToken.address as Address,
541
+ BigInt(step.action.fromAmount),
542
+ permit2Signature.values.nonce,
543
+ permit2Signature.values.deadline,
544
+ transactionRequest.data as Hex,
545
+ permit2Signature.signature
532
546
  )
533
- txHash = await getAction(
534
- this.client,
535
- sendTransaction,
536
- 'sendTransaction'
537
- )({
538
- to: transactionRequest.to as Address,
539
- account: this.client.account!,
540
- data: transactionRequest.data as Hex,
541
- value: transactionRequest.value,
542
- gas: transactionRequest.gas,
543
- gasPrice: transactionRequest.gasPrice,
544
- maxFeePerGas: transactionRequest.maxFeePerGas,
545
- maxPriorityFeePerGas: transactionRequest.maxPriorityFeePerGas,
546
- chain: convertExtendedChain(fromChain),
547
- } as SendTransactionParameters)
548
547
  }
548
+
549
+ if (nativePermitSignature || permit2Supported) {
550
+ try {
551
+ // Target address should be the Permit2 proxy contract in case of native permit or Permit2
552
+ transactionRequest.to = fromChain.permit2Proxy
553
+ // Try to re-estimate the gas due to additional Permit data
554
+ const estimatedGas = await estimateGas(this.client, {
555
+ account: this.client.account!,
556
+ to: transactionRequest.to as Address,
557
+ data: transactionRequest.data as Hex,
558
+ value: transactionRequest.value,
559
+ })
560
+ transactionRequest.gas =
561
+ transactionRequest.gas && transactionRequest.gas > estimatedGas
562
+ ? transactionRequest.gas
563
+ : estimatedGas
564
+ } catch {
565
+ // Let the wallet estimate the gas in case of failure
566
+ transactionRequest.gas = undefined
567
+ } finally {
568
+ this.statusManager.updateProcess(step, process.type, 'DONE')
569
+ }
570
+ }
571
+ process = this.statusManager.updateProcess(
572
+ step,
573
+ process.type,
574
+ 'ACTION_REQUIRED'
575
+ )
576
+ txHash = await getAction(
577
+ this.client,
578
+ sendTransaction,
579
+ 'sendTransaction'
580
+ )({
581
+ to: transactionRequest.to as Address,
582
+ account: this.client.account!,
583
+ data: transactionRequest.data as Hex,
584
+ value: transactionRequest.value,
585
+ gas: transactionRequest.gas,
586
+ gasPrice: transactionRequest.gasPrice,
587
+ maxFeePerGas: transactionRequest.maxFeePerGas,
588
+ maxPriorityFeePerGas: transactionRequest.maxPriorityFeePerGas,
589
+ chain: convertExtendedChain(fromChain),
590
+ } as SendTransactionParameters)
549
591
  }
592
+
550
593
  process = this.statusManager.updateProcess(
551
594
  step,
552
595
  process.type,
553
596
  'PENDING',
554
- // When atomic batch is supported, txHash represents the batch hash rather than an individual transaction hash at this point
555
- atomicBatchSupported
556
- ? {
557
- atomicBatchSupported,
558
- }
559
- : isTransactionRelayed
560
- ? undefined
561
- : {
562
- txHash: txHash,
563
- txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,
564
- }
597
+ // When atomic batch or relayer are supported, txHash represents the batch hash or taskId rather than an individual transaction hash
598
+ {
599
+ txHash,
600
+ txType,
601
+ txLink:
602
+ txType === 'standard'
603
+ ? `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`
604
+ : undefined,
605
+ }
565
606
  )
566
607
 
567
608
  await this.waitForTransaction({
@@ -569,9 +610,8 @@ export class EVMStepExecutor extends BaseStepExecutor {
569
610
  process,
570
611
  fromChain,
571
612
  toChain,
572
- atomicBatchSupported,
573
- isRelayerTransaction,
574
613
  txHash,
614
+ txType,
575
615
  isBridgeExecution,
576
616
  })
577
617
 
@@ -5,7 +5,16 @@ import type { StatusManager } from '../StatusManager.js'
5
5
  import type { ExecutionOptions, Process, ProcessType } from '../types.js'
6
6
  import { getAllowance } from './getAllowance.js'
7
7
  import { parseEVMErrors } from './parseEVMErrors.js'
8
+ 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'
8
15
  import { setAllowance } from './setAllowance.js'
16
+ import { isRelayerStep } from './typeguards.js'
17
+ import type { Call } from './types.js'
9
18
  import { waitForTransactionReceipt } from './waitForTransactionReceipt.js'
10
19
 
11
20
  export type CheckAllowanceParams = {
@@ -19,6 +28,19 @@ export type CheckAllowanceParams = {
19
28
  permit2Supported?: boolean
20
29
  }
21
30
 
31
+ export type AllowanceResult =
32
+ | {
33
+ status: 'ACTION_REQUIRED' | 'DONE'
34
+ }
35
+ | {
36
+ status: 'BATCH_APPROVAL'
37
+ data: Call
38
+ }
39
+ | {
40
+ status: 'NATIVE_PERMIT'
41
+ data: NativePermitSignature
42
+ }
43
+
22
44
  export const checkAllowance = async ({
23
45
  client,
24
46
  chain,
@@ -28,7 +50,7 @@ export const checkAllowance = async ({
28
50
  allowUserInteraction = false,
29
51
  atomicBatchSupported = false,
30
52
  permit2Supported = false,
31
- }: CheckAllowanceParams): Promise<Hash | void> => {
53
+ }: CheckAllowanceParams): Promise<AllowanceResult> => {
32
54
  // Find existing or create new allowance process
33
55
  const allowanceProcess: Process = statusManager.findOrCreateProcess({
34
56
  step,
@@ -47,7 +69,7 @@ export const checkAllowance = async ({
47
69
  chain,
48
70
  statusManager
49
71
  )
50
- return
72
+ return { status: 'DONE' }
51
73
  }
52
74
 
53
75
  // Start new allowance check
@@ -68,15 +90,47 @@ export const checkAllowance = async ({
68
90
  // Return early if already approved
69
91
  if (fromAmount <= approved) {
70
92
  statusManager.updateProcess(step, allowanceProcess.type, 'DONE')
71
- return
93
+ return { status: 'DONE' }
72
94
  }
73
95
 
74
- if (!allowUserInteraction) {
75
- return
96
+ const isRelayerTransaction = isRelayerStep(step)
97
+
98
+ let nativePermitData: NativePermitData | undefined
99
+ if (isRelayerTransaction) {
100
+ const permitData = step.permits.find(
101
+ (p) => p.permitType === 'Permit'
102
+ )?.permitData
103
+ if (permitData) {
104
+ nativePermitData = prettifyNativePermitData(permitData)
105
+ }
106
+ } else {
107
+ nativePermitData = await getNativePermit(
108
+ client,
109
+ chain,
110
+ step.action.fromToken.address as Address,
111
+ fromAmount
112
+ )
76
113
  }
77
114
 
78
115
  statusManager.updateProcess(step, allowanceProcess.type, 'ACTION_REQUIRED')
79
116
 
117
+ if (!allowUserInteraction) {
118
+ return { status: 'ACTION_REQUIRED' }
119
+ }
120
+
121
+ // Check if proxy contract is available and token supports native permits, not available for atomic batch
122
+ const nativePermitSupported =
123
+ !!nativePermitData && !!chain.permit2Proxy && !atomicBatchSupported
124
+
125
+ if (nativePermitSupported && nativePermitData) {
126
+ const nativePermitSignature = await signNativePermitMessage(
127
+ client,
128
+ nativePermitData
129
+ )
130
+ statusManager.updateProcess(step, allowanceProcess.type, 'DONE')
131
+ return { status: 'NATIVE_PERMIT', data: nativePermitSignature }
132
+ }
133
+
80
134
  // Set new allowance
81
135
  const approveAmount = permit2Supported ? MaxUint256 : fromAmount
82
136
  const approveTxHash = await setAllowance(
@@ -90,7 +144,14 @@ export const checkAllowance = async ({
90
144
 
91
145
  if (atomicBatchSupported) {
92
146
  statusManager.updateProcess(step, allowanceProcess.type, 'DONE')
93
- return approveTxHash
147
+ return {
148
+ status: 'BATCH_APPROVAL',
149
+ data: {
150
+ to: step.action.fromToken.address as Address,
151
+ data: approveTxHash,
152
+ chainId: step.action.fromToken.chainId,
153
+ },
154
+ }
94
155
  }
95
156
 
96
157
  await waitForApprovalTransaction(
@@ -101,6 +162,8 @@ export const checkAllowance = async ({
101
162
  chain,
102
163
  statusManager
103
164
  )
165
+
166
+ return { status: 'DONE' }
104
167
  } catch (e: any) {
105
168
  const error = await parseEVMErrors(e, step, allowanceProcess)
106
169
  statusManager.updateProcess(step, allowanceProcess.type, 'FAILED', {
@@ -0,0 +1,74 @@
1
+ import type { ExtendedChain } from '@lifi/types'
2
+ import { ChainType } from '@lifi/types'
3
+ import type { Address } from 'viem'
4
+ import { config } from '../../config.js'
5
+ import { getAllowance } from './getAllowance.js'
6
+ import { getNativePermit } from './permits/getNativePermit.js'
7
+ import type { NativePermitData } from './permits/types.js'
8
+ import { getPublicClient } from './publicClient.js'
9
+ import type { EVMProvider } from './types.js'
10
+
11
+ export type PermitSupport = {
12
+ /** Whether the token supports EIP-2612 native permits */
13
+ nativePermitSupported: boolean
14
+ /** Whether Permit2 is available and has sufficient allowance */
15
+ permit2AllowanceSufficient: boolean
16
+ }
17
+
18
+ /**
19
+ * Checks what permit types are supported for a token on a specific chain.
20
+ * Checks in order:
21
+ * 1. Native permit (EIP-2612) support
22
+ * 2. Permit2 availability and allowance
23
+ *
24
+ * @param chain - The chain to check permit support on
25
+ * @param tokenAddress - The token address to check
26
+ * @param ownerAddress - The address that would sign the permit
27
+ * @param amount - The amount to check allowance against for Permit2
28
+ * @returns Object indicating which permit types are supported
29
+ */
30
+ export const checkPermitSupport = async ({
31
+ chain,
32
+ tokenAddress,
33
+ ownerAddress,
34
+ amount,
35
+ }: {
36
+ chain: ExtendedChain
37
+ tokenAddress: Address
38
+ ownerAddress: Address
39
+ amount: bigint
40
+ }): Promise<PermitSupport> => {
41
+ const provider = config.getProvider(ChainType.EVM) as EVMProvider | undefined
42
+
43
+ let client = await provider?.getWalletClient?.()
44
+
45
+ if (!client) {
46
+ client = await getPublicClient(chain.id)
47
+ }
48
+
49
+ let nativePermit: NativePermitData | undefined
50
+ // Try with wallet client first, fallback to public client
51
+ try {
52
+ nativePermit = await getNativePermit(client, chain, tokenAddress, amount)
53
+ } catch {
54
+ client = await getPublicClient(chain.id)
55
+ nativePermit = await getNativePermit(client, chain, tokenAddress, amount)
56
+ }
57
+
58
+ let permit2Allowance: bigint | undefined
59
+ // Check Permit2 allowance if available on chain
60
+ if (chain.permit2) {
61
+ permit2Allowance = await getAllowance(
62
+ chain.id,
63
+ tokenAddress,
64
+ ownerAddress,
65
+ chain.permit2 as Address
66
+ )
67
+ }
68
+
69
+ return {
70
+ nativePermitSupported: !!nativePermit,
71
+ permit2AllowanceSufficient:
72
+ !!permit2Allowance && permit2Allowance >= amount,
73
+ }
74
+ }