Skip to content

Commit eb98bae

Browse files
committed
Correct handling of stale accounts
1 parent 7daf466 commit eb98bae

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

althea-info-server/src/total_suppy.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ async fn compute_liquid_supply(
179179
let vesting_start_time =
180180
UNIX_EPOCH + Duration::from_secs(account_info.start_time as u64);
181181
let base = account_info.base_vesting_account.unwrap();
182+
// delegated vesting may be more than the remaining vesting amount if the user hasn't updated thier delegation
183+
// since the last vesting event
182184
let (total_delegated_free, total_delegated_vesting, original_vesting_amount) =
183185
sum_vesting(base, denom.clone());
184186
// obvious stuff requiring no computation
@@ -210,8 +212,19 @@ async fn compute_liquid_supply(
210212
total_vested += total_amount_vested;
211213
total_vesting += total_amount_still_vesting;
212214

213-
assert!(total_amount_still_vesting >= total_delegated_vesting);
214-
let vesting_in_balance = total_amount_still_vesting - total_delegated_vesting;
215+
// this is a hard edegcase to handle in the current implementation. If someone has delegated and not touched their delegation for a long time
216+
// vesting events have elapsed but their delegated vesting number has not been updated. In this case we can be confident that the total_delegated_vesting
217+
// is the original amount they have delegated out of their vesting total. So what has vested since then can't be in their balance since that would require them
218+
// to interact with thier account and update the total_delegated_vesting number.
219+
let vesting_in_balance = if total_delegated_vesting > total_amount_still_vesting {
220+
// vested tokens show up in the balance first, so we take what they originally left in their balance
221+
// subtract it from what's vested so far and that's what's delegated and still vesting in this case
222+
let org_vest_bal = original_vesting_amount - total_delegated_vesting;
223+
let delegated_vesting = total_amount_vested - org_vest_bal;
224+
total_amount_vested - delegated_vesting
225+
} else {
226+
total_amount_still_vesting - total_delegated_vesting
227+
};
215228
// unvested tokens show up in the balance
216229
// but unvested delegated tokens do not, in the case where a user
217230
// has some vesting, some delegation, some balance, and some unclaimed rewards

0 commit comments

Comments
 (0)