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: update LSP14 Natspec #629

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
pragma solidity ^0.8.4;

/**
* @title Interface of the LSP14 - Ownable 2-step standard, an extension of the EIP173 (Ownable) standard with 2-step process to transfer or renounce ownership.
* @title Interface of the LSP14 - Ownable 2-step standard, an extension of the [EIP173] (Ownable) standard with 2-step process to transfer or renounce ownership.
*/
interface ILSP14Ownable2Step {
/**
* @dev emitted when starting the `transferOwnership(..)` 2-step process.
* @dev Emitted when {transferOwnership(..)} was called and the first step of transferring ownership completed successfully which leads to {pendingOwner} being updated.
* @notice The transfer of ownership of the contract was initiated. Pending new owner set to: `newOwner`.
* @param previousOwner The address of the previous owner.
* @param newOwner The address of the new owner.
*/
event OwnershipTransferStarted(
address indexed previousOwner,
Expand All @@ -19,59 +22,57 @@ interface ILSP14Ownable2Step {
*/

/**
* @dev emitted when starting the `renounceOwnership(..)` 2-step process.
* @dev Emitted when starting the {renounceOwnership(..)} 2-step process.
b00ste marked this conversation as resolved.
Show resolved Hide resolved
* @notice Ownership renouncement initiated.
*/
event RenounceOwnershipStarted();

/**
* @dev emitted when the ownership of the contract has been renounced.
* @dev Emitted when the ownership of the contract has been renounced.
* @notice Successfully renounced ownership of the contract. This contract is now owned by anyone, it's owner is `address(0)`.
*/
event OwnershipRenounced();

/**
* @inheritdoc OwnableUnset
* function owner() external view returns (address);
* function {owner()} external view returns (address);
CJ42 marked this conversation as resolved.
Show resolved Hide resolved
*/

/**
* @dev The address that ownership of the contract is transferred to.
* This address may use {acceptOwnership()} to gain ownership of the contract.
*
* @custom:info If no ownership transfer is in progress, the pendingOwner will be `address(0)`.
b00ste marked this conversation as resolved.
Show resolved Hide resolved
*/
function pendingOwner() external view returns (address);

/**
* @dev Initiate the process of transferring ownership of the contract by setting the new owner as the pending owner.
*
* If the new owner is a contract that supports + implements LSP1, this will also attempt to notify the new owner that
* ownership has been transferred to them by calling the {`universalReceiver()`} function on the `newOwner` contract.
* If the new owner is a contract that supports + implements LSP1, this will also attempt to notify the new owner that ownership has been transferred to them by calling the {universalReceiver()} function on the `newOwner` contract.
*
* @param newOwner the address of the new owner.
* @notice Transfer ownership initiated by `newOwner`.
*
* @custom:requirements `newOwner` MUST NOT accept ownership of the contract in the same transaction.
* @param newOwner The address of the new owner.
*/
function transferOwnership(address newOwner) external;

/**
* @dev Transfer ownership of the contract from the current {`owner()`} to the {`pendingOwner()`}.
* @dev Transfer ownership of the contract from the current {owner()} to the {pendingOwner()}.
CJ42 marked this conversation as resolved.
Show resolved Hide resolved
*
* Once this function is called:
* - the current {`owner()`} will loose access to the functions restricted to the {`owner()`} only.
* - the {`pendingOwner()`} will gain access to the functions restricted to the {`owner()`} only.
* - The current {owner()} will loose access to the functions restricted to the {owner()} only.
* - The {pendingOwner()} will gain access to the functions restricted to the {owner()} only.
*
* @custom:requirements
b00ste marked this conversation as resolved.
Show resolved Hide resolved
* - MUST be called by the {`pendingOwner`}.
* @notice `msg.sender` is accepting ownership of contract: `address(this)`.
*/
function acceptOwnership() external;

/**
* @dev Renounce ownership of the contract in a two step process.
* @dev Renounce ownership of the contract in a 2-step process.
*
* 1. the first call will initiate the process of renouncing ownership.
* 2. the second is used as a confirmation and will leave the contract without an owner.
* 1. The first call will initiate the process of renouncing ownership.
* 2. The second call is used as a confirmation and will leave the contract without an owner.
*
* @custom:danger Leaves the contract without an owner. Once ownership of the contract has been renounced, any functions that are restricted to be called by the owner will be permanently inaccessible, making these functions not callable anymore and unusable.
b00ste marked this conversation as resolved.
Show resolved Hide resolved
* @notice `msg.sender` is renouncing ownership of contract `address(this)`.
*/
function renounceOwnership() external;
}
12 changes: 9 additions & 3 deletions contracts/LSP14Ownable2Step/LSP14Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
pragma solidity ^0.8.4;

/**
* @dev reverts when trying to renounce ownership before the initial confirmation delay
* @dev Reverts when trying to renounce ownership before the initial confirmation delay.
* @notice Cannot confirm ownership renouncement yet. The ownership renouncement is allowed from: `renounceOwnershipStart` until: `renounceOwnershipEnd`.
*
* @param renounceOwnershipStart The start timestamp when one can confirm the renouncement of ownership.
* @param renounceOwnershipEnd The end timestamp when one can confirm the renouncement of ownership.
*/
error NotInRenounceOwnershipInterval(
uint256 renounceOwnershipStart,
uint256 renounceOwnershipEnd
);

/**
* @dev reverts when trying to transfer ownership to the address(this)
* @dev Reverts when trying to transfer ownership to the `address(this)`.
* @notice Cannot transfer ownership to the address of the contract itself.
*/
error CannotTransferOwnershipToSelf();

/**
* @dev reverts when pending owner accept ownership in the same transaction of transferring ownership
* @dev Reverts when pending owner accept ownership in the same transaction of transferring ownership.
* @notice Cannot accept ownership in the same transaction with {transferOwnership(...)}.
*/
error LSP14MustAcceptOwnershipInSeparateTransaction();
34 changes: 19 additions & 15 deletions contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,30 @@ import {
/**
* @title LSP14Ownable2Step
* @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi), Daniel Afteni (B00ste)
* @dev This contract is a modified version of the OwnableUnset implementation, where transferring and renouncing ownership
* works as a 2 steps process. This can be used as a confirmation mechanism to prevent potential mistakes when
* transferring ownership of the contract, where the control of the contract could be lost forever.
* @dev This contract is a modified version of the [`OwnableUnset.sol`] implementation, where transferring and renouncing ownership works as a 2-step process. This can be used as a confirmation mechanism to prevent potential mistakes when transferring ownership of the contract, where the control of the contract could be lost forever. (_e.g: providing the wrong address as a parameter to the function, transferring ownership to an EOA for which the user lost its private key, etc..._)
*/
abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
using LSP1Utils for address;

/**
* @dev The number of block that MUST pass before one is able to
* confirm renouncing ownership
* @dev The number of block that MUST pass before one is able to confirm renouncing ownership.
* @return Number of blocks.
*/
uint256 public constant RENOUNCE_OWNERSHIP_CONFIRMATION_DELAY = 200;

/**
* @dev The number of blocks during which one can renounce ownership
* @dev The number of blocks during which one can renounce ownership.
* @return Number of blocks.
*/
uint256 public constant RENOUNCE_OWNERSHIP_CONFIRMATION_PERIOD = 200;

/**
* @dev The block number saved when initiating the process of renouncing ownerhsip
* @dev The block number saved when initiating the process of renouncing ownerhsip.
*/
uint256 private _renounceOwnershipStartedAt;

/**
* @dev see `pendingOwner()`
* @dev see {pendingOwner()}
*/
address private _pendingOwner;

Expand All @@ -70,13 +69,17 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {

/**
* @inheritdoc ILSP14Ownable2Step
*
* @custom:info If no ownership transfer is in progress, the pendingOwner will be `address(0).`.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}

/**
* @inheritdoc ILSP14Ownable2Step
*
* @custom:requirements `newOwner` cannot accept ownership of the contract in the same transaction. (For instance, via a callback from its {universalReceiver(...)} function).
*/
function transferOwnership(
address newOwner
Expand All @@ -100,6 +103,8 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {

/**
* @inheritdoc ILSP14Ownable2Step
*
* @custom:requirements This function can only be called by the {pendingOwner()}.
*/
function acceptOwnership() public virtual NotInTransferOwnership {
address previousOwner = owner();
Expand All @@ -119,6 +124,8 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {

/**
* @inheritdoc ILSP14Ownable2Step
*
* @custom:danger Leaves the contract without an owner. Once ownership of the contract has been renounced, any function that is restricted to be called only by the owner will be permanently inaccessible, making these functions not callable anymore and unusable.
*/
function renounceOwnership()
public
Expand All @@ -132,13 +139,11 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
// --- Internal methods

/**
* @dev set the pending owner of the contract and cancel any renounce ownership
* process that was previously started.
* @dev Set the pending owner of the contract and cancel any renounce ownership process that was previously started.
*
* @param newOwner The address of the new pending owner.
*
* Requirements:
* - `newOwner` cannot be the address of the contract itself.
* @custom:requirements `newOwner` cannot be the address of the contract itself.
*/
function _transferOwnership(address newOwner) internal virtual {
if (newOwner == address(this)) revert CannotTransferOwnershipToSelf();
Expand All @@ -148,7 +153,7 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
}

/**
* @dev set the pending owner of the contract as the new owner.
* @dev Set the pending owner of the contract as the new owner.
*/
function _acceptOwnership() internal virtual {
require(
Expand All @@ -161,8 +166,7 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
}

/**
* @dev initiate or confirm the process of renouncing ownership
* after a specific delay of blocks have passed.
* @dev Initiate or confirm the process of renouncing ownership after a specific delay of blocks have passed.
*/
function _renounceOwnership() internal virtual {
uint256 currentBlock = block.number;
Expand Down
Loading
Loading