diff --git a/CHANGELOG.md b/CHANGELOG.md index f777c8923..f17421475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ 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 @@ -16,6 +18,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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 diff --git a/contracts-proc/src/interface_id.rs b/contracts-proc/src/interface_id.rs index 41222dd36..b8c7a6a39 100644 --- a/contracts-proc/src/interface_id.rs +++ b/contracts-proc/src/interface_id.rs @@ -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) { @@ -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, { diff --git a/contracts-proc/src/lib.rs b/contracts-proc/src/lib.rs index 4799a02ec..6ae1e7a5d 100644 --- a/contracts-proc/src/lib.rs +++ b/contracts-proc/src/lib.rs @@ -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 { /// ::interface_id() == interface_id /// || ::interface_id() == interface_id /// } diff --git a/contracts/src/access/control/extensions/enumerable.rs b/contracts/src/access/control/extensions/enumerable.rs index d05e38fab..9a90dba9e 100644 --- a/contracts/src/access/control/extensions/enumerable.rs +++ b/contracts/src/access/control/extensions/enumerable.rs @@ -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}; @@ -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 { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -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) } diff --git a/contracts/src/access/control/mod.rs b/contracts/src/access/control/mod.rs index 5949228c0..b34553eab 100644 --- a/contracts/src/access/control/mod.rs +++ b/contracts/src/access/control/mod.rs @@ -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; @@ -128,14 +128,14 @@ pub struct RoleData { /// Whether an account is member of a certain role. pub has_role: StorageMap, /// 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, RoleData>, + pub(crate) roles: StorageMap, } /// Interface for an [`AccessControl`] contract. @@ -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 { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -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 @@ -737,7 +734,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x7965db0b_u32.into(); + let expected: B32 = 0x7965db0b_u32.into(); assert_ne!(actual, expected); } diff --git a/contracts/src/access/ownable.rs b/contracts/src/access/ownable.rs index f9ae0e5f9..fcc2ca4ef 100644 --- a/contracts/src/access/ownable.rs +++ b/contracts/src/access/ownable.rs @@ -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::{ @@ -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 { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -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; @@ -417,7 +414,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0xe083076_u32.into(); + let expected: B32 = 0xe083076_u32.into(); assert_eq!(actual, expected); } diff --git a/contracts/src/access/ownable_two_step.rs b/contracts/src/access/ownable_two_step.rs index 9f0f466d0..04d1f35c1 100644 --- a/contracts/src/access/ownable_two_step.rs +++ b/contracts/src/access/ownable_two_step.rs @@ -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}; @@ -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 { ::interface_id() == interface_id || self.ownable.supports_interface(interface_id) || ::interface_id() == interface_id @@ -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; @@ -446,7 +443,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x94be5999_u32.into(); + let expected: B32 = 0x94be5999_u32.into(); assert_eq!(actual, expected); } diff --git a/contracts/src/finance/vesting_wallet.rs b/contracts/src/finance/vesting_wallet.rs index 5f74a9f29..2ec785f93 100644 --- a/contracts/src/finance/vesting_wallet.rs +++ b/contracts/src/finance/vesting_wallet.rs @@ -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::{ @@ -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 { ::interface_id() == interface_id || self.ownable.supports_interface(interface_id) || ::interface_id() == interface_id @@ -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, }; @@ -755,7 +755,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x23a2649d_u32.into(); + let expected: B32 = 0x23a2649d_u32.into(); assert_ne!(actual, expected); } diff --git a/contracts/src/token/common/erc2981.rs b/contracts/src/token/common/erc2981.rs index cc657c4b9..7db58814e 100644 --- a/contracts/src/token/common/erc2981.rs +++ b/contracts/src/token/common/erc2981.rs @@ -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::{ @@ -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 { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -832,7 +835,7 @@ mod tests { let actual = ::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); } diff --git a/contracts/src/token/erc1155/extensions/metadata_uri.rs b/contracts/src/token/erc1155/extensions/metadata_uri.rs index 33ad0316c..038579d11 100644 --- a/contracts/src/token/erc1155/extensions/metadata_uri.rs +++ b/contracts/src/token/erc1155/extensions/metadata_uri.rs @@ -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}; @@ -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 { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -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 {} @@ -117,7 +117,7 @@ mod tests { fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x0e89341c_u32.into(); + let expected: B32 = 0x0e89341c_u32.into(); assert_eq!(actual, expected); } diff --git a/contracts/src/token/erc1155/extensions/supply.rs b/contracts/src/token/erc1155/extensions/supply.rs index 077d59dd2..c7a8a21c3 100644 --- a/contracts/src/token/erc1155/extensions/supply.rs +++ b/contracts/src/token/erc1155/extensions/supply.rs @@ -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, @@ -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 { ::interface_id() == interface_id || self.erc1155.supports_interface(interface_id) } @@ -607,7 +607,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = fixed_bytes!("0xeac6339d"); + let expected: B32 = fixed_bytes!("0xeac6339d"); assert_eq!(actual, expected); } diff --git a/contracts/src/token/erc1155/mod.rs b/contracts/src/token/erc1155/mod.rs index b9ab107a3..fec5b7a8b 100644 --- a/contracts/src/token/erc1155/mod.rs +++ b/contracts/src/token/erc1155/mod.rs @@ -5,7 +5,7 @@ use alloc::{ 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, @@ -21,30 +21,13 @@ use crate::utils::{ }; pub mod extensions; -mod receiver; -pub use receiver::IERC1155Receiver; - -/// The expected value returned from [`IERC1155Receiver::on_erc_1155_received`]. -pub const SINGLE_TRANSFER_FN_SELECTOR: [u8; 4] = function_selector!( - "onERC1155Received", - Address, - Address, - U256, - U256, - Bytes -); - -/// The expected value returned from -/// [`IERC1155Receiver::on_erc_1155_batch_received`]. -pub const BATCH_TRANSFER_FN_SELECTOR: [u8; 4] = function_selector!( - "onERC1155BatchReceived", - Address, - Address, - Vec, - Vec, - Bytes -); +pub mod receiver; +pub mod utils; +pub use receiver::{ + IErc1155Receiver, IErc1155ReceiverInterface, BATCH_TRANSFER_FN_SELECTOR, + SINGLE_TRANSFER_FN_SELECTOR, +}; pub use sol::*; #[cfg_attr(coverage_nightly, coverage(off))] mod sol { @@ -298,7 +281,7 @@ pub trait IErc1155: IErc165 { /// # Errors /// /// * [`Error::InvalidReceiver`] - Returned when `to` is [`Address::ZERO`] - /// or when [`IERC1155Receiver::on_erc_1155_received`] hasn't returned its + /// or when [`IErc1155Receiver::on_erc1155_received`] hasn't returned its /// interface id or returned with error. /// * [`Error::InvalidSender`] - Returned when `from` is [`Address::ZERO`]. /// * [`Error::MissingApprovalForAll`] - Returned when `from` is not the @@ -334,7 +317,7 @@ pub trait IErc1155: IErc165 { /// # Errors /// /// * [`Error::InvalidReceiver`] - Returned when `to` is [`Address::ZERO`] - /// or when [`IERC1155Receiver::on_erc_1155_batch_received`] hasn't + /// or when [`IErc1155Receiver::on_erc1155_batch_received`] hasn't /// returned its interface id or returned with error. /// * [`Error::InvalidSender`] - Returned when `from` is [`Address::ZERO`]. /// * [`Error::InvalidArrayLength`] - Returned when the length of `ids` is @@ -426,7 +409,7 @@ impl IErc1155 for Erc1155 { #[public] impl IErc165 for Erc1155 { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -491,8 +474,8 @@ impl Erc1155 { } /// Version of [`Self::_update`] that performs the token acceptance check by - /// calling [`IERC1155Receiver::on_erc_1155_received`] or - /// [`IERC1155Receiver::on_erc_1155_batch_received`] on the receiver address + /// calling [`IErc1155Receiver::on_erc1155_received`] or + /// [`IErc1155Receiver::on_erc1155_batch_received`] on the receiver address /// if it contains code. /// /// # Arguments @@ -512,8 +495,8 @@ impl Erc1155 { /// * [`Error::InsufficientBalance`] - Returned when `value` is greater than /// the balance of the `from` account. /// * [`Error::InvalidReceiver`] - Returned when - /// [`IERC1155Receiver::on_erc_1155_received`] or - /// [`IERC1155Receiver::on_erc_1155_batch_received`] hasn't returned its + /// [`IErc1155Receiver::on_erc1155_received`] or + /// [`IErc1155Receiver::on_erc1155_batch_received`] hasn't returned its /// interface id or returned with error. /// /// # Events @@ -564,7 +547,7 @@ impl Erc1155 { /// /// * [`Error::InvalidReceiver`] - If `to` is [`Address::ZERO`]. /// * [`Error::InvalidReceiver`] - If - /// [`IERC1155Receiver::on_erc_1155_received`] hasn't returned its + /// [`IErc1155Receiver::on_erc1155_received`] hasn't returned its /// interface id or returned with error. /// /// # Events @@ -600,10 +583,10 @@ impl Erc1155 { /// * [`Error::InvalidReceiver`] - If `to` is [`Address::ZERO`]. /// * [`Error::InvalidArrayLength`] - If length of `ids` is not equal to /// length of `values`. - /// * [`IERC1155Receiver::on_erc_1155_received`] - If hasn't returned its + /// * [`IErc1155Receiver::on_erc1155_received`] - If hasn't returned its /// * [`Error::InvalidReceiver`] - interface id or returned with error. /// * [`Error::InvalidReceiver`] - If - /// [`IERC1155Receiver::on_erc_1155_batch_received`] hasn't returned its + /// [`IErc1155Receiver::on_erc1155_batch_received`] hasn't returned its /// interface id or returned with error. /// /// # Events @@ -719,15 +702,15 @@ impl Erc1155 { impl Erc1155 { /// Performs an acceptance check for the provided `operator` by calling - /// [`IERC1155Receiver::on_erc_1155_received`] in case of single token - /// transfer, or [`IERC1155Receiver::on_erc_1155_batch_received`] in + /// [`IErc1155Receiver::on_erc1155_received`] in case of single token + /// transfer, or [`IErc1155Receiver::on_erc1155_batch_received`] in /// case of batch transfer on the `to` address. /// /// The acceptance call is not executed and treated as a no-op if the /// target address doesn't contain code (i.e. an EOA). Otherwise, /// the recipient must implement either - /// [`IERC1155Receiver::on_erc_1155_received`] for single transfer, or - /// [`IERC1155Receiver::on_erc_1155_batch_received`] for a batch transfer, + /// [`IErc1155Receiver::on_erc1155_received`] for single transfer, or + /// [`IErc1155Receiver::on_erc1155_batch_received`] for a batch transfer, /// and return the acceptance value to accept the transfer. /// /// # Arguments @@ -745,12 +728,12 @@ impl Erc1155 { /// # Errors /// /// * [`Error::InvalidReceiver`] - If - /// [`IERC1155Receiver::on_erc_1155_received`] or - /// [`IERC1155Receiver::on_erc_1155_batch_received`] haven't returned the + /// [`IErc1155Receiver::on_erc1155_received`] or + /// [`IErc1155Receiver::on_erc1155_batch_received`] haven't returned the /// interface id or returned an error. /// * [`Error::InvalidReceiverWithReason`] - If - /// [`IERC1155Receiver::on_erc_1155_received`] or - /// [`IERC1155Receiver::on_erc_1155_batch_received`] reverted with revert + /// [`IErc1155Receiver::on_erc1155_received`] or + /// [`IErc1155Receiver::on_erc1155_batch_received`] reverted with revert /// data. fn _check_on_erc1155_received( &mut self, @@ -764,7 +747,7 @@ impl Erc1155 { return Ok(()); } - let receiver = IERC1155Receiver::new(to); + let receiver = IErc1155ReceiverInterface::new(to); let call = Call::new_in(self); let result = match details.transfer { Transfer::Single { id, value } => receiver @@ -805,8 +788,8 @@ impl Erc1155 { /// Creates `values` of tokens specified by `ids`, and assigns /// them to `to`. Performs the token acceptance check by - /// calling [`IERC1155Receiver::on_erc_1155_received`] or - /// [`IERC1155Receiver::on_erc_1155_batch_received`] on the `to` address if + /// calling [`IErc1155Receiver::on_erc1155_received`] or + /// [`IErc1155Receiver::on_erc1155_batch_received`] on the `to` address if /// it contains code. /// /// # Arguments @@ -822,10 +805,10 @@ impl Erc1155 { /// /// * [`Error::InvalidReceiver`] - If `to` is [`Address::ZERO`]. /// * [`Error::InvalidReceiver`] - If - /// [`IERC1155Receiver::on_erc_1155_received`] hasn't returned its + /// [`IErc1155Receiver::on_erc1155_received`] hasn't returned its /// interface id or returned with error. /// * [`Error::InvalidReceiver`] - If - /// [`IERC1155Receiver::on_erc_1155_batch_received`] hasn't returned its + /// [`IErc1155Receiver::on_erc1155_batch_received`] hasn't returned its /// interface id or returned with error. /// * [`Error::InvalidArrayLength`] - If length of `ids` is not equal to /// length of `values`. @@ -924,10 +907,10 @@ impl Erc1155 { /// * [`Error::InsufficientBalance`] - If `value` is greater than the /// balance of the `from` account. /// * [`Error::InvalidReceiver`] - If - /// [`IERC1155Receiver::on_erc_1155_received`] hasn't returned its + /// [`IErc1155Receiver::on_erc1155_received`] hasn't returned its /// interface id or returned with error. /// * [`Error::InvalidReceiver`] - If - /// [`IERC1155Receiver::on_erc_1155_batch_received`] hasn't returned its + /// [`IErc1155Receiver::on_erc1155_batch_received`] hasn't returned its /// interface id or returned with error. /// /// # Events @@ -1061,10 +1044,10 @@ impl Erc1155 { } /// Data struct to be passed to a contract that -/// implements [`IERC1155Receiver`] interface. +/// implements [`IErc1155Receiver`] interface. struct Erc1155ReceiverData { /// ERC-1155 Receiver function selector. - receiver_fn_selector: [u8; 4], + receiver_fn_selector: B32, /// Transfer details, either [`Transfer::Single`] or [`Transfer::Batch`]. transfer: Transfer, } @@ -1093,7 +1076,7 @@ impl Erc1155ReceiverData { } /// Creates a new instance for a [`Transfer::Single`]. - /// Check [`IERC1155Receiver::on_erc_1155_received`]. + /// Check [`IErc1155Receiver::on_erc1155_received`]. /// /// # Arguments /// @@ -1107,7 +1090,7 @@ impl Erc1155ReceiverData { } /// Creates a new instance for a [`Transfer::Batch`]. - /// Check [`IERC1155Receiver::on_erc_1155_batch_received`]. + /// Check [`IErc1155Receiver::on_erc1155_batch_received`]. /// /// # Arguments /// @@ -1142,16 +1125,10 @@ enum Transfer { #[cfg(test)] mod tests { - use alloy_primitives::{uint, Address, FixedBytes, U256}; + use alloy_primitives::{aliases::B32, uint, Address, U256}; use motsu::prelude::Contract; - use super::{ - ERC1155InsufficientBalance, ERC1155InvalidArrayLength, - ERC1155InvalidOperator, ERC1155InvalidReceiver, ERC1155InvalidSender, - ERC1155MissingApprovalForAll, Erc1155, Erc1155ReceiverData, Error, - IErc1155, Transfer, BATCH_TRANSFER_FN_SELECTOR, - SINGLE_TRANSFER_FN_SELECTOR, - }; + use super::*; use crate::utils::introspection::erc165::IErc165; pub(crate) fn random_token_ids(size: usize) -> Vec { @@ -2348,7 +2325,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0xd9b67a26_u32.into(); + let expected: B32 = 0xd9b67a26_u32.into(); assert_eq!(actual, expected); } diff --git a/contracts/src/token/erc1155/receiver.rs b/contracts/src/token/erc1155/receiver.rs index 908642a72..77d26c95c 100644 --- a/contracts/src/token/erc1155/receiver.rs +++ b/contracts/src/token/erc1155/receiver.rs @@ -2,33 +2,41 @@ //! ERC-1155 token transfers. #![allow(missing_docs)] #![cfg_attr(coverage_nightly, coverage(off))] -use alloc::vec; +use alloc::{vec, vec::Vec}; -use stylus_sdk::prelude::sol_interface; +use alloy_primitives::{aliases::B32, Address, U256}; +use openzeppelin_stylus_proc::interface_id; +use stylus_sdk::{abi::Bytes, function_selector, prelude::*}; + +use crate::utils::introspection::erc165::IErc165; + +/// The expected value returned from [`IErc1155Receiver::on_erc1155_received`]. +pub const SINGLE_TRANSFER_FN_SELECTOR: B32 = B32::new(function_selector!( + "onERC1155Received", + Address, + Address, + U256, + U256, + Bytes +)); + +/// The expected value returned from +/// [`IErc1155Receiver::on_erc1155_batch_received`]. +pub const BATCH_TRANSFER_FN_SELECTOR: B32 = B32::new(function_selector!( + "onERC1155BatchReceived", + Address, + Address, + Vec, + Vec, + Bytes +)); sol_interface! { - /// [`super::Erc1155`] token receiver interface. + /// [`super::Erc1155`] token receiver Solidity interface. /// - /// Interface for any contract that wants to support safe transfers from - /// [`super::Erc1155`] asset contracts. - interface IERC1155Receiver { - /// Handles the receipt of a single ERC-1155 token type. This function - /// is called at the end of [`super::IErc1155::safe_transfer_from`] - /// after the balance has been updated. - /// - /// NOTE: To accept the transfer, this must return - /// [`super::SINGLE_TRANSFER_FN_SELECTOR`], or its own function - /// selector. - /// - /// # Arguments - /// - /// # Arguments - /// - /// * `operator` - The address which initiated the transfer. - /// * `from` - The address which previously owned the token. - /// * `id` - The ID of the token being transferred. - /// * `value` - The amount of tokens being transferred. - /// * `data` - Additional data with no specified format. + /// Check [`super::IErc1155Receiver`] trait for more details. + interface IErc1155ReceiverInterface { + /// See [`super::IErc1155Receiver::on_erc1155_received`]. #[allow(missing_docs)] function onERC1155Received( address operator, @@ -38,25 +46,7 @@ sol_interface! { bytes calldata data ) external returns (bytes4); - /// Handles the receipt of multiple ERC-1155 token types. This function - /// is called at the end of - /// [`super::IErc1155::safe_batch_transfer_from`] after the balances - /// have been updated. - /// - /// NOTE: To accept the transfer(s), this must return - /// [`super::BATCH_TRANSFER_FN_SELECTOR`], or its own function selector. - /// - /// # Arguments - /// - /// # Arguments - /// - /// * `operator` - The address which initiated the batch transfer. - /// * `from` - The address which previously owned the token. - /// * `ids` - An array containing ids of each token being transferred - /// (order and length must match `values` array). - /// * `values` - An array containing amounts of each token being - /// transferred (order and length must match `ids` array). - /// * `data` - Additional data with no specified format. + /// See [`super::IErc1155Receiver::on_erc1155_batch_received`]. #[allow(missing_docs)] function onERC1155BatchReceived( address operator, @@ -67,3 +57,66 @@ sol_interface! { ) external returns (bytes4); } } + +/// Interface that must be implemented by smart contracts in order to receive +/// ERC-1155 token transfers. +#[interface_id] +pub trait IErc1155Receiver: IErc165 { + /// The error type associated to the trait implementation. + type Error: Into>; + + /// Handles the receipt of a single ERC-1155 token type. This function + /// is called at the end of [`super::IErc1155::safe_transfer_from`] after + /// the balance has been updated. + /// + /// # Arguments + /// + /// * `&mut self` - Write access to the contract's state. + /// * `operator` - The address which initiated the transfer. + /// * `from` - The address which previously owned the token. + /// * `id` - The ID of the token being transferred. + /// * `value` - The amount of tokens being transferred. + /// * `data` - Additional data with no specified format. + /// + /// # Errors + /// + /// * May return a custom error. + #[selector(name = "onERC1155Received")] + fn on_erc1155_received( + &mut self, + operator: Address, + from: Address, + id: U256, + value: U256, + data: Bytes, + ) -> Result; + + /// Handles the receipt of multiple ERC-1155 token types. This function + /// is called at the end of + /// [`super::IErc1155::safe_batch_transfer_from`] after the balances + /// have been updated. + /// + /// # Arguments + /// + /// * `&mut self` - Write access to the contract's state. + /// * `operator` - The address which initiated the batch transfer. + /// * `from` - The address which previously owned the token. + /// * `ids` - An array containing ids of each token being transferred (order + /// and length must match `values` array). + /// * `values` - An array containing amounts of each token being transferred + /// (order and length must match `ids` array). + /// * `data` - Additional data with no specified format. + /// + /// # Errors + /// + /// * May return a custom error. + #[selector(name = "onERC1155BatchReceived")] + fn on_erc1155_batch_received( + &mut self, + operator: Address, + from: Address, + ids: Vec, + values: Vec, + data: Bytes, + ) -> Result; +} diff --git a/contracts/src/token/erc1155/utils/holder.rs b/contracts/src/token/erc1155/utils/holder.rs new file mode 100644 index 000000000..d83625a5b --- /dev/null +++ b/contracts/src/token/erc1155/utils/holder.rs @@ -0,0 +1,112 @@ +//! Implementation of the [`IErc1155Receiver`] trait. +use alloc::{vec, vec::Vec}; + +use alloy_primitives::{aliases::B32, Address, U256}; +use stylus_sdk::{abi::Bytes, function_selector, prelude::*}; + +use crate::{ + token::erc1155::receiver::{ + IErc1155Receiver, BATCH_TRANSFER_FN_SELECTOR, + SINGLE_TRANSFER_FN_SELECTOR, + }, + utils::introspection::erc165::IErc165, +}; + +/// Simple implementation of [`IErc1155Receiver`] that will allow a contract to +/// hold ERC-1155 tokens. +#[storage] +pub struct Erc1155Holder; + +#[public] +#[implements(IErc1155Receiver>, IErc165)] +impl Erc1155Holder {} + +#[public] +impl IErc1155Receiver for Erc1155Holder { + type Error = Vec; + + #[selector(name = "onERC1155Received")] + fn on_erc1155_received( + &mut self, + _operator: Address, + _from: Address, + _id: U256, + _value: U256, + _data: Bytes, + ) -> Result { + Ok(SINGLE_TRANSFER_FN_SELECTOR) + } + + #[selector(name = "onERC1155BatchReceived")] + fn on_erc1155_batch_received( + &mut self, + _operator: Address, + _from: Address, + _ids: Vec, + _values: Vec, + _data: Bytes, + ) -> Result { + Ok(BATCH_TRANSFER_FN_SELECTOR) + } +} + +#[public] +impl IErc165 for Erc1155Holder { + fn supports_interface(&self, interface_id: B32) -> bool { + ::interface_id() == interface_id + || ::interface_id() == interface_id + } +} + +#[cfg(test)] +mod tests { + use motsu::prelude::Contract; + + use super::*; + + unsafe impl TopLevelStorage for Erc1155Holder {} + + #[motsu::test] + fn holder_returns_proper_selectors( + contract: Contract, + alice: Address, + ) { + let one = U256::from(1); + assert_eq!( + contract.sender(alice).on_erc1155_received( + alice, + alice, + one, + one, + vec![].into() + ), + Ok(SINGLE_TRANSFER_FN_SELECTOR) + ); + + assert_eq!( + contract.sender(alice).on_erc1155_batch_received( + alice, + alice, + vec![one], + vec![one], + vec![].into() + ), + Ok(BATCH_TRANSFER_FN_SELECTOR) + ); + } + + #[motsu::test] + fn supports_interface(contract: Contract, alice: Address) { + assert!(contract.sender(alice).supports_interface( + ::interface_id() + )); + assert!(contract + .sender(alice) + .supports_interface(::interface_id())); + + let fake_interface_id = 0x12345678_u32; + assert!(!contract + .sender(alice) + .supports_interface(fake_interface_id.into())); + } +} diff --git a/contracts/src/token/erc1155/utils/mod.rs b/contracts/src/token/erc1155/utils/mod.rs new file mode 100644 index 000000000..d6dc20cbf --- /dev/null +++ b/contracts/src/token/erc1155/utils/mod.rs @@ -0,0 +1,4 @@ +//! Utility functions and smart contracts for the ERC-1155 token. +mod holder; + +pub use holder::*; diff --git a/contracts/src/token/erc20/extensions/erc4626.rs b/contracts/src/token/erc20/extensions/erc4626.rs index 5e753b169..707e3820b 100644 --- a/contracts/src/token/erc20/extensions/erc4626.rs +++ b/contracts/src/token/erc20/extensions/erc4626.rs @@ -1118,7 +1118,7 @@ impl Erc4626 { // TODO: implement `IErc165` once `IErc4626` is implemented for `Erc4626`. // #[public] // impl IErc165 for Erc4626 { -// fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { +// fn supports_interface(&self, interface_id: B32) -> bool { // ::interface_id() == interface_id // || ::interface_id() == interface_id // } @@ -1127,7 +1127,7 @@ impl Erc4626 { // TODO: Add missing tests once `motsu` supports calling external contracts. #[cfg(test)] mod tests { - use alloy_primitives::{address, Address, FixedBytes, U256, U8}; + use alloy_primitives::{address, aliases::B32, Address, U256, U8}; use motsu::prelude::*; use stylus_sdk::prelude::*; @@ -1255,7 +1255,7 @@ mod tests { #[public] impl IErc165 for Erc4626TestExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || self.erc20.supports_interface(interface_id) || self.metadata.supports_interface(interface_id) @@ -1331,7 +1331,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x87dfe5a0_u32.into(); + let expected: B32 = 0x87dfe5a0_u32.into(); assert_eq!(actual, expected); } } diff --git a/contracts/src/token/erc20/extensions/flash_mint.rs b/contracts/src/token/erc20/extensions/flash_mint.rs index 8e93ebe19..ff767ae67 100644 --- a/contracts/src/token/erc20/extensions/flash_mint.rs +++ b/contracts/src/token/erc20/extensions/flash_mint.rs @@ -359,7 +359,7 @@ impl Erc20FlashMint { // TODO: implement `IErc165` once `IErc3156FlashLender` is implemented for // `Erc20FlashMint`. // impl IErc165 for Erc20FlashMint { -// fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { +// fn supports_interface(&self, interface_id: B32) -> bool { // ::interface_id() == interface_id // || ::interface_id() == interface_id // } @@ -370,7 +370,7 @@ mod tests { use motsu::prelude::*; use stylus_sdk::{ abi::Bytes, - alloy_primitives::{uint, Address, FixedBytes, U256}, + alloy_primitives::{aliases::B32, uint, Address, U256}, prelude::*, }; @@ -573,7 +573,7 @@ mod tests { fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0xe4143091_u32.into(); + let expected: B32 = 0xe4143091_u32.into(); assert_eq!(actual, expected); } } diff --git a/contracts/src/token/erc20/extensions/metadata.rs b/contracts/src/token/erc20/extensions/metadata.rs index b543cdd13..0b523c468 100644 --- a/contracts/src/token/erc20/extensions/metadata.rs +++ b/contracts/src/token/erc20/extensions/metadata.rs @@ -2,11 +2,9 @@ use alloc::{string::String, vec, vec::Vec}; +use alloy_primitives::{aliases::B32, uint, U8}; use openzeppelin_stylus_proc::interface_id; -use stylus_sdk::{ - alloy_primitives::{uint, FixedBytes, U8}, - prelude::*, -}; +use stylus_sdk::prelude::*; use crate::utils::{introspection::erc165::IErc165, Metadata}; @@ -94,7 +92,7 @@ impl IErc20Metadata for Erc20Metadata { #[public] impl IErc165 for Erc20Metadata { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -103,19 +101,16 @@ impl IErc165 for Erc20Metadata { #[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::{Erc20Metadata, IErc165, IErc20Metadata}; + use super::*; unsafe impl TopLevelStorage for Erc20Metadata {} #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0xa219a025_u32.into(); + let expected: B32 = 0xa219a025_u32.into(); assert_eq!(actual, expected); } diff --git a/contracts/src/token/erc20/extensions/permit.rs b/contracts/src/token/erc20/extensions/permit.rs index 029f680b6..ccdfa5e94 100644 --- a/contracts/src/token/erc20/extensions/permit.rs +++ b/contracts/src/token/erc20/extensions/permit.rs @@ -14,7 +14,7 @@ use alloc::{vec, vec::Vec}; -use alloy_primitives::{keccak256, Address, FixedBytes, B256, U256, U8}; +use alloy_primitives::{aliases::B32, keccak256, Address, B256, U256, U8}; use alloy_sol_types::SolType; use stylus_sdk::{block, call::MethodError, function_selector, prelude::*}; @@ -145,13 +145,13 @@ pub trait IErc20Permit: INonces { /// Solidity interface id associated with [`IErc20Permit`] trait. /// Computed as a XOR of selectors for each function in the trait. #[must_use] - fn interface_id() -> FixedBytes<4> + fn interface_id() -> B32 where Self: Sized, { - FixedBytes::<4>::new(function_selector!("DOMAIN_SEPARATOR",)) - ^ FixedBytes::<4>::new(function_selector!("nonces", Address,)) - ^ FixedBytes::<4>::new(function_selector!( + B32::new(function_selector!("DOMAIN_SEPARATOR",)) + ^ B32::new(function_selector!("nonces", Address,)) + ^ B32::new(function_selector!( "permit", Address, Address, U256, U256, U8, B256, B256 )) } diff --git a/contracts/src/token/erc20/extensions/wrapper.rs b/contracts/src/token/erc20/extensions/wrapper.rs index b50cba892..b0e1003c1 100644 --- a/contracts/src/token/erc20/extensions/wrapper.rs +++ b/contracts/src/token/erc20/extensions/wrapper.rs @@ -370,7 +370,7 @@ impl Erc20Wrapper { #[cfg(test)] mod tests { - use alloy_primitives::{uint, FixedBytes}; + use alloy_primitives::{aliases::B32, uint}; use motsu::prelude::*; use super::*; @@ -404,7 +404,7 @@ mod tests { #[public] impl IErc165 for DummyErc20Metadata { - fn supports_interface(&self, _interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, _interface_id: B32) -> bool { // dummy implementation, required by [`IErc20Metadata`] trait. true } @@ -1035,7 +1035,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x511f913e_u32.into(); + let expected: B32 = 0x511f913e_u32.into(); assert_eq!(actual, expected); } } diff --git a/contracts/src/token/erc20/mod.rs b/contracts/src/token/erc20/mod.rs index 368af8ea1..372546fff 100644 --- a/contracts/src/token/erc20/mod.rs +++ b/contracts/src/token/erc20/mod.rs @@ -6,7 +6,7 @@ //! [`Erc20`] applications. 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::{ call::MethodError, @@ -585,7 +585,7 @@ impl Erc20 { } impl IErc165 for Erc20 { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -593,10 +593,10 @@ impl IErc165 for Erc20 { #[cfg(test)] mod tests { - use alloy_primitives::{uint, Address, FixedBytes, U256}; + use alloy_primitives::{uint, Address, U256}; use motsu::prelude::*; - use super::{Approval, Erc20, Error, IErc165, IErc20, Transfer}; + use super::*; #[motsu::test] fn mint(contract: Contract, alice: Address) { @@ -948,7 +948,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x36372b07_u32.into(); + let expected: B32 = 0x36372b07_u32.into(); assert_eq!(actual, expected); } diff --git a/contracts/src/token/erc20/utils/safe_erc20.rs b/contracts/src/token/erc20/utils/safe_erc20.rs index 078b82089..c07909ced 100644 --- a/contracts/src/token/erc20/utils/safe_erc20.rs +++ b/contracts/src/token/erc20/utils/safe_erc20.rs @@ -11,7 +11,7 @@ use alloc::{vec, vec::Vec}; -use alloy_primitives::{Address, FixedBytes, U256}; +use alloy_primitives::{aliases::B32, Address, U256}; use alloy_sol_types::SolCall; use openzeppelin_stylus_proc::interface_id; pub use sol::*; @@ -399,7 +399,7 @@ impl SafeErc20 { } impl IErc165 for SafeErc20 { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -408,9 +408,9 @@ impl IErc165 for SafeErc20 { #[cfg(test)] mod tests { use motsu::prelude::Contract; - use stylus_sdk::alloy_primitives::{Address, FixedBytes}; + use stylus_sdk::alloy_primitives::Address; - use super::{ISafeErc20, SafeErc20}; + use super::*; use crate::utils::introspection::erc165::IErc165; #[test] @@ -446,7 +446,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0xf71993e3_u32.into(); + let expected: B32 = 0xf71993e3_u32.into(); assert_eq!(actual, expected); } diff --git a/contracts/src/token/erc721/extensions/consecutive.rs b/contracts/src/token/erc721/extensions/consecutive.rs index 6eda31690..1e2acda51 100644 --- a/contracts/src/token/erc721/extensions/consecutive.rs +++ b/contracts/src/token/erc721/extensions/consecutive.rs @@ -19,7 +19,10 @@ use alloc::{vec, vec::Vec}; -use alloy_primitives::{aliases::U96, uint, Address, FixedBytes, U256}; +use alloy_primitives::{ + aliases::{B32, U96}, + uint, Address, U256, +}; use stylus_sdk::{abi::Bytes, call::MethodError, evm, msg, prelude::*}; use crate::{ @@ -828,14 +831,14 @@ impl Erc721Consecutive { #[public] impl IErc165 for Erc721Consecutive { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } #[cfg(test)] mod tests { - use alloy_primitives::{uint, Address, FixedBytes, U256}; + use alloy_primitives::{uint, Address, U256}; use motsu::prelude::Contract; use super::*; @@ -1443,7 +1446,7 @@ mod tests { ) ); - let fake_interface_id: FixedBytes<4> = 0x12345678_u32.into(); + let fake_interface_id: B32 = 0x12345678_u32.into(); assert!(!contract.sender(alice).supports_interface(fake_interface_id)); } } diff --git a/contracts/src/token/erc721/extensions/enumerable.rs b/contracts/src/token/erc721/extensions/enumerable.rs index bd4be5a55..c4030ab35 100644 --- a/contracts/src/token/erc721/extensions/enumerable.rs +++ b/contracts/src/token/erc721/extensions/enumerable.rs @@ -11,7 +11,7 @@ use alloc::{vec, vec::Vec}; -use alloy_primitives::{uint, Address, FixedBytes, U256}; +use alloy_primitives::{aliases::B32, uint, Address, U256}; use openzeppelin_stylus_proc::interface_id; pub use sol::*; use stylus_sdk::{ @@ -170,7 +170,7 @@ impl IErc721Enumerable for Erc721Enumerable { #[public] impl IErc165 for Erc721Enumerable { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -388,7 +388,7 @@ mod tests { #[public] impl IErc165 for Erc721EnumerableTestExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id @@ -740,7 +740,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x780e9d63.into(); + let expected: B32 = 0x780e9d63.into(); assert_eq!(actual, expected); } diff --git a/contracts/src/token/erc721/extensions/metadata.rs b/contracts/src/token/erc721/extensions/metadata.rs index 5048ac770..7df27da14 100644 --- a/contracts/src/token/erc721/extensions/metadata.rs +++ b/contracts/src/token/erc721/extensions/metadata.rs @@ -118,7 +118,7 @@ impl Erc721Metadata { #[cfg(test)] mod tests { - use alloy_primitives::{Address, FixedBytes}; + use alloy_primitives::{aliases::B32, Address}; use motsu::prelude::Contract; use super::*; @@ -162,7 +162,7 @@ mod tests { #[public] impl IErc165 for Erc721MetadataExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -173,7 +173,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x5b5e139f.into(); + let expected: B32 = 0x5b5e139f.into(); assert_eq!(actual, expected); } @@ -189,7 +189,7 @@ mod tests { ::interface_id() )); - let fake_interface_id: FixedBytes<4> = 0x12345678_u32.into(); + let fake_interface_id: B32 = 0x12345678_u32.into(); assert!(!contract.sender(alice).supports_interface(fake_interface_id)); } diff --git a/contracts/src/token/erc721/extensions/uri_storage.rs b/contracts/src/token/erc721/extensions/uri_storage.rs index b43b2a04a..bd005621e 100644 --- a/contracts/src/token/erc721/extensions/uri_storage.rs +++ b/contracts/src/token/erc721/extensions/uri_storage.rs @@ -108,7 +108,7 @@ mod tests { utils::introspection::erc165::IErc165, }; const TOKEN_ID: U256 = uint!(1_U256); - use alloy_primitives::FixedBytes; + use alloy_primitives::aliases::B32; #[storage] struct Erc721MetadataExample { @@ -151,7 +151,7 @@ mod tests { #[public] impl IErc165 for Erc721MetadataExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -162,7 +162,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = 0x5b5e139f.into(); + let expected: B32 = 0x5b5e139f.into(); assert_eq!(actual, expected); } @@ -178,7 +178,7 @@ mod tests { ::interface_id() )); - let fake_interface_id: FixedBytes<4> = 0x12345678_u32.into(); + let fake_interface_id: B32 = 0x12345678_u32.into(); assert!(!contract.sender(alice).supports_interface(fake_interface_id)); } #[motsu::test] diff --git a/contracts/src/token/erc721/extensions/wrapper.rs b/contracts/src/token/erc721/extensions/wrapper.rs index c2d997527..b4825ac37 100644 --- a/contracts/src/token/erc721/extensions/wrapper.rs +++ b/contracts/src/token/erc721/extensions/wrapper.rs @@ -9,7 +9,7 @@ use alloc::{ vec::Vec, }; -use alloy_primitives::{Address, FixedBytes, U256}; +use alloy_primitives::{aliases::B32, Address, U256}; use openzeppelin_stylus_proc::interface_id; pub use sol::*; use stylus_sdk::{ @@ -202,7 +202,7 @@ pub trait IErc721Wrapper { from: Address, token_id: U256, data: Bytes, - ) -> Result, Self::Error>; + ) -> Result; /// Returns the underlying token. /// @@ -326,7 +326,7 @@ impl Erc721Wrapper { token_id: U256, _data: &Bytes, erc721: &mut Erc721, - ) -> Result, Error> { + ) -> Result { let sender = msg::sender(); if self.underlying() != sender { return Err(Error::UnsupportedToken(ERC721UnsupportedToken { @@ -541,7 +541,7 @@ mod tests { from: Address, token_id: U256, data: Bytes, - ) -> Result, Error> { + ) -> Result { self.wrapper.on_erc721_received( operator, from, @@ -554,7 +554,7 @@ mod tests { #[public] impl IErc165 for Erc721WrapperTestExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } diff --git a/contracts/src/token/erc721/mod.rs b/contracts/src/token/erc721/mod.rs index ec52784f6..ecd600425 100644 --- a/contracts/src/token/erc721/mod.rs +++ b/contracts/src/token/erc721/mod.rs @@ -5,7 +5,7 @@ use alloc::{ vec::Vec, }; -use alloy_primitives::{uint, Address, FixedBytes, U128, U256}; +use alloy_primitives::{aliases::B32, uint, Address, U128, U256}; use openzeppelin_stylus_proc::interface_id; use stylus_sdk::{ abi::Bytes, @@ -503,7 +503,7 @@ impl IErc721 for Erc721 { #[public] impl IErc165 for Erc721 { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || ::interface_id() == interface_id } @@ -1057,7 +1057,7 @@ impl Erc721 { #[cfg(test)] mod tests { - use alloy_primitives::{fixed_bytes, uint, Address, FixedBytes, U256}; + use alloy_primitives::{aliases::B32, fixed_bytes, uint, Address, U256}; use motsu::prelude::*; use stylus_sdk::{abi::Bytes, prelude::*}; @@ -2689,7 +2689,7 @@ mod tests { #[motsu::test] fn interface_id() { let actual = ::interface_id(); - let expected: FixedBytes<4> = fixed_bytes!("80ac58cd"); + let expected: B32 = fixed_bytes!("80ac58cd"); assert_eq!(actual, expected); } @@ -2723,7 +2723,7 @@ mod tests { _from: Address, token_id: U256, _data: Bytes, - ) -> FixedBytes<4> { + ) -> B32 { self._received_token_id.set(token_id); fixed_bytes!("150b7a02") } diff --git a/contracts/src/token/erc721/receiver.rs b/contracts/src/token/erc721/receiver.rs index 432ea772a..e61124904 100644 --- a/contracts/src/token/erc721/receiver.rs +++ b/contracts/src/token/erc721/receiver.rs @@ -4,14 +4,18 @@ #![cfg_attr(coverage_nightly, coverage(off))] 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, function_selector, prelude::*}; /// The expected value returned from [`IErc721Receiver::on_erc721_received`]. -pub const RECEIVER_FN_SELECTOR: FixedBytes<4> = FixedBytes::new( - function_selector!("onERC721Received", Address, Address, U256, Bytes,), -); +pub const RECEIVER_FN_SELECTOR: B32 = B32::new(function_selector!( + "onERC721Received", + Address, + Address, + U256, + Bytes, +)); sol_interface! { /// [`super::Erc721`] token receiver Solidity interface. @@ -66,5 +70,5 @@ pub trait IErc721Receiver { from: Address, token_id: U256, data: Bytes, - ) -> Result, Self::Error>; + ) -> Result; } diff --git a/contracts/src/token/erc721/utils/holder.rs b/contracts/src/token/erc721/utils/holder.rs index 34d1a57d6..83610e39a 100644 --- a/contracts/src/token/erc721/utils/holder.rs +++ b/contracts/src/token/erc721/utils/holder.rs @@ -1,7 +1,7 @@ //! Implementation of the [`IErc721Receiver`] trait. use alloc::{vec, vec::Vec}; -use alloy_primitives::{Address, FixedBytes, U256}; +use alloy_primitives::{aliases::B32, Address, U256}; use stylus_sdk::{abi::Bytes, function_selector, prelude::*}; use crate::token::erc721::receiver::{IErc721Receiver, RECEIVER_FN_SELECTOR}; @@ -25,7 +25,7 @@ impl IErc721Receiver for Erc721Holder { _from: Address, _token_id: U256, _data: Bytes, - ) -> Result, Self::Error> { + ) -> Result { Ok(RECEIVER_FN_SELECTOR) } } diff --git a/contracts/src/utils/introspection/erc165.rs b/contracts/src/utils/introspection/erc165.rs index 1ef9e4a1f..d3db5cc84 100644 --- a/contracts/src/utils/introspection/erc165.rs +++ b/contracts/src/utils/introspection/erc165.rs @@ -2,7 +2,7 @@ //! //! [ERC]: https://eips.ethereum.org/EIPS/eip-165 -use alloy_primitives::FixedBytes; +use alloy_primitives::aliases::B32; use openzeppelin_stylus_proc::interface_id; /// Interface of the ERC-165 standard, as defined in the [ERC]. @@ -14,7 +14,7 @@ use openzeppelin_stylus_proc::interface_id; /// /// ```rust,ignore /// impl IErc165 for Erc20 { -/// fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { +/// fn supports_interface(&self, interface_id: B32) -> bool { /// ::interface_id() == interface_id /// || ::interface_id() == interface_id /// } @@ -34,5 +34,5 @@ pub trait IErc165 { /// * `interface_id` - The interface identifier, as specified in the [ERC]. /// /// [ERC]: https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool; + fn supports_interface(&self, interface_id: B32) -> bool; } diff --git a/docs/modules/ROOT/pages/erc1155-burnable.adoc b/docs/modules/ROOT/pages/erc1155-burnable.adoc index 8aae8c3f9..545dd5957 100644 --- a/docs/modules/ROOT/pages/erc1155-burnable.adoc +++ b/docs/modules/ROOT/pages/erc1155-burnable.adoc @@ -127,7 +127,7 @@ impl IErc1155 for Erc1155Example { #[public] impl IErc165 for Erc1155Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc1155.supports_interface(interface_id) } } diff --git a/docs/modules/ROOT/pages/erc1155-metadata-uri.adoc b/docs/modules/ROOT/pages/erc1155-metadata-uri.adoc index bef5b68b8..3ad1906da 100644 --- a/docs/modules/ROOT/pages/erc1155-metadata-uri.adoc +++ b/docs/modules/ROOT/pages/erc1155-metadata-uri.adoc @@ -99,7 +99,7 @@ impl IErc1155MetadataUri for Erc1155MetadataUriExample { #[public] impl IErc165 for Erc1155MetadataUriExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc1155.supports_interface(interface_id) || self.metadata_uri.supports_interface(interface_id) } diff --git a/docs/modules/ROOT/pages/erc1155-pausable.adoc b/docs/modules/ROOT/pages/erc1155-pausable.adoc index ee3cb3230..a350f3f4b 100644 --- a/docs/modules/ROOT/pages/erc1155-pausable.adoc +++ b/docs/modules/ROOT/pages/erc1155-pausable.adoc @@ -169,7 +169,7 @@ impl IErc1155 for Erc1155Example { #[public] impl IErc165 for Erc1155Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc1155.supports_interface(interface_id) } } diff --git a/docs/modules/ROOT/pages/erc1155-supply.adoc b/docs/modules/ROOT/pages/erc1155-supply.adoc index 0e219cf1a..dddf1afb3 100644 --- a/docs/modules/ROOT/pages/erc1155-supply.adoc +++ b/docs/modules/ROOT/pages/erc1155-supply.adoc @@ -123,7 +123,7 @@ impl IErc1155 for Erc1155Example { #[public] impl IErc165 for Erc1155Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc1155_supply.supports_interface(interface_id) } } diff --git a/docs/modules/ROOT/pages/erc1155-uri-storage.adoc b/docs/modules/ROOT/pages/erc1155-uri-storage.adoc index ffa7fface..38cb6e2bc 100644 --- a/docs/modules/ROOT/pages/erc1155-uri-storage.adoc +++ b/docs/modules/ROOT/pages/erc1155-uri-storage.adoc @@ -113,7 +113,7 @@ impl IErc1155MetadataUri for Erc1155MetadataUriExample { #[public] impl IErc165 for Erc1155MetadataUriExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc1155.supports_interface(interface_id) || self.metadata_uri.supports_interface(interface_id) } diff --git a/docs/modules/ROOT/pages/erc20-metadata.adoc b/docs/modules/ROOT/pages/erc20-metadata.adoc index adeb31809..6a4a52d0d 100644 --- a/docs/modules/ROOT/pages/erc20-metadata.adoc +++ b/docs/modules/ROOT/pages/erc20-metadata.adoc @@ -94,7 +94,7 @@ impl IErc20Metadata for Erc20Example { #[public] impl IErc165 for Erc20Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc20.supports_interface(interface_id) || self.metadata.supports_interface(interface_id) } diff --git a/docs/modules/ROOT/pages/erc20.adoc b/docs/modules/ROOT/pages/erc20.adoc index 4dd9dc2c6..38525461f 100644 --- a/docs/modules/ROOT/pages/erc20.adoc +++ b/docs/modules/ROOT/pages/erc20.adoc @@ -100,7 +100,7 @@ impl IErc20Metadata for GLDToken { #[public] impl IErc165 for GLDToken { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc20.supports_interface(interface_id) || self.metadata.supports_interface(interface_id) } diff --git a/docs/modules/ROOT/pages/erc4626.adoc b/docs/modules/ROOT/pages/erc4626.adoc index cdfe9c6c3..3b1bed423 100644 --- a/docs/modules/ROOT/pages/erc4626.adoc +++ b/docs/modules/ROOT/pages/erc4626.adoc @@ -196,7 +196,7 @@ impl IErc20Metadata for Erc4626Example { #[public] impl IErc165 for Erc4626Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || self.erc20.supports_interface(interface_id) || self.metadata.supports_interface(interface_id) diff --git a/docs/modules/ROOT/pages/erc721-burnable.adoc b/docs/modules/ROOT/pages/erc721-burnable.adoc index fc3394e51..09f93e953 100644 --- a/docs/modules/ROOT/pages/erc721-burnable.adoc +++ b/docs/modules/ROOT/pages/erc721-burnable.adoc @@ -106,7 +106,7 @@ impl IErc721Burnable for Erc721Example { #[public] impl IErc165 for Erc721Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } diff --git a/docs/modules/ROOT/pages/erc721-consecutive.adoc b/docs/modules/ROOT/pages/erc721-consecutive.adoc index a89ac027d..2595978c0 100644 --- a/docs/modules/ROOT/pages/erc721-consecutive.adoc +++ b/docs/modules/ROOT/pages/erc721-consecutive.adoc @@ -110,7 +110,7 @@ impl IErc721 for Erc721ConsecutiveExample { #[public] impl IErc165 for Erc721ConsecutiveExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } diff --git a/docs/modules/ROOT/pages/erc721-enumerable.adoc b/docs/modules/ROOT/pages/erc721-enumerable.adoc index 0741c76e8..03a37596a 100644 --- a/docs/modules/ROOT/pages/erc721-enumerable.adoc +++ b/docs/modules/ROOT/pages/erc721-enumerable.adoc @@ -256,7 +256,7 @@ impl IErc721Enumerable for Erc721Example { #[public] impl IErc165 for Erc721Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) || self.enumerable.supports_interface(interface_id) } diff --git a/docs/modules/ROOT/pages/erc721-metadata.adoc b/docs/modules/ROOT/pages/erc721-metadata.adoc index ee9633a6d..52a238204 100644 --- a/docs/modules/ROOT/pages/erc721-metadata.adoc +++ b/docs/modules/ROOT/pages/erc721-metadata.adoc @@ -128,7 +128,7 @@ impl IErc721Metadata for Erc721MetadataExample { #[public] impl IErc165 for Erc721MetadataExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) || ::interface_id() == interface_id } diff --git a/docs/modules/ROOT/pages/erc721-pausable.adoc b/docs/modules/ROOT/pages/erc721-pausable.adoc index f5e7a99ff..e55392908 100644 --- a/docs/modules/ROOT/pages/erc721-pausable.adoc +++ b/docs/modules/ROOT/pages/erc721-pausable.adoc @@ -166,7 +166,7 @@ impl IPausable for Erc721Example { #[public] impl IErc165 for Erc721Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } diff --git a/docs/modules/ROOT/pages/erc721-uri-storage.adoc b/docs/modules/ROOT/pages/erc721-uri-storage.adoc index 642d7b14d..693e64b6d 100644 --- a/docs/modules/ROOT/pages/erc721-uri-storage.adoc +++ b/docs/modules/ROOT/pages/erc721-uri-storage.adoc @@ -146,7 +146,7 @@ impl IErc721UriStorage for Erc721MetadataExample {} #[public] impl IErc165 for Erc721MetadataExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) || ::interface_id() == interface_id } diff --git a/docs/modules/ROOT/pages/erc721-wrapper.adoc b/docs/modules/ROOT/pages/erc721-wrapper.adoc index 2aac2471c..2eb4a5619 100644 --- a/docs/modules/ROOT/pages/erc721-wrapper.adoc +++ b/docs/modules/ROOT/pages/erc721-wrapper.adoc @@ -133,7 +133,7 @@ impl IErc721Wrapper for Erc721WrapperExample { from: Address, token_id: U256, data: Bytes, - ) -> Result, Self::Error> { + ) -> Result { self.erc721_wrapper.on_erc721_received( operator, from, @@ -146,7 +146,7 @@ impl IErc721Wrapper for Erc721WrapperExample { #[public] impl IErc165 for Erc721WrapperExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } diff --git a/docs/modules/ROOT/pages/erc721.adoc b/docs/modules/ROOT/pages/erc721.adoc index d611fc9d8..1773047bb 100644 --- a/docs/modules/ROOT/pages/erc721.adoc +++ b/docs/modules/ROOT/pages/erc721.adoc @@ -142,7 +142,7 @@ impl IErc721Metadata for GameItem { #[public] impl IErc165 for GameItem { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) || ::interface_id() == interface_id } diff --git a/docs/modules/ROOT/pages/utilities.adoc b/docs/modules/ROOT/pages/utilities.adoc index 6785ee34d..43636665f 100644 --- a/docs/modules/ROOT/pages/utilities.adoc +++ b/docs/modules/ROOT/pages/utilities.adoc @@ -29,7 +29,7 @@ impl Erc721Example { #[public] impl IErc165 for Erc721Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } diff --git a/examples/access-control/src/lib.rs b/examples/access-control/src/lib.rs index 6d910b89b..f656e403b 100644 --- a/examples/access-control/src/lib.rs +++ b/examples/access-control/src/lib.rs @@ -13,7 +13,7 @@ use openzeppelin_stylus::{ utils::introspection::erc165::IErc165, }; use stylus_sdk::{ - alloy_primitives::{Address, FixedBytes, B256, U256}, + alloy_primitives::{aliases::B32, Address, B256, U256}, msg, prelude::*, }; @@ -220,7 +220,7 @@ impl IAccessControlEnumerable for AccessControlExample { #[public] impl IErc165 for AccessControlExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.access.supports_interface(interface_id) || self.access_enumerable.supports_interface(interface_id) || self.erc20.supports_interface(interface_id) diff --git a/examples/basic/token/src/lib.rs b/examples/basic/token/src/lib.rs index a2d3e4cfa..61b448500 100644 --- a/examples/basic/token/src/lib.rs +++ b/examples/basic/token/src/lib.rs @@ -12,7 +12,7 @@ use openzeppelin_stylus::{ utils::introspection::erc165::IErc165, }; use stylus_sdk::{ - alloy_primitives::{Address, FixedBytes, U256, U8}, + alloy_primitives::{aliases::B32, Address, U256, U8}, prelude::*, }; @@ -99,7 +99,7 @@ impl IErc20Metadata for Erc20Example { #[public] impl IErc165 for Erc20Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc20.supports_interface(interface_id) || self.metadata.supports_interface(interface_id) } diff --git a/examples/erc1155-metadata-uri/src/lib.rs b/examples/erc1155-metadata-uri/src/lib.rs index 6996a623c..488b26a6e 100644 --- a/examples/erc1155-metadata-uri/src/lib.rs +++ b/examples/erc1155-metadata-uri/src/lib.rs @@ -15,7 +15,7 @@ use openzeppelin_stylus::{ }; use stylus_sdk::{ abi::Bytes, - alloy_primitives::{Address, FixedBytes, U256}, + alloy_primitives::{aliases::B32, Address, U256}, prelude::*, }; @@ -106,7 +106,7 @@ impl IErc1155MetadataUri for Erc1155MetadataUriExample { #[public] impl IErc165 for Erc1155MetadataUriExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc1155.supports_interface(interface_id) || self.metadata_uri.supports_interface(interface_id) } diff --git a/examples/erc1155-supply/src/lib.rs b/examples/erc1155-supply/src/lib.rs index cdf2c6194..d0e75004d 100644 --- a/examples/erc1155-supply/src/lib.rs +++ b/examples/erc1155-supply/src/lib.rs @@ -14,7 +14,7 @@ use openzeppelin_stylus::{ }; use stylus_sdk::{ abi::Bytes, - alloy_primitives::{Address, FixedBytes, U256}, + alloy_primitives::{aliases::B32, Address, U256}, prelude::*, }; @@ -143,7 +143,7 @@ impl IErc1155Supply for Erc1155Example { #[public] impl IErc165 for Erc1155Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc1155_supply.supports_interface(interface_id) } } diff --git a/examples/erc1155-supply/tests/mock/receiver.rs b/examples/erc1155-supply/tests/mock/receiver.rs index 6959954ab..15e7f0168 100644 --- a/examples/erc1155-supply/tests/mock/receiver.rs +++ b/examples/erc1155-supply/tests/mock/receiver.rs @@ -1,13 +1,13 @@ #![allow(dead_code)] #![cfg(feature = "e2e")] use alloy::{ - primitives::{Address, FixedBytes, U256}, + primitives::{aliases::B32, Address, U256}, sol, }; use e2e::Wallet; use stylus_sdk::{abi::Bytes, function_selector}; -const REC_RETVAL: FixedBytes<4> = FixedBytes(function_selector!( +const REC_RETVAL: B32 = B32::new(function_selector!( "onERC1155Received", Address, Address, @@ -16,7 +16,7 @@ const REC_RETVAL: FixedBytes<4> = FixedBytes(function_selector!( Bytes )); -const BAT_RETVAL: FixedBytes<4> = FixedBytes(function_selector!( +const BAT_RETVAL: B32 = B32::new(function_selector!( "onERC1155BatchReceived", Address, Address, diff --git a/examples/erc1155/src/ERC1155ReceiverMock.sol b/examples/erc1155/src/ERC1155ReceiverMock.sol deleted file mode 100644 index 0ff6e73bc..000000000 --- a/examples/erc1155/src/ERC1155ReceiverMock.sol +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.21; - -import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.1.0/contracts/token/ERC1155/IERC1155Receiver.sol"; -import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.1.0/contracts/utils/introspection/ERC165.sol"; - -contract ERC1155ReceiverMock is ERC165, IERC1155Receiver { - enum RevertType { - None, - RevertWithoutMessage, - RevertWithMessage, - RevertWithCustomError, - Panic - } - - bytes4 private immutable _recRetval; - bytes4 private immutable _batRetval; - RevertType private immutable _error; - - event Received(address operator, address from, uint256 id, uint256 value, bytes data); - event BatchReceived(address operator, address from, uint256[] ids, uint256[] values, bytes data); - error CustomError(bytes4); - - constructor(bytes4 recRetval, bytes4 batRetval, RevertType error) { - _recRetval = recRetval; - _batRetval = batRetval; - _error = error; - } - - function onERC1155Received( - address operator, - address from, - uint256 id, - uint256 value, - bytes calldata data - ) external returns (bytes4) { - if (_error == RevertType.RevertWithoutMessage) { - revert(); - } else if (_error == RevertType.RevertWithMessage) { - revert("ERC1155ReceiverMock: reverting on receive"); - } else if (_error == RevertType.RevertWithCustomError) { - revert CustomError(_recRetval); - } else if (_error == RevertType.Panic) { - uint256 a = uint256(0) / uint256(0); - a; - } - - emit Received(operator, from, id, value, data); - return _recRetval; - } - - function onERC1155BatchReceived( - address operator, - address from, - uint256[] calldata ids, - uint256[] calldata values, - bytes calldata data - ) external returns (bytes4) { - if (_error == RevertType.RevertWithoutMessage) { - revert(); - } else if (_error == RevertType.RevertWithMessage) { - revert("ERC1155ReceiverMock: reverting on batch receive"); - } else if (_error == RevertType.RevertWithCustomError) { - revert CustomError(_recRetval); - } else if (_error == RevertType.Panic) { - uint256 a = uint256(0) / uint256(0); - a; - } - - emit BatchReceived(operator, from, ids, values, data); - return _batRetval; - } -} diff --git a/examples/erc1155/src/lib.rs b/examples/erc1155/src/lib.rs index f5412ce53..8d21a0f12 100644 --- a/examples/erc1155/src/lib.rs +++ b/examples/erc1155/src/lib.rs @@ -10,7 +10,7 @@ use openzeppelin_stylus::{ }; use stylus_sdk::{ abi::Bytes, - alloy_primitives::{Address, FixedBytes, U256}, + alloy_primitives::{aliases::B32, Address, U256}, prelude::*, }; @@ -120,7 +120,7 @@ impl IErc1155Burnable for Erc1155Example { #[public] impl IErc165 for Erc1155Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc1155.supports_interface(interface_id) } } diff --git a/examples/erc1155/tests/mock/receiver.rs b/examples/erc1155/tests/mock/receiver.rs index 6959954ab..15e7f0168 100644 --- a/examples/erc1155/tests/mock/receiver.rs +++ b/examples/erc1155/tests/mock/receiver.rs @@ -1,13 +1,13 @@ #![allow(dead_code)] #![cfg(feature = "e2e")] use alloy::{ - primitives::{Address, FixedBytes, U256}, + primitives::{aliases::B32, Address, U256}, sol, }; use e2e::Wallet; use stylus_sdk::{abi::Bytes, function_selector}; -const REC_RETVAL: FixedBytes<4> = FixedBytes(function_selector!( +const REC_RETVAL: B32 = B32::new(function_selector!( "onERC1155Received", Address, Address, @@ -16,7 +16,7 @@ const REC_RETVAL: FixedBytes<4> = FixedBytes(function_selector!( Bytes )); -const BAT_RETVAL: FixedBytes<4> = FixedBytes(function_selector!( +const BAT_RETVAL: B32 = B32::new(function_selector!( "onERC1155BatchReceived", Address, Address, diff --git a/examples/erc20-flash-mint/src/lib.rs b/examples/erc20-flash-mint/src/lib.rs index 795c3e230..66eee1590 100644 --- a/examples/erc20-flash-mint/src/lib.rs +++ b/examples/erc20-flash-mint/src/lib.rs @@ -12,7 +12,7 @@ use openzeppelin_stylus::{ }; use stylus_sdk::{ abi::Bytes, - alloy_primitives::{Address, FixedBytes, U256}, + alloy_primitives::{aliases::B32, Address, U256}, prelude::*, }; @@ -124,7 +124,7 @@ impl IErc20 for Erc20FlashMintExample { #[public] impl IErc165 for Erc20FlashMintExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || self.erc20.supports_interface(interface_id) } diff --git a/examples/erc20/src/lib.rs b/examples/erc20/src/lib.rs index 19ab648da..0020b12b9 100644 --- a/examples/erc20/src/lib.rs +++ b/examples/erc20/src/lib.rs @@ -15,7 +15,7 @@ use openzeppelin_stylus::{ utils::{introspection::erc165::IErc165, pausable, IPausable, Pausable}, }; use stylus_sdk::{ - alloy_primitives::{uint, Address, FixedBytes, U256, U8}, + alloy_primitives::{aliases::B32, uint, Address, U256, U8}, prelude::*, }; @@ -201,7 +201,7 @@ impl IErc20Metadata for Erc20Example { #[public] impl IErc165 for Erc20Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { Erc20::supports_interface(&self.erc20, interface_id) || Erc20Metadata::supports_interface(&self.metadata, interface_id) } diff --git a/examples/erc4626/src/lib.rs b/examples/erc4626/src/lib.rs index 20770be37..e6d375aa0 100644 --- a/examples/erc4626/src/lib.rs +++ b/examples/erc4626/src/lib.rs @@ -13,7 +13,7 @@ use openzeppelin_stylus::{ utils::introspection::erc165::IErc165, }; use stylus_sdk::{ - alloy_primitives::{Address, FixedBytes, U256, U8}, + alloy_primitives::{aliases::B32, Address, U256, U8}, prelude::*, }; @@ -187,7 +187,7 @@ impl IErc20Metadata for Erc4626Example { #[public] impl IErc165 for Erc4626Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { ::interface_id() == interface_id || self.erc20.supports_interface(interface_id) || self.metadata.supports_interface(interface_id) diff --git a/examples/erc721-consecutive/src/lib.rs b/examples/erc721-consecutive/src/lib.rs index 9fabbb097..e98c73024 100644 --- a/examples/erc721-consecutive/src/lib.rs +++ b/examples/erc721-consecutive/src/lib.rs @@ -1,7 +1,10 @@ #![cfg_attr(not(any(test, feature = "export-abi")), no_main)] extern crate alloc; -use alloy_primitives::{aliases::U96, Address, FixedBytes, U256}; +use alloy_primitives::{ + aliases::{B32, U96}, + Address, U256, +}; use openzeppelin_stylus::{ token::erc721::{ extensions::{consecutive, Erc721Consecutive, IErc721Burnable}, @@ -121,7 +124,7 @@ impl IErc721Burnable for Erc721ConsecutiveExample { #[public] impl IErc165 for Erc721ConsecutiveExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } diff --git a/examples/erc721-metadata/src/lib.rs b/examples/erc721-metadata/src/lib.rs index ac218ba4a..53150f97c 100644 --- a/examples/erc721-metadata/src/lib.rs +++ b/examples/erc721-metadata/src/lib.rs @@ -16,7 +16,7 @@ use openzeppelin_stylus::{ }; use stylus_sdk::{ abi::Bytes, - alloy_primitives::{Address, FixedBytes, U256}, + alloy_primitives::{aliases::B32, Address, U256}, prelude::*, }; @@ -147,7 +147,7 @@ impl IErc721UriStorage for Erc721MetadataExample {} #[public] impl IErc165 for Erc721MetadataExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) || ::interface_id() == interface_id } diff --git a/examples/erc721-wrapper/src/lib.rs b/examples/erc721-wrapper/src/lib.rs index 4514dd474..eb3d39fd2 100644 --- a/examples/erc721-wrapper/src/lib.rs +++ b/examples/erc721-wrapper/src/lib.rs @@ -13,7 +13,7 @@ use openzeppelin_stylus::{ }; use stylus_sdk::{ abi::Bytes, - alloy_primitives::{Address, FixedBytes, U256}, + alloy_primitives::{aliases::B32, Address, U256}, prelude::*, }; @@ -137,7 +137,7 @@ impl IErc721Wrapper for Erc721WrapperExample { from: Address, token_id: U256, data: Bytes, - ) -> Result, Self::Error> { + ) -> Result { self.erc721_wrapper.on_erc721_received( operator, from, @@ -150,7 +150,7 @@ impl IErc721Wrapper for Erc721WrapperExample { #[public] impl IErc165 for Erc721WrapperExample { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) } } diff --git a/examples/erc721/src/lib.rs b/examples/erc721/src/lib.rs index 1e38c5899..9af363dbc 100644 --- a/examples/erc721/src/lib.rs +++ b/examples/erc721/src/lib.rs @@ -15,7 +15,7 @@ use openzeppelin_stylus::{ }; use stylus_sdk::{ abi::Bytes, - alloy_primitives::{Address, FixedBytes, U256}, + alloy_primitives::{aliases::B32, Address, U256}, prelude::*, }; @@ -275,7 +275,7 @@ impl IErc721Enumerable for Erc721Example { #[public] impl IErc165 for Erc721Example { - fn supports_interface(&self, interface_id: FixedBytes<4>) -> bool { + fn supports_interface(&self, interface_id: B32) -> bool { self.erc721.supports_interface(interface_id) || self.enumerable.supports_interface(interface_id) } diff --git a/examples/erc721/tests/mock/receiver.rs b/examples/erc721/tests/mock/receiver.rs index 9c12742ab..c8de4d26d 100644 --- a/examples/erc721/tests/mock/receiver.rs +++ b/examples/erc721/tests/mock/receiver.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] #![cfg(feature = "e2e")] use alloy::{ - primitives::{Address, FixedBytes, U256}, + primitives::{aliases::B32, Address, U256}, sol, }; use e2e::Wallet; @@ -56,7 +56,7 @@ sol! { } } -const RET_VAL: FixedBytes<4> = FixedBytes(function_selector!( +const RET_VAL: B32 = B32::new(function_selector!( "onERC721Received", Address, Address,