Skip to content

Commit

Permalink
upgrade rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed May 13, 2024
1 parent 9fc71f5 commit f302388
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 23 deletions.
125 changes: 125 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [
"libs/utils",
"pallets/anchors",
"pallets/bridge",
#"pallets/block-rewards",
"pallets/block-rewards",
"pallets/collator-allowlist",
#"pallets/crowdloan-claim",
#"pallets/crowdloan-reward",
Expand All @@ -25,7 +25,7 @@ members = [
#"pallets/liquidity-pools-gateway",
#"pallets/liquidity-pools-gateway/axelar-gateway-precompile",
#"pallets/liquidity-pools-gateway/routers",
#"pallets/liquidity-rewards",
"pallets/liquidity-rewards",
#"pallets/loans",
"pallets/oracle-feed",
"pallets/oracle-collection",
Expand All @@ -36,7 +36,7 @@ members = [
#"pallets/pool-registry",
#"pallets/restricted-tokens",
#"pallets/restricted-xtokens",
#"pallets/rewards",
"pallets/rewards",
"pallets/swaps",
#"pallets/token-mux",
#"pallets/transfer-allowlist",
Expand Down
1 change: 0 additions & 1 deletion pallets/block-rewards/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use frame_support::{
};
use frame_system::RawOrigin;
use sp_runtime::traits::Zero;
use sp_std::vec; // required for #[benchmarks]

use super::*;
use crate::{pallet::Config, Pallet as BlockRewards};
Expand Down
21 changes: 4 additions & 17 deletions pallets/block-rewards/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use parity_scale_codec::{Decode, Encode};
use sp_runtime::FixedPointNumber;
#[cfg(feature = "try-runtime")]
use sp_runtime::TryRuntimeError;
use sp_std::{marker::PhantomData, vec::Vec};
use sp_std::marker::PhantomData;

use crate::{pallet, Config, Pallet, SessionData};

Expand All @@ -31,7 +31,7 @@ fn inflation_rate<T: Config>(percent: u32) -> T::Rate {
pub mod init {
use cfg_traits::rewards::{AccountRewards, CurrencyGroupChange, GroupRewards};
use num_traits::Zero;
use sp_runtime::{BoundedVec, SaturatedConversion};
use sp_runtime::SaturatedConversion;

use super::*;

Expand All @@ -40,19 +40,6 @@ pub mod init {
PhantomData<(T, CollatorReward, AnnualTreasuryInflationPercent)>,
);

fn get_collators<T: pallet_collator_selection::Config>() -> Vec<T::AccountId> {
let candidates = BoundedVec::<
T::AccountId,
<T as pallet_collator_selection::Config>::MaxCandidates,
>::truncate_from(
pallet_collator_selection::Pallet::<T>::candidates()
.into_iter()
.map(|c| c.who)
.collect(),
);
pallet_collator_selection::Pallet::<T>::assemble_collators(candidates)
}

impl<T, CollatorReward, AnnualTreasuryInflationPercent> OnRuntimeUpgrade
for InitBlockRewards<T, CollatorReward, AnnualTreasuryInflationPercent>
where
Expand All @@ -63,7 +50,7 @@ pub mod init {
{
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
let collators = get_collators::<T>();
let collators = pallet_collator_selection::Pallet::<T>::assemble_collators();
assert!(!collators.is_empty());

assert!(!CollatorReward::get().is_zero());
Expand All @@ -85,7 +72,7 @@ pub mod init {
pallet::ActiveSessionData::<T>::get() != Default::default();

log::info!("{LOG_PREFIX} Getting list of collators");
let collators = get_collators::<T>();
let collators = pallet_collator_selection::Pallet::<T>::assemble_collators();

let collators_are_staked = collators.clone().into_iter().all(|c| {
log::info!("{LOG_PREFIX} Checking stake of collator {c:?}");
Expand Down
5 changes: 3 additions & 2 deletions pallets/rewards/src/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use cfg_traits::rewards::RewardIssuance;
use frame_support::traits::{fungibles::Mutate, tokens::Preservation};
use parity_scale_codec::{Decode, Encode};
use sp_runtime::{traits::Get, DispatchResult};
use sp_std::cmp::Eq;
use sp_std::marker::PhantomData;

/// Enables rewarding out of thin air, e.g. via minting.
Expand All @@ -25,7 +26,7 @@ pub struct MintReward<AccountId, Balance, CurrencyId, Currency>(
impl<AccountId, Balance, CurrencyId, Currency> RewardIssuance
for MintReward<AccountId, Balance, CurrencyId, Currency>
where
AccountId: Encode + Decode,
AccountId: Encode + Decode + Eq,
Currency: Mutate<AccountId, AssetId = CurrencyId, Balance = Balance>,
{
type AccountId = AccountId;
Expand All @@ -49,7 +50,7 @@ pub struct TransferReward<AccountId, Balance, CurrencyId, Currency, SourceAddres
impl<AccountId, Balance, CurrencyId, Currency, SourceAddress> RewardIssuance
for TransferReward<AccountId, Balance, CurrencyId, Currency, SourceAddress>
where
AccountId: Encode + Decode,
AccountId: Encode + Decode + Eq,
Currency: Mutate<AccountId, AssetId = CurrencyId, Balance = Balance>,
SourceAddress: Get<AccountId>,
{
Expand Down

0 comments on commit f302388

Please sign in to comment.