Skip to content

Commit 06971b1

Browse files
authored
Fix vesting calculated amount immediately after the end of the cliff period (#92)
1 parent 54fa77c commit 06971b1

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

contracts/finance/vesting/Vesting.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ abstract contract Vesting is Initializable {
385385
_baseData.secondsInPeriod
386386
);
387387

388-
if (elapsedPeriods_ <= _baseData.cliffInPeriods) {
388+
if (elapsedPeriods_ < _baseData.cliffInPeriods) {
389389
return 0;
390390
}
391391

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solarity/solidity-lib",
3-
"version": "2.7.0",
3+
"version": "2.7.1",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"readme": "README.md",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solarity/solidity-lib",
3-
"version": "2.7.0",
3+
"version": "2.7.1",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"description": "Solidity Library by Distributed Lab",

test/finance/vesting/Vesting.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,22 +407,42 @@ describe("Vesting", () => {
407407
let vestingStartTime = BigInt(await time.latest());
408408
let timestampUpTo = vestingStartTime;
409409

410+
await vesting.createSchedule(defaultSchedule);
411+
410412
expect(await vesting.vestingCalculation(scheduleId, vestingAmount, vestingStartTime, timestampUpTo)).to.be.equal(
411413
0,
412414
);
413415
});
414416

415417
it("should return 0 if cliff is active", async () => {
416418
let vestingStartTime = BigInt(await time.latest());
417-
let timestampUpTo = vestingStartTime + secondsInPeriod;
419+
let timestampUpTo = vestingStartTime + secondsInPeriod * 2n;
418420

419-
defaultSchedule.scheduleData.cliffInPeriods = 2n;
421+
defaultSchedule.scheduleData.cliffInPeriods = 3n;
420422

421423
await vesting.createSchedule(defaultSchedule);
422424

423425
expect(await vesting.vestingCalculation(scheduleId, vestingAmount, vestingStartTime, timestampUpTo)).to.be.equal(
424426
0,
425427
);
426428
});
429+
430+
it("should return correct tokens amount right after cliff period is over", async () => {
431+
let vestingStartTime = BigInt(await time.latest());
432+
let timestampUpTo = vestingStartTime + secondsInPeriod * 3n + 1n;
433+
434+
const newCliffInPeriods = 3n;
435+
const someVestingAmount = wei(120_000);
436+
const expectedAmount = (someVestingAmount / durationInPeriods) * newCliffInPeriods;
437+
438+
defaultSchedule.scheduleData.cliffInPeriods = newCliffInPeriods;
439+
defaultSchedule.exponent = 1;
440+
441+
await vesting.createSchedule(defaultSchedule);
442+
443+
expect(
444+
await vesting.vestingCalculation(scheduleId, someVestingAmount, vestingStartTime, timestampUpTo),
445+
).to.be.equal(expectedAmount);
446+
});
427447
});
428448
});

0 commit comments

Comments
 (0)