diff --git a/rewards/src/mock.rs b/rewards/src/mock.rs index f8fe43f473232dd7d0bc0a5ca8db1b3c407cf7ca..495425486c2bed0ac26e8313ef347822d9e181b9 100644 --- a/rewards/src/mock.rs +++ b/rewards/src/mock.rs @@ -14,6 +14,7 @@ pub type Balance = u64; pub type Share = u64; pub type PoolId = u32; pub type BlockNumber = u64; +pub type CurrencyId = u32; pub const ALICE: AccountId = 1; pub const BOB: AccountId = 2; @@ -74,8 +75,12 @@ impl RewardHandler<AccountId, BlockNumber> for Handler { type Share = Share; type Balance = Balance; type PoolId = PoolId; + type CurrencyId = CurrencyId; - fn accumulate_reward(now: BlockNumber, callback: impl Fn(Self::PoolId, Self::Balance)) -> Self::Balance { + fn accumulate_reward( + now: BlockNumber, + callback: impl Fn(Self::PoolId, Self::Balance), + ) -> Vec<(Self::CurrencyId, Self::Balance)> { if now % 2 == 0 { let mut total_accumulated_rewards = 0; let valid_pool_ids = vec![DOT_POOL, BTC_POOL]; @@ -88,9 +93,9 @@ impl RewardHandler<AccountId, BlockNumber> for Handler { } } - total_accumulated_rewards + vec![(1, total_accumulated_rewards)] } else { - 0 + vec![] } } diff --git a/traits/src/rewards.rs b/traits/src/rewards.rs index e0909ce20827f4be29539c8329328b68d9fc9df0..7e545f2a5a836fa6cceb4784922389b91582cee8 100644 --- a/traits/src/rewards.rs +++ b/traits/src/rewards.rs @@ -1,6 +1,6 @@ use codec::FullCodec; use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeSerializeDeserialize}; -use sp_std::fmt::Debug; +use sp_std::{fmt::Debug, vec::Vec}; /// Hooks to manage reward pool pub trait RewardHandler<AccountId, BlockNumber> { @@ -13,8 +13,14 @@ pub trait RewardHandler<AccountId, BlockNumber> { /// The reward pool ID type type PoolId: Copy + FullCodec; + /// The currency type + type CurrencyId: FullCodec + Eq + PartialEq + Copy + MaybeSerializeDeserialize + Debug; + /// Accumulate rewards - fn accumulate_reward(now: BlockNumber, callback: impl Fn(Self::PoolId, Self::Balance)) -> Self::Balance; + fn accumulate_reward( + now: BlockNumber, + callback: impl Fn(Self::PoolId, Self::Balance), + ) -> Vec<(Self::CurrencyId, Self::Balance)>; /// Payout the reward to `who` fn payout(who: &AccountId, pool: Self::PoolId, amount: Self::Balance);