0xtrails 0.2.6 → 0.4.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 (218) hide show
  1. package/dist/aave.d.ts +2 -0
  2. package/dist/aave.d.ts.map +1 -1
  3. package/dist/{ccip-Xjh9d1gb.js → ccip-BpQGQiWq.js} +7 -7
  4. package/dist/config.d.ts +0 -5
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/constants.d.ts +2 -4
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/error.d.ts +4 -1
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/fees.d.ts +2 -2
  11. package/dist/fees.d.ts.map +1 -1
  12. package/dist/{index-BnhdZ8Ho.js → index-DsJM5F-V.js} +46084 -48697
  13. package/dist/index.d.ts +9 -8
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +741 -923
  16. package/dist/intentReceiptMonitor.d.ts +24 -0
  17. package/dist/intentReceiptMonitor.d.ts.map +1 -0
  18. package/dist/intentReceiptPoller.d.ts +69 -0
  19. package/dist/intentReceiptPoller.d.ts.map +1 -0
  20. package/dist/intents.d.ts +15 -11
  21. package/dist/intents.d.ts.map +1 -1
  22. package/dist/morpho.d.ts +6 -5
  23. package/dist/morpho.d.ts.map +1 -1
  24. package/dist/mutations.d.ts +16 -0
  25. package/dist/mutations.d.ts.map +1 -0
  26. package/dist/preconditions.d.ts +5 -4
  27. package/dist/preconditions.d.ts.map +1 -1
  28. package/dist/prepareSend.d.ts +5 -190
  29. package/dist/prepareSend.d.ts.map +1 -1
  30. package/dist/prices.d.ts +9 -6
  31. package/dist/prices.d.ts.map +1 -1
  32. package/dist/sequenceWallet.d.ts +3 -16
  33. package/dist/sequenceWallet.d.ts.map +1 -1
  34. package/dist/tokenBalances.d.ts +17 -13
  35. package/dist/tokenBalances.d.ts.map +1 -1
  36. package/dist/trails.d.ts +24 -40
  37. package/dist/trails.d.ts.map +1 -1
  38. package/dist/trailsClient.d.ts +5 -6
  39. package/dist/trailsClient.d.ts.map +1 -1
  40. package/dist/transactionIntent/constants.d.ts +7 -0
  41. package/dist/transactionIntent/constants.d.ts.map +1 -0
  42. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +44 -0
  43. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -0
  44. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +30 -0
  45. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -0
  46. package/dist/transactionIntent/deposits/index.d.ts +4 -0
  47. package/dist/transactionIntent/deposits/index.d.ts.map +1 -0
  48. package/dist/transactionIntent/deposits/standardDeposit.d.ts +30 -0
  49. package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -0
  50. package/dist/transactionIntent/execution/index.d.ts +2 -0
  51. package/dist/transactionIntent/execution/index.d.ts.map +1 -0
  52. package/dist/transactionIntent/execution/transactionState.d.ts +5 -0
  53. package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -0
  54. package/dist/transactionIntent/handlers/crossChain.d.ts +82 -0
  55. package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -0
  56. package/dist/transactionIntent/handlers/index.d.ts +4 -0
  57. package/dist/transactionIntent/handlers/index.d.ts.map +1 -0
  58. package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +62 -0
  59. package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +1 -0
  60. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +72 -0
  61. package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -0
  62. package/dist/transactionIntent/index.d.ts +9 -0
  63. package/dist/transactionIntent/index.d.ts.map +1 -0
  64. package/dist/transactionIntent/quote/feeExtractors.d.ts +17 -0
  65. package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -0
  66. package/dist/transactionIntent/quote/index.d.ts +4 -0
  67. package/dist/transactionIntent/quote/index.d.ts.map +1 -0
  68. package/dist/transactionIntent/quote/normalizeQuote.d.ts +34 -0
  69. package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -0
  70. package/dist/transactionIntent/quote/quoteHelpers.d.ts +5 -0
  71. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -0
  72. package/dist/transactionIntent/types.d.ts +131 -0
  73. package/dist/transactionIntent/types.d.ts.map +1 -0
  74. package/dist/transactionIntent/utils/balanceChecker.d.ts +18 -0
  75. package/dist/transactionIntent/utils/balanceChecker.d.ts.map +1 -0
  76. package/dist/transactionIntent/utils/index.d.ts +4 -0
  77. package/dist/transactionIntent/utils/index.d.ts.map +1 -0
  78. package/dist/transactionIntent/utils/lifiHelpers.d.ts +10 -0
  79. package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +1 -0
  80. package/dist/transactionIntent/utils/testnetHelpers.d.ts +3 -0
  81. package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -0
  82. package/dist/transactionIntent/validators.d.ts +6 -0
  83. package/dist/transactionIntent/validators.d.ts.map +1 -0
  84. package/dist/transactions.d.ts +2 -1
  85. package/dist/transactions.d.ts.map +1 -1
  86. package/dist/widget/components/AccountSettings.d.ts.map +1 -1
  87. package/dist/widget/components/ClassicSwap.d.ts +0 -1
  88. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  89. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  90. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
  91. package/dist/widget/components/DynamicSizeInputField.d.ts +13 -0
  92. package/dist/widget/components/DynamicSizeInputField.d.ts.map +1 -0
  93. package/dist/widget/components/Earn.d.ts +0 -1
  94. package/dist/widget/components/Earn.d.ts.map +1 -1
  95. package/dist/widget/components/FeeOptions.d.ts +5 -13
  96. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  97. package/dist/widget/components/Fund.d.ts +0 -1
  98. package/dist/widget/components/Fund.d.ts.map +1 -1
  99. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  100. package/dist/widget/components/FundSwap.d.ts +0 -1
  101. package/dist/widget/components/FundSwap.d.ts.map +1 -1
  102. package/dist/widget/components/Pay.d.ts +0 -1
  103. package/dist/widget/components/Pay.d.ts.map +1 -1
  104. package/dist/widget/components/PoolDeposit.d.ts +0 -1
  105. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  106. package/dist/widget/components/PoolWithdraw.d.ts +0 -18
  107. package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
  108. package/dist/widget/components/QuoteDetails.d.ts +1 -0
  109. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  110. package/dist/widget/components/Swap.d.ts +0 -1
  111. package/dist/widget/components/Swap.d.ts.map +1 -1
  112. package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
  113. package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
  114. package/dist/widget/css/compiled.css +2 -2
  115. package/dist/widget/hooks/useCheckout.d.ts +17 -4
  116. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  117. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
  118. package/dist/widget/hooks/useQuote.d.ts +3 -4
  119. package/dist/widget/hooks/useQuote.d.ts.map +1 -1
  120. package/dist/widget/hooks/useSelectedFeeToken.d.ts +1 -0
  121. package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -1
  122. package/dist/widget/hooks/useSendForm.d.ts +3 -4
  123. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  124. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  125. package/dist/widget/hooks/useWalletConnectionContext.d.ts +25 -0
  126. package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +1 -0
  127. package/dist/widget/index.js +1 -1
  128. package/dist/widget/widget.d.ts +12 -7
  129. package/dist/widget/widget.d.ts.map +1 -1
  130. package/package.json +21 -23
  131. package/src/aave.ts +54 -1
  132. package/src/config.ts +57 -58
  133. package/src/constants.ts +8 -9
  134. package/src/error.ts +21 -3
  135. package/src/fees.ts +53 -42
  136. package/src/index.ts +35 -13
  137. package/src/intentReceiptMonitor.ts +102 -0
  138. package/src/intentReceiptPoller.ts +299 -0
  139. package/src/intents.ts +206 -172
  140. package/src/morpho.ts +58 -9
  141. package/src/mutations.ts +129 -0
  142. package/src/preconditions.ts +16 -21
  143. package/src/prepareSend.ts +80 -4514
  144. package/src/prices.ts +26 -22
  145. package/src/relaySdk.ts +2 -2
  146. package/src/sequenceWallet.ts +6 -73
  147. package/src/tokenBalances.ts +175 -69
  148. package/src/trails.ts +230 -722
  149. package/src/trailsClient.ts +10 -23
  150. package/src/transactionIntent/constants.ts +11 -0
  151. package/src/transactionIntent/deposits/depositOrchestrator.ts +210 -0
  152. package/src/transactionIntent/deposits/gaslessDeposit.ts +588 -0
  153. package/src/transactionIntent/deposits/index.ts +3 -0
  154. package/src/transactionIntent/deposits/standardDeposit.ts +379 -0
  155. package/src/transactionIntent/execution/index.ts +1 -0
  156. package/src/transactionIntent/execution/transactionState.ts +35 -0
  157. package/src/transactionIntent/handlers/crossChain.ts +1707 -0
  158. package/src/transactionIntent/handlers/index.ts +3 -0
  159. package/src/transactionIntent/handlers/sameChainDifferentToken.ts +323 -0
  160. package/src/transactionIntent/handlers/sameChainSameToken.ts +712 -0
  161. package/src/transactionIntent/index.ts +9 -0
  162. package/src/transactionIntent/quote/feeExtractors.ts +81 -0
  163. package/src/transactionIntent/quote/index.ts +3 -0
  164. package/src/transactionIntent/quote/normalizeQuote.ts +367 -0
  165. package/src/transactionIntent/quote/quoteHelpers.ts +53 -0
  166. package/src/transactionIntent/types.ts +157 -0
  167. package/src/transactionIntent/utils/balanceChecker.ts +96 -0
  168. package/src/transactionIntent/utils/index.ts +3 -0
  169. package/src/transactionIntent/utils/lifiHelpers.ts +68 -0
  170. package/src/transactionIntent/utils/testnetHelpers.ts +10 -0
  171. package/src/transactionIntent/validators.ts +57 -0
  172. package/src/transactions.ts +36 -53
  173. package/src/widget/compiled.css +2 -2
  174. package/src/widget/components/AccountIntentTransactionHistory.tsx +36 -36
  175. package/src/widget/components/AccountSettings.tsx +23 -6
  176. package/src/widget/components/ClassicSwap.tsx +28 -53
  177. package/src/widget/components/ConfigDisplay.tsx +0 -11
  178. package/src/widget/components/ConnectedWallets.tsx +30 -4
  179. package/src/widget/components/DynamicSizeInputField.tsx +109 -0
  180. package/src/widget/components/Earn.tsx +0 -16
  181. package/src/widget/components/FeeBreakdown.tsx +3 -3
  182. package/src/widget/components/FeeOption.tsx +2 -2
  183. package/src/widget/components/FeeOptions.tsx +151 -112
  184. package/src/widget/components/Fund.tsx +0 -3
  185. package/src/widget/components/FundMethods.tsx +4 -3
  186. package/src/widget/components/FundSwap.tsx +0 -1
  187. package/src/widget/components/Pay.tsx +11 -16
  188. package/src/widget/components/PoolDeposit.tsx +35 -32
  189. package/src/widget/components/PoolWithdraw.tsx +153 -256
  190. package/src/widget/components/QuoteDetails.tsx +899 -494
  191. package/src/widget/components/Swap.tsx +0 -1
  192. package/src/widget/components/TransferPendingVertical.tsx +12 -8
  193. package/src/widget/components/WaasFeeOptions.tsx +23 -7
  194. package/src/widget/components/WalletConfirmation.tsx +1 -1
  195. package/src/widget/hooks/useAmountUsd.ts +9 -9
  196. package/src/widget/hooks/useCheckout.ts +97 -9
  197. package/src/widget/hooks/useDefaultTokenSelection.tsx +27 -21
  198. package/src/widget/hooks/useQuote.ts +86 -33
  199. package/src/widget/hooks/useSelectedFeeToken.tsx +32 -37
  200. package/src/widget/hooks/useSendForm.ts +37 -47
  201. package/src/widget/hooks/useTokenList.ts +34 -26
  202. package/src/widget/hooks/useWalletConnectionContext.tsx +128 -0
  203. package/src/widget/widget.tsx +197 -207
  204. package/dist/apiClient.d.ts +0 -9
  205. package/dist/apiClient.d.ts.map +0 -1
  206. package/dist/intentEntrypoint.d.ts +0 -114
  207. package/dist/intentEntrypoint.d.ts.map +0 -1
  208. package/dist/metaTxnMonitor.d.ts +0 -15
  209. package/dist/metaTxnMonitor.d.ts.map +0 -1
  210. package/dist/metaTxns.d.ts +0 -11
  211. package/dist/metaTxns.d.ts.map +0 -1
  212. package/dist/relayer.d.ts +0 -43
  213. package/dist/relayer.d.ts.map +0 -1
  214. package/src/apiClient.ts +0 -35
  215. package/src/intentEntrypoint.ts +0 -203
  216. package/src/metaTxnMonitor.ts +0 -171
  217. package/src/metaTxns.ts +0 -45
  218. package/src/relayer.ts +0 -289
@@ -0,0 +1,96 @@
1
+ import type { Account, PublicClient } from "viem"
2
+ import { erc20Abi, formatUnits, zeroAddress } from "viem"
3
+ import { InsufficientBalanceError } from "../../error.js"
4
+ import { formatAmount } from "../../tokenBalances.js"
5
+ import { logger } from "../../logger.js"
6
+
7
+ /**
8
+ * Check if the account has enough balance for the deposit amount
9
+ */
10
+ export async function checkAccountBalance({
11
+ account,
12
+ tokenAddress,
13
+ depositAmount,
14
+ publicClient,
15
+ }: {
16
+ account: Account
17
+ tokenAddress: string
18
+ depositAmount: string
19
+ publicClient: PublicClient
20
+ }): Promise<{
21
+ hasEnoughBalance: boolean
22
+ balance: bigint
23
+ requiredAmount: bigint
24
+ balanceFormatted: string
25
+ requiredAmountFormatted: string
26
+ balanceError: Error | null
27
+ }> {
28
+ try {
29
+ let balance: bigint
30
+
31
+ if (tokenAddress === zeroAddress) {
32
+ // Native token balance
33
+ balance = await publicClient.getBalance({ address: account.address })
34
+ } else {
35
+ // ERC20 token balance
36
+ balance = await publicClient.readContract({
37
+ address: tokenAddress as `0x${string}`,
38
+ abi: erc20Abi,
39
+ functionName: "balanceOf",
40
+ args: [account.address],
41
+ })
42
+ }
43
+
44
+ const requiredAmount = BigInt(depositAmount)
45
+
46
+ logger.console.log("[trails-sdk] balance", balance)
47
+ logger.console.log("[trails-sdk] requiredAmount", requiredAmount)
48
+ const hasEnoughBalance = balance >= requiredAmount
49
+ logger.console.log("[trails-sdk] hasEnoughBalance", hasEnoughBalance)
50
+
51
+ let balanceFormatted = ""
52
+ let requiredAmountFormatted = ""
53
+ if (tokenAddress === zeroAddress) {
54
+ balanceFormatted = formatUnits(balance, 18)
55
+ requiredAmountFormatted = formatUnits(requiredAmount, 18)
56
+ } else {
57
+ // ERC20 token balance
58
+ const decimals = await publicClient.readContract({
59
+ address: tokenAddress as `0x${string}`,
60
+ abi: erc20Abi,
61
+ functionName: "decimals",
62
+ })
63
+ if (!decimals) {
64
+ throw new Error("Decimals not found")
65
+ }
66
+ balanceFormatted = formatUnits(balance, decimals)
67
+ requiredAmountFormatted = formatUnits(requiredAmount, decimals)
68
+ }
69
+
70
+ let balanceError = null
71
+ if (!hasEnoughBalance) {
72
+ balanceError = new InsufficientBalanceError(
73
+ `Insufficient balance: Need ${formatAmount(requiredAmountFormatted)} ${tokenAddress} for ${account.address} on ${publicClient.chain?.name} but only have ${formatAmount(balanceFormatted)} ${tokenAddress}`,
74
+ )
75
+ }
76
+
77
+ return {
78
+ hasEnoughBalance,
79
+ balance,
80
+ balanceFormatted,
81
+ requiredAmount,
82
+ requiredAmountFormatted,
83
+ balanceError,
84
+ }
85
+ } catch (error) {
86
+ logger.console.error("[trails-sdk] Error checking account balance:", error)
87
+ return {
88
+ hasEnoughBalance: false,
89
+ balance: BigInt(0),
90
+ balanceFormatted: "0",
91
+ requiredAmount: BigInt(0),
92
+ requiredAmountFormatted: "0",
93
+ balanceError: error instanceof Error ? error : null,
94
+ }
95
+ }
96
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./testnetHelpers.js"
2
+ export * from "./balanceChecker.js"
3
+ export * from "./lifiHelpers.js"
@@ -0,0 +1,68 @@
1
+ import { formatUnits, zeroAddress } from "viem"
2
+ import { calcAmountUsdPrice } from "../../prices.js"
3
+ import { logger } from "../../logger.js"
4
+
5
+ // ETH fee required by some bridges for low token amounts
6
+ // TODO: update backend API to return the native fee requirement, if any
7
+ export function getNeedsLifiNativeFee({
8
+ originTokenAddress,
9
+ destinationTokenAmount,
10
+ destinationTokenDecimals,
11
+ sourceTokenDecimals,
12
+ sourceTokenPriceUsd,
13
+ destinationTokenPriceUsd,
14
+ depositAmount,
15
+ }: {
16
+ originTokenAddress: string
17
+ destinationTokenAmount: string
18
+ destinationTokenDecimals: number
19
+ sourceTokenDecimals: number
20
+ sourceTokenPriceUsd: number | null
21
+ destinationTokenPriceUsd: number | null
22
+ depositAmount: string
23
+ }): boolean {
24
+ let needsNativeFee = false
25
+ if (
26
+ originTokenAddress !== zeroAddress &&
27
+ sourceTokenPriceUsd &&
28
+ destinationTokenPriceUsd &&
29
+ depositAmount &&
30
+ destinationTokenDecimals !== undefined &&
31
+ sourceTokenDecimals !== undefined
32
+ ) {
33
+ // Convert from wei to token units using formatUnits
34
+ const destinationAmount = Number(
35
+ formatUnits(BigInt(destinationTokenAmount), destinationTokenDecimals),
36
+ )
37
+ const depositAmountFormatted = Number(
38
+ formatUnits(BigInt(depositAmount), sourceTokenDecimals),
39
+ )
40
+ logger.console.log("[trails-sdk] destinationAmount", destinationAmount)
41
+ logger.console.log(
42
+ "[trails-sdk] depositAmountFormatted",
43
+ depositAmountFormatted,
44
+ )
45
+ const destinationAmountUsd = calcAmountUsdPrice({
46
+ amount: destinationAmount,
47
+ usdPrice: destinationTokenPriceUsd,
48
+ })
49
+ const depositAmountUsd = calcAmountUsdPrice({
50
+ amount: depositAmountFormatted,
51
+ usdPrice: sourceTokenPriceUsd,
52
+ })
53
+ const diff = depositAmountUsd - destinationAmountUsd
54
+ logger.console.log(
55
+ "[trails-sdk] destinationAmountUsd",
56
+ destinationAmountUsd,
57
+ "[trails-sdk] depositAmountUsd",
58
+ depositAmountUsd,
59
+ "[trails-sdk] diff",
60
+ diff,
61
+ )
62
+ if (diff >= 0 && diff <= 0.02) {
63
+ needsNativeFee = true
64
+ }
65
+ }
66
+
67
+ return needsNativeFee
68
+ }
@@ -0,0 +1,10 @@
1
+ import { getQueryParam } from "../../queryParams.js"
2
+ import { getUSDCTokenAddress } from "../../cctp.js"
3
+
4
+ export function isTestnetDebugMode(): boolean {
5
+ return getQueryParam("testnet") === "true"
6
+ }
7
+
8
+ export function getTestnetOriginTokenAddress(testnetChainId: number): string {
9
+ return getUSDCTokenAddress(testnetChainId)!
10
+ }
@@ -0,0 +1,57 @@
1
+ import { getIsUsdcAddress } from "../cctp.js"
2
+
3
+ export function isSameChain(
4
+ originChainId: number,
5
+ destinationChainId: number,
6
+ ): boolean {
7
+ return originChainId?.toString() === destinationChainId?.toString()
8
+ }
9
+
10
+ export function isSameToken(
11
+ originTokenAddress: string,
12
+ destinationTokenAddress: string,
13
+ ): boolean {
14
+ return (
15
+ originTokenAddress?.toLowerCase() === destinationTokenAddress?.toLowerCase()
16
+ )
17
+ }
18
+
19
+ export function isSameChainAndToken(
20
+ originChainId: number,
21
+ originTokenAddress: string,
22
+ destinationChainId: number,
23
+ destinationTokenAddress: string,
24
+ ): boolean {
25
+ return (
26
+ isSameChain(originChainId, destinationChainId) &&
27
+ isSameToken(originTokenAddress, destinationTokenAddress)
28
+ )
29
+ }
30
+
31
+ export function shouldUseCctp(
32
+ originTokenAddress: string,
33
+ destinationTokenAddress: string,
34
+ originChainId: number,
35
+ destinationChainId: number,
36
+ ) {
37
+ return (
38
+ getIsUsdcAddress(originTokenAddress, originChainId) &&
39
+ getIsUsdcAddress(destinationTokenAddress, destinationChainId)
40
+ )
41
+ }
42
+
43
+ export function validateCctpDestinationToken(
44
+ destinationTokenAddress: string,
45
+ destinationChainId: number,
46
+ quoteProvider?: string | null,
47
+ ): void {
48
+ // If CCTP provider is selected, destination token must be USDC
49
+ if (
50
+ quoteProvider === "cctp" &&
51
+ !getIsUsdcAddress(destinationTokenAddress, destinationChainId)
52
+ ) {
53
+ throw new Error(
54
+ `CCTP provider requires destination token to be USDC. Current destination token: ${destinationTokenAddress} on chain ${destinationChainId}. Please ensure the destination token is USDC as listed in the Circle CCTP documentation.`,
55
+ )
56
+ }
57
+ }
@@ -1,4 +1,3 @@
1
- import { createPublicClient, http } from "viem"
2
1
  import { useQuery } from "@tanstack/react-query"
3
2
  import { getChainInfo } from "./chains.js"
4
3
  import { getSequenceProjectAccessKey } from "./config.js"
@@ -27,6 +26,7 @@ export type TransactionState = {
27
26
  decodedTrailsTokenSweeperEvents?: TrailsTokenSweeperEvent[]
28
27
  decodedGuestModuleEvents?: GuestModuleEvent[]
29
28
  refunded?: boolean
29
+ txnMinedAt?: string
30
30
  }
31
31
 
32
32
  export type TransferType = "SEND" | "RECEIVE"
@@ -126,57 +126,25 @@ export async function getTxTimeDiff(
126
126
  return 0
127
127
  }
128
128
 
129
- const firstChainInfo = getChainInfo(firstTx.chainId)
130
- const lastChainInfo = getChainInfo(lastTx.chainId)
131
- if (!firstChainInfo || !lastChainInfo) return 0
132
-
133
- const firstClient = createPublicClient({
134
- chain: firstChainInfo,
135
- transport: http(),
136
- })
137
- const lastClient = createPublicClient({
138
- chain: lastChainInfo,
139
- transport: http(),
140
- })
141
-
142
- async function getBlockNumber(
143
- client: ReturnType<typeof createPublicClient>,
144
- tx: TransactionState,
145
- ) {
146
- if (tx.blockNumber) return BigInt(tx.blockNumber)
147
- const receipt = await client.getTransactionReceipt({
148
- hash: tx.transactionHash as `0x${string}`,
149
- })
150
- return receipt.blockNumber
151
- }
152
-
153
- async function getTimestamp(
154
- client: ReturnType<typeof createPublicClient>,
155
- blockNumber: bigint,
156
- ) {
157
- const block = await client.getBlock({ blockNumber })
158
- return typeof block.timestamp === "bigint"
159
- ? Number(block.timestamp)
160
- : block.timestamp
161
- }
162
-
163
129
  try {
164
- const [firstBlockNumber, lastBlockNumber] = await Promise.all([
165
- getBlockNumber(firstClient, firstTx),
166
- getBlockNumber(lastClient, lastTx),
167
- ])
168
-
169
- const [firstTs, lastTs] = await Promise.all([
170
- getTimestamp(firstClient, firstBlockNumber),
171
- getTimestamp(lastClient, lastBlockNumber),
172
- ])
173
-
174
- const diff = lastTs - firstTs
175
- if (diff < 1) {
176
- return 1 // round up to 1 second
130
+ // Use txnMinedAt timestamps from API if available
131
+ if (firstTx.txnMinedAt && lastTx.txnMinedAt) {
132
+ const firstTs = new Date(firstTx.txnMinedAt).getTime() / 1000
133
+ const lastTs = new Date(lastTx.txnMinedAt).getTime() / 1000
134
+
135
+ const diff = lastTs - firstTs
136
+ if (diff < 1) {
137
+ return 1 // round up to 1 second
138
+ }
139
+
140
+ return diff
177
141
  }
178
142
 
179
- return diff
143
+ // Fallback: return 0 if txnMinedAt is not available
144
+ logger.console.warn(
145
+ "[trails-sdk] txnMinedAt not available for transactions, cannot calculate time difference",
146
+ )
147
+ return 0
180
148
  } catch (error) {
181
149
  logger.console.error(
182
150
  "[trails-sdk] Error calculating transaction time difference:",
@@ -349,7 +317,7 @@ export type GetIntentTransactionHistoryParams = {
349
317
  }
350
318
 
351
319
  export async function getIntentTransactionHistory({
352
- accountAddress,
320
+ accountAddress: _accountAddress,
353
321
  pageSize = 10,
354
322
  page = 1,
355
323
  }: GetIntentTransactionHistoryParams): Promise<IntentTransactionHistoryResponse> {
@@ -364,9 +332,7 @@ export async function getIntentTransactionHistory({
364
332
 
365
333
  // Use the hybrid client's getIntentTransactionHistory method which tries Trails API first, then Sequence API
366
334
  const result = await trailsClient.getIntentTransactionHistory({
367
- accountAddress: accountAddress.toLowerCase(),
368
335
  page: {
369
- page,
370
336
  pageSize,
371
337
  sort: [
372
338
  {
@@ -377,7 +343,24 @@ export async function getIntentTransactionHistory({
377
343
  },
378
344
  })
379
345
 
380
- return result
346
+ // Note: The new API has a different IntentTransaction structure.
347
+ // We need to map the API response to our local type structure.
348
+ // For now, return an empty result as the API structure has changed significantly.
349
+ // TODO: Implement proper mapping from new API IntentTransaction to SDK IntentTransaction
350
+ return {
351
+ page: result.nextPage
352
+ ? {
353
+ page,
354
+ pageSize,
355
+ more: true,
356
+ }
357
+ : {
358
+ page,
359
+ pageSize,
360
+ more: false,
361
+ },
362
+ transactions: [], // TODO: Map result.transactions to SDK IntentTransaction format
363
+ }
381
364
  } catch (error) {
382
365
  logger.console.error(
383
366
  "[trails-sdk] Error fetching intent transaction history:",