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/dist/cctp.js
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { createPublicClient, encodeFunctionData, erc20Abi, getAddress, http, maxUint256, } from "viem";
|
|
2
|
+
import * as chains from "viem/chains";
|
|
3
|
+
import { attemptSwitchChain } from "./chainSwitch.js";
|
|
4
|
+
const domains = {
|
|
5
|
+
[chains.mainnet.id]: 0,
|
|
6
|
+
[chains.sepolia.id]: 0,
|
|
7
|
+
[chains.avalanche.id]: 1,
|
|
8
|
+
[chains.avalancheFuji.id]: 1,
|
|
9
|
+
[chains.optimism.id]: 2,
|
|
10
|
+
[chains.optimismSepolia.id]: 2,
|
|
11
|
+
[chains.arbitrum.id]: 3,
|
|
12
|
+
[chains.arbitrumSepolia.id]: 3,
|
|
13
|
+
[chains.base.id]: 6,
|
|
14
|
+
[chains.baseSepolia.id]: 6,
|
|
15
|
+
[chains.polygon.id]: 7,
|
|
16
|
+
[chains.polygonAmoy.id]: 7,
|
|
17
|
+
[chains.unichain.id]: 10,
|
|
18
|
+
[chains.unichainSepolia.id]: 10,
|
|
19
|
+
[chains.linea.id]: 11,
|
|
20
|
+
[chains.lineaSepolia.id]: 11,
|
|
21
|
+
[chains.worldchain.id]: 14,
|
|
22
|
+
[chains.worldchainSepolia.id]: 14,
|
|
23
|
+
};
|
|
24
|
+
const tokenAddresses = {
|
|
25
|
+
[chains.mainnet.id]: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
26
|
+
[chains.sepolia.id]: "0x1c7d4b196cb0c7b01d743fbc6116a902379c7238",
|
|
27
|
+
[chains.avalanche.id]: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
28
|
+
[chains.avalancheFuji.id]: "0x5425890298aed601595a70AB815c96711a31Bc65",
|
|
29
|
+
[chains.optimism.id]: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
30
|
+
[chains.optimismSepolia.id]: "0x5fd84259d66Cd46123540766Be93DFE6D43130D7",
|
|
31
|
+
[chains.arbitrum.id]: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
32
|
+
[chains.arbitrumSepolia.id]: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
|
|
33
|
+
[chains.base.id]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
34
|
+
[chains.baseSepolia.id]: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
35
|
+
[chains.polygon.id]: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
36
|
+
[chains.polygonAmoy.id]: "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582",
|
|
37
|
+
[chains.unichain.id]: "0x078D782b760474a361dDA0AF3839290b0EF57AD6",
|
|
38
|
+
[chains.unichainSepolia.id]: "0x31d0220469e10c4E71834a79b1f276d740d3768F",
|
|
39
|
+
[chains.linea.id]: "0x176211869cA2b568f2A7D4EE941E073a821EE1ff",
|
|
40
|
+
[chains.lineaSepolia.id]: "0xFEce4462D57bD51A6A552365A011b95f0E16d9B7",
|
|
41
|
+
[chains.worldchain.id]: "0x79A02482A880bCe3F13E09da970dC34dB4cD24D1",
|
|
42
|
+
[chains.worldchainSepolia.id]: "0x66145f38cBAC35Ca6F1Dfb4914dF98F1614aeA88",
|
|
43
|
+
};
|
|
44
|
+
const tokenMessengers = {
|
|
45
|
+
[chains.mainnet.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
46
|
+
[chains.sepolia.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
47
|
+
[chains.avalanche.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
48
|
+
[chains.avalancheFuji.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
49
|
+
[chains.optimism.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
50
|
+
[chains.optimismSepolia.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
51
|
+
[chains.arbitrum.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
52
|
+
[chains.arbitrumSepolia.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
53
|
+
[chains.base.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
54
|
+
[chains.baseSepolia.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
55
|
+
[chains.polygon.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
56
|
+
[chains.polygonAmoy.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
57
|
+
[chains.unichain.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
58
|
+
[chains.unichainSepolia.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
59
|
+
[chains.linea.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
60
|
+
[chains.lineaSepolia.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
61
|
+
[chains.worldchain.id]: "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d",
|
|
62
|
+
[chains.worldchainSepolia.id]: "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA",
|
|
63
|
+
};
|
|
64
|
+
const messageTransmitters = {
|
|
65
|
+
[chains.mainnet.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
66
|
+
[chains.sepolia.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
67
|
+
[chains.avalanche.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
68
|
+
[chains.avalancheFuji.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
69
|
+
[chains.optimism.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
70
|
+
[chains.optimismSepolia.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
71
|
+
[chains.arbitrum.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
72
|
+
[chains.arbitrumSepolia.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
73
|
+
[chains.base.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
74
|
+
[chains.baseSepolia.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
75
|
+
[chains.polygon.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
76
|
+
[chains.polygonAmoy.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
77
|
+
[chains.unichain.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
78
|
+
[chains.unichainSepolia.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
79
|
+
[chains.linea.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
80
|
+
[chains.lineaSepolia.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
81
|
+
[chains.worldchain.id]: "0x81D40F21F12A8F0E3252Bccb954D722d4c464B64",
|
|
82
|
+
[chains.worldchainSepolia.id]: "0xE737e5cEBEEBa77EFE34D4aa090756590b1CE275",
|
|
83
|
+
};
|
|
84
|
+
export function getDomain(chainId) {
|
|
85
|
+
return domains[chainId] ?? null;
|
|
86
|
+
}
|
|
87
|
+
export function getTokenAddress(chainId) {
|
|
88
|
+
return tokenAddresses[chainId] ?? null;
|
|
89
|
+
}
|
|
90
|
+
export function getTokenMessenger(chainId) {
|
|
91
|
+
return tokenMessengers[chainId] ?? null;
|
|
92
|
+
}
|
|
93
|
+
export function getMessageTransmitter(chainId) {
|
|
94
|
+
return messageTransmitters[chainId] ?? null;
|
|
95
|
+
}
|
|
96
|
+
export async function cctpTransfer({ walletClient, originChain, destinationChain, amount, }) {
|
|
97
|
+
const originToken = getTokenAddress(originChain.id);
|
|
98
|
+
const originDomain = getDomain(originChain.id);
|
|
99
|
+
const destinationDomain = getDomain(destinationChain.id);
|
|
100
|
+
const originTokenMessenger = getTokenMessenger(originChain.id);
|
|
101
|
+
const destinationAddress = walletClient.account?.address;
|
|
102
|
+
if (!originToken ||
|
|
103
|
+
!originDomain ||
|
|
104
|
+
!originTokenMessenger ||
|
|
105
|
+
!destinationDomain ||
|
|
106
|
+
!destinationAddress) {
|
|
107
|
+
throw new Error("Invalid origin chain");
|
|
108
|
+
}
|
|
109
|
+
const originClient = createPublicClient({
|
|
110
|
+
chain: originChain,
|
|
111
|
+
transport: http(),
|
|
112
|
+
});
|
|
113
|
+
await attemptSwitchChain({
|
|
114
|
+
walletClient,
|
|
115
|
+
desiredChainId: originChain.id,
|
|
116
|
+
});
|
|
117
|
+
const account = walletClient.account?.address;
|
|
118
|
+
if (!account) {
|
|
119
|
+
throw new Error("No account found");
|
|
120
|
+
}
|
|
121
|
+
const needsApproval = await getNeedsApproval({
|
|
122
|
+
publicClient: originClient,
|
|
123
|
+
token: originToken,
|
|
124
|
+
account,
|
|
125
|
+
spender: originTokenMessenger,
|
|
126
|
+
amount: amount,
|
|
127
|
+
});
|
|
128
|
+
if (needsApproval) {
|
|
129
|
+
const txHash = await approveUSDC({
|
|
130
|
+
walletClient,
|
|
131
|
+
tokenAddress: originToken,
|
|
132
|
+
spender: originTokenMessenger,
|
|
133
|
+
amount: maxUint256,
|
|
134
|
+
chain: originChain,
|
|
135
|
+
});
|
|
136
|
+
console.log("waiting for approve", txHash);
|
|
137
|
+
await originClient.waitForTransactionReceipt({
|
|
138
|
+
hash: txHash,
|
|
139
|
+
});
|
|
140
|
+
console.log("approve done");
|
|
141
|
+
}
|
|
142
|
+
const maxFee = getMaxFee();
|
|
143
|
+
const txHash = await burnUSDC({
|
|
144
|
+
walletClient,
|
|
145
|
+
tokenMessenger: originTokenMessenger,
|
|
146
|
+
destinationDomain,
|
|
147
|
+
destinationAddress,
|
|
148
|
+
amount,
|
|
149
|
+
burnToken: originToken,
|
|
150
|
+
maxFee,
|
|
151
|
+
chain: originChain,
|
|
152
|
+
});
|
|
153
|
+
await originClient.waitForTransactionReceipt({
|
|
154
|
+
hash: txHash,
|
|
155
|
+
});
|
|
156
|
+
const attestation = await waitForAttestation({
|
|
157
|
+
domain: originDomain,
|
|
158
|
+
transactionHash: txHash,
|
|
159
|
+
});
|
|
160
|
+
if (!attestation) {
|
|
161
|
+
throw new Error("Failed to retrieve attestation");
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
attestation,
|
|
165
|
+
txHash: txHash,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
export async function cctpDestinationTx({ relayerClient, destinationChain, attestation, }) {
|
|
169
|
+
const destinationTokenMessenger = getMessageTransmitter(destinationChain.id);
|
|
170
|
+
if (!destinationTokenMessenger) {
|
|
171
|
+
throw new Error("Invalid destination chain");
|
|
172
|
+
}
|
|
173
|
+
await attemptSwitchChain({
|
|
174
|
+
walletClient: relayerClient,
|
|
175
|
+
desiredChainId: destinationChain.id,
|
|
176
|
+
});
|
|
177
|
+
const txHash = await mintUSDC({
|
|
178
|
+
walletClient: relayerClient,
|
|
179
|
+
tokenMessenger: destinationTokenMessenger,
|
|
180
|
+
attestation,
|
|
181
|
+
chain: destinationChain,
|
|
182
|
+
});
|
|
183
|
+
console.log("[trails-sdk] minted USDC");
|
|
184
|
+
return txHash;
|
|
185
|
+
}
|
|
186
|
+
export function getMaxFee() {
|
|
187
|
+
return 500n; // Set fast transfer max fee in 10^6 subunits (0.0005 USDC; change as needed)
|
|
188
|
+
}
|
|
189
|
+
export async function getNeedsApproval({ publicClient, token, account, spender, amount, }) {
|
|
190
|
+
const allowance = await publicClient.readContract({
|
|
191
|
+
address: token,
|
|
192
|
+
abi: erc20Abi,
|
|
193
|
+
functionName: "allowance",
|
|
194
|
+
args: [getAddress(account), getAddress(spender)],
|
|
195
|
+
});
|
|
196
|
+
return allowance < amount;
|
|
197
|
+
}
|
|
198
|
+
export async function approveUSDC({ walletClient, tokenAddress, spender, amount, chain, }) {
|
|
199
|
+
const approvalData = await getApproveUSDCData({
|
|
200
|
+
tokenAddress,
|
|
201
|
+
spender,
|
|
202
|
+
amount,
|
|
203
|
+
});
|
|
204
|
+
console.log("[trails-sdk] approving USDC transfer", approvalData);
|
|
205
|
+
await attemptSwitchChain({
|
|
206
|
+
walletClient,
|
|
207
|
+
desiredChainId: chain.id,
|
|
208
|
+
});
|
|
209
|
+
const account = walletClient.account?.address;
|
|
210
|
+
if (!account) {
|
|
211
|
+
throw new Error("No account found");
|
|
212
|
+
}
|
|
213
|
+
return walletClient.sendTransaction({
|
|
214
|
+
...approvalData,
|
|
215
|
+
account: account,
|
|
216
|
+
chain,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
async function getApproveUSDCData({ tokenAddress, spender, amount, }) {
|
|
220
|
+
console.log("[trails-sdk] get approve USDC transfer data", {
|
|
221
|
+
tokenAddress,
|
|
222
|
+
spender,
|
|
223
|
+
amount,
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
to: tokenAddress,
|
|
227
|
+
value: BigInt(0),
|
|
228
|
+
data: encodeFunctionData({
|
|
229
|
+
abi: [
|
|
230
|
+
{
|
|
231
|
+
type: "function",
|
|
232
|
+
name: "approve",
|
|
233
|
+
stateMutability: "nonpayable",
|
|
234
|
+
inputs: [
|
|
235
|
+
{ name: "spender", type: "address" },
|
|
236
|
+
{ name: "amount", type: "uint256" },
|
|
237
|
+
],
|
|
238
|
+
outputs: [{ name: "", type: "bool" }],
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
functionName: "approve",
|
|
242
|
+
args: [spender, amount],
|
|
243
|
+
}),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
export async function burnUSDC({ walletClient, tokenMessenger, destinationDomain, destinationAddress, amount, burnToken, maxFee, chain, }) {
|
|
247
|
+
const burnData = await getBurnUSDCData({
|
|
248
|
+
tokenMessenger,
|
|
249
|
+
destinationDomain,
|
|
250
|
+
destinationAddress,
|
|
251
|
+
amount,
|
|
252
|
+
burnToken,
|
|
253
|
+
maxFee: maxFee,
|
|
254
|
+
});
|
|
255
|
+
await attemptSwitchChain({
|
|
256
|
+
walletClient,
|
|
257
|
+
desiredChainId: chain.id,
|
|
258
|
+
});
|
|
259
|
+
const account = walletClient.account?.address;
|
|
260
|
+
if (!account) {
|
|
261
|
+
throw new Error("No account found");
|
|
262
|
+
}
|
|
263
|
+
return walletClient.sendTransaction({
|
|
264
|
+
...burnData,
|
|
265
|
+
account: account,
|
|
266
|
+
chain,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
export async function getBurnUSDCData({ tokenMessenger, destinationDomain, destinationAddress, amount, burnToken, maxFee, }) {
|
|
270
|
+
console.log("[trails-sdk] get burn USDC data", {
|
|
271
|
+
tokenMessenger,
|
|
272
|
+
destinationDomain,
|
|
273
|
+
destinationAddress,
|
|
274
|
+
amount,
|
|
275
|
+
burnToken,
|
|
276
|
+
maxFee,
|
|
277
|
+
});
|
|
278
|
+
// Bytes32 Formatted Parameters
|
|
279
|
+
const DESTINATION_ADDRESS_BYTES32 = `0x000000000000000000000000${destinationAddress.slice(2)}`; // Destination address in bytes32 format
|
|
280
|
+
const DESTINATION_CALLER_BYTES32 = "0x0000000000000000000000000000000000000000000000000000000000000000"; // Empty bytes32 allows any address to call MessageTransmitterV2.receiveMessage()
|
|
281
|
+
return {
|
|
282
|
+
to: tokenMessenger,
|
|
283
|
+
value: BigInt(0),
|
|
284
|
+
data: encodeFunctionData({
|
|
285
|
+
abi: [
|
|
286
|
+
{
|
|
287
|
+
type: "function",
|
|
288
|
+
name: "depositForBurn",
|
|
289
|
+
stateMutability: "nonpayable",
|
|
290
|
+
inputs: [
|
|
291
|
+
{ name: "amount", type: "uint256" },
|
|
292
|
+
{ name: "destinationDomain", type: "uint32" },
|
|
293
|
+
{ name: "mintRecipient", type: "bytes32" },
|
|
294
|
+
{ name: "burnToken", type: "address" },
|
|
295
|
+
{ name: "destinationCaller", type: "bytes32" },
|
|
296
|
+
{ name: "maxFee", type: "uint256" },
|
|
297
|
+
{ name: "minFinalityThreshold", type: "uint32" },
|
|
298
|
+
],
|
|
299
|
+
outputs: [],
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
functionName: "depositForBurn",
|
|
303
|
+
args: [
|
|
304
|
+
amount,
|
|
305
|
+
destinationDomain,
|
|
306
|
+
DESTINATION_ADDRESS_BYTES32,
|
|
307
|
+
burnToken,
|
|
308
|
+
DESTINATION_CALLER_BYTES32,
|
|
309
|
+
maxFee,
|
|
310
|
+
1000, // minFinalityThreshold (1000 or less for Fast Transfer)
|
|
311
|
+
],
|
|
312
|
+
}),
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
export async function retrieveAttestation({ domain, transactionHash, }) {
|
|
316
|
+
console.log("[trails-sdk] retrieving attestation", {
|
|
317
|
+
domain,
|
|
318
|
+
transactionHash,
|
|
319
|
+
});
|
|
320
|
+
const url = `https://iris-api-sandbox.circle.com/v2/messages/${domain}?transactionHash=${transactionHash}`;
|
|
321
|
+
while (true) {
|
|
322
|
+
try {
|
|
323
|
+
const response = await fetch(url);
|
|
324
|
+
const data = await response.json();
|
|
325
|
+
if (response.status === 404) {
|
|
326
|
+
console.log("[trails-sdk] waiting for attestation...");
|
|
327
|
+
}
|
|
328
|
+
if (data?.messages?.[0]?.status === "complete") {
|
|
329
|
+
console.log("[trails-sdk] attestation retrieved successfully!");
|
|
330
|
+
return data.messages[0];
|
|
331
|
+
}
|
|
332
|
+
console.log("[trails-sdk] waiting for attestation...");
|
|
333
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
console.error("[trails-sdk] error fetching attestation:", error instanceof Error ? error.message : String(error));
|
|
337
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
export async function mintUSDC({ walletClient, tokenMessenger, attestation, chain, }) {
|
|
342
|
+
const mintData = await getMintUSDCData({
|
|
343
|
+
tokenMessenger,
|
|
344
|
+
attestation,
|
|
345
|
+
});
|
|
346
|
+
await attemptSwitchChain({
|
|
347
|
+
walletClient,
|
|
348
|
+
desiredChainId: chain.id,
|
|
349
|
+
});
|
|
350
|
+
const account = walletClient.account?.address;
|
|
351
|
+
if (!account) {
|
|
352
|
+
throw new Error("No account found");
|
|
353
|
+
}
|
|
354
|
+
return walletClient.sendTransaction({
|
|
355
|
+
...mintData,
|
|
356
|
+
account: account,
|
|
357
|
+
chain,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
export async function getMintUSDCData({ tokenMessenger, attestation, }) {
|
|
361
|
+
console.log("[trails-sdk] get mint USDC data", {
|
|
362
|
+
tokenMessenger,
|
|
363
|
+
attestation,
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
to: tokenMessenger,
|
|
367
|
+
value: BigInt(0),
|
|
368
|
+
data: encodeFunctionData({
|
|
369
|
+
abi: [
|
|
370
|
+
{
|
|
371
|
+
type: "function",
|
|
372
|
+
name: "receiveMessage",
|
|
373
|
+
stateMutability: "nonpayable",
|
|
374
|
+
inputs: [
|
|
375
|
+
{ name: "message", type: "bytes" },
|
|
376
|
+
{ name: "attestation", type: "bytes" },
|
|
377
|
+
],
|
|
378
|
+
outputs: [],
|
|
379
|
+
},
|
|
380
|
+
],
|
|
381
|
+
functionName: "receiveMessage",
|
|
382
|
+
args: [attestation.message, attestation.attestation],
|
|
383
|
+
}),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
export async function waitForAttestation({ domain, transactionHash, }) {
|
|
387
|
+
while (true) {
|
|
388
|
+
const attestation = await retrieveAttestation({
|
|
389
|
+
domain,
|
|
390
|
+
transactionHash,
|
|
391
|
+
});
|
|
392
|
+
if (attestation) {
|
|
393
|
+
return attestation;
|
|
394
|
+
}
|
|
395
|
+
console.log("[trails-sdk] waiting for attestation...");
|
|
396
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
export function getIsUsdcAddress(address, chainId) {
|
|
400
|
+
return address?.toLowerCase() === tokenAddresses[chainId]?.toLowerCase();
|
|
401
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WalletClient } from "viem";
|
|
2
|
+
export type AttemptSwitchChainParams = {
|
|
3
|
+
walletClient: WalletClient;
|
|
4
|
+
desiredChainId: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function attemptSwitchChain({ walletClient, desiredChainId, }: AttemptSwitchChainParams): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=chainSwitch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chainSwitch.d.ts","sourceRoot":"","sources":["../src/chainSwitch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAGxC,MAAM,MAAM,wBAAwB,GAAG;IACrC,YAAY,EAAE,YAAY,CAAA;IAC1B,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,wBAAsB,kBAAkB,CAAC,EACvC,YAAY,EACZ,cAAc,GACf,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2C1C"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getChainInfo } from "./chains.js";
|
|
2
|
+
export async function attemptSwitchChain({ walletClient, desiredChainId, }) {
|
|
3
|
+
try {
|
|
4
|
+
// Check if the chain was switched successfully
|
|
5
|
+
let currentChainId = await walletClient.getChainId();
|
|
6
|
+
if (currentChainId === desiredChainId) {
|
|
7
|
+
console.log("[trails-sdk] Chain already switched to:", desiredChainId);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
console.log("[trails-sdk] Switching to chain:", desiredChainId, "currentChainId", currentChainId);
|
|
11
|
+
await walletClient.switchChain({ id: desiredChainId });
|
|
12
|
+
// Check if the chain was switched successfully
|
|
13
|
+
currentChainId = await walletClient.getChainId();
|
|
14
|
+
if (currentChainId !== desiredChainId) {
|
|
15
|
+
throw new Error("Failed to switch chain");
|
|
16
|
+
}
|
|
17
|
+
console.log("[trails-sdk] Chain switched to:", desiredChainId);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof Error &&
|
|
21
|
+
error.message.includes("wallet_addEthereumChain")) {
|
|
22
|
+
const chainInfo = getChainInfo(desiredChainId);
|
|
23
|
+
if (chainInfo) {
|
|
24
|
+
await walletClient.addChain({
|
|
25
|
+
chain: chainInfo,
|
|
26
|
+
});
|
|
27
|
+
return attemptSwitchChain({ walletClient, desiredChainId });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
console.error("[trails-sdk] Chain switch failed:", error);
|
|
31
|
+
throw new Error(`[trails-sdk] Failed to switch chain: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/chains.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Chain } from "viem";
|
|
2
|
+
export declare const supportedSequenceChains: Record<number, Chain>;
|
|
3
|
+
export declare const supportedSequenceTestnetChains: Record<number, Chain>;
|
|
4
|
+
export declare function getChainInfo(chainId: number): Chain | null;
|
|
5
|
+
export declare function getTestnetChainInfo(mainnetChain: Chain | number): Chain | null;
|
|
6
|
+
export declare function getSupportedSequenceChains(): Promise<Chain[]>;
|
|
7
|
+
export declare function getSupportedSequenceTestnetChains(): Promise<Chain[]>;
|
|
8
|
+
export declare function getSupportedChains(): Promise<Chain[]>;
|
|
9
|
+
export declare function useSupportedChains(): {
|
|
10
|
+
supportedChains: Chain[];
|
|
11
|
+
isLoadingChains: boolean;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chains.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAIjC,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAezD,CAAA;AAED,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAahE,CAAA;AAGD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAM1D;AAGD,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,KAAK,GAAG,MAAM,GAC3B,KAAK,GAAG,IAAI,CAKd;AAED,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAEnE;AAED,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAE1E;AA0BD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAgB3D;AAED,wBAAgB,kBAAkB,IAAI;IACpC,eAAe,EAAE,KAAK,EAAE,CAAA;IACxB,eAAe,EAAE,OAAO,CAAA;CACzB,CAcA"}
|
package/dist/chains.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import * as chains from "viem/chains";
|
|
3
|
+
import { getRelaySupportedChains } from "./relaySdk.js";
|
|
4
|
+
export const supportedSequenceChains = {
|
|
5
|
+
[chains.apeChain.id]: chains.mainnet,
|
|
6
|
+
[chains.arbitrum.id]: chains.arbitrum,
|
|
7
|
+
[chains.arbitrumNova.id]: chains.arbitrumNova,
|
|
8
|
+
[chains.avalanche.id]: chains.avalanche,
|
|
9
|
+
[chains.b3.id]: chains.b3,
|
|
10
|
+
[chains.base.id]: chains.base,
|
|
11
|
+
[chains.blast.id]: chains.polygon,
|
|
12
|
+
// [chains.opBNB.id]: chains.opBNB, // Needs chain image
|
|
13
|
+
[chains.mainnet.id]: chains.mainnet,
|
|
14
|
+
[chains.gnosis.id]: chains.gnosis,
|
|
15
|
+
[chains.optimism.id]: chains.optimism,
|
|
16
|
+
[chains.polygon.id]: chains.polygon,
|
|
17
|
+
[chains.soneium.id]: chains.soneium,
|
|
18
|
+
[chains.xai.id]: chains.xai,
|
|
19
|
+
};
|
|
20
|
+
export const supportedSequenceTestnetChains = {
|
|
21
|
+
[chains.arbitrumSepolia.id]: chains.arbitrumSepolia,
|
|
22
|
+
[chains.avalancheFuji.id]: chains.avalancheFuji,
|
|
23
|
+
[chains.b3Sepolia.id]: chains.b3Sepolia,
|
|
24
|
+
[chains.baseSepolia.id]: chains.baseSepolia,
|
|
25
|
+
[chains.blastSepolia.id]: chains.blastSepolia,
|
|
26
|
+
[chains.opBNBTestnet.id]: chains.opBNBTestnet,
|
|
27
|
+
[chains.sepolia.id]: chains.sepolia,
|
|
28
|
+
[chains.gnosisChiado.id]: chains.gnosisChiado,
|
|
29
|
+
[chains.polygonAmoy.id]: chains.polygonAmoy,
|
|
30
|
+
[chains.optimismSepolia.id]: chains.optimismSepolia,
|
|
31
|
+
[chains.soneiumMinato.id]: chains.soneiumMinato,
|
|
32
|
+
[chains.xaiTestnet.id]: chains.xaiTestnet,
|
|
33
|
+
};
|
|
34
|
+
// Helper to get chain info
|
|
35
|
+
export function getChainInfo(chainId) {
|
|
36
|
+
return (Object.values(chains).find((chain) => chain.id === chainId) || null);
|
|
37
|
+
}
|
|
38
|
+
// Get testnet chain info from mainnet chain as input
|
|
39
|
+
export function getTestnetChainInfo(mainnetChain) {
|
|
40
|
+
if (typeof mainnetChain === "number") {
|
|
41
|
+
return supportedSequenceTestnetChains[mainnetChain] || null;
|
|
42
|
+
}
|
|
43
|
+
return supportedSequenceTestnetChains[mainnetChain.id] || null;
|
|
44
|
+
}
|
|
45
|
+
export async function getSupportedSequenceChains() {
|
|
46
|
+
return Object.values(supportedSequenceChains);
|
|
47
|
+
}
|
|
48
|
+
export async function getSupportedSequenceTestnetChains() {
|
|
49
|
+
return Object.values(supportedSequenceTestnetChains);
|
|
50
|
+
}
|
|
51
|
+
// Priority chains that should appear first in the list
|
|
52
|
+
const PRIORITY_CHAIN_IDS = [1, 8453, 42161, 10, 137];
|
|
53
|
+
// Sort function for chains with priority order and then by name
|
|
54
|
+
function sortChains(chains) {
|
|
55
|
+
return chains.sort((a, b) => {
|
|
56
|
+
// 1. Priority chains first (1, 8453, 42161, 10, 137)
|
|
57
|
+
const aPriority = PRIORITY_CHAIN_IDS.indexOf(a.id);
|
|
58
|
+
const bPriority = PRIORITY_CHAIN_IDS.indexOf(b.id);
|
|
59
|
+
// If both are priority chains, sort by priority order
|
|
60
|
+
if (aPriority !== -1 && bPriority !== -1) {
|
|
61
|
+
return aPriority - bPriority;
|
|
62
|
+
}
|
|
63
|
+
// If only one is a priority chain, prioritize it
|
|
64
|
+
if (aPriority !== -1)
|
|
65
|
+
return -1;
|
|
66
|
+
if (bPriority !== -1)
|
|
67
|
+
return 1;
|
|
68
|
+
// 2. Sort by chain name alphabetically
|
|
69
|
+
return a.name.localeCompare(b.name);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export async function getSupportedChains() {
|
|
73
|
+
const sequenceChains = await getSupportedSequenceChains();
|
|
74
|
+
const relayChains = await getRelaySupportedChains();
|
|
75
|
+
// Find intersection of sequence chains and relay chains
|
|
76
|
+
const supportedChains = sequenceChains.filter((sequenceChain) => relayChains.some((relayChain) => relayChain.id === sequenceChain.id));
|
|
77
|
+
// Ensure unique chain IDs by filtering duplicates
|
|
78
|
+
const uniqueChains = supportedChains.filter((chain, index, self) => index === self.findIndex((c) => c.id === chain.id));
|
|
79
|
+
// Sort chains by priority and then by name
|
|
80
|
+
return sortChains(uniqueChains);
|
|
81
|
+
}
|
|
82
|
+
export function useSupportedChains() {
|
|
83
|
+
const { data: supportedChains = [], isLoading: isLoadingChains } = useQuery({
|
|
84
|
+
queryKey: ["supportedChains"],
|
|
85
|
+
queryFn: getSupportedChains,
|
|
86
|
+
staleTime: 60 * 60 * 1000, // 1 hour - chains rarely change
|
|
87
|
+
gcTime: 24 * 60 * 60 * 1000, // 24 hours - keep in cache for a full day
|
|
88
|
+
refetchOnWindowFocus: false, // Don't refetch when window regains focus
|
|
89
|
+
refetchOnReconnect: false, // Don't refetch on network reconnect
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
supportedChains: supportedChains || [],
|
|
93
|
+
isLoadingChains,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const ATTESATION_SIGNER_ADDRESS = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
|
|
2
|
+
export declare const TRAILS_LIFI_SAPIENT_SIGNER_ADDRESS = "0xd7571bd1e3af468c3a49966c9a92a2e907cdfa52";
|
|
3
|
+
export declare const TRAILS_RELAY_SAPIENT_SIGNER_ADDRESS = "0x9a013e7d186611af36a918ef23d81886e8c256f8";
|
|
4
|
+
export declare const TRAILS_CCTP_SAPIENT_SIGNER_ADDRESS = "0xc1A9B197eBb31Fc2B613C59dAC3f3E5698A429D0";
|
|
5
|
+
export declare const DEFAULT_INDEXER_GATEWAY_URL = "https://dev-indexer.sequence.app";
|
|
6
|
+
export declare const DEFAULT_API_URL = "https://v3-api.sequence.app";
|
|
7
|
+
export declare const DEFAULT_ENV = "dev";
|
|
8
|
+
export declare const intentEntrypoints: Record<number, `0x${string}`>;
|
|
9
|
+
export declare const DEFAULT_SEQUENCE_PROJECT_ACCESS_KEY = "AQAAAAAAAAaq1E41OU0QxifQgrVBMgfqg7k";
|
|
10
|
+
export declare const DEFAULT_USE_V3_RELAYERS = true;
|
|
11
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,+CACQ,CAAA;AAE9C,eAAO,MAAM,kCAAkC,+CACD,CAAA;AAC9C,eAAO,MAAM,mCAAmC,+CACF,CAAA;AAC9C,eAAO,MAAM,kCAAkC,+CACD,CAAA;AAE9C,eAAO,MAAM,2BAA2B,qCAAqC,CAAA;AAC7E,eAAO,MAAM,eAAe,gCAAgC,CAAA;AAC5D,eAAO,MAAM,WAAW,QAAQ,CAAA;AAEhC,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAM3D,CAAA;AAED,eAAO,MAAM,mCAAmC,wCACT,CAAA;AAEvC,eAAO,MAAM,uBAAuB,OAAO,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const ATTESATION_SIGNER_ADDRESS = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
|
|
2
|
+
export const TRAILS_LIFI_SAPIENT_SIGNER_ADDRESS = "0xd7571bd1e3af468c3a49966c9a92a2e907cdfa52";
|
|
3
|
+
export const TRAILS_RELAY_SAPIENT_SIGNER_ADDRESS = "0x9a013e7d186611af36a918ef23d81886e8c256f8";
|
|
4
|
+
export const TRAILS_CCTP_SAPIENT_SIGNER_ADDRESS = "0xc1A9B197eBb31Fc2B613C59dAC3f3E5698A429D0";
|
|
5
|
+
export const DEFAULT_INDEXER_GATEWAY_URL = "https://dev-indexer.sequence.app";
|
|
6
|
+
export const DEFAULT_API_URL = "https://v3-api.sequence.app";
|
|
7
|
+
export const DEFAULT_ENV = "dev";
|
|
8
|
+
export const intentEntrypoints = {
|
|
9
|
+
8453: "0x2bf4c63199eD7D8A737E8DB2cC19E0C0103F6bE3",
|
|
10
|
+
84532: "0xdcd9160492C6D43ABbd28D4d06F68ad77f1A0F2b",
|
|
11
|
+
421614: "0xf18A16E1C778baCA5d6f7F48cC4c9bb913e5e579",
|
|
12
|
+
42161: "0x674827B6BE8780DBdb96DC02c735275e3a982c90",
|
|
13
|
+
137: "0x4dBb20eA3A969F1A44d7653D4Dc8632B853E36DE",
|
|
14
|
+
};
|
|
15
|
+
export const DEFAULT_SEQUENCE_PROJECT_ACCESS_KEY = "AQAAAAAAAAaq1E41OU0QxifQgrVBMgfqg7k";
|
|
16
|
+
export const DEFAULT_USE_V3_RELAYERS = true;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoders.d.ts","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAE/B,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,wBAAgB,oBAAoB,CAAC,EACnC,SAAS,EACT,MAAM,GACP,EAAE,mBAAmB,GAAG,GAAG,CAQ3B"}
|
package/dist/encoders.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AbiFunction } from "ox";
|
|
2
|
+
export function getERC20TransferData({ recipient, amount, }) {
|
|
3
|
+
const erc20Transfer = AbiFunction.from("function transfer(address,uint256) returns (bool)");
|
|
4
|
+
return AbiFunction.encodeData(erc20Transfer, [
|
|
5
|
+
recipient,
|
|
6
|
+
amount,
|
|
7
|
+
]);
|
|
8
|
+
}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,UAc3C"}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function getFullErrorMessage(err) {
|
|
2
|
+
const messages = [];
|
|
3
|
+
let current = err;
|
|
4
|
+
while (current) {
|
|
5
|
+
if (current.message) {
|
|
6
|
+
messages.push(current.message);
|
|
7
|
+
}
|
|
8
|
+
// Check for nested error cause
|
|
9
|
+
current = current.cause ?? current.originalError ?? current.error ?? null;
|
|
10
|
+
}
|
|
11
|
+
return messages.join(" | Caused by: ");
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ExplorerUrlParams = {
|
|
2
|
+
txHash: string;
|
|
3
|
+
chainId: number;
|
|
4
|
+
};
|
|
5
|
+
export type ExplorerUrlForAddressParams = {
|
|
6
|
+
address: string;
|
|
7
|
+
chainId: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function getBaseExplorerUrl(chainId: number): string;
|
|
10
|
+
export declare function getExplorerUrl({ txHash, chainId }: ExplorerUrlParams): string;
|
|
11
|
+
export declare function getExplorerUrlForAddress({ address, chainId, }: ExplorerUrlForAddressParams): string;
|
|
12
|
+
//# sourceMappingURL=explorer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../src/explorer.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAW1D;AAED,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,iBAAiB,GAAG,MAAM,CAG7E;AAED,wBAAgB,wBAAwB,CAAC,EACvC,OAAO,EACP,OAAO,GACR,EAAE,2BAA2B,GAAG,MAAM,CAGtC"}
|