diff --git a/pallets/vtoken-minting/src/lib.rs b/pallets/vtoken-minting/src/lib.rs index 0b46582f6..d40a79999 100644 --- a/pallets/vtoken-minting/src/lib.rs +++ b/pallets/vtoken-minting/src/lib.rs @@ -219,6 +219,10 @@ pub mod pallet { FastRedeemFailed { err: DispatchError, }, + CurrencyTimeUnitRecreated { + token_id: CurrencyIdOf, + time_unit: TimeUnit, + }, } #[pallet::error] @@ -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, + token_id: CurrencyIdOf, + time_unit: TimeUnit, + ) -> DispatchResult { + T::ControlOrigin::ensure_origin(origin)?; + + OngoingTimeUnit::::mutate(&token_id, |old_time_unit| { + *old_time_unit = Some(time_unit.clone()) + }); + + Self::deposit_event(Event::CurrencyTimeUnitRecreated { token_id, time_unit }); + Ok(()) + } } impl Pallet { diff --git a/pallets/vtoken-minting/src/tests.rs b/pallets/vtoken-minting/src/tests.rs index f2d91c3e7..55825f508 100644 --- a/pallets/vtoken-minting/src/tests.rs +++ b/pallets/vtoken-minting/src/tests.rs @@ -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::::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))); + }) +} diff --git a/pallets/vtoken-minting/src/weights.rs b/pallets/vtoken-minting/src/weights.rs index f83fd7ca5..2cdc0f2de 100644 --- a/pallets/vtoken-minting/src/weights.rs +++ b/pallets/vtoken-minting/src/weights.rs @@ -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 @@ -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)) + } } diff --git a/runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs b/runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs index 357805ee9..5868cdd65 100644 --- a/runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs +++ b/runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs @@ -263,4 +263,10 @@ impl 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)) + } } diff --git a/runtime/bifrost-polkadot/src/weights/bifrost_vtoken_minting.rs b/runtime/bifrost-polkadot/src/weights/bifrost_vtoken_minting.rs index 357805ee9..5868cdd65 100644 --- a/runtime/bifrost-polkadot/src/weights/bifrost_vtoken_minting.rs +++ b/runtime/bifrost-polkadot/src/weights/bifrost_vtoken_minting.rs @@ -263,4 +263,10 @@ impl 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)) + } }