Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bidzyyys committed Feb 13, 2025
1 parent a6e0c18 commit c5f38a2
Show file tree
Hide file tree
Showing 54 changed files with 235 additions and 254 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ all = "warn"

[workspace.dependencies]
# Stylus SDK related
stylus-sdk = { version = "0.8.0", default-features = false, features = [
stylus-sdk = { version = "0.8.1-alpha.1", default-features = false, features = [
"mini-alloc",
] }

Expand Down
33 changes: 18 additions & 15 deletions contracts/src/access/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//!
//! ```rust,ignore
//! pub fn foo() {
//! assert!(self.has_role(MY_ROLE.into(), msg::sender()));
//! assert!(self.has_role(MY_ROLE.into(), self.vm().msg_sender()));
//! // ...
//! }
//! ```
Expand All @@ -39,16 +39,14 @@
//! taken to secure accounts that have been granted it. We recommend using
//! `AccessControlDefaultAdminRules` to enforce additional security measures for
//! this role.
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};

use alloy_primitives::{Address, FixedBytes, B256};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
evm, msg,
prelude::storage,
prelude::*,
storage::{StorageBool, StorageFixedBytes, StorageMap},
stylus_proc::{public, SolidityError},
};

#[cfg_attr(coverage_nightly, coverage(off))]
Expand Down Expand Up @@ -250,7 +248,7 @@ impl IAccessControl for AccessControl {
}

fn only_role(&self, role: B256) -> Result<(), Self::Error> {
self._check_role(role, msg::sender())
self._check_role(role, self.vm().msg_sender())
}

#[must_use]
Expand Down Expand Up @@ -285,7 +283,7 @@ impl IAccessControl for AccessControl {
role: B256,
confirmation: Address,
) -> Result<(), Self::Error> {
if msg::sender() != confirmation {
if self.vm().msg_sender() != confirmation {
return Err(Error::BadConfirmation(
AccessControlBadConfirmation {},
));
Expand Down Expand Up @@ -314,11 +312,10 @@ impl AccessControl {
pub fn _set_role_admin(&mut self, role: B256, new_admin_role: B256) {
let previous_admin_role = self.get_role_admin(role);
self.roles.setter(role).admin_role.set(new_admin_role);
evm::log(RoleAdminChanged {
role,
previous_admin_role,
new_admin_role,
});
log(
self.vm(),
RoleAdminChanged { role, previous_admin_role, new_admin_role },
);
}

/// Checks if `account` has been granted `role`.
Expand Down Expand Up @@ -366,7 +363,10 @@ impl AccessControl {
false
} else {
self.roles.setter(role).has_role.insert(account, true);
evm::log(RoleGranted { role, account, sender: msg::sender() });
log(
self.vm(),
RoleGranted { role, account, sender: self.vm().msg_sender() },
);
true
}
}
Expand All @@ -388,7 +388,10 @@ impl AccessControl {
pub fn _revoke_role(&mut self, role: B256, account: Address) -> bool {
if self.has_role(role, account) {
self.roles.setter(role).has_role.insert(account, false);
evm::log(RoleRevoked { role, account, sender: msg::sender() });
log(
self.vm(),
RoleRevoked { role, account, sender: self.vm().msg_sender() },
);
true
} else {
false
Expand All @@ -400,7 +403,7 @@ impl AccessControl {
mod tests {
use alloy_primitives::Address;
use motsu::prelude::Contract;
use stylus_sdk::prelude::TopLevelStorage;
use stylus_sdk::prelude::*;

use super::{AccessControl, Error, IAccessControl};

Expand Down
16 changes: 5 additions & 11 deletions contracts/src/access/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@
//! This module is used through inheritance. It will make available the
//! [`Ownable::only_owner`] function, which can be called to restrict operations
//! to the owner.
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};

use alloy_primitives::Address;
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
call::MethodError,
evm, msg,
prelude::storage,
storage::StorageAddress,
stylus_proc::{public, SolidityError},
};
use stylus_sdk::{call::MethodError, prelude::*, storage::StorageAddress};

#[cfg_attr(coverage_nightly, coverage(off))]
mod sol {
Expand Down Expand Up @@ -170,7 +164,7 @@ impl Ownable {
/// * [`Error::UnauthorizedAccount`] - If called by any account other than
/// the owner.
pub fn only_owner(&self) -> Result<(), Error> {
let account = msg::sender();
let account = self.vm().msg_sender();
if self.owner() != account {
return Err(Error::UnauthorizedAccount(
OwnableUnauthorizedAccount { account },
Expand All @@ -194,15 +188,15 @@ impl Ownable {
pub fn _transfer_ownership(&mut self, new_owner: Address) {
let previous_owner = self.owner.get();
self.owner.set(new_owner);
evm::log(OwnershipTransferred { previous_owner, new_owner });
log(self.vm(), OwnershipTransferred { previous_owner, new_owner });
}
}

#[cfg(all(test, feature = "std"))]
mod tests {
use alloy_primitives::Address;
use motsu::prelude::Contract;
use stylus_sdk::prelude::TopLevelStorage;
use stylus_sdk::prelude::*;

use super::{Error, IOwnable, Ownable};

Expand Down
24 changes: 11 additions & 13 deletions contracts/src/access/ownable_two_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@
//! This module uses [`Ownable`] as a member, and makes all its public functions
//! available.
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};

use alloy_primitives::Address;
pub use sol::*;
use stylus_sdk::{
evm, msg,
prelude::storage,
storage::StorageAddress,
stylus_proc::{public, SolidityError},
};
use stylus_sdk::{prelude::*, storage::StorageAddress};

use crate::access::ownable::{
Error as OwnableError, IOwnable, Ownable, OwnableUnauthorizedAccount,
Expand Down Expand Up @@ -172,15 +167,18 @@ impl IOwnable2Step for Ownable2Step {
self.pending_owner.set(new_owner);

let current_owner = self.owner();
evm::log(OwnershipTransferStarted {
previous_owner: current_owner,
new_owner,
});
log(
self.vm(),
OwnershipTransferStarted {
previous_owner: current_owner,
new_owner,
},
);
Ok(())
}

fn accept_ownership(&mut self) -> Result<(), Self::Error> {
let sender = msg::sender();
let sender = self.vm().msg_sender();
let pending_owner = self.pending_owner();
if sender != pending_owner {
return Err(OwnableError::UnauthorizedAccount(
Expand Down Expand Up @@ -225,7 +223,7 @@ impl Ownable2Step {
mod tests {
use alloy_primitives::Address;
use motsu::prelude::Contract;
use stylus_sdk::prelude::TopLevelStorage;
use stylus_sdk::prelude::*;

use super::{Error, IOwnable2Step, Ownable2Step, OwnableError};

Expand Down
13 changes: 6 additions & 7 deletions contracts/src/finance/vesting_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@
//! adjustment in the vesting schedule to ensure the vested amount is as
//! intended.
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};

use alloy_primitives::{Address, U256, U64};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
block,
call::{self, call, Call},

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / stable

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / stable

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / wasm32-unknown-unknown

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / wasm32-unknown-unknown

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / nightly / coverage

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / nightly / coverage

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / macos-latest / stable

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / macos-latest / stable

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / Check WASM binary

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / Check WASM binary

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / stable / features

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / stable / features

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / Gas usage report

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / Gas usage report

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 35 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead
contract, evm, function_selector,
prelude::storage,
storage::{StorageMap, StorageU256, StorageU64, TopLevelStorage},
stylus_proc::{public, SolidityError},
contract, function_selector,
prelude::*,
storage::{StorageMap, StorageU256, StorageU64},
};

use crate::{
Expand Down Expand Up @@ -421,7 +420,7 @@ impl IVestingWallet for VestingWallet {

call(Call::new_in(self).value(amount), owner, &[])?;

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / nightly / doc

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / stable

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / wasm32-unknown-unknown

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / wasm32-unknown-unknown

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / beta

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / nightly / coverage

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / macos-latest / stable

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / Check WASM binary

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / Check WASM binary

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / stable / features

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / ubuntu / stable / features

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / Gas usage report

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / Gas usage report

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated function `stylus_sdk::call::call`: Use the .vm() method available on Stylus contracts instead to access host environment methods

Check warning on line 421 in contracts/src/finance/vesting_wallet.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `stylus_sdk::call::Call`: Use the Call struct defined in stylus_core::calls::context instead

evm::log(EtherReleased { amount });
log(self.vm(), EtherReleased { amount });

Ok(())
}
Expand All @@ -438,7 +437,7 @@ impl IVestingWallet for VestingWallet {

self.safe_erc20.safe_transfer(token, owner, amount)?;

evm::log(ERC20Released { token, amount });
log(self.vm(), ERC20Released { token, amount });

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/token/erc1155/extensions/burnable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloc::vec::Vec;

use alloy_primitives::{Address, U256};
use stylus_sdk::msg;
use stylus_sdk::prelude::*;

use crate::token::erc1155::{
self, ERC1155MissingApprovalForAll, Erc1155, IErc1155,
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Erc1155 {
&self,
account: Address,
) -> Result<(), erc1155::Error> {
let sender = msg::sender();
let sender = self.vm().msg_sender();
if account != sender && !self.is_approved_for_all(account, sender) {
return Err(erc1155::Error::MissingApprovalForAll(
ERC1155MissingApprovalForAll {
Expand Down
8 changes: 3 additions & 5 deletions contracts/src/token/erc1155/extensions/metadata_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
//!
//! [ERC]: https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions
use alloc::{string::String, vec::Vec};
use alloc::{string::String, vec, vec::Vec};

use alloy_primitives::{FixedBytes, U256};
use openzeppelin_stylus_proc::interface_id;
pub use sol::*;
use stylus_sdk::{
prelude::storage, storage::StorageString, stylus_proc::public,
};
use stylus_sdk::{prelude::*, storage::StorageString};

use crate::utils::introspection::erc165::{Erc165, IErc165};

Expand Down Expand Up @@ -76,7 +74,7 @@ impl IErc165 for Erc1155MetadataUri {
mod tests {
use alloy_primitives::Address;
use motsu::prelude::Contract;
use stylus_sdk::{alloy_primitives::uint, prelude::TopLevelStorage};
use stylus_sdk::{alloy_primitives::uint, prelude::*};

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

Expand Down
7 changes: 3 additions & 4 deletions contracts/src/token/erc1155/extensions/supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ use alloy_primitives::{Address, U256};
use openzeppelin_stylus_proc::interface_id;
use stylus_sdk::{
abi::Bytes,
msg,
prelude::{public, storage},
prelude::*,
storage::{StorageMap, StorageU256},
};

Expand Down Expand Up @@ -279,7 +278,7 @@ impl Erc1155Supply {

if !to.is_zero() {
self.erc1155._check_on_erc1155_received(
msg::sender(),
self.vm().msg_sender(),
from,
to,
erc1155::Erc1155ReceiverData::new(ids, values),
Expand Down Expand Up @@ -359,7 +358,7 @@ impl Erc1155Supply {
mod tests {
use alloy_primitives::{Address, U256};
use motsu::prelude::Contract;
use stylus_sdk::prelude::TopLevelStorage;
use stylus_sdk::prelude::*;

use super::{Erc1155Supply, IErc1155Supply};
use crate::token::erc1155::{
Expand Down
Loading

0 comments on commit c5f38a2

Please sign in to comment.