Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: make Rust docs consistent #497

Merged
merged 28 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
19c5277
ref: made rust docs consistent with format specified in #476
DarkLord017 Jan 15, 2025
96bbc2e
Merge branch 'OpenZeppelin:main' into ConsistentDocs
DarkLord017 Jan 15, 2025
adb2f80
chore: fmt
bidzyyys Jan 17, 2025
dc25581
ref: Fixed failing ci errors (ref: #476)
DarkLord017 Jan 18, 2025
4cf43a5
ref: Fixed merge conflicts in ERC1155 module
DarkLord017 Jan 18, 2025
697e2ca
ref: Made events consistent and fixed suggested changes regarding er…
DarkLord017 Jan 20, 2025
eeacf7e
ref: Made events consistent add description for required events(ref: …
DarkLord017 Jan 21, 2025
55ceec5
docs: improve docs for access contracts
bidzyyys Jan 21, 2025
0ce27d5
docs: improve docs for finance contracts.
bidzyyys Jan 21, 2025
a7cd278
docs: improve docs for erc1155
bidzyyys Jan 21, 2025
5cef690
docs: improve docs for erc20
bidzyyys Jan 21, 2025
7727782
docs: improve docs for erc721
bidzyyys Jan 21, 2025
9a4153b
docs: improve docs for utils
bidzyyys Jan 21, 2025
62c2f6b
docs: improve docs for crypto lib
bidzyyys Jan 21, 2025
89040e2
docs: remove redundant line
bidzyyys Jan 21, 2025
98406d0
docs: fix order in Erc721 Consecutive docs
bidzyyys Jan 21, 2025
c438661
docs: remove redundant line
bidzyyys Jan 21, 2025
c297553
Apply suggestions from code review (ref: #476)
DarkLord017 Jan 23, 2025
5412d18
Merged same errors and fixed naming(ref: #476)
DarkLord017 Jan 25, 2025
873a332
Fixed linter errors for commit Merged same errors and fixed naming(re…
DarkLord017 Jan 25, 2025
7c41ab3
Removed from panic in docs (ref: #476)
DarkLord017 Jan 28, 2025
7edee5f
ref: rename Example -> Examples
bidzyyys Feb 4, 2025
970e858
Merge remote-tracking branch 'oz/main' into ConsistentDocs
bidzyyys Feb 4, 2025
8d1dba8
ref: remove redundant note
bidzyyys Feb 4, 2025
305ec17
ref: improve imports
bidzyyys Feb 4, 2025
b17fe2a
docs: remove requirements section
bidzyyys Feb 4, 2025
4bb8ae9
docs: remove relies section
bidzyyys Feb 4, 2025
7952e34
docs: fix missing imports
bidzyyys Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 16 additions & 29 deletions contracts/src/access/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] has not been granted `role`, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If [`msg::sender`] has not been
/// granted `role`.
pub fn only_role(&self, role: B256) -> Result<(), Error> {
self._check_role(role, msg::sender())
}
Expand All @@ -170,10 +170,6 @@ impl AccessControl {
/// If `account` had not been already granted `role`, emits a
/// [`RoleGranted`] event.
///
/// # Requirements:
///
/// * The caller must have `role`'s admin role.
///
/// # Arguments
///
/// * `&mut self` - Write access to the contract's state.
Expand All @@ -182,12 +178,12 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] has not been granted `role`, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If [`msg::sender`] has not been
/// granted `role`.
///
/// # Events
///
/// May emit a [`RoleGranted`] event.
/// * [`RoleGranted`]
pub fn grant_role(
&mut self,
role: B256,
Expand All @@ -203,10 +199,6 @@ impl AccessControl {
///
/// If `account` had been granted `role`, emits a [`RoleRevoked`] event.
///
/// # Requirements:
///
/// * The caller must have `role`'s admin role.
///
/// # Arguments
///
/// * `&mut self` - Write access to the contract's state.
Expand All @@ -215,12 +207,12 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] has not been granted `role`, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If [`msg::sender`] has not been
/// granted `role`.
///
/// # Events
///
/// May emit a [`RoleRevoked`] event.
/// * [`RoleRevoked`].
pub fn revoke_role(
&mut self,
role: B256,
Expand All @@ -239,10 +231,6 @@ impl AccessControl {
/// for accounts to lose their privileges if they are compromised (such as
/// when a trusted device is misplaced).
///
/// # Requirements:
///
/// * The caller must be `confirmation`.
///
/// # Arguments
///
/// * `&mut self` - Write access to the contract's state.
Expand All @@ -251,13 +239,12 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] is not the `confirmation` address, then the error
/// [`Error::BadConfirmation`] is returned.
/// * [`Error::BadConfirmation`] - If [`msg::sender`] is not the
/// `confirmation` address.
///
/// # Events
///
/// If the calling account has its `role` revoked, emits a [`RoleRevoked`]
/// event.
/// * [`RoleRevoked`] - If the calling account has its `role` revoked.
pub fn renounce_role(
&mut self,
role: B256,
Expand Down Expand Up @@ -288,7 +275,7 @@ impl AccessControl {
///
/// # Events
///
/// Emits a [`RoleAdminChanged`] event.
/// * [`RoleAdminChanged`].
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);
Expand All @@ -309,8 +296,8 @@ impl AccessControl {
///
/// # Errors
///
/// If [`msg::sender`] has not been granted `role`, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If [`msg::sender`] has not been
/// granted `role`.
pub fn _check_role(
&self,
role: B256,
Expand Down Expand Up @@ -338,7 +325,7 @@ impl AccessControl {
///
/// # Events
///
/// May emit a [`RoleGranted`] event.
/// * [`RoleGranted`].
pub fn _grant_role(&mut self, role: B256, account: Address) -> bool {
if self.has_role(role, account) {
false
Expand All @@ -362,7 +349,7 @@ impl AccessControl {
///
/// # Events
///
/// May emit a [`RoleRevoked`] event.
/// * [`RoleRevoked`].
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);
Expand Down
16 changes: 7 additions & 9 deletions contracts/src/access/ownable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ pub trait IOwnable {
///
/// # Errors
///
/// If `new_owner` is the zero address, then the error
/// [`OwnableInvalidOwner`] is returned.
/// * [`OwnableInvalidOwner`] - If `new_owner` is the `Address::ZERO`.
///
/// # Events
///
/// Emits a [`OwnershipTransferred`] event.
/// * [`OwnershipTransferred`].
fn transfer_ownership(
&mut self,
new_owner: Address,
Expand All @@ -120,12 +119,11 @@ pub trait IOwnable {
///
/// # Errors
///
/// If not called by the owner, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If not called by the owner.
///
/// # Events
///
/// Emits a [`OwnershipTransferred`] event.
/// * [`OwnershipTransferred`].
fn renounce_ownership(&mut self) -> Result<(), Self::Error>;
}

Expand Down Expand Up @@ -170,8 +168,8 @@ impl Ownable {
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`Error::UnauthorizedAccount`] is returned.
/// * [`Error::UnauthorizedAccount`] - If called by any account other than
/// the owner.
pub fn only_owner(&self) -> Result<(), Error> {
let account = msg::sender();
if self.owner() != account {
Expand All @@ -193,7 +191,7 @@ impl Ownable {
///
/// # Events
///
/// Emits a [`OwnershipTransferred`] event.
/// * [`OwnershipTransferred`].
pub fn _transfer_ownership(&mut self, new_owner: Address) {
let previous_owner = self._owner.get();
self._owner.set(new_owner);
Expand Down
22 changes: 12 additions & 10 deletions contracts/src/access/ownable_two_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ pub trait IOwnable2Step {
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`OwnableError::UnauthorizedAccount`] is returned.
/// * [`OwnableError::UnauthorizedAccount`] - If called by any account other
/// than the owner.
///
/// # Events
///
/// Emits a [`OwnershipTransferStarted`] event.
/// * [`OwnershipTransferStarted`].
fn transfer_ownership(
&mut self,
new_owner: Address,
Expand All @@ -123,12 +123,12 @@ pub trait IOwnable2Step {
///
/// # Errors
///
/// If called by any account other than the pending owner, then the error
/// [`OwnableError::UnauthorizedAccount`] is returned.
/// * [`OwnableError::UnauthorizedAccount`] - If called by any account other
/// than the pending owner.
///
/// # Events
///
/// Emits a [`crate::access::ownable::OwnershipTransferred`] event.
/// * [`crate::access::ownable::OwnershipTransferred`].
fn accept_ownership(&mut self) -> Result<(), Self::Error>;

/// Leaves the contract without owner. It will not be possible to call
Expand All @@ -139,14 +139,16 @@ pub trait IOwnable2Step {
/// thereby disabling any functionality that is only available to the owner.
///
/// # Arguments
///
/// * `&mut self` - Write access to the contract's state.
///
/// # Errors
///
/// If not called by the owner, then the error
/// [`OwnableError::UnauthorizedAccount`] is returned.
/// * [`OwnableError::UnauthorizedAccount`] - If not called by the owner.
///
/// # Events
///
/// Emits a [`crate::access::ownable::OwnershipTransferred`] event.
/// * [`crate::access::ownable::OwnershipTransferred`].
fn renounce_ownership(&mut self) -> Result<(), Self::Error>;
}

Expand Down Expand Up @@ -212,7 +214,7 @@ impl Ownable2Step {
///
/// # Events
///
/// Emits a [`crate::access::ownable::OwnershipTransferred`] event.
/// * [`crate::access::ownable::OwnershipTransferred`].
fn _transfer_ownership(&mut self, new_owner: Address) {
self._pending_owner.set(Address::ZERO);
self._ownable._transfer_ownership(new_owner);
Expand Down
61 changes: 28 additions & 33 deletions contracts/src/finance/vesting_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If called by any account other than the owner, then the error
/// [`ownable::Error::UnauthorizedAccount`] is returned.
/// If `new_owner` is the `Address::ZERO`, then the error
/// [`ownable::Error::InvalidOwner`] is returned.
/// * [`ownable::Error::UnauthorizedAccount`] - If called by any account
/// other than the owner.
/// * [`ownable::Error::InvalidOwner`] - If `new_owner` is the
/// `Address::ZERO`.
///
/// # Events
///
/// Emits an [`ownable::OwnershipTransferred`] event.
/// * [`ownable::OwnershipTransferred`].
fn transfer_ownership(
&mut self,
new_owner: Address,
Expand All @@ -176,12 +176,11 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If not called by the owner, then the error
/// [`ownable::Error::UnauthorizedAccount`] is returned.
/// * [`ownable::Error::UnauthorizedAccount`] - If not called by the owner.
///
/// # Events
///
/// Emits an [`ownable::OwnershipTransferred`] event.
/// * [`ownable::OwnershipTransferred`].
fn renounce_ownership(&mut self) -> Result<(), Self::Error>;

/// The contract should be able to receive Ether.
Expand Down Expand Up @@ -237,8 +236,8 @@ pub trait IVestingWallet {
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "releasable")]
fn releasable_eth(&self) -> U256;

Expand All @@ -252,13 +251,12 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If the `token` address is not a contract, then the error
/// [`Error::InvalidToken`] is returned.
/// * [`Error::InvalidToken`] - If the `token` address is not a contract.
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "releasable")]
fn releasable_erc20(&mut self, token: Address)
-> Result<U256, Self::Error>;
Expand All @@ -271,17 +269,16 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If Ether transfer fails, then the error [`Error::ReleaseEtherFailed`] is
/// returned.
/// * [`Error::ReleaseEtherFailed`] - If Ether transfer fails.
///
/// # Events
///
/// Emits an [`EtherReleased`] event.
/// * [`EtherReleased`].
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "release")]
fn release_eth(&mut self) -> Result<(), Self::Error>;

Expand All @@ -294,19 +291,18 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If the `token` address is not a contract, then the error
/// [`Error::InvalidToken`] is returned.
/// If the contract fails to execute the call, then the error
/// [`safe_erc20::Error::SafeErc20FailedOperation`] is returned.
/// * [`Error::InvalidToken`] - If the `token` address is not a contract.
/// * [`safe_erc20::Error::SafeErc20FailedOperation`] - If the contract
/// fails to execute the call.
///
/// # Events
///
/// Emits an [`ERC20Released`] event.
/// * [`ERC20Released`].
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "release")]
fn release_erc20(&mut self, token: Address) -> Result<(), Self::Error>;

Expand All @@ -320,8 +316,8 @@ pub trait IVestingWallet {
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "vestedAmount")]
fn vested_amount_eth(&self, timestamp: u64) -> U256;

Expand All @@ -336,13 +332,12 @@ pub trait IVestingWallet {
///
/// # Errors
///
/// If the `token` address is not a contract, then the error
/// [`Error::InvalidToken`] is returned.
/// * [`Error::InvalidToken`] - If the `token` address is not a contract.
///
/// # Panics
///
/// If total allocation exceeds `U256::MAX`.
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If total allocation exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
#[selector(name = "vestedAmount")]
fn vested_amount_erc20(
&mut self,
Expand Down Expand Up @@ -491,7 +486,7 @@ impl VestingWallet {
///
/// # Panics
///
/// If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
/// * If scaled, total allocation (mid calculation) exceeds `U256::MAX`.
fn vesting_schedule(&self, total_allocation: U256, timestamp: U64) -> U256 {
let timestamp = U256::from(timestamp);

Expand Down
Loading
Loading