From fcf30cde8faf03143b680172b03da7cf47691958 Mon Sep 17 00:00:00 2001 From: r4bbit <445106+0x-r4bbit@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:14:30 +0100 Subject: [PATCH] refactor(OwnerToken)!: use custom error in `setMaxSupply` This changes the usage of a string error message to a custom error for slight gas improvements. BREAKING CHANGE: `OwnerToken.setMaxSupply(uint256)` now emits `OwnerToken.OwnerToken_MaxSupplyLocked.selector` instead of `"max supply locked"` --- .gas-snapshot | 14 +++++++------- contracts/tokens/OwnerToken.sol | 6 ++++-- test/OwnerToken.t.sol | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index cb7f201..4fc933d 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -7,8 +7,8 @@ CommunityTokenDeployerTest:test_Deployment() (gas: 14805) CommunityVaultBaseERC20Test:test_Deployment() (gas: 10436) CommunityVaultBaseERC721Test:test_Deployment() (gas: 10436) CommunityVaultTest:test_Deployment() (gas: 10436) -CreateTest:test_Create() (gas: 2440150) -CreateTest:test_Create() (gas: 2731735) +CreateTest:test_Create() (gas: 2374801) +CreateTest:test_Create() (gas: 2661968) CreateTest:test_RevertWhen_InvalidOwnerTokenAddress() (gas: 15523) CreateTest:test_RevertWhen_InvalidReceiverAddress() (gas: 15656) CreateTest:test_RevertWhen_InvalidSignerPublicKey() (gas: 17057) @@ -18,14 +18,14 @@ CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16421) CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16524) DeployContracts:test() (gas: 120) DeployOwnerAndMasterToken:test() (gas: 120) -DeployTest:test_Deploy() (gas: 5244498) +DeployTest:test_Deploy() (gas: 5109377) DeployTest:test_Deployment() (gas: 14947) -DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 5240774) +DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 5105653) 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: 2857514) +DeployTest:test_RevertWhen_InvalidTokenMetadata() (gas: 2787747) DeploymentTest:test_Deployment() (gas: 14671) DeploymentTest:test_Deployment() (gas: 14671) DeploymentTest:test_Deployment() (gas: 17295) @@ -64,9 +64,9 @@ SetMasterTokenFactoryAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12465) SetMasterTokenFactoryAddressTest:test_SetOwnerTokenFactoryAddress() (gas: 22861) SetMaxSupplyTest:test_Deployment() (gas: 35198) SetMaxSupplyTest:test_Deployment() (gas: 83330) -SetMaxSupplyTest:test_RevertWhen_CalledBecauseMaxSupplyIsLocked() (gas: 14304) +SetMaxSupplyTest:test_RevertWhen_CalledBecauseMaxSupplyIsLocked() (gas: 13876) SetMaxSupplyTest:test_RevertWhen_MaxSupplyLowerThanTotalSupply() (gas: 163551) -SetMaxSupplyTest:test_RevertWhen_SenderIsNotOwner() (gas: 12459) +SetMaxSupplyTest:test_RevertWhen_SenderIsNotOwner() (gas: 12456) SetMaxSupplyTest:test_RevertWhen_SenderIsNotOwner() (gas: 21355) SetMaxSupplyTest:test_SetMaxSupply() (gas: 23953) SetOwnerTokenFactoryAddressTest:test_Deployment() (gas: 14805) diff --git a/contracts/tokens/OwnerToken.sol b/contracts/tokens/OwnerToken.sol index d9cf1e4..44cc03a 100644 --- a/contracts/tokens/OwnerToken.sol +++ b/contracts/tokens/OwnerToken.sol @@ -5,6 +5,8 @@ import { BaseToken } from "./BaseToken.sol"; import { CommunityOwnable } from "../CommunityOwnable.sol"; contract OwnerToken is BaseToken { + error OwnerToken_MaxSupplyLocked(); + bytes public signerPublicKey; constructor( @@ -22,8 +24,8 @@ contract OwnerToken is BaseToken { _mintTo(addresses); } - function setMaxSupply(uint256 _newMaxSupply) external override onlyCommunityOwnerOrTokenMaster { - revert("max supply locked"); + function setMaxSupply(uint256 _newMaxSupply) external view override onlyCommunityOwnerOrTokenMaster { + revert OwnerToken_MaxSupplyLocked(); } function setSignerPublicKey(bytes memory _newSignerPublicKey) external onlyCommunityOwnerOrTokenMaster { diff --git a/test/OwnerToken.t.sol b/test/OwnerToken.t.sol index 2b047da..5f5a901 100644 --- a/test/OwnerToken.t.sol +++ b/test/OwnerToken.t.sol @@ -50,7 +50,7 @@ contract SetMaxSupplyTest is OwnerTokenTest { function test_RevertWhen_CalledBecauseMaxSupplyIsLocked() public { vm.startPrank(deployer); - vm.expectRevert(bytes("max supply locked")); + vm.expectRevert(OwnerToken.OwnerToken_MaxSupplyLocked.selector); ownerToken.setMaxSupply(1000); } }