0xtrails 0.0.1 → 0.0.2
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/LICENSE +202 -0
- package/README.md +42 -0
- package/dist/abi.d.ts +37 -0
- package/dist/abi.d.ts.map +1 -0
- package/dist/abi.js +36 -0
- package/dist/apiClient.d.ts +9 -0
- package/dist/apiClient.d.ts.map +1 -0
- package/dist/apiClient.js +18 -0
- package/dist/buffer.d.ts +3 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +8 -0
- package/dist/cctp.d.ts +84 -0
- package/dist/cctp.d.ts.map +1 -0
- package/dist/cctp.js +401 -0
- package/dist/chainSwitch.d.ts +7 -0
- package/dist/chainSwitch.d.ts.map +1 -0
- package/dist/chainSwitch.js +33 -0
- package/dist/chains.d.ts +13 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +95 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -0
- package/dist/encoders.d.ts +7 -0
- package/dist/encoders.d.ts.map +1 -0
- package/dist/encoders.js +8 -0
- package/dist/error.d.ts +2 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +12 -0
- package/dist/explorer.d.ts +12 -0
- package/dist/explorer.d.ts.map +1 -0
- package/dist/explorer.js +18 -0
- package/dist/gasless.d.ts +116 -0
- package/dist/gasless.d.ts.map +1 -0
- package/dist/gasless.js +297 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/indexerClient.d.ts +9 -0
- package/dist/indexerClient.d.ts.map +1 -0
- package/dist/indexerClient.js +18 -0
- package/dist/intents.d.ts +83 -0
- package/dist/intents.d.ts.map +1 -0
- package/dist/intents.js +288 -0
- package/dist/metaTxnMonitor.d.ts +14 -0
- package/dist/metaTxnMonitor.d.ts.map +1 -0
- package/dist/metaTxnMonitor.js +121 -0
- package/dist/metaTxns.d.ts +6 -0
- package/dist/metaTxns.d.ts.map +1 -0
- package/dist/metaTxns.js +4 -0
- package/dist/paymasterSend.d.ts +90 -0
- package/dist/paymasterSend.d.ts.map +1 -0
- package/dist/paymasterSend.js +329 -0
- package/dist/preconditions.d.ts +11 -0
- package/dist/preconditions.d.ts.map +1 -0
- package/dist/preconditions.js +29 -0
- package/dist/prepareSend.d.ts +102 -0
- package/dist/prepareSend.d.ts.map +1 -0
- package/dist/prepareSend.js +1080 -0
- package/dist/prices.d.ts +18 -0
- package/dist/prices.d.ts.map +1 -0
- package/dist/prices.js +142 -0
- package/dist/queryParams.d.ts +9 -0
- package/dist/queryParams.d.ts.map +1 -0
- package/dist/queryParams.js +66 -0
- package/dist/relaySdk.d.ts +65 -0
- package/dist/relaySdk.d.ts.map +1 -0
- package/dist/relaySdk.js +314 -0
- package/dist/relayer.d.ts +23 -0
- package/dist/relayer.d.ts.map +1 -0
- package/dist/relayer.js +230 -0
- package/dist/sendUserOp.d.ts +140 -0
- package/dist/sendUserOp.d.ts.map +1 -0
- package/dist/sendUserOp.js +388 -0
- package/dist/sequenceWallet.d.ts +79 -0
- package/dist/sequenceWallet.d.ts.map +1 -0
- package/dist/sequenceWallet.js +374 -0
- package/dist/theme.d.ts +3 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +1 -0
- package/dist/toSimpleSmartAccount.d.ts +95 -0
- package/dist/toSimpleSmartAccount.d.ts.map +1 -0
- package/dist/toSimpleSmartAccount.js +373 -0
- package/dist/tokenBalances.d.ts +118 -0
- package/dist/tokenBalances.d.ts.map +1 -0
- package/dist/tokenBalances.js +492 -0
- package/dist/tokens.d.ts +50 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +356 -0
- package/dist/trails.d.ts +128 -0
- package/dist/trails.d.ts.map +1 -0
- package/dist/trails.js +1031 -0
- package/dist/umd/trails.min.js +12610 -0
- package/dist/umd/trails.min.js.map +1 -0
- package/dist/umd.d.ts +24 -0
- package/dist/umd.d.ts.map +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +9 -0
- package/dist/widget/ConstantsUtil-B-_-u8aQ.js +6 -0
- package/dist/widget/add-hVLs3ldJ.js +20 -0
- package/dist/widget/all-wallets-Cwxnx4BT.js +11 -0
- package/dist/widget/app-store-CAAVQjW0.js +22 -0
- package/dist/widget/apple-C3BSbglw.js +23 -0
- package/dist/widget/arrow-bottom-circle-BGU9MmsZ.js +16 -0
- package/dist/widget/arrow-bottom-hS_SA8Gp.js +13 -0
- package/dist/widget/arrow-left-CJZanWz7.js +13 -0
- package/dist/widget/arrow-right-C1qL8EMd.js +13 -0
- package/dist/widget/arrow-top-CbuCmbQs.js +13 -0
- package/dist/widget/bank-CXBEEGbb.js +19 -0
- package/dist/widget/bin-Dqzv3zCZ.js +9 -0
- package/dist/widget/bitcoin-4y3sovZp.js +18 -0
- package/dist/widget/browser-DyOl4_8m.js +1413 -0
- package/dist/widget/browser-t7Fh0sEU.js +19 -0
- package/dist/widget/card-Bo4CZkTs.js +19 -0
- package/dist/widget/ccip-BynehMIN.js +232 -0
- package/dist/widget/checkmark-DV6OKvnY.js +16 -0
- package/dist/widget/checkmark-bold-CAp1-IQ2.js +13 -0
- package/dist/widget/chevron-bottom-BjzsVzk9.js +13 -0
- package/dist/widget/chevron-left-CQZBDCiR.js +13 -0
- package/dist/widget/chevron-right-Dhg4zeZM.js +13 -0
- package/dist/widget/chevron-top-CDQmfJef.js +13 -0
- package/dist/widget/chrome-store-BNaC_b6w.js +66 -0
- package/dist/widget/circle-BC_GBj91.js +9 -0
- package/dist/widget/clock-BmF8-4a0.js +13 -0
- package/dist/widget/close-Bf61nZ8o.js +13 -0
- package/dist/widget/coinPlaceholder-7cZW2058.js +13 -0
- package/dist/widget/compass-CFC3yhnW.js +13 -0
- package/dist/widget/components/ChainImage.d.ts +8 -0
- package/dist/widget/components/ChainImage.d.ts.map +1 -0
- package/dist/widget/components/ChainImage.js +6 -0
- package/dist/widget/components/ConnectWallet.d.ts +18 -0
- package/dist/widget/components/ConnectWallet.d.ts.map +1 -0
- package/dist/widget/components/ConnectWallet.js +66 -0
- package/dist/widget/components/DebugScreensDropdown.d.ts +9 -0
- package/dist/widget/components/DebugScreensDropdown.d.ts.map +1 -0
- package/dist/widget/components/DebugScreensDropdown.js +40 -0
- package/dist/widget/components/FeeOptions.d.ts +17 -0
- package/dist/widget/components/FeeOptions.d.ts.map +1 -0
- package/dist/widget/components/FeeOptions.js +65 -0
- package/dist/widget/components/Footer.d.ts +9 -0
- package/dist/widget/components/Footer.d.ts.map +1 -0
- package/dist/widget/components/Footer.js +13 -0
- package/dist/widget/components/GreenCheckAnimation.d.ts +2 -0
- package/dist/widget/components/GreenCheckAnimation.d.ts.map +1 -0
- package/dist/widget/components/GreenCheckAnimation.js +74 -0
- package/dist/widget/components/Modal.d.ts +11 -0
- package/dist/widget/components/Modal.d.ts.map +1 -0
- package/dist/widget/components/Modal.js +36 -0
- package/dist/widget/components/Receipt.d.ts +13 -0
- package/dist/widget/components/Receipt.d.ts.map +1 -0
- package/dist/widget/components/Receipt.js +36 -0
- package/dist/widget/components/SendForm.d.ts +44 -0
- package/dist/widget/components/SendForm.d.ts.map +1 -0
- package/dist/widget/components/SendForm.js +177 -0
- package/dist/widget/components/TokenImage.d.ts +10 -0
- package/dist/widget/components/TokenImage.d.ts.map +1 -0
- package/dist/widget/components/TokenImage.js +8 -0
- package/dist/widget/components/TokenList.d.ts +16 -0
- package/dist/widget/components/TokenList.d.ts.map +1 -0
- package/dist/widget/components/TokenList.js +39 -0
- package/dist/widget/components/TransferPending.d.ts +11 -0
- package/dist/widget/components/TransferPending.d.ts.map +1 -0
- package/dist/widget/components/TransferPending.js +77 -0
- package/dist/widget/components/TransferPendingVertical.d.ts +18 -0
- package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -0
- package/dist/widget/components/TransferPendingVertical.js +183 -0
- package/dist/widget/components/WalletConfirmation.d.ts +18 -0
- package/dist/widget/components/WalletConfirmation.d.ts.map +1 -0
- package/dist/widget/components/WalletConfirmation.js +22 -0
- package/dist/widget/config.d.ts +4 -0
- package/dist/widget/config.d.ts.map +1 -0
- package/dist/widget/config.js +3 -0
- package/dist/widget/copy-e0xXvKN0.js +20 -0
- package/dist/widget/cursor-CqM3v0xJ.js +8 -0
- package/dist/widget/cursor-transparent-CUQpdsCG.js +17 -0
- package/dist/widget/desktop-DUDGIRpM.js +14 -0
- package/dist/widget/disconnect-DUFST9QQ.js +13 -0
- package/dist/widget/discord-C1cj365Z.js +22 -0
- package/dist/widget/email-BHhmb_lX.js +703 -0
- package/dist/widget/embedded-wallet-CuuC4eah.js +467 -0
- package/dist/widget/ethereum-CfmBVfeB.js +15 -0
- package/dist/widget/etherscan-BSiynDhW.js +11 -0
- package/dist/widget/exclamation-triangle-DEiFNpHw.js +9 -0
- package/dist/widget/extension-mRmfCDxo.js +13 -0
- package/dist/widget/external-link-B4xMIVnW.js +13 -0
- package/dist/widget/facebook-CBAZStBR.js +31 -0
- package/dist/widget/farcaster-LHDEDf5S.js +17 -0
- package/dist/widget/filters-CBijuvFv.js +13 -0
- package/dist/widget/github-C3ILD420.js +23 -0
- package/dist/widget/google-CSj73POX.js +23 -0
- package/dist/widget/help-circle-2hdG5IdB.js +17 -0
- package/dist/widget/hooks/useAmountUsd.d.ts +13 -0
- package/dist/widget/hooks/useAmountUsd.d.ts.map +1 -0
- package/dist/widget/hooks/useAmountUsd.js +35 -0
- package/dist/widget/hooks/useSendForm.d.ts +125 -0
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.js +450 -0
- package/dist/widget/hooks/useTokenList.d.ts +52 -0
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -0
- package/dist/widget/hooks/useTokenList.js +252 -0
- package/dist/widget/id-ByYSrwsd.js +17 -0
- package/dist/widget/if-defined-DRXJEhv7.js +752 -0
- package/dist/widget/image-C90L4Rf6.js +9 -0
- package/dist/widget/index-B3SlQ9v3.js +46 -0
- package/dist/widget/index-B8LPuLXQ.js +78 -0
- package/dist/widget/index-BDbworWA.js +171 -0
- package/dist/widget/index-BTlDgFSK.js +98 -0
- package/dist/widget/index-BUCcjXbd.js +306 -0
- package/dist/widget/index-BZ34edi2.js +1055 -0
- package/dist/widget/index-BiCU29wK.js +147 -0
- package/dist/widget/index-BlmqIKsY.js +266 -0
- package/dist/widget/index-BlviH5nG.js +55 -0
- package/dist/widget/index-Bwd5X3fS.js +8306 -0
- package/dist/widget/index-C5gmknHK.js +78 -0
- package/dist/widget/index-CD6dBcRj.js +76 -0
- package/dist/widget/index-CDlhy529.js +63 -0
- package/dist/widget/index-CHXa5ke-.js +59 -0
- package/dist/widget/index-CK94R-H7.js +22498 -0
- package/dist/widget/index-CQzo3m3x.js +182 -0
- package/dist/widget/index-CRT8cAwG.js +325 -0
- package/dist/widget/index-CY7Lt2Yu.js +310 -0
- package/dist/widget/index-CiKfAu1E.js +79 -0
- package/dist/widget/index-CkCu6rMi.js +258 -0
- package/dist/widget/index-CngLTu_R.js +517 -0
- package/dist/widget/index-CsMV8-em.js +2577 -0
- package/dist/widget/index-Cu2Wva8v.js +200 -0
- package/dist/widget/index-DKBxLTEF.js +240 -0
- package/dist/widget/index-DQEVT3dx.js +511 -0
- package/dist/widget/index-DU2HcCis.js +200 -0
- package/dist/widget/index-DutZGWNW.js +321 -0
- package/dist/widget/index-O0glArmc.js +182 -0
- package/dist/widget/index-O8FmRjKe.js +63719 -0
- package/dist/widget/index-RtKXrB6I.js +576 -0
- package/dist/widget/index-TIYtS0gE.js +88 -0
- package/dist/widget/index-dQNJvWHs.js +66 -0
- package/dist/widget/index-wmEwdsq7.js +909 -0
- package/dist/widget/index.d.ts +3 -0
- package/dist/widget/index.d.ts.map +1 -0
- package/dist/widget/index.js +2 -0
- package/dist/widget/info-DMPChDjV.js +8 -0
- package/dist/widget/info-circle-DAvS_7nY.js +17 -0
- package/dist/widget/lightbulb-DnZ9mNEs.js +8 -0
- package/dist/widget/lit-html-BRjl1r6K.js +243 -0
- package/dist/widget/mail-DpaVSOP8.js +13 -0
- package/dist/widget/mobile-CRvdyu7I.js +14 -0
- package/dist/widget/more-C5VqW9PR.js +16 -0
- package/dist/widget/network-placeholder-CZ0vApma.js +19 -0
- package/dist/widget/nftPlaceholder-7jjIK2bT.js +13 -0
- package/dist/widget/off-4mHjJLLX.js +9 -0
- package/dist/widget/onramp-Bc0ozVsw.js +929 -0
- package/dist/widget/play-store-Uocul8nC.js +37 -0
- package/dist/widget/plus-DrYF7siO.js +18 -0
- package/dist/widget/prepareSend-BQJmzM5B.js +54987 -0
- package/dist/widget/qr-code-DcnGMUB3.js +11 -0
- package/dist/widget/receive-fvIVd7R_.js +184 -0
- package/dist/widget/recycle-horizontal-DrDwXC4D.js +14 -0
- package/dist/widget/ref-CXNmEjML.js +41 -0
- package/dist/widget/refresh-OK9lIPLS.js +13 -0
- package/dist/widget/reown-logo-C-Qn7mS3.js +17 -0
- package/dist/widget/search-DZqv1oKg.js +13 -0
- package/dist/widget/send-CJlmI-xe.js +1039 -0
- package/dist/widget/send-otoEC8uU.js +20 -0
- package/dist/widget/socials-BJciurWF.js +599 -0
- package/dist/widget/solana-Bv5Hs_0T.js +18 -0
- package/dist/widget/swapHorizontal-BzOPGV37.js +13 -0
- package/dist/widget/swapHorizontalBold-axyHnSmj.js +13 -0
- package/dist/widget/swapHorizontalMedium-C6YOPfPz.js +21 -0
- package/dist/widget/swapHorizontalRoundedBold-yVcLbWNT.js +13 -0
- package/dist/widget/swapVertical-BDjxt9pE.js +13 -0
- package/dist/widget/swaps-DEWNj4kd.js +1637 -0
- package/dist/widget/telegram-BQJD7dlP.js +21 -0
- package/dist/widget/three-dots-DW9jmSMG.js +10 -0
- package/dist/widget/transactions-uCseGQQt.js +38 -0
- package/dist/widget/twitch-XugxDfOE.js +23 -0
- package/dist/widget/twitterIcon-DQVObQUL.js +11 -0
- package/dist/widget/types.d.ts +51 -0
- package/dist/widget/types.d.ts.map +1 -0
- package/dist/widget/types.js +1 -0
- package/dist/widget/verify-DpMYHxLf.js +13 -0
- package/dist/widget/verify-filled-KpEL6ZJ_.js +13 -0
- package/dist/widget/w3m-modal-C8e-6Kba.js +1047 -0
- package/dist/widget/wallet-D8ssEB0o.js +13 -0
- package/dist/widget/wallet-placeholder-HtAy21Wc.js +19 -0
- package/dist/widget/walletconnect-Bp_4XfrY.js +37 -0
- package/dist/widget/warning-circle-FgYS7P7n.js +17 -0
- package/dist/widget/widget/index.js +7 -0
- package/dist/widget/widget.d.ts +47 -0
- package/dist/widget/widget.d.ts.map +1 -0
- package/dist/widget/widget.js +932 -0
- package/dist/widget/x-DlZBoP9k.js +17 -0
- package/dist/widget/x-mark-Ba9pt-_h.js +8 -0
- package/package.json +102 -8
- package/src/abi.ts +38 -0
- package/src/apiClient.ts +32 -0
- package/src/buffer.ts +10 -0
- package/src/cctp.ts +579 -0
- package/src/chainSwitch.ts +55 -0
- package/src/chains.ts +124 -0
- package/src/constants.ts +26 -0
- package/src/encoders.ts +20 -0
- package/src/error.ts +15 -0
- package/src/explorer.ts +37 -0
- package/src/gasless.ts +545 -0
- package/src/index.ts +48 -0
- package/src/indexerClient.ts +36 -0
- package/src/intents.ts +537 -0
- package/src/metaTxnMonitor.ts +163 -0
- package/src/metaTxns.ts +21 -0
- package/src/paymasterSend.ts +503 -0
- package/src/preconditions.ts +52 -0
- package/src/prepareSend.ts +1849 -0
- package/src/prices.ts +186 -0
- package/src/queryParams.ts +80 -0
- package/src/relaySdk.ts +481 -0
- package/src/relayer.ts +255 -0
- package/src/sendUserOp.ts +570 -0
- package/src/sequenceWallet.ts +579 -0
- package/src/theme.ts +2 -0
- package/src/toSimpleSmartAccount.ts +567 -0
- package/src/tokenBalances.ts +760 -0
- package/src/tokens.ts +471 -0
- package/src/trails.ts +1591 -0
- package/src/types.d.ts +11 -0
- package/src/umd.tsx +49 -0
- package/src/utils.ts +16 -0
- package/src/vite-env.d.ts +4 -0
- package/src/widget/assets/MetaMask-icon-fox-with-margins.svg +31 -0
- package/src/widget/assets/MetaMask-icon-fox.svg +26 -0
- package/src/widget/assets/MetaMask-logo-black.svg +3 -0
- package/src/widget/assets/MetaMask-logo-white.svg +16 -0
- package/src/widget/assets/Privy_Brandmark_Black.svg +9 -0
- package/src/widget/assets/Privy_Brandmark_White.svg +9 -0
- package/src/widget/assets/Trails-logo-black.svg +11 -0
- package/src/widget/assets/Trails-logo-white.svg +11 -0
- package/src/widget/components/ChainImage.tsx +28 -0
- package/src/widget/components/ConnectWallet.tsx +206 -0
- package/src/widget/components/DebugScreensDropdown.tsx +88 -0
- package/src/widget/components/FeeOptions.tsx +199 -0
- package/src/widget/components/Footer.tsx +51 -0
- package/src/widget/components/GreenCheckAnimation.tsx +119 -0
- package/src/widget/components/Modal.tsx +97 -0
- package/src/widget/components/Receipt.tsx +237 -0
- package/src/widget/components/SendForm.tsx +695 -0
- package/src/widget/components/TokenImage.tsx +37 -0
- package/src/widget/components/TokenList.tsx +287 -0
- package/src/widget/components/TransferPending.tsx +204 -0
- package/src/widget/components/TransferPendingVertical.tsx +412 -0
- package/src/widget/components/WalletConfirmation.tsx +172 -0
- package/src/widget/config.ts +5 -0
- package/src/widget/hooks/useAmountUsd.ts +59 -0
- package/src/widget/hooks/useSendForm.ts +715 -0
- package/src/widget/hooks/useTokenList.ts +397 -0
- package/src/widget/index.css +2 -0
- package/src/widget/index.tsx +8 -0
- package/src/widget/types/svg.d.ts +8 -0
- package/src/widget/types.ts +59 -0
- package/src/widget/widget.tsx +1438 -0
- package/index.js +0 -1
package/src/intents.ts
ADDED
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CommitIntentConfigArgs,
|
|
3
|
+
CommitIntentConfigReturn,
|
|
4
|
+
GetIntentCallsPayloadsArgs,
|
|
5
|
+
GetIntentCallsPayloadsReturn as GetIntentCallsPayloadsReturnFromAPI,
|
|
6
|
+
IntentCallsPayload,
|
|
7
|
+
IntentPrecondition,
|
|
8
|
+
SequenceAPIClient,
|
|
9
|
+
} from "@0xsequence/trails-api"
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
IntentCallsPayload,
|
|
13
|
+
IntentPrecondition,
|
|
14
|
+
} from "@0xsequence/trails-api"
|
|
15
|
+
|
|
16
|
+
import type { Context as ContextLike } from "@0xsequence/wallet-primitives"
|
|
17
|
+
import { Config, type Context, Payload } from "@0xsequence/wallet-primitives"
|
|
18
|
+
import {
|
|
19
|
+
AbiParameters,
|
|
20
|
+
Address,
|
|
21
|
+
Bytes,
|
|
22
|
+
ContractAddress,
|
|
23
|
+
Hash,
|
|
24
|
+
type Hex,
|
|
25
|
+
} from "ox"
|
|
26
|
+
import {
|
|
27
|
+
type Account,
|
|
28
|
+
type Chain,
|
|
29
|
+
isAddressEqual,
|
|
30
|
+
type WalletClient,
|
|
31
|
+
} from "viem"
|
|
32
|
+
import { ATTESATION_SIGNER_ADDRESS } from "./constants.js"
|
|
33
|
+
import { findPreconditionAddresses } from "./preconditions.js"
|
|
34
|
+
|
|
35
|
+
export interface MetaTxnFeeDetail {
|
|
36
|
+
metaTxnID: string
|
|
37
|
+
estimatedGasLimit: string
|
|
38
|
+
feeNative: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ChainExecuteQuote {
|
|
42
|
+
chainId: string
|
|
43
|
+
totalGasLimit: string
|
|
44
|
+
gasPrice: string
|
|
45
|
+
totalFeeAmount: string
|
|
46
|
+
nativeTokenSymbol: string
|
|
47
|
+
nativeTokenPrice?: string
|
|
48
|
+
metaTxnFeeDetails: Array<MetaTxnFeeDetail>
|
|
49
|
+
totalFeeUSD?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ExecuteQuote {
|
|
53
|
+
chainQuotes: Array<ChainExecuteQuote>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface CrossChainFee {
|
|
57
|
+
providerFee: string
|
|
58
|
+
trailsSwapFee: string
|
|
59
|
+
providerFeeUSD: number
|
|
60
|
+
trailsSwapFeeUSD: number
|
|
61
|
+
totalFeeAmount: string
|
|
62
|
+
totalFeeUSD: number
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface TrailsFee {
|
|
66
|
+
executeQuote: ExecuteQuote
|
|
67
|
+
crossChainFee?: CrossChainFee
|
|
68
|
+
trailsFixedFeeUSD?: number
|
|
69
|
+
feeToken?: string
|
|
70
|
+
originTokenTotalAmount?: string
|
|
71
|
+
totalFeeAmount?: string
|
|
72
|
+
totalFeeUSD?: string
|
|
73
|
+
quoteProvider?: string
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// QuoteProvider defines the possible liquidity providers.
|
|
77
|
+
export type QuoteProvider = "lifi" | "relay" | "cctp"
|
|
78
|
+
|
|
79
|
+
export type GetIntentCallsPayloadsReturn = GetIntentCallsPayloadsReturnFromAPI
|
|
80
|
+
|
|
81
|
+
export type OriginCallParams = {
|
|
82
|
+
to: `0x${string}` | null
|
|
83
|
+
data: Hex.Hex | null
|
|
84
|
+
value: bigint | null
|
|
85
|
+
chainId: number | null
|
|
86
|
+
error?: string
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type SendOriginCallTxArgs = {
|
|
90
|
+
to: string
|
|
91
|
+
data: Hex.Hex
|
|
92
|
+
value: bigint
|
|
93
|
+
chain: Chain
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function getIntentCallsPayloads(
|
|
97
|
+
apiClient: SequenceAPIClient,
|
|
98
|
+
args: GetIntentCallsPayloadsArgs,
|
|
99
|
+
): Promise<GetIntentCallsPayloadsReturn> {
|
|
100
|
+
return apiClient.getIntentCallsPayloads(args)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function calculateIntentAddress(
|
|
104
|
+
mainSigner: string,
|
|
105
|
+
calls: Array<IntentCallsPayload>,
|
|
106
|
+
): `0x${string}` {
|
|
107
|
+
console.log("[trails-sdk] calculateIntentAddress inputs:", {
|
|
108
|
+
mainSigner,
|
|
109
|
+
calls: JSON.stringify(calls, null, 2),
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const context: ContextLike.Context = {
|
|
113
|
+
factory: "0xBd0F8abD58B4449B39C57Ac9D5C67433239aC447" as `0x${string}`,
|
|
114
|
+
stage1: "0x53bA242E7C2501839DF2972c75075dc693176Cd0" as `0x${string}`,
|
|
115
|
+
stage2: "0xa29874c88b8Fd557e42219B04b0CeC693e1712f5" as `0x${string}`,
|
|
116
|
+
creationCode:
|
|
117
|
+
"0x603e600e3d39601e805130553df33d3d34601c57363d3d373d363d30545af43d82803e903d91601c57fd5bf3" as `0x${string}`,
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const coreCalls = calls.map((call) => ({
|
|
121
|
+
type: "call" as const,
|
|
122
|
+
chainId: call.chainId.toString(),
|
|
123
|
+
space: call.space ? call.space.toString() : "0",
|
|
124
|
+
nonce: call.nonce ? call.nonce.toString() : "0",
|
|
125
|
+
calls: call.calls.map((call) => ({
|
|
126
|
+
to: Address.from(call.to) as `0x${string}`,
|
|
127
|
+
value: call.value?.toString() || "0",
|
|
128
|
+
data: Bytes.toHex(Bytes.from((call.data as Hex.Hex) || "0x")),
|
|
129
|
+
gasLimit: call.gasLimit?.toString() || "0",
|
|
130
|
+
delegateCall: !!call.delegateCall,
|
|
131
|
+
onlyFallback: !!call.onlyFallback,
|
|
132
|
+
behaviorOnError: call.behaviorOnError,
|
|
133
|
+
})),
|
|
134
|
+
}))
|
|
135
|
+
|
|
136
|
+
const calculatedAddress = calculateIntentConfigurationAddress(
|
|
137
|
+
Address.from(mainSigner),
|
|
138
|
+
coreCalls,
|
|
139
|
+
context,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
console.log(
|
|
143
|
+
"[trails-sdk] Final calculated address:",
|
|
144
|
+
calculatedAddress.toString(),
|
|
145
|
+
)
|
|
146
|
+
return calculatedAddress
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function calculateOriginAndDestinationIntentAddresses(
|
|
150
|
+
mainSigner: string,
|
|
151
|
+
calls: Array<IntentCallsPayload>,
|
|
152
|
+
) {
|
|
153
|
+
const originChainId = calls[0]?.chainId
|
|
154
|
+
const destinationChainId = calls[1]?.chainId
|
|
155
|
+
|
|
156
|
+
console.log("[trails-sdk] originChainId:", originChainId)
|
|
157
|
+
console.log("[trails-sdk] destinationChainId:", destinationChainId)
|
|
158
|
+
|
|
159
|
+
// Different origin and destination chains: cross-chain execution.
|
|
160
|
+
const originCalls = calls.filter((c) => c.chainId === originChainId)
|
|
161
|
+
const destinationCalls = calls.filter((c) => c.chainId === destinationChainId)
|
|
162
|
+
|
|
163
|
+
console.log("[trails-sdk] originCalls:", originCalls)
|
|
164
|
+
console.log("[trails-sdk] destinationCalls:", destinationCalls)
|
|
165
|
+
|
|
166
|
+
const originIntentAddress = calculateIntentAddress(mainSigner, originCalls)
|
|
167
|
+
const destinationIntentAddress = calculateIntentAddress(
|
|
168
|
+
mainSigner,
|
|
169
|
+
destinationCalls,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
console.log("[trails-sdk] originIntentAddress:", originIntentAddress)
|
|
173
|
+
console.log(
|
|
174
|
+
"[trails-sdk] destinationIntentAddress:",
|
|
175
|
+
destinationIntentAddress,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
return { originIntentAddress, destinationIntentAddress }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function commitIntentConfig(
|
|
182
|
+
apiClient: SequenceAPIClient,
|
|
183
|
+
mainSignerAddress: string,
|
|
184
|
+
calls: Array<IntentCallsPayload>,
|
|
185
|
+
preconditions: Array<IntentPrecondition>,
|
|
186
|
+
): Promise<CommitIntentConfigReturn> {
|
|
187
|
+
console.log("[trails-sdk] commitIntentConfig inputs:", {
|
|
188
|
+
mainSignerAddress,
|
|
189
|
+
calls: JSON.stringify(calls, null, 2),
|
|
190
|
+
preconditions: JSON.stringify(preconditions, null, 2),
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const { originIntentAddress, destinationIntentAddress } =
|
|
194
|
+
calculateOriginAndDestinationIntentAddresses(mainSignerAddress, calls)
|
|
195
|
+
|
|
196
|
+
console.log(
|
|
197
|
+
"[trails-sdk] originIntentAddress:",
|
|
198
|
+
originIntentAddress.toString(),
|
|
199
|
+
)
|
|
200
|
+
console.log(
|
|
201
|
+
"[trails-sdk] destinationIntentAddress:",
|
|
202
|
+
destinationIntentAddress.toString(),
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
const originChainIdStr = calls[0]?.chainId
|
|
206
|
+
const destinationChainIdStr = calls[1]?.chainId
|
|
207
|
+
|
|
208
|
+
// The executionInfos could be empty, so we need to handle the undefined case.
|
|
209
|
+
const { originAddress: receivedAddress } =
|
|
210
|
+
originChainIdStr && destinationChainIdStr
|
|
211
|
+
? findPreconditionAddresses(
|
|
212
|
+
preconditions,
|
|
213
|
+
Number(originChainIdStr),
|
|
214
|
+
Number(destinationChainIdStr),
|
|
215
|
+
)
|
|
216
|
+
: { originAddress: undefined }
|
|
217
|
+
|
|
218
|
+
console.log("[trails-sdk] Address comparison:", {
|
|
219
|
+
receivedAddress,
|
|
220
|
+
calculatedAddress: originIntentAddress.toString(),
|
|
221
|
+
match:
|
|
222
|
+
receivedAddress &&
|
|
223
|
+
isAddressEqual(Address.from(receivedAddress), originIntentAddress),
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
const args: CommitIntentConfigArgs = {
|
|
227
|
+
originIntentAddress: originIntentAddress.toString(),
|
|
228
|
+
destinationIntentAddress: destinationIntentAddress.toString(),
|
|
229
|
+
mainSigner: mainSignerAddress,
|
|
230
|
+
calls: calls,
|
|
231
|
+
preconditions: preconditions,
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return apiClient.commitIntentConfig(args)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export async function sendOriginTransaction(
|
|
238
|
+
account: Account,
|
|
239
|
+
walletClient: WalletClient,
|
|
240
|
+
originParams: SendOriginCallTxArgs,
|
|
241
|
+
): Promise<`0x${string}`> {
|
|
242
|
+
const chainId = await walletClient.getChainId()
|
|
243
|
+
if (chainId.toString() !== originParams.chain.id.toString()) {
|
|
244
|
+
console.log(
|
|
245
|
+
"[trails-sdk] sendOriginTransaction: switching chain",
|
|
246
|
+
"want:",
|
|
247
|
+
originParams.chain.id,
|
|
248
|
+
"current:",
|
|
249
|
+
chainId,
|
|
250
|
+
)
|
|
251
|
+
await walletClient.switchChain({ id: originParams.chain.id })
|
|
252
|
+
console.log(
|
|
253
|
+
"[trails-sdk] sendOriginTransaction: switched chain to",
|
|
254
|
+
originParams.chain.id,
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
console.log("[trails-sdk] sending origin tx")
|
|
259
|
+
console.time("[trails-sdk] sendTx")
|
|
260
|
+
const hash = await walletClient.sendTransaction({
|
|
261
|
+
account: account,
|
|
262
|
+
to: originParams.to as `0x${string}`,
|
|
263
|
+
data: originParams.data as `0x${string}`,
|
|
264
|
+
value: BigInt(originParams.value),
|
|
265
|
+
chain: originParams.chain,
|
|
266
|
+
})
|
|
267
|
+
console.timeEnd("[trails-sdk] sendTx")
|
|
268
|
+
|
|
269
|
+
return hash
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface OriginTokenParam {
|
|
273
|
+
address: Address.Address
|
|
274
|
+
chainId: bigint
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface DestinationTokenParam {
|
|
278
|
+
address: Address.Address
|
|
279
|
+
chainId: bigint
|
|
280
|
+
amount: bigint
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function hashIntentParams({
|
|
284
|
+
userAddress,
|
|
285
|
+
nonce,
|
|
286
|
+
originTokens,
|
|
287
|
+
destinationCalls,
|
|
288
|
+
destinationTokens,
|
|
289
|
+
}: {
|
|
290
|
+
userAddress: Address.Address
|
|
291
|
+
nonce: bigint
|
|
292
|
+
originTokens: OriginTokenParam[]
|
|
293
|
+
destinationCalls: Array<IntentCallsPayload>
|
|
294
|
+
destinationTokens: DestinationTokenParam[]
|
|
295
|
+
}): string {
|
|
296
|
+
if (
|
|
297
|
+
!userAddress ||
|
|
298
|
+
userAddress === "0x0000000000000000000000000000000000000000"
|
|
299
|
+
)
|
|
300
|
+
throw new Error("UserAddress is zero")
|
|
301
|
+
if (typeof nonce !== "bigint") throw new Error("Nonce is not a bigint")
|
|
302
|
+
if (!originTokens || originTokens.length === 0)
|
|
303
|
+
throw new Error("OriginTokens is empty")
|
|
304
|
+
if (!destinationCalls || destinationCalls.length === 0)
|
|
305
|
+
throw new Error("DestinationCalls is empty")
|
|
306
|
+
if (!destinationTokens || destinationTokens.length === 0)
|
|
307
|
+
throw new Error("DestinationTokens is empty")
|
|
308
|
+
for (let i = 0; i < destinationCalls.length; i++) {
|
|
309
|
+
const currentCall = destinationCalls[i]
|
|
310
|
+
if (!currentCall) throw new Error(`DestinationCalls[${i}] is nil`)
|
|
311
|
+
if (!currentCall.calls || currentCall.calls.length === 0) {
|
|
312
|
+
throw new Error(`DestinationCalls[${i}] has no calls`)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const originTokensForAbi = originTokens.map((token) => ({
|
|
317
|
+
address: token.address,
|
|
318
|
+
chainId: token.chainId,
|
|
319
|
+
}))
|
|
320
|
+
|
|
321
|
+
let cumulativeCallsHashBytes: Bytes.Bytes = Bytes.from(new Uint8Array(32))
|
|
322
|
+
|
|
323
|
+
for (let i = 0; i < destinationCalls.length; i++) {
|
|
324
|
+
const callPayload = destinationCalls[i]
|
|
325
|
+
if (!callPayload) throw new Error(`DestinationCalls[${i}] is nil`)
|
|
326
|
+
|
|
327
|
+
const currentDestCallPayloadHashBytes = Payload.hash(
|
|
328
|
+
ATTESATION_SIGNER_ADDRESS,
|
|
329
|
+
BigInt(callPayload.chainId),
|
|
330
|
+
{
|
|
331
|
+
type: "call",
|
|
332
|
+
space: callPayload.space ? BigInt(callPayload.space) : 0n,
|
|
333
|
+
nonce: callPayload.nonce ? BigInt(callPayload.nonce) : 0n,
|
|
334
|
+
calls: callPayload.calls.map((call) => ({
|
|
335
|
+
type: "call",
|
|
336
|
+
to: call.to as `0x${string}`,
|
|
337
|
+
value: BigInt(call.value?.toString() || "0"),
|
|
338
|
+
data: Bytes.toHex(Bytes.from((call.data as Hex.Hex) || "0x")),
|
|
339
|
+
gasLimit: BigInt(call.gasLimit?.toString() || "0"),
|
|
340
|
+
delegateCall: !!call.delegateCall,
|
|
341
|
+
onlyFallback: !!call.onlyFallback,
|
|
342
|
+
behaviorOnError:
|
|
343
|
+
call.behaviorOnError === 0
|
|
344
|
+
? "ignore"
|
|
345
|
+
: call.behaviorOnError === 1
|
|
346
|
+
? "revert"
|
|
347
|
+
: "abort",
|
|
348
|
+
})),
|
|
349
|
+
},
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
cumulativeCallsHashBytes = Hash.keccak256(
|
|
353
|
+
Bytes.concat(cumulativeCallsHashBytes, currentDestCallPayloadHashBytes),
|
|
354
|
+
{
|
|
355
|
+
as: "Bytes",
|
|
356
|
+
},
|
|
357
|
+
)
|
|
358
|
+
}
|
|
359
|
+
const cumulativeCallsHashHex = Bytes.toHex(cumulativeCallsHashBytes)
|
|
360
|
+
|
|
361
|
+
const destinationTokensForAbi = destinationTokens.map((token) => ({
|
|
362
|
+
address: token.address,
|
|
363
|
+
chainId: token.chainId,
|
|
364
|
+
amount: token.amount,
|
|
365
|
+
}))
|
|
366
|
+
|
|
367
|
+
const abiSchema = [
|
|
368
|
+
{ type: "address" },
|
|
369
|
+
{ type: "uint256" },
|
|
370
|
+
{
|
|
371
|
+
type: "tuple[]",
|
|
372
|
+
components: [
|
|
373
|
+
{ name: "address", type: "address" },
|
|
374
|
+
{ name: "chainId", type: "uint256" },
|
|
375
|
+
],
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
type: "tuple[]",
|
|
379
|
+
components: [
|
|
380
|
+
{ name: "address", type: "address" },
|
|
381
|
+
{ name: "chainId", type: "uint256" },
|
|
382
|
+
{ name: "amount", type: "uint256" },
|
|
383
|
+
],
|
|
384
|
+
},
|
|
385
|
+
{ type: "bytes32" },
|
|
386
|
+
]
|
|
387
|
+
|
|
388
|
+
const encodedHex = AbiParameters.encode(abiSchema, [
|
|
389
|
+
userAddress,
|
|
390
|
+
nonce,
|
|
391
|
+
originTokensForAbi,
|
|
392
|
+
destinationTokensForAbi,
|
|
393
|
+
cumulativeCallsHashHex,
|
|
394
|
+
]) as Hex.Hex
|
|
395
|
+
|
|
396
|
+
const encodedBytes = Bytes.fromHex(encodedHex)
|
|
397
|
+
const hashBytes = Hash.keccak256(encodedBytes)
|
|
398
|
+
const hashHex = Bytes.toHex(hashBytes)
|
|
399
|
+
|
|
400
|
+
return hashHex
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// TODO: Add proper type
|
|
404
|
+
export function bigintReplacer(_key: string, value: any) {
|
|
405
|
+
return typeof value === "bigint" ? value.toString() : value
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export function calculateIntentConfigurationAddress(
|
|
409
|
+
mainSigner: Address.Address,
|
|
410
|
+
calls: Array<IntentCallsPayload>,
|
|
411
|
+
context: Context.Context,
|
|
412
|
+
): Address.Address {
|
|
413
|
+
const config = createIntentConfiguration(mainSigner, calls)
|
|
414
|
+
|
|
415
|
+
// Calculate the image hash of the configuration
|
|
416
|
+
const imageHash = Config.hashConfiguration(config)
|
|
417
|
+
|
|
418
|
+
// Calculate the counterfactual address using the image hash and context
|
|
419
|
+
return ContractAddress.fromCreate2({
|
|
420
|
+
from: context.factory,
|
|
421
|
+
bytecodeHash: Hash.keccak256(
|
|
422
|
+
Bytes.concat(
|
|
423
|
+
Bytes.from(context.creationCode),
|
|
424
|
+
Bytes.padLeft(Bytes.from(context.stage1), 32),
|
|
425
|
+
),
|
|
426
|
+
{ as: "Bytes" },
|
|
427
|
+
),
|
|
428
|
+
salt: imageHash,
|
|
429
|
+
})
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function createIntentConfiguration(
|
|
433
|
+
mainSigner: Address.Address,
|
|
434
|
+
calls: IntentCallsPayload[],
|
|
435
|
+
): Config.Config {
|
|
436
|
+
const mainSignerLeaf: Config.SignerLeaf = {
|
|
437
|
+
type: "signer",
|
|
438
|
+
address: mainSigner,
|
|
439
|
+
weight: 1n,
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
console.log("[trails-sdk] mainSignerLeaf:", mainSignerLeaf)
|
|
443
|
+
|
|
444
|
+
const subdigestLeaves: Config.AnyAddressSubdigestLeaf[] = calls.map(
|
|
445
|
+
(call) => {
|
|
446
|
+
const digest = Payload.hash(
|
|
447
|
+
Address.from("0x0000000000000000000000000000000000000000"),
|
|
448
|
+
BigInt(call.chainId),
|
|
449
|
+
{
|
|
450
|
+
type: "call",
|
|
451
|
+
space: BigInt(call.space || 0),
|
|
452
|
+
nonce: BigInt(call.nonce || 0),
|
|
453
|
+
calls: call.calls.map((call) => ({
|
|
454
|
+
type: "call",
|
|
455
|
+
to: call.to as `0x${string}`,
|
|
456
|
+
value: BigInt(call.value?.toString() || "0"),
|
|
457
|
+
data: Bytes.toHex(Bytes.from((call.data as Hex.Hex) || "0x")),
|
|
458
|
+
gasLimit: BigInt(call.gasLimit?.toString() || "0"),
|
|
459
|
+
delegateCall: !!call.delegateCall,
|
|
460
|
+
onlyFallback: !!call.onlyFallback,
|
|
461
|
+
behaviorOnError:
|
|
462
|
+
call.behaviorOnError === 0
|
|
463
|
+
? "ignore"
|
|
464
|
+
: call.behaviorOnError === 1
|
|
465
|
+
? "revert"
|
|
466
|
+
: "abort",
|
|
467
|
+
})),
|
|
468
|
+
},
|
|
469
|
+
)
|
|
470
|
+
console.log("[trails-sdk] digest:", Bytes.toHex(digest))
|
|
471
|
+
return {
|
|
472
|
+
type: "any-address-subdigest",
|
|
473
|
+
digest: Bytes.toHex(digest),
|
|
474
|
+
} as Config.AnyAddressSubdigestLeaf
|
|
475
|
+
},
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
console.log("[trails-sdk] calls:", calls)
|
|
479
|
+
console.log("[trails-sdk] subdigestLeaves:", subdigestLeaves)
|
|
480
|
+
|
|
481
|
+
const otherLeaves: Config.Topology[] = [...subdigestLeaves]
|
|
482
|
+
|
|
483
|
+
if (otherLeaves.length === 0) {
|
|
484
|
+
throw new Error(
|
|
485
|
+
"Intent configuration must have at least one call or LiFi information.",
|
|
486
|
+
)
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
let secondaryTopologyNode: Config.Topology
|
|
490
|
+
|
|
491
|
+
if (otherLeaves.length === 1) {
|
|
492
|
+
secondaryTopologyNode = otherLeaves[0]!
|
|
493
|
+
} else {
|
|
494
|
+
secondaryTopologyNode = buildMerkleTreeFromMembers(otherLeaves)
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Print the topology
|
|
498
|
+
console.log(
|
|
499
|
+
"[trails-sdk] Topology:",
|
|
500
|
+
JSON.stringify([mainSignerLeaf, secondaryTopologyNode], bigintReplacer, 2),
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
return {
|
|
504
|
+
threshold: 1n,
|
|
505
|
+
checkpoint: 0n,
|
|
506
|
+
topology: [mainSignerLeaf, secondaryTopologyNode] as Config.Node,
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Renamed and generalized from createSubdigestTree
|
|
511
|
+
function buildMerkleTreeFromMembers(
|
|
512
|
+
members: Config.Topology[],
|
|
513
|
+
): Config.Topology {
|
|
514
|
+
if (members.length === 0) {
|
|
515
|
+
throw new Error("Cannot create a tree from empty members")
|
|
516
|
+
}
|
|
517
|
+
if (members.length === 1) {
|
|
518
|
+
return members[0]! // Returns a single Leaf or a Node
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
let currentLevel = [...members]
|
|
522
|
+
while (currentLevel.length > 1) {
|
|
523
|
+
const nextLevel: Config.Topology[] = []
|
|
524
|
+
for (let i = 0; i < currentLevel.length; i += 2) {
|
|
525
|
+
const left = currentLevel[i]!
|
|
526
|
+
if (i + 1 < currentLevel.length) {
|
|
527
|
+
const right = currentLevel[i + 1]!
|
|
528
|
+
nextLevel.push([left, right] as Config.Node)
|
|
529
|
+
} else {
|
|
530
|
+
// Odd one out, carries over to the next level
|
|
531
|
+
nextLevel.push(left)
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
currentLevel = nextLevel
|
|
535
|
+
}
|
|
536
|
+
return currentLevel[0]!
|
|
537
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { Relayer } from "@0xsequence/wallet-core"
|
|
2
|
+
import { type Query, useQueries } from "@tanstack/react-query"
|
|
3
|
+
import { useMemo } from "react"
|
|
4
|
+
import type { Hex } from "viem"
|
|
5
|
+
|
|
6
|
+
export type MetaTxn = {
|
|
7
|
+
id: string
|
|
8
|
+
chainId: string
|
|
9
|
+
contract?: string | undefined
|
|
10
|
+
input?: string | undefined
|
|
11
|
+
walletAddress?: string | undefined
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type MetaTxnStatus = {
|
|
15
|
+
[key: string]: Relayer.OperationStatus
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const POLL_INTERVAL = 3_000 // 3 seconds
|
|
19
|
+
|
|
20
|
+
export const getMetaTxStatus = async (
|
|
21
|
+
relayer: Relayer.Standard.Rpc.RpcRelayer,
|
|
22
|
+
metaTxId: string,
|
|
23
|
+
chainId: number,
|
|
24
|
+
): Promise<Relayer.OperationStatus> => {
|
|
25
|
+
return relayer.status(metaTxId as `0x${string}`, BigInt(chainId))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const useMetaTxnsMonitor = (
|
|
29
|
+
metaTxns: MetaTxn[] | undefined,
|
|
30
|
+
getRelayer: (chainId: number) => Relayer.Standard.Rpc.RpcRelayer,
|
|
31
|
+
) => {
|
|
32
|
+
const results = useQueries({
|
|
33
|
+
queries: (metaTxns || []).map((metaTxn) => {
|
|
34
|
+
const opHashToPoll = metaTxn.id as Hex
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
queryKey: ["metaTxnStatus", metaTxn.chainId, metaTxn.id],
|
|
38
|
+
queryFn: async (): Promise<Relayer.OperationStatus> => {
|
|
39
|
+
const relayer = getRelayer(parseInt(metaTxn.chainId))
|
|
40
|
+
|
|
41
|
+
if (!opHashToPoll) {
|
|
42
|
+
return {
|
|
43
|
+
status: "failed",
|
|
44
|
+
reason: "Missing operation hash for monitoring.",
|
|
45
|
+
} as Relayer.OperationFailedStatus
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!relayer) {
|
|
49
|
+
return {
|
|
50
|
+
status: "failed",
|
|
51
|
+
reason: `Relayer not available for chain ${metaTxn.chainId}.`,
|
|
52
|
+
} as Relayer.OperationFailedStatus
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const opStatus = await relayer.status(
|
|
56
|
+
opHashToPoll,
|
|
57
|
+
BigInt(metaTxn.chainId),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
let newStatusEntry: Relayer.OperationStatus
|
|
61
|
+
|
|
62
|
+
if (opStatus.status === "confirmed") {
|
|
63
|
+
newStatusEntry = {
|
|
64
|
+
status: "confirmed",
|
|
65
|
+
transactionHash: opStatus.transactionHash,
|
|
66
|
+
data: opStatus.data,
|
|
67
|
+
} as Relayer.OperationConfirmedStatus
|
|
68
|
+
} else if (opStatus.status === "failed") {
|
|
69
|
+
newStatusEntry = {
|
|
70
|
+
status: "failed",
|
|
71
|
+
reason: opStatus.reason,
|
|
72
|
+
data: opStatus.data,
|
|
73
|
+
} as Relayer.OperationFailedStatus
|
|
74
|
+
} else if (opStatus.status === "pending") {
|
|
75
|
+
newStatusEntry = {
|
|
76
|
+
status: "pending",
|
|
77
|
+
} as Relayer.OperationPendingStatus
|
|
78
|
+
} else if (opStatus.status === "unknown") {
|
|
79
|
+
newStatusEntry = {
|
|
80
|
+
status: "unknown",
|
|
81
|
+
} as Relayer.OperationUnknownStatus
|
|
82
|
+
} else {
|
|
83
|
+
const originalStatus = (opStatus as any).status as string
|
|
84
|
+
console.warn(
|
|
85
|
+
`[trails-sdk] ⚠️ Unexpected relayer status "${originalStatus}" for ${opHashToPoll}:`,
|
|
86
|
+
opStatus,
|
|
87
|
+
)
|
|
88
|
+
newStatusEntry = {
|
|
89
|
+
status: "unknown",
|
|
90
|
+
} as Relayer.OperationUnknownStatus
|
|
91
|
+
}
|
|
92
|
+
return newStatusEntry
|
|
93
|
+
},
|
|
94
|
+
refetchInterval: (
|
|
95
|
+
query: Query<
|
|
96
|
+
Relayer.OperationStatus,
|
|
97
|
+
Error,
|
|
98
|
+
Relayer.OperationStatus,
|
|
99
|
+
ReadonlyArray<unknown>
|
|
100
|
+
>,
|
|
101
|
+
) => {
|
|
102
|
+
const data = query.state.data
|
|
103
|
+
if (!data) return POLL_INTERVAL
|
|
104
|
+
if (data.status === "confirmed") return false
|
|
105
|
+
return POLL_INTERVAL
|
|
106
|
+
},
|
|
107
|
+
enabled: !!metaTxn && !!metaTxn.id && !!metaTxn.chainId,
|
|
108
|
+
retry: (failureCount: number, error: Error) => {
|
|
109
|
+
if (failureCount >= 30) {
|
|
110
|
+
console.error(
|
|
111
|
+
`[trails-sdk] ❌ Giving up on transaction ${opHashToPoll} after 3 failed API attempts:`,
|
|
112
|
+
error,
|
|
113
|
+
)
|
|
114
|
+
return false
|
|
115
|
+
}
|
|
116
|
+
return true
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const statuses: MetaTxnStatus = useMemo(() => {
|
|
123
|
+
const newStatuses: MetaTxnStatus = {}
|
|
124
|
+
;(metaTxns || []).forEach((metaTxn, index) => {
|
|
125
|
+
const operationKey = `${metaTxn.chainId}-${metaTxn.id}`
|
|
126
|
+
const queryResult = results[index]
|
|
127
|
+
|
|
128
|
+
if (queryResult) {
|
|
129
|
+
if (
|
|
130
|
+
queryResult.isLoading &&
|
|
131
|
+
queryResult.fetchStatus !== "idle" &&
|
|
132
|
+
!queryResult.data
|
|
133
|
+
) {
|
|
134
|
+
newStatuses[operationKey] = {
|
|
135
|
+
status: "pending",
|
|
136
|
+
} as Relayer.OperationPendingStatus
|
|
137
|
+
} else if (queryResult.isError) {
|
|
138
|
+
newStatuses[operationKey] = {
|
|
139
|
+
status: "failed",
|
|
140
|
+
reason:
|
|
141
|
+
(queryResult.error as Error)?.message ||
|
|
142
|
+
"An unknown error occurred",
|
|
143
|
+
} as Relayer.OperationFailedStatus
|
|
144
|
+
} else if (queryResult.data) {
|
|
145
|
+
newStatuses[operationKey] =
|
|
146
|
+
queryResult.data as Relayer.OperationStatus
|
|
147
|
+
} else {
|
|
148
|
+
newStatuses[operationKey] = {
|
|
149
|
+
status: "unknown",
|
|
150
|
+
} as Relayer.OperationUnknownStatus
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
newStatuses[operationKey] = {
|
|
154
|
+
status: "failed",
|
|
155
|
+
reason: "Query result unexpectedly missing",
|
|
156
|
+
} as Relayer.OperationFailedStatus
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
return newStatuses
|
|
160
|
+
}, [metaTxns, results])
|
|
161
|
+
|
|
162
|
+
return statuses
|
|
163
|
+
}
|
package/src/metaTxns.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IntentPrecondition } from "@0xsequence/trails-api"
|
|
2
|
+
import type { Relayer } from "@0xsequence/wallet-core"
|
|
3
|
+
import type { Hex } from "viem"
|
|
4
|
+
import type { MetaTxn } from "./metaTxnMonitor.js"
|
|
5
|
+
|
|
6
|
+
export async function relayerSendMetaTx(
|
|
7
|
+
relayer: Relayer.Standard.Rpc.RpcRelayer,
|
|
8
|
+
metaTx: MetaTxn,
|
|
9
|
+
preconditions: IntentPrecondition[],
|
|
10
|
+
): Promise<Hex> {
|
|
11
|
+
const { opHash } = await relayer.sendMetaTxn(
|
|
12
|
+
metaTx.walletAddress as `0x${string}`,
|
|
13
|
+
metaTx.contract as `0x${string}`,
|
|
14
|
+
metaTx.input as Hex,
|
|
15
|
+
BigInt(metaTx.chainId),
|
|
16
|
+
undefined,
|
|
17
|
+
preconditions,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
return opHash
|
|
21
|
+
}
|