Skip to content

Commit

Permalink
Don't go into main loop if it is last period for vesting and unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
axiongsupra committed Dec 18, 2024
1 parent f9652d1 commit c47affe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ module supra_framework::pbo_delegation_pool {
use supra_framework::staking_config;
use supra_framework::timestamp;
use supra_framework::multisig_account;
#[test_only]
use aptos_std::debug;

const MODULE_SALT: vector<u8> = b"supra_framework::pbo_delegation_pool";

Expand Down Expand Up @@ -1782,9 +1780,19 @@ module supra_framework::pbo_delegation_pool {
} else {
*vector::borrow(&unlock_schedule.schedule, last_unlocked_period)
};
cfraction = fixed_point64::add(cfraction, next_fraction);
let next_fraction_unchanged = next_fraction == *vector::borrow(&unlock_schedule.schedule, schedule_length - 1);
// If next fraction is same as last unlocked period, then no need to fetch from schedule
if (next_fraction_unchanged) {
while (last_unlocked_period < unlock_periods_passed
&& fixed_point64::less(cfraction, one)) {
cfraction = fixed_point64::add(cfraction, next_fraction);
last_unlocked_period = last_unlocked_period + 1;
};
} else {
cfraction = fixed_point64::add(cfraction, next_fraction);

last_unlocked_period = last_unlocked_period + 1;
last_unlocked_period = last_unlocked_period + 1;
};
};

unlock_schedule.cumulative_unlocked_fraction = cfraction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,17 +503,32 @@ module supra_framework::vesting_without_staking {
// Last vesting schedule fraction will repeat until the grant runs out.
*vector::borrow(schedule, vector::length(schedule) - 1)
};
vest_transfer(vesting_record, signer_cap, beneficiary, vesting_fraction);

emit_event(&mut vesting_contract.vest_events,
VestEvent {
admin: vesting_contract.admin,
shareholder_address: shareholder_address,
vesting_contract_address: contract_address,
period_vested: next_period_to_vest,
},
);
next_period_to_vest = next_period_to_vest + 1;
let vesting_fraction_unchange = vesting_fraction == *vector::borrow(schedule, vector::length(schedule) - 1);
if (vesting_fraction_unchange) {
while (last_completed_period >= next_period_to_vest && vesting_record.left_amount > 0) {
vest_transfer(vesting_record, signer_cap, beneficiary, vesting_fraction);
emit_event(&mut vesting_contract.vest_events,
VestEvent {
admin: vesting_contract.admin,
shareholder_address: shareholder_address,
vesting_contract_address: contract_address,
period_vested: next_period_to_vest,
},
);
next_period_to_vest = next_period_to_vest + 1;
}
} else {
vest_transfer(vesting_record, signer_cap, beneficiary, vesting_fraction);
emit_event(&mut vesting_contract.vest_events,
VestEvent {
admin: vesting_contract.admin,
shareholder_address: shareholder_address,
vesting_contract_address: contract_address,
period_vested: next_period_to_vest,
},
);
next_period_to_vest = next_period_to_vest + 1;
};
};

//update last_vested_period for the shareholder
Expand Down

0 comments on commit c47affe

Please sign in to comment.