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 8 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
2 changes: 1 addition & 1 deletion 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 {TransparentUpgradeableProxy} from "../proxy/transparent/TransparentUpgradeableProxy.sol";
import {AbstractDependant} from "./AbstractDependant.sol";

/**
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
6 changes: 0 additions & 6 deletions contracts/diamond/Diamond.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import {DiamondStorage} from "./DiamondStorage.sol";
Expand All @@ -20,7 +19,6 @@ import {DiamondStorage} from "./DiamondStorage.sol";
* If you wish to add a receive() function, attach a "0x00000000" selector to a facet that has such a function.
*/
contract Diamond is DiamondStorage {
using Address for address;
using EnumerableSet for EnumerableSet.Bytes32Set;
using EnumerableSet for EnumerableSet.AddressSet;

Expand Down Expand Up @@ -102,7 +100,6 @@ contract Diamond is DiamondStorage {
*/
function _addFacet(address facet_, bytes4[] memory selectors_) internal virtual {
require(facet_ != address(0), "Diamond: facet cannot be zero address");
require(facet_.isContract(), "Diamond: facet is not a contract");
require(selectors_.length != 0, "Diamond: no selectors provided");

DStorage storage _ds = _getDiamondStorage();
Expand Down Expand Up @@ -153,7 +150,6 @@ contract Diamond is DiamondStorage {
*/
function _updateFacet(address facet_, bytes4[] memory selectors_) internal virtual {
require(facet_ != address(0), "Diamond: facet cannot be zero address");
require(facet_.isContract(), "Diamond: facet is not a contract");
require(selectors_.length != 0, "Diamond: no selectors provided");

DStorage storage _ds = _getDiamondStorage();
Expand Down Expand Up @@ -190,8 +186,6 @@ contract Diamond is DiamondStorage {
return;
}

require(initFacet_.isContract(), "Diamond: init_ address has no code");

(bool success_, bytes memory err_) = initFacet_.delegatecall(initData_);

if (!success_) {
Expand Down
5 changes: 1 addition & 4 deletions contracts/diamond/tokens/ERC721/DiamondERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.4;

import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

import {DiamondERC721Storage} from "./DiamondERC721Storage.sol";

Expand All @@ -14,8 +13,6 @@ import {DiamondERC721Storage} from "./DiamondERC721Storage.sol";
* by the Diamond Standard.
*/
contract DiamondERC721 is DiamondERC721Storage {
using Address for address;

/**
* @notice Sets the values for {name} and {symbol}.
*/
Expand Down Expand Up @@ -243,7 +240,7 @@ contract DiamondERC721 is DiamondERC721Storage {
uint256 tokenId_,
bytes memory data_
) private returns (bool) {
if (to_.isContract()) {
if (to_.code.length > 0) {
try IERC721Receiver(to_).onERC721Received(msg.sender, from_, tokenId_, data_) returns (
bytes4 retval
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract OwnableCompoundRateKeeper is AbstractCompoundRateKeeper, OwnableUpgrade
uint256 capitalizationRate_,
uint64 capitalizationPeriod_
) public initializer {
__Ownable_init();
__Ownable_init(msg.sender);
__CompoundRateKeeper_init(capitalizationRate_, capitalizationPeriod_);
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/finance/vesting/Vesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity ^0.8.4;

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

import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

import {PRECISION} from "../../utils/Globals.sol";

Expand Down Expand Up @@ -69,7 +69,7 @@ import {PRECISION} from "../../utils/Globals.sol";
* It's not possible to create a schedule with an exponent equal to 0.
*/
abstract contract Vesting is Initializable {
using MathUpgradeable for uint256;
using Math for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.UintSet;

Expand Down
1 change: 0 additions & 1 deletion contracts/mock/diamond/tokens/DiamondERC721Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.4;

import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";

import {DiamondERC721} from "../../../diamond/tokens/ERC721/DiamondERC721.sol";

Expand Down
6 changes: 6 additions & 0 deletions contracts/mock/diamond/tokens/ERC721HolderMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";

contract ERC721HolderMock is ERC721Holder {}
5 changes: 1 addition & 4 deletions contracts/proxy/beacon/ProxyBeacon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.4;

import {IBeacon} from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

import {PermanentOwnable} from "../../access/PermanentOwnable.sol";

Expand All @@ -12,8 +11,6 @@ import {PermanentOwnable} from "../../access/PermanentOwnable.sol";
* This is a lightweight utility ProxyBeacon contract that may be used as a beacon that BeaconProxies point to.
*/
contract ProxyBeacon is IBeacon, PermanentOwnable {
using Address for address;

constructor() PermanentOwnable(msg.sender) {}

address private _implementation;
Expand All @@ -25,7 +22,7 @@ contract ProxyBeacon is IBeacon, PermanentOwnable {
* @param newImplementation_ the new implementation
*/
function upgradeTo(address newImplementation_) external virtual onlyOwner {
require(newImplementation_.isContract(), "ProxyBeacon: not a contract");
require(newImplementation_.code.length > 0, "ProxyBeacon: not a contract");

_implementation = newImplementation_;

Expand Down
12 changes: 2 additions & 10 deletions contracts/proxy/transparent/TransparentProxyUpgrader.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

import {PermanentOwnable} from "../../access/PermanentOwnable.sol";
import {ITransparentUpgradeableProxy} from "./TransparentUpgradeableProxy.sol";

/**
* @notice The proxies module
*
* This is the lightweight helper contract that may be used as a TransparentProxy admin.
*/
contract TransparentProxyUpgrader is PermanentOwnable {
using Address for address;

constructor() PermanentOwnable(msg.sender) {}

/**
Expand All @@ -23,11 +19,7 @@ contract TransparentProxyUpgrader is PermanentOwnable {
* @param data_ arbitrary data the proxy will be called with after the upgrade
*/
function upgrade(address what_, address to_, bytes calldata data_) external virtual onlyOwner {
if (data_.length > 0) {
ITransparentUpgradeableProxy(payable(what_)).upgradeToAndCall(to_, data_);
} else {
ITransparentUpgradeableProxy(payable(what_)).upgradeTo(to_);
}
ITransparentUpgradeableProxy(payable(what_)).upgradeToAndCall(to_, data_);
}

/**
Expand Down
82 changes: 82 additions & 0 deletions contracts/proxy/transparent/TransparentUpgradeableProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: MIT
// Reference: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.2/contracts/proxy/transparent/TransparentUpgradeableProxy.sol

pragma solidity ^0.8.4;

import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {IERC1967} from "@openzeppelin/contracts/interfaces/IERC1967.sol";

/**
* @notice The proxies module
*
* Interface for TransparentUpgradeableProxy.
**/
interface ITransparentUpgradeableProxy is IERC1967 {
/**
* @notice The function to upgrade the implementation contract with additional setup call if data is nonempty.
*/
function upgradeToAndCall(address, bytes calldata) external payable;

/**
* @notice The function to return the current implementation address.
*/
function implementation() external returns (address);
}

/**
* @notice This contract implements a proxy that is upgradeable by an admin.
*
* The implementation of this contract is based on OpenZeppelin's TransparentUpgradeableProxy.
* The main change is in the constructor. While the original contract deploys an instance of ProxyAdmin
* for every proxy, this implementation simply sets the specified address as the admin.
* Additionally, an implementation function has been added.
*
* For more information about proxy logic, please refer to the OpenZeppelin documentation.
*/
contract TransparentUpgradeableProxy is ERC1967Proxy {
address private immutable _admin;

error ProxyDeniedAdminAccess();

constructor(
address logic_,
address admin_,
bytes memory data_
) payable ERC1967Proxy(logic_, data_) {
_admin = admin_;
ERC1967Utils.changeAdmin(admin_);
}

function _fallback() internal virtual override {
if (msg.sender == _admin) {
bytes4 selector_ = msg.sig;

if (selector_ == ITransparentUpgradeableProxy.upgradeToAndCall.selector) {
_dispatchUpgradeToAndCall();
} else if (selector_ == ITransparentUpgradeableProxy.implementation.selector) {
bytes memory returndata_ = _dispatchImplementation();

assembly {
return(add(returndata_, 0x20), mload(returndata_))
}
} else {
revert ProxyDeniedAdminAccess();
}
} else {
super._fallback();
}
}

function _dispatchUpgradeToAndCall() private {
(address newImplementation_, bytes memory data_) = abi.decode(
msg.data[4:],
(address, bytes)
);
ERC1967Utils.upgradeToAndCall(newImplementation_, data_);
}

function _dispatchImplementation() private view returns (bytes memory) {
return abi.encode(_implementation());
}
}
33 changes: 18 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"publish-to-npm": "npm run lint-fix && bash ./scripts/publish.sh --public"
},
"dependencies": {
"@openzeppelin/contracts": "4.9.6",
"@openzeppelin/contracts-upgradeable": "4.9.6",
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "5.0.2",
"@uniswap/v2-core": "1.0.1",
"@uniswap/v2-periphery": "1.1.0-beta.0",
"@uniswap/v3-core": "1.0.1",
Expand Down
7 changes: 4 additions & 3 deletions test/access/MultiOwnable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ describe("MultiOwnable", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(multiOwnable.mockInit()).to.be.revertedWith("Initializable: contract is not initializing");
await expect(multiOwnable.__MultiOwnableMock_init()).to.be.revertedWith(
"Initializable: contract is already initialized",
await expect(multiOwnable.mockInit()).to.be.revertedWithCustomError(multiOwnable, "NotInitializing");
await expect(multiOwnable.__MultiOwnableMock_init()).to.be.revertedWithCustomError(
multiOwnable,
"InvalidInitialization",
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/access/RBAC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("RBAC", () => {

describe("access", () => {
it("should not initialize twice", async () => {
await expect(rbac.mockInit()).to.be.revertedWith("Initializable: contract is not initializing");
await expect(rbac.mockInit()).to.be.revertedWithCustomError(rbac, "NotInitializing");
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/access/extensions/RBACGroupable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("RBAC", () => {

describe("__RBACGroupable_init", () => {
it("should not initialize twice", async () => {
await expect(rbac.mockInit()).to.be.revertedWith("Initializable: contract is not initializing");
await expect(rbac.mockInit()).to.be.revertedWithCustomError(rbac, "NotInitializing");
});
});

Expand Down
Loading
Loading