Skip to content

Commit

Permalink
refactor: use immutable properties where possible
Browse files Browse the repository at this point in the history
This commit changes a few token properties to be `immutable` as this
reduces gas costs even further.

This was reported by Slither.

A gas report with changes in gas cost is attached.
  • Loading branch information
0x-r4bbit committed Sep 19, 2023
1 parent 1707f9e commit 9d8d19d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
54 changes: 27 additions & 27 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ AddEntryTest:test_AddEntry() (gas: 44369)
AddEntryTest:test_RevertWhen_EntryAlreadyExists() (gas: 42598)
AddEntryTest:test_RevertWhen_InvalidAddress() (gas: 25087)
AddEntryTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 14804)
CollectibleV1Test:test_Deployment() (gas: 38626)
CommunityERC20Test:test_Deployment() (gas: 29720)
CollectibleV1Test:test_Deployment() (gas: 36386)
CommunityERC20Test:test_Deployment() (gas: 27614)
CommunityTokenDeployerTest:test_Deployment() (gas: 14805)
CreateTest:test_Create() (gas: 2216454)
CreateTest:test_Create() (gas: 2489668)
CreateTest:test_Create() (gas: 2251262)
CreateTest:test_Create() (gas: 2548166)
CreateTest:test_RevertWhen_InvalidOwnerTokenAddress() (gas: 15523)
CreateTest:test_RevertWhen_InvalidReceiverAddress() (gas: 15656)
CreateTest:test_RevertWhen_InvalidSignerPublicKey() (gas: 17057)
Expand All @@ -16,34 +16,34 @@ CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16421)
CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16524)
DeployContracts:test() (gas: 120)
DeployOwnerAndMasterToken:test() (gas: 120)
DeployTest:test_Deploy() (gas: 4776466)
DeployTest:test_Deploy() (gas: 4869772)
DeployTest:test_Deployment() (gas: 14925)
DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 4772349)
DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 4866016)
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: 2612126)
DeployTest:test_RevertWhen_InvalidTokenMetadata() (gas: 2670624)
DeploymentTest:test_Deployment() (gas: 14671)
DeploymentTest:test_Deployment() (gas: 14671)
DeploymentTest:test_Deployment() (gas: 17250)
GetEntryTest:test_ReturnZeroAddressIfEntryDoesNotExist() (gas: 11906)
MintToTest:test_Deployment() (gas: 29742)
MintToTest:test_Deployment() (gas: 38626)
MintToTest:test_Deployment() (gas: 85460)
MintToTest:test_MintTo() (gas: 509094)
MintToTest:test_Deployment() (gas: 27636)
MintToTest:test_Deployment() (gas: 36386)
MintToTest:test_Deployment() (gas: 83220)
MintToTest:test_MintTo() (gas: 506888)
MintToTest:test_RevertWhen_AddressesAndAmountsAreNotEqualLength() (gas: 23778)
MintToTest:test_RevertWhen_MaxSupplyIsReached() (gas: 22859)
MintToTest:test_RevertWhen_MaxSupplyIsReached() (gas: 505067)
MintToTest:test_RevertWhen_MaxSupplyIsReached() (gas: 20653)
MintToTest:test_RevertWhen_MaxSupplyIsReached() (gas: 502655)
MintToTest:test_RevertWhen_MaxSupplyReached() (gas: 122988)
MintToTest:test_RevertWhen_SenderIsNotOwner() (gas: 35956)
OwnerTokenTest:test_Deployment() (gas: 85460)
RemoteBurnTest:test_Deployment() (gas: 38626)
RemoteBurnTest:test_Deployment() (gas: 85482)
RemoteBurnTest:test_RemoteBurn() (gas: 455309)
RemoteBurnTest:test_RevertWhen_RemoteBurn() (gas: 19091)
RemoteBurnTest:test_RevertWhen_SenderIsNotOwner() (gas: 24791)
MintToTest:test_RevertWhen_SenderIsNotOwner() (gas: 31544)
OwnerTokenTest:test_Deployment() (gas: 83220)
RemoteBurnTest:test_Deployment() (gas: 36386)
RemoteBurnTest:test_Deployment() (gas: 83242)
RemoteBurnTest:test_RemoteBurn() (gas: 450780)
RemoteBurnTest:test_RevertWhen_RemoteBurn() (gas: 14768)
RemoteBurnTest:test_RevertWhen_SenderIsNotOwner() (gas: 20379)
SetCommunityTokenDeployerAddressTest:test_RevertWhen_InvalidTokenDeployerAddress() (gas: 12963)
SetCommunityTokenDeployerAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12504)
SetCommunityTokenDeployerAddressTest:test_SetCommunityTokenDeployerAddress() (gas: 22807)
Expand All @@ -55,20 +55,20 @@ SetMasterTokenFactoryAddressTest:test_Deployment() (gas: 14805)
SetMasterTokenFactoryAddressTest:test_RevertWhen_InvalidTokenFactoryAddress() (gas: 13014)
SetMasterTokenFactoryAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12487)
SetMasterTokenFactoryAddressTest:test_SetOwnerTokenFactoryAddress() (gas: 22861)
SetMaxSupplyTest:test_Deployment() (gas: 29720)
SetMaxSupplyTest:test_Deployment() (gas: 85482)
SetMaxSupplyTest:test_RevertWhen_CalledBecauseMaxSupplyIsLocked() (gas: 16533)
SetMaxSupplyTest:test_Deployment() (gas: 27614)
SetMaxSupplyTest:test_Deployment() (gas: 83242)
SetMaxSupplyTest:test_RevertWhen_CalledBecauseMaxSupplyIsLocked() (gas: 14327)
SetMaxSupplyTest:test_RevertWhen_MaxSupplyLowerThanTotalSupply() (gas: 148572)
SetMaxSupplyTest:test_RevertWhen_SenderIsNotOwner() (gas: 12527)
SetMaxSupplyTest:test_RevertWhen_SenderIsNotOwner() (gas: 12817)
SetMaxSupplyTest:test_RevertWhen_SenderIsNotOwner() (gas: 16939)
SetMaxSupplyTest:test_SetMaxSupply() (gas: 15597)
SetOwnerTokenFactoryAddressTest:test_Deployment() (gas: 14805)
SetOwnerTokenFactoryAddressTest:test_RevertWhen_InvalidTokenFactoryAddress() (gas: 12992)
SetOwnerTokenFactoryAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12465)
SetOwnerTokenFactoryAddressTest:test_SetOwnerTokenFactoryAddress() (gas: 22862)
SetSignerPublicKeyTest:test_Deployment() (gas: 85460)
SetSignerPublicKeyTest:test_RevertWhen_SenderIsNotOwner() (gas: 17634)
SetSignerPublicKeyTest:test_SetSignerPublicKey() (gas: 26369)
SetSignerPublicKeyTest:test_Deployment() (gas: 83220)
SetSignerPublicKeyTest:test_RevertWhen_SenderIsNotOwner() (gas: 13222)
SetSignerPublicKeyTest:test_SetSignerPublicKey() (gas: 24163)
SetTokenDeployerAddressTest:test_RevertWhen_InvalidTokenDeployerAddress() (gas: 12964)
SetTokenDeployerAddressTest:test_RevertWhen_InvalidTokenDeployerAddress() (gas: 12964)
SetTokenDeployerAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12438)
Expand Down
8 changes: 4 additions & 4 deletions contracts/tokens/BaseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ abstract contract BaseToken is Context, ERC721Enumerable {
*/
uint256 public maxSupply;

address public ownerToken;
address public masterToken;
address public immutable ownerToken;
address public immutable masterToken;

/**
* If set to true, the contract owner can burn any token.
*/
bool public remoteBurnable;
bool public immutable remoteBurnable;

/**
* If set to false it acts as a soulbound token.
*/
bool public transferable;
bool public immutable transferable;

string public baseTokenURI;

Expand Down
2 changes: 1 addition & 1 deletion contracts/tokens/CommunityERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract CommunityERC20 is Context, Ownable, ERC20 {
*/
uint256 public maxSupply;

uint8 private customDecimals;
uint8 private immutable customDecimals;

constructor(
string memory _name,
Expand Down

0 comments on commit 9d8d19d

Please sign in to comment.