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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Re-export all public APIs
|
|
2
|
+
export * from "./types.js"
|
|
3
|
+
export * from "./constants.js"
|
|
4
|
+
export * from "./validators.js"
|
|
5
|
+
export * from "./utils/index.js"
|
|
6
|
+
export * from "./quote/index.js"
|
|
7
|
+
export * from "./execution/index.js"
|
|
8
|
+
export * from "./deposits/index.js"
|
|
9
|
+
export * from "./handlers/index.js"
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Intent } from "@0xsequence/trails-api"
|
|
2
|
+
import type { RelayQuote } from "../../relaySdk.js"
|
|
3
|
+
import { zeroAddress } from "viem"
|
|
4
|
+
import { formatUsdAmountDisplay } from "../../tokenBalances.js"
|
|
5
|
+
import { logger } from "../../logger.js"
|
|
6
|
+
import type { TradeType, PrepareSendFees } from "../types.js"
|
|
7
|
+
|
|
8
|
+
export function getFeesFromIntent(
|
|
9
|
+
intent: Intent,
|
|
10
|
+
{
|
|
11
|
+
tradeType,
|
|
12
|
+
fromAmountUsd,
|
|
13
|
+
toAmountUsd,
|
|
14
|
+
}: { tradeType: TradeType; fromAmountUsd: number; toAmountUsd: number },
|
|
15
|
+
): PrepareSendFees {
|
|
16
|
+
const totalFeeAmountUsd = intent.fees?.totalFeeUsd || 0
|
|
17
|
+
const totalFeeAmountUsdDisplay = formatUsdAmountDisplay(totalFeeAmountUsd)
|
|
18
|
+
|
|
19
|
+
logger.console.log("[trails-sdk] getFeesFromIntent", {
|
|
20
|
+
tradeType,
|
|
21
|
+
fromAmountUsd,
|
|
22
|
+
toAmountUsd,
|
|
23
|
+
totalFeeAmountUsd,
|
|
24
|
+
totalFeeAmountUsdDisplay,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
feeTokenAddress: intent.fees?.feeTokenAddress ?? zeroAddress,
|
|
29
|
+
totalFeeAmount: intent.fees?.totalFeeAmount?.toString() ?? "0",
|
|
30
|
+
totalFeeAmountUsd: totalFeeAmountUsd.toString(),
|
|
31
|
+
totalFeeAmountUsdDisplay,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getSlippageToleranceFromIntent(intent: Intent): string {
|
|
36
|
+
return intent.quote?.maxSlippage?.toString() ?? "0"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getPriceImpactFromIntent(intent: Intent): string {
|
|
40
|
+
return intent?.quote?.priceImpact?.toString() ?? "0"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getPriceImpactUsdFromIntent(intent: Intent): string {
|
|
44
|
+
return intent?.quote?.priceImpactUsd?.toString() ?? "0"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getFeesFromRelaySdkQuote(quote: RelayQuote): PrepareSendFees {
|
|
48
|
+
const totalFeeAmountUsd = quote?.fees?.relayer?.amount ?? 0
|
|
49
|
+
const totalFeeAmountUsdDisplay = formatUsdAmountDisplay(totalFeeAmountUsd)
|
|
50
|
+
return {
|
|
51
|
+
feeTokenAddress: quote?.fees?.relayer?.currency?.address ?? zeroAddress,
|
|
52
|
+
totalFeeAmount: quote?.fees?.relayer?.amount ?? "0",
|
|
53
|
+
totalFeeAmountUsd: totalFeeAmountUsd.toString(),
|
|
54
|
+
totalFeeAmountUsdDisplay,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getSlippageToleranceFromRelaySdkQuote(
|
|
59
|
+
quote: RelayQuote,
|
|
60
|
+
): string {
|
|
61
|
+
return (
|
|
62
|
+
Number(quote?.details?.slippageTolerance?.origin?.percent ?? "0") / 100
|
|
63
|
+
).toString()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getPriceImpactFromRelaySdkQuote(quote: RelayQuote): string {
|
|
67
|
+
return (quote?.details?.swapImpact?.percent ?? 0).toString()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function getPriceImpactUsdFromRelaySdkQuote(quote: RelayQuote): string {
|
|
71
|
+
return (quote?.details?.swapImpact?.usd ?? 0).toString()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function getZeroFees(): PrepareSendFees {
|
|
75
|
+
return {
|
|
76
|
+
feeTokenAddress: zeroAddress,
|
|
77
|
+
totalFeeAmount: "0",
|
|
78
|
+
totalFeeAmountUsd: "0",
|
|
79
|
+
totalFeeAmountUsdDisplay: formatUsdAmountDisplay(0),
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import type { Intent } from "@0xsequence/trails-api"
|
|
2
|
+
import type { TransactionState } from "../../transactions.js"
|
|
3
|
+
import type { PrepareSendQuote, PrepareSendFees } from "../types.js"
|
|
4
|
+
import type { QuoteProviderInfo } from "../../widget/hooks/useQuote.js"
|
|
5
|
+
import { createPublicClient, formatUnits, http } from "viem"
|
|
6
|
+
import { mainnet } from "viem/chains"
|
|
7
|
+
import { getTokenInfo } from "../../tokens.js"
|
|
8
|
+
import { getChainInfo } from "../../chains.js"
|
|
9
|
+
import { logger } from "../../logger.js"
|
|
10
|
+
import {
|
|
11
|
+
formatRawAmount,
|
|
12
|
+
formatAmount,
|
|
13
|
+
formatAmountDisplay,
|
|
14
|
+
formatUsdAmountDisplay,
|
|
15
|
+
} from "../../tokenBalances.js"
|
|
16
|
+
import { calcAmountUsdPrice } from "../../prices.js"
|
|
17
|
+
import { getIsCustomCalldata } from "../../contractUtils.js"
|
|
18
|
+
import {
|
|
19
|
+
estimateGasCost,
|
|
20
|
+
estimateGasCostUsd,
|
|
21
|
+
DEFAULT_MIN_GASLIMIT,
|
|
22
|
+
} from "../../estimate.js"
|
|
23
|
+
import { extractTrailsFeeBreakdown } from "../../fees.js"
|
|
24
|
+
import { getZeroFees } from "./feeExtractors.js"
|
|
25
|
+
|
|
26
|
+
// TODO: make this dyanamic
|
|
27
|
+
export function getCompletionEstimateSeconds({
|
|
28
|
+
originChainId,
|
|
29
|
+
destinationChainId,
|
|
30
|
+
}: {
|
|
31
|
+
originChainId: number
|
|
32
|
+
destinationChainId: number
|
|
33
|
+
}): number {
|
|
34
|
+
if (originChainId === mainnet.id && destinationChainId === mainnet.id) {
|
|
35
|
+
return 60
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (originChainId === mainnet.id || destinationChainId === mainnet.id) {
|
|
39
|
+
return 45
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return 15
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function getNormalizedQuoteObject({
|
|
46
|
+
originDepositAddress,
|
|
47
|
+
destinationDepositAddress,
|
|
48
|
+
destinationAddress,
|
|
49
|
+
destinationCalldata,
|
|
50
|
+
originChainId,
|
|
51
|
+
destinationChainId,
|
|
52
|
+
originAmount,
|
|
53
|
+
originAmountMin,
|
|
54
|
+
destinationAmount,
|
|
55
|
+
destinationAmountMin,
|
|
56
|
+
originTokenAddress,
|
|
57
|
+
destinationTokenAddress,
|
|
58
|
+
originTokenPriceUsd,
|
|
59
|
+
destinationTokenPriceUsd,
|
|
60
|
+
transactionStates,
|
|
61
|
+
fees,
|
|
62
|
+
slippageTolerance,
|
|
63
|
+
priceImpact,
|
|
64
|
+
priceImpactUsd,
|
|
65
|
+
originNativeTokenPriceUsd,
|
|
66
|
+
quoteProvider,
|
|
67
|
+
noSufficientBalance,
|
|
68
|
+
estimatedGasLimit,
|
|
69
|
+
intent,
|
|
70
|
+
}: {
|
|
71
|
+
originDepositAddress?: string
|
|
72
|
+
destinationDepositAddress?: string
|
|
73
|
+
destinationAddress?: string
|
|
74
|
+
destinationCalldata?: string
|
|
75
|
+
originChainId: number
|
|
76
|
+
destinationChainId?: number
|
|
77
|
+
originAmount: string
|
|
78
|
+
originAmountMin?: string
|
|
79
|
+
destinationAmount: string
|
|
80
|
+
destinationAmountMin?: string
|
|
81
|
+
originTokenAddress: string
|
|
82
|
+
destinationTokenAddress?: string
|
|
83
|
+
originTokenPriceUsd?: string | null
|
|
84
|
+
destinationTokenPriceUsd?: string | null
|
|
85
|
+
transactionStates?: TransactionState[]
|
|
86
|
+
fees?: PrepareSendFees
|
|
87
|
+
slippageTolerance?: string
|
|
88
|
+
priceImpact?: string
|
|
89
|
+
priceImpactUsd?: string
|
|
90
|
+
originNativeTokenPriceUsd?: number | null
|
|
91
|
+
quoteProvider?: string
|
|
92
|
+
noSufficientBalance?: boolean
|
|
93
|
+
estimatedGasLimit?: bigint
|
|
94
|
+
intent?: Intent
|
|
95
|
+
}): Promise<PrepareSendQuote> {
|
|
96
|
+
if (!destinationChainId) {
|
|
97
|
+
throw new Error("Destination chain id is required")
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!destinationTokenAddress && originChainId === destinationChainId) {
|
|
101
|
+
destinationTokenAddress = originTokenAddress
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!destinationTokenAddress && originChainId === destinationChainId) {
|
|
105
|
+
destinationTokenAddress = originTokenAddress
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!destinationTokenAddress) {
|
|
109
|
+
throw new Error("Destination token address is required")
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const originToken = await getTokenInfo(originChainId, originTokenAddress)
|
|
113
|
+
const destinationToken = await getTokenInfo(
|
|
114
|
+
destinationChainId,
|
|
115
|
+
destinationTokenAddress,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
const originChain = getChainInfo(originChainId)
|
|
119
|
+
const destinationChain = getChainInfo(destinationChainId)
|
|
120
|
+
|
|
121
|
+
if (!originToken || !destinationToken || !originChain || !destinationChain) {
|
|
122
|
+
logger.console.error("[trails-sdk] Token or chain not found", {
|
|
123
|
+
originToken,
|
|
124
|
+
destinationToken,
|
|
125
|
+
originChain,
|
|
126
|
+
destinationChain,
|
|
127
|
+
})
|
|
128
|
+
throw new Error("Token or chain not found")
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const originAmountMinFormatted = formatRawAmount(
|
|
132
|
+
originAmountMin || "0",
|
|
133
|
+
originToken.decimals,
|
|
134
|
+
)
|
|
135
|
+
const originAmountMinUsdFormatted = formatAmount(
|
|
136
|
+
calcAmountUsdPrice({
|
|
137
|
+
amount: originAmountMinFormatted,
|
|
138
|
+
usdPrice: originTokenPriceUsd,
|
|
139
|
+
}),
|
|
140
|
+
)
|
|
141
|
+
const originAmountMinUsdDisplay = formatUsdAmountDisplay(
|
|
142
|
+
originAmountMinUsdFormatted,
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
const destinationAmountMinFormatted = formatRawAmount(
|
|
146
|
+
destinationAmountMin || "0",
|
|
147
|
+
destinationToken.decimals,
|
|
148
|
+
)
|
|
149
|
+
const destinationAmountMinUsdFormatted = formatAmount(
|
|
150
|
+
calcAmountUsdPrice({
|
|
151
|
+
amount: destinationAmountMinFormatted,
|
|
152
|
+
usdPrice: destinationTokenPriceUsd,
|
|
153
|
+
}),
|
|
154
|
+
)
|
|
155
|
+
const destinationAmountMinUsdDisplay = formatUsdAmountDisplay(
|
|
156
|
+
destinationAmountMinUsdFormatted,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
const originAmountFormatted = formatRawAmount(
|
|
160
|
+
originAmount,
|
|
161
|
+
originToken.decimals,
|
|
162
|
+
)
|
|
163
|
+
const originAmountUsdFormatted = formatAmount(
|
|
164
|
+
calcAmountUsdPrice({
|
|
165
|
+
amount: originAmountFormatted,
|
|
166
|
+
usdPrice: originTokenPriceUsd,
|
|
167
|
+
}),
|
|
168
|
+
)
|
|
169
|
+
const originAmountUsdDisplay = formatUsdAmountDisplay(
|
|
170
|
+
originAmountUsdFormatted,
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
const destinationAmountFormatted = formatRawAmount(
|
|
174
|
+
destinationAmount,
|
|
175
|
+
destinationToken.decimals,
|
|
176
|
+
)
|
|
177
|
+
const destinationAmountUsdFormatted = formatAmount(
|
|
178
|
+
calcAmountUsdPrice({
|
|
179
|
+
amount: destinationAmountFormatted,
|
|
180
|
+
usdPrice: destinationTokenPriceUsd,
|
|
181
|
+
}),
|
|
182
|
+
)
|
|
183
|
+
const destinationAmountUsdDisplay = formatUsdAmountDisplay(
|
|
184
|
+
destinationAmountUsdFormatted,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
const hasCustomCalldata = getIsCustomCalldata(destinationCalldata)
|
|
188
|
+
|
|
189
|
+
const publicClient = createPublicClient({
|
|
190
|
+
chain: originChain,
|
|
191
|
+
transport: http(),
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
let gasCostUsd: number = 0
|
|
195
|
+
let gasCostUsdDisplay: string = "0"
|
|
196
|
+
let gasCost: string = "0"
|
|
197
|
+
let gasCostFormatted: string = "0"
|
|
198
|
+
try {
|
|
199
|
+
if (originNativeTokenPriceUsd) {
|
|
200
|
+
// Use the actual estimated gas limit if provided, otherwise use default
|
|
201
|
+
// This ensures the quote gas cost matches what will be used in the actual transaction
|
|
202
|
+
const gasLimitForCost = estimatedGasLimit || DEFAULT_MIN_GASLIMIT
|
|
203
|
+
|
|
204
|
+
logger.console.log(
|
|
205
|
+
"[trails-sdk][gas-estimation] Calculating gas cost for quote with gasLimit:",
|
|
206
|
+
gasLimitForCost,
|
|
207
|
+
"(estimated:",
|
|
208
|
+
estimatedGasLimit,
|
|
209
|
+
"default:",
|
|
210
|
+
DEFAULT_MIN_GASLIMIT,
|
|
211
|
+
")",
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
const gasCostWei = await estimateGasCost(publicClient, gasLimitForCost)
|
|
215
|
+
gasCost = gasCostWei.toString()
|
|
216
|
+
gasCostFormatted = formatUnits(gasCostWei, 18) // Native tokens always use 18 decimals
|
|
217
|
+
|
|
218
|
+
// Calculate USD value
|
|
219
|
+
gasCostUsd = await estimateGasCostUsd(
|
|
220
|
+
publicClient,
|
|
221
|
+
originNativeTokenPriceUsd,
|
|
222
|
+
gasLimitForCost,
|
|
223
|
+
)
|
|
224
|
+
gasCostUsdDisplay = formatUsdAmountDisplay(gasCostUsd)
|
|
225
|
+
|
|
226
|
+
logger.console.log(
|
|
227
|
+
"[trails-sdk][gas-estimation] Quote gas cost calculated:",
|
|
228
|
+
{
|
|
229
|
+
gasCostWei,
|
|
230
|
+
gasCost,
|
|
231
|
+
gasCostFormatted,
|
|
232
|
+
gasCostUsd,
|
|
233
|
+
gasCostUsdDisplay,
|
|
234
|
+
},
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
} catch (error) {
|
|
238
|
+
logger.console.error(
|
|
239
|
+
"[trails-sdk][gas-estimation] Error estimating gas cost for quote display",
|
|
240
|
+
error,
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Calculate exchange rates
|
|
245
|
+
const originTokenPrice = originTokenPriceUsd ? Number(originTokenPriceUsd) : 0
|
|
246
|
+
const destinationTokenPrice = destinationTokenPriceUsd
|
|
247
|
+
? Number(destinationTokenPriceUsd)
|
|
248
|
+
: 0
|
|
249
|
+
const exchangeRates = getTokenExchangeRates(
|
|
250
|
+
originTokenPrice,
|
|
251
|
+
destinationTokenPrice,
|
|
252
|
+
originToken.symbol,
|
|
253
|
+
destinationToken.symbol,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
let quoteProviderUrl = ""
|
|
257
|
+
if (quoteProvider === "cctp") {
|
|
258
|
+
quoteProviderUrl = "https://www.circle.com/"
|
|
259
|
+
} else if (quoteProvider === "relay") {
|
|
260
|
+
quoteProviderUrl = "https://relay.link/"
|
|
261
|
+
} else if (quoteProvider === "lifi") {
|
|
262
|
+
quoteProviderUrl = "https://li.fi/"
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const quoteProviderNames = {
|
|
266
|
+
cctp: "Circle CCTP",
|
|
267
|
+
relay: "Relay",
|
|
268
|
+
lifi: "LiFi",
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const quoteProviderName =
|
|
272
|
+
quoteProviderNames[quoteProvider as keyof typeof quoteProviderNames] ||
|
|
273
|
+
quoteProvider ||
|
|
274
|
+
""
|
|
275
|
+
const quoteProviderInfo: QuoteProviderInfo = {
|
|
276
|
+
id: quoteProvider || "",
|
|
277
|
+
name: quoteProviderName || "",
|
|
278
|
+
url: quoteProviderUrl || "",
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const priceImpactUsdDisplay = formatUsdAmountDisplay(priceImpactUsd)
|
|
282
|
+
|
|
283
|
+
// Extract fee breakdown from intent if available
|
|
284
|
+
let trailsFeeBreakdown = null
|
|
285
|
+
if (intent) {
|
|
286
|
+
trailsFeeBreakdown = await extractTrailsFeeBreakdown(intent)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return {
|
|
290
|
+
originDepositAddress: originDepositAddress || "",
|
|
291
|
+
destinationDepositAddress: destinationDepositAddress || "",
|
|
292
|
+
destinationAddress: destinationAddress || "",
|
|
293
|
+
destinationCalldata: hasCustomCalldata ? destinationCalldata || "" : "",
|
|
294
|
+
originAmount: originAmount || "0",
|
|
295
|
+
originAmountMin: originAmountMin || originAmount || "0",
|
|
296
|
+
originAmountMinUsdFormatted: originAmountMinUsdFormatted || "0",
|
|
297
|
+
originAmountMinUsdDisplay: originAmountMinUsdDisplay || "0",
|
|
298
|
+
destinationAmount: destinationAmount || "0",
|
|
299
|
+
destinationAmountMin: destinationAmountMin || destinationAmount || "0",
|
|
300
|
+
destinationAmountMinUsdFormatted: destinationAmountMinUsdFormatted || "0",
|
|
301
|
+
destinationAmountMinUsdDisplay: destinationAmountMinUsdDisplay || "0",
|
|
302
|
+
originAmountFormatted,
|
|
303
|
+
originAmountUsdFormatted,
|
|
304
|
+
originAmountUsdDisplay,
|
|
305
|
+
destinationAmountFormatted,
|
|
306
|
+
destinationAmountUsdFormatted,
|
|
307
|
+
destinationAmountUsdDisplay,
|
|
308
|
+
originToken,
|
|
309
|
+
destinationToken,
|
|
310
|
+
fees: fees || getZeroFees(),
|
|
311
|
+
slippageTolerance: slippageTolerance || "0",
|
|
312
|
+
priceImpact: priceImpact || "0",
|
|
313
|
+
priceImpactUsdDisplay: priceImpactUsdDisplay || "0",
|
|
314
|
+
originChain,
|
|
315
|
+
destinationChain,
|
|
316
|
+
completionEstimateSeconds: getCompletionEstimateSeconds({
|
|
317
|
+
originChainId,
|
|
318
|
+
destinationChainId,
|
|
319
|
+
}),
|
|
320
|
+
transactionStates: transactionStates || [],
|
|
321
|
+
gasCostUsd,
|
|
322
|
+
gasCostUsdDisplay,
|
|
323
|
+
gasCost,
|
|
324
|
+
gasCostFormatted,
|
|
325
|
+
originTokenRate: exchangeRates.originTokenRate,
|
|
326
|
+
destinationTokenRate: exchangeRates.destinationTokenRate,
|
|
327
|
+
originAmountDisplay: formatAmountDisplay(originAmountFormatted),
|
|
328
|
+
destinationAmountDisplay: formatAmountDisplay(destinationAmountFormatted),
|
|
329
|
+
originAmountMinDisplay: formatAmountDisplay(originAmountMinFormatted),
|
|
330
|
+
destinationAmountMinDisplay: formatAmountDisplay(
|
|
331
|
+
destinationAmountMinFormatted,
|
|
332
|
+
),
|
|
333
|
+
quoteProvider: quoteProviderInfo,
|
|
334
|
+
noSufficientBalance: noSufficientBalance || false,
|
|
335
|
+
trailsFeeBreakdown,
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function getTokenExchangeRates(
|
|
340
|
+
originTokenPrice: number,
|
|
341
|
+
destinationTokenPrice: number,
|
|
342
|
+
originTokenSymbol: string,
|
|
343
|
+
destinationTokenSymbol: string,
|
|
344
|
+
): { originTokenRate: string; destinationTokenRate: string } {
|
|
345
|
+
if (originTokenPrice === 0 || destinationTokenPrice === 0) {
|
|
346
|
+
return {
|
|
347
|
+
originTokenRate: "0",
|
|
348
|
+
destinationTokenRate: "0",
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const originToDestination = originTokenPrice / destinationTokenPrice
|
|
353
|
+
const destinationToOrigin = destinationTokenPrice / originTokenPrice
|
|
354
|
+
|
|
355
|
+
// Format the rates with appropriate precision
|
|
356
|
+
const originTokenRate = formatAmountDisplay(originToDestination, {
|
|
357
|
+
maxFractionDigits: destinationTokenSymbol === "USDC" ? 2 : 7,
|
|
358
|
+
})
|
|
359
|
+
const destinationTokenRate = formatAmountDisplay(destinationToOrigin, {
|
|
360
|
+
maxFractionDigits: originTokenSymbol === "USDC" ? 2 : 7,
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
return {
|
|
364
|
+
originTokenRate: `1 ${originTokenSymbol} = ${originTokenRate} ${destinationTokenSymbol}`,
|
|
365
|
+
destinationTokenRate: `1 ${destinationTokenSymbol} = ${destinationTokenRate} ${originTokenSymbol}`,
|
|
366
|
+
}
|
|
367
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { QuoteIntentRequest } from "@0xsequence/trails-api"
|
|
2
|
+
import { QuoteProviderType } from "@0xsequence/trails-api"
|
|
3
|
+
import { getIsCustomCalldata } from "../../contractUtils.js"
|
|
4
|
+
import type { TradeType } from "../types.js"
|
|
5
|
+
|
|
6
|
+
export function getIntentArgs(
|
|
7
|
+
mainSignerAddress: string,
|
|
8
|
+
originChainId: number,
|
|
9
|
+
originTokenAddress: string,
|
|
10
|
+
originTokenAmount: string,
|
|
11
|
+
destinationChainId: number,
|
|
12
|
+
destinationTokenAddress: string,
|
|
13
|
+
destinationTokenAmount: string,
|
|
14
|
+
recipient: string,
|
|
15
|
+
destinationCalldata: string | undefined,
|
|
16
|
+
_destinationSalt: string = Date.now().toString(),
|
|
17
|
+
slippageTolerance: string, // 0.03 = 3%
|
|
18
|
+
tradeType: TradeType,
|
|
19
|
+
provider?: string | null,
|
|
20
|
+
): QuoteIntentRequest {
|
|
21
|
+
const hasCustomCalldata = getIsCustomCalldata(destinationCalldata)
|
|
22
|
+
|
|
23
|
+
if (!provider || provider === "auto") {
|
|
24
|
+
provider = undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const intentArgs: QuoteIntentRequest = {
|
|
28
|
+
ownerAddress: mainSignerAddress,
|
|
29
|
+
originChainId,
|
|
30
|
+
originTokenAddress,
|
|
31
|
+
originTokenAmount: BigInt(originTokenAmount),
|
|
32
|
+
destinationChainId,
|
|
33
|
+
destinationToAddress: recipient,
|
|
34
|
+
destinationTokenAddress: destinationTokenAddress,
|
|
35
|
+
destinationTokenAmount: BigInt(destinationTokenAmount),
|
|
36
|
+
destinationCallData: hasCustomCalldata ? destinationCalldata : "0x",
|
|
37
|
+
destinationCallValue: "0",
|
|
38
|
+
options: {
|
|
39
|
+
slippageTolerance: Number(slippageTolerance),
|
|
40
|
+
quoteProvider:
|
|
41
|
+
provider === "relay"
|
|
42
|
+
? QuoteProviderType.RELAY
|
|
43
|
+
: provider === "cctp"
|
|
44
|
+
? QuoteProviderType.CCTPV2
|
|
45
|
+
: provider === "lifi"
|
|
46
|
+
? QuoteProviderType.LIFI
|
|
47
|
+
: undefined,
|
|
48
|
+
},
|
|
49
|
+
tradeType,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return intentArgs
|
|
53
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { Account, Chain, TransactionReceipt, WalletClient } from "viem"
|
|
2
|
+
import type {
|
|
3
|
+
TrailsAPIClient,
|
|
4
|
+
Intent,
|
|
5
|
+
CommitIntentResponse,
|
|
6
|
+
DepositSignature,
|
|
7
|
+
FeeOption,
|
|
8
|
+
GasFeeOptions,
|
|
9
|
+
ExecuteIntentResponse,
|
|
10
|
+
} from "@0xsequence/trails-api"
|
|
11
|
+
import type { TransactionState } from "../transactions.js"
|
|
12
|
+
import type { SupportedToken } from "../tokens.js"
|
|
13
|
+
import type { CheckoutOnHandlers } from "../widget/hooks/useCheckout.js"
|
|
14
|
+
import type { QuoteProviderInfo } from "../widget/hooks/useQuote.js"
|
|
15
|
+
import type { TrailsFeeBreakdown } from "../fees.js"
|
|
16
|
+
import type { IntentTransaction } from "@0xsequence/trails-api"
|
|
17
|
+
|
|
18
|
+
// Use native IntentTransaction from trails-api instead of deprecated MetaTxnReceipt
|
|
19
|
+
export type MetaTxnReceipt = IntentTransaction
|
|
20
|
+
|
|
21
|
+
// Flexible fee token type that accepts both full FeeOption and minimal fee token objects
|
|
22
|
+
// Also accepts objects with amountUSD for widget components
|
|
23
|
+
export type SelectedFeeToken =
|
|
24
|
+
| FeeOption
|
|
25
|
+
| {
|
|
26
|
+
tokenAddress: string
|
|
27
|
+
tokenSymbol?: string
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
tokenAddress: string
|
|
31
|
+
tokenSymbol: string
|
|
32
|
+
tokenDecimals: number
|
|
33
|
+
amount: string
|
|
34
|
+
amountUSD: number
|
|
35
|
+
notEnoughBalance?: boolean
|
|
36
|
+
tokenImageUrl?: string
|
|
37
|
+
chainId?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export enum TradeType {
|
|
41
|
+
EXACT_INPUT = "EXACT_INPUT",
|
|
42
|
+
EXACT_OUTPUT = "EXACT_OUTPUT",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type PrepareSendOptions = {
|
|
46
|
+
account: Account
|
|
47
|
+
originTokenAddress: string
|
|
48
|
+
originChainId: number
|
|
49
|
+
originTokenBalance: string
|
|
50
|
+
destinationChainId: number
|
|
51
|
+
recipient: string
|
|
52
|
+
destinationTokenAddress: string
|
|
53
|
+
swapAmount: string
|
|
54
|
+
tradeType?: TradeType
|
|
55
|
+
originTokenSymbol: string
|
|
56
|
+
destinationTokenSymbol: string
|
|
57
|
+
sequenceProjectAccessKey?: string
|
|
58
|
+
fee: string
|
|
59
|
+
client?: WalletClient
|
|
60
|
+
dryMode: boolean
|
|
61
|
+
trailsClient: TrailsAPIClient
|
|
62
|
+
destinationCalldata?: string
|
|
63
|
+
onTransactionStateChange: (transactionStates: TransactionState[]) => void
|
|
64
|
+
sourceTokenPriceUsd?: number | null
|
|
65
|
+
destinationTokenPriceUsd?: number | null
|
|
66
|
+
sourceTokenDecimals: number
|
|
67
|
+
destinationTokenDecimals: number
|
|
68
|
+
paymasterUrl?: string
|
|
69
|
+
gasless?: boolean
|
|
70
|
+
slippageTolerance?: string
|
|
71
|
+
originNativeTokenPriceUsd?: number | null
|
|
72
|
+
quoteProvider?: string | null
|
|
73
|
+
fundMethod?: string
|
|
74
|
+
mode?: "pay" | "fund" | "earn" | "swap" | "receive"
|
|
75
|
+
checkoutOnHandlers?: CheckoutOnHandlers
|
|
76
|
+
refundAddress?: string
|
|
77
|
+
selectedFeeToken?: SelectedFeeToken
|
|
78
|
+
walletId?: string
|
|
79
|
+
abortSignal?: AbortSignal
|
|
80
|
+
// Optional mutation callbacks for React Query integration
|
|
81
|
+
commitIntentFn?: (intent: Intent) => Promise<CommitIntentResponse>
|
|
82
|
+
executeIntentFn?: (params: {
|
|
83
|
+
intentId: string
|
|
84
|
+
depositTransactionHash?: string
|
|
85
|
+
depositSignature?: DepositSignature
|
|
86
|
+
}) => Promise<ExecuteIntentResponse>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type PrepareSendFees = {
|
|
90
|
+
feeTokenAddress: string | null
|
|
91
|
+
totalFeeAmount: string | null
|
|
92
|
+
totalFeeAmountUsd: string | null
|
|
93
|
+
totalFeeAmountUsdDisplay: string | null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type PrepareSendQuote = {
|
|
97
|
+
originDepositAddress: string
|
|
98
|
+
destinationDepositAddress: string
|
|
99
|
+
destinationAddress: string
|
|
100
|
+
destinationCalldata: string
|
|
101
|
+
originChain: Chain
|
|
102
|
+
destinationChain: Chain
|
|
103
|
+
originAmount: string
|
|
104
|
+
originAmountDisplay: string
|
|
105
|
+
originAmountMin: string
|
|
106
|
+
originAmountMinDisplay: string
|
|
107
|
+
originAmountMinUsdFormatted: string
|
|
108
|
+
originAmountMinUsdDisplay: string
|
|
109
|
+
destinationAmount: string
|
|
110
|
+
destinationAmountDisplay: string
|
|
111
|
+
destinationAmountMin: string
|
|
112
|
+
destinationAmountMinDisplay: string
|
|
113
|
+
destinationAmountMinUsdFormatted: string
|
|
114
|
+
destinationAmountMinUsdDisplay: string
|
|
115
|
+
originAmountFormatted: string
|
|
116
|
+
originAmountUsdFormatted: string
|
|
117
|
+
originAmountUsdDisplay: string
|
|
118
|
+
destinationAmountFormatted: string
|
|
119
|
+
destinationAmountUsdFormatted: string
|
|
120
|
+
destinationAmountUsdDisplay: string
|
|
121
|
+
originToken: SupportedToken
|
|
122
|
+
destinationToken: SupportedToken
|
|
123
|
+
fees: PrepareSendFees
|
|
124
|
+
slippageTolerance: string
|
|
125
|
+
priceImpact: string
|
|
126
|
+
priceImpactUsdDisplay: string
|
|
127
|
+
completionEstimateSeconds: number
|
|
128
|
+
transactionStates: TransactionState[]
|
|
129
|
+
gasCostUsd: number
|
|
130
|
+
gasCostUsdDisplay: string
|
|
131
|
+
gasCost: string
|
|
132
|
+
gasCostFormatted: string
|
|
133
|
+
originTokenRate: string
|
|
134
|
+
destinationTokenRate: string
|
|
135
|
+
quoteProvider: QuoteProviderInfo | null
|
|
136
|
+
noSufficientBalance: boolean
|
|
137
|
+
trailsFeeBreakdown?: TrailsFeeBreakdown | null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type PrepareSendReturn = {
|
|
141
|
+
quote: PrepareSendQuote
|
|
142
|
+
feeOptions?: GasFeeOptions
|
|
143
|
+
send: ({
|
|
144
|
+
onOriginSend,
|
|
145
|
+
selectedFeeToken,
|
|
146
|
+
}: {
|
|
147
|
+
onOriginSend?: () => void
|
|
148
|
+
selectedFeeToken?: SelectedFeeToken
|
|
149
|
+
}) => Promise<SendReturn>
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export type SendReturn = {
|
|
153
|
+
depositUserTxnReceipt: TransactionReceipt | null
|
|
154
|
+
originMetaTxnReceipt: MetaTxnReceipt | null
|
|
155
|
+
destinationMetaTxnReceipt: MetaTxnReceipt | null
|
|
156
|
+
totalCompletionSeconds?: number
|
|
157
|
+
}
|