Skip to content

Commit

Permalink
Add timeunit revise function (#1157)
Browse files Browse the repository at this point in the history
* add recreate_currency_ongoing_timeunit function

* fixes
  • Loading branch information
herryho committed Jan 19, 2024
1 parent e0af448 commit 6f7249d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pallets/vtoken-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ pub mod pallet {
FastRedeemFailed {
err: DispatchError,
},
CurrencyTimeUnitRecreated {
token_id: CurrencyIdOf<T>,
time_unit: TimeUnit,
},
}

#[pallet::error]
Expand Down Expand Up @@ -802,6 +806,23 @@ pub mod pallet {
Self::deposit_event(Event::MinTimeUnitSet { token_id, time_unit });
Ok(())
}

#[pallet::call_index(13)]
#[pallet::weight({0})]
pub fn recreate_currency_ongoing_time_unit(
origin: OriginFor<T>,
token_id: CurrencyIdOf<T>,
time_unit: TimeUnit,
) -> DispatchResult {
T::ControlOrigin::ensure_origin(origin)?;

OngoingTimeUnit::<T>::mutate(&token_id, |old_time_unit| {
*old_time_unit = Some(time_unit.clone())
});

Self::deposit_event(Event::CurrencyTimeUnitRecreated { token_id, time_unit });
Ok(())
}
}

impl<T: Config> Pallet<T> {
Expand Down
19 changes: 19 additions & 0 deletions pallets/vtoken-minting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,22 @@ fn fast_redeem_for_fil() {
);
});
}

#[test]
fn recreate_currency_ongoing_time_unit_should_work() {
ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| {
env_logger::try_init().unwrap_or(());

// set KSM ongoing time unit to be Era(1)
OngoingTimeUnit::<Runtime>::insert(KSM, TimeUnit::Era(1));
assert_eq!(VtokenMinting::ongoing_time_unit(KSM), Some(TimeUnit::Era(1)));

// recreate_currency_ongoing_time_unit the ongoing time unit of KSM to be Round(2)
assert_ok!(VtokenMinting::recreate_currency_ongoing_time_unit(
RuntimeOrigin::signed(ALICE),
KSM,
TimeUnit::Round(2)
));
assert_eq!(VtokenMinting::ongoing_time_unit(KSM), Some(TimeUnit::Round(2)));
})
}
7 changes: 7 additions & 0 deletions pallets/vtoken-minting/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub trait WeightInfo {
fn rebond() -> Weight;
fn rebond_by_unlock_id() -> Weight;
fn on_initialize() -> Weight;
fn recreate_currency_ongoing_time_unit() -> Weight;
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -278,4 +279,10 @@ impl WeightInfo for () {
Weight::from_parts(15_243_000, 3492)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}

fn recreate_currency_ongoing_time_unit() -> Weight {
Weight::from_parts(70_238_000, 4197)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
6 changes: 6 additions & 0 deletions runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,10 @@ impl<T: frame_system::Config> bifrost_vtoken_minting::WeightInfo for BifrostWeig
Weight::from_parts(16_763_000, 3492)
.saturating_add(T::DbWeight::get().reads(1))
}

fn recreate_currency_ongoing_time_unit() -> Weight {
Weight::from_parts(70_238_000, 4197)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,10 @@ impl<T: frame_system::Config> bifrost_vtoken_minting::WeightInfo for BifrostWeig
Weight::from_parts(16_763_000, 3492)
.saturating_add(T::DbWeight::get().reads(1))
}

fn recreate_currency_ongoing_time_unit() -> Weight {
Weight::from_parts(70_238_000, 4197)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

0 comments on commit 6f7249d

Please sign in to comment.