Adjust for >75% capacity (#4109)

* Adjust for >75% capacity

* operator wording
This commit is contained in:
Jaco Greeff 2020-11-30 11:32:51 +01:00 committed by GitHub
parent 30b3357e35
commit e1848edd95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 18 deletions

View File

@ -53,7 +53,8 @@ const CLASSES: Record<string, string> = {
rankComm: 'media--1100',
rankNumNominators: 'media--1200'
};
const MAX_COMM_FILTER = 20;
const MAX_CAP_PERCENT = 75;
const MAX_COMM_PERCENT = 20; // %
const MAX_DAYS = 7;
const SORT_KEYS = ['rankNumNominators', 'rankComm', 'rankBondTotal', 'rankBondOwn', 'rankBondOther', 'rankOverall'];
@ -72,8 +73,8 @@ function filterValidators (validators: ValidatorInfo[], allIdentity: Record<stri
(!withElected || isElected) &&
(!withIdentity || !!thisIdentity?.hasIdentity) &&
(!withPayout || !isBabe || (!!lastPayout && daysPayout.gte(lastPayout))) &&
(!withoutComm || (commissionPer < MAX_COMM_FILTER)) &&
(!withoutOver || !maxPaid || maxPaid.gtn(numNominators))
(!withoutComm || (commissionPer < MAX_COMM_PERCENT)) &&
(!withoutOver || !maxPaid || maxPaid.muln(MAX_CAP_PERCENT).divn(100).gtn(numNominators))
) {
if (!withGroup || !thisIdentity || !thisIdentity.parentId) {
if (!parentIds.includes(stashId)) {
@ -149,7 +150,7 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
const [withElected, setWithElected] = useState(false);
const [withGroup, setWithGroup] = useState(true);
const [withIdentity, setWithIdentity] = useState(false);
const [withPayout, setWithPayout] = useState(true);
const [withPayout, setWithPayout] = useState(false);
const [withoutComm, setWithoutComm] = useState(true);
const [withoutOver, setWithoutOver] = useState(true);
const [{ sortBy, sortFromMax }, setSortBy] = useState<SortState>({ sortBy: 'rankOverall', sortFromMax: true });
@ -254,16 +255,22 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
>
<Toggle
className='staking--buttonToggle'
label={t<string>('limit operator exposure')}
label={t<string>('single from operator')}
onChange={setWithGroup}
value={withGroup}
/>
<Toggle
className='staking--buttonToggle'
label={t<string>('no {{maxComm}}%+ comm', { replace: { maxComm: MAX_COMM_FILTER } })}
label={t<string>('no {{maxComm}}%+ comm', { replace: { maxComm: MAX_COMM_PERCENT } })}
onChange={setWithoutComm}
value={withoutComm}
/>
<Toggle
className='staking--buttonToggle'
label={t<string>('no {{maxCap}}%+ capacity', { replace: { maxCap: MAX_CAP_PERCENT } })}
onChange={setWithoutOver}
value={withoutOver}
/>
{api.consts.babe && (
// FIXME have some sane era defaults for Aura
<Toggle
@ -273,12 +280,6 @@ function Targets ({ className = '', isInElection, ownStashes, targets: { avgStak
value={withPayout}
/>
)}
<Toggle
className='staking--buttonToggle'
label={t<string>('no oversubscribed')}
onChange={setWithoutOver}
value={withoutOver}
/>
<Toggle
className='staking--buttonToggle'
label={t<string>('only elected')}

View File

@ -84,10 +84,11 @@ function sortValidators (list: ValidatorInfo[]): ValidatorInfo[] {
);
}
function extractSingle (allAccounts: string[], derive: DeriveStakingElected | DeriveStakingWaiting, favorites: string[], perValidatorReward: BN, { eraLength, lastEra, sessionLength }: LastEra): [ValidatorInfo[], string[]] {
function extractSingle (allAccounts: string[], derive: DeriveStakingElected | DeriveStakingWaiting, favorites: string[], perValidatorReward: BN, { eraLength, lastEra, sessionLength }: LastEra, historyDepth?: BN): [ValidatorInfo[], string[]] {
const nominators: Record<string, boolean> = {};
const emptyExposure = registry.createType('Exposure');
const info = derive.info;
const earliestEra = historyDepth && lastEra.sub(historyDepth).addn(1);
const list = info.map(({ accountId, exposure = emptyExposure, stakingLedger, validatorPrefs }): ValidatorInfo => {
// some overrides (e.g. Darwinia Crab) does not have the own field in Exposure
let bondOwn = exposure.own?.unwrap() || BN_ZERO;
@ -114,7 +115,11 @@ function extractSingle (allAccounts: string[], derive: DeriveStakingElected | De
const lastEraPayout = !lastEra.isZero()
? stakingLedger.claimedRewards[stakingLedger.claimedRewards.length - 1]
: undefined;
let lastPayout: BN | undefined = lastEraPayout;
// only use if it is more recent than historyDepth
let lastPayout: BN | undefined = earliestEra && lastEraPayout && lastEraPayout.gt(earliestEra)
? lastEraPayout
: undefined;
if (lastPayout && !sessionLength.eq(BN_ONE)) {
lastPayout = lastEra.sub(lastPayout).mul(eraLength);
@ -156,9 +161,9 @@ function extractSingle (allAccounts: string[], derive: DeriveStakingElected | De
return [list, Object.keys(nominators)];
}
function extractInfo (api: ApiPromise, allAccounts: string[], electedDerive: DeriveStakingElected, waitingDerive: DeriveStakingWaiting, favorites: string[], totalIssuance: BN, lastEraInfo: LastEra, lastReward: BN): Partial<SortedTargets> {
function extractInfo (api: ApiPromise, allAccounts: string[], electedDerive: DeriveStakingElected, waitingDerive: DeriveStakingWaiting, favorites: string[], totalIssuance: BN, lastEraInfo: LastEra, lastReward: BN, historyDepth?: BN): Partial<SortedTargets> {
const perValidatorReward = lastReward.divn(electedDerive.info.length);
const [elected, nominators] = extractSingle(allAccounts, electedDerive, favorites, perValidatorReward, lastEraInfo);
const [elected, nominators] = extractSingle(allAccounts, electedDerive, favorites, perValidatorReward, lastEraInfo, historyDepth);
const [waiting] = extractSingle(allAccounts, waitingDerive, favorites, perValidatorReward, lastEraInfo);
const activeTotals = elected
.filter(({ isActive }) => isActive)
@ -206,6 +211,7 @@ const transformReward = {
export default function useSortedTargets (favorites: string[]): SortedTargets {
const { api } = useApi();
const { allAccounts } = useAccounts();
const historyDepth = useCall<BN>(api.query.staking.historyDepth);
const totalIssuance = useCall<BN>(api.query.balances.totalIssuance);
const electedInfo = useCall<DeriveStakingElected>(api.derive.staking.electedInfo);
const waitingInfo = useCall<DeriveStakingWaiting>(api.derive.staking.waitingInfo);
@ -214,9 +220,9 @@ export default function useSortedTargets (favorites: string[]): SortedTargets {
const partial = useMemo(
() => electedInfo && lastEraInfo && lastReward && totalIssuance && waitingInfo
? extractInfo(api, allAccounts, electedInfo, waitingInfo, favorites, totalIssuance, lastEraInfo, lastReward)
? extractInfo(api, allAccounts, electedInfo, waitingInfo, favorites, totalIssuance, lastEraInfo, lastReward, historyDepth)
: EMPTY_PARTIAL,
[api, allAccounts, electedInfo, favorites, lastEraInfo, lastReward, totalIssuance, waitingInfo]
[api, allAccounts, electedInfo, favorites, historyDepth, lastEraInfo, lastReward, totalIssuance, waitingInfo]
);
return { inflation: { inflation: 0, stakedReturn: 0 }, ...partial, lastReward };