Skip to content

Commit

Permalink
Fix vesting calculated amount immediately after the end of the cliff …
Browse files Browse the repository at this point in the history
…period (#92)
  • Loading branch information
Hrom131 authored Mar 14, 2024
1 parent 54fa77c commit 06971b1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion contracts/finance/vesting/Vesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ abstract contract Vesting is Initializable {
_baseData.secondsInPeriod
);

if (elapsedPeriods_ <= _baseData.cliffInPeriods) {
if (elapsedPeriods_ < _baseData.cliffInPeriods) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solarity/solidity-lib",
"version": "2.7.0",
"version": "2.7.1",
"license": "MIT",
"author": "Distributed Lab",
"readme": "README.md",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 22 additions & 2 deletions test/finance/vesting/Vesting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,22 +407,42 @@ 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,
);
});

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);

expect(await vesting.vestingCalculation(scheduleId, vestingAmount, vestingStartTime, timestampUpTo)).to.be.equal(
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);
});
});
});

0 comments on commit 06971b1

Please sign in to comment.