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.
- package/dist/aave.d.ts +2 -0
- package/dist/aave.d.ts.map +1 -1
- package/dist/abortController.d.ts +8 -0
- package/dist/abortController.d.ts.map +1 -0
- package/dist/{ccip-CXlshvBY.js → ccip-BMB3uDZt.js} +1 -1
- package/dist/config.d.ts +0 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +4 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/error.d.ts +4 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/fees.d.ts +19 -0
- package/dist/fees.d.ts.map +1 -0
- package/dist/{index-_QuyGrjU.js → index-QXPUrZVv.js} +48719 -50852
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +811 -784
- package/dist/intentReceiptMonitor.d.ts +24 -0
- package/dist/intentReceiptMonitor.d.ts.map +1 -0
- package/dist/intentReceiptPoller.d.ts +69 -0
- package/dist/intentReceiptPoller.d.ts.map +1 -0
- package/dist/intents.d.ts +15 -11
- package/dist/intents.d.ts.map +1 -1
- package/dist/morpho.d.ts +6 -5
- package/dist/morpho.d.ts.map +1 -1
- package/dist/mutations.d.ts +16 -0
- package/dist/mutations.d.ts.map +1 -0
- package/dist/preconditions.d.ts +5 -4
- package/dist/preconditions.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +7 -258
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prices.d.ts +9 -6
- package/dist/prices.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +3 -16
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts +17 -13
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/trails.d.ts +24 -40
- package/dist/trails.d.ts.map +1 -1
- package/dist/transactionIntent/constants.d.ts +7 -0
- package/dist/transactionIntent/constants.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +44 -0
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +30 -0
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/index.d.ts +4 -0
- package/dist/transactionIntent/deposits/index.d.ts.map +1 -0
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +30 -0
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -0
- package/dist/transactionIntent/execution/index.d.ts +2 -0
- package/dist/transactionIntent/execution/index.d.ts.map +1 -0
- package/dist/transactionIntent/execution/transactionState.d.ts +5 -0
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/crossChain.d.ts +82 -0
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/index.d.ts +4 -0
- package/dist/transactionIntent/handlers/index.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +62 -0
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +1 -0
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +72 -0
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -0
- package/dist/transactionIntent/index.d.ts +9 -0
- package/dist/transactionIntent/index.d.ts.map +1 -0
- package/dist/transactionIntent/quote/feeExtractors.d.ts +17 -0
- package/dist/transactionIntent/quote/feeExtractors.d.ts.map +1 -0
- package/dist/transactionIntent/quote/index.d.ts +4 -0
- package/dist/transactionIntent/quote/index.d.ts.map +1 -0
- package/dist/transactionIntent/quote/normalizeQuote.d.ts +34 -0
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -0
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +5 -0
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/types.d.ts +131 -0
- package/dist/transactionIntent/types.d.ts.map +1 -0
- package/dist/transactionIntent/utils/balanceChecker.d.ts +18 -0
- package/dist/transactionIntent/utils/balanceChecker.d.ts.map +1 -0
- package/dist/transactionIntent/utils/index.d.ts +4 -0
- package/dist/transactionIntent/utils/index.d.ts.map +1 -0
- package/dist/transactionIntent/utils/lifiHelpers.d.ts +10 -0
- package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/utils/testnetHelpers.d.ts +3 -0
- package/dist/transactionIntent/utils/testnetHelpers.d.ts.map +1 -0
- package/dist/transactionIntent/validators.d.ts +6 -0
- package/dist/transactionIntent/validators.d.ts.map +1 -0
- package/dist/transactions.d.ts +6 -3
- package/dist/transactions.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts +4 -0
- package/dist/widget/components/AccountIntentTransactionHistoryButton.d.ts.map +1 -0
- package/dist/widget/components/AccountSettings.d.ts.map +1 -1
- package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts +2 -3
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts.map +1 -1
- package/dist/widget/components/DynamicInputStyles.d.ts +18 -0
- package/dist/widget/components/DynamicInputStyles.d.ts.map +1 -0
- package/dist/widget/components/DynamicSizeInputField.d.ts +13 -0
- package/dist/widget/components/DynamicSizeInputField.d.ts.map +1 -0
- package/dist/widget/components/Earn.d.ts +2 -3
- package/dist/widget/components/Earn.d.ts.map +1 -1
- package/dist/widget/components/ErrorAnimationIcon.d.ts +2 -0
- package/dist/widget/components/ErrorAnimationIcon.d.ts.map +1 -0
- package/dist/widget/components/FeeBreakdown.d.ts +9 -0
- package/dist/widget/components/FeeBreakdown.d.ts.map +1 -0
- package/dist/widget/components/FeeOptions.d.ts +5 -13
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/Fund.d.ts +2 -3
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/FundSwap.d.ts +2 -3
- package/dist/widget/components/FundSwap.d.ts.map +1 -1
- package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Identicon.d.ts.map +1 -1
- package/dist/widget/components/MeshConnectExchanges.d.ts +0 -3
- package/dist/widget/components/MeshConnectExchanges.d.ts.map +1 -1
- package/dist/widget/components/Modal.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts +2 -3
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts +3 -3
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/PoolWithdraw.d.ts +3 -20
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts +2 -0
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +2 -3
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts +11 -0
- package/dist/widget/components/TokenDisplayNonSelectable.d.ts.map +1 -0
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -1
- package/dist/widget/components/Tooltip.d.ts +9 -0
- package/dist/widget/components/Tooltip.d.ts.map +1 -0
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
- package/dist/widget/components/WaasFeeOptions.d.ts +1 -0
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -1
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +2 -2
- package/dist/widget/hooks/useCheckout.d.ts +17 -4
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +82 -0
- package/dist/widget/hooks/useQuote.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedFeeToken.d.ts +1 -0
- package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +5 -6
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/hooks/useWalletConnectionContext.d.ts +25 -0
- package/dist/widget/hooks/useWalletConnectionContext.d.ts.map +1 -0
- package/dist/widget/index.js +2 -2
- package/dist/widget/widget.d.ts +17 -7
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +19 -21
- package/src/aave.ts +54 -1
- package/src/abortController.ts +35 -0
- package/src/config.ts +57 -58
- package/src/constants.ts +11 -9
- package/src/error.ts +21 -3
- package/src/fees.ts +210 -0
- package/src/index.ts +35 -13
- package/src/intentReceiptMonitor.ts +102 -0
- package/src/intentReceiptPoller.ts +299 -0
- package/src/intents.ts +205 -171
- package/src/morpho.ts +58 -9
- package/src/mutations.ts +129 -0
- package/src/preconditions.ts +16 -21
- package/src/prepareSend.ts +92 -4699
- package/src/prices.ts +26 -22
- package/src/relaySdk.ts +2 -2
- package/src/sequenceWallet.ts +6 -73
- package/src/tokenBalances.ts +175 -69
- package/src/trails.ts +230 -722
- package/src/transactionIntent/constants.ts +11 -0
- package/src/transactionIntent/deposits/depositOrchestrator.ts +210 -0
- package/src/transactionIntent/deposits/gaslessDeposit.ts +588 -0
- package/src/transactionIntent/deposits/index.ts +3 -0
- package/src/transactionIntent/deposits/standardDeposit.ts +379 -0
- package/src/transactionIntent/execution/index.ts +1 -0
- package/src/transactionIntent/execution/transactionState.ts +35 -0
- package/src/transactionIntent/handlers/crossChain.ts +1707 -0
- package/src/transactionIntent/handlers/index.ts +3 -0
- package/src/transactionIntent/handlers/sameChainDifferentToken.ts +323 -0
- package/src/transactionIntent/handlers/sameChainSameToken.ts +712 -0
- package/src/transactionIntent/index.ts +9 -0
- package/src/transactionIntent/quote/feeExtractors.ts +81 -0
- package/src/transactionIntent/quote/index.ts +3 -0
- package/src/transactionIntent/quote/normalizeQuote.ts +367 -0
- package/src/transactionIntent/quote/quoteHelpers.ts +53 -0
- package/src/transactionIntent/types.ts +157 -0
- package/src/transactionIntent/utils/balanceChecker.ts +96 -0
- package/src/transactionIntent/utils/index.ts +3 -0
- package/src/transactionIntent/utils/lifiHelpers.ts +68 -0
- package/src/transactionIntent/utils/testnetHelpers.ts +10 -0
- package/src/transactionIntent/validators.ts +57 -0
- package/src/transactions.ts +98 -71
- package/src/widget/compiled.css +2 -2
- package/src/widget/components/AccountIntentTransactionHistory.tsx +36 -36
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
- package/src/widget/components/AccountSettings.tsx +70 -41
- package/src/widget/components/ChainFilterDropdown.tsx +24 -3
- package/src/widget/components/ClassicSwap.tsx +44 -107
- package/src/widget/components/ConfigDisplay.tsx +0 -11
- package/src/widget/components/ConnectWallet.tsx +4 -1
- package/src/widget/components/ConnectedWallets.tsx +51 -25
- package/src/widget/components/DynamicInputStyles.tsx +76 -0
- package/src/widget/components/DynamicSizeInputField.tsx +109 -0
- package/src/widget/components/Earn.tsx +34 -45
- package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
- package/src/widget/components/FeeBreakdown.tsx +155 -0
- package/src/widget/components/FeeOption.tsx +2 -2
- package/src/widget/components/FeeOptions.tsx +151 -112
- package/src/widget/components/Fund.tsx +10 -29
- package/src/widget/components/FundMethods.tsx +4 -3
- package/src/widget/components/FundSwap.tsx +2 -3
- package/src/widget/components/FundingMethodSelectorButton.tsx +24 -14
- package/src/widget/components/Identicon.tsx +164 -95
- package/src/widget/components/MeshConnectExchanges.tsx +2 -15
- package/src/widget/components/Modal.tsx +0 -12
- package/src/widget/components/Pay.tsx +72 -75
- package/src/widget/components/PoolDeposit.tsx +221 -242
- package/src/widget/components/PoolWithdraw.tsx +347 -469
- package/src/widget/components/PriceImpactWarning.tsx +1 -1
- package/src/widget/components/QuoteDetails.tsx +906 -484
- package/src/widget/components/Receipt.tsx +16 -2
- package/src/widget/components/RecipientSelectorButton.tsx +7 -5
- package/src/widget/components/Recipients.tsx +1 -1
- package/src/widget/components/ScreenHeader.tsx +60 -36
- package/src/widget/components/Swap.tsx +2 -3
- package/src/widget/components/ThemeProvider.tsx +2 -1
- package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
- package/src/widget/components/TokenImage.tsx +1 -1
- package/src/widget/components/TokenSelector.tsx +62 -53
- package/src/widget/components/TokenSelectorButton.tsx +38 -15
- package/src/widget/components/Tooltip.tsx +51 -0
- package/src/widget/components/TransferPendingVertical.tsx +12 -8
- package/src/widget/components/WaasFeeOptions.tsx +139 -4
- package/src/widget/components/WalletConfirmation.tsx +23 -13
- package/src/widget/components/WalletConnect.tsx +93 -29
- package/src/widget/hooks/useAmountUsd.ts +9 -9
- package/src/widget/hooks/useCheckout.ts +97 -9
- package/src/widget/hooks/useDefaultTokenSelection.tsx +27 -21
- package/src/widget/hooks/useQuote.ts +466 -0
- package/src/widget/hooks/useSelectedFeeToken.tsx +32 -37
- package/src/widget/hooks/useSendForm.ts +45 -51
- package/src/widget/hooks/useTokenList.ts +34 -26
- package/src/widget/hooks/useWalletConnectionContext.tsx +128 -0
- package/src/widget/widget.tsx +365 -390
- package/dist/apiClient.d.ts +0 -9
- package/dist/apiClient.d.ts.map +0 -1
- package/dist/intentEntrypoint.d.ts +0 -114
- package/dist/intentEntrypoint.d.ts.map +0 -1
- package/dist/metaTxnMonitor.d.ts +0 -15
- package/dist/metaTxnMonitor.d.ts.map +0 -1
- package/dist/metaTxns.d.ts +0 -11
- package/dist/metaTxns.d.ts.map +0 -1
- package/dist/relayer.d.ts +0 -43
- package/dist/relayer.d.ts.map +0 -1
- package/src/apiClient.ts +0 -35
- package/src/intentEntrypoint.ts +0 -203
- package/src/metaTxnMonitor.ts +0 -171
- package/src/metaTxns.ts +0 -45
- package/src/relayer.ts +0 -289
package/src/intents.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
145
|
+
trailsClient = getTrailsClient({
|
|
145
146
|
hostname: "http://localhost:4422",
|
|
146
147
|
})
|
|
147
148
|
}
|
|
148
|
-
return
|
|
149
|
+
return trailsClient
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
export async function
|
|
152
|
-
|
|
153
|
-
args:
|
|
152
|
+
export async function getIntent(
|
|
153
|
+
trailsClient: TrailsAPIClient,
|
|
154
|
+
args: QuoteIntentRequest,
|
|
154
155
|
additionalTrackingProps: Record<string, string> = {},
|
|
155
|
-
): Promise<
|
|
156
|
-
|
|
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.
|
|
161
|
-
destinationChainId: args.
|
|
162
|
-
originTokenAddress: args.
|
|
163
|
-
destinationTokenAddress: args.
|
|
164
|
-
userAddress: args.
|
|
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]
|
|
170
|
-
const
|
|
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 (!
|
|
175
|
-
logger.console.error("[trails-sdk] No result from
|
|
176
|
-
throw new Error("No result from
|
|
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.
|
|
181
|
-
const destinationChainId = args.
|
|
182
|
-
const originPrecondition = result.
|
|
183
|
-
(p:
|
|
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.
|
|
186
|
-
(p:
|
|
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.
|
|
193
|
-
totalFeeUSD: result.
|
|
194
|
-
crossChainFeeTotalUSD:
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
result.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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?.
|
|
212
|
-
fromAmount: result.
|
|
213
|
-
fromAmountMin: result.
|
|
214
|
-
toAmount: result.
|
|
215
|
-
toAmountMin: result.
|
|
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
|
|
223
|
+
return {
|
|
224
|
+
intent: result,
|
|
225
|
+
gasFeeOptions: response.gasFeeOptions,
|
|
226
|
+
}
|
|
220
227
|
} catch (error) {
|
|
221
|
-
logger.console.error("[trails-sdk] Error in
|
|
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.
|
|
226
|
-
originChainId: args.
|
|
227
|
-
destinationChainId: args.
|
|
228
|
-
originTokenAddress: args.
|
|
229
|
-
destinationTokenAddress: args.
|
|
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<
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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<
|
|
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
|
-
|
|
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
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
384
|
+
intent.originIntentAddress,
|
|
346
385
|
)
|
|
347
386
|
logger.console.log(
|
|
348
387
|
"[trails-sdk] destinationIntentAddress:",
|
|
349
|
-
destinationIntentAddress
|
|
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
|
|
406
|
+
calculatedAddress: intent.originIntentAddress,
|
|
368
407
|
match:
|
|
369
408
|
receivedAddress &&
|
|
370
|
-
isAddressEqual(
|
|
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
|
|
416
|
+
// Track intent commit start
|
|
418
417
|
trackIntentCommitStarted({
|
|
419
|
-
intentAddress: originIntentAddress
|
|
420
|
-
userAddress:
|
|
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
|
-
|
|
429
|
-
|
|
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
|
|
435
|
-
userAddress:
|
|
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
|
|
441
|
+
return response
|
|
444
442
|
} catch (error) {
|
|
445
443
|
// Track intent commit error
|
|
446
444
|
trackIntentCommitError({
|
|
447
445
|
error: getFullErrorMessage(error),
|
|
448
|
-
userAddress:
|
|
449
|
-
intentAddress: originIntentAddress
|
|
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<
|
|
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<
|
|
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:
|
|
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
|
|
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
|
|
432
|
-
* @param
|
|
433
|
-
* @param
|
|
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: "
|
|
449
|
-
{ name: "
|
|
450
|
-
{ name: "
|
|
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: [
|
|
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
|