Skip to content

Commit

Permalink
reset incentives.PendingMultiRewards and rewards.SharesAndWithdrawnRe…
Browse files Browse the repository at this point in the history
…wards for Pool aUSD-IBTC
  • Loading branch information
wangjj9219 committed Sep 26, 2022
1 parent 39d92de commit 8c1acf3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 35 deletions.
8 changes: 0 additions & 8 deletions modules/incentives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,6 @@ pub mod module {
pub type IncentiveRewardAmounts<T: Config> =
StorageDoubleMap<_, Twox64Concat, PoolId, Twox64Concat, CurrencyId, Balance, ValueQuery>;

/// NOTE: already deprecated, need remove it after next runtime upgrade
/// Mapping from pool to its fixed reward rate per period.
///
/// DexSavingRewardRates: map Pool => SavingRatePerPeriod
#[pallet::storage]
#[pallet::getter(fn dex_saving_reward_rates)]
pub type DexSavingRewardRates<T: Config> = StorageMap<_, Twox64Concat, PoolId, Rate, ValueQuery>;

/// Mapping from pool to its claim reward deduction rate.
///
/// ClaimRewardDeductionRates: map Pool => DeductionRate
Expand Down
61 changes: 53 additions & 8 deletions modules/incentives/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,74 @@
use super::*;
use crate::log;
use frame_support::traits::OnRuntimeUpgrade;
use sp_std::marker::PhantomData;

/// Clear all DexSavingRewardRates storage
pub struct ClearDexSavingRewardRates<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for ClearDexSavingRewardRates<T> {
type WithdrawnRewards = BTreeMap<CurrencyId, Balance>;

/// Clear all PendingMultiRewards for specific Pool
pub struct ClearPendingMultiRewards<T, GetPoolId>(PhantomData<T>, PhantomData<GetPoolId>);
impl<T: Config, GetPoolId: Get<PoolId>> OnRuntimeUpgrade for ClearPendingMultiRewards<T, GetPoolId> {
fn on_runtime_upgrade() -> Weight {
let pool_id = GetPoolId::get();
log::info!(
target: "incentives",
"ClearDexSavingRewardRates::on_runtime_upgrade execute, will clear Storage DexSavingRewardRates",
"ClearPendingMultiRewards::on_runtime_upgrade execute, will clear Storage PendingMultiRewards for Pool {:?}",
pool_id,
);

// clear storage DexSavingRewardRates,
let _ = DexSavingRewardRates::<T>::clear(u32::max_value(), None);
// clear all PendingMultiRewards for specific pool
let _ = PendingMultiRewards::<T>::clear_prefix(pool_id, u32::max_value(), None);

0
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
assert_eq!(DexSavingRewardRates::<T>::iter().count(), 0);
let pool_id = GetPoolId::get();
assert_eq!(PendingMultiRewards::<T>::iter_prefix(pool_id).count(), 0);

log::info!(
target: "incentives",
"ClearDexSavingRewardRates done!",
"ClearPendingMultiRewards for Pool {:?} done!",
pool_id,
);

Ok(())
}
}

/// Reset WithdrawnRewards records for rewards.SharesAndWithdrawnRewards at specific PoolId
pub struct ResetSharesAndWithdrawnRewards<T, GetPoolId>(PhantomData<T>, PhantomData<GetPoolId>);
impl<T: Config, GetPoolId: Get<PoolId>> OnRuntimeUpgrade for ResetSharesAndWithdrawnRewards<T, GetPoolId> {
fn on_runtime_upgrade() -> Weight {
let pool_id = GetPoolId::get();
log::info!(
target: "rewards",
"ResetSharesAndWithdrawnRewards::on_runtime_upgrade execute, will reset Storage SharesAndWithdrawnRewards for Pool {:?}",
pool_id
);

for (who, (_, _)) in orml_rewards::SharesAndWithdrawnRewards::<T>::iter_prefix(&pool_id) {
orml_rewards::SharesAndWithdrawnRewards::<T>::mutate(&pool_id, &who, |(_, withdrawn_rewards)| {
*withdrawn_rewards = WithdrawnRewards::new();
});
}

0
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
let pool_id = GetPoolId::get();

for (_, (_, withdrawn_rewards)) in orml_rewards::SharesAndWithdrawnRewards::<T>::iter_prefix(&pool_id) {
assert_eq!(withdrawn_rewards, WithdrawnRewards::new());
}

log::info!(
target: "rewards",
"ResetSharesAndWithdrawnRewards for Pool {:?} done!",
pool_id,
);

Ok(())
Expand Down
15 changes: 12 additions & 3 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub use primitives::{
task::TaskResult,
unchecked_extrinsic::AcalaUncheckedExtrinsic,
AccountId, AccountIndex, Address, Amount, AuctionId, AuthoritysOriginId, Balance, BlockNumber, CurrencyId,
DataProviderId, EraIndex, Hash, Lease, Moment, Multiplier, Nonce, ReserveIdentifier, Share, Signature, TokenSymbol,
TradingPair,
DataProviderId, DexShare, EraIndex, Hash, Lease, Moment, Multiplier, Nonce, ReserveIdentifier, Share, Signature,
TokenSymbol, TradingPair,
};
pub use runtime_common::{
cent, dollar, microcent, millicent, AcalaDropAssets, AllPrecompiles, CheckRelayNumber,
Expand Down Expand Up @@ -1244,6 +1244,12 @@ impl orml_rewards::Config for Runtime {
parameter_types! {
pub const AccumulatePeriod: BlockNumber = MINUTES;
pub const EarnShareBooster: Permill = Permill::from_percent(30);
pub const GetAusdIbtcPoolId: PoolId = PoolId::Dex(
CurrencyId::DexShare(
DexShare::Token(TokenSymbol::AUSD),
DexShare::ForeignAsset(3)
)
);
}

impl module_incentives::Config for Runtime {
Expand Down Expand Up @@ -1772,7 +1778,10 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
module_incentives::migration::ClearDexSavingRewardRates<Runtime>,
(
module_incentives::migration::ResetSharesAndWithdrawnRewards<Runtime, GetAusdIbtcPoolId>,
module_incentives::migration::ClearPendingMultiRewards<Runtime, GetAusdIbtcPoolId>,
),
>;

#[cfg(feature = "runtime-benchmarks")]
Expand Down
10 changes: 2 additions & 8 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1799,14 +1799,8 @@ pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
module_incentives::migration::ClearDexSavingRewardRates<Runtime>,
>;
pub type Executive =
frame_executive::Executive<Runtime, Block, frame_system::ChainContext<Runtime>, Runtime, AllPalletsWithSystem, ()>;

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
Expand Down
10 changes: 2 additions & 8 deletions runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,14 +1919,8 @@ pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
module_incentives::migration::ClearDexSavingRewardRates<Runtime>,
>;
pub type Executive =
frame_executive::Executive<Runtime, Block, frame_system::ChainContext<Runtime>, Runtime, AllPalletsWithSystem, ()>;

construct_runtime!(
pub enum Runtime where
Expand Down

0 comments on commit 8c1acf3

Please sign in to comment.