diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index fb45991e..4b72628a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -78,7 +78,7 @@ jobs: - name: Install nightly uses: dtolnay/rust-toolchain@nightly - name: cargo doc - run: cargo doc --no-deps --all-features + run: cargo doc --workspace --no-deps --all-features env: RUSTDOCFLAGS: --cfg docsrs hack: diff --git a/.github/workflows/nostd.yml b/.github/workflows/nostd.yml index b2475e33..0366eabc 100644 --- a/.github/workflows/nostd.yml +++ b/.github/workflows/nostd.yml @@ -29,4 +29,4 @@ jobs: - name: rustup target add ${{ matrix.target }} run: rustup target add ${{ matrix.target }} - name: cargo check - run: cargo check --target ${{ matrix.target }} --no-default-features + run: cargo check --target ${{ matrix.target }} --no-default-features --workspace --all-features diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e122115d..6e6d24f9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,10 +50,10 @@ jobs: run: cargo generate-lockfile # https://twitter.com/jonhoo/status/1571290371124260865 - name: cargo test --locked - run: cargo test --locked --all-features --all-targets + run: cargo test --locked --all-features --all-targets --workspace # https://github.com/rust-lang/cargo/issues/6669 - name: cargo test --doc - run: cargo test --locked --all-features --doc + run: cargo test --locked --all-features --doc --workspace os-check: # Run cargo test on MacOS and Windows. runs-on: ${{ matrix.os }} @@ -61,7 +61,9 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-latest, windows-latest] + os: [macos-latest] + # Windows fails because of `stylus-proc`. + # os: [macos-latest, windows-latest] steps: - uses: actions/checkout@v4 with: @@ -72,7 +74,7 @@ jobs: if: hashFiles('Cargo.lock') == '' run: cargo generate-lockfile - name: cargo test - run: cargo test --locked --all-features --all-targets + run: cargo test --locked --all-features --all-targets --workspace coverage: # Use llvm-cov to build and collect coverage and outputs in a format that # is compatible with codecov.io. diff --git a/Cargo.lock b/Cargo.lock index 8591dec6..10ab889a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,31 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", -] - -[[package]] -name = "alloy-primitives" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e416903084d3392ebd32d94735c395d6709415b76c7728e594d3f996f2b03e65" -dependencies = [ - "bytes", - "cfg-if 1.0.0", - "const-hex", - "derive_more", - "hex-literal", - "itoa", - "ruint", - "tiny-keccak", -] - [[package]] name = "alloy-primitives" version = "0.6.4" @@ -34,7 +9,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "600d34d8de81e23b6d909c094e23b3d357e01ca36b78a8c5424c501eedbe86f0" dependencies = [ "bytes", - "cfg-if 1.0.0", + "cfg-if", "const-hex", "derive_more", "hex-literal", @@ -43,21 +18,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "alloy-sol-macro" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a74ceeffdacf9dd0910404d743d07273776fd17b85f9cb17b49a97e5c6055ce9" -dependencies = [ - "dunce", - "heck", - "proc-macro2", - "quote", - "syn 2.0.48", - "syn-solidity 0.3.1", - "tiny-keccak", -] - [[package]] name = "alloy-sol-macro" version = "0.6.4" @@ -72,29 +32,18 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.48", - "syn-solidity 0.6.4", + "syn-solidity", "tiny-keccak", ] -[[package]] -name = "alloy-sol-types" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f347cb6bb307b3802ec455ef43ce00f5e590e0ceca3d2f3b070f5ee367e235" -dependencies = [ - "alloy-primitives 0.3.3", - "alloy-sol-macro 0.3.1", - "const-hex", -] - [[package]] name = "alloy-sol-types" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad09ec5853fa700d12d778ad224dcdec636af424d29fad84fb9a2f16a5b0ef09" dependencies = [ - "alloy-primitives 0.6.4", - "alloy-sol-macro 0.6.4", + "alloy-primitives", + "alloy-sol-macro", "const-hex", ] @@ -110,27 +59,12 @@ version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - [[package]] name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -143,7 +77,7 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efbd12d49ab0eaf8193ba9175e45f56bbc2e4b27d57b8cfe62aa47942a46b9a9" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "hex", "proptest", @@ -156,15 +90,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "cpufeatures" version = "0.2.12" @@ -184,57 +109,26 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" name = "crypto" version = "0.1.0" dependencies = [ - "alloy-primitives 0.6.4", - "alloy-sol-types 0.6.4", + "alloy-primitives", + "alloy-sol-types", "const-hex", "rand", "thiserror", ] -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "derive_more" version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ - "convert_case 0.4.0", + "convert_case", "proc-macro2", "quote", "rustc_version", "syn 1.0.109", ] -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "dunce" version = "1.0.4" @@ -247,40 +141,13 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "erc20" -version = "0.1.0" -dependencies = [ - "alloy-primitives 0.3.3", - "alloy-sol-types 0.3.1", - "mini-alloc", - "stylus-proc", - "stylus-sdk", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi", ] @@ -325,21 +192,6 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" -[[package]] -name = "keccak" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" -dependencies = [ - "cpufeatures", -] - -[[package]] -name = "keccak-const" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d8d8ce877200136358e0bbff3a77965875db3af755a11e1fa6b1b3e2df13ea" - [[package]] name = "lazy_static" version = "1.4.0" @@ -358,28 +210,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" -[[package]] -name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "mini-alloc" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd9993556d3850cdbd0da06a3dc81297edcfa050048952d84d75e8b944e8f5af" -dependencies = [ - "cfg-if 1.0.0", - "wee_alloc", -] - [[package]] name = "num-traits" version = "0.2.18" @@ -499,29 +329,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "regex" -version = "1.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - [[package]] name = "regex-syntax" version = "0.8.2" @@ -583,53 +390,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "sha3" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" -dependencies = [ - "digest", - "keccak", -] - -[[package]] -name = "stylus-proc" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "366c3323b03fc99c7d0124cec4eee10e37a226a14b08829a416feec9f2ebb641" -dependencies = [ - "alloy-primitives 0.3.3", - "alloy-sol-types 0.3.1", - "cfg-if 1.0.0", - "convert_case 0.6.0", - "lazy_static", - "proc-macro2", - "quote", - "regex", - "sha3", - "syn 1.0.109", - "syn-solidity 0.3.1", -] - -[[package]] -name = "stylus-sdk" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74778bf11048b0155b937ee6d52440709d864aa488843238b62272e6c9bdbc1a" -dependencies = [ - "alloy-primitives 0.3.3", - "alloy-sol-types 0.3.1", - "cfg-if 1.0.0", - "derivative", - "fnv", - "hex", - "keccak-const", - "lazy_static", - "regex", - "stylus-proc", -] - [[package]] name = "syn" version = "1.0.109" @@ -652,17 +412,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn-solidity" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f995d2140b0f751dbe94365be2591edbf3d1b75dcfaeac14183abbd2ff07bd" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "syn-solidity" version = "0.6.4" @@ -704,12 +453,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - [[package]] name = "unarray" version = "0.1.4" @@ -722,12 +465,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - [[package]] name = "valuable" version = "0.1.0" @@ -746,40 +483,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "zeroize" version = "1.7.0" diff --git a/Cargo.toml b/Cargo.toml index 4103e324..5880b30f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["contracts/token/erc20", "lib/crypto"] +members = ["lib/crypto"] # Explicitly set the resolver to version 2, which is the default for packages # with edition >= 2021. diff --git a/GUIDELINES.md b/GUIDELINES.md index 3f7bc950..8f3a1aa3 100644 --- a/GUIDELINES.md +++ b/GUIDELINES.md @@ -193,7 +193,7 @@ Some other examples of automation are: Always check your code with the linter (`clippy`), by running: - $ cargo clippy --workspace --tests + $ cargo clippy --workspace --tests --all-features And make sure your code is formatted with, using: @@ -205,7 +205,7 @@ Finally, ensure there is no trailing whitespace anywhere. Make sure all tests are passing with: - $ cargo test --workspace + $ cargo test --workspace --all-features ### Checking the docs diff --git a/contracts/token/erc20/Cargo.toml b/contracts/token/erc20/Cargo.toml deleted file mode 100644 index 84584cd5..00000000 --- a/contracts/token/erc20/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "erc20" -version = "0.1.0" -edition.workspace = true -license.workspace = true -keywords.workspace = true -description = "Stylus Token Standards" - -[dependencies] -alloy-primitives = { version = "0.3.1", default-features = false } -alloy-sol-types = { version = "0.3.1", default-features = false } -mini-alloc = "0.4.2" -stylus-sdk = "0.4.3" -stylus-proc = "0.4.3" - -[features] -export-abi = ["stylus-sdk/export-abi"] - -[lib] -crate-type = ["lib", "cdylib"] diff --git a/contracts/token/erc20/src/erc20.rs b/contracts/token/erc20/src/erc20.rs deleted file mode 100644 index e9cbe4ff..00000000 --- a/contracts/token/erc20/src/erc20.rs +++ /dev/null @@ -1,200 +0,0 @@ -use alloc::{borrow::ToOwned, string::String, vec}; -use core::marker::PhantomData; - -use alloy_primitives::{Address, U256}; -use alloy_sol_types::sol; -use stylus_proc::SolidityError; -use stylus_sdk::{ - evm, msg, - stylus_proc::{external, sol_storage}, -}; - -sol! { - event Transfer(address indexed from, address indexed to, uint256 value); - event Approval(address indexed owner, address indexed spender, uint256 value); -} - -sol! { - error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); - error ERC20InvalidSender(address sender); - error ERC20InvalidReceiver(address receiver); - error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); - error ERC20InvalidApprover(address approver); - error ERC20InvalidSpender(address spender); -} - -#[derive(SolidityError)] -pub enum Erc20Error { - InsufficientBalance(ERC20InsufficientBalance), - InvalidSender(ERC20InvalidSender), - InvalidReceiver(ERC20InvalidReceiver), - InsufficientAllowance(ERC20InsufficientAllowance), - InvalidApprover(ERC20InvalidApprover), - InvalidSpender(ERC20InvalidSpender), -} - -sol_storage! { - pub struct Erc20 { - mapping(address => uint256) _balances; - mapping(address => mapping(address => uint256)) _allowances; - uint256 _total_supply; - - PhantomData metadata; - } -} - -pub trait IErc20Metadata { - const NAME: &'static str; - const SYMBOL: &'static str; - const DECIMALS: u8; -} - -#[external] -impl Erc20 -where - Metadata: IErc20Metadata, -{ - pub fn name() -> String { - Metadata::NAME.to_owned() - } - - pub fn symbol() -> String { - Metadata::SYMBOL.to_owned() - } - - pub fn decimals() -> u8 { - Metadata::DECIMALS - } - - pub fn total_supply(&self) -> U256 { - self._total_supply.get() - } - - pub fn balance_of(&self, account: Address) -> U256 { - self._balances.get(account) - } - - pub fn transfer( - &mut self, - to: Address, - value: U256, - ) -> Result { - let from = msg::sender(); - if from == Address::ZERO { - return Err(Erc20Error::InvalidSender(ERC20InvalidSender { - sender: Address::ZERO, - })); - } - if to == Address::ZERO { - return Err(Erc20Error::InvalidReceiver(ERC20InvalidReceiver { - receiver: Address::ZERO, - })); - } - - self._transfer(from, to, value)?; - Ok(true) - } - - pub fn allowance(&self, owner: Address, spender: Address) -> U256 { - self._allowances.get(owner).get(spender) - } - - pub fn approve( - &mut self, - spender: Address, - value: U256, - ) -> Result { - let owner = msg::sender(); - if owner == Address::ZERO { - return Err(Erc20Error::InvalidApprover(ERC20InvalidApprover { - approver: Address::ZERO, - })); - } - if spender == Address::ZERO { - return Err(Erc20Error::InvalidSpender(ERC20InvalidSpender { - spender: Address::ZERO, - })); - } - - self._allowances.setter(owner).insert(spender, value); - evm::log(Approval { owner, spender, value }); - Ok(true) - } - - pub fn transfer_from( - &mut self, - from: Address, - to: Address, - value: U256, - ) -> Result { - if from == Address::ZERO { - return Err(Erc20Error::InvalidSender(ERC20InvalidSender { - sender: Address::ZERO, - })); - } - if to == Address::ZERO { - return Err(Erc20Error::InvalidReceiver(ERC20InvalidReceiver { - receiver: Address::ZERO, - })); - } - - let spender = msg::sender(); - self._use_allowance(from, spender, value)?; - self._transfer(from, to, value)?; - - Ok(true) - } -} - -impl Erc20 -where - Metadata: IErc20Metadata, -{ - fn _transfer( - &mut self, - from: Address, - to: Address, - value: U256, - ) -> Result<(), Erc20Error> { - let from_balance = self._balances.get(from); - if from_balance < value { - return Err(Erc20Error::InsufficientBalance( - ERC20InsufficientBalance { - sender: from, - balance: from_balance, - needed: value, - }, - )); - } - - let from_balance = from_balance - value; - self._balances.insert(from, from_balance); - let to_balance = self._balances.get(to); - self._balances.insert(to, to_balance + value); - Ok(()) - } - - pub fn _use_allowance( - &mut self, - owner: Address, - spender: Address, - value: U256, - ) -> Result<(), Erc20Error> { - let allowed = self._allowances.get(owner).get(spender); - if allowed != U256::MAX { - if allowed < value { - return Err(Erc20Error::InsufficientAllowance( - ERC20InsufficientAllowance { - spender, - allowance: allowed, - needed: value, - }, - )); - } - - self._allowances.setter(owner).insert(spender, allowed - value); - } - - Ok(()) - } -} diff --git a/contracts/token/erc20/src/lib.rs b/contracts/token/erc20/src/lib.rs deleted file mode 100644 index 735c0900..00000000 --- a/contracts/token/erc20/src/lib.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![cfg_attr(not(feature = "export-abi"), no_std)] -extern crate alloc; - -#[cfg(target_arch = "wasm32")] -#[global_allocator] -static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT; - -mod erc20; - -use erc20::{Erc20, IErc20Metadata}; -use stylus_sdk::stylus_proc::{entrypoint, external, sol_storage}; - -struct TokenMetadata; - -pub const TOKEN_NAME: &str = "Token"; -pub const TOKEN_SYMBOL: &str = "TKN"; -pub const TOKEN_DECIMALS: u8 = 6; - -impl IErc20Metadata for TokenMetadata { - const DECIMALS: u8 = TOKEN_DECIMALS; - const NAME: &'static str = TOKEN_NAME; - const SYMBOL: &'static str = TOKEN_SYMBOL; -} - -sol_storage! { - #[entrypoint] - struct Token { - #[borrow] - Erc20 erc20; - } -} - -#[external] -#[inherit(Erc20)] -impl Token {} diff --git a/contracts/token/erc20/src/main.rs b/contracts/token/erc20/src/main.rs deleted file mode 100644 index a909e933..00000000 --- a/contracts/token/erc20/src/main.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![cfg_attr(not(feature = "export-abi"), no_main)] - -#[cfg(feature = "export-abi")] -fn main() { - erc20::main(); -}