Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeunit revise function #1157

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}
Loading