From 7b862e4939d8ccdc6d70bf846917fadb91d1f179 Mon Sep 17 00:00:00 2001 From: stadolf Date: Sat, 24 Feb 2024 15:09:16 -0700 Subject: [PATCH] adjusts vesting contracts & test suite to oz5 & solidity 8.24 Signed-off-by: stadolf --- .gas-snapshot | 43 ++++++++++++++++---------------- contracts/TokenVesting.sol | 8 +++--- contracts/TokenVestingMerkle.sol | 2 +- contracts/test/Token.sol | 2 +- foundry.toml | 2 +- test/TokenVesting.t.sol | 15 ++++------- 6 files changed, 34 insertions(+), 38 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 4ec66c8..93e61fb 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,21 +1,22 @@ -TokenVestingMerkleTest:testCanOnlyClaimOnce() (gas: 308286) -TokenVestingMerkleTest:testCannotClaimWithoutTokens() (gas: 94109) -TokenVestingMerkleTest:testProofMustBeValid() (gas: 41172) -TokenVestingMerkleTest:testcanClaimSchedule() (gas: 305416) -TokenVestingTest:testCanOnlyBeRevokedIfRevokable() (gas: 306345) -TokenVestingTest:testCannotClaimMoreThanAvailable() (gas: 568697) -TokenVestingTest:testClaimAvailableTokens() (gas: 568743) -TokenVestingTest:testComputationMultipleForSchedules() (gas: 474575) -TokenVestingTest:testFuzzCreateAndRelease(uint256,uint256) (runs: 256, μ: 2439562, ~: 2442361) -TokenVestingTest:testGradualTokenVesting() (gas: 393032) -TokenVestingTest:testNativeTokenDecimals() (gas: 665021) -TokenVestingTest:testNonOwnerCannotCreateSchedule() (gas: 52168) -TokenVestingTest:testNonOwnerCannotRevokeSchedule() (gas: 308653) -TokenVestingTest:testNonTransferability() (gas: 312611) -TokenVestingTest:testRevokeScheduleReleasesVestedTokens() (gas: 340297) -TokenVestingTest:testScheduleIndexComputation() (gas: 8090) -TokenVestingTest:testTextInputParameterChecks() (gas: 76477) -TokenVestingTest:testTokenSupply() (gas: 12771) -TokenVestingTest:testVirtualTokenMeta() (gas: 15447) -TokenVestingTest:testVirtualTokenTotalSupplyAndBalance() (gas: 325425) -TokenVestingTest:testWrongToken() (gas: 119043) \ No newline at end of file +TokenVestingMerkleTest:testCanOnlyClaimOnce() (gas: 308308) +TokenVestingMerkleTest:testCannotClaimWithoutTokens() (gas: 94202) +TokenVestingMerkleTest:testProofMustBeValid() (gas: 41195) +TokenVestingMerkleTest:testcanClaimSchedule() (gas: 305318) +TokenVestingTest:testCanOnlyBeRevokedIfRevokable() (gas: 308729) +TokenVestingTest:testCannotClaimMoreThanAvailable() (gas: 571392) +TokenVestingTest:testClaimAvailableTokens() (gas: 571393) +TokenVestingTest:testComputationMultipleForSchedules() (gas: 475186) +TokenVestingTest:testFuzzCreateAndRelease(uint256,uint256) (runs: 256, μ: 2517777, ~: 2518710) +TokenVestingTest:testGradualTokenVesting() (gas: 400975) +TokenVestingTest:testNativeTokenDecimals() (gas: 604228) +TokenVestingTest:testNonOwnerCannotRevokeSchedule() (gas: 311502) +TokenVestingTest:testNonTransferability() (gas: 316473) +TokenVestingTest:testOnlySchedulerRoleCanCreateSchedule() (gas: 53899) +TokenVestingTest:testRevokeScheduleReleasesVestedTokens() (gas: 342847) +TokenVestingTest:testScheduleIndexComputation() (gas: 8111) +TokenVestingTest:testTextInputParameterChecks() (gas: 77401) +TokenVestingTest:testTokenSupply() (gas: 12749) +TokenVestingTest:testVestingWithCliff() (gas: 314706) +TokenVestingTest:testVirtualTokenMeta() (gas: 15513) +TokenVestingTest:testVirtualTokenTotalSupplyAndBalance() (gas: 328198) +TokenVestingTest:testWrongToken() (gas: 119132) \ No newline at end of file diff --git a/contracts/TokenVesting.sol b/contracts/TokenVesting.sol index fc4119e..9d56ae1 100644 --- a/contracts/TokenVesting.sol +++ b/contracts/TokenVesting.sol @@ -1,14 +1,14 @@ // contracts/TokenVesting.sol // SPDX-License-Identifier: Apache-2.0 -pragma solidity 0.8.18; +pragma solidity 0.8.24; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; +import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; -import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol"; +import { Pausable } from "@openzeppelin/contracts/utils/Pausable.sol"; /// @title TokenVesting - On-Chain vesting scheme enabled by smart contracts. /// The TokenVesting contract can release its token balance gradually like a @@ -133,7 +133,7 @@ contract TokenVesting is IERC20Metadata, Ownable, ReentrancyGuard, Pausable, Acc * @param _name name of the virtual token * @param _symbol symbol of the virtual token */ - constructor(IERC20Metadata token_, string memory _name, string memory _symbol) { + constructor(IERC20Metadata token_, string memory _name, string memory _symbol) Ownable(msg.sender) { nativeToken = token_; if (nativeToken.decimals() != 18) revert DecimalsError(); name = _name; diff --git a/contracts/TokenVestingMerkle.sol b/contracts/TokenVestingMerkle.sol index d7943fb..009ef8a 100644 --- a/contracts/TokenVestingMerkle.sol +++ b/contracts/TokenVestingMerkle.sol @@ -1,6 +1,6 @@ // contracts/TokenVestingMerkle.sol // SPDX-License-Identifier: Apache-2.0 -pragma solidity 0.8.18; +pragma solidity 0.8.24; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { TokenVesting } from "./TokenVesting.sol"; diff --git a/contracts/test/Token.sol b/contracts/test/Token.sol index 635948f..72c5699 100644 --- a/contracts/test/Token.sol +++ b/contracts/test/Token.sol @@ -1,6 +1,6 @@ // contracts/Token.sol // SPDX-License-Identifier: Apache-2.0 -pragma solidity 0.8.18; +pragma solidity 0.8.24; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; diff --git a/foundry.toml b/foundry.toml index 0c13ff4..5712557 100644 --- a/foundry.toml +++ b/foundry.toml @@ -3,7 +3,7 @@ src = 'contracts' out = 'out' libs = ['lib'] test = 'test' -solc_version = "0.8.18" +solc_version = "0.8.24" gas_reports = ["TokenVesting", "TokenVestingMerkle"] [fmt] diff --git a/test/TokenVesting.t.sol b/test/TokenVesting.t.sol index 7b021c3..33197ca 100644 --- a/test/TokenVesting.t.sol +++ b/test/TokenVesting.t.sol @@ -4,7 +4,8 @@ pragma solidity ^0.8.18; import "forge-std/Test.sol"; import { console } from "forge-std/console.sol"; import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; - +import {IAccessControl} from '@openzeppelin/contracts/access/IAccessControl.sol'; +import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { Token } from "../contracts/test/Token.sol"; import { TokenVesting } from "../contracts/TokenVesting.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; @@ -181,7 +182,7 @@ contract TokenVestingTest is Test { bytes32 vestingScheduleId = tokenVesting.computeVestingScheduleIdForAddressAndIndex(alice, 0); vm.startPrank(bob); - vm.expectRevert("Ownable: caller is not the owner"); + vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, bob)); tokenVesting.revoke(vestingScheduleId); vm.stopPrank(); } @@ -209,15 +210,9 @@ contract TokenVestingTest is Test { token.transfer(address(tokenVesting), 100 ether); vm.stopPrank(); vm.startPrank(alice); - - bytes memory expectedError = abi.encodePacked( - "AccessControl: account ", - Strings.toHexString(alice), - " is missing role ", - Strings.toHexString(uint256(tokenVesting.ROLE_CREATE_SCHEDULE())) + vm.expectRevert( + abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, tokenVesting.ROLE_CREATE_SCHEDULE()) ); - - vm.expectRevert(expectedError); tokenVesting.createVestingSchedule(alice, baseTime, 0, duration, 1, true, 100 ether); vm.stopPrank(); }