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"`
This commit is contained in:
r4bbit 2024-02-28 09:14:30 +01:00
parent a84c46b3d6
commit fcf30cde8f
3 changed files with 12 additions and 10 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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);
}
}