0xtrails 0.2.4 → 0.2.6

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 (212) hide show
  1. package/dist/aave.d.ts +8 -0
  2. package/dist/aave.d.ts.map +1 -1
  3. package/dist/abortController.d.ts +8 -0
  4. package/dist/abortController.d.ts.map +1 -0
  5. package/dist/{ccip-BlV1Mry3.js → ccip-Xjh9d1gb.js} +7 -7
  6. package/dist/config.d.ts +1 -1
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/constants.d.ts +3 -0
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/error.d.ts +1 -0
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/estimate.d.ts +52 -0
  13. package/dist/estimate.d.ts.map +1 -1
  14. package/dist/fees.d.ts +19 -0
  15. package/dist/fees.d.ts.map +1 -0
  16. package/dist/{index-BNWCIGfQ.js → index-BnhdZ8Ho.js} +76406 -75798
  17. package/dist/index.js +726 -520
  18. package/dist/intents.d.ts +40 -0
  19. package/dist/intents.d.ts.map +1 -1
  20. package/dist/metaTxnMonitor.d.ts +3 -3
  21. package/dist/metaTxnMonitor.d.ts.map +1 -1
  22. package/dist/metaTxns.d.ts +3 -3
  23. package/dist/metaTxns.d.ts.map +1 -1
  24. package/dist/morpho.d.ts +8 -0
  25. package/dist/morpho.d.ts.map +1 -1
  26. package/dist/prepareSend.d.ts +19 -75
  27. package/dist/prepareSend.d.ts.map +1 -1
  28. package/dist/queryParams.d.ts.map +1 -1
  29. package/dist/relayer.d.ts +6 -6
  30. package/dist/relayer.d.ts.map +1 -1
  31. package/dist/sequenceWallet.d.ts +2 -2
  32. package/dist/sequenceWallet.d.ts.map +1 -1
  33. package/dist/tokens.d.ts.map +1 -1
  34. package/dist/transactions.d.ts +4 -2
  35. package/dist/transactions.d.ts.map +1 -1
  36. package/dist/wallets.d.ts.map +1 -1
  37. package/dist/widget/components/AccountActionsDropdown.d.ts.map +1 -1
  38. package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
  39. package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
  40. package/dist/widget/components/AccountSettings.d.ts.map +1 -1
  41. package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
  42. package/dist/widget/components/ClassicSwap.d.ts +4 -2
  43. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  44. package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
  45. package/dist/widget/components/ConnectedWallets.d.ts +4 -0
  46. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
  47. package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
  48. package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
  49. package/dist/widget/components/Earn.d.ts +2 -2
  50. package/dist/widget/components/Earn.d.ts.map +1 -1
  51. package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
  52. package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
  53. package/dist/widget/components/FeeBreakdown.d.ts +9 -0
  54. package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
  55. package/dist/widget/components/Fund.d.ts +2 -2
  56. package/dist/widget/components/Fund.d.ts.map +1 -1
  57. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  58. package/dist/widget/components/{FundSendForm.d.ts → FundSwap.d.ts} +13 -7
  59. package/dist/widget/components/FundSwap.d.ts.map +1 -0
  60. package/dist/widget/components/FundingMethodSelectorButton.d.ts +4 -0
  61. package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -0
  62. package/dist/widget/components/Identicon.d.ts.map +1 -1
  63. package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
  64. package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
  65. package/dist/widget/components/Modal.d.ts.map +1 -1
  66. package/dist/widget/components/Pay.d.ts +2 -2
  67. package/dist/widget/components/Pay.d.ts.map +1 -1
  68. package/dist/widget/components/PercentageMaxButtons.d.ts +12 -0
  69. package/dist/widget/components/PercentageMaxButtons.d.ts.map +1 -0
  70. package/dist/widget/components/{PaySendForm.d.ts → PoolDeposit.d.ts} +14 -36
  71. package/dist/widget/components/PoolDeposit.d.ts.map +1 -0
  72. package/dist/widget/components/{SimpleSwap.d.ts → PoolWithdraw.d.ts} +19 -10
  73. package/dist/widget/components/PoolWithdraw.d.ts.map +1 -0
  74. package/dist/widget/components/QuoteDetails.d.ts +1 -0
  75. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  76. package/dist/widget/components/Receipt.d.ts.map +1 -1
  77. package/dist/widget/components/Receive.d.ts.map +1 -1
  78. package/dist/widget/components/RecipientSelectorButton.d.ts +4 -0
  79. package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -0
  80. package/dist/widget/components/Recipients.d.ts.map +1 -1
  81. package/dist/widget/components/RequiredPropsError.d.ts +8 -0
  82. package/dist/widget/components/RequiredPropsError.d.ts.map +1 -0
  83. package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
  84. package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
  85. package/dist/widget/components/Swap.d.ts +3 -2
  86. package/dist/widget/components/Swap.d.ts.map +1 -1
  87. package/dist/widget/components/SwapSettings.d.ts.map +1 -1
  88. package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
  89. package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
  90. package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
  91. package/dist/widget/components/TokenImage.d.ts +1 -0
  92. package/dist/widget/components/TokenImage.d.ts.map +1 -1
  93. package/dist/widget/components/TokenList.d.ts.map +1 -1
  94. package/dist/widget/components/TokenSelector.d.ts.map +1 -1
  95. package/dist/widget/components/TokenSelectorButton.d.ts +16 -0
  96. package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -0
  97. package/dist/widget/components/Tooltip.d.ts +9 -0
  98. package/dist/widget/components/Tooltip.d.ts.map +1 -0
  99. package/dist/widget/components/UserPreferences.d.ts.map +1 -1
  100. package/dist/widget/components/WaasFeeOptions.d.ts +9 -0
  101. package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -0
  102. package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
  103. package/dist/widget/components/WalletConnect.d.ts.map +1 -1
  104. package/dist/widget/components/WalletList.d.ts.map +1 -1
  105. package/dist/widget/css/compiled.css +2 -0
  106. package/dist/widget/css/index.css +554 -0
  107. package/dist/widget/hooks/useBack.d.ts +1 -0
  108. package/dist/widget/hooks/useBack.d.ts.map +1 -1
  109. package/dist/widget/hooks/useCheckout.d.ts +1 -1
  110. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  111. package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
  112. package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
  113. package/dist/widget/hooks/useDefaultTokenSelection.d.ts +3 -3
  114. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
  115. package/dist/widget/hooks/usePayMessage.d.ts.map +1 -1
  116. package/dist/widget/hooks/useQuote.d.ts +83 -0
  117. package/dist/widget/hooks/useQuote.d.ts.map +1 -0
  118. package/dist/widget/hooks/useSelectedFundMethod.d.ts +12 -0
  119. package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +1 -0
  120. package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -1
  121. package/dist/widget/hooks/useSendForm.d.ts +2 -2
  122. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  123. package/dist/widget/index.js +2 -2
  124. package/dist/widget/widget.d.ts +9 -4
  125. package/dist/widget/widget.d.ts.map +1 -1
  126. package/package.json +18 -12
  127. package/src/aave.ts +32 -0
  128. package/src/abortController.ts +35 -0
  129. package/src/config.ts +12 -4
  130. package/src/constants.ts +5 -0
  131. package/src/error.ts +19 -1
  132. package/src/estimate.ts +416 -5
  133. package/src/fees.ts +199 -0
  134. package/src/intents.ts +161 -11
  135. package/src/metaTxnMonitor.ts +3 -3
  136. package/src/metaTxns.ts +3 -5
  137. package/src/morpho.ts +32 -0
  138. package/src/prepareSend.ts +714 -550
  139. package/src/queryParams.ts +2 -1
  140. package/src/relayer.ts +11 -11
  141. package/src/sequenceWallet.ts +2 -2
  142. package/src/tokens.ts +7 -1
  143. package/src/trails.ts +3 -3
  144. package/src/transactions.ts +62 -18
  145. package/src/wallets.ts +8 -0
  146. package/src/widget/compiled.css +2 -2
  147. package/src/widget/components/AccountActionsDropdown.tsx +3 -13
  148. package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
  149. package/src/widget/components/AccountSettings.tsx +48 -54
  150. package/src/widget/components/ChainFilterDropdown.tsx +24 -3
  151. package/src/widget/components/ClassicSwap.tsx +131 -213
  152. package/src/widget/components/ConnectWallet.tsx +8 -38
  153. package/src/widget/components/ConnectedWallets.tsx +132 -77
  154. package/src/widget/components/DynamicInputStyles.tsx +76 -0
  155. package/src/widget/components/Earn.tsx +82 -593
  156. package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
  157. package/src/widget/components/FeeBreakdown.tsx +155 -0
  158. package/src/widget/components/Fund.tsx +41 -108
  159. package/src/widget/components/FundMethods.tsx +82 -159
  160. package/src/widget/components/FundSwap.tsx +52 -0
  161. package/src/widget/components/FundingMethodSelectorButton.tsx +70 -0
  162. package/src/widget/components/Identicon.tsx +164 -95
  163. package/src/widget/components/MeshConnectExchanges.tsx +2 -15
  164. package/src/widget/components/Modal.tsx +0 -8
  165. package/src/widget/components/Pay.tsx +214 -237
  166. package/src/widget/components/PercentageMaxButtons.tsx +77 -0
  167. package/src/widget/components/PoolDeposit.tsx +569 -0
  168. package/src/widget/components/PoolWithdraw.tsx +884 -0
  169. package/src/widget/components/PriceImpactWarning.tsx +1 -1
  170. package/src/widget/components/QuoteDetails.tsx +43 -12
  171. package/src/widget/components/Receipt.tsx +16 -2
  172. package/src/widget/components/Receive.tsx +0 -2
  173. package/src/widget/components/RecipientSelectorButton.tsx +44 -0
  174. package/src/widget/components/Recipients.tsx +63 -157
  175. package/src/widget/components/RequiredPropsError.tsx +33 -0
  176. package/src/widget/components/ScreenHeader.tsx +62 -34
  177. package/src/widget/components/SlippageToleranceSettings.tsx +2 -1
  178. package/src/widget/components/Swap.tsx +4 -45
  179. package/src/widget/components/SwapSettings.tsx +2 -14
  180. package/src/widget/components/ThemeProvider.tsx +2 -1
  181. package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
  182. package/src/widget/components/TokenImage.tsx +22 -5
  183. package/src/widget/components/TokenList.tsx +0 -1
  184. package/src/widget/components/TokenSelector.tsx +63 -53
  185. package/src/widget/components/TokenSelectorButton.tsx +98 -0
  186. package/src/widget/components/Tooltip.tsx +51 -0
  187. package/src/widget/components/TransferPendingVertical.tsx +1 -1
  188. package/src/widget/components/UserPreferences.tsx +6 -24
  189. package/src/widget/components/WaasFeeOptions.tsx +450 -0
  190. package/src/widget/components/WalletConfirmation.tsx +76 -14
  191. package/src/widget/components/WalletConnect.tsx +93 -29
  192. package/src/widget/components/WalletList.tsx +4 -2
  193. package/src/widget/hooks/useBack.tsx +2 -0
  194. package/src/widget/hooks/useCheckout.ts +36 -20
  195. package/src/widget/hooks/useCurrentScreen.tsx +1 -0
  196. package/src/widget/hooks/useDefaultTokenSelection.tsx +104 -28
  197. package/src/widget/hooks/usePayMessage.tsx +86 -11
  198. package/src/widget/hooks/useQuote.ts +413 -0
  199. package/src/widget/hooks/useSelectedFundMethod.tsx +41 -0
  200. package/src/widget/hooks/useSelectedRecipient.tsx +10 -0
  201. package/src/widget/hooks/useSendForm.ts +32 -6
  202. package/src/widget/index.css +27 -0
  203. package/src/widget/widget.tsx +326 -283
  204. package/dist/widget/components/FundSendForm.d.ts.map +0 -1
  205. package/dist/widget/components/PaySendForm.d.ts.map +0 -1
  206. package/dist/widget/components/SimpleSwap.d.ts.map +0 -1
  207. package/dist/widget/hooks/useSwapSettings.d.ts +0 -16
  208. package/dist/widget/hooks/useSwapSettings.d.ts.map +0 -1
  209. package/src/widget/components/FundSendForm.tsx +0 -903
  210. package/src/widget/components/PaySendForm.tsx +0 -869
  211. package/src/widget/components/SimpleSwap.tsx +0 -983
  212. package/src/widget/hooks/useSwapSettings.tsx +0 -100
package/src/intents.ts CHANGED
@@ -53,6 +53,9 @@ import {
53
53
  } from "./analytics.js"
54
54
  import { getQueryParam } from "./queryParams.js"
55
55
  import { getFullErrorMessage } from "./error.js"
56
+ import { GAS_BUFFER, getFeeData } from "./estimate.js"
57
+ import { getERC20TransferData } from "./encoders.js"
58
+ import { zeroAddress } from "viem"
56
59
 
57
60
  export type IntentRequestParams = {
58
61
  userAddress: string
@@ -126,6 +129,9 @@ export type SendOriginCallTxArgs = {
126
129
  data: Hex.Hex
127
130
  value: bigint
128
131
  chain: Chain
132
+ gasLimit?: bigint // Optional: if provided, skip gas estimation
133
+ maxFeePerGas?: bigint // Optional: EIP-1559 max fee per gas
134
+ maxPriorityFeePerGas?: bigint // Optional: EIP-1559 max priority fee per gas
129
135
  }
130
136
 
131
137
  export async function getLocalClientIfEnabled(
@@ -486,17 +492,67 @@ export async function sendOriginTransaction(
486
492
  transport: http(),
487
493
  })
488
494
 
489
- const estimatedGasLimit = await publicClient.estimateGas({
490
- account: account,
491
- to: originParams.to as `0x${string}`,
492
- data: originParams.data as `0x${string}`,
493
- value: BigInt(originParams.value),
494
- })
495
+ // Use provided gasLimit if available, otherwise estimate
496
+ let gasLimit: bigint
497
+ if (originParams.gasLimit) {
498
+ gasLimit = originParams.gasLimit
499
+ logger.console.log(
500
+ "[trails-sdk][gas-estimation] using provided gasLimit:",
501
+ gasLimit,
502
+ )
503
+ } else {
504
+ const estimatedGasLimit = await publicClient.estimateGas({
505
+ account: account,
506
+ to: originParams.to as `0x${string}`,
507
+ data: originParams.data as `0x${string}`,
508
+ value: BigInt(originParams.value),
509
+ })
495
510
 
496
- const gsaBuffer = BigInt(50_000)
497
- const gasLimit = estimatedGasLimit + gsaBuffer
511
+ gasLimit = estimatedGasLimit + GAS_BUFFER
512
+ logger.console.log(
513
+ "[trails-sdk][gas-estimation] estimated gasLimit in sendOriginTransaction:",
514
+ gasLimit,
515
+ "(estimated:",
516
+ estimatedGasLimit,
517
+ "buffer:",
518
+ GAS_BUFFER,
519
+ ")",
520
+ )
521
+ }
498
522
 
499
- logger.console.log("[trails-sdk] estimated gasLimit:", gasLimit)
523
+ // Get fee parameters - try EIP-1559 first, then fall back to legacy
524
+ // Use provided fees if available, otherwise fetch and boost them for faster processing
525
+ let maxFeePerGas: bigint | undefined = originParams.maxFeePerGas
526
+ let maxPriorityFeePerGas: bigint | undefined =
527
+ originParams.maxPriorityFeePerGas
528
+ let gasPrice: bigint | undefined
529
+
530
+ if (!maxFeePerGas) {
531
+ try {
532
+ // Use getFeeData which applies the PRIORITY_FEE_MULTIPLIER
533
+ const feeData = await getFeeData(publicClient)
534
+
535
+ if (feeData.maxFeePerGas) {
536
+ maxFeePerGas = feeData.maxFeePerGas
537
+ maxPriorityFeePerGas = feeData.maxPriorityFeePerGas
538
+ logger.console.log(
539
+ "[trails-sdk][gas-estimation] Using boosted EIP-1559 fees in sendOriginTransaction:",
540
+ { maxFeePerGas, maxPriorityFeePerGas },
541
+ )
542
+ } else if (feeData.gasPrice) {
543
+ gasPrice = feeData.gasPrice
544
+ logger.console.log(
545
+ "[trails-sdk][gas-estimation] Using boosted legacy gas price in sendOriginTransaction:",
546
+ { gasPrice },
547
+ )
548
+ }
549
+ } catch (_error) {
550
+ // Fee data fetch failed, will use wallet default
551
+ logger.console.log(
552
+ "[trails-sdk][gas-estimation] Fee data fetch failed in sendOriginTransaction, wallet will use default",
553
+ )
554
+ }
555
+ }
500
556
 
501
557
  logger.console.log(
502
558
  "[trails-sdk] sending origin tx with walletClient.sendTransaction()",
@@ -505,14 +561,27 @@ export async function sendOriginTransaction(
505
561
  logger.console.time(`[trails-sdk] walletClient.sendTransaction-${id}`)
506
562
 
507
563
  try {
508
- const hash = await walletClient.sendTransaction({
564
+ // Build transaction parameters - EIP-1559 and legacy are mutually exclusive
565
+ const txParams: any = {
509
566
  account: account,
510
567
  to: originParams.to as `0x${string}`,
511
568
  data: originParams.data as `0x${string}`,
512
569
  value: BigInt(originParams.value),
513
570
  chain: originParams.chain,
514
571
  gas: gasLimit,
515
- })
572
+ }
573
+
574
+ // Add fee parameters based on transaction type
575
+ if (maxFeePerGas && maxPriorityFeePerGas) {
576
+ // EIP-1559 transaction
577
+ txParams.maxFeePerGas = maxFeePerGas
578
+ txParams.maxPriorityFeePerGas = maxPriorityFeePerGas
579
+ } else if (gasPrice) {
580
+ // Legacy transaction
581
+ txParams.gasPrice = gasPrice
582
+ }
583
+
584
+ const hash = await walletClient.sendTransaction(txParams)
516
585
  logger.console.timeEnd(`[trails-sdk] walletClient.sendTransaction-${id}`)
517
586
  logger.console.log("[trails-sdk] done sending, origin tx hash", hash)
518
587
 
@@ -807,3 +876,84 @@ function buildMerkleTreeFromMembers(
807
876
  }
808
877
  return currentLevel[0]!
809
878
  }
879
+
880
+ /**
881
+ * Build transaction parameters for same-chain same-token transactions
882
+ * Centralizes the logic for determining transaction destination, data, and value
883
+ */
884
+ export function buildSameChainTransactionParams({
885
+ hasCustomCalldata,
886
+ recipient,
887
+ effectiveOriginTokenAddress,
888
+ destinationCalldata,
889
+ swapAmount,
890
+ effectiveOriginChainId,
891
+ effectiveOriginChain,
892
+ }: {
893
+ hasCustomCalldata: boolean
894
+ recipient: string
895
+ effectiveOriginTokenAddress: string
896
+ destinationCalldata?: string
897
+ swapAmount: string
898
+ effectiveOriginChainId: number
899
+ effectiveOriginChain: Chain
900
+ }) {
901
+ return {
902
+ to: hasCustomCalldata
903
+ ? recipient
904
+ : effectiveOriginTokenAddress === zeroAddress
905
+ ? recipient
906
+ : effectiveOriginTokenAddress,
907
+ data: hasCustomCalldata
908
+ ? destinationCalldata || "0x"
909
+ : effectiveOriginTokenAddress === zeroAddress
910
+ ? "0x"
911
+ : getERC20TransferData({
912
+ recipient,
913
+ amount: BigInt(swapAmount),
914
+ }),
915
+ value:
916
+ effectiveOriginTokenAddress === zeroAddress ? BigInt(swapAmount) : "0",
917
+ chainId: effectiveOriginChainId,
918
+ chain: effectiveOriginChain,
919
+ }
920
+ }
921
+
922
+ /**
923
+ * Build transaction parameters for cross-chain deposit transactions
924
+ * Centralizes the logic for determining transaction destination, data, and value for deposits
925
+ */
926
+ export function buildCrossChainDepositParams({
927
+ originTokenAddress,
928
+ originIntentAddress,
929
+ depositAmount,
930
+ fee,
931
+ originChainId,
932
+ chain,
933
+ }: {
934
+ originTokenAddress: string
935
+ originIntentAddress: string
936
+ depositAmount: string
937
+ fee: string
938
+ originChainId: number
939
+ chain: Chain
940
+ }) {
941
+ const totalAmount = BigInt(depositAmount) + BigInt(fee)
942
+
943
+ return {
944
+ to:
945
+ originTokenAddress === zeroAddress
946
+ ? originIntentAddress
947
+ : originTokenAddress,
948
+ data:
949
+ originTokenAddress === zeroAddress
950
+ ? "0x"
951
+ : getERC20TransferData({
952
+ recipient: originIntentAddress,
953
+ amount: totalAmount,
954
+ }),
955
+ value: originTokenAddress === zeroAddress ? totalAmount : "0",
956
+ chainId: originChainId,
957
+ chain,
958
+ }
959
+ }
@@ -5,7 +5,7 @@ import type {
5
5
  RelayerOperationStatus,
6
6
  RelayerOperationUnknownStatus,
7
7
  } from "./relayer.js"
8
- import type { RpcRelayer } from "@0xsequence/relayer"
8
+ import type { Relayer } from "@0xsequence/relayer"
9
9
  import { type Query, useQueries } from "@tanstack/react-query"
10
10
  import { useMemo } from "react"
11
11
  import type { Hex } from "viem"
@@ -26,7 +26,7 @@ export type MetaTxnStatus = {
26
26
  const POLL_INTERVAL = 3_000 // 3 seconds
27
27
 
28
28
  export const getMetaTxStatus = async (
29
- relayer: RpcRelayer.RpcRelayer,
29
+ relayer: Relayer.RpcRelayer,
30
30
  metaTxId: string,
31
31
  chainId: number,
32
32
  ): Promise<RelayerOperationStatus> => {
@@ -35,7 +35,7 @@ export const getMetaTxStatus = async (
35
35
 
36
36
  export const useMetaTxnsMonitor = (
37
37
  metaTxns: MetaTxn[] | undefined,
38
- getRelayer: (chainId: number) => RpcRelayer.RpcRelayer,
38
+ getRelayer: (chainId: number) => Relayer.RpcRelayer,
39
39
  ) => {
40
40
  const results = useQueries({
41
41
  queries: (metaTxns || []).map((metaTxn) => {
package/src/metaTxns.ts CHANGED
@@ -1,13 +1,11 @@
1
+ import type { Relayer } from "@0xsequence/relayer"
1
2
  import type { IntentPrecondition } from "@0xsequence/trails-api"
2
3
  import type { Hex } from "viem"
3
4
  import type { MetaTxn } from "./metaTxnMonitor.js"
4
- import type { RpcRelayer } from "@0xsequence/relayer"
5
-
6
5
  import { logger } from "./logger.js"
7
- import type { Relayer } from "@0xsequence/relayer"
8
6
 
9
7
  export async function relayerSendMetaTx(
10
- relayer: RpcRelayer.RpcRelayer,
8
+ relayer: Relayer.RpcRelayer,
11
9
  metaTx: MetaTxn,
12
10
  preconditions: IntentPrecondition[],
13
11
  feeQuote?: Relayer.FeeQuote,
@@ -25,7 +23,7 @@ export async function relayerSendMetaTx(
25
23
  }
26
24
 
27
25
  export async function getMetaTxnReceipt(
28
- relayer: RpcRelayer.RpcRelayer,
26
+ relayer: Relayer.RpcRelayer,
29
27
  metaTxId: string,
30
28
  chainId: number,
31
29
  ): Promise<{ receipt: { status: "confirmed" | "failed" | "pending" } }> {
package/src/morpho.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { useMemo, useState, useEffect } from "react"
2
2
  import type { Address, PublicClient } from "viem"
3
+ import { encodeFunctionData } from "viem"
3
4
  import { logger } from "./logger.js"
4
5
 
5
6
  type AccrualPosition = any
@@ -425,4 +426,35 @@ export async function getAllVaults(
425
426
  return transformedVaults
426
427
  }
427
428
 
429
+ /**
430
+ * Generate Morpho vault withdraw calldata
431
+ * @param asset - The address of the underlying asset to withdraw
432
+ * @param amount - The amount to withdraw in wei (or max uint256 for full balance)
433
+ * @param to - The address that will receive the underlying tokens
434
+ * @returns Encoded calldata for Morpho withdraw function
435
+ */
436
+ export function generateMorphoWithdrawCalldata(
437
+ asset: string,
438
+ amount: bigint,
439
+ to: string,
440
+ ): `0x${string}` {
441
+ return encodeFunctionData({
442
+ abi: [
443
+ {
444
+ name: "withdraw",
445
+ type: "function",
446
+ stateMutability: "nonpayable",
447
+ inputs: [
448
+ { name: "asset", type: "address" },
449
+ { name: "amount", type: "uint256" },
450
+ { name: "to", type: "address" },
451
+ ],
452
+ outputs: [{ type: "uint256" }],
453
+ },
454
+ ],
455
+ functionName: "withdraw",
456
+ args: [asset as `0x${string}`, amount, to as `0x${string}`],
457
+ })
458
+ }
459
+
428
460
  export default useMorphoVaults