-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ERC20 Example + Eliminate Solc Warnings on Exports #101
Open
rauljordan
wants to merge
6
commits into
stylus
Choose a base branch
from
update-erc20-example
base: stylus
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+145
−74
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a306eef
updates erc20 example
rauljordan f1c1534
update eol
rauljordan 0eca562
Update stylus-sdk/src/abi/export.rs
rauljordan af12121
move profile opts back to cargo toml
rauljordan 7f7df37
Merge branch 'update-erc20-example' of github.com:OffchainLabs/stylus…
rauljordan 72fbe68
newline
rauljordan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,7 +1,23 @@ | ||
[build] | ||
target = "wasm32-unknown-unknown" | ||
|
||
[target.wasm32-unknown-unknown] | ||
rustflags = [ | ||
"-C", "link-arg=-zstack-size=32768", | ||
] | ||
|
||
[target.aarch64-apple-darwin] | ||
rustflags = [ | ||
"-C", "link-arg=-undefined", | ||
"-C", "link-arg=dynamic_lookup", | ||
] | ||
|
||
[target.x86_64-apple-darwin] | ||
rustflags = [ | ||
"-C", "link-arg=-undefined", | ||
"-C", "link-arg=dynamic_lookup", | ||
] | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
strip = true | ||
lto = true | ||
panic = "abort" | ||
opt-level = "s" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#![cfg_attr(not(feature = "export-abi"), no_main, no_std)] | ||
extern crate alloc; | ||
|
||
use crate::erc20::{Erc20, Erc20Params}; | ||
use alloc::{string::String, vec::Vec}; | ||
use stylus_sdk::{alloy_primitives::U256, call, msg, prelude::*}; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
#[global_allocator] | ||
static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT; | ||
|
||
mod erc20; | ||
|
||
struct WethParams; | ||
|
||
/// Immutable definitions | ||
impl Erc20Params for WethParams { | ||
const NAME: &'static str = "Wrapped Ether Example"; | ||
const SYMBOL: &'static str = "WETH"; | ||
const DECIMALS: u8 = 18; | ||
} | ||
|
||
// The contract | ||
sol_storage! { | ||
#[entrypoint] // Makes Weth the entrypoint | ||
struct Weth { | ||
#[borrow] // Allows erc20 to access Weth's storage and make calls | ||
Erc20<WethParams> erc20; | ||
} | ||
} | ||
|
||
// Another contract we'd like to call | ||
sol_interface! { | ||
interface IMath { | ||
function sum(uint256[] values) pure returns (string, uint256); | ||
} | ||
} | ||
|
||
#[external] | ||
#[inherit(Erc20<WethParams>)] | ||
impl Weth { | ||
#[payable] | ||
pub fn deposit(&mut self) -> Result<(), Vec<u8>> { | ||
self.erc20.mint(msg::sender(), msg::value()); | ||
Ok(()) | ||
} | ||
|
||
pub fn withdraw(&mut self, amount: U256) -> Result<(), Vec<u8>> { | ||
self.erc20.burn(msg::sender(), amount)?; | ||
|
||
// send the user their funds | ||
call::transfer_eth(msg::sender(), amount) | ||
} | ||
|
||
// sums numbers | ||
pub fn sum(values: Vec<U256>) -> Result<(String, U256), Vec<u8>> { | ||
Ok(("sum".into(), values.iter().sum())) | ||
} | ||
|
||
// calls the sum() method from the interface | ||
pub fn sum_with_helper(&self, helper: IMath, values: Vec<U256>) -> Result<U256, Vec<u8>> { | ||
let (text, sum) = helper.sum(self, values)?; | ||
assert_eq!(&text, "sum"); | ||
Ok(sum) | ||
} | ||
} |
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,66 +1,6 @@ | ||
#![cfg_attr(not(feature = "export-abi"), no_main, no_std)] | ||
extern crate alloc; | ||
#![cfg_attr(not(feature = "export-abi"), no_main)] | ||
|
||
use crate::erc20::{Erc20, Erc20Params}; | ||
use alloc::{string::String, vec::Vec}; | ||
use stylus_sdk::{alloy_primitives::U256, call, msg, prelude::*}; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
#[global_allocator] | ||
static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT; | ||
|
||
mod erc20; | ||
|
||
struct WethParams; | ||
|
||
/// Immutable definitions | ||
impl Erc20Params for WethParams { | ||
const NAME: &'static str = "Wrapped Ether Example"; | ||
const SYMBOL: &'static str = "WETH"; | ||
const DECIMALS: u8 = 18; | ||
} | ||
|
||
// The contract | ||
sol_storage! { | ||
#[entrypoint] // Makes Weth the entrypoint | ||
struct Weth { | ||
#[borrow] // Allows erc20 to access Weth's storage and make calls | ||
Erc20<WethParams> erc20; | ||
} | ||
} | ||
|
||
// Another contract we'd like to call | ||
sol_interface! { | ||
interface IMath { | ||
function sum(uint256[] values) pure returns (string, uint256); | ||
} | ||
} | ||
|
||
#[external] | ||
#[inherit(Erc20<WethParams>)] | ||
impl Weth { | ||
#[payable] | ||
pub fn deposit(&mut self) -> Result<(), Vec<u8>> { | ||
self.erc20.mint(msg::sender(), msg::value()); | ||
Ok(()) | ||
} | ||
|
||
pub fn withdraw(&mut self, amount: U256) -> Result<(), Vec<u8>> { | ||
self.erc20.burn(msg::sender(), amount)?; | ||
|
||
// send the user their funds | ||
call::transfer_eth(msg::sender(), amount) | ||
} | ||
|
||
// sums numbers | ||
pub fn sum(values: Vec<U256>) -> Result<(String, U256), Vec<u8>> { | ||
Ok(("sum".into(), values.iter().sum())) | ||
} | ||
|
||
// calls the sum() method from the interface | ||
pub fn sum_with_helper(&self, helper: IMath, values: Vec<U256>) -> Result<U256, Vec<u8>> { | ||
let (text, sum) = helper.sum(self, values)?; | ||
assert_eq!(&text, "sum"); | ||
Ok(sum) | ||
} | ||
#[cfg(feature = "export-abi")] | ||
fn main() { | ||
erc20::main(); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should either parse the toml for this or drop the line imo. Otherwise you're letting the consumer of the crate decide the license of the abi in a way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, will drop this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do some investigation into parsing the toml to get rid of the pesky warning and use the right license here