Skip to content

Updated OpenZeppelin to version 5.1.0 #109

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

Merged
merged 34 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f617a34
updated dependencies
aritkulova Jul 22, 2024
2abbd20
specified initialOwner for __Ownable_init function
aritkulova Jul 22, 2024
9a07b3f
MathUpgradeable lib -> Math lib
aritkulova Jul 22, 2024
ab45e91
created mock contract for ERC721Holder
aritkulova Jul 22, 2024
986f89c
updated test's error handlers to catch custom errors
aritkulova Jul 22, 2024
079f373
fixed typo in test
aritkulova Jul 22, 2024
fb146e2
Added custom TransparentUpgradeableProxy contract
aritkulova Jul 23, 2024
e2f8cad
Removed isContract()
aritkulova Jul 23, 2024
40654bc
Fixed typo
aritkulova Jul 29, 2024
157bb61
Cleaned up dependencies
aritkulova Jul 29, 2024
8157d52
Dropped tests for isContract() check in Diamond
aritkulova Jul 30, 2024
2c640f1
Removed unnecessary dependency
aritkulova Aug 2, 2024
f4b6501
Added solhint command to scripts
aritkulova Aug 2, 2024
7cb5d08
Merge branch 'master' of https://github.com/dl-solarity/solidity-lib …
aritkulova Aug 5, 2024
f629e9b
Renamed TransparentUpgradeableProxy to avoid collisions
aritkulova Aug 5, 2024
a29c83e
Updated dependencies
aritkulova Aug 5, 2024
5f260e0
Fixed package-lock
aritkulova Aug 5, 2024
e995cf5
Switched to custom errors in contracts (#113)
aritkulova Aug 21, 2024
a2fb96f
Added missed .withArgs() to error handlers
aritkulova Aug 21, 2024
ce09777
Updated .solhint config
KyrylR Sep 30, 2024
6cebb56
Updated versions
KyrylR Sep 30, 2024
ff5c0ae
updated openzeppelin to 5.1.0
aritkulova Nov 11, 2024
0d73294
review fixes: linting
aritkulova Nov 11, 2024
8b48a26
renamed TransparentProxy to AdminableProxy
aritkulova Nov 11, 2024
76342a6
moved IAdminableProxy to the interfaces;
aritkulova Nov 11, 2024
d0f13dd
switched from staticcall to call through interface in AdminableProxyU…
aritkulova Nov 11, 2024
482efa6
updated dev dependencies
aritkulova Nov 11, 2024
d780e5d
downgraded types/chai and types/node
aritkulova Nov 11, 2024
68b9f95
renamed transparent dir to adminable
aritkulova Nov 11, 2024
0c9429c
placed Traversal lib into AvlTree file
aritkulova Nov 12, 2024
8403147
erc721:
aritkulova Nov 12, 2024
a5d9922
erc20:
aritkulova Nov 12, 2024
6de7262
linting
aritkulova Nov 13, 2024
6375a28
linting
aritkulova Nov 13, 2024
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
11 changes: 6 additions & 5 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "warn",
"reentrancy": "off",
"modifier-name-mixedcase": "off",
"reentrancy": "warn",
"modifier-name-mixedcase": "warn",
"no-empty-blocks": "off",
"func-visibility": "off",
"max-states-count": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }],
"max-states-count": "warn",
"not-rely-on-time": "off",
"compiler-version": "off"
"func-name-mixedcase": "off",
"no-inline-assembly": "off"
}
}
10 changes: 5 additions & 5 deletions contracts/access/MerkleWhitelisted.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ abstract contract MerkleWhitelisted {

bytes32 private _merkleRoot;

error LeafNotWhitelisted(bytes data);
error UserNotWhitelisted(address user);

modifier onlyWhitelisted(bytes memory data_, bytes32[] memory merkleProof_) {
require(
_isWhitelisted(keccak256(data_), merkleProof_),
"MerkleWhitelisted: not whitelisted"
);
if (!_isWhitelisted(keccak256(data_), merkleProof_)) revert LeafNotWhitelisted(data_);
_;
}

modifier onlyWhitelistedUser(address user_, bytes32[] memory merkleProof_) {
require(_isWhitelistedUser(user_, merkleProof_), "MerkleWhitelisted: not whitelisted");
if (!_isWhitelistedUser(user_, merkleProof_)) revert UserNotWhitelisted(user_);
_;
}

Expand Down
7 changes: 5 additions & 2 deletions contracts/access/MultiOwnable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ abstract contract MultiOwnable is IMultiOwnable, Initializable {

EnumerableSet.AddressSet private _owners;

error InvalidOwner();
error UnauthorizedAccount(address account);

modifier onlyOwner() {
_checkOwner();
_;
Expand Down Expand Up @@ -91,7 +94,7 @@ abstract contract MultiOwnable is IMultiOwnable, Initializable {
function _addOwners(address[] memory newOwners_) private {
_owners.add(newOwners_);

require(!_owners.contains(address(0)), "MultiOwnable: zero address can not be added");
if (_owners.contains(address(0))) revert InvalidOwner();

emit OwnersAdded(newOwners_);
}
Expand All @@ -115,6 +118,6 @@ abstract contract MultiOwnable is IMultiOwnable, Initializable {
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() private view {
require(isOwner(msg.sender), "MultiOwnable: caller is not the owner");
if (!isOwner(msg.sender)) revert UnauthorizedAccount(msg.sender);
}
}
7 changes: 5 additions & 2 deletions contracts/access/PermanentOwnable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pragma solidity ^0.8.4;
abstract contract PermanentOwnable {
address private immutable _OWNER;

error InvalidOwner();
error UnauthorizedAccount(address account);

/**
* @dev Throws if called by any account other than the owner.
*/
Expand All @@ -28,7 +31,7 @@ abstract contract PermanentOwnable {
* @param owner_ the address of the permanent owner.
*/
constructor(address owner_) {
require(owner_ != address(0), "PermanentOwnable: zero address can not be the owner");
if (owner_ == address(0)) revert InvalidOwner();

_OWNER = owner_;
}
Expand All @@ -42,6 +45,6 @@ abstract contract PermanentOwnable {
}

function _onlyOwner() internal view virtual {
require(_OWNER == msg.sender, "PermanentOwnable: caller is not the owner");
if (_OWNER != msg.sender) revert UnauthorizedAccount(msg.sender);
}
}
15 changes: 7 additions & 8 deletions contracts/access/RBAC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ abstract contract RBAC is IRBAC, Initializable {

mapping(address => DynamicSet.StringSet) private _userRoles;

error EmptyRoles();
error NoPermissionForResource(address account, string permission, string resource);

modifier onlyPermission(string memory resource_, string memory permission_) {
require(
hasPermission(msg.sender, resource_, permission_),
string(
abi.encodePacked("RBAC: no ", permission_, " permission for resource ", resource_)
)
);
if (!hasPermission(msg.sender, resource_, permission_))
revert NoPermissionForResource(msg.sender, permission_, resource_);
_;
}

Expand All @@ -79,7 +78,7 @@ abstract contract RBAC is IRBAC, Initializable {
address to_,
string[] memory rolesToGrant_
) public virtual override onlyPermission(RBAC_RESOURCE, CREATE_PERMISSION) {
require(rolesToGrant_.length > 0, "RBAC: empty roles");
if (rolesToGrant_.length == 0) revert EmptyRoles();

_grantRoles(to_, rolesToGrant_);
}
Expand All @@ -93,7 +92,7 @@ abstract contract RBAC is IRBAC, Initializable {
address from_,
string[] memory rolesToRevoke_
) public virtual override onlyPermission(RBAC_RESOURCE, DELETE_PERMISSION) {
require(rolesToRevoke_.length > 0, "RBAC: empty roles");
if (rolesToRevoke_.length == 0) revert EmptyRoles();

_revokeRoles(from_, rolesToRevoke_);
}
Expand Down
10 changes: 6 additions & 4 deletions contracts/access/extensions/RBACGroupable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ abstract contract RBACGroupable is IRBACGroupable, RBAC {
mapping(address => DynamicSet.StringSet) private _userGroups;
mapping(string => DynamicSet.StringSet) private _groupRoles;

error EmptyGroups();

/**
* @notice The initialization function
*/
Expand All @@ -47,7 +49,7 @@ abstract contract RBACGroupable is IRBACGroupable, RBAC {
address who_,
string[] memory groupsToAddTo_
) public virtual override onlyPermission(RBAC_RESOURCE, CREATE_PERMISSION) {
require(groupsToAddTo_.length > 0, "RBACGroupable: empty groups");
if (groupsToAddTo_.length == 0) revert EmptyGroups();

_addUserToGroups(who_, groupsToAddTo_);
}
Expand All @@ -61,7 +63,7 @@ abstract contract RBACGroupable is IRBACGroupable, RBAC {
address who_,
string[] memory groupsToRemoveFrom_
) public virtual override onlyPermission(RBAC_RESOURCE, DELETE_PERMISSION) {
require(groupsToRemoveFrom_.length > 0, "RBACGroupable: empty groups");
if (groupsToRemoveFrom_.length == 0) revert EmptyGroups();

_removeUserFromGroups(who_, groupsToRemoveFrom_);
}
Expand All @@ -75,7 +77,7 @@ abstract contract RBACGroupable is IRBACGroupable, RBAC {
string memory groupTo_,
string[] memory rolesToGrant_
) public virtual override onlyPermission(RBAC_RESOURCE, CREATE_PERMISSION) {
require(rolesToGrant_.length > 0, "RBACGroupable: empty roles");
if (rolesToGrant_.length == 0) revert EmptyRoles();

_grantGroupRoles(groupTo_, rolesToGrant_);
}
Expand All @@ -89,7 +91,7 @@ abstract contract RBACGroupable is IRBACGroupable, RBAC {
string memory groupFrom_,
string[] memory rolesToRevoke_
) public virtual override onlyPermission(RBAC_RESOURCE, DELETE_PERMISSION) {
require(rolesToRevoke_.length > 0, "RBACGroupable: empty roles");
if (rolesToRevoke_.length == 0) revert EmptyRoles();

_revokeGroupRoles(groupFrom_, rolesToRevoke_);
}
Expand Down
34 changes: 22 additions & 12 deletions contracts/contracts-registry/AbstractContractsRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity ^0.8.4;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import {TransparentProxyUpgrader} from "../proxy/transparent/TransparentProxyUpgrader.sol";
import {SolarityTransparentProxy} from "../proxy/transparent/SolarityTransparentProxy.sol";
import {AbstractDependant} from "./AbstractDependant.sol";

/**
Expand Down Expand Up @@ -48,6 +48,10 @@ abstract contract AbstractContractsRegistry is Initializable {
event ProxyContractUpgraded(string name, address newImplementation);
event ContractRemoved(string name);

error NoMappingExists(string contractName);
error NotAProxy(string contractName, address contractProxy);
error ZeroAddressProvided(string contractName);

/**
* @notice The initialization function
*/
Expand All @@ -63,7 +67,7 @@ abstract contract AbstractContractsRegistry is Initializable {
function getContract(string memory name_) public view returns (address) {
address contractAddress_ = _contracts[name_];

require(contractAddress_ != address(0), "ContractsRegistry: this mapping doesn't exist");
_checkIfMappingExist(contractAddress_, name_);

return contractAddress_;
}
Expand Down Expand Up @@ -93,8 +97,9 @@ abstract contract AbstractContractsRegistry is Initializable {
function getImplementation(string memory name_) public view returns (address) {
address contractProxy_ = _contracts[name_];

require(contractProxy_ != address(0), "ContractsRegistry: this mapping doesn't exist");
require(_isProxy[contractProxy_], "ContractsRegistry: not a proxy contract");
if (contractProxy_ == address(0)) revert NoMappingExists(name_);

if (!_isProxy[contractProxy_]) revert NotAProxy(name_, contractProxy_);

return _proxyUpgrader.getImplementation(contractProxy_);
}
Expand All @@ -118,7 +123,7 @@ abstract contract AbstractContractsRegistry is Initializable {
) internal virtual {
address contractAddress_ = _contracts[name_];

require(contractAddress_ != address(0), "ContractsRegistry: this mapping doesn't exist");
_checkIfMappingExist(contractAddress_, name_);

AbstractDependant dependant_ = AbstractDependant(contractAddress_);
dependant_.setDependencies(address(this), data_);
Expand Down Expand Up @@ -150,8 +155,9 @@ abstract contract AbstractContractsRegistry is Initializable {
) internal virtual {
address contractToUpgrade_ = _contracts[name_];

require(contractToUpgrade_ != address(0), "ContractsRegistry: this mapping doesn't exist");
require(_isProxy[contractToUpgrade_], "ContractsRegistry: not a proxy contract");
if (contractToUpgrade_ == address(0)) revert NoMappingExists(name_);

if (!_isProxy[contractToUpgrade_]) revert NotAProxy(name_, contractToUpgrade_);

_proxyUpgrader.upgrade(contractToUpgrade_, newImplementation_, data_);

Expand All @@ -165,7 +171,7 @@ abstract contract AbstractContractsRegistry is Initializable {
* @param contractAddress_ the address of the contract
*/
function _addContract(string memory name_, address contractAddress_) internal virtual {
require(contractAddress_ != address(0), "ContractsRegistry: zero address is forbidden");
if (contractAddress_ == address(0)) revert ZeroAddressProvided(name_);

_contracts[name_] = contractAddress_;

Expand Down Expand Up @@ -194,7 +200,7 @@ abstract contract AbstractContractsRegistry is Initializable {
address contractAddress_,
bytes memory data_
) internal virtual {
require(contractAddress_ != address(0), "ContractsRegistry: zero address is forbidden");
if (contractAddress_ == address(0)) revert ZeroAddressProvided(name_);

address proxyAddr_ = _deployProxy(contractAddress_, address(_proxyUpgrader), data_);

Expand All @@ -215,7 +221,7 @@ abstract contract AbstractContractsRegistry is Initializable {
string memory name_,
address contractAddress_
) internal virtual {
require(contractAddress_ != address(0), "ContractsRegistry: zero address is forbidden");
if (contractAddress_ == address(0)) revert ZeroAddressProvided(name_);

_contracts[name_] = contractAddress_;
_isProxy[contractAddress_] = true;
Expand All @@ -234,7 +240,7 @@ abstract contract AbstractContractsRegistry is Initializable {
function _removeContract(string memory name_) internal virtual {
address contractAddress_ = _contracts[name_];

require(contractAddress_ != address(0), "ContractsRegistry: this mapping doesn't exist");
_checkIfMappingExist(contractAddress_, name_);

delete _isProxy[contractAddress_];
delete _contracts[name_];
Expand All @@ -254,6 +260,10 @@ abstract contract AbstractContractsRegistry is Initializable {
address admin_,
bytes memory data_
) internal virtual returns (address) {
return address(new TransparentUpgradeableProxy(contractAddress_, admin_, data_));
return address(new SolarityTransparentProxy(contractAddress_, admin_, data_));
}

function _checkIfMappingExist(address contractAddress_, string memory name_) internal pure {
if (contractAddress_ == address(0)) revert NoMappingExists(name_);
}
}
5 changes: 4 additions & 1 deletion contracts/contracts-registry/AbstractDependant.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract contract AbstractDependant {
bytes32 private constant _INJECTOR_SLOT =
0x3d1f25f1ac447e55e7fec744471c4dab1c6a2b6ffb897825f9ea3d2e8c9be583;

error NotAnInjector(address injector, address caller);

modifier dependant() {
_checkInjector();
_;
Expand Down Expand Up @@ -76,6 +78,7 @@ abstract contract AbstractDependant {
function _checkInjector() internal view {
address injector_ = getInjector();

require(injector_ == address(0) || injector_ == msg.sender, "Dependant: not an injector");
if (injector_ != address(0) && injector_ != msg.sender)
revert NotAnInjector(injector_, msg.sender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ abstract contract AbstractPoolContractsRegistry is Initializable, AbstractDepend
mapping(string => ProxyBeacon) private _beacons;
mapping(string => EnumerableSet.AddressSet) private _pools; // name => pool

error NoMappingExists(string poolName);
error NoPoolsToInject(string poolName);
error ProxyDoesNotExist(string poolName);

/**
* @notice The proxy initializer function
*/
Expand Down Expand Up @@ -66,10 +70,7 @@ abstract contract AbstractPoolContractsRegistry is Initializable, AbstractDepend
* @return address_ the implementation these pools point to
*/
function getImplementation(string memory name_) public view returns (address) {
require(
address(_beacons[name_]) != address(0),
"PoolContractsRegistry: this mapping doesn't exist"
);
if (address(_beacons[name_]) == address(0)) revert NoMappingExists(name_);

return _beacons[name_].implementation();
}
Expand All @@ -82,7 +83,7 @@ abstract contract AbstractPoolContractsRegistry is Initializable, AbstractDepend
function getProxyBeacon(string memory name_) public view returns (address) {
address beacon_ = address(_beacons[name_]);

require(beacon_ != address(0), "PoolContractsRegistry: bad ProxyBeacon");
if (beacon_ == address(0)) revert ProxyDoesNotExist(name_);

return beacon_;
}
Expand Down Expand Up @@ -173,7 +174,7 @@ abstract contract AbstractPoolContractsRegistry is Initializable, AbstractDepend

uint256 to_ = (offset_ + limit_).min(_namedPools.length()).max(offset_);

require(to_ != offset_, "PoolContractsRegistry: no pools to inject");
if (to_ == offset_) revert NoPoolsToInject(name_);

address contractsRegistry_ = _contractsRegistry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract contract OwnablePoolContractsRegistry is
* @notice The initialization function
*/
function __OwnablePoolContractsRegistry_init() public initializer {
__Ownable_init();
__Ownable_init(msg.sender);
__PoolContractsRegistry_init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract OwnableContractsRegistry is AbstractContractsRegistry, OwnableUpgradeab
* @notice The initialization function
*/
function __OwnableContractsRegistry_init() public initializer {
__Ownable_init();
__Ownable_init(msg.sender);
__ContractsRegistry_init();
}

Expand Down
Loading
Loading