Skip to content

Commit

Permalink
Merge pull request #253 from ERC725Alliance/refactor/reove-ownableunset
Browse files Browse the repository at this point in the history
refactor!: remove `Core` contracts and `OwnableUnset`
  • Loading branch information
CJ42 authored Oct 9, 2024
2 parents d4e1cdb + 1047659 commit 0e1a57e
Show file tree
Hide file tree
Showing 20 changed files with 2,025 additions and 895 deletions.
31 changes: 9 additions & 22 deletions implementations/contracts/ERC725.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@
pragma solidity ^0.8.5;

// modules
import {OwnableUnset} from "./custom/OwnableUnset.sol";
import {ERC725XCore} from "./ERC725XCore.sol";
import {ERC725YCore} from "./ERC725YCore.sol";

// constants
import {_INTERFACEID_ERC725X, _INTERFACEID_ERC725Y} from "./constants.sol";

// errors
import {OwnableCannotSetZeroAddressAsOwner} from "./errors.sol";
import {ERC725X} from "./ERC725X.sol";
import {ERC725Y} from "./ERC725Y.sol";

/**
* @title ERC725 bundle.
Expand All @@ -19,7 +12,7 @@ import {OwnableCannotSetZeroAddressAsOwner} from "./errors.sol";
*
* @custom:warning This implementation does not have by default a `receive()` or `fallback()` function.
*/
contract ERC725 is ERC725XCore, ERC725YCore {
contract ERC725 is ERC725X, ERC725Y {
/**
* @notice Deploying an ERC725 smart contract and setting address `initialOwner` as the contract owner.
* @dev Deploy a new ERC725 contract with the provided `initialOwner` as the contract {owner}.
Expand All @@ -28,22 +21,16 @@ contract ERC725 is ERC725XCore, ERC725YCore {
* @custom:requirements
* - `initialOwner` CANNOT be the zero address.
*/
constructor(address initialOwner) payable {
if (initialOwner == address(0)) {
revert OwnableCannotSetZeroAddressAsOwner();
}
OwnableUnset._setOwner(initialOwner);
}
constructor(
address initialOwner
) payable ERC725X(initialOwner) ERC725Y(initialOwner) {}

/**
* @inheritdoc ERC725XCore
* @inheritdoc ERC725X
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC725XCore, ERC725YCore) returns (bool) {
return
interfaceId == _INTERFACEID_ERC725X ||
interfaceId == _INTERFACEID_ERC725Y ||
super.supportsInterface(interfaceId);
) public view virtual override(ERC725X, ERC725Y) returns (bool) {
return super.supportsInterface(interfaceId);
}
}
46 changes: 26 additions & 20 deletions implementations/contracts/ERC725InitAbstract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@
pragma solidity ^0.8.5;

// modules
import {
Initializable
} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {OwnableUnset} from "./custom/OwnableUnset.sol";
import {ERC725XCore} from "./ERC725XCore.sol";
import {ERC725YCore} from "./ERC725YCore.sol";

// constants
import {_INTERFACEID_ERC725X, _INTERFACEID_ERC725Y} from "./constants.sol";
import {ERC725XInitAbstract} from "./ERC725XInitAbstract.sol";
import {ERC725YInitAbstract} from "./ERC725YInitAbstract.sol";

// errors
import {OwnableCannotSetZeroAddressAsOwner} from "./errors.sol";
Expand All @@ -23,35 +16,48 @@ import {OwnableCannotSetZeroAddressAsOwner} from "./errors.sol";
* @custom:warning This implementation does not have by default a `receive()` or `fallback()` function.
*/
abstract contract ERC725InitAbstract is
Initializable,
ERC725XCore,
ERC725YCore
ERC725XInitAbstract,
ERC725YInitAbstract
{
/**
* @dev Internal function to initialize the contract with the provided `initialOwner` as the contract {owner}.
* @param initialOwner the owner of the contract.
*
* NOTE: we can safely override this function and not call the parent `_initialize(...)` functions from `ERC725XInitAbstract` and `ERC725YInitAbstract`
* as the code logic from this `_initialize(...)` is the exactly the same.
*
* @custom:warning If a child contract that inherits `ERC725InitAbstract` needs to override the logic of the `_initialize` function, make sure it calls
* also this function inside this logic via `super._initialize(initialOwner)` or `ERC725InitAbstract._initialize(initialOwner)`.
*
* @custom:requirements
* - `initialOwner` CANNOT be the zero address.
*/
function _initialize(
address initialOwner
) internal virtual onlyInitializing {
)
internal
virtual
override(ERC725XInitAbstract, ERC725YInitAbstract)
onlyInitializing
{
if (initialOwner == address(0)) {
revert OwnableCannotSetZeroAddressAsOwner();
}
OwnableUnset._setOwner(initialOwner);
_transferOwnership(initialOwner);
}

/**
* @inheritdoc ERC725XCore
* @inheritdoc ERC725XInitAbstract
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC725XCore, ERC725YCore) returns (bool) {
return
interfaceId == _INTERFACEID_ERC725X ||
interfaceId == _INTERFACEID_ERC725Y ||
super.supportsInterface(interfaceId);
)
public
view
virtual
override(ERC725XInitAbstract, ERC725YInitAbstract)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}
Loading

0 comments on commit 0e1a57e

Please sign in to comment.