improve updateValueAtNow

This commit is contained in:
Ricardo Guilherme Schmidt 2023-09-26 12:46:06 -03:00
parent f26130b402
commit 8dadbbb6e7
3 changed files with 38 additions and 33 deletions

View File

@ -1,21 +1,21 @@
| contracts/MiniMeToken.sol:MiniMeToken contract | | | | | | | contracts/MiniMeToken.sol:MiniMeToken contract | | | | | |
|------------------------------------------------|-----------------|-------|--------|-------|---------| |------------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
| 2135687 | 12092 | | | | | | 2142502 | 12126 | | | | |
| Function Name | min | avg | median | max | # calls | | Function Name | min | avg | median | max | # calls |
| DOMAIN_SEPARATOR | 387 | 387 | 387 | 387 | 10 | | DOMAIN_SEPARATOR | 387 | 387 | 387 | 387 | 10 |
| allowance | 0 | 190 | 0 | 763 | 16 | | allowance | 0 | 190 | 0 | 763 | 16 |
| approve | 0 | 15064 | 14767 | 31771 | 10 | | approve | 0 | 15064 | 14767 | 31771 | 10 |
| approveAndCall | 0 | 31140 | 0 | 93422 | 3 | | approveAndCall | 0 | 30979 | 0 | 92937 | 3 |
| balanceOf | 0 | 622 | 0 | 2753 | 67 | | balanceOf | 0 | 622 | 0 | 2753 | 67 |
| balanceOfAt | 0 | 830 | 0 | 3766 | 78 | | balanceOfAt | 0 | 830 | 0 | 3766 | 78 |
| changeController | 0 | 596 | 0 | 3580 | 6 | | changeController | 0 | 596 | 0 | 3580 | 6 |
| claimTokens | 9559 | 41038 | 56778 | 56778 | 3 | | claimTokens | 9559 | 40715 | 56293 | 56293 | 3 |
| controller | 0 | 0 | 0 | 0 | 10 | | controller | 0 | 0 | 0 | 0 | 10 |
| decimals | 0 | 0 | 0 | 0 | 10 | | decimals | 0 | 0 | 0 | 0 | 10 |
| destroyTokens | 2098 | 4857 | 3890 | 8585 | 3 | | destroyTokens | 2098 | 4543 | 3890 | 7643 | 3 |
| enableTransfers | 0 | 0 | 0 | 0 | 3 | | enableTransfers | 0 | 0 | 0 | 0 | 3 |
| generateTokens | 0 | 16436 | 0 | 95310 | 64 | | generateTokens | 0 | 16391 | 0 | 95282 | 64 |
| name | 0 | 0 | 0 | 0 | 10 | | name | 0 | 0 | 0 | 0 | 10 |
| nonces | 654 | 1854 | 2654 | 2654 | 5 | | nonces | 654 | 1854 | 2654 | 2654 | 5 |
| parentSnapShotBlock | 0 | 0 | 0 | 0 | 11 | | parentSnapShotBlock | 0 | 0 | 0 | 0 | 11 |
@ -25,8 +25,8 @@
| symbol | 0 | 0 | 0 | 0 | 10 | | symbol | 0 | 0 | 0 | 0 | 10 |
| totalSupply | 0 | 255 | 0 | 2480 | 23 | | totalSupply | 0 | 255 | 0 | 2480 | 23 |
| totalSupplyAt | 0 | 797 | 0 | 3398 | 17 | | totalSupplyAt | 0 | 797 | 0 | 3398 | 17 |
| transfer | 548 | 39069 | 50207 | 92814 | 20 | | transfer | 548 | 38898 | 49722 | 92786 | 20 |
| transferFrom | 0 | 19588 | 3495 | 66131 | 11 | | transferFrom | 0 | 19430 | 3495 | 65646 | 11 |

View File

@ -1,32 +1,32 @@
AllowanceTest:testAllowance() (gas: 42775) AllowanceTest:testAllowance() (gas: 42775)
AllowanceTest:testAllowanceAlreadySet() (gas: 36905) AllowanceTest:testAllowanceAlreadySet() (gas: 36905)
AllowanceTest:testAllowanceReset() (gas: 46071) AllowanceTest:testAllowanceReset() (gas: 46071)
AllowanceTest:testApproveAndCall() (gas: 98341) AllowanceTest:testApproveAndCall() (gas: 97856)
AllowanceTest:testApproveTransferDisabled() (gas: 7994) AllowanceTest:testApproveTransferDisabled() (gas: 7994)
AllowanceTest:testDeployment() (gas: 26711) AllowanceTest:testDeployment() (gas: 26711)
AllowanceTest:testNoAllowance() (gas: 9462) AllowanceTest:testNoAllowance() (gas: 9462)
AllowanceTest:testRejectedApproval() (gas: 13683) AllowanceTest:testRejectedApproval() (gas: 13683)
ClaimTokensTest:testClaimERC20() (gas: 63364) ClaimTokensTest:testClaimERC20() (gas: 62879)
ClaimTokensTest:testClaimETH() (gas: 13659) ClaimTokensTest:testClaimETH() (gas: 13659)
ClaimTokensTest:testClaimSelf() (gas: 60846) ClaimTokensTest:testClaimSelf() (gas: 60361)
ClaimTokensTest:testDeployment() (gas: 26595) ClaimTokensTest:testDeployment() (gas: 26595)
CreateCloneTokenTest:testCloneFutureSnapshot() (gas: 101032) CreateCloneTokenTest:testCloneFutureSnapshot() (gas: 101004)
CreateCloneTokenTest:testCreateCloneToken() (gas: 2174794) CreateCloneTokenTest:testCreateCloneToken() (gas: 2181617)
CreateCloneTokenTest:testDeployment() (gas: 26550) CreateCloneTokenTest:testDeployment() (gas: 26550)
CreateCloneTokenTest:testGenerateTokens() (gas: 101386) CreateCloneTokenTest:testGenerateTokens() (gas: 101358)
DestroyTokensTest:testDeployment() (gas: 26595) DestroyTokensTest:testDeployment() (gas: 26595)
DestroyTokensTest:testDestroyTokens() (gas: 13085) DestroyTokensTest:testDestroyTokens() (gas: 12143)
DestroyTokensTest:testDestroyTokensNotEnoughBalance() (gas: 9246) DestroyTokensTest:testDestroyTokensNotEnoughBalance() (gas: 9246)
DestroyTokensTest:testDestroyTokensNotEnoughSupply() (gas: 7787) DestroyTokensTest:testDestroyTokensNotEnoughSupply() (gas: 7787)
GenerateTokensTest:testDeployment() (gas: 26550) GenerateTokensTest:testDeployment() (gas: 26550)
GenerateTokensTest:testGenerateTokens() (gas: 109522) GenerateTokensTest:testGenerateTokens() (gas: 109494)
GenerateTokensTest:testGenerateTokensSupplyOverflow() (gas: 3126) GenerateTokensTest:testGenerateTokensSupplyOverflow() (gas: 3126)
GenerateTokensTest:test_RevertWhen_SenderIsNotController() (gas: 14951) GenerateTokensTest:test_RevertWhen_SenderIsNotController() (gas: 14951)
MiniMeTokenTest:testDeployment() (gas: 26535) MiniMeTokenTest:testDeployment() (gas: 26535)
ReceiveTest:testAcceptingEther() (gas: 18628) ReceiveTest:testAcceptingEther() (gas: 18628)
ReceiveTest:testDeployment() (gas: 26595) ReceiveTest:testDeployment() (gas: 26595)
ReceiveTest:testRejectingEther() (gas: 18691) ReceiveTest:testRejectingEther() (gas: 18691)
ReentrancyTest:testAttack() (gas: 228605) ReentrancyTest:testAttack() (gas: 228092)
TestPermit:testDeployment() (gas: 26573) TestPermit:testDeployment() (gas: 26573)
TestPermit:testInvalidAllowance() (gas: 84299) TestPermit:testInvalidAllowance() (gas: 84299)
TestPermit:testInvalidBalance() (gas: 67380) TestPermit:testInvalidBalance() (gas: 67380)
@ -35,21 +35,21 @@ TestPermit:testRevertExpiredPermit() (gas: 27867)
TestPermit:testRevertInvalidNonce() (gas: 57221) TestPermit:testRevertInvalidNonce() (gas: 57221)
TestPermit:testRevertInvalidSigner() (gas: 56059) TestPermit:testRevertInvalidSigner() (gas: 56059)
TestPermit:testRevertSignatureReplay() (gas: 96568) TestPermit:testRevertSignatureReplay() (gas: 96568)
TestPermit:testTransferFromLimitedPermit() (gas: 215505) TestPermit:testTransferFromLimitedPermit() (gas: 214992)
TestPermit:testTransferFromMaxPermit() (gas: 235444) TestPermit:testTransferFromMaxPermit() (gas: 234931)
TestSnapshotReads:testDeployment() (gas: 26550) TestSnapshotReads:testDeployment() (gas: 26550)
TestSnapshotReads:testSnapshotReads() (gas: 743821) TestSnapshotReads:testSnapshotReads() (gas: 741048)
TransferTest:testDeployment() (gas: 26617) TransferTest:testDeployment() (gas: 26617)
TransferTest:testDoubleTransfer() (gas: 91839) TransferTest:testDoubleTransfer() (gas: 91011)
TransferTest:testDoubleTransfer2() (gas: 69782) TransferTest:testDoubleTransfer2() (gas: 69096)
TransferTest:testInvalidDestinationTransfer() (gas: 6424) TransferTest:testInvalidDestinationTransfer() (gas: 6424)
TransferTest:testInvalidDestinationTransfer2() (gas: 6421) TransferTest:testInvalidDestinationTransfer2() (gas: 6421)
TransferTest:testMultipleTransferToSame() (gas: 114069) TransferTest:testMultipleTransferToSame() (gas: 113840)
TransferTest:testMultipleTransferToSame2() (gas: 92056) TransferTest:testMultipleTransferToSame2() (gas: 91969)
TransferTest:testRejectedTransfer() (gas: 59733) TransferTest:testRejectedTransfer() (gas: 59248)
TransferTest:testTransfer() (gas: 81530) TransferTest:testTransfer() (gas: 81644)
TransferTest:testTransfer2() (gas: 59496) TransferTest:testTransfer2() (gas: 59752)
TransferTest:testTransferControllerZero() (gas: 59653) TransferTest:testTransferControllerZero() (gas: 59168)
TransferTest:testTransferDisabled() (gas: 7990) TransferTest:testTransferDisabled() (gas: 7990)
TransferTest:testTransferFromDisabled() (gas: 6526) TransferTest:testTransferFromDisabled() (gas: 6526)
TransferTest:testTransferNoBalance() (gas: 16949) TransferTest:testTransferNoBalance() (gas: 16949)

View File

@ -441,13 +441,18 @@ abstract contract MiniMeBase is Controlled, IERC20, IERC20Permit, EIP712, Nonces
/// @param checkpoints The history of data being updated /// @param checkpoints The history of data being updated
/// @param _value The new number of tokens /// @param _value The new number of tokens
function updateValueAtNow(Checkpoint[] storage checkpoints, uint256 _value) internal { function updateValueAtNow(Checkpoint[] storage checkpoints, uint256 _value) internal {
if ((checkpoints.length == 0) || (checkpoints[checkpoints.length - 1].fromBlock < block.number)) { uint256 len = checkpoints.length;
Checkpoint storage newCheckPoint = checkpoints.push(); if (len > 0) {
newCheckPoint.fromBlock = uint128(block.number); Checkpoint storage checkpoint = checkpoints[len - 1];
newCheckPoint.value = uint128(_value); if (checkpoint.fromBlock < block.number) {
checkpoint = checkpoints.push();
checkpoint.fromBlock = uint128(block.number);
}
checkpoint.value = uint128(_value);
} else { } else {
Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length - 1]; Checkpoint storage checkpoint = checkpoints.push();
oldCheckPoint.value = uint128(_value); checkpoint.fromBlock = uint128(block.number);
checkpoint.value = uint128(_value);
} }
} }