Skip to content

Commit

Permalink
migrate examples to #[storage] macro
Browse files Browse the repository at this point in the history
  • Loading branch information
qalisander committed Dec 11, 2024
1 parent 6e7e5a4 commit 200c2c0
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 136 deletions.
19 changes: 9 additions & 10 deletions examples/access-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ use openzeppelin_stylus::{
access::control::AccessControl,
token::erc20::{Erc20, IErc20},
};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};

sol_storage! {
#[entrypoint]
struct AccessControlExample {
#[borrow]
Erc20 erc20;
#[borrow]
AccessControl access;
}
use stylus_sdk::prelude::{entrypoint, public, storage};

#[entrypoint]
#[storage]
struct AccessControlExample {
#[borrow]
pub erc20: Erc20,
#[borrow]
pub access: AccessControl,
}

// `keccak256("TRANSFER_ROLE")`
Expand Down
17 changes: 8 additions & 9 deletions examples/basic/token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ use alloc::vec::Vec;

use alloy_primitives::{Address, U256};
use openzeppelin_stylus::token::erc20::{extensions::Erc20Metadata, Erc20};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

sol_storage! {
#[entrypoint]
struct Erc20Example {
#[borrow]
Erc20 erc20;
#[borrow]
Erc20Metadata metadata;
}
#[entrypoint]
#[storage]
struct Erc20Example {
#[borrow]
pub erc20: Erc20,
#[borrow]
pub metadata: Erc20Metadata,
}

#[public]
Expand Down
9 changes: 4 additions & 5 deletions examples/ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use alloc::vec::Vec;

use alloy_primitives::{Address, B256};
use openzeppelin_stylus::utils::cryptography::ecdsa;
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

sol_storage! {
#[entrypoint]
struct ECDSAExample {}
}
#[entrypoint]
#[storage]
struct ECDSAExample {}

#[public]
impl ECDSAExample {
Expand Down
17 changes: 8 additions & 9 deletions examples/erc1155-metadata-uri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ use openzeppelin_stylus::{
},
utils::introspection::erc165::IErc165,
};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

sol_storage! {
#[entrypoint]
struct Erc1155MetadataUriExample {
#[borrow]
Erc1155 erc1155;
Erc1155MetadataUri metadata_uri;
Erc1155UriStorage uri_storage;
}
#[entrypoint]
#[storage]
struct Erc1155MetadataUriExample {
#[borrow]
pub erc1155: Erc1155,
pub metadata_uri: Erc1155MetadataUri,
pub uri_storage: Erc1155UriStorage,
}

#[public]
Expand Down
14 changes: 7 additions & 7 deletions examples/erc1155-supply/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use openzeppelin_stylus::token::erc1155::extensions::{
};
use stylus_sdk::{
abi::Bytes,
prelude::{entrypoint, public, sol_storage},
prelude::{entrypoint, public, storage},
};

sol_storage! {
#[entrypoint]
struct Erc1155Example {
#[borrow]
Erc1155Supply erc1155_supply;
}
#[entrypoint]
#[storage]
struct Erc1155Example {
#[borrow]
pub erc1155_supply: Erc1155Supply,
}

#[public]
#[inherit(Erc1155Supply)]
impl Erc1155Example {
Expand Down
17 changes: 8 additions & 9 deletions examples/erc1155/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ use openzeppelin_stylus::{
};
use stylus_sdk::{
abi::Bytes,
prelude::{entrypoint, public, sol_storage},
prelude::{entrypoint, public, storage},
};

sol_storage! {
#[entrypoint]
struct Erc1155Example {
#[borrow]
Erc1155 erc1155;
#[borrow]
Pausable pausable;
}
#[entrypoint]
#[storage]
struct Erc1155Example {
#[borrow]
pub erc1155: Erc1155,
#[borrow]
pub pausable: Pausable,
}

#[public]
Expand Down
17 changes: 8 additions & 9 deletions examples/erc20-permit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ use alloy_primitives::{Address, U256};
use openzeppelin_stylus::{
token::erc20::extensions::Erc20Permit, utils::cryptography::eip712::IEip712,
};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

sol_storage! {
#[entrypoint]
struct Erc20PermitExample {
#[borrow]
Erc20Permit<Eip712> erc20_permit;
}

struct Eip712 {}
#[entrypoint]
#[storage]
struct Erc20PermitExample {
#[borrow]
pub erc20_permit: Erc20Permit<Eip712>,
}
#[storage]
struct Eip712 {}

impl IEip712 for Eip712 {
const NAME: &'static str = "ERC-20 Permit Example";
Expand Down
25 changes: 12 additions & 13 deletions examples/erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ use openzeppelin_stylus::{
},
utils::{introspection::erc165::IErc165, Pausable},
};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

const DECIMALS: u8 = 10;

sol_storage! {
#[entrypoint]
struct Erc20Example {
#[borrow]
Erc20 erc20;
#[borrow]
Erc20Metadata metadata;
#[borrow]
Capped capped;
#[borrow]
Pausable pausable;
}
#[entrypoint]
#[storage]
struct Erc20Example {
#[borrow]
pub erc20: Erc20,
#[borrow]
pub metadata: Erc20Metadata,
#[borrow]
pub capped: Capped,
#[borrow]
pub pausable: Pausable,
}

#[public]
Expand Down
11 changes: 5 additions & 6 deletions examples/erc721-consecutive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ use openzeppelin_stylus::token::erc721::extensions::consecutive::{
};
use stylus_sdk::prelude::*;

sol_storage! {
#[entrypoint]
struct Erc721ConsecutiveExample {
#[borrow]
Erc721Consecutive erc721_consecutive;
}
#[entrypoint]
#[storage]
struct Erc721ConsecutiveExample {
#[borrow]
pub erc721_consecutive: Erc721Consecutive,
}

#[public]
Expand Down
21 changes: 10 additions & 11 deletions examples/erc721-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ use openzeppelin_stylus::{
},
utils::introspection::erc165::IErc165,
};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};

sol_storage! {
#[entrypoint]
struct Erc721MetadataExample {
#[borrow]
Erc721 erc721;
#[borrow]
Metadata metadata;
UriStorage uri_storage;
}
use stylus_sdk::prelude::{entrypoint, public, storage};

#[entrypoint]
#[storage]
struct Erc721MetadataExample {
#[borrow]
pub erc721: Erc721,
#[borrow]
pub metadata: Metadata,
pub uri_storage: UriStorage,
}

#[public]
Expand Down
21 changes: 10 additions & 11 deletions examples/erc721/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ use openzeppelin_stylus::{
};
use stylus_sdk::{
abi::Bytes,
prelude::{entrypoint, public, sol_storage},
prelude::{entrypoint, public, storage},
};

sol_storage! {
#[entrypoint]
struct Erc721Example {
#[borrow]
Erc721 erc721;
#[borrow]
Enumerable enumerable;
#[borrow]
Pausable pausable;
}
#[entrypoint]
#[storage]
struct Erc721Example {
#[borrow]
pub erc721: Erc721,
#[borrow]
pub enumerable: Enumerable,
#[borrow]
pub pausable: Pausable,
}

#[public]
Expand Down
9 changes: 4 additions & 5 deletions examples/merkle-proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use openzeppelin_crypto::{
};
use stylus_sdk::{
alloy_sol_types::sol,
prelude::{entrypoint, public, sol_storage},
prelude::{entrypoint, public, storage},
stylus_proc::SolidityError,
};

Expand Down Expand Up @@ -47,10 +47,9 @@ impl core::convert::From<merkle::MultiProofError> for VerifierError {
}
}

sol_storage! {
#[entrypoint]
struct VerifierContract { }
}
#[entrypoint]
#[storage]
struct VerifierContract {}

#[public]
impl VerifierContract {
Expand Down
17 changes: 8 additions & 9 deletions examples/ownable-two-step/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ use openzeppelin_stylus::{
access::ownable_two_step::Ownable2Step,
token::erc20::{Erc20, IErc20},
};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

sol_storage! {
#[entrypoint]
struct Ownable2StepExample {
#[borrow]
Erc20 erc20;
#[borrow]
Ownable2Step ownable;
}
#[entrypoint]
#[storage]
struct Ownable2StepExample {
#[borrow]
pub erc20: Erc20,
#[borrow]
pub ownable: Ownable2Step,
}

#[public]
Expand Down
17 changes: 8 additions & 9 deletions examples/ownable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ use openzeppelin_stylus::{
access::ownable::Ownable,
token::erc20::{Erc20, IErc20},
};
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

sol_storage! {
#[entrypoint]
struct OwnableExample {
#[borrow]
Erc20 erc20;
#[borrow]
Ownable ownable;
}
#[entrypoint]
#[storage]
struct OwnableExample {
#[borrow]
pub erc20: Erc20,
#[borrow]
pub ownable: Ownable,
}

#[public]
Expand Down
13 changes: 6 additions & 7 deletions examples/safe-erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
extern crate alloc;

use openzeppelin_stylus::token::erc20::utils::safe_erc20::SafeErc20;
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

sol_storage! {
#[entrypoint]
struct SafeErc20Example {
#[borrow]
SafeErc20 safe_erc20;
}
#[entrypoint]
#[storage]
struct SafeErc20Example {
#[borrow]
pub safe_erc20: SafeErc20,
}

#[public]
Expand Down
13 changes: 6 additions & 7 deletions examples/vesting-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
extern crate alloc;

use openzeppelin_stylus::finance::vesting_wallet::VestingWallet;
use stylus_sdk::prelude::{entrypoint, public, sol_storage};
use stylus_sdk::prelude::{entrypoint, public, storage};

sol_storage! {
#[entrypoint]
struct VestingWalletExample {
#[borrow]
VestingWallet vesting_wallet;
}
#[entrypoint]
#[storage]
struct VestingWalletExample {
#[borrow]
pub vesting_wallet: VestingWallet,
}

#[public]
Expand Down

0 comments on commit 200c2c0

Please sign in to comment.