Skip to content

Commit 3eac1ca

Browse files
committed
fix: tge unlock should happen at launch date
1 parent 55cf373 commit 3eac1ca

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

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

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

102-
// Calculate the claimable amount:
103-
// + tokens allocated * TGE unlock percentage
104-
int64_t claimable = vesting_allocation.tokens_allocated.amount * category.tge_unlock;
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);
105106

106-
// Check if vesting period after cliff has started
107-
if (now >= cliff_finished)
107+
if (now >= vesting_end)
108108
{
109-
// Calculate the total claimable amount
110-
if (now >= vesting_end)
111-
{
112-
claimable = vesting_allocation.tokens_allocated.amount;
113-
}
114-
else
115-
{
116-
// Calculate the percentage of the vesting period that has passed
117-
double vesting_finished = static_cast<double>((now - vesting_start).count()) / category.vesting_period.count();
118-
// Calculate the claimable amount:
119-
// + tokens allocated * % of vesting time that has passed * what is left after TGE unlock
120-
claimable += vesting_allocation.tokens_allocated.amount * (1.0 - category.tge_unlock) * vesting_finished;
121-
// Ensure the claimable amount is not greater than the total allocated amount
122-
claimable = std::min(claimable, vesting_allocation.tokens_allocated.amount);
123-
}
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+
}
124120

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

127126
// Update the tokens_claimed field
128127
eosio::asset tokens_claimed = eosio::asset(claimable, vesting_allocation.tokens_claimed.symbol);
129128

130-
if (claimable == vesting_allocation.tokens_allocated.amount)
129+
if (claimable == total_allocated)
131130
{
132-
// Erase and update iterator correctly
131+
// Fully vested and claimed: remove the row
133132
iter = vesting_table.erase(iter);
134133
}
135134
else
@@ -143,7 +142,7 @@ namespace vestingtoken
143142
}
144143
else
145144
{
146-
++iter;
145+
++iter;
147146
}
148147
}
149148

0 commit comments

Comments
 (0)