0xtrails 0.2.4 → 0.2.6
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 +8 -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-BlV1Mry3.js → ccip-Xjh9d1gb.js} +7 -7
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/error.d.ts +1 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/estimate.d.ts +52 -0
- package/dist/estimate.d.ts.map +1 -1
- package/dist/fees.d.ts +19 -0
- package/dist/fees.d.ts.map +1 -0
- package/dist/{index-BNWCIGfQ.js → index-BnhdZ8Ho.js} +76406 -75798
- package/dist/index.js +726 -520
- package/dist/intents.d.ts +40 -0
- package/dist/intents.d.ts.map +1 -1
- package/dist/metaTxnMonitor.d.ts +3 -3
- package/dist/metaTxnMonitor.d.ts.map +1 -1
- package/dist/metaTxns.d.ts +3 -3
- package/dist/metaTxns.d.ts.map +1 -1
- package/dist/morpho.d.ts +8 -0
- package/dist/morpho.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +19 -75
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/queryParams.d.ts.map +1 -1
- package/dist/relayer.d.ts +6 -6
- package/dist/relayer.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +2 -2
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/transactions.d.ts +4 -2
- 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/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 +4 -2
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
- package/dist/widget/components/ConnectedWallets.d.ts +4 -0
- 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/Earn.d.ts +2 -2
- 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/Fund.d.ts +2 -2
- package/dist/widget/components/Fund.d.ts.map +1 -1
- package/dist/widget/components/FundMethods.d.ts.map +1 -1
- package/dist/widget/components/{FundSendForm.d.ts → FundSwap.d.ts} +13 -7
- package/dist/widget/components/FundSwap.d.ts.map +1 -0
- package/dist/widget/components/FundingMethodSelectorButton.d.ts +4 -0
- package/dist/widget/components/FundingMethodSelectorButton.d.ts.map +1 -0
- 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 -2
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PercentageMaxButtons.d.ts +12 -0
- package/dist/widget/components/PercentageMaxButtons.d.ts.map +1 -0
- package/dist/widget/components/{PaySendForm.d.ts → PoolDeposit.d.ts} +14 -36
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -0
- package/dist/widget/components/{SimpleSwap.d.ts → PoolWithdraw.d.ts} +19 -10
- package/dist/widget/components/PoolWithdraw.d.ts.map +1 -0
- package/dist/widget/components/QuoteDetails.d.ts +1 -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/Receive.d.ts.map +1 -1
- package/dist/widget/components/RecipientSelectorButton.d.ts +4 -0
- package/dist/widget/components/RecipientSelectorButton.d.ts.map +1 -0
- package/dist/widget/components/Recipients.d.ts.map +1 -1
- package/dist/widget/components/RequiredPropsError.d.ts +8 -0
- package/dist/widget/components/RequiredPropsError.d.ts.map +1 -0
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
- package/dist/widget/components/Swap.d.ts +3 -2
- package/dist/widget/components/Swap.d.ts.map +1 -1
- package/dist/widget/components/SwapSettings.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/TokenImage.d.ts +1 -0
- package/dist/widget/components/TokenImage.d.ts.map +1 -1
- package/dist/widget/components/TokenList.d.ts.map +1 -1
- package/dist/widget/components/TokenSelector.d.ts.map +1 -1
- package/dist/widget/components/TokenSelectorButton.d.ts +16 -0
- package/dist/widget/components/TokenSelectorButton.d.ts.map +1 -0
- package/dist/widget/components/Tooltip.d.ts +9 -0
- package/dist/widget/components/Tooltip.d.ts.map +1 -0
- package/dist/widget/components/UserPreferences.d.ts.map +1 -1
- package/dist/widget/components/WaasFeeOptions.d.ts +9 -0
- package/dist/widget/components/WaasFeeOptions.d.ts.map +1 -0
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -1
- package/dist/widget/components/WalletConnect.d.ts.map +1 -1
- package/dist/widget/components/WalletList.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +2 -0
- package/dist/widget/css/index.css +554 -0
- package/dist/widget/hooks/useBack.d.ts +1 -0
- package/dist/widget/hooks/useBack.d.ts.map +1 -1
- package/dist/widget/hooks/useCheckout.d.ts +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/useDefaultTokenSelection.d.ts +3 -3
- package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -1
- package/dist/widget/hooks/usePayMessage.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +83 -0
- package/dist/widget/hooks/useQuote.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedFundMethod.d.ts +12 -0
- package/dist/widget/hooks/useSelectedFundMethod.d.ts.map +1 -0
- package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +2 -2
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/index.js +2 -2
- package/dist/widget/widget.d.ts +9 -4
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +18 -12
- package/src/aave.ts +32 -0
- package/src/abortController.ts +35 -0
- package/src/config.ts +12 -4
- package/src/constants.ts +5 -0
- package/src/error.ts +19 -1
- package/src/estimate.ts +416 -5
- package/src/fees.ts +199 -0
- package/src/intents.ts +161 -11
- package/src/metaTxnMonitor.ts +3 -3
- package/src/metaTxns.ts +3 -5
- package/src/morpho.ts +32 -0
- package/src/prepareSend.ts +714 -550
- package/src/queryParams.ts +2 -1
- package/src/relayer.ts +11 -11
- package/src/sequenceWallet.ts +2 -2
- package/src/tokens.ts +7 -1
- package/src/trails.ts +3 -3
- package/src/transactions.ts +62 -18
- package/src/wallets.ts +8 -0
- package/src/widget/compiled.css +2 -2
- package/src/widget/components/AccountActionsDropdown.tsx +3 -13
- package/src/widget/components/AccountIntentTransactionHistoryButton.tsx +22 -0
- package/src/widget/components/AccountSettings.tsx +48 -54
- package/src/widget/components/ChainFilterDropdown.tsx +24 -3
- package/src/widget/components/ClassicSwap.tsx +131 -213
- package/src/widget/components/ConnectWallet.tsx +8 -38
- package/src/widget/components/ConnectedWallets.tsx +132 -77
- package/src/widget/components/DynamicInputStyles.tsx +76 -0
- package/src/widget/components/Earn.tsx +82 -593
- package/src/widget/components/ErrorAnimationIcon.tsx +130 -0
- package/src/widget/components/FeeBreakdown.tsx +155 -0
- package/src/widget/components/Fund.tsx +41 -108
- package/src/widget/components/FundMethods.tsx +82 -159
- package/src/widget/components/FundSwap.tsx +52 -0
- package/src/widget/components/FundingMethodSelectorButton.tsx +70 -0
- package/src/widget/components/Identicon.tsx +164 -95
- package/src/widget/components/MeshConnectExchanges.tsx +2 -15
- package/src/widget/components/Modal.tsx +0 -8
- package/src/widget/components/Pay.tsx +214 -237
- package/src/widget/components/PercentageMaxButtons.tsx +77 -0
- package/src/widget/components/PoolDeposit.tsx +569 -0
- package/src/widget/components/PoolWithdraw.tsx +884 -0
- package/src/widget/components/PriceImpactWarning.tsx +1 -1
- package/src/widget/components/QuoteDetails.tsx +43 -12
- package/src/widget/components/Receipt.tsx +16 -2
- package/src/widget/components/Receive.tsx +0 -2
- package/src/widget/components/RecipientSelectorButton.tsx +44 -0
- package/src/widget/components/Recipients.tsx +63 -157
- package/src/widget/components/RequiredPropsError.tsx +33 -0
- package/src/widget/components/ScreenHeader.tsx +62 -34
- package/src/widget/components/SlippageToleranceSettings.tsx +2 -1
- package/src/widget/components/Swap.tsx +4 -45
- package/src/widget/components/SwapSettings.tsx +2 -14
- package/src/widget/components/ThemeProvider.tsx +2 -1
- package/src/widget/components/TokenDisplayNonSelectable.tsx +40 -0
- package/src/widget/components/TokenImage.tsx +22 -5
- package/src/widget/components/TokenList.tsx +0 -1
- package/src/widget/components/TokenSelector.tsx +63 -53
- package/src/widget/components/TokenSelectorButton.tsx +98 -0
- package/src/widget/components/Tooltip.tsx +51 -0
- package/src/widget/components/TransferPendingVertical.tsx +1 -1
- package/src/widget/components/UserPreferences.tsx +6 -24
- package/src/widget/components/WaasFeeOptions.tsx +450 -0
- package/src/widget/components/WalletConfirmation.tsx +76 -14
- package/src/widget/components/WalletConnect.tsx +93 -29
- package/src/widget/components/WalletList.tsx +4 -2
- package/src/widget/hooks/useBack.tsx +2 -0
- package/src/widget/hooks/useCheckout.ts +36 -20
- package/src/widget/hooks/useCurrentScreen.tsx +1 -0
- package/src/widget/hooks/useDefaultTokenSelection.tsx +104 -28
- package/src/widget/hooks/usePayMessage.tsx +86 -11
- package/src/widget/hooks/useQuote.ts +413 -0
- package/src/widget/hooks/useSelectedFundMethod.tsx +41 -0
- package/src/widget/hooks/useSelectedRecipient.tsx +10 -0
- package/src/widget/hooks/useSendForm.ts +32 -6
- package/src/widget/index.css +27 -0
- package/src/widget/widget.tsx +326 -283
- package/dist/widget/components/FundSendForm.d.ts.map +0 -1
- package/dist/widget/components/PaySendForm.d.ts.map +0 -1
- package/dist/widget/components/SimpleSwap.d.ts.map +0 -1
- package/dist/widget/hooks/useSwapSettings.d.ts +0 -16
- package/dist/widget/hooks/useSwapSettings.d.ts.map +0 -1
- package/src/widget/components/FundSendForm.tsx +0 -903
- package/src/widget/components/PaySendForm.tsx +0 -869
- package/src/widget/components/SimpleSwap.tsx +0 -983
- package/src/widget/hooks/useSwapSettings.tsx +0 -100
package/src/intents.ts
CHANGED
|
@@ -53,6 +53,9 @@ import {
|
|
|
53
53
|
} from "./analytics.js"
|
|
54
54
|
import { getQueryParam } from "./queryParams.js"
|
|
55
55
|
import { getFullErrorMessage } from "./error.js"
|
|
56
|
+
import { GAS_BUFFER, getFeeData } from "./estimate.js"
|
|
57
|
+
import { getERC20TransferData } from "./encoders.js"
|
|
58
|
+
import { zeroAddress } from "viem"
|
|
56
59
|
|
|
57
60
|
export type IntentRequestParams = {
|
|
58
61
|
userAddress: string
|
|
@@ -126,6 +129,9 @@ export type SendOriginCallTxArgs = {
|
|
|
126
129
|
data: Hex.Hex
|
|
127
130
|
value: bigint
|
|
128
131
|
chain: Chain
|
|
132
|
+
gasLimit?: bigint // Optional: if provided, skip gas estimation
|
|
133
|
+
maxFeePerGas?: bigint // Optional: EIP-1559 max fee per gas
|
|
134
|
+
maxPriorityFeePerGas?: bigint // Optional: EIP-1559 max priority fee per gas
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
export async function getLocalClientIfEnabled(
|
|
@@ -486,17 +492,67 @@ export async function sendOriginTransaction(
|
|
|
486
492
|
transport: http(),
|
|
487
493
|
})
|
|
488
494
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
+
// Use provided gasLimit if available, otherwise estimate
|
|
496
|
+
let gasLimit: bigint
|
|
497
|
+
if (originParams.gasLimit) {
|
|
498
|
+
gasLimit = originParams.gasLimit
|
|
499
|
+
logger.console.log(
|
|
500
|
+
"[trails-sdk][gas-estimation] using provided gasLimit:",
|
|
501
|
+
gasLimit,
|
|
502
|
+
)
|
|
503
|
+
} else {
|
|
504
|
+
const estimatedGasLimit = await publicClient.estimateGas({
|
|
505
|
+
account: account,
|
|
506
|
+
to: originParams.to as `0x${string}`,
|
|
507
|
+
data: originParams.data as `0x${string}`,
|
|
508
|
+
value: BigInt(originParams.value),
|
|
509
|
+
})
|
|
495
510
|
|
|
496
|
-
|
|
497
|
-
|
|
511
|
+
gasLimit = estimatedGasLimit + GAS_BUFFER
|
|
512
|
+
logger.console.log(
|
|
513
|
+
"[trails-sdk][gas-estimation] estimated gasLimit in sendOriginTransaction:",
|
|
514
|
+
gasLimit,
|
|
515
|
+
"(estimated:",
|
|
516
|
+
estimatedGasLimit,
|
|
517
|
+
"buffer:",
|
|
518
|
+
GAS_BUFFER,
|
|
519
|
+
")",
|
|
520
|
+
)
|
|
521
|
+
}
|
|
498
522
|
|
|
499
|
-
|
|
523
|
+
// Get fee parameters - try EIP-1559 first, then fall back to legacy
|
|
524
|
+
// Use provided fees if available, otherwise fetch and boost them for faster processing
|
|
525
|
+
let maxFeePerGas: bigint | undefined = originParams.maxFeePerGas
|
|
526
|
+
let maxPriorityFeePerGas: bigint | undefined =
|
|
527
|
+
originParams.maxPriorityFeePerGas
|
|
528
|
+
let gasPrice: bigint | undefined
|
|
529
|
+
|
|
530
|
+
if (!maxFeePerGas) {
|
|
531
|
+
try {
|
|
532
|
+
// Use getFeeData which applies the PRIORITY_FEE_MULTIPLIER
|
|
533
|
+
const feeData = await getFeeData(publicClient)
|
|
534
|
+
|
|
535
|
+
if (feeData.maxFeePerGas) {
|
|
536
|
+
maxFeePerGas = feeData.maxFeePerGas
|
|
537
|
+
maxPriorityFeePerGas = feeData.maxPriorityFeePerGas
|
|
538
|
+
logger.console.log(
|
|
539
|
+
"[trails-sdk][gas-estimation] Using boosted EIP-1559 fees in sendOriginTransaction:",
|
|
540
|
+
{ maxFeePerGas, maxPriorityFeePerGas },
|
|
541
|
+
)
|
|
542
|
+
} else if (feeData.gasPrice) {
|
|
543
|
+
gasPrice = feeData.gasPrice
|
|
544
|
+
logger.console.log(
|
|
545
|
+
"[trails-sdk][gas-estimation] Using boosted legacy gas price in sendOriginTransaction:",
|
|
546
|
+
{ gasPrice },
|
|
547
|
+
)
|
|
548
|
+
}
|
|
549
|
+
} catch (_error) {
|
|
550
|
+
// Fee data fetch failed, will use wallet default
|
|
551
|
+
logger.console.log(
|
|
552
|
+
"[trails-sdk][gas-estimation] Fee data fetch failed in sendOriginTransaction, wallet will use default",
|
|
553
|
+
)
|
|
554
|
+
}
|
|
555
|
+
}
|
|
500
556
|
|
|
501
557
|
logger.console.log(
|
|
502
558
|
"[trails-sdk] sending origin tx with walletClient.sendTransaction()",
|
|
@@ -505,14 +561,27 @@ export async function sendOriginTransaction(
|
|
|
505
561
|
logger.console.time(`[trails-sdk] walletClient.sendTransaction-${id}`)
|
|
506
562
|
|
|
507
563
|
try {
|
|
508
|
-
|
|
564
|
+
// Build transaction parameters - EIP-1559 and legacy are mutually exclusive
|
|
565
|
+
const txParams: any = {
|
|
509
566
|
account: account,
|
|
510
567
|
to: originParams.to as `0x${string}`,
|
|
511
568
|
data: originParams.data as `0x${string}`,
|
|
512
569
|
value: BigInt(originParams.value),
|
|
513
570
|
chain: originParams.chain,
|
|
514
571
|
gas: gasLimit,
|
|
515
|
-
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// Add fee parameters based on transaction type
|
|
575
|
+
if (maxFeePerGas && maxPriorityFeePerGas) {
|
|
576
|
+
// EIP-1559 transaction
|
|
577
|
+
txParams.maxFeePerGas = maxFeePerGas
|
|
578
|
+
txParams.maxPriorityFeePerGas = maxPriorityFeePerGas
|
|
579
|
+
} else if (gasPrice) {
|
|
580
|
+
// Legacy transaction
|
|
581
|
+
txParams.gasPrice = gasPrice
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const hash = await walletClient.sendTransaction(txParams)
|
|
516
585
|
logger.console.timeEnd(`[trails-sdk] walletClient.sendTransaction-${id}`)
|
|
517
586
|
logger.console.log("[trails-sdk] done sending, origin tx hash", hash)
|
|
518
587
|
|
|
@@ -807,3 +876,84 @@ function buildMerkleTreeFromMembers(
|
|
|
807
876
|
}
|
|
808
877
|
return currentLevel[0]!
|
|
809
878
|
}
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Build transaction parameters for same-chain same-token transactions
|
|
882
|
+
* Centralizes the logic for determining transaction destination, data, and value
|
|
883
|
+
*/
|
|
884
|
+
export function buildSameChainTransactionParams({
|
|
885
|
+
hasCustomCalldata,
|
|
886
|
+
recipient,
|
|
887
|
+
effectiveOriginTokenAddress,
|
|
888
|
+
destinationCalldata,
|
|
889
|
+
swapAmount,
|
|
890
|
+
effectiveOriginChainId,
|
|
891
|
+
effectiveOriginChain,
|
|
892
|
+
}: {
|
|
893
|
+
hasCustomCalldata: boolean
|
|
894
|
+
recipient: string
|
|
895
|
+
effectiveOriginTokenAddress: string
|
|
896
|
+
destinationCalldata?: string
|
|
897
|
+
swapAmount: string
|
|
898
|
+
effectiveOriginChainId: number
|
|
899
|
+
effectiveOriginChain: Chain
|
|
900
|
+
}) {
|
|
901
|
+
return {
|
|
902
|
+
to: hasCustomCalldata
|
|
903
|
+
? recipient
|
|
904
|
+
: effectiveOriginTokenAddress === zeroAddress
|
|
905
|
+
? recipient
|
|
906
|
+
: effectiveOriginTokenAddress,
|
|
907
|
+
data: hasCustomCalldata
|
|
908
|
+
? destinationCalldata || "0x"
|
|
909
|
+
: effectiveOriginTokenAddress === zeroAddress
|
|
910
|
+
? "0x"
|
|
911
|
+
: getERC20TransferData({
|
|
912
|
+
recipient,
|
|
913
|
+
amount: BigInt(swapAmount),
|
|
914
|
+
}),
|
|
915
|
+
value:
|
|
916
|
+
effectiveOriginTokenAddress === zeroAddress ? BigInt(swapAmount) : "0",
|
|
917
|
+
chainId: effectiveOriginChainId,
|
|
918
|
+
chain: effectiveOriginChain,
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Build transaction parameters for cross-chain deposit transactions
|
|
924
|
+
* Centralizes the logic for determining transaction destination, data, and value for deposits
|
|
925
|
+
*/
|
|
926
|
+
export function buildCrossChainDepositParams({
|
|
927
|
+
originTokenAddress,
|
|
928
|
+
originIntentAddress,
|
|
929
|
+
depositAmount,
|
|
930
|
+
fee,
|
|
931
|
+
originChainId,
|
|
932
|
+
chain,
|
|
933
|
+
}: {
|
|
934
|
+
originTokenAddress: string
|
|
935
|
+
originIntentAddress: string
|
|
936
|
+
depositAmount: string
|
|
937
|
+
fee: string
|
|
938
|
+
originChainId: number
|
|
939
|
+
chain: Chain
|
|
940
|
+
}) {
|
|
941
|
+
const totalAmount = BigInt(depositAmount) + BigInt(fee)
|
|
942
|
+
|
|
943
|
+
return {
|
|
944
|
+
to:
|
|
945
|
+
originTokenAddress === zeroAddress
|
|
946
|
+
? originIntentAddress
|
|
947
|
+
: originTokenAddress,
|
|
948
|
+
data:
|
|
949
|
+
originTokenAddress === zeroAddress
|
|
950
|
+
? "0x"
|
|
951
|
+
: getERC20TransferData({
|
|
952
|
+
recipient: originIntentAddress,
|
|
953
|
+
amount: totalAmount,
|
|
954
|
+
}),
|
|
955
|
+
value: originTokenAddress === zeroAddress ? totalAmount : "0",
|
|
956
|
+
chainId: originChainId,
|
|
957
|
+
chain,
|
|
958
|
+
}
|
|
959
|
+
}
|
package/src/metaTxnMonitor.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
RelayerOperationStatus,
|
|
6
6
|
RelayerOperationUnknownStatus,
|
|
7
7
|
} from "./relayer.js"
|
|
8
|
-
import type {
|
|
8
|
+
import type { Relayer } from "@0xsequence/relayer"
|
|
9
9
|
import { type Query, useQueries } from "@tanstack/react-query"
|
|
10
10
|
import { useMemo } from "react"
|
|
11
11
|
import type { Hex } from "viem"
|
|
@@ -26,7 +26,7 @@ export type MetaTxnStatus = {
|
|
|
26
26
|
const POLL_INTERVAL = 3_000 // 3 seconds
|
|
27
27
|
|
|
28
28
|
export const getMetaTxStatus = async (
|
|
29
|
-
relayer:
|
|
29
|
+
relayer: Relayer.RpcRelayer,
|
|
30
30
|
metaTxId: string,
|
|
31
31
|
chainId: number,
|
|
32
32
|
): Promise<RelayerOperationStatus> => {
|
|
@@ -35,7 +35,7 @@ export const getMetaTxStatus = async (
|
|
|
35
35
|
|
|
36
36
|
export const useMetaTxnsMonitor = (
|
|
37
37
|
metaTxns: MetaTxn[] | undefined,
|
|
38
|
-
getRelayer: (chainId: number) =>
|
|
38
|
+
getRelayer: (chainId: number) => Relayer.RpcRelayer,
|
|
39
39
|
) => {
|
|
40
40
|
const results = useQueries({
|
|
41
41
|
queries: (metaTxns || []).map((metaTxn) => {
|
package/src/metaTxns.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
+
import type { Relayer } from "@0xsequence/relayer"
|
|
1
2
|
import type { IntentPrecondition } from "@0xsequence/trails-api"
|
|
2
3
|
import type { Hex } from "viem"
|
|
3
4
|
import type { MetaTxn } from "./metaTxnMonitor.js"
|
|
4
|
-
import type { RpcRelayer } from "@0xsequence/relayer"
|
|
5
|
-
|
|
6
5
|
import { logger } from "./logger.js"
|
|
7
|
-
import type { Relayer } from "@0xsequence/relayer"
|
|
8
6
|
|
|
9
7
|
export async function relayerSendMetaTx(
|
|
10
|
-
relayer:
|
|
8
|
+
relayer: Relayer.RpcRelayer,
|
|
11
9
|
metaTx: MetaTxn,
|
|
12
10
|
preconditions: IntentPrecondition[],
|
|
13
11
|
feeQuote?: Relayer.FeeQuote,
|
|
@@ -25,7 +23,7 @@ export async function relayerSendMetaTx(
|
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export async function getMetaTxnReceipt(
|
|
28
|
-
relayer:
|
|
26
|
+
relayer: Relayer.RpcRelayer,
|
|
29
27
|
metaTxId: string,
|
|
30
28
|
chainId: number,
|
|
31
29
|
): Promise<{ receipt: { status: "confirmed" | "failed" | "pending" } }> {
|
package/src/morpho.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMemo, useState, useEffect } from "react"
|
|
2
2
|
import type { Address, PublicClient } from "viem"
|
|
3
|
+
import { encodeFunctionData } from "viem"
|
|
3
4
|
import { logger } from "./logger.js"
|
|
4
5
|
|
|
5
6
|
type AccrualPosition = any
|
|
@@ -425,4 +426,35 @@ export async function getAllVaults(
|
|
|
425
426
|
return transformedVaults
|
|
426
427
|
}
|
|
427
428
|
|
|
429
|
+
/**
|
|
430
|
+
* Generate Morpho vault withdraw calldata
|
|
431
|
+
* @param asset - The address of the underlying asset to withdraw
|
|
432
|
+
* @param amount - The amount to withdraw in wei (or max uint256 for full balance)
|
|
433
|
+
* @param to - The address that will receive the underlying tokens
|
|
434
|
+
* @returns Encoded calldata for Morpho withdraw function
|
|
435
|
+
*/
|
|
436
|
+
export function generateMorphoWithdrawCalldata(
|
|
437
|
+
asset: string,
|
|
438
|
+
amount: bigint,
|
|
439
|
+
to: string,
|
|
440
|
+
): `0x${string}` {
|
|
441
|
+
return encodeFunctionData({
|
|
442
|
+
abi: [
|
|
443
|
+
{
|
|
444
|
+
name: "withdraw",
|
|
445
|
+
type: "function",
|
|
446
|
+
stateMutability: "nonpayable",
|
|
447
|
+
inputs: [
|
|
448
|
+
{ name: "asset", type: "address" },
|
|
449
|
+
{ name: "amount", type: "uint256" },
|
|
450
|
+
{ name: "to", type: "address" },
|
|
451
|
+
],
|
|
452
|
+
outputs: [{ type: "uint256" }],
|
|
453
|
+
},
|
|
454
|
+
],
|
|
455
|
+
functionName: "withdraw",
|
|
456
|
+
args: [asset as `0x${string}`, amount, to as `0x${string}`],
|
|
457
|
+
})
|
|
458
|
+
}
|
|
459
|
+
|
|
428
460
|
export default useMorphoVaults
|