From 06971b1758b78978a00eb657c2cf1997fd359ef7 Mon Sep 17 00:00:00 2001 From: Oleg Komendant <44612825+Hrom131@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:26:00 +0200 Subject: [PATCH] Fix vesting calculated amount immediately after the end of the cliff period (#92) --- contracts/finance/vesting/Vesting.sol | 2 +- contracts/package.json | 2 +- package.json | 2 +- test/finance/vesting/Vesting.test.ts | 24 ++++++++++++++++++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/contracts/finance/vesting/Vesting.sol b/contracts/finance/vesting/Vesting.sol index 5f9aca14..f6c8ad58 100644 --- a/contracts/finance/vesting/Vesting.sol +++ b/contracts/finance/vesting/Vesting.sol @@ -385,7 +385,7 @@ abstract contract Vesting is Initializable { _baseData.secondsInPeriod ); - if (elapsedPeriods_ <= _baseData.cliffInPeriods) { + if (elapsedPeriods_ < _baseData.cliffInPeriods) { return 0; } diff --git a/contracts/package.json b/contracts/package.json index dc81e21a..7a19f192 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/solidity-lib", - "version": "2.7.0", + "version": "2.7.1", "license": "MIT", "author": "Distributed Lab", "readme": "README.md", diff --git a/package.json b/package.json index 56439232..949885f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/solidity-lib", - "version": "2.7.0", + "version": "2.7.1", "license": "MIT", "author": "Distributed Lab", "description": "Solidity Library by Distributed Lab", diff --git a/test/finance/vesting/Vesting.test.ts b/test/finance/vesting/Vesting.test.ts index 6dfab23b..726ddeaa 100644 --- a/test/finance/vesting/Vesting.test.ts +++ b/test/finance/vesting/Vesting.test.ts @@ -407,6 +407,8 @@ describe("Vesting", () => { let vestingStartTime = BigInt(await time.latest()); let timestampUpTo = vestingStartTime; + await vesting.createSchedule(defaultSchedule); + expect(await vesting.vestingCalculation(scheduleId, vestingAmount, vestingStartTime, timestampUpTo)).to.be.equal( 0, ); @@ -414,9 +416,9 @@ describe("Vesting", () => { it("should return 0 if cliff is active", async () => { let vestingStartTime = BigInt(await time.latest()); - let timestampUpTo = vestingStartTime + secondsInPeriod; + let timestampUpTo = vestingStartTime + secondsInPeriod * 2n; - defaultSchedule.scheduleData.cliffInPeriods = 2n; + defaultSchedule.scheduleData.cliffInPeriods = 3n; await vesting.createSchedule(defaultSchedule); @@ -424,5 +426,23 @@ describe("Vesting", () => { 0, ); }); + + it("should return correct tokens amount right after cliff period is over", async () => { + let vestingStartTime = BigInt(await time.latest()); + let timestampUpTo = vestingStartTime + secondsInPeriod * 3n + 1n; + + const newCliffInPeriods = 3n; + const someVestingAmount = wei(120_000); + const expectedAmount = (someVestingAmount / durationInPeriods) * newCliffInPeriods; + + defaultSchedule.scheduleData.cliffInPeriods = newCliffInPeriods; + defaultSchedule.exponent = 1; + + await vesting.createSchedule(defaultSchedule); + + expect( + await vesting.vestingCalculation(scheduleId, someVestingAmount, vestingStartTime, timestampUpTo), + ).to.be.equal(expectedAmount); + }); }); });