0xtrails 0.1.13 → 0.2.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 (216) hide show
  1. package/dist/aave.d.ts.map +1 -1
  2. package/dist/analytics.d.ts +11 -2
  3. package/dist/analytics.d.ts.map +1 -1
  4. package/dist/apiClient.d.ts +1 -1
  5. package/dist/apiClient.d.ts.map +1 -1
  6. package/dist/{proxyCaller.d.ts → balanceInjector.d.ts} +5 -4
  7. package/dist/balanceInjector.d.ts.map +1 -0
  8. package/dist/{ccip-D3gTQONK.js → ccip-D6ToCrWc.js} +12 -12
  9. package/dist/cctp.d.ts.map +1 -1
  10. package/dist/cctpqueue.d.ts +3 -3
  11. package/dist/cctpqueue.d.ts.map +1 -1
  12. package/dist/chains.d.ts.map +1 -1
  13. package/dist/config.d.ts +17 -3
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/constants.d.ts +5 -4
  16. package/dist/constants.d.ts.map +1 -1
  17. package/dist/contractUtils.d.ts +2 -0
  18. package/dist/contractUtils.d.ts.map +1 -1
  19. package/dist/customChains.d.ts +24 -0
  20. package/dist/customChains.d.ts.map +1 -0
  21. package/dist/{index-CnUM7lKf.js → index-BqgeTLL8.js} +34072 -30146
  22. package/dist/index.d.ts +5 -3
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +411 -400
  25. package/dist/intentEntrypoint.d.ts +96 -0
  26. package/dist/intentEntrypoint.d.ts.map +1 -0
  27. package/dist/intents.d.ts +5 -3
  28. package/dist/intents.d.ts.map +1 -1
  29. package/dist/metaTxnMonitor.d.ts.map +1 -1
  30. package/dist/morpho.d.ts.map +1 -1
  31. package/dist/pools.d.ts +3 -1
  32. package/dist/pools.d.ts.map +1 -1
  33. package/dist/prepareSend.d.ts +8 -2
  34. package/dist/prepareSend.d.ts.map +1 -1
  35. package/dist/prices.d.ts +1 -1
  36. package/dist/prices.d.ts.map +1 -1
  37. package/dist/relaySdk.d.ts.map +1 -1
  38. package/dist/relayer.d.ts.map +1 -1
  39. package/dist/toast.d.ts +9 -0
  40. package/dist/toast.d.ts.map +1 -0
  41. package/dist/tokenBalances.d.ts +6 -2
  42. package/dist/tokenBalances.d.ts.map +1 -1
  43. package/dist/tokens.d.ts.map +1 -1
  44. package/dist/trails.d.ts +6 -5
  45. package/dist/trails.d.ts.map +1 -1
  46. package/dist/trailsClient.d.ts +12 -0
  47. package/dist/trailsClient.d.ts.map +1 -0
  48. package/dist/transactions.d.ts +8 -0
  49. package/dist/transactions.d.ts.map +1 -1
  50. package/dist/wallets.d.ts.map +1 -1
  51. package/dist/widget/components/AccountActionsDropdown.d.ts.map +1 -1
  52. package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
  53. package/dist/widget/components/AccountSettings.d.ts +7 -0
  54. package/dist/widget/components/AccountSettings.d.ts.map +1 -0
  55. package/dist/widget/components/ChainList.d.ts +0 -1
  56. package/dist/widget/components/ChainList.d.ts.map +1 -1
  57. package/dist/widget/components/ClassicSwap.d.ts +46 -0
  58. package/dist/widget/components/ClassicSwap.d.ts.map +1 -0
  59. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  60. package/dist/widget/components/ConnectedWallets.d.ts +9 -0
  61. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -0
  62. package/dist/widget/components/DebugMenu.d.ts.map +1 -1
  63. package/dist/widget/components/DebugScreensList.d.ts.map +1 -1
  64. package/dist/widget/components/DebugToast.d.ts +3 -0
  65. package/dist/widget/components/DebugToast.d.ts.map +1 -0
  66. package/dist/widget/components/Earn.d.ts.map +1 -1
  67. package/dist/widget/components/EarnPools.d.ts.map +1 -1
  68. package/dist/widget/components/Fund.d.ts +44 -0
  69. package/dist/widget/components/Fund.d.ts.map +1 -0
  70. package/dist/widget/components/Identicon.d.ts +9 -0
  71. package/dist/widget/components/Identicon.d.ts.map +1 -0
  72. package/dist/widget/components/Pay.d.ts +46 -0
  73. package/dist/widget/components/Pay.d.ts.map +1 -0
  74. package/dist/widget/components/Receive.d.ts.map +1 -1
  75. package/dist/widget/components/RecentTokens.d.ts.map +1 -1
  76. package/dist/widget/components/Recipients.d.ts +9 -0
  77. package/dist/widget/components/Recipients.d.ts.map +1 -0
  78. package/dist/widget/components/RefundWarning.d.ts +9 -0
  79. package/dist/widget/components/RefundWarning.d.ts.map +1 -0
  80. package/dist/widget/components/SimpleSwap.d.ts.map +1 -1
  81. package/dist/widget/components/Swap.d.ts.map +1 -1
  82. package/dist/widget/components/SwapSettings.d.ts +1 -5
  83. package/dist/widget/components/SwapSettings.d.ts.map +1 -1
  84. package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
  85. package/dist/widget/components/ThemeSyncer.d.ts +6 -0
  86. package/dist/widget/components/ThemeSyncer.d.ts.map +1 -0
  87. package/dist/widget/components/Toast.d.ts +24 -0
  88. package/dist/widget/components/Toast.d.ts.map +1 -0
  89. package/dist/widget/components/TokenList.d.ts.map +1 -1
  90. package/dist/widget/components/TransactionDetails.d.ts.map +1 -1
  91. package/dist/widget/components/TruncatedAddress.d.ts +2 -0
  92. package/dist/widget/components/TruncatedAddress.d.ts.map +1 -1
  93. package/dist/widget/components/UserPreferences.d.ts +7 -0
  94. package/dist/widget/components/UserPreferences.d.ts.map +1 -0
  95. package/dist/widget/hooks/useBalanceVisible.d.ts +1 -0
  96. package/dist/widget/hooks/useBalanceVisible.d.ts.map +1 -1
  97. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  98. package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
  99. package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
  100. package/dist/widget/hooks/useDebugScreens.d.ts +1 -1
  101. package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
  102. package/dist/widget/hooks/useDefaultTokenSelection.d.ts +54 -0
  103. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -0
  104. package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
  105. package/dist/widget/hooks/usePayMessage.d.ts +34 -0
  106. package/dist/widget/hooks/usePayMessage.d.ts.map +1 -0
  107. package/dist/widget/hooks/useRecipients.d.ts +17 -0
  108. package/dist/widget/hooks/useRecipients.d.ts.map +1 -0
  109. package/dist/widget/hooks/useSelectedRecipient.d.ts +12 -0
  110. package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -0
  111. package/dist/widget/hooks/useSendForm.d.ts +2 -0
  112. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  113. package/dist/widget/hooks/useSwapAmount.d.ts +13 -0
  114. package/dist/widget/hooks/useSwapAmount.d.ts.map +1 -0
  115. package/dist/widget/hooks/useSwapSettings.d.ts +16 -0
  116. package/dist/widget/hooks/useSwapSettings.d.ts.map +1 -0
  117. package/dist/widget/hooks/useTargetAmount.d.ts +5 -0
  118. package/dist/widget/hooks/useTargetAmount.d.ts.map +1 -0
  119. package/dist/widget/hooks/useTheme.d.ts +14 -0
  120. package/dist/widget/hooks/useTheme.d.ts.map +1 -0
  121. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  122. package/dist/widget/index.js +2 -2
  123. package/dist/widget/widget.d.ts +9 -0
  124. package/dist/widget/widget.d.ts.map +1 -1
  125. package/package.json +29 -28
  126. package/src/aave.ts +6 -1
  127. package/src/analytics.ts +103 -53
  128. package/src/apiClient.ts +1 -1
  129. package/src/{proxyCaller.ts → balanceInjector.ts} +22 -17
  130. package/src/cctp.ts +6 -2
  131. package/src/cctpqueue.ts +7 -7
  132. package/src/chains.ts +8 -0
  133. package/src/config.ts +40 -9
  134. package/src/constants.ts +11 -8
  135. package/src/contractUtils.ts +33 -2
  136. package/src/customChains.ts +24 -0
  137. package/src/index.ts +11 -1
  138. package/src/intentEntrypoint.ts +253 -0
  139. package/src/intents.ts +87 -54
  140. package/src/metaTxnMonitor.ts +1 -0
  141. package/src/morpho.ts +13 -2
  142. package/src/pools.ts +68 -86
  143. package/src/prepareSend.ts +437 -207
  144. package/src/prices.ts +51 -7
  145. package/src/relaySdk.ts +6 -4
  146. package/src/relayer.ts +2 -0
  147. package/src/toast.ts +110 -0
  148. package/src/tokenBalances.ts +112 -20
  149. package/src/tokens.ts +70 -7
  150. package/src/trails.ts +80 -77
  151. package/src/trailsClient.ts +45 -0
  152. package/src/transactions.ts +27 -35
  153. package/src/umd.tsx +1 -1
  154. package/src/wallets.ts +2 -1
  155. package/src/widget/assets/sequence-logo.svg +15 -0
  156. package/src/widget/compiled.css +2 -2
  157. package/src/widget/components/AccountActionsDropdown.tsx +18 -159
  158. package/src/widget/components/AccountIntentTransactionHistory.tsx +346 -63
  159. package/src/widget/components/AccountSettings.tsx +96 -0
  160. package/src/widget/components/ChainFilterDropdown.tsx +1 -1
  161. package/src/widget/components/ChainList.tsx +10 -20
  162. package/src/widget/components/ClassicSwap.tsx +923 -0
  163. package/src/widget/components/ConfigDisplay.tsx +8 -5
  164. package/src/widget/components/ConnectedWallets.tsx +260 -0
  165. package/src/widget/components/DebugMenu.tsx +2 -0
  166. package/src/widget/components/DebugScreensList.tsx +3 -0
  167. package/src/widget/components/DebugToast.tsx +63 -0
  168. package/src/widget/components/Earn.tsx +108 -116
  169. package/src/widget/components/EarnPools.tsx +2 -4
  170. package/src/widget/components/EarnPoolsFilters.tsx +6 -6
  171. package/src/widget/components/Fund.tsx +1245 -0
  172. package/src/widget/components/FundMethods.tsx +1 -1
  173. package/src/widget/components/FundSendForm.tsx +1 -1
  174. package/src/widget/components/Identicon.tsx +158 -0
  175. package/src/widget/components/Pay.tsx +1088 -0
  176. package/src/widget/components/PaySendForm.tsx +1 -1
  177. package/src/widget/components/QuoteDetails.tsx +1 -1
  178. package/src/widget/components/Receipt.tsx +1 -1
  179. package/src/widget/components/Receive.tsx +4 -2
  180. package/src/widget/components/RecentTokens.tsx +2 -1
  181. package/src/widget/components/Recipients.tsx +448 -0
  182. package/src/widget/components/RefundWarning.tsx +61 -0
  183. package/src/widget/components/ScreenHeader.tsx +1 -1
  184. package/src/widget/components/SimpleSwap.tsx +74 -58
  185. package/src/widget/components/Swap.tsx +35 -853
  186. package/src/widget/components/SwapSettings.tsx +5 -11
  187. package/src/widget/components/ThemeProvider.tsx +32 -0
  188. package/src/widget/components/ThemeSyncer.tsx +47 -0
  189. package/src/widget/components/Toast.tsx +315 -0
  190. package/src/widget/components/TokenList.tsx +2 -34
  191. package/src/widget/components/TokenSelector.tsx +3 -3
  192. package/src/widget/components/TransactionDetails.tsx +153 -13
  193. package/src/widget/components/TruncatedAddress.tsx +5 -1
  194. package/src/widget/components/UserPreferences.tsx +156 -0
  195. package/src/widget/components/WalletList.tsx +1 -1
  196. package/src/widget/hooks/useBalanceVisible.tsx +40 -2
  197. package/src/widget/hooks/useCheckout.ts +13 -0
  198. package/src/widget/hooks/useCurrentScreen.tsx +3 -0
  199. package/src/widget/hooks/useDebugScreens.ts +12 -2
  200. package/src/widget/hooks/useDefaultTokenSelection.tsx +475 -0
  201. package/src/widget/hooks/useIntentTransactionHistory.ts +212 -0
  202. package/src/widget/hooks/usePayMessage.tsx +370 -0
  203. package/src/widget/hooks/useRecipients.ts +168 -0
  204. package/src/widget/hooks/useSelectedRecipient.tsx +48 -0
  205. package/src/widget/hooks/useSendForm.ts +179 -26
  206. package/src/widget/hooks/useSwapAmount.tsx +50 -0
  207. package/src/widget/hooks/useSwapSettings.tsx +100 -0
  208. package/src/widget/hooks/useTargetAmount.ts +23 -0
  209. package/src/widget/hooks/useTheme.tsx +80 -0
  210. package/src/widget/hooks/useTokenList.ts +20 -11
  211. package/src/widget/index.css +45 -21
  212. package/src/widget/widget.tsx +164 -68
  213. package/dist/address.d.ts +0 -2
  214. package/dist/address.d.ts.map +0 -1
  215. package/dist/proxyCaller.d.ts.map +0 -1
  216. package/src/address.ts +0 -6
package/src/intents.ts CHANGED
@@ -5,8 +5,9 @@ import type {
5
5
  GetIntentCallsPayloadsReturn,
6
6
  IntentCallsPayload,
7
7
  IntentPrecondition,
8
- SequenceAPIClient,
9
8
  } from "@0xsequence/trails-api"
9
+ import type { TrailsAPIClient } from "@0xsequence/trails-api"
10
+ import type { TrailsClient } from "./trailsClient.js"
10
11
  import { logger } from "./logger.js"
11
12
  import { bigintReplacer } from "./utils.js"
12
13
 
@@ -35,9 +36,7 @@ import {
35
36
  import {
36
37
  ATTESATION_SIGNER_ADDRESS,
37
38
  SEQUENCE_V3_CONTRACT_ADDRESSES,
38
- TRAILS_CCTP_SAPIENT_SIGNER_ADDRESS,
39
- TRAILS_LIFI_SAPIENT_SIGNER_ADDRESS,
40
- TRAILS_RELAY_SAPIENT_SIGNER_ADDRESS,
39
+ SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES,
41
40
  } from "./constants.js"
42
41
  import { findPreconditionAddresses } from "./preconditions.js"
43
42
  import { getChainInfo } from "./chains.js"
@@ -129,58 +128,87 @@ export type SendOriginCallTxArgs = {
129
128
  chain: Chain
130
129
  }
131
130
 
132
- export async function getIntentCallsPayloads(
133
- apiClient: SequenceAPIClient,
134
- args: GetIntentCallsPayloadsArgs,
135
- additionalTrackingProps: Record<string, string> = {},
136
- ): Promise<GetIntentCallsPayloadsReturn> {
131
+ export async function getLocalClientIfEnabled(
132
+ apiClient: TrailsAPIClient,
133
+ ): Promise<TrailsAPIClient> {
137
134
  const localApiIntent = getQueryParam("localapiintent") === "true"
138
135
  if (localApiIntent) {
139
136
  // for testing local api changes
140
- const { getAPIClient } = await import("./apiClient.js")
141
- apiClient = getAPIClient({
142
- apiUrl: "http://localhost:4422",
137
+ const { getTrailsClient } = await import("./trailsClient.js")
138
+ apiClient = getTrailsClient({
139
+ hostname: "http://localhost:4422",
143
140
  })
144
141
  }
142
+ return apiClient
143
+ }
144
+
145
+ export async function getIntentCallsPayloads(
146
+ apiClient: TrailsAPIClient,
147
+ args: GetIntentCallsPayloadsArgs,
148
+ additionalTrackingProps: Record<string, string> = {},
149
+ ): Promise<GetIntentCallsPayloadsReturn> {
150
+ apiClient = await getLocalClientIfEnabled(apiClient)
145
151
 
146
152
  // Track intent quote request
147
153
  trackIntentQuoteRequested({
148
- originChainId: args.originChainId || 0,
149
- destinationChainId: args.destinationChainId || 0,
150
- originTokenAddress: args.originTokenAddress,
151
- destinationTokenAddress: args.destinationTokenAddress,
152
- userAddress: args.userAddress,
154
+ originChainId: args.params.originChainId || 0,
155
+ destinationChainId: args.params.destinationChainId || 0,
156
+ originTokenAddress: args.params.originTokenAddress,
157
+ destinationTokenAddress: args.params.destinationTokenAddress,
158
+ userAddress: args.params.userAddress,
153
159
  ...additionalTrackingProps,
154
160
  })
155
161
 
156
162
  try {
157
163
  logger.console.log("[trails-sdk] getIntentCallsPayloads args:", args)
158
- const result = await apiClient.getIntentCallsPayloads(args)
164
+ const result = await apiClient.getIntentCallsPayloads({
165
+ params: args.params,
166
+ })
159
167
 
160
168
  if (!result) {
161
169
  logger.console.error("[trails-sdk] No result from getIntentCallsPayloads")
162
170
  throw new Error("No result from getIntentCallsPayloads")
163
171
  }
164
172
 
173
+ // Extract precondition amounts
174
+ const originChainId = args.params.originChainId || 0
175
+ const destinationChainId = args.params.destinationChainId || 0
176
+ const originPrecondition = result.payloads.preconditions?.find(
177
+ (p: IntentPrecondition) => Number(p.chainId) === Number(originChainId),
178
+ )
179
+ const destinationPrecondition = result.payloads.preconditions?.find(
180
+ (p: IntentPrecondition) =>
181
+ Number(p.chainId) === Number(destinationChainId),
182
+ )
183
+
165
184
  // Track successful intent quote received
166
185
  trackIntentQuoteReceived({
167
- quoteId: result.originIntentAddress || "unknown",
168
- totalFeeUSD: result.trailsFee?.totalFeeUSD,
169
- trailsFixedFeeUSD: result.trailsFee?.trailsFixedFeeUSD,
170
- crossChainFeeTotalUSD: result.trailsFee?.crossChainFee?.totalFeeUSD,
171
- takerFeeUSD: result.trailsFee?.crossChainFee?.providerFeeUSD,
172
- providerFeeUSD: result.trailsFee?.crossChainFee?.providerFeeUSD,
173
- trailsSwapFeeUSD: result.trailsFee?.crossChainFee?.trailsSwapFeeUSD,
186
+ quoteId: result.payloads.originIntentAddress || "unknown",
187
+ totalFeeUSD: result.payloads.trailsFee?.totalFeeUSD,
188
+ trailsFixedFeeUSD: result.payloads.trailsFee?.trailsFixedFeeUSD,
189
+ crossChainFeeTotalUSD:
190
+ result.payloads.trailsFee?.crossChainFee?.totalFeeUSD,
191
+ takerFeeUSD: result.payloads.trailsFee?.takerFeeUSD,
192
+ providerFeeUSD: result.payloads.trailsFee?.crossChainFee?.providerFeeUSD,
193
+ trailsSwapFeeUSD:
194
+ result.payloads.trailsFee?.crossChainFee?.trailsSwapFeeUSD,
174
195
  gasFeesPerChainUSD:
175
- result.trailsFee?.executeQuote?.chainQuotes?.map((quote: any) =>
176
- parseFloat(quote.totalFeeUSD || "0"),
196
+ result.payloads.trailsFee?.executeQuote?.chainQuotes?.map(
197
+ (quote: any) => parseFloat(quote.totalFeeUSD || "0"),
177
198
  ) || [],
178
- originTokenTotalAmount: result.trailsFee?.originTokenTotalAmount,
179
- destinationTokenAmount: result.trailsFee?.totalFeeAmount, // Using available property
180
- provider: result.trailsFee?.quoteProvider,
181
- feeToken: result.trailsFee?.feeToken,
182
- userAddress: args.userAddress,
183
- intentAddress: result.originIntentAddress,
199
+ originTokenTotalAmount: result.payloads.trailsFee?.originTokenTotalAmount,
200
+ totalFeeAmount: result.payloads.trailsFee?.totalFeeAmount, // Using available property
201
+ provider: result.payloads.trailsFee?.quoteProvider,
202
+ feeToken: result.payloads.trailsFee?.feeToken,
203
+ userAddress: args.params.userAddress,
204
+ intentAddress: result.payloads.originIntentAddress,
205
+ originPreconditionAmount: originPrecondition?.data?.min?.toString(),
206
+ destinationPreconditionAmount:
207
+ destinationPrecondition?.data?.min?.toString(),
208
+ fromAmount: result.payloads.quote?.fromAmount,
209
+ fromAmountMin: result.payloads.quote?.fromAmountMin,
210
+ toAmount: result.payloads.quote?.toAmount,
211
+ toAmountMin: result.payloads.quote?.toAmountMin,
184
212
  ...additionalTrackingProps,
185
213
  })
186
214
 
@@ -190,11 +218,11 @@ export async function getIntentCallsPayloads(
190
218
  // Track intent quote error
191
219
  trackIntentQuoteError({
192
220
  error: getFullErrorMessage(error),
193
- userAddress: args.userAddress,
194
- originChainId: args.originChainId || 0,
195
- destinationChainId: args.destinationChainId || 0,
196
- originTokenAddress: args.originTokenAddress,
197
- destinationTokenAddress: args.destinationTokenAddress,
221
+ userAddress: args.params.userAddress,
222
+ originChainId: args.params.originChainId || 0,
223
+ destinationChainId: args.params.destinationChainId || 0,
224
+ originTokenAddress: args.params.originTokenAddress,
225
+ destinationTokenAddress: args.params.destinationTokenAddress,
198
226
  ...additionalTrackingProps,
199
227
  })
200
228
  throw error
@@ -277,13 +305,15 @@ export function calculateOriginAndDestinationIntentAddresses(
277
305
  }
278
306
 
279
307
  export async function commitIntentConfig(
280
- apiClient: SequenceAPIClient,
308
+ apiClient: TrailsClient,
281
309
  mainSignerAddress: string,
282
310
  calls: Array<IntentCallsPayload>,
283
311
  preconditions: Array<IntentPrecondition>,
284
312
  additionalTrackingProps: Record<string, string> = {},
285
313
  requestParams?: IntentRequestParams,
286
314
  ): Promise<CommitIntentConfigReturn> {
315
+ apiClient = await getLocalClientIfEnabled(apiClient)
316
+
287
317
  logger.console.log("[trails-sdk] commitIntentConfig inputs:", {
288
318
  mainSignerAddress,
289
319
  calls: JSON.stringify(calls, bigintReplacer, 2),
@@ -336,12 +366,21 @@ export async function commitIntentConfig(
336
366
  isAddressEqual(Address.from(receivedAddress), originIntentAddress),
337
367
  })
338
368
 
369
+ const addressOverrides = SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES
370
+
339
371
  const args: CommitIntentConfigArgs = {
340
- originIntentAddress: originIntentAddress.toString(),
341
- destinationIntentAddress: destinationIntentAddress.toString(),
342
- mainSigner: mainSignerAddress,
343
- calls: calls,
344
- preconditions: preconditions,
372
+ params: {
373
+ originIntentAddress: originIntentAddress.toString(),
374
+ destinationIntentAddress: destinationIntentAddress.toString(),
375
+ mainSigner: mainSignerAddress,
376
+ calls: calls,
377
+ preconditions: preconditions,
378
+ addressOverrides: addressOverrides,
379
+ requestParams: {
380
+ version: "1.0",
381
+ ...requestParams,
382
+ } as any,
383
+ },
345
384
  }
346
385
 
347
386
  // Add request parameters if provided
@@ -370,13 +409,6 @@ export async function commitIntentConfig(
370
409
  // This will need to be updated when the API client is regenerated
371
410
  }
372
411
 
373
- const addressOverrides = {
374
- trailsLiFiSapientSignerAddress: TRAILS_LIFI_SAPIENT_SIGNER_ADDRESS,
375
- trailsRelaySapientSignerAddress: TRAILS_RELAY_SAPIENT_SIGNER_ADDRESS,
376
- trailsCCTPV2SapientSignerAddress: TRAILS_CCTP_SAPIENT_SIGNER_ADDRESS,
377
- ...args.addressOverrides,
378
- }
379
-
380
412
  try {
381
413
  // Track successful intent commit
382
414
  trackIntentCommitStarted({
@@ -391,8 +423,6 @@ export async function commitIntentConfig(
391
423
 
392
424
  const result = await apiClient.commitIntentConfig({
393
425
  ...args,
394
- addressOverrides,
395
- // requestParams: requestParams, // TODO
396
426
  })
397
427
 
398
428
  // Track successful intent commit
@@ -458,13 +488,16 @@ export async function sendOriginTransaction(
458
488
  transport: http(),
459
489
  })
460
490
 
461
- const gasLimit = await publicClient.estimateGas({
491
+ const estimatedGasLimit = await publicClient.estimateGas({
462
492
  account: account,
463
493
  to: originParams.to as `0x${string}`,
464
494
  data: originParams.data as `0x${string}`,
465
495
  value: BigInt(originParams.value),
466
496
  })
467
497
 
498
+ const gsaBuffer = BigInt(50_000)
499
+ const gasLimit = estimatedGasLimit + gsaBuffer
500
+
468
501
  logger.console.log("[trails-sdk] estimated gasLimit:", gasLimit)
469
502
 
470
503
  logger.console.log(
@@ -92,6 +92,7 @@ export const useMetaTxnsMonitor = (
92
92
  }
93
93
  return newStatusEntry
94
94
  },
95
+ refetchIntervalInBackground: true,
95
96
  refetchInterval: (
96
97
  query: Query<
97
98
  Relayer.OperationStatus,
package/src/morpho.ts CHANGED
@@ -295,11 +295,22 @@ function transformVaultToPool(vaultData: any): Pool | null {
295
295
  // Use the actual APY from the API
296
296
  const apy = state?.apy || state?.netApy || 0
297
297
 
298
+ const decimals = asset?.decimals
299
+ if (!decimals) {
300
+ // logger.console.warn("Decimals not found", {
301
+ // asset,
302
+ // state,
303
+ // vaultData,
304
+ // chainId,
305
+ // })
306
+ return null
307
+ }
308
+
298
309
  // Calculate TVL from totalAssetsUsd if available, otherwise from totalAssets
299
310
  const tvl = state?.totalAssetsUsd
300
311
  ? Number(state.totalAssetsUsd)
301
312
  : state?.totalAssets
302
- ? Number(state.totalAssets) / 10 ** (asset?.decimals || 18)
313
+ ? Number(state.totalAssets) / 10 ** decimals
303
314
  : 0
304
315
 
305
316
  // Filter out vaults with TVL < 1M OR APY > 20%
@@ -324,7 +335,7 @@ function transformVaultToPool(vaultData: any): Pool | null {
324
335
  symbol: vaultData.symbol || asset?.symbol || "UNKNOWN",
325
336
  name: vaultData.name || asset?.name || "Unknown Token",
326
337
  address: asset?.address || vaultData.address,
327
- decimals: asset?.decimals || 18,
338
+ decimals,
328
339
  logoUrl: asset?.logoURI || undefined,
329
340
  },
330
341
  depositAddress: vaultData.address,
package/src/pools.ts CHANGED
@@ -1,19 +1,9 @@
1
- import { useMemo, useEffect } from "react"
1
+ import { useMemo } from "react"
2
+ import { useQuery } from "@tanstack/react-query"
2
3
  import { useAavePools } from "./aave.js"
3
4
  import { useMorphoVaults } from "./morpho.js"
4
5
  import { logger } from "./logger.js"
5
6
 
6
- // Cache configuration
7
- const CACHE_DURATION = 5 * 60 * 1000 // 5 minutes in milliseconds
8
-
9
- // Global cache for pools data
10
- let poolsCache: {
11
- data: Pool[]
12
- timestamp: number
13
- aaveData: Pool[] | null
14
- morphoData: Pool[] | null
15
- } | null = null
16
-
17
7
  // Pool data interface (shared across all protocols)
18
8
  export interface Pool {
19
9
  id: string
@@ -36,7 +26,7 @@ export interface Pool {
36
26
  wrappedTokenGatewayAddress?: string
37
27
  }
38
28
 
39
- export function usePools() {
29
+ export function usePools({ enabled = true }: { enabled?: boolean } = {}) {
40
30
  // Fetch pools from Aave
41
31
  const {
42
32
  data: aavePools,
@@ -51,31 +41,18 @@ export function usePools() {
51
41
  error: morphoError,
52
42
  } = useMorphoVaults()
53
43
 
54
- // Check if cache is valid
55
- const isCacheValid = useMemo(() => {
56
- if (!poolsCache) return false
57
-
58
- const now = Date.now()
59
- const isExpired = now - poolsCache.timestamp > CACHE_DURATION
60
-
61
- // Check if underlying data has changed
62
- const aaveDataChanged =
63
- JSON.stringify(poolsCache.aaveData) !== JSON.stringify(aavePools)
64
- const morphoDataChanged =
65
- JSON.stringify(poolsCache.morphoData) !== JSON.stringify(morphoPools)
66
-
67
- return !isExpired && !aaveDataChanged && !morphoDataChanged
68
- }, [aavePools, morphoPools])
44
+ // Combine pools data with memoization
45
+ const combinedPools = useMemo(() => {
46
+ // Don't process if not enabled
47
+ if (!enabled) {
48
+ return []
49
+ }
69
50
 
70
- // Combine and transform all pools with caching
71
- const allPools: Pool[] = useMemo(() => {
72
- // Return cached data if valid
73
- if (isCacheValid && poolsCache) {
74
- logger.console.log("[trails-sdk] Using cached pools data")
75
- return poolsCache.data
51
+ if (!aavePools && !morphoPools) {
52
+ return []
76
53
  }
77
54
 
78
- logger.console.log("[trails-sdk] Generating new pools data")
55
+ logger.console.log("[trails-sdk] Combining pools data from sources")
79
56
  const pools: Pool[] = []
80
57
 
81
58
  // Add Aave pools
@@ -88,68 +65,73 @@ export function usePools() {
88
65
  pools.push(...morphoPools)
89
66
  }
90
67
 
91
- // Update cache
92
- poolsCache = {
93
- data: pools,
94
- timestamp: Date.now(),
95
- aaveData: aavePools,
96
- morphoData: morphoPools,
68
+ // Sort by APY descending
69
+ const sortedPools = pools.sort((a: Pool, b: Pool) => b.apy - a.apy)
70
+
71
+ logger.console.log(
72
+ "[trails-sdk] Combined and sorted",
73
+ sortedPools.length,
74
+ "pools",
75
+ )
76
+ return sortedPools
77
+ }, [aavePools, morphoPools, enabled])
78
+
79
+ // Use React Query for caching the combined pools data
80
+ const { data: cachedPools } = useQuery({
81
+ queryKey: ["pools", "combined", combinedPools.length, enabled],
82
+ queryFn: async () => {
83
+ return combinedPools
84
+ },
85
+ enabled: enabled && combinedPools.length > 0,
86
+ staleTime: 5 * 60 * 1000, // 5 minutes
87
+ gcTime: 10 * 60 * 1000, // 10 minutes
88
+ refetchOnWindowFocus: false,
89
+ refetchIntervalInBackground: true,
90
+ refetchOnReconnect: true,
91
+ retry: 2,
92
+ initialData: combinedPools.length > 0 ? combinedPools : undefined,
93
+ })
94
+
95
+ // Determine loading state
96
+ const loading = useMemo(() => {
97
+ // If not enabled, never show loading
98
+ if (!enabled) {
99
+ return false
97
100
  }
98
101
 
99
- return pools
100
- }, [aavePools, morphoPools, isCacheValid])
101
-
102
- // Determine overall loading and error states
103
- const loading = useMemo(() => {
104
- // Don't show loading if we have valid cached data
105
- if (isCacheValid && poolsCache) {
102
+ // If we have cached data, never show loading (this is the key fix!)
103
+ if (cachedPools && cachedPools.length > 0) {
104
+ logger.console.log("[trails-sdk] Using cached pools, not showing loading")
106
105
  return false
107
106
  }
108
- return aaveLoading || morphoLoading
109
- }, [aaveLoading, morphoLoading, isCacheValid])
110
107
 
108
+ // Show loading if sources are still loading
109
+ const shouldShowLoading = aaveLoading || morphoLoading
110
+
111
+ if (shouldShowLoading) {
112
+ logger.console.log("[trails-sdk] Showing loading - sources still loading")
113
+ }
114
+
115
+ return shouldShowLoading
116
+ }, [aaveLoading, morphoLoading, cachedPools, enabled])
117
+
118
+ // Determine error state
111
119
  const error = useMemo(() => {
112
- // Don't show error if we have valid cached data
113
- if (isCacheValid && poolsCache) {
120
+ // If not enabled, don't show errors
121
+ if (!enabled) {
114
122
  return null
115
123
  }
116
- return aaveError || morphoError
117
- }, [aaveError, morphoError, isCacheValid])
118
-
119
- // Sort by APY descending with caching
120
- const sortedPools = useMemo(() => {
121
- return allPools.sort((a: Pool, b: Pool) => b.apy - a.apy)
122
- }, [allPools])
123
-
124
- // Clear cache when there are errors
125
- useEffect(() => {
126
- if (aaveError || morphoError) {
127
- logger.console.log("[trails-sdk] Clearing cache due to errors")
128
- poolsCache = null
124
+
125
+ // If we have cached data, don't show errors
126
+ if (cachedPools && cachedPools.length > 0) {
127
+ return null
129
128
  }
130
- }, [aaveError, morphoError])
131
-
132
- // logger.console.log("[trails-sdk] === COMBINED POOLS DEBUG ===")
133
- // logger.console.log("[trails-sdk] Cache valid:", isCacheValid)
134
- // logger.console.log("[trails-sdk] Aave pools count:", aavePools?.length || 0)
135
- // logger.console.log("[trails-sdk] Morpho pools count:", morphoPools?.length || 0)
136
- // logger.console.log("[trails-sdk] Total pools count:", sortedPools.length)
137
- // logger.console.log(
138
- // "[trails-sdk] Loading states - Aave:",
139
- // aaveLoading,
140
- // "Morpho:",
141
- // morphoLoading,
142
- // )
143
- // logger.console.log(
144
- // "[trails-sdk] Error states - Aave:",
145
- // aaveError,
146
- // "Morpho:",
147
- // morphoError,
148
- // )
149
- // logger.console.log("[trails-sdk] ==============================")
129
+
130
+ return aaveError || morphoError
131
+ }, [aaveError, morphoError, cachedPools, enabled])
150
132
 
151
133
  return {
152
- data: sortedPools,
134
+ data: cachedPools || [],
153
135
  loading,
154
136
  error,
155
137
  }