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
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Address,
|
|
3
|
+
type Chain,
|
|
4
|
+
concat,
|
|
5
|
+
createPublicClient,
|
|
6
|
+
createWalletClient,
|
|
7
|
+
encodeAbiParameters,
|
|
8
|
+
encodeFunctionData,
|
|
9
|
+
getAddress,
|
|
10
|
+
type Hex,
|
|
11
|
+
http,
|
|
12
|
+
keccak256,
|
|
13
|
+
pad,
|
|
14
|
+
size,
|
|
15
|
+
slice,
|
|
16
|
+
toHex,
|
|
17
|
+
} from "viem"
|
|
18
|
+
import { privateKeyToAccount } from "viem/accounts"
|
|
19
|
+
|
|
20
|
+
export type UserOperation = {
|
|
21
|
+
sender: Address
|
|
22
|
+
nonce: bigint
|
|
23
|
+
initCode: Hex
|
|
24
|
+
callData: Hex
|
|
25
|
+
verificationGasLimit: bigint
|
|
26
|
+
callGasLimit: bigint
|
|
27
|
+
maxPriorityFeePerGas: bigint
|
|
28
|
+
maxFeePerGas: bigint
|
|
29
|
+
factory: Address
|
|
30
|
+
factoryData: Hex
|
|
31
|
+
paymaster: Address
|
|
32
|
+
paymasterVerificationGasLimit: bigint
|
|
33
|
+
paymasterPostOpGasLimit: bigint
|
|
34
|
+
paymasterData: Hex
|
|
35
|
+
preVerificationGas: bigint
|
|
36
|
+
signature: Hex
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Minimal EntryPoint ABI for handleOps
|
|
40
|
+
export const ENTRYPOINT_ABI = [
|
|
41
|
+
{
|
|
42
|
+
inputs: [
|
|
43
|
+
{
|
|
44
|
+
components: [
|
|
45
|
+
{
|
|
46
|
+
internalType: "address",
|
|
47
|
+
name: "sender",
|
|
48
|
+
type: "address",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
internalType: "uint256",
|
|
52
|
+
name: "nonce",
|
|
53
|
+
type: "uint256",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
internalType: "bytes",
|
|
57
|
+
name: "initCode",
|
|
58
|
+
type: "bytes",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
internalType: "bytes",
|
|
62
|
+
name: "callData",
|
|
63
|
+
type: "bytes",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
internalType: "bytes32",
|
|
67
|
+
name: "accountGasLimits",
|
|
68
|
+
type: "bytes32",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
internalType: "uint256",
|
|
72
|
+
name: "preVerificationGas",
|
|
73
|
+
type: "uint256",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
internalType: "bytes32",
|
|
77
|
+
name: "gasFees",
|
|
78
|
+
type: "bytes32",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
internalType: "bytes",
|
|
82
|
+
name: "paymasterAndData",
|
|
83
|
+
type: "bytes",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
internalType: "bytes",
|
|
87
|
+
name: "signature",
|
|
88
|
+
type: "bytes",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
internalType: "struct PackedUserOperation",
|
|
92
|
+
name: "userOp",
|
|
93
|
+
type: "tuple",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
internalType: "bytes32",
|
|
97
|
+
name: "userOpHash",
|
|
98
|
+
type: "bytes32",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
name: "executeUserOp",
|
|
102
|
+
outputs: [],
|
|
103
|
+
stateMutability: "nonpayable",
|
|
104
|
+
type: "function",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
inputs: [
|
|
108
|
+
{
|
|
109
|
+
components: [
|
|
110
|
+
{
|
|
111
|
+
internalType: "address",
|
|
112
|
+
name: "sender",
|
|
113
|
+
type: "address",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
internalType: "uint256",
|
|
117
|
+
name: "nonce",
|
|
118
|
+
type: "uint256",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
internalType: "bytes",
|
|
122
|
+
name: "initCode",
|
|
123
|
+
type: "bytes",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
internalType: "bytes",
|
|
127
|
+
name: "callData",
|
|
128
|
+
type: "bytes",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
internalType: "bytes32",
|
|
132
|
+
name: "accountGasLimits",
|
|
133
|
+
type: "bytes32",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
internalType: "uint256",
|
|
137
|
+
name: "preVerificationGas",
|
|
138
|
+
type: "uint256",
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
internalType: "bytes32",
|
|
142
|
+
name: "gasFees",
|
|
143
|
+
type: "bytes32",
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
internalType: "bytes",
|
|
147
|
+
name: "paymasterAndData",
|
|
148
|
+
type: "bytes",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
internalType: "bytes",
|
|
152
|
+
name: "signature",
|
|
153
|
+
type: "bytes",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
internalType: "struct PackedUserOperation[]",
|
|
157
|
+
name: "ops",
|
|
158
|
+
type: "tuple[]",
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
internalType: "address payable",
|
|
162
|
+
name: "beneficiary",
|
|
163
|
+
type: "address",
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
name: "handleOps",
|
|
167
|
+
outputs: [],
|
|
168
|
+
stateMutability: "nonpayable",
|
|
169
|
+
type: "function",
|
|
170
|
+
},
|
|
171
|
+
]
|
|
172
|
+
|
|
173
|
+
export const ENTRYPOINT_ADDRESS = "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
|
|
174
|
+
|
|
175
|
+
export async function sendUserOperationDirectly({
|
|
176
|
+
userOp,
|
|
177
|
+
relayerPrivateKey,
|
|
178
|
+
chain,
|
|
179
|
+
}: {
|
|
180
|
+
userOp: any // fully formed + signed UserOp
|
|
181
|
+
relayerPrivateKey: `0x${string}`
|
|
182
|
+
chain: Chain
|
|
183
|
+
}) {
|
|
184
|
+
console.log("[trails-sdk] userOp", userOp)
|
|
185
|
+
const relayerAccount = privateKeyToAccount(relayerPrivateKey)
|
|
186
|
+
|
|
187
|
+
const walletClient = createWalletClient({
|
|
188
|
+
chain: chain,
|
|
189
|
+
transport: http(),
|
|
190
|
+
account: relayerAccount,
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
const publicClient = createPublicClient({
|
|
194
|
+
chain: chain,
|
|
195
|
+
transport: http(),
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
const packedOp = toPackedUserOperation(userOp) // converts to PackedUserOperation
|
|
199
|
+
|
|
200
|
+
// const paymasterAddress = "0x73749B2BBE88abFFfe48BA81b3B7899CE7733e36"
|
|
201
|
+
// packedOp.paymasterAndData = encodePacked(['address'], [paymasterAddress])
|
|
202
|
+
|
|
203
|
+
const opHash = await getUserOperationHashV07({
|
|
204
|
+
userOperation: packedOp,
|
|
205
|
+
entryPointAddress: ENTRYPOINT_ADDRESS,
|
|
206
|
+
chainId: chain.id,
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
console.log("[trails-sdk] opHash", opHash)
|
|
210
|
+
|
|
211
|
+
console.log("[trails-sdk] packedOp", packedOp)
|
|
212
|
+
|
|
213
|
+
console.log("[trails-sdk] relayerAccount", relayerAccount)
|
|
214
|
+
|
|
215
|
+
const handleOpsData = encodeHandleOpsCalldata({
|
|
216
|
+
userOps: [userOp],
|
|
217
|
+
beneficiary: relayerAccount.address,
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
console.log("[trails-sdk] handleOpsData", handleOpsData)
|
|
221
|
+
|
|
222
|
+
const txHash = await walletClient.sendTransaction({
|
|
223
|
+
to: ENTRYPOINT_ADDRESS,
|
|
224
|
+
data: handleOpsData,
|
|
225
|
+
value: BigInt(0),
|
|
226
|
+
gasLimit: 1000000,
|
|
227
|
+
chain: chain,
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
console.log("[trails-sdk] Sent handleOps tx:", txHash)
|
|
231
|
+
|
|
232
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash })
|
|
233
|
+
console.log("[trails-sdk] Confirmed handleOps tx:", receipt.transactionHash)
|
|
234
|
+
|
|
235
|
+
return receipt.transactionHash
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export type PackedUserOperation = {
|
|
239
|
+
sender: `0x${string}`
|
|
240
|
+
nonce: bigint
|
|
241
|
+
initCode: `0x${string}`
|
|
242
|
+
callData: `0x${string}`
|
|
243
|
+
accountGasLimits: `0x${string}`
|
|
244
|
+
preVerificationGas: bigint
|
|
245
|
+
gasFees: `0x${string}`
|
|
246
|
+
paymasterAndData: `0x${string}`
|
|
247
|
+
signature: `0x${string}`
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export type UserOperationV07 = {
|
|
251
|
+
sender: `0x${string}`
|
|
252
|
+
nonce: bigint
|
|
253
|
+
initCode: `0x${string}`
|
|
254
|
+
callData: `0x${string}`
|
|
255
|
+
verificationGasLimit: bigint
|
|
256
|
+
callGasLimit: bigint
|
|
257
|
+
maxPriorityFeePerGas: bigint
|
|
258
|
+
maxFeePerGas: bigint
|
|
259
|
+
factory: `0x${string}`
|
|
260
|
+
factoryData: `0x${string}`
|
|
261
|
+
paymaster: `0x${string}`
|
|
262
|
+
paymasterVerificationGasLimit: bigint
|
|
263
|
+
paymasterPostOpGasLimit: bigint
|
|
264
|
+
paymasterData: `0x${string}`
|
|
265
|
+
preVerificationGas: bigint
|
|
266
|
+
signature: `0x${string}`
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Helper to encode account gas limits as bytes32
|
|
270
|
+
export function getAccountGasLimits(op: UserOperationV07) {
|
|
271
|
+
if (!op.verificationGasLimit) {
|
|
272
|
+
throw new Error("verificationGasLimit is required")
|
|
273
|
+
}
|
|
274
|
+
if (!op.callGasLimit) {
|
|
275
|
+
throw new Error("callGasLimit is required")
|
|
276
|
+
}
|
|
277
|
+
return concat([
|
|
278
|
+
pad(toHex(op.verificationGasLimit), { size: 16 }),
|
|
279
|
+
pad(toHex(op.callGasLimit), { size: 16 }),
|
|
280
|
+
])
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Helper to encode fee parameters as bytes32
|
|
284
|
+
export function getGasFees(op: UserOperationV07) {
|
|
285
|
+
if (!op.maxPriorityFeePerGas) {
|
|
286
|
+
throw new Error("maxPriorityFeePerGas is required")
|
|
287
|
+
}
|
|
288
|
+
if (!op.maxFeePerGas) {
|
|
289
|
+
throw new Error("maxFeePerGas is required")
|
|
290
|
+
}
|
|
291
|
+
return concat([
|
|
292
|
+
pad(toHex(op.maxPriorityFeePerGas), { size: 16 }),
|
|
293
|
+
pad(toHex(op.maxFeePerGas), { size: 16 }),
|
|
294
|
+
])
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Helper to encode initCode
|
|
298
|
+
export function getInitCode(op: UserOperationV07) {
|
|
299
|
+
if (!op.factory) return "0x"
|
|
300
|
+
return concat([
|
|
301
|
+
op.factory === "0x7702"
|
|
302
|
+
? pad(op.factory, { dir: "right", size: 20 })
|
|
303
|
+
: op.factory,
|
|
304
|
+
op.factoryData || "0x",
|
|
305
|
+
])
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Helper to encode paymasterAndData field
|
|
309
|
+
export function getPaymasterAndData(op: UserOperationV07) {
|
|
310
|
+
if (!op.paymaster) return "0x"
|
|
311
|
+
if (!op.paymasterVerificationGasLimit) {
|
|
312
|
+
throw new Error("paymasterVerificationGasLimit is required")
|
|
313
|
+
}
|
|
314
|
+
if (!op.paymasterPostOpGasLimit) {
|
|
315
|
+
throw new Error("paymasterPostOpGasLimit is required")
|
|
316
|
+
}
|
|
317
|
+
return concat([
|
|
318
|
+
op.paymaster,
|
|
319
|
+
pad(toHex(op.paymasterVerificationGasLimit || 0n), { size: 16 }),
|
|
320
|
+
pad(toHex(op.paymasterPostOpGasLimit || 0n), { size: 16 }),
|
|
321
|
+
op.paymasterData || "0x",
|
|
322
|
+
])
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Final conversion function
|
|
326
|
+
export function toPackedUserOperation(
|
|
327
|
+
op: UserOperationV07,
|
|
328
|
+
): PackedUserOperation {
|
|
329
|
+
return {
|
|
330
|
+
sender: op.sender,
|
|
331
|
+
nonce: op.nonce,
|
|
332
|
+
initCode: getInitCode(op),
|
|
333
|
+
callData: op.callData,
|
|
334
|
+
accountGasLimits: getAccountGasLimits(op),
|
|
335
|
+
preVerificationGas: op.preVerificationGas,
|
|
336
|
+
gasFees: getGasFees(op),
|
|
337
|
+
paymasterAndData: getPaymasterAndData(op),
|
|
338
|
+
signature: op.signature,
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export const getNonceKeyAndSequence = (nonce: bigint) => {
|
|
343
|
+
const nonceKey = nonce >> 64n // first 192 bits of nonce
|
|
344
|
+
const nonceSequence = nonce & 0xffffffffffffffffn // last 64 bits of nonce
|
|
345
|
+
|
|
346
|
+
return [nonceKey, nonceSequence]
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export const encodeNonce = ({
|
|
350
|
+
nonceKey,
|
|
351
|
+
nonceSequence,
|
|
352
|
+
}: {
|
|
353
|
+
nonceKey: bigint
|
|
354
|
+
nonceSequence: bigint
|
|
355
|
+
}) => {
|
|
356
|
+
return (nonceKey << 64n) | nonceSequence
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export const getUserOperationHashV07 = ({
|
|
360
|
+
userOperation,
|
|
361
|
+
entryPointAddress,
|
|
362
|
+
chainId,
|
|
363
|
+
}: {
|
|
364
|
+
userOperation: PackedUserOperation
|
|
365
|
+
entryPointAddress: Address
|
|
366
|
+
chainId: number
|
|
367
|
+
}) => {
|
|
368
|
+
const hash = keccak256(
|
|
369
|
+
encodeAbiParameters(
|
|
370
|
+
[
|
|
371
|
+
{
|
|
372
|
+
name: "sender",
|
|
373
|
+
type: "address",
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
name: "nonce",
|
|
377
|
+
type: "uint256",
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
name: "initCodeHash",
|
|
381
|
+
type: "bytes32",
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
name: "callDataHash",
|
|
385
|
+
type: "bytes32",
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
name: "accountGasLimits",
|
|
389
|
+
type: "bytes32",
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
name: "preVerificationGas",
|
|
393
|
+
type: "uint256",
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
name: "gasFees",
|
|
397
|
+
type: "bytes32",
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
name: "paymasterAndDataHash",
|
|
401
|
+
type: "bytes32",
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
[
|
|
405
|
+
userOperation.sender,
|
|
406
|
+
userOperation.nonce,
|
|
407
|
+
keccak256(userOperation.initCode),
|
|
408
|
+
keccak256(userOperation.callData),
|
|
409
|
+
userOperation.accountGasLimits,
|
|
410
|
+
userOperation.preVerificationGas,
|
|
411
|
+
userOperation.gasFees,
|
|
412
|
+
keccak256(userOperation.paymasterAndData),
|
|
413
|
+
],
|
|
414
|
+
),
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
return keccak256(
|
|
418
|
+
encodeAbiParameters(
|
|
419
|
+
[
|
|
420
|
+
{
|
|
421
|
+
name: "userOpHash",
|
|
422
|
+
type: "bytes32",
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
name: "entryPointAddress",
|
|
426
|
+
type: "address",
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
name: "chainId",
|
|
430
|
+
type: "uint256",
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
[hash, entryPointAddress, BigInt(chainId)],
|
|
434
|
+
),
|
|
435
|
+
)
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export const encodeHandleOpsCalldata = ({
|
|
439
|
+
userOps,
|
|
440
|
+
beneficiary,
|
|
441
|
+
}: {
|
|
442
|
+
userOps: UserOperation[]
|
|
443
|
+
beneficiary: Address
|
|
444
|
+
}): Hex => {
|
|
445
|
+
const packedUserOps = packUserOps(userOps)
|
|
446
|
+
|
|
447
|
+
console.log(
|
|
448
|
+
"[trails-sdk] encodeHandleOpsCalldata packedUserOps",
|
|
449
|
+
packedUserOps,
|
|
450
|
+
)
|
|
451
|
+
|
|
452
|
+
return encodeFunctionData({
|
|
453
|
+
abi: ENTRYPOINT_ABI,
|
|
454
|
+
functionName: "handleOps",
|
|
455
|
+
args: [packedUserOps, beneficiary],
|
|
456
|
+
})
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export const packUserOps = (userOps: UserOperation[]) => {
|
|
460
|
+
const packedUserOps = userOps.map((op) =>
|
|
461
|
+
toPackedUserOperation(op as UserOperationV07),
|
|
462
|
+
)
|
|
463
|
+
return packedUserOps as PackedUserOperation[]
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export type UnpackedUserOperation = {
|
|
467
|
+
sender: Address
|
|
468
|
+
nonce: bigint
|
|
469
|
+
callData: Hex
|
|
470
|
+
callGasLimit: bigint
|
|
471
|
+
factory: Address | null
|
|
472
|
+
factoryData: Hex | null
|
|
473
|
+
verificationGasLimit: bigint
|
|
474
|
+
preVerificationGas: bigint
|
|
475
|
+
maxFeePerGas: bigint
|
|
476
|
+
maxPriorityFeePerGas: bigint
|
|
477
|
+
paymaster: Address | null
|
|
478
|
+
paymasterVerificationGasLimit: bigint | null
|
|
479
|
+
paymasterPostOpGasLimit: bigint | null
|
|
480
|
+
paymasterData: Hex | null
|
|
481
|
+
signature: Hex
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export function toUnpackedUserOperation(
|
|
485
|
+
packedUserOperation: PackedUserOperation,
|
|
486
|
+
): UnpackedUserOperation {
|
|
487
|
+
const { factory, factoryData } = unPackInitCode(packedUserOperation.initCode)
|
|
488
|
+
|
|
489
|
+
const { callGasLimit, verificationGasLimit } = unpackAccountGasLimits(
|
|
490
|
+
packedUserOperation.accountGasLimits,
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = unpackGasLimits(
|
|
494
|
+
packedUserOperation.gasFees,
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
const {
|
|
498
|
+
paymaster,
|
|
499
|
+
paymasterVerificationGasLimit,
|
|
500
|
+
paymasterPostOpGasLimit,
|
|
501
|
+
paymasterData,
|
|
502
|
+
} = unpackPaymasterAndData(packedUserOperation.paymasterAndData)
|
|
503
|
+
|
|
504
|
+
return {
|
|
505
|
+
sender: packedUserOperation.sender,
|
|
506
|
+
nonce: packedUserOperation.nonce,
|
|
507
|
+
factory: factory,
|
|
508
|
+
factoryData: factoryData,
|
|
509
|
+
callData: packedUserOperation.callData,
|
|
510
|
+
callGasLimit: callGasLimit,
|
|
511
|
+
verificationGasLimit: verificationGasLimit,
|
|
512
|
+
preVerificationGas: packedUserOperation.preVerificationGas,
|
|
513
|
+
maxFeePerGas: maxFeePerGas,
|
|
514
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas,
|
|
515
|
+
paymaster: paymaster,
|
|
516
|
+
paymasterVerificationGasLimit: paymasterVerificationGasLimit,
|
|
517
|
+
paymasterPostOpGasLimit: paymasterPostOpGasLimit,
|
|
518
|
+
paymasterData: paymasterData,
|
|
519
|
+
signature: packedUserOperation.signature,
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export function unPackInitCode(initCode: Hex) {
|
|
524
|
+
if (initCode === "0x") {
|
|
525
|
+
return {
|
|
526
|
+
factory: null,
|
|
527
|
+
factoryData: null,
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return {
|
|
532
|
+
factory: getAddress(slice(initCode, 0, 20)),
|
|
533
|
+
factoryData: size(initCode) > 20 ? slice(initCode, 20) : null,
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export function unpackAccountGasLimits(accountGasLimits: Hex) {
|
|
538
|
+
return {
|
|
539
|
+
verificationGasLimit: BigInt(slice(accountGasLimits, 0, 16)),
|
|
540
|
+
callGasLimit: BigInt(slice(accountGasLimits, 16)),
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export function unpackGasLimits(gasLimits: Hex) {
|
|
545
|
+
return {
|
|
546
|
+
maxPriorityFeePerGas: BigInt(slice(gasLimits, 0, 16)),
|
|
547
|
+
maxFeePerGas: BigInt(slice(gasLimits, 16)),
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export function unpackPaymasterAndData(paymasterAndData: Hex) {
|
|
552
|
+
if (paymasterAndData === "0x") {
|
|
553
|
+
return {
|
|
554
|
+
paymaster: null,
|
|
555
|
+
paymasterVerificationGasLimit: null,
|
|
556
|
+
paymasterPostOpGasLimit: null,
|
|
557
|
+
paymasterData: null,
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const paymasterAndDataSize = size(paymasterAndData)
|
|
562
|
+
|
|
563
|
+
return {
|
|
564
|
+
paymaster: getAddress(slice(paymasterAndData, 0, 20)),
|
|
565
|
+
paymasterVerificationGasLimit: BigInt(slice(paymasterAndData, 20, 36)),
|
|
566
|
+
paymasterPostOpGasLimit: BigInt(slice(paymasterAndData, 36, 52)),
|
|
567
|
+
paymasterData:
|
|
568
|
+
paymasterAndDataSize > 52 ? slice(paymasterAndData, 52) : null,
|
|
569
|
+
}
|
|
570
|
+
}
|