Skip to content

Commit 0cf6981

Browse files
committed
fix: define startTime param
1 parent cb3ff32 commit 0cf6981

File tree

7 files changed

+139
-74
lines changed

7 files changed

+139
-74
lines changed

src/tokenDistribution/MetaTokenDistributor.sol

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,24 @@ contract MetaTokenDistributor is IMetaTokenDistributor {
1818
IERC20 private _META;
1919

2020
IVestingParams private _vestingParams;
21-
uint64 private _vestingStartTime;
2221

2322
mapping(VestingType vestingType => address vesting) private _vestingAddresses;
2423

2524
modifier validateTime(VestingType vestingType) {
26-
if (block.timestamp < _vestingStartTime) {
25+
uint64 startTime = _vestingParams.getStartTime();
26+
27+
if (block.timestamp < startTime) {
2728
revert VestingStartTimeHasNotArrived();
2829
}
2930

3031
_;
3132
}
3233

33-
constructor(address vestingParams, uint64 vestingStartTime) {
34-
if (vestingStartTime < block.timestamp) {
35-
revert InvalidVestingStartTime();
36-
}
37-
34+
constructor(address vestingParams) {
3835
if (address(vestingParams) == address(0)) {
3936
revert ZeroAddress();
4037
}
4138

42-
_vestingStartTime = vestingStartTime;
4339
_vestingParams = IVestingParams(vestingParams);
4440

4541
_vestingImpl = address(new Vesting());
@@ -82,8 +78,4 @@ contract MetaTokenDistributor is IMetaTokenDistributor {
8278
function getVestingParamsAddress() external view returns (address) {
8379
return address(_vestingParams);
8480
}
85-
86-
function getVestingStartTime() external view returns (uint64) {
87-
return _vestingStartTime;
88-
}
8981
}

src/tokenDistribution/interfaces/IMetaTokenDistributor.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ interface IMetaTokenDistributor {
77
event VestingStarted(address vesting);
88
event MetaTokenDeployed(address META);
99

10-
error InvalidVestingStartTime();
1110
error VestingStartTimeHasNotArrived();
1211
error ZeroAddress();
1312
error VestingHasAlreadyStarted();
@@ -16,5 +15,4 @@ interface IMetaTokenDistributor {
1615
function getMETAAddress() external view returns (address);
1716
function getVestingAddress(VestingType vestingType) external view returns (address);
1817
function getVestingParamsAddress() external view returns (address);
19-
function getVestingStartTime() external view returns (uint64);
2018
}

src/tokenDistribution/vesting/VestingParams.sol

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ contract VestingParams is IVestingParams {
2121
uint256 public constant LIQUIDITY_CLIFF_PERIOD = 4 * MONTH; // 4 month
2222
uint256 public constant LIQUIDITY_VESTING_PORTION = 400; // 4%
2323

24+
uint64 private _startTime;
2425
mapping(VestingType vestingType => Beneficiary[] beneficiaries) private _beneficiaries;
2526

2627
constructor(
28+
uint64 startTime,
2729
Beneficiary[] memory teamBeneficiaries,
2830
Beneficiary[] memory liquidityBeneficiaries
2931
) {
32+
if (startTime < block.timestamp) {
33+
revert InvalidStartTime();
34+
}
35+
36+
_startTime = startTime;
37+
3038
_validateAndStoreBeneficiaries(VestingType.TEAM, teamBeneficiaries, TEAM_TOTAL_AMOUNT);
3139
_validateAndStoreBeneficiaries(VestingType.LIQUIDITY, liquidityBeneficiaries, LIQUIDITY_TOTAL_AMOUNT);
3240
}
@@ -44,20 +52,19 @@ contract VestingParams is IVestingParams {
4452
Period[] memory periods = new Period[](numberOfPeriods);
4553

4654
// TGE
47-
periods[0] = Period({endTime: block.timestamp, portion: tgePortion});
55+
periods[0] = Period({endTime: _startTime, portion: tgePortion});
4856

4957
// Cliff period
50-
periods[1] = Period({endTime: block.timestamp + cliffPeriod, portion: 0});
58+
periods[1] = Period({endTime: _startTime + cliffPeriod, portion: 0});
5159

5260
// Vesting period
53-
uint256 vestingStartTime = block.timestamp + cliffPeriod;
61+
uint256 vestingStartTime = _startTime + cliffPeriod;
5462
for (uint256 i = 2; i < numberOfPeriods; i++) {
5563
periods[i] = Period({endTime: vestingStartTime + (i - 1) * MONTH, portion: vestingPortion});
5664
}
5765

5866
schedule = Schedule({
59-
// TODO: подумать на тем, как упростить время
60-
startTime: block.timestamp, // Start time is vesting creation time
67+
startTime: _startTime,
6168
periods: periods
6269
});
6370
}
@@ -116,6 +123,10 @@ contract VestingParams is IVestingParams {
116123
);
117124
}
118125

126+
function getStartTime() external view returns (uint64) {
127+
return _startTime;
128+
}
129+
119130
function _validateAndStoreBeneficiaries(
120131
VestingType vestingType,
121132
Beneficiary[] memory beneficiaries,

src/tokenDistribution/vesting/interfaces/IVestingParams.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity 0.8.28;
44
import {VestingType, Beneficiary, Schedule} from "../../utils/Common.sol";
55

66
interface IVestingParams {
7+
error InvalidStartTime();
78
error ZeroBeneficiaries();
89
error ZeroAddress();
910
error ZeroAmount();
@@ -29,4 +30,5 @@ interface IVestingParams {
2930
Beneficiary[] memory beneficiaries,
3031
uint256 totalAmount
3132
);
33+
function getStartTime() external view returns (uint64);
3234
}

test/tokenDistribution/MetaTokenDistributor.t.sol

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,45 @@ contract MetaTokenDistributorTest is Test {
2424
(Beneficiary[] memory teamBeneficiaries, Beneficiary[] memory liquidityBeneficiaries)
2525
= _generateBeneficiaries();
2626

27-
vestingParams = new VestingParams(teamBeneficiaries, liquidityBeneficiaries);
28-
distributor = new MetaTokenDistributor(address(vestingParams), vestingStartTime);
27+
vestingParams = new VestingParams(vestingStartTime, teamBeneficiaries, liquidityBeneficiaries);
28+
distributor = new MetaTokenDistributor(address(vestingParams));
2929
}
3030

3131
// region - Deploy -
3232

3333
function test_deploy() external view {
3434
assertEq(distributor.getVestingParamsAddress(), address(vestingParams));
35-
assertEq(distributor.getVestingStartTime(), vestingStartTime);
36-
3735
assertNotEq(distributor.getMETAAddress(), address(0));
3836
}
3937

40-
function test_deploy_revertIfInvalidVestingStartTime(uint64 invalidVestingStartTime) external {
41-
// simulate timestamp
42-
vm.warp(1000);
38+
function test_deploy_emitMetaTokenDeployed() external {
39+
vm.expectEmit(true, true, true, false); // data is not checking
40+
emit IMetaTokenDistributor.MetaTokenDeployed(address(0));
4341

44-
vm.assume(invalidVestingStartTime < block.timestamp);
42+
distributor = new MetaTokenDistributor(address(vestingParams));
43+
}
4544

46-
vm.expectRevert(IMetaTokenDistributor.InvalidVestingStartTime.selector);
45+
function test_deploy_startTimeEqualBlockTimestamp() external {
46+
vestingStartTime = uint64(block.timestamp);
47+
(Beneficiary[] memory teamBeneficiaries, Beneficiary[] memory liquidityBeneficiaries)
48+
= _generateBeneficiaries();
4749

48-
distributor = new MetaTokenDistributor(address(vestingParams), invalidVestingStartTime);
49-
}
50+
vestingParams = new VestingParams(vestingStartTime, teamBeneficiaries, liquidityBeneficiaries);
51+
distributor = new MetaTokenDistributor(address(vestingParams));
5052

51-
function test_deploy_revertIfZeroAddress() external {
53+
address teamVesting = distributor.startVesting(VestingType.TEAM);
5254

53-
vm.expectRevert(IMetaTokenDistributor.ZeroAddress.selector);
55+
assertNotEq(teamVesting, address(0));
5456

55-
distributor = new MetaTokenDistributor(address(0), vestingStartTime);
57+
IERC20 META = IERC20(distributor.getMETAAddress());
58+
assertEq(META.balanceOf(teamVesting), vestingParams.TEAM_TOTAL_AMOUNT());
5659
}
5760

58-
function test_deploy_emitMetaTokenDeployed() external {
59-
vm.expectEmit(true, true, true, false); // data is not checking
60-
emit IMetaTokenDistributor.MetaTokenDeployed(address(0));
61+
function test_deploy_revertIfZeroAddress() external {
62+
63+
vm.expectRevert(IMetaTokenDistributor.ZeroAddress.selector);
6164

62-
distributor = new MetaTokenDistributor(address(vestingParams), vestingStartTime);
65+
distributor = new MetaTokenDistributor(address(0));
6366
}
6467

6568
// endregion

0 commit comments

Comments
 (0)