create-stylus 0.0.5
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/.github/issue_template.md +7 -0
- package/.github/pull_request_template.md +11 -0
- package/.github/workflows/release-alpha.yml +32 -0
- package/.github/workflows/release-manual.yml +26 -0
- package/.yarnrc.yml +1 -0
- package/CONTRIBUTING.md +42 -0
- package/README.md +66 -0
- package/bin/create-dapp-ss.js +4 -0
- package/package.json +46 -0
- package/rollup.config.js +22 -0
- package/src/cli.ts +14 -0
- package/src/extensions.json +14 -0
- package/src/main.ts +72 -0
- package/src/tasks/copy-extension-file.ts +227 -0
- package/src/tasks/copy-template-files.ts +252 -0
- package/src/tasks/create-first-git-commit.ts +35 -0
- package/src/tasks/create-project-directory.ts +34 -0
- package/src/tasks/index.ts +5 -0
- package/src/tasks/install-packages.ts +15 -0
- package/src/tasks/prettier-format.ts +17 -0
- package/src/types.ts +31 -0
- package/src/utils/consts.ts +1 -0
- package/src/utils/find-files-recursively.ts +19 -0
- package/src/utils/link.ts +44 -0
- package/src/utils/load-extensions.ts +10 -0
- package/src/utils/merge-package-json.ts +33 -0
- package/src/utils/parse-arguments-into-options.ts +38 -0
- package/src/utils/prompt-for-missing-options.ts +53 -0
- package/src/utils/render-intro-message.ts +11 -0
- package/src/utils/render-outro-message.ts +34 -0
- package/templates/base/.github/ISSUE_TEMPLATE/bug_report.yml +58 -0
- package/templates/base/.github/ISSUE_TEMPLATE/config.yml +8 -0
- package/templates/base/.github/pull_request_template.md +16 -0
- package/templates/base/.github/workflows/lint.yaml +300 -0
- package/templates/base/.gitignore.template.mjs +19 -0
- package/templates/base/.gitmodules +0 -0
- package/templates/base/.husky/pre-commit +4 -0
- package/templates/base/.lintstagedrc.js +21 -0
- package/templates/base/.vscode/settings.json +7 -0
- package/templates/base/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
- package/templates/base/.yarn/releases/yarn-3.2.3.cjs +783 -0
- package/templates/base/.yarnrc.yml +11 -0
- package/templates/base/CONTRIBUTING.md +86 -0
- package/templates/base/LICENCE +21 -0
- package/templates/base/dist/cli.js +683 -0
- package/templates/base/dist/cli.js.map +1 -0
- package/templates/base/nitro-devnode/LICENSE +201 -0
- package/templates/base/nitro-devnode/README.md +70 -0
- package/templates/base/nitro-devnode/run-dev-node.sh +132 -0
- package/templates/base/nitro-devnode/start-chain-with-cors.sh +150 -0
- package/templates/base/nitro-devnode/stylus-deployer-bytecode.txt +1 -0
- package/templates/base/nitro-devnode/stylus-dev/Dockerfile +10 -0
- package/templates/base/package.json +44 -0
- package/templates/base/packages/nextjs/.env.example +13 -0
- package/templates/base/packages/nextjs/.eslintignore +11 -0
- package/templates/base/packages/nextjs/.eslintrc.json +15 -0
- package/templates/base/packages/nextjs/.gitignore.template.mjs +42 -0
- package/templates/base/packages/nextjs/.prettierrc.js +9 -0
- package/templates/base/packages/nextjs/.prettierrc.json +8 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/AddressCodeTab.tsx +27 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/AddressComponent.tsx +36 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/AddressLogsTab.tsx +21 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/AddressStorageTab.tsx +61 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/BackButton.tsx +12 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/ContractTabs.tsx +102 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/PaginationButton.tsx +39 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/SearchBar.tsx +49 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/TransactionHash.tsx +28 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/TransactionsTable.tsx +71 -0
- package/templates/base/packages/nextjs/app/blockexplorer/_components/index.tsx +7 -0
- package/templates/base/packages/nextjs/app/blockexplorer/address/[address]/page.tsx +101 -0
- package/templates/base/packages/nextjs/app/blockexplorer/layout.tsx +12 -0
- package/templates/base/packages/nextjs/app/blockexplorer/page.tsx +83 -0
- package/templates/base/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx +23 -0
- package/templates/base/packages/nextjs/app/blockexplorer/transaction/_components/TransactionComp.tsx +152 -0
- package/templates/base/packages/nextjs/app/debug/_components/DebugContracts.tsx +73 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/ContractInput.tsx +84 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx +43 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/ContractUI.tsx +164 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/ContractVariables.tsx +50 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx +49 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/DisplayVariable.tsx +85 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/InheritanceTooltip.tsx +14 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx +102 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/Tuple.tsx +44 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/TupleArray.tsx +142 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx +42 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/WriteOnlyFunctionForm.tsx +144 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/index.tsx +8 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/utilsContract.tsx +166 -0
- package/templates/base/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx +114 -0
- package/templates/base/packages/nextjs/app/debug/page.tsx +14 -0
- package/templates/base/packages/nextjs/app/layout.tsx +67 -0
- package/templates/base/packages/nextjs/app/not-found.tsx +16 -0
- package/templates/base/packages/nextjs/app/page.tsx +94 -0
- package/templates/base/packages/nextjs/components/Background.tsx +37 -0
- package/templates/base/packages/nextjs/components/Card.tsx +40 -0
- package/templates/base/packages/nextjs/components/Footer.tsx +93 -0
- package/templates/base/packages/nextjs/components/Header.tsx +114 -0
- package/templates/base/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx +77 -0
- package/templates/base/packages/nextjs/components/SwitchTheme.tsx +41 -0
- package/templates/base/packages/nextjs/components/ThemeProvider.tsx +13 -0
- package/templates/base/packages/nextjs/components/assets/BuidlGuidlLogo.tsx +18 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Address/Address.tsx +187 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Address/AddressCopyIcon.tsx +23 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Address/AddressLinkWrapper.tsx +29 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Balance.tsx +75 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/BlockieAvatar.tsx +17 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Faucet.tsx +131 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/FaucetButton.tsx +75 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Input/AddressInput.tsx +120 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Input/Bytes32Input.tsx +31 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Input/BytesInput.tsx +28 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Input/EtherInput.tsx +128 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Input/InputBase.tsx +66 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Input/IntegerInput.tsx +63 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Input/index.ts +9 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/Input/utils.ts +109 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/AddressInfoDropdown.tsx +121 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/AddressQRCodeModal.tsx +33 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BurnerWalletModal.tsx +63 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/NetworkOptions.tsx +48 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/WrongNetworkDropdown.tsx +32 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/index.tsx +89 -0
- package/templates/base/packages/nextjs/components/scaffold-eth/index.tsx +7 -0
- package/templates/base/packages/nextjs/contracts/deployedContracts.ts +9 -0
- package/templates/base/packages/nextjs/contracts/externalContracts.ts +16 -0
- package/templates/base/packages/nextjs/eslint.config.mjs +32 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/index.ts +17 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useAnimationConfig.ts +20 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useContractLogs.ts +40 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useCopyToClipboard.ts +19 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useDeployedContractInfo.ts +86 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useDisplayUsdMode.ts +21 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useFetchBlocks.ts +133 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useInitializeNativeCurrencyPrice.ts +32 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useNativeCurrencyPrice.ts +34 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useNetworkColor.ts +22 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useOutsideClick.ts +23 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts +65 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts +213 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldReadContract.ts +80 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWatchContractEvent.ts +40 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts +191 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useSelectedNetwork.ts +18 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useTargetNetwork.ts +23 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useTransactor.tsx +114 -0
- package/templates/base/packages/nextjs/hooks/scaffold-eth/useWatchBalance.ts +21 -0
- package/templates/base/packages/nextjs/icons/CompassIcon.tsx +39 -0
- package/templates/base/packages/nextjs/icons/DarkBugAntIcon.tsx +30 -0
- package/templates/base/packages/nextjs/icons/LightBugAntIcon.tsx +52 -0
- package/templates/base/packages/nextjs/next-env.d.ts +5 -0
- package/templates/base/packages/nextjs/next.config.js +19 -0
- package/templates/base/packages/nextjs/package.json +58 -0
- package/templates/base/packages/nextjs/postcss.config.js +6 -0
- package/templates/base/packages/nextjs/public/debug-image.png +0 -0
- package/templates/base/packages/nextjs/public/favicon.png +0 -0
- package/templates/base/packages/nextjs/public/logo.svg +8 -0
- package/templates/base/packages/nextjs/public/manifest.json +5 -0
- package/templates/base/packages/nextjs/public/thumbnail.jpg +0 -0
- package/templates/base/packages/nextjs/react-copy-to-clipboard.d.ts +44 -0
- package/templates/base/packages/nextjs/scaffold.config.ts +56 -0
- package/templates/base/packages/nextjs/services/store/store.ts +39 -0
- package/templates/base/packages/nextjs/services/web3/wagmiConfig.tsx +44 -0
- package/templates/base/packages/nextjs/services/web3/wagmiConnectors.tsx +51 -0
- package/templates/base/packages/nextjs/styles/globals.css +80 -0
- package/templates/base/packages/nextjs/tailwind.config.js +97 -0
- package/templates/base/packages/nextjs/tsconfig.json +28 -0
- package/templates/base/packages/nextjs/types/abitype/abi.d.ts +16 -0
- package/templates/base/packages/nextjs/types/utils.ts +3 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/block.ts +17 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/common.ts +8 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/contract.ts +352 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/contractsData.ts +11 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/decodeTxData.ts +65 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts +72 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts +50 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/getParsedError.ts +35 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/index.ts +6 -0
- package/templates/base/packages/nextjs/utils/scaffold-eth/notification.tsx +90 -0
- package/templates/base/packages/nextjs/utils/scaffold-stylus/burner.ts +59 -0
- package/templates/base/packages/nextjs/utils/scaffold-stylus/chain.ts +42 -0
- package/templates/base/packages/nextjs/utils/scaffold-stylus/index.ts +3 -0
- package/templates/base/packages/nextjs/utils/scaffold-stylus/networks.ts +94 -0
- package/templates/base/packages/nextjs/vercel.json +3 -0
- package/templates/base/packages/stylus/.env.example +16 -0
- package/templates/base/packages/stylus/.eslintrc.js +23 -0
- package/templates/base/packages/stylus/.gitignore.template.mjs +7 -0
- package/templates/base/packages/stylus/jest.config.js +15 -0
- package/templates/base/packages/stylus/package.json +48 -0
- package/templates/base/packages/stylus/scripts/deploy.ts +46 -0
- package/templates/base/packages/stylus/scripts/deploy_contract.ts +84 -0
- package/templates/base/packages/stylus/scripts/deploy_wrapper.ts +39 -0
- package/templates/base/packages/stylus/scripts/export_abi.ts +87 -0
- package/templates/base/packages/stylus/scripts/index.ts +0 -0
- package/templates/base/packages/stylus/scripts/new_module.sh +35 -0
- package/templates/base/packages/stylus/scripts/test_network.ts +31 -0
- package/templates/base/packages/stylus/scripts/utils/command.ts +152 -0
- package/templates/base/packages/stylus/scripts/utils/contract.ts +228 -0
- package/templates/base/packages/stylus/scripts/utils/deployment.ts +260 -0
- package/templates/base/packages/stylus/scripts/utils/index.ts +6 -0
- package/templates/base/packages/stylus/scripts/utils/network.ts +132 -0
- package/templates/base/packages/stylus/scripts/utils/type.ts +51 -0
- package/templates/base/packages/stylus/scripts/utils.ts +3 -0
- package/templates/base/packages/stylus/tsconfig.json +41 -0
- package/templates/base/packages/stylus/your-contract/.cargo/config.toml +18 -0
- package/templates/base/packages/stylus/your-contract/Cargo.lock +5761 -0
- package/templates/base/packages/stylus/your-contract/Cargo.toml +48 -0
- package/templates/base/packages/stylus/your-contract/examples/counter.rs +78 -0
- package/templates/base/packages/stylus/your-contract/header.png +0 -0
- package/templates/base/packages/stylus/your-contract/licenses/Apache-2.0 +201 -0
- package/templates/base/packages/stylus/your-contract/licenses/COPYRIGHT.md +5 -0
- package/templates/base/packages/stylus/your-contract/licenses/DCO.txt +34 -0
- package/templates/base/packages/stylus/your-contract/licenses/MIT +21 -0
- package/templates/base/packages/stylus/your-contract/rust-toolchain.toml +2 -0
- package/templates/base/packages/stylus/your-contract/src/lib.rs +241 -0
- package/templates/base/packages/stylus/your-contract/src/main.rs +10 -0
- package/templates/base/readme.md +352 -0
- package/templates/base/yarn.lock +17859 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** @type {import('tailwindcss').Config} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
content: ["./app/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}", "./utils/**/*.{js,ts,jsx,tsx}"],
|
|
4
|
+
plugins: [require("daisyui")],
|
|
5
|
+
darkMode: "class",
|
|
6
|
+
// DaisyUI theme colors
|
|
7
|
+
daisyui: {
|
|
8
|
+
themes: [
|
|
9
|
+
{
|
|
10
|
+
light: {
|
|
11
|
+
primary: "#93BBFB",
|
|
12
|
+
"primary-content": "#212638",
|
|
13
|
+
secondary: "#DAE8FF",
|
|
14
|
+
"secondary-content": "#212638",
|
|
15
|
+
accent: "#93BBFB",
|
|
16
|
+
"accent-content": "#212638",
|
|
17
|
+
neutral: "#212638",
|
|
18
|
+
"neutral-content": "#ffffff",
|
|
19
|
+
"base-100": "#ffffff",
|
|
20
|
+
"base-200": "#f4f8ff",
|
|
21
|
+
"base-300": "#DAE8FF",
|
|
22
|
+
"base-content": "#212638",
|
|
23
|
+
info: "#93BBFB",
|
|
24
|
+
success: "#34EEB6",
|
|
25
|
+
warning: "#FFCF72",
|
|
26
|
+
error: "#FF8863",
|
|
27
|
+
|
|
28
|
+
"--bg-border": "#ffffff",
|
|
29
|
+
"--round-color": "#000",
|
|
30
|
+
"--rounded-btn": "9999rem",
|
|
31
|
+
"--gradient-start": "#3283EB",
|
|
32
|
+
"--gradient-end": "#E3066E",
|
|
33
|
+
|
|
34
|
+
".tooltip": {
|
|
35
|
+
"--tooltip-tail": "6px",
|
|
36
|
+
},
|
|
37
|
+
".link": {
|
|
38
|
+
textUnderlineOffset: "2px",
|
|
39
|
+
},
|
|
40
|
+
".link:hover": {
|
|
41
|
+
opacity: "80%",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
dark: {
|
|
47
|
+
primary: "#212638",
|
|
48
|
+
"primary-content": "#F9FBFF",
|
|
49
|
+
secondary: "#323f61",
|
|
50
|
+
"secondary-content": "#F9FBFF",
|
|
51
|
+
accent: "#4969A6",
|
|
52
|
+
"accent-content": "#F9FBFF",
|
|
53
|
+
neutral: "#F9FBFF",
|
|
54
|
+
"neutral-content": "#385183",
|
|
55
|
+
"base-100": "#000",
|
|
56
|
+
"base-200": "#2A3655",
|
|
57
|
+
"base-300": "#212638",
|
|
58
|
+
"base-content": "#F9FBFF",
|
|
59
|
+
info: "#385183",
|
|
60
|
+
success: "#34EEB6",
|
|
61
|
+
warning: "#FFCF72",
|
|
62
|
+
error: "#FF8863",
|
|
63
|
+
|
|
64
|
+
"--bg-border": "#000000",
|
|
65
|
+
"--round-color": "#E3066E",
|
|
66
|
+
"--rounded-btn": "9999rem",
|
|
67
|
+
"--gradient-start": "#3283EB",
|
|
68
|
+
"--gradient-end": "#E3066E",
|
|
69
|
+
|
|
70
|
+
".tooltip": {
|
|
71
|
+
"--tooltip-tail": "6px",
|
|
72
|
+
"--tooltip-color": "oklch(var(--p))",
|
|
73
|
+
},
|
|
74
|
+
".link": {
|
|
75
|
+
textUnderlineOffset: "2px",
|
|
76
|
+
},
|
|
77
|
+
".link:hover": {
|
|
78
|
+
opacity: "80%",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
theme: {
|
|
85
|
+
extend: {
|
|
86
|
+
fontFamily: {
|
|
87
|
+
sans: ["var(--font-dm-sans)", "system-ui", "sans-serif"],
|
|
88
|
+
},
|
|
89
|
+
boxShadow: {
|
|
90
|
+
center: "0 0 12px -2px rgb(0 0 0 / 0.05)",
|
|
91
|
+
},
|
|
92
|
+
animation: {
|
|
93
|
+
"pulse-fast": "pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"module": "esnext",
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"isolatedModules": true,
|
|
15
|
+
"jsx": "preserve",
|
|
16
|
+
"incremental": true,
|
|
17
|
+
"paths": {
|
|
18
|
+
"~~/*": ["./*"]
|
|
19
|
+
},
|
|
20
|
+
"plugins": [
|
|
21
|
+
{
|
|
22
|
+
"name": "next"
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
27
|
+
"exclude": ["node_modules"]
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "abitype";
|
|
2
|
+
import "~~/node_modules/viem/node_modules/abitype";
|
|
3
|
+
|
|
4
|
+
type AddressType = string;
|
|
5
|
+
|
|
6
|
+
declare module "abitype" {
|
|
7
|
+
export interface Register {
|
|
8
|
+
AddressType: AddressType;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module "~~/node_modules/viem/node_modules/abitype" {
|
|
13
|
+
export interface Register {
|
|
14
|
+
AddressType: AddressType;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Block, Transaction, TransactionReceipt } from "viem";
|
|
2
|
+
|
|
3
|
+
export type TransactionWithFunction = Transaction & {
|
|
4
|
+
functionName?: string;
|
|
5
|
+
functionArgs?: any[];
|
|
6
|
+
functionArgNames?: string[];
|
|
7
|
+
functionArgTypes?: string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type TransactionReceipts = {
|
|
11
|
+
[key: string]: TransactionReceipt;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type TransactionsTableProps = {
|
|
15
|
+
blocks: Block[];
|
|
16
|
+
transactionReceipts: TransactionReceipts;
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// To be used in JSON.stringify when a field might be bigint
|
|
2
|
+
|
|
3
|
+
// https://wagmi.sh/react/faq#bigint-serialization
|
|
4
|
+
export const replacer = (_key: string, value: unknown) => (typeof value === "bigint" ? value.toString() : value);
|
|
5
|
+
|
|
6
|
+
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
7
|
+
|
|
8
|
+
export const isZeroAddress = (address: string) => address === ZERO_ADDRESS;
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { getParsedError } from "./getParsedError";
|
|
2
|
+
import { AllowedChainIds } from "../scaffold-stylus/networks";
|
|
3
|
+
import { notification } from "./notification";
|
|
4
|
+
import { MutateOptions } from "@tanstack/react-query";
|
|
5
|
+
import {
|
|
6
|
+
Abi,
|
|
7
|
+
AbiParameter,
|
|
8
|
+
AbiParameterToPrimitiveType,
|
|
9
|
+
AbiParametersToPrimitiveTypes,
|
|
10
|
+
ExtractAbiEvent,
|
|
11
|
+
ExtractAbiEventNames,
|
|
12
|
+
ExtractAbiFunction,
|
|
13
|
+
} from "abitype";
|
|
14
|
+
import type { ExtractAbiFunctionNames } from "abitype";
|
|
15
|
+
import type { Simplify } from "type-fest";
|
|
16
|
+
import type { MergeDeepRecord } from "type-fest/source/merge-deep";
|
|
17
|
+
import {
|
|
18
|
+
Address,
|
|
19
|
+
Block,
|
|
20
|
+
GetEventArgs,
|
|
21
|
+
GetTransactionReceiptReturnType,
|
|
22
|
+
GetTransactionReturnType,
|
|
23
|
+
Log,
|
|
24
|
+
TransactionReceipt,
|
|
25
|
+
WriteContractErrorType,
|
|
26
|
+
} from "viem";
|
|
27
|
+
import { Config, UseReadContractParameters, UseWatchContractEventParameters, UseWriteContractParameters } from "wagmi";
|
|
28
|
+
import { WriteContractParameters, WriteContractReturnType, simulateContract } from "wagmi/actions";
|
|
29
|
+
import { WriteContractVariables } from "wagmi/query";
|
|
30
|
+
import deployedContractsData from "~~/contracts/deployedContracts";
|
|
31
|
+
import externalContractsData from "~~/contracts/externalContracts";
|
|
32
|
+
import scaffoldConfig from "~~/scaffold.config";
|
|
33
|
+
|
|
34
|
+
type AddExternalFlag<T> = {
|
|
35
|
+
[ChainId in keyof T]: {
|
|
36
|
+
[ContractName in keyof T[ChainId]]: T[ChainId][ContractName] & { external?: true };
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const deepMergeContracts = <L extends Record<PropertyKey, any>, E extends Record<PropertyKey, any>>(
|
|
41
|
+
local: L,
|
|
42
|
+
external: E,
|
|
43
|
+
) => {
|
|
44
|
+
const result: Record<PropertyKey, any> = {};
|
|
45
|
+
const allKeys = Array.from(new Set([...Object.keys(external), ...Object.keys(local)]));
|
|
46
|
+
for (const key of allKeys) {
|
|
47
|
+
if (!external[key]) {
|
|
48
|
+
result[key] = local[key];
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const amendedExternal = Object.fromEntries(
|
|
52
|
+
Object.entries(external[key] as Record<string, Record<string, unknown>>).map(([contractName, declaration]) => [
|
|
53
|
+
contractName,
|
|
54
|
+
{ ...declaration, external: true },
|
|
55
|
+
]),
|
|
56
|
+
);
|
|
57
|
+
result[key] = { ...local[key], ...amendedExternal };
|
|
58
|
+
}
|
|
59
|
+
return result as MergeDeepRecord<AddExternalFlag<L>, AddExternalFlag<E>, { arrayMergeMode: "replace" }>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const contractsData = deepMergeContracts(deployedContractsData, externalContractsData);
|
|
63
|
+
|
|
64
|
+
export type InheritedFunctions = { readonly [key: string]: string };
|
|
65
|
+
|
|
66
|
+
export type GenericContract = {
|
|
67
|
+
address: Address;
|
|
68
|
+
abi: Abi;
|
|
69
|
+
inheritedFunctions?: InheritedFunctions;
|
|
70
|
+
external?: true;
|
|
71
|
+
deployedOnBlock?: number;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type GenericContractsDeclaration = {
|
|
75
|
+
[chainId: number]: {
|
|
76
|
+
[contractName: string]: GenericContract;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const contracts = contractsData as GenericContractsDeclaration | null;
|
|
81
|
+
|
|
82
|
+
type ConfiguredChainId = (typeof scaffoldConfig)["targetNetworks"][0]["id"];
|
|
83
|
+
|
|
84
|
+
type IsContractDeclarationMissing<TYes, TNo> = typeof contractsData extends { [key in ConfiguredChainId]: any }
|
|
85
|
+
? TNo
|
|
86
|
+
: TYes;
|
|
87
|
+
|
|
88
|
+
type ContractsDeclaration = IsContractDeclarationMissing<GenericContractsDeclaration, typeof contractsData>;
|
|
89
|
+
|
|
90
|
+
type Contracts = ContractsDeclaration[ConfiguredChainId];
|
|
91
|
+
|
|
92
|
+
export type ContractName = keyof Contracts;
|
|
93
|
+
|
|
94
|
+
export type Contract<TContractName extends ContractName> = Contracts[TContractName];
|
|
95
|
+
|
|
96
|
+
type InferContractAbi<TContract> = TContract extends { abi: infer TAbi } ? TAbi : never;
|
|
97
|
+
|
|
98
|
+
export type ContractAbi<TContractName extends ContractName = ContractName> = InferContractAbi<Contract<TContractName>>;
|
|
99
|
+
|
|
100
|
+
export type AbiFunctionInputs<TAbi extends Abi, TFunctionName extends string> = ExtractAbiFunction<
|
|
101
|
+
TAbi,
|
|
102
|
+
TFunctionName
|
|
103
|
+
>["inputs"];
|
|
104
|
+
|
|
105
|
+
export type AbiFunctionArguments<TAbi extends Abi, TFunctionName extends string> = AbiParametersToPrimitiveTypes<
|
|
106
|
+
AbiFunctionInputs<TAbi, TFunctionName>
|
|
107
|
+
>;
|
|
108
|
+
|
|
109
|
+
export type AbiFunctionOutputs<TAbi extends Abi, TFunctionName extends string> = ExtractAbiFunction<
|
|
110
|
+
TAbi,
|
|
111
|
+
TFunctionName
|
|
112
|
+
>["outputs"];
|
|
113
|
+
|
|
114
|
+
export type AbiFunctionReturnType<TAbi extends Abi, TFunctionName extends string> = IsContractDeclarationMissing<
|
|
115
|
+
any,
|
|
116
|
+
AbiParametersToPrimitiveTypes<AbiFunctionOutputs<TAbi, TFunctionName>> extends readonly [any]
|
|
117
|
+
? AbiParametersToPrimitiveTypes<AbiFunctionOutputs<TAbi, TFunctionName>>[0]
|
|
118
|
+
: AbiParametersToPrimitiveTypes<AbiFunctionOutputs<TAbi, TFunctionName>>
|
|
119
|
+
>;
|
|
120
|
+
|
|
121
|
+
export type AbiEventInputs<TAbi extends Abi, TEventName extends ExtractAbiEventNames<TAbi>> = ExtractAbiEvent<
|
|
122
|
+
TAbi,
|
|
123
|
+
TEventName
|
|
124
|
+
>["inputs"];
|
|
125
|
+
|
|
126
|
+
export enum ContractCodeStatus {
|
|
127
|
+
"LOADING",
|
|
128
|
+
"DEPLOYED",
|
|
129
|
+
"NOT_FOUND",
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
type AbiStateMutability = "pure" | "view" | "nonpayable" | "payable";
|
|
133
|
+
export type ReadAbiStateMutability = "view" | "pure";
|
|
134
|
+
export type WriteAbiStateMutability = "nonpayable" | "payable";
|
|
135
|
+
|
|
136
|
+
export type FunctionNamesWithInputs<
|
|
137
|
+
TContractName extends ContractName,
|
|
138
|
+
TAbiStateMutability extends AbiStateMutability = AbiStateMutability,
|
|
139
|
+
> = Exclude<
|
|
140
|
+
Extract<
|
|
141
|
+
ContractAbi<TContractName>[number],
|
|
142
|
+
{
|
|
143
|
+
type: "function";
|
|
144
|
+
stateMutability: TAbiStateMutability;
|
|
145
|
+
}
|
|
146
|
+
>,
|
|
147
|
+
{
|
|
148
|
+
inputs: readonly [];
|
|
149
|
+
}
|
|
150
|
+
>["name"];
|
|
151
|
+
|
|
152
|
+
type Expand<T> = T extends object ? (T extends infer O ? { [K in keyof O]: O[K] } : never) : T;
|
|
153
|
+
|
|
154
|
+
type UnionToIntersection<U> = Expand<(U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never>;
|
|
155
|
+
|
|
156
|
+
type OptionalTuple<T> = T extends readonly [infer H, ...infer R] ? readonly [H | undefined, ...OptionalTuple<R>] : T;
|
|
157
|
+
|
|
158
|
+
type UseScaffoldArgsParam<
|
|
159
|
+
TContractName extends ContractName,
|
|
160
|
+
TFunctionName extends ExtractAbiFunctionNames<ContractAbi<TContractName>>,
|
|
161
|
+
> =
|
|
162
|
+
TFunctionName extends FunctionNamesWithInputs<TContractName>
|
|
163
|
+
? {
|
|
164
|
+
args: OptionalTuple<UnionToIntersection<AbiFunctionArguments<ContractAbi<TContractName>, TFunctionName>>>;
|
|
165
|
+
value?: ExtractAbiFunction<ContractAbi<TContractName>, TFunctionName>["stateMutability"] extends "payable"
|
|
166
|
+
? bigint | undefined
|
|
167
|
+
: undefined;
|
|
168
|
+
}
|
|
169
|
+
: {
|
|
170
|
+
args?: never;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export type UseDeployedContractConfig<TContractName extends ContractName> = {
|
|
174
|
+
contractName: TContractName;
|
|
175
|
+
chainId?: AllowedChainIds;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export type UseScaffoldWriteConfig<TContractName extends ContractName> = {
|
|
179
|
+
contractName: TContractName;
|
|
180
|
+
chainId?: AllowedChainIds;
|
|
181
|
+
disableSimulate?: boolean;
|
|
182
|
+
writeContractParams?: UseWriteContractParameters;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export type UseScaffoldReadConfig<
|
|
186
|
+
TContractName extends ContractName,
|
|
187
|
+
TFunctionName extends ExtractAbiFunctionNames<ContractAbi<TContractName>, ReadAbiStateMutability>,
|
|
188
|
+
> = {
|
|
189
|
+
contractName: TContractName;
|
|
190
|
+
chainId?: AllowedChainIds;
|
|
191
|
+
watch?: boolean;
|
|
192
|
+
} & IsContractDeclarationMissing<
|
|
193
|
+
Partial<UseReadContractParameters>,
|
|
194
|
+
{
|
|
195
|
+
functionName: TFunctionName;
|
|
196
|
+
} & UseScaffoldArgsParam<TContractName, TFunctionName> &
|
|
197
|
+
Omit<UseReadContractParameters, "chainId" | "abi" | "address" | "functionName" | "args">
|
|
198
|
+
>;
|
|
199
|
+
|
|
200
|
+
export type ScaffoldWriteContractVariables<
|
|
201
|
+
TContractName extends ContractName,
|
|
202
|
+
TFunctionName extends ExtractAbiFunctionNames<ContractAbi<TContractName>, WriteAbiStateMutability>,
|
|
203
|
+
> = IsContractDeclarationMissing<
|
|
204
|
+
Partial<WriteContractParameters>,
|
|
205
|
+
{
|
|
206
|
+
functionName: TFunctionName;
|
|
207
|
+
} & UseScaffoldArgsParam<TContractName, TFunctionName> &
|
|
208
|
+
Omit<WriteContractParameters, "chainId" | "abi" | "address" | "functionName" | "args">
|
|
209
|
+
>;
|
|
210
|
+
|
|
211
|
+
type WriteVariables = WriteContractVariables<Abi, string, any[], Config, number>;
|
|
212
|
+
|
|
213
|
+
export type TransactorFuncOptions = {
|
|
214
|
+
onBlockConfirmation?: (txnReceipt: TransactionReceipt) => void;
|
|
215
|
+
blockConfirmations?: number;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export type ScaffoldWriteContractOptions = MutateOptions<
|
|
219
|
+
WriteContractReturnType,
|
|
220
|
+
WriteContractErrorType,
|
|
221
|
+
WriteVariables,
|
|
222
|
+
unknown
|
|
223
|
+
> &
|
|
224
|
+
TransactorFuncOptions;
|
|
225
|
+
|
|
226
|
+
export type UseScaffoldEventConfig<
|
|
227
|
+
TContractName extends ContractName,
|
|
228
|
+
TEventName extends ExtractAbiEventNames<ContractAbi<TContractName>>,
|
|
229
|
+
TEvent extends ExtractAbiEvent<ContractAbi<TContractName>, TEventName> = ExtractAbiEvent<
|
|
230
|
+
ContractAbi<TContractName>,
|
|
231
|
+
TEventName
|
|
232
|
+
>,
|
|
233
|
+
> = {
|
|
234
|
+
contractName: TContractName;
|
|
235
|
+
eventName: TEventName;
|
|
236
|
+
chainId?: AllowedChainIds;
|
|
237
|
+
} & IsContractDeclarationMissing<
|
|
238
|
+
Omit<UseWatchContractEventParameters, "onLogs" | "address" | "abi" | "eventName"> & {
|
|
239
|
+
onLogs: (
|
|
240
|
+
logs: Simplify<
|
|
241
|
+
Omit<Log<bigint, number, any>, "args" | "eventName"> & {
|
|
242
|
+
args: Record<string, unknown>;
|
|
243
|
+
eventName: string;
|
|
244
|
+
}
|
|
245
|
+
>[],
|
|
246
|
+
) => void;
|
|
247
|
+
},
|
|
248
|
+
Omit<UseWatchContractEventParameters<ContractAbi<TContractName>>, "onLogs" | "address" | "abi" | "eventName"> & {
|
|
249
|
+
onLogs: (
|
|
250
|
+
logs: Simplify<
|
|
251
|
+
Omit<Log<bigint, number, false, TEvent, false, [TEvent], TEventName>, "args"> & {
|
|
252
|
+
args: AbiParametersToPrimitiveTypes<TEvent["inputs"]> &
|
|
253
|
+
GetEventArgs<
|
|
254
|
+
ContractAbi<TContractName>,
|
|
255
|
+
TEventName,
|
|
256
|
+
{
|
|
257
|
+
IndexedOnly: false;
|
|
258
|
+
}
|
|
259
|
+
>;
|
|
260
|
+
}
|
|
261
|
+
>[],
|
|
262
|
+
) => void;
|
|
263
|
+
}
|
|
264
|
+
>;
|
|
265
|
+
|
|
266
|
+
type IndexedEventInputs<
|
|
267
|
+
TContractName extends ContractName,
|
|
268
|
+
TEventName extends ExtractAbiEventNames<ContractAbi<TContractName>>,
|
|
269
|
+
> = Extract<AbiEventInputs<ContractAbi<TContractName>, TEventName>[number], { indexed: true }>;
|
|
270
|
+
|
|
271
|
+
export type EventFilters<
|
|
272
|
+
TContractName extends ContractName,
|
|
273
|
+
TEventName extends ExtractAbiEventNames<ContractAbi<TContractName>>,
|
|
274
|
+
> = IsContractDeclarationMissing<
|
|
275
|
+
any,
|
|
276
|
+
IndexedEventInputs<TContractName, TEventName> extends never
|
|
277
|
+
? never
|
|
278
|
+
: {
|
|
279
|
+
[Key in IsContractDeclarationMissing<
|
|
280
|
+
any,
|
|
281
|
+
IndexedEventInputs<TContractName, TEventName>["name"]
|
|
282
|
+
>]?: AbiParameterToPrimitiveType<Extract<IndexedEventInputs<TContractName, TEventName>, { name: Key }>>;
|
|
283
|
+
}
|
|
284
|
+
>;
|
|
285
|
+
|
|
286
|
+
export type UseScaffoldEventHistoryConfig<
|
|
287
|
+
TContractName extends ContractName,
|
|
288
|
+
TEventName extends ExtractAbiEventNames<ContractAbi<TContractName>>,
|
|
289
|
+
TBlockData extends boolean = false,
|
|
290
|
+
TTransactionData extends boolean = false,
|
|
291
|
+
TReceiptData extends boolean = false,
|
|
292
|
+
> = {
|
|
293
|
+
contractName: TContractName;
|
|
294
|
+
eventName: IsContractDeclarationMissing<string, TEventName>;
|
|
295
|
+
fromBlock: bigint;
|
|
296
|
+
toBlock?: bigint;
|
|
297
|
+
chainId?: AllowedChainIds;
|
|
298
|
+
filters?: EventFilters<TContractName, TEventName>;
|
|
299
|
+
blockData?: TBlockData;
|
|
300
|
+
transactionData?: TTransactionData;
|
|
301
|
+
receiptData?: TReceiptData;
|
|
302
|
+
watch?: boolean;
|
|
303
|
+
enabled?: boolean;
|
|
304
|
+
blocksBatchSize?: number;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
export type UseScaffoldEventHistoryData<
|
|
308
|
+
TContractName extends ContractName,
|
|
309
|
+
TEventName extends ExtractAbiEventNames<ContractAbi<TContractName>>,
|
|
310
|
+
TBlockData extends boolean = false,
|
|
311
|
+
TTransactionData extends boolean = false,
|
|
312
|
+
TReceiptData extends boolean = false,
|
|
313
|
+
TEvent extends ExtractAbiEvent<ContractAbi<TContractName>, TEventName> = ExtractAbiEvent<
|
|
314
|
+
ContractAbi<TContractName>,
|
|
315
|
+
TEventName
|
|
316
|
+
>,
|
|
317
|
+
> =
|
|
318
|
+
| IsContractDeclarationMissing<
|
|
319
|
+
any[],
|
|
320
|
+
{
|
|
321
|
+
args: AbiParametersToPrimitiveTypes<TEvent["inputs"]> &
|
|
322
|
+
GetEventArgs<
|
|
323
|
+
ContractAbi<TContractName>,
|
|
324
|
+
TEventName,
|
|
325
|
+
{
|
|
326
|
+
IndexedOnly: false;
|
|
327
|
+
}
|
|
328
|
+
>;
|
|
329
|
+
blockData: TBlockData extends true ? Block<bigint, true> : null;
|
|
330
|
+
receiptData: TReceiptData extends true ? GetTransactionReturnType : null;
|
|
331
|
+
transactionData: TTransactionData extends true ? GetTransactionReceiptReturnType : null;
|
|
332
|
+
} & Log<bigint, number, false, TEvent, false, [TEvent], TEventName>[]
|
|
333
|
+
>
|
|
334
|
+
| undefined;
|
|
335
|
+
|
|
336
|
+
export type AbiParameterTuple = Extract<AbiParameter, { type: "tuple" | `tuple[${string}]` }>;
|
|
337
|
+
|
|
338
|
+
export const simulateContractWriteAndNotifyError = async ({
|
|
339
|
+
wagmiConfig,
|
|
340
|
+
writeContractParams: params,
|
|
341
|
+
}: {
|
|
342
|
+
wagmiConfig: Config;
|
|
343
|
+
writeContractParams: WriteContractVariables<Abi, string, any[], Config, number>;
|
|
344
|
+
}) => {
|
|
345
|
+
try {
|
|
346
|
+
await simulateContract(wagmiConfig, params);
|
|
347
|
+
} catch (error) {
|
|
348
|
+
const parsedError = getParsedError(error);
|
|
349
|
+
notification.error(parsedError);
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useTargetNetwork } from "~~/hooks/scaffold-eth";
|
|
2
|
+
import { GenericContractsDeclaration, contracts } from "~~/utils/scaffold-eth/contract";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_ALL_CONTRACTS: GenericContractsDeclaration[number] = {};
|
|
5
|
+
|
|
6
|
+
export function useAllContracts() {
|
|
7
|
+
const { targetNetwork } = useTargetNetwork();
|
|
8
|
+
const contractsData = contracts?.[targetNetwork.id];
|
|
9
|
+
// using constant to avoid creating a new object on every call
|
|
10
|
+
return contractsData || DEFAULT_ALL_CONTRACTS;
|
|
11
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { TransactionWithFunction } from "./block";
|
|
2
|
+
import { GenericContractsDeclaration } from "./contract";
|
|
3
|
+
import { Abi, AbiFunction, decodeFunctionData, getAbiItem } from "viem";
|
|
4
|
+
import { arbitrumNitro } from "~~/utils/scaffold-stylus/chain";
|
|
5
|
+
import contractData from "~~/contracts/deployedContracts";
|
|
6
|
+
|
|
7
|
+
type ContractsInterfaces = Record<string, Abi>;
|
|
8
|
+
type TransactionType = TransactionWithFunction | null;
|
|
9
|
+
|
|
10
|
+
const deployedContracts = contractData as GenericContractsDeclaration | null;
|
|
11
|
+
const chainMetaData = deployedContracts?.[arbitrumNitro.id];
|
|
12
|
+
const interfaces = chainMetaData
|
|
13
|
+
? Object.entries(chainMetaData).reduce((finalInterfacesObj, [contractName, contract]) => {
|
|
14
|
+
finalInterfacesObj[contractName] = contract.abi;
|
|
15
|
+
return finalInterfacesObj;
|
|
16
|
+
}, {} as ContractsInterfaces)
|
|
17
|
+
: {};
|
|
18
|
+
|
|
19
|
+
export const decodeTransactionData = (tx: TransactionWithFunction) => {
|
|
20
|
+
if (tx.input.length >= 10 && !tx.input.startsWith("0x60e06040")) {
|
|
21
|
+
let foundInterface = false;
|
|
22
|
+
for (const [, contractAbi] of Object.entries(interfaces)) {
|
|
23
|
+
try {
|
|
24
|
+
const { functionName, args } = decodeFunctionData({
|
|
25
|
+
abi: contractAbi,
|
|
26
|
+
data: tx.input,
|
|
27
|
+
});
|
|
28
|
+
tx.functionName = functionName;
|
|
29
|
+
tx.functionArgs = args as any[];
|
|
30
|
+
tx.functionArgNames = getAbiItem<AbiFunction[], string>({
|
|
31
|
+
abi: contractAbi as AbiFunction[],
|
|
32
|
+
name: functionName,
|
|
33
|
+
})?.inputs?.map((input: any) => input.name);
|
|
34
|
+
tx.functionArgTypes = getAbiItem<AbiFunction[], string>({
|
|
35
|
+
abi: contractAbi as AbiFunction[],
|
|
36
|
+
name: functionName,
|
|
37
|
+
})?.inputs.map((input: any) => input.type);
|
|
38
|
+
foundInterface = true;
|
|
39
|
+
break;
|
|
40
|
+
} catch {
|
|
41
|
+
// do nothing
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!foundInterface) {
|
|
45
|
+
tx.functionName = "⚠️ Unknown";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return tx;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const getFunctionDetails = (transaction: TransactionType) => {
|
|
52
|
+
if (
|
|
53
|
+
transaction &&
|
|
54
|
+
transaction.functionName &&
|
|
55
|
+
transaction.functionArgNames &&
|
|
56
|
+
transaction.functionArgTypes &&
|
|
57
|
+
transaction.functionArgs
|
|
58
|
+
) {
|
|
59
|
+
const details = transaction.functionArgNames.map(
|
|
60
|
+
(name, i) => `${transaction.functionArgTypes?.[i] || ""} ${name} = ${transaction.functionArgs?.[i] ?? ""}`,
|
|
61
|
+
);
|
|
62
|
+
return `${transaction.functionName}(${details.join(", ")})`;
|
|
63
|
+
}
|
|
64
|
+
return "";
|
|
65
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ChainWithAttributes, getAlchemyHttpUrl } from "../scaffold-stylus/networks";
|
|
2
|
+
import { CurrencyAmount, Token } from "@uniswap/sdk-core";
|
|
3
|
+
import { Pair, Route } from "@uniswap/v2-sdk";
|
|
4
|
+
import { Address, createPublicClient, fallback, http, parseAbi } from "viem";
|
|
5
|
+
import { mainnet } from "viem/chains";
|
|
6
|
+
|
|
7
|
+
const alchemyHttpUrl = getAlchemyHttpUrl(mainnet.id);
|
|
8
|
+
const rpcFallbacks = alchemyHttpUrl ? [http(alchemyHttpUrl), http()] : [http()];
|
|
9
|
+
const publicClient = createPublicClient({
|
|
10
|
+
chain: mainnet,
|
|
11
|
+
transport: fallback(rpcFallbacks),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const ABI = parseAbi([
|
|
15
|
+
"function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)",
|
|
16
|
+
"function token0() external view returns (address)",
|
|
17
|
+
"function token1() external view returns (address)",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export const fetchPriceFromUniswap = async (targetNetwork: ChainWithAttributes): Promise<number> => {
|
|
21
|
+
if (
|
|
22
|
+
targetNetwork.nativeCurrency.symbol !== "ETH" &&
|
|
23
|
+
targetNetwork.nativeCurrency.symbol !== "SEP" &&
|
|
24
|
+
!targetNetwork.nativeCurrencyTokenAddress
|
|
25
|
+
) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const DAI = new Token(1, "0x6B175474E89094C44Da98b954EedeAC495271d0F", 18);
|
|
30
|
+
const TOKEN = new Token(
|
|
31
|
+
1,
|
|
32
|
+
targetNetwork.nativeCurrencyTokenAddress || "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
33
|
+
18,
|
|
34
|
+
);
|
|
35
|
+
const pairAddress = Pair.getAddress(TOKEN, DAI) as Address;
|
|
36
|
+
|
|
37
|
+
const wagmiConfig = {
|
|
38
|
+
address: pairAddress,
|
|
39
|
+
abi: ABI,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const reserves = await publicClient.readContract({
|
|
43
|
+
...wagmiConfig,
|
|
44
|
+
functionName: "getReserves",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const token0Address = await publicClient.readContract({
|
|
48
|
+
...wagmiConfig,
|
|
49
|
+
functionName: "token0",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const token1Address = await publicClient.readContract({
|
|
53
|
+
...wagmiConfig,
|
|
54
|
+
functionName: "token1",
|
|
55
|
+
});
|
|
56
|
+
const token0 = [TOKEN, DAI].find(token => token.address === token0Address) as Token;
|
|
57
|
+
const token1 = [TOKEN, DAI].find(token => token.address === token1Address) as Token;
|
|
58
|
+
const pair = new Pair(
|
|
59
|
+
CurrencyAmount.fromRawAmount(token0, reserves[0].toString()),
|
|
60
|
+
CurrencyAmount.fromRawAmount(token1, reserves[1].toString()),
|
|
61
|
+
);
|
|
62
|
+
const route = new Route([pair], TOKEN, DAI);
|
|
63
|
+
const price = parseFloat(route.midPrice.toSignificant(6));
|
|
64
|
+
return price;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(
|
|
67
|
+
`useNativeCurrencyPrice - Error fetching ${targetNetwork.nativeCurrency.symbol} price from Uniswap: `,
|
|
68
|
+
error,
|
|
69
|
+
);
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
};
|