From c036ff1252c0fb67d3e25fb840814b147ea1037e Mon Sep 17 00:00:00 2001 From: r4bbit <445106+0x-r4bbit@users.noreply.github.com> Date: Wed, 13 Sep 2023 09:37:10 +0200 Subject: [PATCH] refactor: use `Ownable2Step` instead of `Ownable` This has been discussed in #7 and be further explored in https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3620 Closes #7 --- .gas-snapshot | 36 +++++++++++------------ contracts/CommunityOwnerTokenRegistry.sol | 4 +-- contracts/CommunityTokenDeployer.sol | 4 +-- contracts/factories/BaseTokenFactory.sol | 4 +-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 57cdd8a..d70d35c 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,7 +1,7 @@ -AddEntryTest:test_AddEntry() (gas: 44369) -AddEntryTest:test_RevertWhen_EntryAlreadyExists() (gas: 42598) -AddEntryTest:test_RevertWhen_InvalidAddress() (gas: 25087) -AddEntryTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 14804) +AddEntryTest:test_AddEntry() (gas: 44392) +AddEntryTest:test_RevertWhen_EntryAlreadyExists() (gas: 42644) +AddEntryTest:test_RevertWhen_InvalidAddress() (gas: 25133) +AddEntryTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 14827) CollectibleV1Test:test_Deployment() (gas: 38626) CommunityERC20Test:test_Deployment() (gas: 29720) CommunityTokenDeployerTest:test_Deployment() (gas: 14805) @@ -16,18 +16,18 @@ CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16421) CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16524) DeployContracts:test() (gas: 120) DeployOwnerAndMasterToken:test() (gas: 120) -DeployTest:test_Deploy() (gas: 4840232) +DeployTest:test_Deploy() (gas: 4840322) DeployTest:test_Deployment() (gas: 14925) -DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 4836115) -DeployTest:test_RevertWhen_DeploymentSignatureExpired() (gas: 53642) -DeployTest:test_RevertWhen_InvalidCommunityAddress() (gas: 51341) -DeployTest:test_RevertWhen_InvalidDeployerAddress() (gas: 55329) -DeployTest:test_RevertWhen_InvalidDeploymentSignature() (gas: 65663) -DeployTest:test_RevertWhen_InvalidSignerPublicKey() (gas: 53435) -DeployTest:test_RevertWhen_InvalidTokenMetadata() (gas: 2639807) +DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 4836205) +DeployTest:test_RevertWhen_DeploymentSignatureExpired() (gas: 53709) +DeployTest:test_RevertWhen_InvalidCommunityAddress() (gas: 51408) +DeployTest:test_RevertWhen_InvalidDeployerAddress() (gas: 55396) +DeployTest:test_RevertWhen_InvalidDeploymentSignature() (gas: 65730) +DeployTest:test_RevertWhen_InvalidSignerPublicKey() (gas: 53502) +DeployTest:test_RevertWhen_InvalidTokenMetadata() (gas: 2639874) DeploymentTest:test_Deployment() (gas: 14671) DeploymentTest:test_Deployment() (gas: 14671) -DeploymentTest:test_Deployment() (gas: 17250) +DeploymentTest:test_Deployment() (gas: 17295) GetEntryTest:test_ReturnZeroAddressIfEntryDoesNotExist() (gas: 11906) MintToTest:test_Deployment() (gas: 29742) MintToTest:test_Deployment() (gas: 38626) @@ -44,17 +44,17 @@ RemoteBurnTest:test_Deployment() (gas: 85482) RemoteBurnTest:test_RemoteBurn() (gas: 455285) RemoteBurnTest:test_RevertWhen_RemoteBurn() (gas: 19499) RemoteBurnTest:test_RevertWhen_SenderIsNotOwner() (gas: 25211) -SetCommunityTokenDeployerAddressTest:test_RevertWhen_InvalidTokenDeployerAddress() (gas: 12963) -SetCommunityTokenDeployerAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12504) -SetCommunityTokenDeployerAddressTest:test_SetCommunityTokenDeployerAddress() (gas: 22807) +SetCommunityTokenDeployerAddressTest:test_RevertWhen_InvalidTokenDeployerAddress() (gas: 12941) +SetCommunityTokenDeployerAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12482) +SetCommunityTokenDeployerAddressTest:test_SetCommunityTokenDeployerAddress() (gas: 22808) SetDeploymentRegistryAddressTest:test_Deployment() (gas: 14827) SetDeploymentRegistryAddressTest:test_RevertWhen_InvalidDeploymentRegistryAddress() (gas: 13014) SetDeploymentRegistryAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12508) -SetDeploymentRegistryAddressTest:test_SetDeploymentRegistryAddress() (gas: 22903) +SetDeploymentRegistryAddressTest:test_SetDeploymentRegistryAddress() (gas: 22881) SetMasterTokenFactoryAddressTest:test_Deployment() (gas: 14805) SetMasterTokenFactoryAddressTest:test_RevertWhen_InvalidTokenFactoryAddress() (gas: 13014) SetMasterTokenFactoryAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12487) -SetMasterTokenFactoryAddressTest:test_SetOwnerTokenFactoryAddress() (gas: 22861) +SetMasterTokenFactoryAddressTest:test_SetOwnerTokenFactoryAddress() (gas: 22883) SetMaxSupplyTest:test_Deployment() (gas: 29720) SetMaxSupplyTest:test_Deployment() (gas: 85482) SetMaxSupplyTest:test_RevertWhen_CalledBecauseMaxSupplyIsLocked() (gas: 16521) diff --git a/contracts/CommunityOwnerTokenRegistry.sol b/contracts/CommunityOwnerTokenRegistry.sol index 45bbe7b..63c4dea 100644 --- a/contracts/CommunityOwnerTokenRegistry.sol +++ b/contracts/CommunityOwnerTokenRegistry.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.17; -import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; +import { Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol"; import { IAddressRegistry } from "./interfaces/IAddressRegistry.sol"; import { OwnerToken } from "./tokens/OwnerToken.sol"; @@ -24,7 +24,7 @@ import { OwnerToken } from "./tokens/OwnerToken.sol"; * registry contract. * @dev Only `tokenDeployer` can add entries to the registry. */ -contract CommunityOwnerTokenRegistry is IAddressRegistry, Ownable { +contract CommunityOwnerTokenRegistry is IAddressRegistry, Ownable2Step { error CommunityOwnerTokenRegistry_NotAuthorized(); error CommunityOwnerTokenRegistry_EntryAlreadyExists(); error CommunityOwnerTokenRegistry_InvalidAddress(); diff --git a/contracts/CommunityTokenDeployer.sol b/contracts/CommunityTokenDeployer.sol index a85fd51..b30cb68 100644 --- a/contracts/CommunityTokenDeployer.sol +++ b/contracts/CommunityTokenDeployer.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.17; -import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; +import { Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol"; import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; import { ITokenFactory } from "./interfaces/ITokenFactory.sol"; @@ -39,7 +39,7 @@ import { IAddressRegistry } from "./interfaces/IAddressRegistry.sol"; * @dev The `CommunityOwnerTokenFactory` address can be changed by the owner of this contract. * @dev The `CommunityMasterTokenFactory` address can be changed by the owner of this contract. */ -contract CommunityTokenDeployer is EIP712("CommunityTokenDeployer", "1"), Ownable { +contract CommunityTokenDeployer is EIP712("CommunityTokenDeployer", "1"), Ownable2Step { using ECDSA for bytes32; error CommunityTokenDeployer_InvalidDeploymentRegistryAddress(); diff --git a/contracts/factories/BaseTokenFactory.sol b/contracts/factories/BaseTokenFactory.sol index e3cb3a8..8239631 100644 --- a/contracts/factories/BaseTokenFactory.sol +++ b/contracts/factories/BaseTokenFactory.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.17; import { ITokenFactory } from "../interfaces/ITokenFactory.sol"; -import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; +import { Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol"; /** * @title BaseTokenFactory contract @@ -15,7 +15,7 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; * * @dev Other factory contract inherit from this contract. */ -abstract contract BaseTokenFactory is ITokenFactory, Ownable { +abstract contract BaseTokenFactory is ITokenFactory, Ownable2Step { error BaseTokenFactory_InvalidTokenDeployerAddress(); error BaseTokenFactory_NotAuthorized(); error BaseTokenFactory_InvalidTokenMetadata();