Skip to content

Commit

Permalink
Fix pending schedule params (#1237)
Browse files Browse the repository at this point in the history
* No need to change start after set up, so removed it

* No need to use None manager, so removed it

---------

Co-authored-by: Mikhail Tagirov <dev.mikhail.tagirov@outlook.com>
  • Loading branch information
ZlayaMorda and wer1st authored Oct 16, 2024
1 parent 50f54b3 commit 354aee6
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 59 deletions.
6 changes: 3 additions & 3 deletions pallets/vested-rewards/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ benchmarks! {
let asset_id_temp: AssetIdOf<T> = create_asset::<T>("TEST", i.into());
let vesting_schedule = VestingScheduleOf::<T>::LinearPendingVestingSchedule(LinearPendingVestingSchedule {
asset_id,
manager_id: Some(caller.clone()),
manager_id: caller.clone(),
start: None,
period: T::BlockNumber::from(2_u32),
period_count: 2,
Expand All @@ -324,7 +324,7 @@ benchmarks! {
}
let vesting_schedule_locked = VestingScheduleOf::<T>::LinearPendingVestingSchedule(LinearPendingVestingSchedule {
asset_id,
manager_id: Some(caller.clone()),
manager_id: caller.clone(),
start: None,
period: T::BlockNumber::from(1_u32),
period_count: 2,
Expand All @@ -334,7 +334,7 @@ benchmarks! {
schedules.try_push(vesting_schedule_locked.clone()).expect("Error while push to BoundedVec");
<VestingSchedules<T>>::insert(caller.clone(), schedules);
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::from(2_u32));
}: _(RawOrigin::Signed(caller.clone()), T::Lookup::unlookup(caller.clone()), None, vesting_schedule_locked)
}: _(RawOrigin::Signed(caller.clone()), T::Lookup::unlookup(caller.clone()), vesting_schedule_locked)
verify {
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::from(4_u32));
assert_ok!(VestedRewards::<T>::claim_unlocked(RawOrigin::Signed(caller.clone()).into(), asset_id));
Expand Down
29 changes: 6 additions & 23 deletions pallets/vested-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,22 @@ impl<T: Config> Pallet<T> {
fn do_unlock_pending_schedule_by_manager(
manager: T::AccountId,
dest: T::AccountId,
start: T::BlockNumber,
filter_schedule: &mut VestingScheduleOf<T>,
) -> DispatchResult {
// Independent logic for some schedules, so implementation only there
match filter_schedule {
VestingScheduleOf::<T>::LinearPendingVestingSchedule(filter_schedule) => {
filter_schedule.manager_id = Some(manager);
filter_schedule.manager_id = manager;
let mut start = <frame_system::Pallet<T>>::block_number();
if let Some(input_start) = filter_schedule.start.take() {
start = input_start;
}
<VestingSchedules<T>>::try_mutate(dest.clone(), |schedules| {
for sched in schedules.iter_mut() {
if let VestingScheduleOf::<T>::LinearPendingVestingSchedule(sched) = sched {
if sched.eq(&filter_schedule) {
sched.start = Some(start);
sched.ensure_valid_vesting_schedule::<T>()?;
sched.manager_id = None;
Self::deposit_event(Event::PendingScheduleUnlocked {
dest: dest.clone(),
pending_schedule:
Expand All @@ -315,7 +317,6 @@ impl<T: Config> Pallet<T> {
})
.and_then(|_| {
filter_schedule.start = Some(start);
filter_schedule.manager_id = None;
Self::set_auto_claim_block(
dest.clone(),
&VestingScheduleOf::<T>::LinearPendingVestingSchedule(
Expand Down Expand Up @@ -1104,31 +1105,13 @@ pub mod pallet {
pub fn unlock_pending_schedule_by_manager(
origin: OriginFor<T>,
dest: <T::Lookup as StaticLookup>::Source,
start: Option<T::BlockNumber>,
mut filter_schedule: VestingScheduleOf<T>,
) -> DispatchResultWithPostInfo {
let manager = ensure_signed(origin)?;
#[cfg(feature = "wip")] // Pending Vesting
{
let dest = T::Lookup::lookup(dest)?;
match start {
Some(start) => {
Self::do_unlock_pending_schedule_by_manager(
manager,
dest,
start,
&mut filter_schedule,
)?;
}
None => {
Self::do_unlock_pending_schedule_by_manager(
manager,
dest,
<frame_system::Pallet<T>>::block_number(),
&mut filter_schedule,
)?;
}
}
Self::do_unlock_pending_schedule_by_manager(manager, dest, &mut filter_schedule)?;
}
Ok(().into())
}
Expand Down
Loading

0 comments on commit 354aee6

Please sign in to comment.