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,48 @@
1
+ [package]
2
+ name = "your-contract"
3
+ version = "0.1.11"
4
+ edition = "2021"
5
+ license = "MIT OR Apache-2.0"
6
+ homepage = "https://github.com/OffchainLabs/stylus-hello-world"
7
+ repository = "https://github.com/OffchainLabs/stylus-hello-world"
8
+ keywords = ["arbitrum", "ethereum", "stylus", "alloy"]
9
+ description = "Stylus hello world example"
10
+
11
+ [dependencies]
12
+ alloy-primitives = "=0.8.20"
13
+ alloy-sol-types = "=0.8.20"
14
+ stylus-sdk = "0.9.0"
15
+ hex = { version = "0.4", default-features = false }
16
+ openzeppelin-stylus = "0.2.0"
17
+
18
+ [dev-dependencies]
19
+ alloy-primitives = { version = "=0.8.20", features = ["sha3-keccak"] }
20
+ tokio = { version = "1.12.0", features = ["full"] }
21
+ ethers = "2.0"
22
+ eyre = "0.6.8"
23
+ stylus-sdk = { version = "0.9.0", features = ["stylus-test"] }
24
+ dotenv = "0.15.0"
25
+
26
+ [features]
27
+ default = ["mini-alloc"]
28
+ # stylus-sdk/export-abi will be enabled automatically.
29
+ export-abi = ["openzeppelin-stylus/export-abi"]
30
+ debug = ["stylus-sdk/debug"]
31
+ mini-alloc = ["stylus-sdk/mini-alloc"]
32
+
33
+ [[bin]]
34
+ name = "your-contract"
35
+ path = "src/main.rs"
36
+
37
+ [lib]
38
+ crate-type = ["lib", "cdylib"]
39
+
40
+ [profile.release]
41
+ codegen-units = 1
42
+ strip = true
43
+ lto = true
44
+ panic = "abort"
45
+
46
+ # If you need to reduce the binary size, it is advisable to try other
47
+ # optimization levels, such as "s" and "z"
48
+ opt-level = 3
@@ -0,0 +1,78 @@
1
+ //! Example on how to interact with a deployed `stylus-hello-world` contract using defaults.
2
+ //! This example uses ethers-rs to instantiate the contract using a Solidity ABI.
3
+ //! Then, it attempts to check the current counter value, increment it via a tx,
4
+ //! and check the value again. The deployed contract is fully written in Rust and compiled to WASM
5
+ //! but with Stylus, it is accessible just as a normal Solidity smart contract is via an ABI.
6
+
7
+ use dotenv::dotenv;
8
+ use ethers::{
9
+ middleware::SignerMiddleware,
10
+ prelude::abigen,
11
+ providers::{Http, Middleware, Provider},
12
+ signers::{LocalWallet, Signer},
13
+ types::Address,
14
+ };
15
+ use eyre::eyre;
16
+ use std::io::{BufRead, BufReader};
17
+ use std::str::FromStr;
18
+ use std::sync::Arc;
19
+
20
+ /// Your private key file path.
21
+ const PRIV_KEY_PATH: &str = "PRIV_KEY_PATH";
22
+
23
+ /// Stylus RPC endpoint url.
24
+ const RPC_URL: &str = "RPC_URL";
25
+
26
+ /// Deployed pragram address.
27
+ const STYLUS_CONTRACT_ADDRESS: &str = "STYLUS_CONTRACT_ADDRESS";
28
+
29
+ #[tokio::main]
30
+ async fn main() -> eyre::Result<()> {
31
+ dotenv().ok();
32
+ let priv_key_path =
33
+ std::env::var(PRIV_KEY_PATH).map_err(|_| eyre!("No {} env var set", PRIV_KEY_PATH))?;
34
+ let rpc_url = std::env::var(RPC_URL).map_err(|_| eyre!("No {} env var set", RPC_URL))?;
35
+ let contract_address = std::env::var(STYLUS_CONTRACT_ADDRESS)
36
+ .map_err(|_| eyre!("No {} env var set", STYLUS_CONTRACT_ADDRESS))?;
37
+ abigen!(
38
+ Counter,
39
+ r#"[
40
+ function number() external view returns (uint256)
41
+ function setNumber(uint256 number) external
42
+ function increment() external
43
+ ]"#
44
+ );
45
+
46
+ let provider = Provider::<Http>::try_from(rpc_url)?;
47
+ let address: Address = contract_address.parse()?;
48
+
49
+ let privkey = read_secret_from_file(&priv_key_path)?;
50
+ let wallet = LocalWallet::from_str(&privkey)?;
51
+ let chain_id = provider.get_chainid().await?.as_u64();
52
+ let client = Arc::new(SignerMiddleware::new(
53
+ provider,
54
+ wallet.clone().with_chain_id(chain_id),
55
+ ));
56
+
57
+ let counter = Counter::new(address, client);
58
+ let num = counter.number().call().await;
59
+ println!("Counter number value = {:?}", num);
60
+
61
+ let pending = counter.increment();
62
+ if let Some(receipt) = pending.send().await?.await? {
63
+ println!("Receipt = {:?}", receipt);
64
+ }
65
+ println!("Successfully incremented counter via a tx");
66
+
67
+ let num = counter.number().call().await;
68
+ println!("New counter number value = {:?}", num);
69
+ Ok(())
70
+ }
71
+
72
+ fn read_secret_from_file(fpath: &str) -> eyre::Result<String> {
73
+ let f = std::fs::File::open(fpath)?;
74
+ let mut buf_reader = BufReader::new(f);
75
+ let mut secret = String::new();
76
+ buf_reader.read_line(&mut secret)?;
77
+ Ok(secret.trim().to_string())
78
+ }
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 YOUR COMPANY
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ # Licensing Information
2
+
3
+ Copyright 2023 YOUR COMPANY
4
+
5
+ Except as otherwise noted (below and/or in individual files), this project is licensed under the Apache License, Version 2.0 ([`LICENSE-APACHE`](Apache-2.0) or http://www.apache.org/licenses/LICENSE-2.0) or the MIT license, ([`LICENSE-MIT`](MIT) or http://opensource.org/licenses/MIT), at your option.
@@ -0,0 +1,34 @@
1
+ Developer Certificate of Origin
2
+ Version 1.1
3
+
4
+ Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
5
+
6
+ Everyone is permitted to copy and distribute verbatim copies of this
7
+ license document, but changing it is not allowed.
8
+
9
+
10
+ Developer's Certificate of Origin 1.1
11
+
12
+ By making a contribution to this project, I certify that:
13
+
14
+ (a) The contribution was created in whole or in part by me and I
15
+ have the right to submit it under the open source license
16
+ indicated in the file; or
17
+
18
+ (b) The contribution is based upon previous work that, to the best
19
+ of my knowledge, is covered under an appropriate open source
20
+ license and I have the right under that license to submit that
21
+ work with modifications, whether created in whole or in part
22
+ by me, under the same open source license (unless I am
23
+ permitted to submit under a different license), as indicated
24
+ in the file; or
25
+
26
+ (c) The contribution was provided directly to me by some other
27
+ person who certified (a), (b) or (c) and I have not modified
28
+ it.
29
+
30
+ (d) I understand and agree that this project and the contribution
31
+ are public and that a record of the contribution (including all
32
+ personal information I submit with it, including my sign-off) is
33
+ maintained indefinitely and may be redistributed consistent with
34
+ this project or the open source license(s) involved.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright 2023 YOUR COMPANY
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ [toolchain]
2
+ channel = "1.87.0"
@@ -0,0 +1,241 @@
1
+ //!
2
+ //! YourContract in Stylus Rust
3
+ //!
4
+ //! A smart contract that allows changing a state variable of the contract and tracking the changes
5
+ //! It also allows the owner to withdraw the Ether in the contract
6
+ //!
7
+ //! This is the Stylus Rust equivalent of the Solidity YourContract.
8
+ //!
9
+
10
+ // Allow `cargo stylus export-abi` to generate a main function.
11
+ #![cfg_attr(not(any(test, feature = "export-abi")), no_main)]
12
+ #![cfg_attr(not(any(test, feature = "export-abi")), no_std)]
13
+
14
+ #[macro_use]
15
+ extern crate alloc;
16
+
17
+ use alloc::string::String;
18
+ use alloc::vec::Vec;
19
+
20
+ /// Import items from the SDK. The prelude contains common traits and macros.
21
+ use stylus_sdk::{
22
+ alloy_primitives::{Address, U256},
23
+ prelude::*,
24
+ alloy_sol_types::sol,
25
+ stylus_core::log,
26
+ };
27
+
28
+ /// Import OpenZeppelin Ownable functionality
29
+ use openzeppelin_stylus::access::ownable::{self, Ownable, IOwnable};
30
+
31
+ /// Error types for the contract
32
+ #[derive(SolidityError, Debug)]
33
+ pub enum Error {
34
+ UnauthorizedAccount(ownable::OwnableUnauthorizedAccount),
35
+ InvalidOwner(ownable::OwnableInvalidOwner),
36
+ }
37
+
38
+ impl From<ownable::Error> for Error {
39
+ fn from(value: ownable::Error) -> Self {
40
+ match value {
41
+ ownable::Error::UnauthorizedAccount(e) => {
42
+ Error::UnauthorizedAccount(e)
43
+ }
44
+ ownable::Error::InvalidOwner(e) => Error::InvalidOwner(e),
45
+ }
46
+ }
47
+ }
48
+
49
+ // Define the GreetingChange event
50
+ sol! {
51
+ event GreetingChange(address indexed greetingSetter, string newGreeting, bool premium, uint256 value);
52
+ }
53
+
54
+ // Define persistent storage using the Solidity ABI.
55
+ // `YourContract` will be the entrypoint.
56
+ sol_storage! {
57
+ #[entrypoint]
58
+ pub struct YourContract {
59
+ Ownable ownable;
60
+ string greeting;
61
+ bool premium;
62
+ uint256 total_counter;
63
+ mapping(address => uint256) user_greeting_counter;
64
+ }
65
+ }
66
+
67
+ /// Declare that `YourContract` is a contract with the following external methods.
68
+ #[public]
69
+ #[implements(IOwnable<Error = Error>)]
70
+ impl YourContract {
71
+ #[constructor]
72
+ pub fn constructor(&mut self, initial_owner: Address) -> Result<(), Error> {
73
+ // Initialize Ownable with the initial owner using OpenZeppelin pattern
74
+ self.ownable.constructor(initial_owner)?;
75
+ self.greeting.set_str("Building Unstoppable Apps!!!");
76
+ self.premium.set(false);
77
+ self.total_counter.set(U256::ZERO);
78
+ Ok(())
79
+ }
80
+
81
+ /// Gets the current greeting
82
+ pub fn greeting(&self) -> String {
83
+ self.greeting.get_string()
84
+ }
85
+
86
+ /// Gets the premium status
87
+ pub fn premium(&self) -> bool {
88
+ self.premium.get()
89
+ }
90
+
91
+ /// Gets the total counter
92
+ pub fn total_counter(&self) -> U256 {
93
+ self.total_counter.get()
94
+ }
95
+
96
+ /// Gets the user greeting counter for a specific address
97
+ pub fn user_greeting_counter(&self, user: Address) -> U256 {
98
+ self.user_greeting_counter.get(user)
99
+ }
100
+
101
+ /// Function that allows anyone to change the state variable "greeting" of the contract and increase the counters
102
+ #[payable]
103
+ pub fn set_greeting(&mut self, new_greeting: String) {
104
+ // Change state variables
105
+ self.greeting.set_str(&new_greeting);
106
+
107
+ // Increment counters
108
+ let current_total = self.total_counter.get();
109
+ self.total_counter.set(current_total + U256::from(1));
110
+
111
+ let sender: Address = self.vm().msg_sender();
112
+ let current_user_count = self.user_greeting_counter.get(sender);
113
+ self.user_greeting_counter.insert(sender, current_user_count + U256::from(1));
114
+
115
+ // Set premium based on msg.value
116
+ let msg_value = self.vm().msg_value();
117
+ let is_premium = msg_value > U256::ZERO;
118
+ self.premium.set(is_premium);
119
+
120
+ // Emit the event
121
+ log(self.vm(),
122
+ GreetingChange {
123
+ greetingSetter: sender,
124
+ newGreeting: new_greeting,
125
+ premium: is_premium,
126
+ value: msg_value,
127
+ });
128
+ }
129
+
130
+ /// Function that allows the owner to withdraw all the Ether in the contract
131
+ /// The function can only be called by the owner of the contract
132
+ pub fn withdraw(&mut self) -> Result<(), Error> {
133
+ // Check if caller is owner using OpenZeppelin's only_owner
134
+ self.ownable.only_owner()?;
135
+
136
+ // Get contract balance and transfer to owner using transfer_eth
137
+ let balance = self.vm().balance(self.vm().contract_address());
138
+ if balance > U256::ZERO {
139
+ let owner = self.ownable.owner();
140
+ let _ = self.vm().transfer_eth(owner, balance);
141
+ }
142
+
143
+ Ok(())
144
+ }
145
+
146
+ /// Allow contract to receive ETH (equivalent to receive() function)
147
+ #[payable]
148
+ pub fn receive_ether(&self) {
149
+ // This function allows the contract to receive ETH
150
+ // The #[payable] attribute allows it to accept value
151
+ }
152
+ }
153
+
154
+ /// Implementation of the IOwnable interface
155
+ #[public]
156
+ impl IOwnable for YourContract {
157
+ type Error = Error;
158
+
159
+ fn owner(&self) -> Address {
160
+ self.ownable.owner()
161
+ }
162
+
163
+ fn transfer_ownership(
164
+ &mut self,
165
+ new_owner: Address,
166
+ ) -> Result<(), Self::Error> {
167
+ Ok(self.ownable.transfer_ownership(new_owner)?)
168
+ }
169
+
170
+ fn renounce_ownership(&mut self) -> Result<(), Self::Error> {
171
+ Ok(self.ownable.renounce_ownership()?)
172
+ }
173
+ }
174
+
175
+ // #[cfg(test)]
176
+ // mod test {
177
+ // use super::*;
178
+ // use stylus_sdk::testing::*;
179
+
180
+ // #[test]
181
+ // fn test_your_contract() {
182
+ // let vm = TestVM::default();
183
+ // let mut contract = YourContract::from(&vm);
184
+
185
+ // // Test initialization
186
+ // let owner_addr = Address::from([1u8; 20]);
187
+ // contract.init(owner_addr);
188
+
189
+ // assert_eq!(contract.owner(), owner_addr);
190
+ // assert_eq!(contract.greeting(), "Building Unstoppable Apps!!!");
191
+ // assert_eq!(contract.premium(), false);
192
+ // assert_eq!(contract.total_counter(), U256::ZERO);
193
+
194
+ // // Test setting greeting without payment
195
+ // contract.set_greeting("Hello World".to_string());
196
+ // assert_eq!(contract.greeting(), "Hello World");
197
+ // assert_eq!(contract.premium(), false);
198
+ // assert_eq!(contract.total_counter(), U256::from(1));
199
+
200
+ // // Test user greeting counter
201
+ // let sender = vm.addr();
202
+ // assert_eq!(contract.user_greeting_counter(sender), U256::from(1));
203
+
204
+ // // Test setting greeting with payment
205
+ // vm.set_value(U256::from(100));
206
+ // contract.set_greeting("Premium Hello".to_string());
207
+ // assert_eq!(contract.greeting(), "Premium Hello");
208
+ // assert_eq!(contract.premium(), true);
209
+ // assert_eq!(contract.total_counter(), U256::from(2));
210
+ // assert_eq!(contract.user_greeting_counter(sender), U256::from(2));
211
+ // }
212
+
213
+ // #[test]
214
+ // fn test_withdraw() {
215
+ // let vm = TestVM::default();
216
+ // let mut contract = YourContract::from(&vm);
217
+
218
+ // // Initialize with owner
219
+ // let owner_addr = vm.addr(); // Use VM address as owner for testing
220
+ // contract.init(owner_addr);
221
+
222
+ // // Test withdraw (in real scenario, contract would have received ETH)
223
+ // let result = contract.withdraw();
224
+ // assert!(result.is_ok()); // Should not panic since caller is owner
225
+ // }
226
+
227
+ // #[test]
228
+ // fn test_withdraw_not_owner() {
229
+ // let vm = TestVM::default();
230
+ // let mut contract = YourContract::from(&vm);
231
+
232
+ // // Initialize with different owner
233
+ // let owner_addr = Address::from([1u8; 20]);
234
+ // contract.init(owner_addr);
235
+
236
+ // // This test should panic with "Not the Owner" when withdraw is called by non-owner
237
+ // // In a real test environment, you'd want to test this more carefully
238
+ // // but for now we'll just verify the function exists
239
+ // assert_eq!(contract.owner(), owner_addr);
240
+ // }
241
+ // }
@@ -0,0 +1,10 @@
1
+ #![cfg_attr(not(any(test, feature = "export-abi")), no_main)]
2
+
3
+ #[cfg(not(any(test, feature = "export-abi")))]
4
+ #[no_mangle]
5
+ pub extern "C" fn main() {}
6
+
7
+ #[cfg(feature = "export-abi")]
8
+ fn main() {
9
+ your_contract::print_from_args();
10
+ }