Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `IErc1155Receiver` trait. #747
- Add `Erc1155Holder` contract. #747
- Add `IErc721Receiver` trait. #743
- Add `Erc721Holder` contract. #743

### Changed (Breaking)

- Rename `IERC721Receiver` Solidity Interface to `IErc721ReceiverInterface`. #743
- Change `RECEIVER_FN_SELECTOR` type to `FixedBytes<4>`. #743
- Rename `IERC1155Receiver` Solidity Interface to `IErc1155ReceiverInterface`. #747
- Change `Erc1155Receiver` constants `SINGLE_TRANSFER_FN_SELECTOR` and `BATCH_TRANSFER_FN_SELECTOR` to type `B32`. #747
- Change `Erc721Receiver` constant `RECEIVER_FN_SELECTOR` to type `B32`. #747

### Changed

- Rename `FixedBytes<4>` to `B32` and `FixedBytes<32>` to `B256` and `StorageFixedBytes<32>` to `StorageB256`. #747

## [0.3.0-alpha.1] - 2025-07-21

Expand Down
4 changes: 2 additions & 2 deletions contracts-proc/src/interface_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) fn interface_id(
let signature =
format!("{}({})", solidity_fn_name, type_strings.join(","));

let selector = quote! { alloy_primitives::FixedBytes::<4>::new(stylus_sdk::function_selector!(#solidity_fn_name #(, #arg_types )*)) };
let selector = quote! { alloy_primitives::aliases::B32::new(stylus_sdk::function_selector!(#solidity_fn_name #(, #arg_types )*)) };

// Store selector expression from every function in the trait.
match selectors_map.get(&signature) {
Expand Down Expand Up @@ -103,7 +103,7 @@ pub(crate) fn interface_id(

#[doc = concat!("Solidity interface id associated with ", stringify!(#name), " trait.")]
#[doc = "Computed as a XOR of selectors for each function in the trait."]
fn interface_id() -> alloy_primitives::FixedBytes<4>
fn interface_id() -> alloy_primitives::aliases::B32
where
Self: Sized,
{
Expand Down
2 changes: 1 addition & 1 deletion contracts-proc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod interface_id;
///
/// // Now you can use the computed interface ID:
/// impl IErc165 for Erc721 {
/// fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
/// fn supports_interface(&self, interface_id: B32) -> bool {
/// <Self as IErc721>::interface_id() == interface_id
/// || <Self as IErc165>::interface_id() == interface_id
/// }
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/access/control/extensions/enumerable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use alloc::{vec, vec::Vec};

use alloy_primitives::{Address, FixedBytes, B256, U256};
use alloy_primitives::{aliases::B32, Address, B256, U256};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{prelude::*, storage::StorageMap};
Expand Down Expand Up @@ -156,7 +156,7 @@ impl AccessControlEnumerable {

#[public]
impl IErc165 for AccessControlEnumerable {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
<Self as IAccessControlEnumerable>::interface_id() == interface_id
|| <Self as IErc165>::interface_id() == interface_id
}
Expand Down Expand Up @@ -276,7 +276,7 @@ mod tests {

#[public]
impl IErc165 for AccessControlEnumerableExample {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
self.enumerable.supports_interface(interface_id)
|| self.access_control.supports_interface(interface_id)
}
Expand Down
19 changes: 8 additions & 11 deletions contracts/src/access/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
//! this role.
use alloc::{vec, vec::Vec};

use alloy_primitives::{Address, FixedBytes, B256};
use alloy_primitives::{aliases::B32, Address, B256};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
call::MethodError,
evm, msg,
prelude::*,
storage::{StorageBool, StorageFixedBytes, StorageMap},
storage::{StorageB256, StorageBool, StorageMap},
};

use crate::utils::introspection::erc165::IErc165;
Expand Down Expand Up @@ -128,14 +128,14 @@ pub struct RoleData {
/// Whether an account is member of a certain role.
pub has_role: StorageMap<Address, StorageBool>,
/// The admin role for this role.
pub admin_role: StorageFixedBytes<32>,
pub admin_role: StorageB256,
}

/// State of an [`AccessControl`] contract.
#[storage]
pub struct AccessControl {
/// Role identifier -> Role information.
pub(crate) roles: StorageMap<FixedBytes<32>, RoleData>,
pub(crate) roles: StorageMap<B256, RoleData>,
}

/// Interface for an [`AccessControl`] contract.
Expand Down Expand Up @@ -414,7 +414,7 @@ impl AccessControl {

#[public]
impl IErc165 for AccessControl {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
<Self as IAccessControl>::interface_id() == interface_id
|| <Self as IErc165>::interface_id() == interface_id
}
Expand All @@ -423,12 +423,9 @@ impl IErc165 for AccessControl {
#[cfg(test)]
mod tests {
use motsu::prelude::Contract;
use stylus_sdk::{
alloy_primitives::{Address, FixedBytes},
prelude::*,
};
use stylus_sdk::{alloy_primitives::Address, prelude::*};

use super::{AccessControl, Error, IAccessControl};
use super::*;
use crate::utils::introspection::erc165::IErc165;

/// Shorthand for declaring variables converted from a hex literal to a
Expand Down Expand Up @@ -737,7 +734,7 @@ mod tests {
#[motsu::test]
fn interface_id() {
let actual = <AccessControl as IAccessControl>::interface_id();
let expected: FixedBytes<4> = 0x7965db0b_u32.into();
let expected: B32 = 0x7965db0b_u32.into();
assert_ne!(actual, expected);
}

Expand Down
11 changes: 4 additions & 7 deletions contracts/src/access/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! to the owner.
use alloc::{vec, vec::Vec};

use alloy_primitives::{Address, FixedBytes};
use alloy_primitives::{aliases::B32, Address};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
Expand Down Expand Up @@ -275,7 +275,7 @@ impl Ownable {

#[public]
impl IErc165 for Ownable {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
<Self as IOwnable>::interface_id() == interface_id
|| <Self as IErc165>::interface_id() == interface_id
}
Expand All @@ -284,10 +284,7 @@ impl IErc165 for Ownable {
#[cfg(test)]
mod tests {
use motsu::prelude::*;
use stylus_sdk::{
alloy_primitives::{Address, FixedBytes},
prelude::*,
};
use stylus_sdk::{alloy_primitives::Address, prelude::*};

use super::*;
use crate::utils::introspection::erc165::IErc165;
Expand Down Expand Up @@ -417,7 +414,7 @@ mod tests {
#[motsu::test]
fn interface_id() {
let actual = <Ownable as IOwnable>::interface_id();
let expected: FixedBytes<4> = 0xe083076_u32.into();
let expected: B32 = 0xe083076_u32.into();
assert_eq!(actual, expected);
}

Expand Down
11 changes: 4 additions & 7 deletions contracts/src/access/ownable_two_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use alloc::{vec, vec::Vec};

use alloy_primitives::{Address, FixedBytes};
use alloy_primitives::{aliases::B32, Address};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{evm, msg, prelude::*, storage::StorageAddress};
Expand Down Expand Up @@ -226,7 +226,7 @@ impl Ownable2Step {

#[public]
impl IErc165 for Ownable2Step {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
<Self as IOwnable2Step>::interface_id() == interface_id
|| self.ownable.supports_interface(interface_id)
|| <Self as IErc165>::interface_id() == interface_id
Expand All @@ -236,10 +236,7 @@ impl IErc165 for Ownable2Step {
#[cfg(test)]
mod tests {
use motsu::prelude::Contract;
use stylus_sdk::{
alloy_primitives::{Address, FixedBytes},
prelude::*,
};
use stylus_sdk::{alloy_primitives::Address, prelude::*};

use super::*;
use crate::access::ownable::IOwnable;
Expand Down Expand Up @@ -446,7 +443,7 @@ mod tests {
#[motsu::test]
fn interface_id() {
let actual = <Ownable2Step as IOwnable2Step>::interface_id();
let expected: FixedBytes<4> = 0x94be5999_u32.into();
let expected: B32 = 0x94be5999_u32.into();
assert_eq!(actual, expected);
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/src/finance/vesting_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use alloc::{
vec::Vec,
};

use alloy_primitives::{Address, FixedBytes, U256, U64};
use alloy_primitives::{aliases::B32, Address, U256, U64};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
Expand Down Expand Up @@ -605,7 +605,7 @@ impl VestingWallet {

#[public]
impl IErc165 for VestingWallet {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
<Self as IVestingWallet>::interface_id() == interface_id
|| self.ownable.supports_interface(interface_id)
|| <Self as IErc165>::interface_id() == interface_id
Expand All @@ -616,7 +616,7 @@ impl IErc165 for VestingWallet {
mod tests {
use motsu::prelude::Contract;
use stylus_sdk::{
alloy_primitives::{uint, Address, FixedBytes, U256, U64},
alloy_primitives::{uint, Address, U256, U64},
block,
};

Expand Down Expand Up @@ -755,7 +755,7 @@ mod tests {
#[motsu::test]
fn interface_id() {
let actual = <VestingWallet as IVestingWallet>::interface_id();
let expected: FixedBytes<4> = 0x23a2649d_u32.into();
let expected: B32 = 0x23a2649d_u32.into();
assert_ne!(actual, expected);
}

Expand Down
9 changes: 6 additions & 3 deletions contracts/src/token/common/erc2981.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

use alloc::{vec, vec::Vec};

use alloy_primitives::{aliases::U96, Address, FixedBytes, U256};
use alloy_primitives::{
aliases::{B32, U96},
Address, U256,
};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
Expand Down Expand Up @@ -196,7 +199,7 @@ impl IErc2981 for Erc2981 {

#[public]
impl IErc165 for Erc2981 {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
<Self as IErc2981>::interface_id() == interface_id
|| <Self as IErc165>::interface_id() == interface_id
}
Expand Down Expand Up @@ -832,7 +835,7 @@ mod tests {
let actual = <Erc2981 as IErc2981>::interface_id();
// Value taken from official EIP
// https://eips.ethereum.org/EIPS/eip-2981#checking-if-the-nft-being-sold-on-your-marketplace-implemented-royalties
let expected: FixedBytes<4> = 0x2a55205a_u32.into();
let expected: B32 = 0x2a55205a_u32.into();
assert_eq!(actual, expected);
}

Expand Down
10 changes: 5 additions & 5 deletions contracts/src/token/erc1155/extensions/metadata_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use alloc::{string::String, vec, vec::Vec};

use alloy_primitives::{FixedBytes, U256};
use alloy_primitives::{aliases::B32, U256};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{prelude::*, storage::StorageString};
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Erc1155MetadataUri {

#[public]
impl IErc165 for Erc1155MetadataUri {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
<Self as IErc1155MetadataUri>::interface_id() == interface_id
|| <Self as IErc165>::interface_id() == interface_id
}
Expand All @@ -90,11 +90,11 @@ impl IErc165 for Erc1155MetadataUri {
mod tests {
use motsu::prelude::Contract;
use stylus_sdk::{
alloy_primitives::{uint, Address, FixedBytes},
alloy_primitives::{uint, Address},
prelude::*,
};

use super::{Erc1155MetadataUri, IErc1155MetadataUri, IErc165};
use super::*;

unsafe impl TopLevelStorage for Erc1155MetadataUri {}

Expand All @@ -117,7 +117,7 @@ mod tests {
fn interface_id() {
let actual =
<Erc1155MetadataUri as IErc1155MetadataUri>::interface_id();
let expected: FixedBytes<4> = 0x0e89341c_u32.into();
let expected: B32 = 0x0e89341c_u32.into();
assert_eq!(actual, expected);
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/src/token/erc1155/extensions/supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use alloc::{vec, vec::Vec};

use alloy_primitives::{Address, FixedBytes, U256};
use alloy_primitives::{aliases::B32, Address, U256};
use openzeppelin_stylus_proc::interface_id;
use stylus_sdk::{
abi::Bytes,
Expand Down Expand Up @@ -143,7 +143,7 @@ impl IErc1155 for Erc1155Supply {

#[public]
impl IErc165 for Erc1155Supply {
fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool {
fn supports_interface(&self, interface_id: B32) -> bool {
<Self as IErc1155Supply>::interface_id() == interface_id
|| self.erc1155.supports_interface(interface_id)
}
Expand Down Expand Up @@ -607,7 +607,7 @@ mod tests {
#[motsu::test]
fn interface_id() {
let actual = <Erc1155Supply as IErc1155Supply>::interface_id();
let expected: FixedBytes<4> = fixed_bytes!("0xeac6339d");
let expected: B32 = fixed_bytes!("0xeac6339d");
assert_eq!(actual, expected);
}

Expand Down
Loading
Loading