Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjj9219 committed Sep 30, 2022
1 parent 02ae3f6 commit 9e60c95
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
8 changes: 8 additions & 0 deletions modules/incentives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ 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
36 changes: 35 additions & 1 deletion modules/incentives/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ use crate::log;
use frame_support::traits::OnRuntimeUpgrade;
use sp_std::marker::PhantomData;

/// Clear all DexSavingRewardRates storage
pub struct ClearDexSavingRewardRates<T>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for ClearDexSavingRewardRates<T> {
fn on_runtime_upgrade() -> Weight {
log::info!(
target: "incentives",
"ClearDexSavingRewardRates::on_runtime_upgrade execute, will clear Storage DexSavingRewardRates",
);

// clear storage DexSavingRewardRates,
let _ = DexSavingRewardRates::<T>::clear(u32::max_value(), None);

0
}

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

log::info!(
target: "incentives",
"ClearDexSavingRewardRates done!",
);

Ok(())
}
}

type WithdrawnRewards = BTreeMap<CurrencyId, Balance>;

/// Clear all PendingMultiRewards for specific Pool
Expand Down Expand Up @@ -98,7 +126,13 @@ impl<T: Config, GetPoolId: Get<PoolId>> OnRuntimeUpgrade for ResetRewardsRecord<
total_share = total_share.saturating_add(share);
}

assert_eq!(orml_rewards::PoolInfos::<T>::get(&pool_id).total_shares, total_share);
assert_eq!(
orml_rewards::PoolInfos::<T>::get(&pool_id),
orml_rewards::PoolInfo::<Balance, Balance, CurrencyId> {
total_shares: total_share,
..Default::default()
}
);

log::info!(
target: "rewards",
Expand Down
10 changes: 8 additions & 2 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1799,8 +1799,14 @@ 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, ()>;
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
module_incentives::migration::ClearDexSavingRewardRates<Runtime>,
>;

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
Expand Down

0 comments on commit 9e60c95

Please sign in to comment.