Skip to content

Commit

Permalink
[Pools] New runtime api that returns the pot accounts associated with…
Browse files Browse the repository at this point in the history
… the pool (#6357)

closes #6358

Adds the following runtime api to pallet-nomination-pools.
`pool_accounts(pool_id)`: Returns `(bonded_account, reward_account)`
associated with the `pool_id`.

cc: @rossbulat

---------

Co-authored-by: command-bot <>
Co-authored-by: Branislav Kontur <[email protected]>
  • Loading branch information
Ank4n and bkontur authored Nov 6, 2024
1 parent 85521e8 commit 1f381f6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
15 changes: 10 additions & 5 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use frame_support::{
use frame_system::{EnsureRoot, EnsureSigned};
use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId};
use pallet_identity::legacy::IdentityInfo;
use pallet_nomination_pools::PoolId;
use pallet_session::historical as session_historical;
use pallet_transaction_payment::{FeeDetails, FungibleAdapter, RuntimeDispatchInfo};
use polkadot_primitives::{
Expand Down Expand Up @@ -2492,23 +2493,23 @@ sp_api::impl_runtime_apis! {
NominationPools::api_pending_rewards(member).unwrap_or_default()
}

fn points_to_balance(pool_id: pallet_nomination_pools::PoolId, points: Balance) -> Balance {
fn points_to_balance(pool_id: PoolId, points: Balance) -> Balance {
NominationPools::api_points_to_balance(pool_id, points)
}

fn balance_to_points(pool_id: pallet_nomination_pools::PoolId, new_funds: Balance) -> Balance {
fn balance_to_points(pool_id: PoolId, new_funds: Balance) -> Balance {
NominationPools::api_balance_to_points(pool_id, new_funds)
}

fn pool_pending_slash(pool_id: pallet_nomination_pools::PoolId) -> Balance {
fn pool_pending_slash(pool_id: PoolId) -> Balance {
NominationPools::api_pool_pending_slash(pool_id)
}

fn member_pending_slash(member: AccountId) -> Balance {
NominationPools::api_member_pending_slash(member)
}

fn pool_needs_delegate_migration(pool_id: pallet_nomination_pools::PoolId) -> bool {
fn pool_needs_delegate_migration(pool_id: PoolId) -> bool {
NominationPools::api_pool_needs_delegate_migration(pool_id)
}

Expand All @@ -2520,9 +2521,13 @@ sp_api::impl_runtime_apis! {
NominationPools::api_member_total_balance(member)
}

fn pool_balance(pool_id: pallet_nomination_pools::PoolId) -> Balance {
fn pool_balance(pool_id: PoolId) -> Balance {
NominationPools::api_pool_balance(pool_id)
}

fn pool_accounts(pool_id: PoolId) -> (AccountId, AccountId) {
NominationPools::api_pool_accounts(pool_id)
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
Expand Down
20 changes: 20 additions & 0 deletions prdoc/pr_6357.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: New runtime api that returns the associated pool accounts with a nomination pool.

doc:
- audience: Runtime User
description: |
Each nomination pool has two associated pot accounts: the bonded account, where funds are pooled for staking, and
the reward account. This update introduces a runtime api that clients can query to retrieve these accounts.

crates:
- name: westend-runtime
bump: minor
- name: kitchensink-runtime
bump: minor
- name: pallet-nomination-pools
bump: minor
- name: pallet-nomination-pools-runtime-api
bump: minor
15 changes: 10 additions & 5 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ use pallet_identity::legacy::IdentityInfo;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_nfts::PalletFeatures;
use pallet_nis::WithMaximumOf;
use pallet_nomination_pools::PoolId;
use pallet_revive::{evm::runtime::EthExtra, AddressMapper};
use pallet_session::historical as pallet_session_historical;
// Can't use `FungibleAdapter` here until Treasury pallet migrates to fungibles
Expand Down Expand Up @@ -3004,23 +3005,23 @@ impl_runtime_apis! {
NominationPools::api_pending_rewards(who).unwrap_or_default()
}

fn points_to_balance(pool_id: pallet_nomination_pools::PoolId, points: Balance) -> Balance {
fn points_to_balance(pool_id: PoolId, points: Balance) -> Balance {
NominationPools::api_points_to_balance(pool_id, points)
}

fn balance_to_points(pool_id: pallet_nomination_pools::PoolId, new_funds: Balance) -> Balance {
fn balance_to_points(pool_id: PoolId, new_funds: Balance) -> Balance {
NominationPools::api_balance_to_points(pool_id, new_funds)
}

fn pool_pending_slash(pool_id: pallet_nomination_pools::PoolId) -> Balance {
fn pool_pending_slash(pool_id: PoolId) -> Balance {
NominationPools::api_pool_pending_slash(pool_id)
}

fn member_pending_slash(member: AccountId) -> Balance {
NominationPools::api_member_pending_slash(member)
}

fn pool_needs_delegate_migration(pool_id: pallet_nomination_pools::PoolId) -> bool {
fn pool_needs_delegate_migration(pool_id: PoolId) -> bool {
NominationPools::api_pool_needs_delegate_migration(pool_id)
}

Expand All @@ -3032,9 +3033,13 @@ impl_runtime_apis! {
NominationPools::api_member_total_balance(member)
}

fn pool_balance(pool_id: pallet_nomination_pools::PoolId) -> Balance {
fn pool_balance(pool_id: PoolId) -> Balance {
NominationPools::api_pool_balance(pool_id)
}

fn pool_accounts(pool_id: PoolId) -> (AccountId, AccountId) {
NominationPools::api_pool_accounts(pool_id)
}
}

impl pallet_staking_runtime_api::StakingApi<Block, Balance, AccountId> for Runtime {
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/nomination-pools/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@ sp_api::decl_runtime_apis! {

/// Total balance contributed to the pool.
fn pool_balance(pool_id: PoolId) -> Balance;

/// Returns the bonded account and reward account associated with the pool_id.
fn pool_accounts(pool_id: PoolId) -> (AccountId, AccountId);
}
}
7 changes: 7 additions & 0 deletions substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,13 @@ impl<T: Config> Pallet<T> {
T::StakeAdapter::total_balance(Pool::from(Self::generate_bonded_account(pool_id)))
.unwrap_or_default()
}

/// Returns the bonded account and reward account associated with the pool_id.
pub fn api_pool_accounts(pool_id: PoolId) -> (T::AccountId, T::AccountId) {
let bonded_account = Self::generate_bonded_account(pool_id);
let reward_account = Self::generate_reward_account(pool_id);
(bonded_account, reward_account)
}
}

impl<T: Config> sp_staking::OnStakingUpdate<T::AccountId, BalanceOf<T>> for Pallet<T> {
Expand Down

0 comments on commit 1f381f6

Please sign in to comment.