0xtrails 0.2.5 → 0.3.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 (267) hide show
  1. package/dist/aave.d.ts +2 -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-CXlshvBY.js → ccip-BMB3uDZt.js} +1 -1
  6. package/dist/config.d.ts +0 -5
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/constants.d.ts +4 -4
  9. package/dist/constants.d.ts.map +1 -1
  10. package/dist/error.d.ts +4 -1
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/fees.d.ts +19 -0
  13. package/dist/fees.d.ts.map +1 -0
  14. package/dist/{index-_QuyGrjU.js → index-QXPUrZVv.js} +48719 -50852
  15. package/dist/index.d.ts +9 -8
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +811 -784
  18. package/dist/intentReceiptMonitor.d.ts +24 -0
  19. package/dist/intentReceiptMonitor.d.ts.map +1 -0
  20. package/dist/intentReceiptPoller.d.ts +69 -0
  21. package/dist/intentReceiptPoller.d.ts.map +1 -0
  22. package/dist/intents.d.ts +15 -11
  23. package/dist/intents.d.ts.map +1 -1
  24. package/dist/morpho.d.ts +6 -5
  25. package/dist/morpho.d.ts.map +1 -1
  26. package/dist/mutations.d.ts +16 -0
  27. package/dist/mutations.d.ts.map +1 -0
  28. package/dist/preconditions.d.ts +5 -4
  29. package/dist/preconditions.d.ts.map +1 -1
  30. package/dist/prepareSend.d.ts +7 -258
  31. package/dist/prepareSend.d.ts.map +1 -1
  32. package/dist/prices.d.ts +9 -6
  33. package/dist/prices.d.ts.map +1 -1
  34. package/dist/sequenceWallet.d.ts +3 -16
  35. package/dist/sequenceWallet.d.ts.map +1 -1
  36. package/dist/tokenBalances.d.ts +17 -13
  37. package/dist/tokenBalances.d.ts.map +1 -1
  38. package/dist/trails.d.ts +24 -40
  39. package/dist/trails.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 +6 -3
  85. package/dist/transactions.d.ts.map +1 -1
  86. package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
  87. package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
  88. package/dist/widget/components/AccountSettings.d.ts.map +1 -1
  89. package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
  90. package/dist/widget/components/ClassicSwap.d.ts +2 -3
  91. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  92. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  93. package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
  94. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
  95. package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
  96. package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
  97. package/dist/widget/components/DynamicSizeInputField.d.ts +13 -0
  98. package/dist/widget/components/DynamicSizeInputField.d.ts.map +1 -0
  99. package/dist/widget/components/Earn.d.ts +2 -3
  100. package/dist/widget/components/Earn.d.ts.map +1 -1
  101. package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
  102. package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
  103. package/dist/widget/components/FeeBreakdown.d.ts +9 -0
  104. package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
  105. package/dist/widget/components/FeeOptions.d.ts +5 -13
  106. package/dist/widget/components/FeeOptions.d.ts.map +1 -1
  107. package/dist/widget/components/Fund.d.ts +2 -3
  108. package/dist/widget/components/Fund.d.ts.map +1 -1
  109. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  110. package/dist/widget/components/FundSwap.d.ts +2 -3
  111. package/dist/widget/components/FundSwap.d.ts.map +1 -1
  112. package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
  113. package/dist/widget/components/Identicon.d.ts.map +1 -1
  114. package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
  115. package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
  116. package/dist/widget/components/Modal.d.ts.map +1 -1
  117. package/dist/widget/components/Pay.d.ts +2 -3
  118. package/dist/widget/components/Pay.d.ts.map +1 -1
  119. package/dist/widget/components/PoolDeposit.d.ts +3 -3
  120. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  121. package/dist/widget/components/PoolWithdraw.d.ts +3 -20
  122. package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
  123. package/dist/widget/components/QuoteDetails.d.ts +2 -0
  124. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  125. package/dist/widget/components/Receipt.d.ts.map +1 -1
  126. package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
  127. package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
  128. package/dist/widget/components/Swap.d.ts +2 -3
  129. package/dist/widget/components/Swap.d.ts.map +1 -1
  130. package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
  131. package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
  132. package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
  133. package/dist/widget/components/TokenSelector.d.ts.map +1 -1
  134. package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -1
  135. package/dist/widget/components/Tooltip.d.ts +9 -0
  136. package/dist/widget/components/Tooltip.d.ts.map +1 -0
  137. package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
  138. package/dist/widget/components/WaasFeeOptions.d.ts +1 -0
  139. package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
  140. package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
  141. package/dist/widget/components/WalletConnect.d.ts.map +1 -1
  142. package/dist/widget/css/compiled.css +2 -2
  143. package/dist/widget/hooks/useCheckout.d.ts +17 -4
  144. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  145. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
  146. package/dist/widget/hooks/useQuote.d.ts +82 -0
  147. package/dist/widget/hooks/useQuote.d.ts.map +1 -0
  148. package/dist/widget/hooks/useSelectedFeeToken.d.ts +1 -0
  149. package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -1
  150. package/dist/widget/hooks/useSendForm.d.ts +5 -6
  151. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  152. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  153. package/dist/widget/hooks/useWalletConnectionContext.d.ts +25 -0
  154. package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +1 -0
  155. package/dist/widget/index.js +2 -2
  156. package/dist/widget/widget.d.ts +17 -7
  157. package/dist/widget/widget.d.ts.map +1 -1
  158. package/package.json +19 -21
  159. package/src/aave.ts +54 -1
  160. package/src/abortController.ts +35 -0
  161. package/src/config.ts +57 -58
  162. package/src/constants.ts +11 -9
  163. package/src/error.ts +21 -3
  164. package/src/fees.ts +210 -0
  165. package/src/index.ts +35 -13
  166. package/src/intentReceiptMonitor.ts +102 -0
  167. package/src/intentReceiptPoller.ts +299 -0
  168. package/src/intents.ts +205 -171
  169. package/src/morpho.ts +58 -9
  170. package/src/mutations.ts +129 -0
  171. package/src/preconditions.ts +16 -21
  172. package/src/prepareSend.ts +92 -4699
  173. package/src/prices.ts +26 -22
  174. package/src/relaySdk.ts +2 -2
  175. package/src/sequenceWallet.ts +6 -73
  176. package/src/tokenBalances.ts +175 -69
  177. package/src/trails.ts +230 -722
  178. package/src/transactionIntent/constants.ts +11 -0
  179. package/src/transactionIntent/deposits/depositOrchestrator.ts +210 -0
  180. package/src/transactionIntent/deposits/gaslessDeposit.ts +588 -0
  181. package/src/transactionIntent/deposits/index.ts +3 -0
  182. package/src/transactionIntent/deposits/standardDeposit.ts +379 -0
  183. package/src/transactionIntent/execution/index.ts +1 -0
  184. package/src/transactionIntent/execution/transactionState.ts +35 -0
  185. package/src/transactionIntent/handlers/crossChain.ts +1707 -0
  186. package/src/transactionIntent/handlers/index.ts +3 -0
  187. package/src/transactionIntent/handlers/sameChainDifferentToken.ts +323 -0
  188. package/src/transactionIntent/handlers/sameChainSameToken.ts +712 -0
  189. package/src/transactionIntent/index.ts +9 -0
  190. package/src/transactionIntent/quote/feeExtractors.ts +81 -0
  191. package/src/transactionIntent/quote/index.ts +3 -0
  192. package/src/transactionIntent/quote/normalizeQuote.ts +367 -0
  193. package/src/transactionIntent/quote/quoteHelpers.ts +53 -0
  194. package/src/transactionIntent/types.ts +157 -0
  195. package/src/transactionIntent/utils/balanceChecker.ts +96 -0
  196. package/src/transactionIntent/utils/index.ts +3 -0
  197. package/src/transactionIntent/utils/lifiHelpers.ts +68 -0
  198. package/src/transactionIntent/utils/testnetHelpers.ts +10 -0
  199. package/src/transactionIntent/validators.ts +57 -0
  200. package/src/transactions.ts +98 -71
  201. package/src/widget/compiled.css +2 -2
  202. package/src/widget/components/AccountIntentTransactionHistory.tsx +36 -36
  203. package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
  204. package/src/widget/components/AccountSettings.tsx +70 -41
  205. package/src/widget/components/ChainFilterDropdown.tsx +24 -3
  206. package/src/widget/components/ClassicSwap.tsx +44 -107
  207. package/src/widget/components/ConfigDisplay.tsx +0 -11
  208. package/src/widget/components/ConnectWallet.tsx +4 -1
  209. package/src/widget/components/ConnectedWallets.tsx +51 -25
  210. package/src/widget/components/DynamicInputStyles.tsx +76 -0
  211. package/src/widget/components/DynamicSizeInputField.tsx +109 -0
  212. package/src/widget/components/Earn.tsx +34 -45
  213. package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
  214. package/src/widget/components/FeeBreakdown.tsx +155 -0
  215. package/src/widget/components/FeeOption.tsx +2 -2
  216. package/src/widget/components/FeeOptions.tsx +151 -112
  217. package/src/widget/components/Fund.tsx +10 -29
  218. package/src/widget/components/FundMethods.tsx +4 -3
  219. package/src/widget/components/FundSwap.tsx +2 -3
  220. package/src/widget/components/FundingMethodSelectorButton.tsx +24 -14
  221. package/src/widget/components/Identicon.tsx +164 -95
  222. package/src/widget/components/MeshConnectExchanges.tsx +2 -15
  223. package/src/widget/components/Modal.tsx +0 -12
  224. package/src/widget/components/Pay.tsx +72 -75
  225. package/src/widget/components/PoolDeposit.tsx +221 -242
  226. package/src/widget/components/PoolWithdraw.tsx +347 -469
  227. package/src/widget/components/PriceImpactWarning.tsx +1 -1
  228. package/src/widget/components/QuoteDetails.tsx +906 -484
  229. package/src/widget/components/Receipt.tsx +16 -2
  230. package/src/widget/components/RecipientSelectorButton.tsx +7 -5
  231. package/src/widget/components/Recipients.tsx +1 -1
  232. package/src/widget/components/ScreenHeader.tsx +60 -36
  233. package/src/widget/components/Swap.tsx +2 -3
  234. package/src/widget/components/ThemeProvider.tsx +2 -1
  235. package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
  236. package/src/widget/components/TokenImage.tsx +1 -1
  237. package/src/widget/components/TokenSelector.tsx +62 -53
  238. package/src/widget/components/TokenSelectorButton.tsx +38 -15
  239. package/src/widget/components/Tooltip.tsx +51 -0
  240. package/src/widget/components/TransferPendingVertical.tsx +12 -8
  241. package/src/widget/components/WaasFeeOptions.tsx +139 -4
  242. package/src/widget/components/WalletConfirmation.tsx +23 -13
  243. package/src/widget/components/WalletConnect.tsx +93 -29
  244. package/src/widget/hooks/useAmountUsd.ts +9 -9
  245. package/src/widget/hooks/useCheckout.ts +97 -9
  246. package/src/widget/hooks/useDefaultTokenSelection.tsx +27 -21
  247. package/src/widget/hooks/useQuote.ts +466 -0
  248. package/src/widget/hooks/useSelectedFeeToken.tsx +32 -37
  249. package/src/widget/hooks/useSendForm.ts +45 -51
  250. package/src/widget/hooks/useTokenList.ts +34 -26
  251. package/src/widget/hooks/useWalletConnectionContext.tsx +128 -0
  252. package/src/widget/widget.tsx +365 -390
  253. package/dist/apiClient.d.ts +0 -9
  254. package/dist/apiClient.d.ts.map +0 -1
  255. package/dist/intentEntrypoint.d.ts +0 -114
  256. package/dist/intentEntrypoint.d.ts.map +0 -1
  257. package/dist/metaTxnMonitor.d.ts +0 -15
  258. package/dist/metaTxnMonitor.d.ts.map +0 -1
  259. package/dist/metaTxns.d.ts +0 -11
  260. package/dist/metaTxns.d.ts.map +0 -1
  261. package/dist/relayer.d.ts +0 -43
  262. package/dist/relayer.d.ts.map +0 -1
  263. package/src/apiClient.ts +0 -35
  264. package/src/intentEntrypoint.ts +0 -203
  265. package/src/metaTxnMonitor.ts +0 -171
  266. package/src/metaTxns.ts +0 -45
  267. package/src/relayer.ts +0 -289
package/src/intents.ts CHANGED
@@ -1,19 +1,21 @@
1
1
  import type {
2
- CommitIntentConfigArgs,
3
- CommitIntentConfigReturn,
4
- GetIntentCallsPayloadsArgs,
5
- GetIntentCallsPayloadsReturn,
6
- IntentCallsPayload,
7
- IntentPrecondition,
2
+ QuoteIntentRequest,
3
+ CommitIntentResponse,
4
+ Intent,
5
+ IntentCalls,
6
+ TransactionPrecondition,
7
+ TrailsAPIClient,
8
+ ExecuteIntentRequest,
9
+ GasFeeOptions,
10
+ DepositSignature,
8
11
  } from "@0xsequence/trails-api"
9
- import type { TrailsAPIClient } from "@0xsequence/trails-api"
10
12
  import type { TrailsClient } from "./trailsClient.js"
11
13
  import { logger } from "./logger.js"
12
14
  import { bigintReplacer } from "./utils.js"
13
15
 
14
16
  export type {
15
- IntentCallsPayload,
16
- IntentPrecondition,
17
+ IntentCalls,
18
+ TransactionPrecondition,
17
19
  } from "@0xsequence/trails-api"
18
20
 
19
21
  import { Config, type Context, Payload } from "@0xsequence/wallet-primitives"
@@ -36,7 +38,6 @@ import {
36
38
  import {
37
39
  ATTESATION_SIGNER_ADDRESS,
38
40
  SEQUENCE_V3_CONTRACT_ADDRESSES,
39
- SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES,
40
41
  } from "./constants.js"
41
42
  import { findPreconditionAddresses } from "./preconditions.js"
42
43
  import { getChainInfo } from "./chains.js"
@@ -114,7 +115,7 @@ export interface TrailsFee {
114
115
  // QuoteProvider defines the possible liquidity providers.
115
116
  export type QuoteProvider = "lifi" | "relay" | "cctp"
116
117
 
117
- export type { GetIntentCallsPayloadsReturn }
118
+ export type { Intent }
118
119
 
119
120
  export type OriginCallParams = {
120
121
  to: `0x${string}` | null
@@ -135,98 +136,104 @@ export type SendOriginCallTxArgs = {
135
136
  }
136
137
 
137
138
  export async function getLocalClientIfEnabled(
138
- apiClient: TrailsAPIClient,
139
+ trailsClient: TrailsAPIClient,
139
140
  ): Promise<TrailsAPIClient> {
140
141
  const localApiIntent = getQueryParam("localapiintent") === "true"
141
142
  if (localApiIntent) {
142
143
  // for testing local api changes
143
144
  const { getTrailsClient } = await import("./trailsClient.js")
144
- apiClient = getTrailsClient({
145
+ trailsClient = getTrailsClient({
145
146
  hostname: "http://localhost:4422",
146
147
  })
147
148
  }
148
- return apiClient
149
+ return trailsClient
149
150
  }
150
151
 
151
- export async function getIntentCallsPayloads(
152
- apiClient: TrailsAPIClient,
153
- args: GetIntentCallsPayloadsArgs,
152
+ export async function getIntent(
153
+ trailsClient: TrailsAPIClient,
154
+ args: QuoteIntentRequest,
154
155
  additionalTrackingProps: Record<string, string> = {},
155
- ): Promise<GetIntentCallsPayloadsReturn> {
156
- apiClient = await getLocalClientIfEnabled(apiClient)
156
+ ): Promise<{ intent: Intent; gasFeeOptions?: GasFeeOptions }> {
157
+ trailsClient = await getLocalClientIfEnabled(trailsClient)
157
158
 
158
159
  // Track intent quote request
159
160
  trackIntentQuoteRequested({
160
- originChainId: args.params.originChainId || 0,
161
- destinationChainId: args.params.destinationChainId || 0,
162
- originTokenAddress: args.params.originTokenAddress,
163
- destinationTokenAddress: args.params.destinationTokenAddress,
164
- userAddress: args.params.userAddress,
161
+ originChainId: args.originChainId || 0,
162
+ destinationChainId: args.destinationChainId || 0,
163
+ originTokenAddress: args.originTokenAddress,
164
+ destinationTokenAddress: args.destinationTokenAddress,
165
+ userAddress: args.ownerAddress,
165
166
  ...additionalTrackingProps,
166
167
  })
167
168
 
168
169
  try {
169
- logger.console.log("[trails-sdk] getIntentCallsPayloads args:", args)
170
- const result = await apiClient.getIntentCallsPayloads({
171
- params: args.params,
172
- })
170
+ logger.console.log("[trails-sdk] getIntent args:", args)
171
+ const response = await trailsClient.quoteIntent(args)
173
172
 
174
- if (!result) {
175
- logger.console.error("[trails-sdk] No result from getIntentCallsPayloads")
176
- throw new Error("No result from getIntentCallsPayloads")
173
+ if (!response || !response.intent) {
174
+ logger.console.error("[trails-sdk] No result from quoteIntent")
175
+ throw new Error("No result from quoteIntent")
177
176
  }
178
177
 
178
+ const result = response.intent
179
+
179
180
  // Extract precondition amounts
180
- const originChainId = args.params.originChainId || 0
181
- const destinationChainId = args.params.destinationChainId || 0
182
- const originPrecondition = result.payloads.preconditions?.find(
183
- (p: IntentPrecondition) => Number(p.chainId) === Number(originChainId),
181
+ const originChainId = args.originChainId || 0
182
+ const destinationChainId = args.destinationChainId || 0
183
+ const originPrecondition = result.preconditions?.find(
184
+ (p: TransactionPrecondition) =>
185
+ Number(p.chainId) === Number(originChainId),
184
186
  )
185
- const destinationPrecondition = result.payloads.preconditions?.find(
186
- (p: IntentPrecondition) =>
187
+ const destinationPrecondition = result.preconditions?.find(
188
+ (p: TransactionPrecondition) =>
187
189
  Number(p.chainId) === Number(destinationChainId),
188
190
  )
189
191
 
190
192
  // Track successful intent quote received
191
193
  trackIntentQuoteReceived({
192
- quoteId: result.payloads.originIntentAddress || "unknown",
193
- totalFeeUSD: result.payloads.trailsFee?.totalFeeUSD,
194
- crossChainFeeTotalUSD:
195
- result.payloads.trailsFee?.crossChainFee?.totalFeeUSD,
196
- providerFeeUSD: result.payloads.trailsFee?.crossChainFee?.providerFeeUSD,
197
- trailsSwapFeeUSD:
198
- result.payloads.trailsFee?.crossChainFee?.trailsSwapFeeUSD,
199
- gasFeesPerChainUSD:
200
- result.payloads.trailsFee?.executeQuote?.chainQuotes?.map(
201
- (quote: any) => parseFloat(quote.totalFeeUSD || "0"),
202
- ) || [],
203
- originTokenTotalAmount: result.payloads.trailsFee?.originTokenTotalAmount,
204
- totalFeeAmount: result.payloads.trailsFee?.totalFeeAmount, // Using available property
205
- provider: result.payloads.trailsFee?.quoteProvider,
206
- feeToken: result.payloads.trailsFee?.feeToken,
207
- userAddress: args.params.userAddress,
208
- intentAddress: result.payloads.originIntentAddress,
209
- originPreconditionAmount: originPrecondition?.data?.min?.toString(),
194
+ quoteId: result.originIntentAddress || "unknown",
195
+ totalFeeUSD: result.fees?.totalFeeUsd?.toString(),
196
+ crossChainFeeTotalUSD: result.fees?.provider?.totalFeeUsd,
197
+ providerFeeUSD: result.fees?.provider?.quoteProviderFeeUsd,
198
+ trailsSwapFeeUSD: result.fees?.provider?.trailsFeeUsd,
199
+ gasFeesPerChainUSD: [
200
+ typeof result.fees?.originGas?.totalFeeUsd === "string"
201
+ ? parseFloat(result.fees.originGas.totalFeeUsd)
202
+ : result.fees?.originGas?.totalFeeUsd || 0,
203
+ typeof result.fees?.destinationGas?.totalFeeUsd === "string"
204
+ ? parseFloat(result.fees.destinationGas.totalFeeUsd)
205
+ : result.fees?.destinationGas?.totalFeeUsd || 0,
206
+ ],
207
+ originTokenTotalAmount: undefined, // This field no longer exists in IntentFees
208
+ totalFeeAmount: result.fees?.totalFeeAmount?.toString(),
209
+ provider: result.quote?.quoteProvider,
210
+ feeToken: result.fees?.feeTokenAddress,
211
+ userAddress: args.ownerAddress,
212
+ intentAddress: result.originIntentAddress,
213
+ originPreconditionAmount: originPrecondition?.minAmount?.toString(),
210
214
  destinationPreconditionAmount:
211
- destinationPrecondition?.data?.min?.toString(),
212
- fromAmount: result.payloads.quote?.fromAmount,
213
- fromAmountMin: result.payloads.quote?.fromAmountMin,
214
- toAmount: result.payloads.quote?.toAmount,
215
- toAmountMin: result.payloads.quote?.toAmountMin,
215
+ destinationPrecondition?.minAmount?.toString(),
216
+ fromAmount: result.quote?.fromAmount?.toString(),
217
+ fromAmountMin: result.quote?.fromAmountMin?.toString(),
218
+ toAmount: result.quote?.toAmount?.toString(),
219
+ toAmountMin: result.quote?.toAmountMin?.toString(),
216
220
  ...additionalTrackingProps,
217
221
  })
218
222
 
219
- return result
223
+ return {
224
+ intent: result,
225
+ gasFeeOptions: response.gasFeeOptions,
226
+ }
220
227
  } catch (error) {
221
- logger.console.error("[trails-sdk] Error in getIntentCallsPayloads", error)
228
+ logger.console.error("[trails-sdk] Error in getIntent", error)
222
229
  // Track intent quote error
223
230
  trackIntentQuoteError({
224
231
  error: getFullErrorMessage(error),
225
- userAddress: args.params.userAddress,
226
- originChainId: args.params.originChainId || 0,
227
- destinationChainId: args.params.destinationChainId || 0,
228
- originTokenAddress: args.params.originTokenAddress,
229
- destinationTokenAddress: args.params.destinationTokenAddress,
232
+ userAddress: args.ownerAddress,
233
+ originChainId: args.originChainId || 0,
234
+ destinationChainId: args.destinationChainId || 0,
235
+ originTokenAddress: args.originTokenAddress,
236
+ destinationTokenAddress: args.destinationTokenAddress,
230
237
  ...additionalTrackingProps,
231
238
  })
232
239
  throw error
@@ -235,7 +242,7 @@ export async function getIntentCallsPayloads(
235
242
 
236
243
  export function calculateIntentAddress(
237
244
  mainSigner: string,
238
- calls: Array<IntentCallsPayload>,
245
+ calls: Array<IntentCalls>,
239
246
  ): `0x${string}` {
240
247
  logger.console.log("[trails-sdk] calculateIntentAddress inputs:", {
241
248
  mainSigner,
@@ -244,25 +251,52 @@ export function calculateIntentAddress(
244
251
 
245
252
  const context = SEQUENCE_V3_CONTRACT_ADDRESSES
246
253
 
247
- const coreCalls = calls.map((call) => ({
248
- type: "call" as const,
249
- chainId: call.chainId.toString(),
250
- space: call.space ? call.space.toString() : "0",
251
- nonce: call.nonce ? call.nonce.toString() : "0",
252
- calls: call.calls.map((call) => ({
253
- to: Address.from(call.to) as `0x${string}`,
254
- value: call.value?.toString() || "0",
255
- data: Bytes.toHex(Bytes.from((call.data as Hex.Hex) || "0x")),
256
- gasLimit: call.gasLimit?.toString() || "0",
257
- delegateCall: !!call.delegateCall,
258
- onlyFallback: !!call.onlyFallback,
259
- behaviorOnError: call.behaviorOnError,
260
- })),
261
- }))
254
+ const coreCalls = calls.map((call) => {
255
+ const chainId =
256
+ typeof call.chainId === "bigint"
257
+ ? call.chainId
258
+ : BigInt(String(call.chainId))
259
+ const space = call.space
260
+ ? typeof call.space === "bigint"
261
+ ? call.space
262
+ : BigInt(String(call.space))
263
+ : 0n
264
+ const nonce = call.nonce
265
+ ? typeof call.nonce === "bigint"
266
+ ? call.nonce
267
+ : BigInt(String(call.nonce))
268
+ : 0n
269
+
270
+ return {
271
+ type: "call" as const,
272
+ chainId,
273
+ space,
274
+ nonce,
275
+ calls: call.calls.map((call) => ({
276
+ to: Address.from(call.to) as `0x${string}`,
277
+ value:
278
+ typeof call.value === "bigint"
279
+ ? call.value
280
+ : call.value
281
+ ? BigInt(String(call.value))
282
+ : 0n,
283
+ data: Bytes.toHex(Bytes.from((call.data as Hex.Hex) || "0x")),
284
+ gasLimit:
285
+ typeof call.gasLimit === "bigint"
286
+ ? call.gasLimit
287
+ : call.gasLimit
288
+ ? BigInt(String(call.gasLimit))
289
+ : 0n,
290
+ delegateCall: !!call.delegateCall,
291
+ onlyFallback: !!call.onlyFallback,
292
+ behaviorOnError: call.behaviorOnError,
293
+ })),
294
+ }
295
+ })
262
296
 
263
297
  const calculatedAddress = calculateIntentConfigurationAddress(
264
298
  Address.from(mainSigner),
265
- coreCalls,
299
+ coreCalls as any, // Type mismatch between local bigint and API number for chainId
266
300
  context,
267
301
  )
268
302
 
@@ -275,7 +309,7 @@ export function calculateIntentAddress(
275
309
 
276
310
  export function calculateOriginAndDestinationIntentAddresses(
277
311
  mainSigner: string,
278
- calls: Array<IntentCallsPayload>,
312
+ calls: Array<IntentCalls>,
279
313
  ) {
280
314
  const originChainId = calls[0]?.chainId
281
315
  const destinationChainId = calls[1]?.chainId || originChainId
@@ -292,7 +326,11 @@ export function calculateOriginAndDestinationIntentAddresses(
292
326
 
293
327
  const originIntentAddress = calculateIntentAddress(mainSigner, originCalls)
294
328
  let destinationIntentAddress = originIntentAddress
295
- if (originChainId !== destinationChainId) {
329
+
330
+ // Calculate separate destination intent address if:
331
+ // 1. Cross-chain scenario (different chain IDs), OR
332
+ // 2. Same-chain with multiple payloads (e.g., custom calldata creates separate origin/destination payloads)
333
+ if (originChainId !== destinationChainId || calls.length > 1) {
296
334
  destinationIntentAddress = calculateIntentAddress(
297
335
  mainSigner,
298
336
  destinationCalls,
@@ -308,55 +346,56 @@ export function calculateOriginAndDestinationIntentAddresses(
308
346
  return { originIntentAddress, destinationIntentAddress }
309
347
  }
310
348
 
311
- export async function commitIntentConfig(
312
- apiClient: TrailsClient,
313
- mainSignerAddress: string,
314
- calls: Array<IntentCallsPayload>,
315
- preconditions: Array<IntentPrecondition>,
349
+ export async function commitIntent(
350
+ trailsClient: TrailsClient,
351
+ intent: Intent,
316
352
  additionalTrackingProps: Record<string, string> = {},
317
- requestParams?: IntentRequestParams,
318
- ): Promise<CommitIntentConfigReturn> {
319
- apiClient = await getLocalClientIfEnabled(apiClient)
320
-
321
- logger.console.log("[trails-sdk] commitIntentConfig inputs:", {
322
- mainSignerAddress,
323
- calls: JSON.stringify(calls, bigintReplacer, 2),
324
- preconditions: JSON.stringify(preconditions, bigintReplacer, 2),
325
- requestParams: JSON.stringify(requestParams, bigintReplacer, 2),
353
+ ): Promise<CommitIntentResponse> {
354
+ trailsClient = await getLocalClientIfEnabled(trailsClient)
355
+
356
+ logger.console.log("[trails-sdk] commitIntent inputs:", {
357
+ intentId: intent.intentId,
358
+ ownerAddress: intent.ownerAddress,
359
+ originIntentAddress: intent.originIntentAddress,
360
+ destinationIntentAddress: intent.destinationIntentAddress,
361
+ calls: JSON.stringify(intent.calls, bigintReplacer, 2),
362
+ preconditions: JSON.stringify(intent.preconditions, bigintReplacer, 2),
326
363
  })
327
364
 
328
365
  // Additional detailed precondition logging
329
- logger.console.log("[trails-sdk] Detailed preconditions:", preconditions)
366
+ logger.console.log(
367
+ "[trails-sdk] Detailed preconditions:",
368
+ intent.preconditions,
369
+ )
330
370
 
331
371
  // Log each precondition individually for easier reading
332
- preconditions.forEach((precondition, index) => {
372
+ intent.preconditions.forEach((precondition, index) => {
333
373
  logger.console.log(`[trails-sdk] Precondition ${index}:`, {
334
374
  type: precondition.type,
335
375
  chainId: precondition.chainId,
336
- data: precondition.data,
376
+ ownerAddress: precondition.ownerAddress,
377
+ tokenAddress: precondition.tokenAddress,
378
+ minAmount: precondition.minAmount?.toString(),
337
379
  })
338
380
  })
339
381
 
340
- const { originIntentAddress, destinationIntentAddress } =
341
- calculateOriginAndDestinationIntentAddresses(mainSignerAddress, calls)
342
-
343
382
  logger.console.log(
344
383
  "[trails-sdk] originIntentAddress:",
345
- originIntentAddress.toString(),
384
+ intent.originIntentAddress,
346
385
  )
347
386
  logger.console.log(
348
387
  "[trails-sdk] destinationIntentAddress:",
349
- destinationIntentAddress.toString(),
388
+ intent.destinationIntentAddress,
350
389
  )
351
390
 
352
- const originChainIdStr = calls[0]?.chainId
353
- const destinationChainIdStr = calls[1]?.chainId
391
+ const originChainIdStr = intent.calls[0]?.chainId
392
+ const destinationChainIdStr = intent.calls[1]?.chainId
354
393
 
355
394
  // The executionInfos could be empty, so we need to handle the undefined case.
356
395
  const { originAddress: receivedAddress } =
357
396
  originChainIdStr && destinationChainIdStr
358
397
  ? findPreconditionAddresses(
359
- preconditions,
398
+ intent.preconditions,
360
399
  Number(originChainIdStr),
361
400
  Number(destinationChainIdStr),
362
401
  )
@@ -364,60 +403,20 @@ export async function commitIntentConfig(
364
403
 
365
404
  logger.console.log("[trails-sdk] Address comparison:", {
366
405
  receivedAddress,
367
- calculatedAddress: originIntentAddress.toString(),
406
+ calculatedAddress: intent.originIntentAddress,
368
407
  match:
369
408
  receivedAddress &&
370
- isAddressEqual(Address.from(receivedAddress), originIntentAddress),
409
+ isAddressEqual(
410
+ Address.from(receivedAddress),
411
+ Address.from(intent.originIntentAddress),
412
+ ),
371
413
  })
372
414
 
373
- const addressOverrides = SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES
374
-
375
- const args: CommitIntentConfigArgs = {
376
- params: {
377
- originIntentAddress: originIntentAddress.toString(),
378
- destinationIntentAddress: destinationIntentAddress.toString(),
379
- mainSigner: mainSignerAddress,
380
- calls: calls,
381
- preconditions: preconditions,
382
- addressOverrides: addressOverrides,
383
- requestParams: {
384
- version: "1.0",
385
- ...requestParams,
386
- } as any,
387
- },
388
- }
389
-
390
- // Add request parameters if provided
391
- if (requestParams) {
392
- // Convert requestParams to the format expected by the backend
393
- const requestParamsForStorage = {
394
- version: "1.0",
395
- userAddress: requestParams.userAddress,
396
- originChainId: requestParams.originChainId,
397
- originTokenAddress: requestParams.originTokenAddress,
398
- originTokenAmount: requestParams.originTokenAmount,
399
- destinationChainId: requestParams.destinationChainId,
400
- destinationToAddress: requestParams.destinationToAddress,
401
- destinationTokenAddress: requestParams.destinationTokenAddress,
402
- destinationTokenAmount: requestParams.destinationTokenAmount,
403
- destinationCallData: requestParams.destinationCallData,
404
- destinationCallValue: requestParams.destinationCallValue,
405
- createdAt: new Date().toISOString(),
406
- }
407
- // Store request params in a way that can be passed to the API
408
- logger.console.log(
409
- "[trails-sdk] Request params for storage:",
410
- requestParamsForStorage,
411
- )
412
- // Note: The current API client doesn't support request params yet
413
- // This will need to be updated when the API client is regenerated
414
- }
415
-
416
415
  try {
417
- // Track successful intent commit
416
+ // Track intent commit start
418
417
  trackIntentCommitStarted({
419
- intentAddress: originIntentAddress.toString(),
420
- userAddress: mainSignerAddress,
418
+ intentAddress: intent.originIntentAddress,
419
+ userAddress: intent.ownerAddress,
421
420
  originChainId: originChainIdStr ? Number(originChainIdStr) : undefined,
422
421
  destinationChainId: destinationChainIdStr
423
422
  ? Number(destinationChainIdStr)
@@ -425,14 +424,13 @@ export async function commitIntentConfig(
425
424
  ...additionalTrackingProps,
426
425
  })
427
426
 
428
- const result = await apiClient.commitIntentConfig({
429
- ...args,
430
- })
427
+ // Commit the intent that was returned from quoteIntent
428
+ const response = await trailsClient.commitIntent({ intent })
431
429
 
432
430
  // Track successful intent commit
433
431
  trackIntentCommitCompleted({
434
- intentAddress: originIntentAddress.toString(),
435
- userAddress: mainSignerAddress,
432
+ intentAddress: intent.originIntentAddress,
433
+ userAddress: intent.ownerAddress,
436
434
  originChainId: originChainIdStr ? Number(originChainIdStr) : undefined,
437
435
  destinationChainId: destinationChainIdStr
438
436
  ? Number(destinationChainIdStr)
@@ -440,13 +438,13 @@ export async function commitIntentConfig(
440
438
  ...additionalTrackingProps,
441
439
  })
442
440
 
443
- return result
441
+ return response
444
442
  } catch (error) {
445
443
  // Track intent commit error
446
444
  trackIntentCommitError({
447
445
  error: getFullErrorMessage(error),
448
- userAddress: mainSignerAddress,
449
- intentAddress: originIntentAddress.toString(),
446
+ userAddress: intent.ownerAddress,
447
+ intentAddress: intent.originIntentAddress,
450
448
  originChainId: originChainIdStr ? Number(originChainIdStr) : undefined,
451
449
  destinationChainId: destinationChainIdStr
452
450
  ? Number(destinationChainIdStr)
@@ -457,6 +455,42 @@ export async function commitIntentConfig(
457
455
  }
458
456
  }
459
457
 
458
+ export async function executeIntent(
459
+ trailsClient: TrailsClient,
460
+ intentId: string,
461
+ depositTransactionHash?: string,
462
+ depositSignature?: DepositSignature,
463
+ ) {
464
+ trailsClient = await getLocalClientIfEnabled(trailsClient)
465
+
466
+ logger.console.log("[trails-sdk] executeIntent inputs:", {
467
+ intentId,
468
+ depositTransactionHash,
469
+ hasDepositSignature: !!depositSignature,
470
+ })
471
+
472
+ // Validate that we have either traditional or gasless deposit params
473
+ if (!depositTransactionHash && !depositSignature) {
474
+ throw new Error(
475
+ "[trails-sdk] Either depositTransactionHash or depositSignature must be provided",
476
+ )
477
+ }
478
+
479
+ const request: ExecuteIntentRequest = {
480
+ intentId,
481
+ depositTransactionHash,
482
+ depositSignature,
483
+ }
484
+
485
+ logger.console.log("[trails-sdk] executeIntent request:", request)
486
+
487
+ // Call the actual API endpoint
488
+ const response = await trailsClient.executeIntent(request)
489
+ logger.console.log("[trails-sdk] executeIntent response:", response)
490
+
491
+ return response
492
+ }
493
+
460
494
  export async function sendOriginTransaction(
461
495
  account: Account,
462
496
  walletClient: WalletClient,
@@ -636,7 +670,7 @@ export function hashIntentParams({
636
670
  userAddress: Address.Address
637
671
  nonce: bigint
638
672
  originTokens: OriginTokenParam[]
639
- destinationCalls: Array<IntentCallsPayload>
673
+ destinationCalls: Array<IntentCalls>
640
674
  destinationTokens: DestinationTokenParam[]
641
675
  }): string {
642
676
  if (
@@ -748,7 +782,7 @@ export function hashIntentParams({
748
782
 
749
783
  export function calculateIntentConfigurationAddress(
750
784
  mainSigner: Address.Address,
751
- calls: Array<IntentCallsPayload>,
785
+ calls: Array<IntentCalls>,
752
786
  context: Context.Context,
753
787
  ): Address.Address {
754
788
  const config = createIntentConfiguration(mainSigner, calls)
@@ -772,7 +806,7 @@ export function calculateIntentConfigurationAddress(
772
806
 
773
807
  function createIntentConfiguration(
774
808
  mainSigner: Address.Address,
775
- calls: IntentCallsPayload[],
809
+ calls: IntentCalls[],
776
810
  ): Config.Config {
777
811
  const mainSignerLeaf: Config.SignerLeaf = {
778
812
  type: "signer",
@@ -881,7 +915,7 @@ function buildMerkleTreeFromMembers(
881
915
  * Build transaction parameters for same-chain same-token transactions
882
916
  * Centralizes the logic for determining transaction destination, data, and value
883
917
  */
884
- export function buildSameChainTransactionParams({
918
+ export function buildSameChainSameTokenTransactionParams({
885
919
  hasCustomCalldata,
886
920
  recipient,
887
921
  effectiveOriginTokenAddress,
package/src/morpho.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useMemo, useState, useEffect } from "react"
2
- import type { Address, PublicClient } from "viem"
2
+ import type { Address, PublicClient, WalletClient } from "viem"
3
3
  import { encodeFunctionData } from "viem"
4
4
  import { logger } from "./logger.js"
5
5
 
@@ -428,16 +428,17 @@ export async function getAllVaults(
428
428
 
429
429
  /**
430
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
431
+ * @param amount - The amount of underlying assets to withdraw in wei
432
+ * @param to - The address that will receive the underlying tokens (receiver)
433
+ * @param owner - Optional owner address (defaults to 'to' if not provided)
434
434
  * @returns Encoded calldata for Morpho withdraw function
435
435
  */
436
436
  export function generateMorphoWithdrawCalldata(
437
- asset: string,
438
437
  amount: bigint,
439
438
  to: string,
439
+ owner?: string,
440
440
  ): `0x${string}` {
441
+ const ownerAddress = owner || to
441
442
  return encodeFunctionData({
442
443
  abi: [
443
444
  {
@@ -445,16 +446,64 @@ export function generateMorphoWithdrawCalldata(
445
446
  type: "function",
446
447
  stateMutability: "nonpayable",
447
448
  inputs: [
448
- { name: "asset", type: "address" },
449
- { name: "amount", type: "uint256" },
450
- { name: "to", type: "address" },
449
+ { name: "assets", type: "uint256" },
450
+ { name: "receiver", type: "address" },
451
+ { name: "owner", type: "address" },
451
452
  ],
452
453
  outputs: [{ type: "uint256" }],
453
454
  },
454
455
  ],
455
456
  functionName: "withdraw",
456
- args: [asset as `0x${string}`, amount, to as `0x${string}`],
457
+ args: [amount, to as `0x${string}`, ownerAddress as `0x${string}`],
457
458
  })
458
459
  }
459
460
 
461
+ // Generate deposit calldata for Morpho pool
462
+ export const generateMorphoDepositCalldata = (
463
+ walletClient: WalletClient,
464
+ amount: string,
465
+ ) => {
466
+ try {
467
+ const userAddress = walletClient?.account?.address || walletClient?.account
468
+ if (!userAddress) {
469
+ throw new Error("User address not found")
470
+ }
471
+
472
+ // Validate amount
473
+ if (
474
+ !amount ||
475
+ amount === "" ||
476
+ Number.isNaN(Number(amount)) ||
477
+ Number(amount) <= 0
478
+ ) {
479
+ throw new Error("Invalid amount")
480
+ }
481
+
482
+ // Morpho Vault deposit function
483
+ // function deposit(uint256 amount, address receiver)
484
+ const calldata = encodeFunctionData({
485
+ abi: [
486
+ {
487
+ name: "deposit",
488
+ type: "function",
489
+ inputs: [
490
+ { name: "amount", type: "uint256" },
491
+ { name: "receiver", type: "address" },
492
+ ],
493
+ outputs: [{ name: "shares", type: "uint256" }],
494
+ stateMutability: "nonpayable",
495
+ },
496
+ ],
497
+ args: [
498
+ BigInt(amount), // amount to deposit
499
+ userAddress as `0x${string}`, // receiver (user's address)
500
+ ],
501
+ })
502
+ return calldata
503
+ } catch (error) {
504
+ logger.console.error("Error generating Morpho deposit calldata:", error)
505
+ return undefined
506
+ }
507
+ }
508
+
460
509
  export default useMorphoVaults