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.
- package/dist/aave.d.ts.map +1 -1
- package/dist/analytics.d.ts +11 -2
- package/dist/analytics.d.ts.map +1 -1
- package/dist/apiClient.d.ts +1 -1
- package/dist/apiClient.d.ts.map +1 -1
- package/dist/{proxyCaller.d.ts → balanceInjector.d.ts} +5 -4
- package/dist/balanceInjector.d.ts.map +1 -0
- package/dist/{ccip-D3gTQONK.js → ccip-D6ToCrWc.js} +12 -12
- package/dist/cctp.d.ts.map +1 -1
- package/dist/cctpqueue.d.ts +3 -3
- package/dist/cctpqueue.d.ts.map +1 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +17 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +5 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/contractUtils.d.ts +2 -0
- package/dist/contractUtils.d.ts.map +1 -1
- package/dist/customChains.d.ts +24 -0
- package/dist/customChains.d.ts.map +1 -0
- package/dist/{index-CnUM7lKf.js → index-BqgeTLL8.js} +34072 -30146
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +411 -400
- package/dist/intentEntrypoint.d.ts +96 -0
- package/dist/intentEntrypoint.d.ts.map +1 -0
- package/dist/intents.d.ts +5 -3
- package/dist/intents.d.ts.map +1 -1
- package/dist/metaTxnMonitor.d.ts.map +1 -1
- package/dist/morpho.d.ts.map +1 -1
- package/dist/pools.d.ts +3 -1
- package/dist/pools.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +8 -2
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +1 -1
- package/dist/prices.d.ts.map +1 -1
- package/dist/relaySdk.d.ts.map +1 -1
- package/dist/relayer.d.ts.map +1 -1
- package/dist/toast.d.ts +9 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/tokenBalances.d.ts +6 -2
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/trails.d.ts +6 -5
- package/dist/trails.d.ts.map +1 -1
- package/dist/trailsClient.d.ts +12 -0
- package/dist/trailsClient.d.ts.map +1 -0
- package/dist/transactions.d.ts +8 -0
- package/dist/transactions.d.ts.map +1 -1
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountActionsDropdown.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/AccountSettings.d.ts +7 -0
- package/dist/widget/components/AccountSettings.d.ts.map +1 -0
- package/dist/widget/components/ChainList.d.ts +0 -1
- package/dist/widget/components/ChainList.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +46 -0
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -0
- package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts +9 -0
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -0
- package/dist/widget/components/DebugMenu.d.ts.map +1 -1
- package/dist/widget/components/DebugScreensList.d.ts.map +1 -1
- package/dist/widget/components/DebugToast.d.ts +3 -0
- package/dist/widget/components/DebugToast.d.ts.map +1 -0
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/EarnPools.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +44 -0
- package/dist/widget/components/Fund.d.ts.map +1 -0
- package/dist/widget/components/Identicon.d.ts +9 -0
- package/dist/widget/components/Identicon.d.ts.map +1 -0
- package/dist/widget/components/Pay.d.ts +46 -0
- package/dist/widget/components/Pay.d.ts.map +1 -0
- package/dist/widget/components/Receive.d.ts.map +1 -1
- package/dist/widget/components/RecentTokens.d.ts.map +1 -1
- package/dist/widget/components/Recipients.d.ts +9 -0
- package/dist/widget/components/Recipients.d.ts.map +1 -0
- package/dist/widget/components/RefundWarning.d.ts +9 -0
- package/dist/widget/components/RefundWarning.d.ts.map +1 -0
- package/dist/widget/components/SimpleSwap.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/SwapSettings.d.ts +1 -5
- package/dist/widget/components/SwapSettings.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/ThemeSyncer.d.ts +6 -0
- package/dist/widget/components/ThemeSyncer.d.ts.map +1 -0
- package/dist/widget/components/Toast.d.ts +24 -0
- package/dist/widget/components/Toast.d.ts.map +1 -0
- package/dist/widget/components/TokenList.d.ts.map +1 -1
- package/dist/widget/components/TransactionDetails.d.ts.map +1 -1
- package/dist/widget/components/TruncatedAddress.d.ts +2 -0
- package/dist/widget/components/TruncatedAddress.d.ts.map +1 -1
- package/dist/widget/components/UserPreferences.d.ts +7 -0
- package/dist/widget/components/UserPreferences.d.ts.map +1 -0
- package/dist/widget/hooks/useBalanceVisible.d.ts +1 -0
- package/dist/widget/hooks/useBalanceVisible.d.ts.map +1 -1
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts +54 -0
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -0
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/usePayMessage.d.ts +34 -0
- package/dist/widget/hooks/usePayMessage.d.ts.map +1 -0
- package/dist/widget/hooks/useRecipients.d.ts +17 -0
- package/dist/widget/hooks/useRecipients.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedRecipient.d.ts +12 -0
- package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.d.ts +2 -0
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useSwapAmount.d.ts +13 -0
- package/dist/widget/hooks/useSwapAmount.d.ts.map +1 -0
- package/dist/widget/hooks/useSwapSettings.d.ts +16 -0
- package/dist/widget/hooks/useSwapSettings.d.ts.map +1 -0
- package/dist/widget/hooks/useTargetAmount.d.ts +5 -0
- package/dist/widget/hooks/useTargetAmount.d.ts.map +1 -0
- package/dist/widget/hooks/useTheme.d.ts +14 -0
- package/dist/widget/hooks/useTheme.d.ts.map +1 -0
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/index.js +2 -2
- package/dist/widget/widget.d.ts +9 -0
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +29 -28
- package/src/aave.ts +6 -1
- package/src/analytics.ts +103 -53
- package/src/apiClient.ts +1 -1
- package/src/{proxyCaller.ts → balanceInjector.ts} +22 -17
- package/src/cctp.ts +6 -2
- package/src/cctpqueue.ts +7 -7
- package/src/chains.ts +8 -0
- package/src/config.ts +40 -9
- package/src/constants.ts +11 -8
- package/src/contractUtils.ts +33 -2
- package/src/customChains.ts +24 -0
- package/src/index.ts +11 -1
- package/src/intentEntrypoint.ts +253 -0
- package/src/intents.ts +87 -54
- package/src/metaTxnMonitor.ts +1 -0
- package/src/morpho.ts +13 -2
- package/src/pools.ts +68 -86
- package/src/prepareSend.ts +437 -207
- package/src/prices.ts +51 -7
- package/src/relaySdk.ts +6 -4
- package/src/relayer.ts +2 -0
- package/src/toast.ts +110 -0
- package/src/tokenBalances.ts +112 -20
- package/src/tokens.ts +70 -7
- package/src/trails.ts +80 -77
- package/src/trailsClient.ts +45 -0
- package/src/transactions.ts +27 -35
- package/src/umd.tsx +1 -1
- package/src/wallets.ts +2 -1
- package/src/widget/assets/sequence-logo.svg +15 -0
- package/src/widget/compiled.css +2 -2
- package/src/widget/components/AccountActionsDropdown.tsx +18 -159
- package/src/widget/components/AccountIntentTransactionHistory.tsx +346 -63
- package/src/widget/components/AccountSettings.tsx +96 -0
- package/src/widget/components/ChainFilterDropdown.tsx +1 -1
- package/src/widget/components/ChainList.tsx +10 -20
- package/src/widget/components/ClassicSwap.tsx +923 -0
- package/src/widget/components/ConfigDisplay.tsx +8 -5
- package/src/widget/components/ConnectedWallets.tsx +260 -0
- package/src/widget/components/DebugMenu.tsx +2 -0
- package/src/widget/components/DebugScreensList.tsx +3 -0
- package/src/widget/components/DebugToast.tsx +63 -0
- package/src/widget/components/Earn.tsx +108 -116
- package/src/widget/components/EarnPools.tsx +2 -4
- package/src/widget/components/EarnPoolsFilters.tsx +6 -6
- package/src/widget/components/Fund.tsx +1245 -0
- package/src/widget/components/FundMethods.tsx +1 -1
- package/src/widget/components/FundSendForm.tsx +1 -1
- package/src/widget/components/Identicon.tsx +158 -0
- package/src/widget/components/Pay.tsx +1088 -0
- package/src/widget/components/PaySendForm.tsx +1 -1
- package/src/widget/components/QuoteDetails.tsx +1 -1
- package/src/widget/components/Receipt.tsx +1 -1
- package/src/widget/components/Receive.tsx +4 -2
- package/src/widget/components/RecentTokens.tsx +2 -1
- package/src/widget/components/Recipients.tsx +448 -0
- package/src/widget/components/RefundWarning.tsx +61 -0
- package/src/widget/components/ScreenHeader.tsx +1 -1
- package/src/widget/components/SimpleSwap.tsx +74 -58
- package/src/widget/components/Swap.tsx +35 -853
- package/src/widget/components/SwapSettings.tsx +5 -11
- package/src/widget/components/ThemeProvider.tsx +32 -0
- package/src/widget/components/ThemeSyncer.tsx +47 -0
- package/src/widget/components/Toast.tsx +315 -0
- package/src/widget/components/TokenList.tsx +2 -34
- package/src/widget/components/TokenSelector.tsx +3 -3
- package/src/widget/components/TransactionDetails.tsx +153 -13
- package/src/widget/components/TruncatedAddress.tsx +5 -1
- package/src/widget/components/UserPreferences.tsx +156 -0
- package/src/widget/components/WalletList.tsx +1 -1
- package/src/widget/hooks/useBalanceVisible.tsx +40 -2
- package/src/widget/hooks/useCheckout.ts +13 -0
- package/src/widget/hooks/useCurrentScreen.tsx +3 -0
- package/src/widget/hooks/useDebugScreens.ts +12 -2
- package/src/widget/hooks/useDefaultTokenSelection.tsx +475 -0
- package/src/widget/hooks/useIntentTransactionHistory.ts +212 -0
- package/src/widget/hooks/usePayMessage.tsx +370 -0
- package/src/widget/hooks/useRecipients.ts +168 -0
- package/src/widget/hooks/useSelectedRecipient.tsx +48 -0
- package/src/widget/hooks/useSendForm.ts +179 -26
- package/src/widget/hooks/useSwapAmount.tsx +50 -0
- package/src/widget/hooks/useSwapSettings.tsx +100 -0
- package/src/widget/hooks/useTargetAmount.ts +23 -0
- package/src/widget/hooks/useTheme.tsx +80 -0
- package/src/widget/hooks/useTokenList.ts +20 -11
- package/src/widget/index.css +45 -21
- package/src/widget/widget.tsx +164 -68
- package/dist/address.d.ts +0 -2
- package/dist/address.d.ts.map +0 -1
- package/dist/proxyCaller.d.ts.map +0 -1
- 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
|
-
|
|
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
|
|
133
|
-
apiClient:
|
|
134
|
-
|
|
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 {
|
|
141
|
-
apiClient =
|
|
142
|
-
|
|
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(
|
|
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:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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(
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
|
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(
|
package/src/metaTxnMonitor.ts
CHANGED
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 **
|
|
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
|
|
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
|
|
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
|
-
//
|
|
55
|
-
const
|
|
56
|
-
if
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
71
|
-
|
|
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]
|
|
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
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
//
|
|
113
|
-
if (
|
|
120
|
+
// If not enabled, don't show errors
|
|
121
|
+
if (!enabled) {
|
|
114
122
|
return null
|
|
115
123
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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:
|
|
134
|
+
data: cachedPools || [],
|
|
153
135
|
loading,
|
|
154
136
|
error,
|
|
155
137
|
}
|