-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/erc20-burnable
- Loading branch information
Showing
11 changed files
with
131 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
#[cfg(any(test, erc20_metadata))] | ||
pub mod metadata; | ||
//! Common extensions to the ERC-20 standard. | ||
#[cfg(any(test, erc20_burnable))] | ||
pub mod burnable; | ||
cfg_if::cfg_if! { | ||
if #[cfg(any(test, feature = "erc20_metadata"))] { | ||
pub mod metadata; | ||
pub use metadata::Metadata; | ||
} | ||
} | ||
cfg_if::cfg_if! { | ||
if #[cfg(any(test, feature = "erc20_burnable"))] { | ||
pub mod burnable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "erc20-example" | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
publish = false | ||
version = "0.0.0" | ||
|
||
[dependencies] | ||
contracts = { path = "../../contracts", features = ["erc20", "erc20_metadata"] } | ||
stylus-sdk.workspace = true | ||
stylus-proc.workspace = true | ||
mini-alloc.workspace = true | ||
|
||
[lib] | ||
crate-type = ["lib", "cdylib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![cfg_attr(not(test), no_main, no_std)] | ||
extern crate alloc; | ||
|
||
use alloc::string::String; | ||
|
||
use contracts::erc20::{extensions::Metadata, ERC20}; | ||
use stylus_sdk::prelude::{entrypoint, external, sol_storage}; | ||
|
||
const DECIMALS: u8 = 10; | ||
|
||
sol_storage! { | ||
#[entrypoint] | ||
struct Token { | ||
#[borrow] | ||
ERC20 erc20; | ||
#[borrow] | ||
Metadata metadata; | ||
} | ||
} | ||
|
||
#[external] | ||
#[inherit(ERC20, Metadata)] | ||
impl Token { | ||
pub fn constructor(&mut self, name: String, symbol: String) { | ||
self.metadata.constructor(name, symbol); | ||
} | ||
|
||
// Overrides the default [`Metadata::decimals`], and sets it to `10`. | ||
// | ||
// If you don't provide this method in the `entrypoint` contract, it will | ||
// default to `18`. | ||
pub fn decimals(&self) -> u8 { | ||
DECIMALS | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters