Skip to content

Commit bec974b

Browse files
Merge pull request #168 from Tonomy-Foundation/hotfix/claimable-amount
Hotfix/claimable amount
2 parents 773069b + 3eac1ca commit bec974b

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

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

Lines changed: 23 additions & 22 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

0 commit comments

Comments
 (0)