1

I'm writing a script using the polkadot.js API. I want to find the minimum active stake for a certain era. I.e. the minimum amount of DOTs staked by a nominator that also got a reward for that era. Where can I find this value or how can I calculate it? Any help appreciated!

EDIT1: I accidentally wrote epoch when I meant era.

1
  • min active stake does not guarantee rewards as it could have been applied to an oversubscribed validator. The min active nomination value can be seen on the Polkadot JS Staking Targets page. That value seems to be coming from github.com/polkadot-js/apps/blob/…
    – DrW3RK
    Jun 2, 2022 at 15:36

1 Answer 1

2

What you are asking is basically MinActiveThreshold as defined here.

// the ere in which you are interested.
const currentEra = ...
// mapping from nominators, to the sum backing that they are providing to different validators.
const assignments: Map<string, BN> = new Map();

// use erasStakersClipped if you want to take into account oversubscription as well. 
const stakers = await api.query.staking.erasStakers.entries(currentEra);
stakers.sort((a, b) => a[1].total.toBn().cmp(b[1].total.toBn()))

stakers.map((x) => x[1].others).flat(1).forEach((x) => {
    const nominator = (x as PalletStakingIndividualExposure).who.toString();
    const amount = (x as PalletStakingIndividualExposure).value;
    const val = assignments.get(nominator);
    assignments.set(nominator, val ? amount.toBn().add(val) : amount.toBn())
})

/// transform the map to a flat array..
const nominatorStakes = Array.from(assignments);
// .. and sort it..
nominatorStakes.sort((a, b) => a[1].cmp(b[1]));
// .. where the first item will be minimum rewarded.
const minActiveThreshold = nominatorStakes[0][1];
1
  • Great answer. Thanks!
    – sith
    Jun 16, 2022 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.