From 44b21b545c42e77a02462fb23df6490cfeef5b0f 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 | 34 +++++++++++------------ contracts/CommunityOwnerTokenRegistry.sol | 4 +-- contracts/CommunityTokenDeployer.sol | 4 +-- contracts/factories/BaseTokenFactory.sol | 4 +-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index ba08790..d2c0bf5 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,17 +16,17 @@ CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16421) CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16524) DeployContracts:test() (gas: 120) DeployOwnerAndMasterToken:test() (gas: 120) -DeployTest:test_Deploy() (gas: 4778686) +DeployTest:test_Deploy() (gas: 4778776) DeployTest:test_Deployment() (gas: 14947) -DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 4774488) -DeployTest:test_RevertWhen_InvalidCommunityAddress() (gas: 51318) -DeployTest:test_RevertWhen_InvalidDeployerAddress() (gas: 55205) -DeployTest:test_RevertWhen_InvalidDeploymentSignature() (gas: 65550) -DeployTest:test_RevertWhen_InvalidSignerPublicKey() (gas: 53366) -DeployTest:test_RevertWhen_InvalidTokenMetadata() (gas: 2612983) +DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 4774645) +DeployTest:test_RevertWhen_InvalidCommunityAddress() (gas: 51385) +DeployTest:test_RevertWhen_InvalidDeployerAddress() (gas: 55272) +DeployTest:test_RevertWhen_InvalidDeploymentSignature() (gas: 65617) +DeployTest:test_RevertWhen_InvalidSignerPublicKey() (gas: 53433) +DeployTest:test_RevertWhen_InvalidTokenMetadata() (gas: 2613184) 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) @@ -43,17 +43,17 @@ RemoteBurnTest:test_Deployment() (gas: 85482) RemoteBurnTest:test_RemoteBurn() (gas: 455309) RemoteBurnTest:test_RevertWhen_RemoteBurn() (gas: 19091) RemoteBurnTest:test_RevertWhen_SenderIsNotOwner() (gas: 24791) -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: 12992) SetMasterTokenFactoryAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12465) -SetMasterTokenFactoryAddressTest:test_SetOwnerTokenFactoryAddress() (gas: 22839) +SetMasterTokenFactoryAddressTest:test_SetOwnerTokenFactoryAddress() (gas: 22861) SetMaxSupplyTest:test_Deployment() (gas: 29720) SetMaxSupplyTest:test_Deployment() (gas: 85482) SetMaxSupplyTest:test_RevertWhen_CalledBecauseMaxSupplyIsLocked() (gas: 16533) 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 a33216f..82e0ff6 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();