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.
Files changed (220) hide show
  1. package/.github/issue_template.md +7 -0
  2. package/.github/pull_request_template.md +11 -0
  3. package/.github/workflows/release-alpha.yml +32 -0
  4. package/.github/workflows/release-manual.yml +26 -0
  5. package/.yarnrc.yml +1 -0
  6. package/CONTRIBUTING.md +42 -0
  7. package/README.md +66 -0
  8. package/bin/create-dapp-ss.js +4 -0
  9. package/package.json +46 -0
  10. package/rollup.config.js +22 -0
  11. package/src/cli.ts +14 -0
  12. package/src/extensions.json +14 -0
  13. package/src/main.ts +72 -0
  14. package/src/tasks/copy-extension-file.ts +227 -0
  15. package/src/tasks/copy-template-files.ts +252 -0
  16. package/src/tasks/create-first-git-commit.ts +35 -0
  17. package/src/tasks/create-project-directory.ts +34 -0
  18. package/src/tasks/index.ts +5 -0
  19. package/src/tasks/install-packages.ts +15 -0
  20. package/src/tasks/prettier-format.ts +17 -0
  21. package/src/types.ts +31 -0
  22. package/src/utils/consts.ts +1 -0
  23. package/src/utils/find-files-recursively.ts +19 -0
  24. package/src/utils/link.ts +44 -0
  25. package/src/utils/load-extensions.ts +10 -0
  26. package/src/utils/merge-package-json.ts +33 -0
  27. package/src/utils/parse-arguments-into-options.ts +38 -0
  28. package/src/utils/prompt-for-missing-options.ts +53 -0
  29. package/src/utils/render-intro-message.ts +11 -0
  30. package/src/utils/render-outro-message.ts +34 -0
  31. package/templates/base/.github/ISSUE_TEMPLATE/bug_report.yml +58 -0
  32. package/templates/base/.github/ISSUE_TEMPLATE/config.yml +8 -0
  33. package/templates/base/.github/pull_request_template.md +16 -0
  34. package/templates/base/.github/workflows/lint.yaml +300 -0
  35. package/templates/base/.gitignore.template.mjs +19 -0
  36. package/templates/base/.gitmodules +0 -0
  37. package/templates/base/.husky/pre-commit +4 -0
  38. package/templates/base/.lintstagedrc.js +21 -0
  39. package/templates/base/.vscode/settings.json +7 -0
  40. package/templates/base/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
  41. package/templates/base/.yarn/releases/yarn-3.2.3.cjs +783 -0
  42. package/templates/base/.yarnrc.yml +11 -0
  43. package/templates/base/CONTRIBUTING.md +86 -0
  44. package/templates/base/LICENCE +21 -0
  45. package/templates/base/dist/cli.js +683 -0
  46. package/templates/base/dist/cli.js.map +1 -0
  47. package/templates/base/nitro-devnode/LICENSE +201 -0
  48. package/templates/base/nitro-devnode/README.md +70 -0
  49. package/templates/base/nitro-devnode/run-dev-node.sh +132 -0
  50. package/templates/base/nitro-devnode/start-chain-with-cors.sh +150 -0
  51. package/templates/base/nitro-devnode/stylus-deployer-bytecode.txt +1 -0
  52. package/templates/base/nitro-devnode/stylus-dev/Dockerfile +10 -0
  53. package/templates/base/package.json +44 -0
  54. package/templates/base/packages/nextjs/.env.example +13 -0
  55. package/templates/base/packages/nextjs/.eslintignore +11 -0
  56. package/templates/base/packages/nextjs/.eslintrc.json +15 -0
  57. package/templates/base/packages/nextjs/.gitignore.template.mjs +42 -0
  58. package/templates/base/packages/nextjs/.prettierrc.js +9 -0
  59. package/templates/base/packages/nextjs/.prettierrc.json +8 -0
  60. package/templates/base/packages/nextjs/app/blockexplorer/_components/AddressCodeTab.tsx +27 -0
  61. package/templates/base/packages/nextjs/app/blockexplorer/_components/AddressComponent.tsx +36 -0
  62. package/templates/base/packages/nextjs/app/blockexplorer/_components/AddressLogsTab.tsx +21 -0
  63. package/templates/base/packages/nextjs/app/blockexplorer/_components/AddressStorageTab.tsx +61 -0
  64. package/templates/base/packages/nextjs/app/blockexplorer/_components/BackButton.tsx +12 -0
  65. package/templates/base/packages/nextjs/app/blockexplorer/_components/ContractTabs.tsx +102 -0
  66. package/templates/base/packages/nextjs/app/blockexplorer/_components/PaginationButton.tsx +39 -0
  67. package/templates/base/packages/nextjs/app/blockexplorer/_components/SearchBar.tsx +49 -0
  68. package/templates/base/packages/nextjs/app/blockexplorer/_components/TransactionHash.tsx +28 -0
  69. package/templates/base/packages/nextjs/app/blockexplorer/_components/TransactionsTable.tsx +71 -0
  70. package/templates/base/packages/nextjs/app/blockexplorer/_components/index.tsx +7 -0
  71. package/templates/base/packages/nextjs/app/blockexplorer/address/[address]/page.tsx +101 -0
  72. package/templates/base/packages/nextjs/app/blockexplorer/layout.tsx +12 -0
  73. package/templates/base/packages/nextjs/app/blockexplorer/page.tsx +83 -0
  74. package/templates/base/packages/nextjs/app/blockexplorer/transaction/[txHash]/page.tsx +23 -0
  75. package/templates/base/packages/nextjs/app/blockexplorer/transaction/_components/TransactionComp.tsx +152 -0
  76. package/templates/base/packages/nextjs/app/debug/_components/DebugContracts.tsx +73 -0
  77. package/templates/base/packages/nextjs/app/debug/_components/contract/ContractInput.tsx +84 -0
  78. package/templates/base/packages/nextjs/app/debug/_components/contract/ContractReadMethods.tsx +43 -0
  79. package/templates/base/packages/nextjs/app/debug/_components/contract/ContractUI.tsx +164 -0
  80. package/templates/base/packages/nextjs/app/debug/_components/contract/ContractVariables.tsx +50 -0
  81. package/templates/base/packages/nextjs/app/debug/_components/contract/ContractWriteMethods.tsx +49 -0
  82. package/templates/base/packages/nextjs/app/debug/_components/contract/DisplayVariable.tsx +85 -0
  83. package/templates/base/packages/nextjs/app/debug/_components/contract/InheritanceTooltip.tsx +14 -0
  84. package/templates/base/packages/nextjs/app/debug/_components/contract/ReadOnlyFunctionForm.tsx +102 -0
  85. package/templates/base/packages/nextjs/app/debug/_components/contract/Tuple.tsx +44 -0
  86. package/templates/base/packages/nextjs/app/debug/_components/contract/TupleArray.tsx +142 -0
  87. package/templates/base/packages/nextjs/app/debug/_components/contract/TxReceipt.tsx +42 -0
  88. package/templates/base/packages/nextjs/app/debug/_components/contract/WriteOnlyFunctionForm.tsx +144 -0
  89. package/templates/base/packages/nextjs/app/debug/_components/contract/index.tsx +8 -0
  90. package/templates/base/packages/nextjs/app/debug/_components/contract/utilsContract.tsx +166 -0
  91. package/templates/base/packages/nextjs/app/debug/_components/contract/utilsDisplay.tsx +114 -0
  92. package/templates/base/packages/nextjs/app/debug/page.tsx +14 -0
  93. package/templates/base/packages/nextjs/app/layout.tsx +67 -0
  94. package/templates/base/packages/nextjs/app/not-found.tsx +16 -0
  95. package/templates/base/packages/nextjs/app/page.tsx +94 -0
  96. package/templates/base/packages/nextjs/components/Background.tsx +37 -0
  97. package/templates/base/packages/nextjs/components/Card.tsx +40 -0
  98. package/templates/base/packages/nextjs/components/Footer.tsx +93 -0
  99. package/templates/base/packages/nextjs/components/Header.tsx +114 -0
  100. package/templates/base/packages/nextjs/components/ScaffoldEthAppWithProviders.tsx +77 -0
  101. package/templates/base/packages/nextjs/components/SwitchTheme.tsx +41 -0
  102. package/templates/base/packages/nextjs/components/ThemeProvider.tsx +13 -0
  103. package/templates/base/packages/nextjs/components/assets/BuidlGuidlLogo.tsx +18 -0
  104. package/templates/base/packages/nextjs/components/scaffold-eth/Address/Address.tsx +187 -0
  105. package/templates/base/packages/nextjs/components/scaffold-eth/Address/AddressCopyIcon.tsx +23 -0
  106. package/templates/base/packages/nextjs/components/scaffold-eth/Address/AddressLinkWrapper.tsx +29 -0
  107. package/templates/base/packages/nextjs/components/scaffold-eth/Balance.tsx +75 -0
  108. package/templates/base/packages/nextjs/components/scaffold-eth/BlockieAvatar.tsx +17 -0
  109. package/templates/base/packages/nextjs/components/scaffold-eth/Faucet.tsx +131 -0
  110. package/templates/base/packages/nextjs/components/scaffold-eth/FaucetButton.tsx +75 -0
  111. package/templates/base/packages/nextjs/components/scaffold-eth/Input/AddressInput.tsx +120 -0
  112. package/templates/base/packages/nextjs/components/scaffold-eth/Input/Bytes32Input.tsx +31 -0
  113. package/templates/base/packages/nextjs/components/scaffold-eth/Input/BytesInput.tsx +28 -0
  114. package/templates/base/packages/nextjs/components/scaffold-eth/Input/EtherInput.tsx +128 -0
  115. package/templates/base/packages/nextjs/components/scaffold-eth/Input/InputBase.tsx +66 -0
  116. package/templates/base/packages/nextjs/components/scaffold-eth/Input/IntegerInput.tsx +63 -0
  117. package/templates/base/packages/nextjs/components/scaffold-eth/Input/index.ts +9 -0
  118. package/templates/base/packages/nextjs/components/scaffold-eth/Input/utils.ts +109 -0
  119. package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/AddressInfoDropdown.tsx +121 -0
  120. package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/AddressQRCodeModal.tsx +33 -0
  121. package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/BurnerWalletModal.tsx +63 -0
  122. package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/NetworkOptions.tsx +48 -0
  123. package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/WrongNetworkDropdown.tsx +32 -0
  124. package/templates/base/packages/nextjs/components/scaffold-eth/RainbowKitCustomConnectButton/index.tsx +89 -0
  125. package/templates/base/packages/nextjs/components/scaffold-eth/index.tsx +7 -0
  126. package/templates/base/packages/nextjs/contracts/deployedContracts.ts +9 -0
  127. package/templates/base/packages/nextjs/contracts/externalContracts.ts +16 -0
  128. package/templates/base/packages/nextjs/eslint.config.mjs +32 -0
  129. package/templates/base/packages/nextjs/hooks/scaffold-eth/index.ts +17 -0
  130. package/templates/base/packages/nextjs/hooks/scaffold-eth/useAnimationConfig.ts +20 -0
  131. package/templates/base/packages/nextjs/hooks/scaffold-eth/useContractLogs.ts +40 -0
  132. package/templates/base/packages/nextjs/hooks/scaffold-eth/useCopyToClipboard.ts +19 -0
  133. package/templates/base/packages/nextjs/hooks/scaffold-eth/useDeployedContractInfo.ts +86 -0
  134. package/templates/base/packages/nextjs/hooks/scaffold-eth/useDisplayUsdMode.ts +21 -0
  135. package/templates/base/packages/nextjs/hooks/scaffold-eth/useFetchBlocks.ts +133 -0
  136. package/templates/base/packages/nextjs/hooks/scaffold-eth/useInitializeNativeCurrencyPrice.ts +32 -0
  137. package/templates/base/packages/nextjs/hooks/scaffold-eth/useNativeCurrencyPrice.ts +34 -0
  138. package/templates/base/packages/nextjs/hooks/scaffold-eth/useNetworkColor.ts +22 -0
  139. package/templates/base/packages/nextjs/hooks/scaffold-eth/useOutsideClick.ts +23 -0
  140. package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts +65 -0
  141. package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts +213 -0
  142. package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldReadContract.ts +80 -0
  143. package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWatchContractEvent.ts +40 -0
  144. package/templates/base/packages/nextjs/hooks/scaffold-eth/useScaffoldWriteContract.ts +191 -0
  145. package/templates/base/packages/nextjs/hooks/scaffold-eth/useSelectedNetwork.ts +18 -0
  146. package/templates/base/packages/nextjs/hooks/scaffold-eth/useTargetNetwork.ts +23 -0
  147. package/templates/base/packages/nextjs/hooks/scaffold-eth/useTransactor.tsx +114 -0
  148. package/templates/base/packages/nextjs/hooks/scaffold-eth/useWatchBalance.ts +21 -0
  149. package/templates/base/packages/nextjs/icons/CompassIcon.tsx +39 -0
  150. package/templates/base/packages/nextjs/icons/DarkBugAntIcon.tsx +30 -0
  151. package/templates/base/packages/nextjs/icons/LightBugAntIcon.tsx +52 -0
  152. package/templates/base/packages/nextjs/next-env.d.ts +5 -0
  153. package/templates/base/packages/nextjs/next.config.js +19 -0
  154. package/templates/base/packages/nextjs/package.json +58 -0
  155. package/templates/base/packages/nextjs/postcss.config.js +6 -0
  156. package/templates/base/packages/nextjs/public/debug-image.png +0 -0
  157. package/templates/base/packages/nextjs/public/favicon.png +0 -0
  158. package/templates/base/packages/nextjs/public/logo.svg +8 -0
  159. package/templates/base/packages/nextjs/public/manifest.json +5 -0
  160. package/templates/base/packages/nextjs/public/thumbnail.jpg +0 -0
  161. package/templates/base/packages/nextjs/react-copy-to-clipboard.d.ts +44 -0
  162. package/templates/base/packages/nextjs/scaffold.config.ts +56 -0
  163. package/templates/base/packages/nextjs/services/store/store.ts +39 -0
  164. package/templates/base/packages/nextjs/services/web3/wagmiConfig.tsx +44 -0
  165. package/templates/base/packages/nextjs/services/web3/wagmiConnectors.tsx +51 -0
  166. package/templates/base/packages/nextjs/styles/globals.css +80 -0
  167. package/templates/base/packages/nextjs/tailwind.config.js +97 -0
  168. package/templates/base/packages/nextjs/tsconfig.json +28 -0
  169. package/templates/base/packages/nextjs/types/abitype/abi.d.ts +16 -0
  170. package/templates/base/packages/nextjs/types/utils.ts +3 -0
  171. package/templates/base/packages/nextjs/utils/scaffold-eth/block.ts +17 -0
  172. package/templates/base/packages/nextjs/utils/scaffold-eth/common.ts +8 -0
  173. package/templates/base/packages/nextjs/utils/scaffold-eth/contract.ts +352 -0
  174. package/templates/base/packages/nextjs/utils/scaffold-eth/contractsData.ts +11 -0
  175. package/templates/base/packages/nextjs/utils/scaffold-eth/decodeTxData.ts +65 -0
  176. package/templates/base/packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts +72 -0
  177. package/templates/base/packages/nextjs/utils/scaffold-eth/getMetadata.ts +50 -0
  178. package/templates/base/packages/nextjs/utils/scaffold-eth/getParsedError.ts +35 -0
  179. package/templates/base/packages/nextjs/utils/scaffold-eth/index.ts +6 -0
  180. package/templates/base/packages/nextjs/utils/scaffold-eth/notification.tsx +90 -0
  181. package/templates/base/packages/nextjs/utils/scaffold-stylus/burner.ts +59 -0
  182. package/templates/base/packages/nextjs/utils/scaffold-stylus/chain.ts +42 -0
  183. package/templates/base/packages/nextjs/utils/scaffold-stylus/index.ts +3 -0
  184. package/templates/base/packages/nextjs/utils/scaffold-stylus/networks.ts +94 -0
  185. package/templates/base/packages/nextjs/vercel.json +3 -0
  186. package/templates/base/packages/stylus/.env.example +16 -0
  187. package/templates/base/packages/stylus/.eslintrc.js +23 -0
  188. package/templates/base/packages/stylus/.gitignore.template.mjs +7 -0
  189. package/templates/base/packages/stylus/jest.config.js +15 -0
  190. package/templates/base/packages/stylus/package.json +48 -0
  191. package/templates/base/packages/stylus/scripts/deploy.ts +46 -0
  192. package/templates/base/packages/stylus/scripts/deploy_contract.ts +84 -0
  193. package/templates/base/packages/stylus/scripts/deploy_wrapper.ts +39 -0
  194. package/templates/base/packages/stylus/scripts/export_abi.ts +87 -0
  195. package/templates/base/packages/stylus/scripts/index.ts +0 -0
  196. package/templates/base/packages/stylus/scripts/new_module.sh +35 -0
  197. package/templates/base/packages/stylus/scripts/test_network.ts +31 -0
  198. package/templates/base/packages/stylus/scripts/utils/command.ts +152 -0
  199. package/templates/base/packages/stylus/scripts/utils/contract.ts +228 -0
  200. package/templates/base/packages/stylus/scripts/utils/deployment.ts +260 -0
  201. package/templates/base/packages/stylus/scripts/utils/index.ts +6 -0
  202. package/templates/base/packages/stylus/scripts/utils/network.ts +132 -0
  203. package/templates/base/packages/stylus/scripts/utils/type.ts +51 -0
  204. package/templates/base/packages/stylus/scripts/utils.ts +3 -0
  205. package/templates/base/packages/stylus/tsconfig.json +41 -0
  206. package/templates/base/packages/stylus/your-contract/.cargo/config.toml +18 -0
  207. package/templates/base/packages/stylus/your-contract/Cargo.lock +5761 -0
  208. package/templates/base/packages/stylus/your-contract/Cargo.toml +48 -0
  209. package/templates/base/packages/stylus/your-contract/examples/counter.rs +78 -0
  210. package/templates/base/packages/stylus/your-contract/header.png +0 -0
  211. package/templates/base/packages/stylus/your-contract/licenses/Apache-2.0 +201 -0
  212. package/templates/base/packages/stylus/your-contract/licenses/COPYRIGHT.md +5 -0
  213. package/templates/base/packages/stylus/your-contract/licenses/DCO.txt +34 -0
  214. package/templates/base/packages/stylus/your-contract/licenses/MIT +21 -0
  215. package/templates/base/packages/stylus/your-contract/rust-toolchain.toml +2 -0
  216. package/templates/base/packages/stylus/your-contract/src/lib.rs +241 -0
  217. package/templates/base/packages/stylus/your-contract/src/main.rs +10 -0
  218. package/templates/base/readme.md +352 -0
  219. package/templates/base/yarn.lock +17859 -0
  220. package/tsconfig.json +13 -0
@@ -0,0 +1,260 @@
1
+ import { config as dotenvConfig } from "dotenv";
2
+ import * as path from "path";
3
+ import * as fs from "fs";
4
+ import { arbitrumNitro } from "../../../nextjs/utils/scaffold-stylus/chain";
5
+ import { DeploymentConfig, DeployOptions, DeploymentData } from "./type";
6
+ import { getAccountAddress, getChain, getPrivateKey } from "./network";
7
+ import { getContractNameFromCargoToml } from "./contract";
8
+
9
+ // Load environment variables from .env file
10
+ const envPath = path.resolve(__dirname, "../../.env");
11
+ if (fs.existsSync(envPath)) {
12
+ dotenvConfig({ path: envPath });
13
+ }
14
+
15
+ export function clearDeploymentDir(): void {
16
+ const deploymentDir = process.env["DEPLOYMENT_DIR"] || "deployments";
17
+ if (fs.existsSync(deploymentDir)) {
18
+ fs.rmSync(deploymentDir, { recursive: true });
19
+ }
20
+ }
21
+
22
+ export function getDeploymentConfig(
23
+ deployOptions: DeployOptions,
24
+ ): DeploymentConfig {
25
+ // If network is specified, try to get RPC URL from viem chains
26
+ if (!deployOptions.network) deployOptions.network = "devnet";
27
+
28
+ const chain = getChain(deployOptions.network);
29
+ if (!chain) throw new Error(`Network ${deployOptions.network} not found`);
30
+
31
+ let contractName: string;
32
+ if (deployOptions.contract) {
33
+ try {
34
+ contractName =
35
+ deployOptions.name ||
36
+ getContractNameFromCargoToml(deployOptions.contract);
37
+ } catch (e) {
38
+ throw new Error(`❌ Could not read contract name from Cargo.toml: ${e}`);
39
+ }
40
+ } else {
41
+ contractName = "your-contract";
42
+ }
43
+
44
+ return {
45
+ deployerAddress: getAccountAddress(deployOptions.network),
46
+ privateKey: getPrivateKey(deployOptions.network),
47
+ contractFolder: deployOptions.contract!,
48
+ contractName,
49
+ deploymentDir: process.env["DEPLOYMENT_DIR"] || "deployments",
50
+ chain,
51
+ };
52
+ }
53
+
54
+ export function ensureDeploymentDirectory(deploymentDir: string): void {
55
+ if (!fs.existsSync(deploymentDir)) {
56
+ console.log(`📁 Creating deployment directory: ${deploymentDir}`);
57
+ fs.mkdirSync(deploymentDir, { recursive: true });
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Save the deployed contract address to <chain.id>_latest.json in the deployment directory.
63
+ * If a latest file already exists, it gets renamed to include a timestamp.
64
+ * Updates or creates the file, using contractName as the key.
65
+ */
66
+ export function saveDeployment(
67
+ config: DeploymentConfig,
68
+ deploymentInfo: DeploymentData,
69
+ ) {
70
+ try {
71
+ const chainId = config.chain?.id || arbitrumNitro.id;
72
+ const networkPath = path.resolve(
73
+ config.deploymentDir,
74
+ `${chainId}_latest.json`,
75
+ );
76
+
77
+ // Check if the latest file exists and contains the same contract name
78
+ let shouldCreateNewFile = false;
79
+ if (fs.existsSync(networkPath)) {
80
+ try {
81
+ const existingDeployments = JSON.parse(
82
+ fs.readFileSync(networkPath, "utf8"),
83
+ );
84
+ if (existingDeployments[config.contractName]) {
85
+ // Contract with same name already exists, create new file
86
+ shouldCreateNewFile = true;
87
+ }
88
+ } catch (e) {
89
+ console.warn(
90
+ `⚠️ Could not parse existing ${chainId}_latest.json, will overwrite. Error: ${e}`,
91
+ );
92
+ }
93
+ }
94
+
95
+ // If we need to create a new file (contract name already exists), backup the current latest file
96
+ if (shouldCreateNewFile) {
97
+ const currentTimestamp = new Date().getTime();
98
+ const backupPath = networkPath.replace(
99
+ "_latest.json",
100
+ `_${currentTimestamp}.json`,
101
+ );
102
+ fs.renameSync(networkPath, backupPath);
103
+ console.log(`📦 Backed up previous deployment to ${backupPath}`);
104
+ }
105
+
106
+ // Read existing deployments or start fresh
107
+ let deployments: Record<string, any> = {};
108
+ if (fs.existsSync(networkPath)) {
109
+ const content = fs.readFileSync(networkPath, "utf8");
110
+ try {
111
+ deployments = JSON.parse(content);
112
+ } catch (e) {
113
+ console.warn(
114
+ `⚠️ Could not parse existing ${chainId}_latest.json, will overwrite. Error: ${e}`,
115
+ );
116
+ }
117
+ }
118
+
119
+ // Save with the new format
120
+ deployments[config.contractName] = {
121
+ address: deploymentInfo.address,
122
+ txHash: deploymentInfo.txHash,
123
+ contract: config.contractFolder,
124
+ };
125
+
126
+ fs.writeFileSync(networkPath, JSON.stringify(deployments, null, 2));
127
+ console.log(`💾 Saved deployed contract to ${networkPath}`);
128
+ } catch (e) {
129
+ console.error(`❌ Failed to save deployed contract: ${e}`);
130
+ }
131
+ }
132
+
133
+ export function printDeployedAddresses(
134
+ deploymentDir: string,
135
+ chainId?: string,
136
+ ): void {
137
+ // If chainId is provided, only look for that specific chain's deployment file
138
+ if (chainId) {
139
+ const networkPath = path.resolve(deploymentDir, `${chainId}_latest.json`);
140
+ if (!fs.existsSync(networkPath)) {
141
+ console.log(
142
+ `📦 No deployment file found for chain ${chainId} in ${deploymentDir}`,
143
+ );
144
+ return;
145
+ }
146
+
147
+ try {
148
+ const deployments = JSON.parse(fs.readFileSync(networkPath, "utf8"));
149
+ console.log(
150
+ `📦 Deployed contracts for chain ${chainId} (${networkPath}):`,
151
+ );
152
+
153
+ // Format the output to show contract name, address, and contract folder clearly
154
+ Object.entries(deployments).forEach(([contractName, contractData]) => {
155
+ const data = contractData as {
156
+ address: string;
157
+ txHash: string;
158
+ contract: string;
159
+ };
160
+ console.log(` ${contractName}:`);
161
+ console.log(` Address: ${data.address}`);
162
+ console.log(` Tx Hash: ${data.txHash}`);
163
+ console.log(` Contract: ${data.contract}`);
164
+ });
165
+ } catch (e) {
166
+ console.warn(`⚠️ Could not parse deployment file ${networkPath}: ${e}`);
167
+ }
168
+ return;
169
+ }
170
+
171
+ // If no chainId provided, look for all chain-specific deployment files
172
+ const files = fs.readdirSync(deploymentDir);
173
+ const deploymentFiles = files.filter((file) => file.endsWith("_latest.json"));
174
+
175
+ if (deploymentFiles.length === 0) {
176
+ console.log(`📦 No deployment files found in ${deploymentDir}`);
177
+ return;
178
+ }
179
+
180
+ deploymentFiles.forEach((file) => {
181
+ const filePath = path.resolve(deploymentDir, file);
182
+ const currentChainId = file.replace("_latest.json", "");
183
+
184
+ try {
185
+ const deployments = JSON.parse(fs.readFileSync(filePath, "utf8"));
186
+ console.log(
187
+ `📦 Deployed contracts for chain ${currentChainId} (${filePath}):`,
188
+ );
189
+
190
+ // Format the output to show contract name, address, and contract folder clearly
191
+ Object.entries(deployments).forEach(([contractName, contractData]) => {
192
+ const data = contractData as {
193
+ address: string;
194
+ txHash: string;
195
+ contract: string;
196
+ };
197
+ console.log(` ${contractName}:`);
198
+ console.log(` Address: ${data.address}`);
199
+ console.log(` Contract: ${data.contract}`);
200
+ });
201
+ } catch (e) {
202
+ console.warn(`⚠️ Could not parse deployment file ${filePath}: ${e}`);
203
+ }
204
+ });
205
+ }
206
+
207
+ /**
208
+ * Reads the deployed contract data from chain-specific deployment files in the deployment directory.
209
+ * Returns an object with address and chainId for the given contractName, or undefined if not found.
210
+ */
211
+ export function getContractDataFromDeployments(
212
+ deploymentDir: string,
213
+ contractName: string,
214
+ chainId?: string,
215
+ ): { address: string; txHash: string; chainId: string } | undefined {
216
+ // If chainId is provided, look for that specific chain's deployment file
217
+ if (chainId) {
218
+ const networkPath = path.resolve(deploymentDir, `${chainId}_latest.json`);
219
+ if (fs.existsSync(networkPath)) {
220
+ try {
221
+ const deployments = JSON.parse(fs.readFileSync(networkPath, "utf8"));
222
+ if (deployments[contractName]?.address) {
223
+ return {
224
+ address: deployments[contractName].address,
225
+ txHash: deployments[contractName].txHash,
226
+ chainId: chainId,
227
+ };
228
+ }
229
+ } catch (e) {
230
+ console.warn(
231
+ `⚠️ Could not parse deployment file at ${networkPath}: ${e}`,
232
+ );
233
+ }
234
+ }
235
+ return undefined;
236
+ }
237
+
238
+ // If no chainId provided, search all deployment files
239
+ const files = fs.readdirSync(deploymentDir);
240
+ const deploymentFiles = files.filter((file) => file.endsWith("_latest.json"));
241
+
242
+ for (const file of deploymentFiles) {
243
+ const filePath = path.resolve(deploymentDir, file);
244
+ const currentChainId = file.replace("_latest.json", "");
245
+ try {
246
+ const deployments = JSON.parse(fs.readFileSync(filePath, "utf8"));
247
+ if (deployments[contractName]?.address) {
248
+ return {
249
+ address: deployments[contractName].address,
250
+ txHash: deployments[contractName].txHash,
251
+ chainId: currentChainId,
252
+ };
253
+ }
254
+ } catch (e) {
255
+ console.warn(`⚠️ Could not parse deployment file at ${filePath}: ${e}`);
256
+ }
257
+ }
258
+
259
+ return undefined;
260
+ }
@@ -0,0 +1,6 @@
1
+ // Re-export all utilities from their respective modules for backward compatibility
2
+ export * from "./deployment";
3
+ export * from "./network";
4
+ export * from "./contract";
5
+ export * from "./command";
6
+ export * from "./type";
@@ -0,0 +1,132 @@
1
+ import { arbitrum, arbitrumSepolia } from "viem/chains";
2
+ import { Address, Chain } from "viem";
3
+ import { arbitrumNitro } from "../../../nextjs/utils/scaffold-stylus/chain";
4
+ import * as path from "path";
5
+ import * as fs from "fs";
6
+ import { config as dotenvConfig } from "dotenv";
7
+ import { SupportedNetworkMinimal } from "./type";
8
+
9
+ const envPath = path.resolve(__dirname, "../../.env");
10
+ if (fs.existsSync(envPath)) {
11
+ dotenvConfig({ path: envPath });
12
+ }
13
+
14
+ export const SUPPORTED_NETWORKS: Record<string, Chain> = {
15
+ arbitrum,
16
+ arbitrumSepolia,
17
+ arbitrumNitro: arbitrumNitro as Chain,
18
+ };
19
+
20
+ export const ALIASES: Record<string, string> = {
21
+ mainnet: "arbitrum",
22
+ sepolia: "arbitrumSepolia",
23
+ devnet: "arbitrumNitro",
24
+ };
25
+
26
+ export function getChain(networkName: string): SupportedNetworkMinimal | null {
27
+ try {
28
+ const actualNetworkName = ALIASES[networkName.toLowerCase()] || networkName;
29
+
30
+ const chainEntry = Object.entries(SUPPORTED_NETWORKS).find(
31
+ ([key]) => key.toLowerCase() === actualNetworkName.toLowerCase(),
32
+ );
33
+
34
+ if (chainEntry) {
35
+ return {
36
+ name: chainEntry[0],
37
+ alias: getAliasFromNetworkName(chainEntry[0]),
38
+ id: chainEntry[1].id.toString(),
39
+ rpcUrl: getRpcUrlFromChain(chainEntry[1]),
40
+ };
41
+ }
42
+
43
+ const supportedNetworks = Object.keys(SUPPORTED_NETWORKS);
44
+ console.warn(
45
+ `⚠️ Network '${networkName}' is not supported. Supported networks: ${supportedNetworks.join(", ")}`,
46
+ );
47
+ return null;
48
+ } catch (error) {
49
+ console.error(`Error getting chain for network ${networkName}:`, error);
50
+ return null;
51
+ }
52
+ }
53
+
54
+ export function getPrivateKey(networkName: string): string {
55
+ const actualNetworkName = ALIASES[networkName.toLowerCase()] || networkName;
56
+
57
+ switch (actualNetworkName.toLowerCase()) {
58
+ case "arbitrum":
59
+ if (process.env["PRIVATE_KEY_MAINNET"]) {
60
+ return process.env["PRIVATE_KEY_MAINNET"];
61
+ } else {
62
+ throw new Error("PRIVATE_KEY_MAINNET is not set");
63
+ }
64
+ case "arbitrumsepolia":
65
+ if (process.env["PRIVATE_KEY_SEPOLIA"]) {
66
+ return process.env["PRIVATE_KEY_SEPOLIA"];
67
+ } else {
68
+ throw new Error("PRIVATE_KEY_SEPOLIA is not set");
69
+ }
70
+ default:
71
+ return (
72
+ process.env["PRIVATE_KEY"] ||
73
+ "0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659"
74
+ );
75
+ }
76
+ }
77
+
78
+ export const getAccountAddress = (networkName: string): Address | undefined => {
79
+ const actualNetworkName = ALIASES[networkName.toLowerCase()] || networkName;
80
+ switch (actualNetworkName.toLowerCase()) {
81
+ case "arbitrum":
82
+ return process.env["ACCOUNT_ADDRESS_MAINNET"] as Address;
83
+ case "arbitrumsepolia":
84
+ return process.env["ACCOUNT_ADDRESS_SEPOLIA"] as Address;
85
+ default:
86
+ return (
87
+ (process.env["ACCOUNT_ADDRESS"] as Address) ||
88
+ "0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E"
89
+ );
90
+ }
91
+ };
92
+
93
+ function getRpcUrlFromChain(chain: Chain): string {
94
+ //Prefer user rpc url from env
95
+ switch (chain.id) {
96
+ case arbitrum.id:
97
+ if (process.env["RPC_URL_MAINNET"]) {
98
+ return process.env["RPC_URL_MAINNET"];
99
+ }
100
+ break;
101
+ case arbitrumSepolia.id:
102
+ if (process.env["RPC_URL_SEPOLIA"]) {
103
+ return process.env["RPC_URL_SEPOLIA"];
104
+ }
105
+ break;
106
+ default:
107
+ if (process.env["RPC_URL"]) {
108
+ return process.env["RPC_URL"];
109
+ }
110
+ }
111
+
112
+ if (chain.rpcUrls?.default?.http && chain.rpcUrls.default.http.length > 0) {
113
+ return chain.rpcUrls.default.http[0]!;
114
+ }
115
+
116
+ if (
117
+ "public" in chain.rpcUrls &&
118
+ chain.rpcUrls.public?.http &&
119
+ chain.rpcUrls.public.http.length > 0
120
+ ) {
121
+ return chain.rpcUrls.public.http[0]!;
122
+ }
123
+
124
+ throw new Error(`No RPC URL found for chain ${chain.name}`);
125
+ }
126
+
127
+ function getAliasFromNetworkName(networkName: string): string {
128
+ return (
129
+ Object.entries(ALIASES).find(([, alias]) => alias === networkName)?.[0] ||
130
+ networkName
131
+ );
132
+ }
@@ -0,0 +1,51 @@
1
+ import { Address } from "viem";
2
+
3
+ interface BaseCommandOptions {
4
+ _: (string | number)[];
5
+ $0: string;
6
+ [x: string]: unknown;
7
+ }
8
+
9
+ export interface DeployCommandOptions
10
+ extends BaseCommandOptions,
11
+ DeployOptions {}
12
+
13
+ export interface DeployOptions {
14
+ contract?: string;
15
+ name?: string;
16
+ constructorArgs?: string[];
17
+ network?: string;
18
+ estimateGas?: boolean;
19
+ maxFee?: string;
20
+ verify?: boolean;
21
+ }
22
+
23
+ export interface DeploymentData {
24
+ address: Address;
25
+ txHash: string;
26
+ }
27
+
28
+ export interface DeploymentConfig {
29
+ deployerAddress: Address | undefined;
30
+ privateKey: string;
31
+ contractFolder: string;
32
+ contractName: string;
33
+ deploymentDir: string;
34
+ chain?: SupportedNetworkMinimal;
35
+ }
36
+
37
+ export interface ExportConfig {
38
+ contractFolder: string;
39
+ contractName: string;
40
+ deploymentDir: string;
41
+ contractAddress: Address;
42
+ txHash: string;
43
+ chainId: string;
44
+ }
45
+
46
+ export interface SupportedNetworkMinimal {
47
+ name: string;
48
+ alias: string;
49
+ id: string;
50
+ rpcUrl: string;
51
+ }
@@ -0,0 +1,3 @@
1
+ // This file is now a re-export for backward compatibility
2
+ // All utilities have been moved to the utils/ folder for better organization
3
+ export * from "./utils";
@@ -0,0 +1,41 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "commonjs",
5
+ "lib": ["ES2022"],
6
+ "types": ["node"],
7
+ "outDir": "./dist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "removeComments": false,
16
+ "noImplicitAny": true,
17
+ "noImplicitReturns": true,
18
+ "noImplicitThis": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "exactOptionalPropertyTypes": true,
22
+ "noImplicitOverride": true,
23
+ "noPropertyAccessFromIndexSignature": true,
24
+ "noUncheckedIndexedAccess": true,
25
+ "resolveJsonModule": true,
26
+ "allowSyntheticDefaultImports": true,
27
+ "baseUrl": "./",
28
+ "paths": {
29
+ "@/*": ["scripts/*"]
30
+ }
31
+ },
32
+ "include": [
33
+ "scripts/**/*"
34
+ ],
35
+ "exclude": [
36
+ "node_modules",
37
+ "dist",
38
+ "**/*.test.ts",
39
+ "**/*.spec.ts"
40
+ ]
41
+ }
@@ -0,0 +1,18 @@
1
+ [target.wasm32-unknown-unknown]
2
+ rustflags = [
3
+ "-C", "link-arg=-zstack-size=32768",
4
+ "-C", "target-feature=-reference-types",
5
+ "-C", "target-feature=+bulk-memory",
6
+ ]
7
+
8
+ [target.aarch64-apple-darwin]
9
+ rustflags = [
10
+ "-C", "link-arg=-undefined",
11
+ "-C", "link-arg=dynamic_lookup",
12
+ ]
13
+
14
+ [target.x86_64-apple-darwin]
15
+ rustflags = [
16
+ "-C", "link-arg=-undefined",
17
+ "-C", "link-arg=dynamic_lookup",
18
+ ]