Skip to content

Commit

Permalink
refactor: use immutable properties where possible (#5)
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 22, 2023
1 parent 8f633ee commit e7d799b
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: 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)
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,33 +16,33 @@ CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16421)
CreateTest:test_RevertWhen_SenderIsNotTokenDeployer() (gas: 16524)
DeployContracts:test() (gas: 120)
DeployOwnerAndMasterToken:test() (gas: 120)
DeployTest:test_Deploy() (gas: 4778776)
DeployTest:test_Deploy() (gas: 4872082)
DeployTest:test_Deployment() (gas: 14947)
DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 4774645)
DeployTest:test_RevertWhen_AlreadyDeployed() (gas: 4868312)
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)
DeployTest:test_RevertWhen_InvalidTokenMetadata() (gas: 2671682)
DeploymentTest:test_Deployment() (gas: 14671)
DeploymentTest:test_Deployment() (gas: 14671)
DeploymentTest:test_Deployment() (gas: 17295)
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: 12941)
SetCommunityTokenDeployerAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12482)
SetCommunityTokenDeployerAddressTest:test_SetCommunityTokenDeployerAddress() (gas: 22808)
Expand All @@ -54,20 +54,20 @@ SetMasterTokenFactoryAddressTest:test_Deployment() (gas: 14805)
SetMasterTokenFactoryAddressTest:test_RevertWhen_InvalidTokenFactoryAddress() (gas: 12992)
SetMasterTokenFactoryAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12465)
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: 12970)
SetOwnerTokenFactoryAddressTest:test_RevertWhen_SenderIsNotOwner() (gas: 12443)
SetOwnerTokenFactoryAddressTest:test_SetOwnerTokenFactoryAddress() (gas: 22840)
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 e7d799b

Please sign in to comment.