Skip to content
Merged
4 changes: 2 additions & 2 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ where
+ 'static,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: FarmingRuntimeApi<Block, AccountId, PoolId>,
C::Api: FarmingRuntimeApi<Block, AccountId, PoolId, CurrencyId>,
C::Api: FeeRuntimeApi<Block, AccountId>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
C::Api: StablePoolRuntimeApi<Block>,
Expand Down Expand Up @@ -126,7 +126,7 @@ where
+ BlockIdTo<Block>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: FarmingRuntimeApi<Block, AccountId, PoolId>,
C::Api: FarmingRuntimeApi<Block, AccountId, PoolId, CurrencyId>,
C::Api: FeeRuntimeApi<Block, AccountId>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
C::Api: VeMintingRuntimeApi<Block, AccountId>,
Expand Down
5 changes: 3 additions & 2 deletions pallets/farming/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

#![cfg_attr(not(feature = "std"), no_std)]

use bifrost_primitives::{Balance, CurrencyId};
use bifrost_primitives::Balance;
use parity_scale_codec::Codec;
use sp_api::decl_runtime_apis;
use sp_std::vec::Vec;

decl_runtime_apis! {
pub trait FarmingRuntimeApi<AccountId, PoolId> where
pub trait FarmingRuntimeApi<AccountId, PoolId, CurrencyId> where
AccountId: Codec,
PoolId: Codec,
CurrencyId: Codec,
{
fn get_farming_rewards(
who: AccountId,
Expand Down
11 changes: 6 additions & 5 deletions pallets/farming/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use std::{marker::PhantomData, sync::Arc};

pub use bifrost_farming_rpc_runtime_api::{self as runtime_api, FarmingRuntimeApi};
use bifrost_primitives::{Balance, CurrencyId};
use bifrost_primitives::Balance;
use jsonrpsee::{
core::{async_trait, RpcResult},
proc_macros::rpc,
Expand All @@ -32,7 +32,7 @@ use sp_rpc::number::NumberOrHex;
use sp_runtime::traits::Block as BlockT;

#[rpc(client, server)]
pub trait FarmingRpcApi<BlockHash, AccountId, PoolId> {
pub trait FarmingRpcApi<BlockHash, AccountId, PoolId, CurrencyId> {
/// rpc method for getting farming rewards
#[method(name = "farming_getFarmingRewards")]
fn get_farming_rewards(
Expand Down Expand Up @@ -65,14 +65,15 @@ impl<C, Block> FarmingRpc<C, Block> {
}

#[async_trait]
impl<C, Block, AccountId, PoolId> FarmingRpcApiServer<<Block as BlockT>::Hash, AccountId, PoolId>
for FarmingRpc<C, Block>
impl<C, Block, AccountId, PoolId, CurrencyId>
FarmingRpcApiServer<<Block as BlockT>::Hash, AccountId, PoolId, CurrencyId> for FarmingRpc<C, Block>
where
Block: BlockT,
C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: FarmingRuntimeApi<Block, AccountId, PoolId>,
C::Api: FarmingRuntimeApi<Block, AccountId, PoolId, CurrencyId>,
AccountId: Codec,
PoolId: Codec,
CurrencyId: Codec,
{
fn get_farming_rewards(
&self,
Expand Down
159 changes: 79 additions & 80 deletions pallets/farming/src/benchmarking.rs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pallets/farming/src/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@ where
pub fn get_farming_rewards(
who: &T::AccountId,
pid: PoolId,
) -> Result<Vec<(CurrencyId, BalanceOf<T>)>, DispatchError> {
) -> Result<Vec<(T::CurrencyId, BalanceOf<T>)>, DispatchError> {
let share_info =
SharesAndWithdrawnRewards::<T>::get(pid, who).ok_or(Error::<T>::ShareInfoNotExists)?;
let pool_info = PoolInfos::<T>::get(pid).ok_or(Error::<T>::PoolDoesNotExist)?;
let total_shares = U256::from(pool_info.total_shares.to_owned().saturated_into::<u128>());
let mut result_vec = Vec::<(CurrencyId, BalanceOf<T>)>::new();
let mut result_vec = Vec::<(T::CurrencyId, BalanceOf<T>)>::new();

pool_info.rewards.iter().try_for_each(
|(reward_currency, (total_reward, total_withdrawn_reward))| -> DispatchResult {
Expand Down Expand Up @@ -446,9 +446,9 @@ where
pub fn get_gauge_rewards(
who: &T::AccountId,
pid: PoolId,
) -> Result<Vec<(CurrencyId, BalanceOf<T>)>, DispatchError> {
) -> Result<Vec<(T::CurrencyId, BalanceOf<T>)>, DispatchError> {
let pool_info = PoolInfos::<T>::get(pid).ok_or(Error::<T>::PoolDoesNotExist)?;
let mut result_vec = Vec::<(CurrencyId, BalanceOf<T>)>::new();
let mut result_vec = Vec::<(T::CurrencyId, BalanceOf<T>)>::new();

match pool_info.gauge {
None => (),
Expand Down
18 changes: 16 additions & 2 deletions pallets/farming/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub mod weights;
pub use weights::WeightInfo;

use crate::boost::*;
use bifrost_primitives::{CurrencyId, FarmingInfo, PoolId};
use bifrost_primitives::{FarmingInfo, PoolId};
use frame_support::{
pallet_prelude::*,
sp_runtime::{
Expand Down Expand Up @@ -62,6 +62,9 @@ pub type CurrencyIdOf<T> = <<T as Config>::MultiCurrency as MultiCurrency<

type BalanceOf<T> = <<T as Config>::MultiCurrency as MultiCurrency<AccountIdOf<T>>>::Balance;

use parity_scale_codec::FullCodec;
use sp_std::fmt::Debug;

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand All @@ -74,7 +77,18 @@ pub mod pallet {
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

type MultiCurrency: MultiCurrency<AccountIdOf<Self>, CurrencyId = CurrencyId>;
type CurrencyId: FullCodec
+ Eq
+ PartialEq
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ scale_info::TypeInfo
+ MaxEncodedLen
+ Ord
+ Default;

type MultiCurrency: MultiCurrency<AccountIdOf<Self>, CurrencyId = Self::CurrencyId>;

type ControlOrigin: EnsureOrigin<Self::RuntimeOrigin>;

Expand Down
1 change: 1 addition & 0 deletions pallets/farming/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ ord_parameter_types! {

impl bifrost_farming::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CurrencyId = CurrencyId;
type MultiCurrency = Currencies;
type ControlOrigin = EnsureSignedBy<One, AccountId>;
type TreasuryAccount = TreasuryAccount;
Expand Down
1 change: 1 addition & 0 deletions pallets/system-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ ord_parameter_types! {

impl bifrost_farming::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CurrencyId = CurrencyId;
type MultiCurrency = Currencies;
type ControlOrigin = EnsureSignedBy<One, AccountId>;
type TreasuryAccount = TreasuryAccount;
Expand Down
3 changes: 2 additions & 1 deletion runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,7 @@ parameter_types! {
impl bifrost_farming::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MultiCurrency = Currencies;
type CurrencyId = CurrencyId;
type ControlOrigin = TechAdminOrCouncil;
type TreasuryAccount = BifrostTreasuryAccount;
type Keeper = FarmingKeeperPalletId;
Expand Down Expand Up @@ -2318,7 +2319,7 @@ impl_runtime_apis! {
}
}

impl bifrost_farming_rpc_runtime_api::FarmingRuntimeApi<Block, AccountId, PoolId> for Runtime {
impl bifrost_farming_rpc_runtime_api::FarmingRuntimeApi<Block, AccountId, PoolId, CurrencyId> for Runtime {
fn get_farming_rewards(who: AccountId, pid: PoolId) -> Vec<(CurrencyId, Balance)> {
Farming::get_farming_rewards(&who, pid).unwrap_or(Vec::new())
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ parameter_types! {

impl bifrost_farming::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CurrencyId = CurrencyId;
type MultiCurrency = Currencies;
type ControlOrigin = TechAdminOrCouncil;
type TreasuryAccount = BifrostTreasuryAccount;
Expand Down Expand Up @@ -2044,7 +2045,7 @@ impl_runtime_apis! {
}
}

impl bifrost_farming_rpc_runtime_api::FarmingRuntimeApi<Block, AccountId, PoolId> for Runtime {
impl bifrost_farming_rpc_runtime_api::FarmingRuntimeApi<Block, AccountId, PoolId, CurrencyId> for Runtime {
fn get_farming_rewards(who: AccountId, pid: PoolId) -> Vec<(CurrencyId, Balance)> {
Farming::get_farming_rewards(&who, pid).unwrap_or(Vec::new())
}
Expand Down