Skip to content

Commit

Permalink
docs: update LSP14 Natspec
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ste committed Aug 9, 2023
1 parent 3e7e2b8 commit d1a5ce6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
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 starting the {transferOwnership(..)} 2-step process.
* @notice Ownership transfer initiated. From: `previousOwner`. 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.
* @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 Ownership renouncement complete.
*/
event OwnershipRenounced();

/**
* @inheritdoc OwnableUnset
* function owner() external view returns (address);
* function {owner()} external view returns (address);
*/

/**
* @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)`.
*/
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()}.
*
* 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
* - 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 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.
* @notice `msg.sender` is renouncing ownership of contract: `address(this)`.
*/
function renounceOwnership() external;
}
8 changes: 6 additions & 2 deletions contracts/LSP14Ownable2Step/LSP14Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
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 of the period when you one can confirm the renouncement of ownership.
* @param renounceOwnershipEnd The end of the period when you 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 ownerhsip to yourself.
*/
error CannotTransferOwnershipToSelf();
23 changes: 15 additions & 8 deletions contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,46 @@ 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.
*/
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;

/**
* @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.
*/
function transferOwnership(
address newOwner
Expand All @@ -83,6 +86,8 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {

/**
* @inheritdoc ILSP14Ownable2Step
*
* @custom:requirements This function can only be called by the {pendingOwner()}.
*/
function acceptOwnership() public virtual {
address previousOwner = owner();
Expand All @@ -102,6 +107,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 functions that are restricted to be called by the owner will be permanently inaccessible, making these functions not callable anymore and unusable.
*/
function renounceOwnership()
public
Expand Down

0 comments on commit d1a5ce6

Please sign in to comment.