Skip to content

Commit 72e0259

Browse files
Merge pull request #172 from Tonomy-Foundation/hotfix/double-special-round-vesting-categories
Rebase from master
2 parents 1b4f573 + c05e8a8 commit 72e0259

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

contracts/vesting.tmy/include/vesting.tmy/vesting.tmy.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ namespace vestingtoken
6161
{26, {days(0 * 30), days(0 * 30), days(5 * 365), 0.0}}, // Platform Dev
6262
{27, {days(0 * 30), days(0 * 30), days(5 * 365), 0.0}}, // Staking & Infra Rewards
6363
{28, {days(0 * 30), days(0 * 30), days(5 * 365), 0.0}}, // Ecosystem
64+
{29, {days(0 * 30), days(26), days(6 * 30), 0.15}}, // Double Special Round - Full
65+
{30, {days(0 * 30), days(26), days(3 * 30), 0.3}}, // Double Special Round - Part 1
66+
{31, {days(0 * 30), days(26 + 3 * 30), days(3 * 30), 0.0}}, // Double Special Round - Part 2
6467
// Testing categories:
6568
#ifdef BUILD_TEST
6669
{997, {days(6 * 30), days(0 * 30), days(2 * 365), 0.0}}, // TESTING ONLY

contracts/vesting.tmy/src/vesting.tmy.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,35 +99,36 @@ namespace vestingtoken
9999
// Calculate the vesting end time
100100
time_point vesting_end = vesting_start + category.vesting_period;
101101

102-
// Check if vesting period after cliff has started
103-
if (now >= cliff_finished)
102+
// Calculate the claimable amount so far
103+
int64_t total_allocated = vesting_allocation.tokens_allocated.amount;
104+
// Portion unlocked at launch date (TGE unlock)
105+
int64_t claimable = static_cast<int64_t>(total_allocated * category.tge_unlock);
106+
107+
if (now >= vesting_end)
104108
{
105-
// Calculate the total claimable amount
106-
int64_t claimable = 0;
107-
if (now >= vesting_end)
108-
{
109-
claimable = vesting_allocation.tokens_allocated.amount;
110-
}
111-
else
112-
{
113-
// Calculate the percentage of the vesting period that has passed
114-
double vesting_finished = static_cast<double>((now - vesting_start).count()) / category.vesting_period.count();
115-
// Calculate the claimable amount:
116-
// + tokens allocated * TGE unlock percentage
117-
// + tokens allocated * % of vesting time that has passed * what is left after TGE unlock
118-
claimable = vesting_allocation.tokens_allocated.amount * ((1.0 - category.tge_unlock) * vesting_finished + category.tge_unlock);
119-
// Ensure the claimable amount is not greater than the total allocated amount
120-
claimable = std::min(claimable, vesting_allocation.tokens_allocated.amount);
121-
}
109+
// All tokens have vested by end of schedule
110+
claimable = total_allocated;
111+
}
112+
else if (now >= cliff_finished)
113+
{
114+
// After cliff, linear vesting for the remaining tokens
115+
double vesting_finished = static_cast<double>((now - vesting_start).count()) / category.vesting_period.count();
116+
int64_t remaining_after_tge = total_allocated - claimable;
117+
claimable = std::min(total_allocated,
118+
claimable + static_cast<int64_t>(remaining_after_tge * vesting_finished));
119+
}
122120

121+
// Only process if there's anything new to claim
122+
if (claimable > vesting_allocation.tokens_claimed.amount)
123+
{
123124
total_claimable += claimable - vesting_allocation.tokens_claimed.amount;
124125

125126
// Update the tokens_claimed field
126127
eosio::asset tokens_claimed = eosio::asset(claimable, vesting_allocation.tokens_claimed.symbol);
127128

128-
if (claimable == vesting_allocation.tokens_allocated.amount)
129+
if (claimable == total_allocated)
129130
{
130-
// Erase and update iterator correctly
131+
// Fully vested and claimed: remove the row
131132
iter = vesting_table.erase(iter);
132133
}
133134
else
@@ -141,7 +142,7 @@ namespace vestingtoken
141142
}
142143
else
143144
{
144-
++iter;
145+
++iter;
145146
}
146147
}
147148

@@ -175,7 +176,7 @@ namespace vestingtoken
175176
// Checks to verify new allocation is valid
176177
eosio::check(iter->tokens_allocated.amount == old_amount.amount, "Old amount does not match existing allocation");
177178
eosio::check(iter->vesting_category_type == old_category_id, "Old category does not match existing allocation");
178-
eosio::check(iter->tokens_claimed.amount < new_amount.amount, "New amount is less than the amount already claimed");
179+
eosio::check(iter->tokens_claimed.amount <= new_amount.amount, "New amount is less than the amount already claimed");
179180

180181
// Modify the table row data, and update the table
181182
vesting_table.modify(iter, get_self(), [&](auto &row)

0 commit comments

Comments
 (0)