Add Polkadot trackinfo (#9029)
This commit is contained in:
parent
b88a15ee5e
commit
16f83a990f
@ -4,11 +4,13 @@
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { TrackInfo } from './types';
|
||||
|
||||
import { KUSAMA_GENESIS } from '../../constants';
|
||||
import { KUSAMA_GENESIS, POLKADOT_GENESIS } from '../../constants';
|
||||
import { kusama } from './kusama';
|
||||
import { polkadot } from './polkadot';
|
||||
|
||||
const KNOWN_GENE_TRACKS: Record<string, Record<string, TrackInfo[]>> = {
|
||||
[KUSAMA_GENESIS]: kusama
|
||||
[KUSAMA_GENESIS]: kusama,
|
||||
[POLKADOT_GENESIS]: polkadot
|
||||
};
|
||||
|
||||
const KNOWN_SPEC_TRACKS: Record<string, Record<string, TrackInfo[]>> = {
|
||||
@ -22,7 +24,8 @@ const KNOWN_SPEC_TRACKS: Record<string, Record<string, TrackInfo[]>> = {
|
||||
origin: { system: 'Root' }
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
polkadot
|
||||
};
|
||||
|
||||
export function getGovernanceTracks (api: ApiPromise, specName: string, palletReferenda: string): TrackInfo[] | undefined {
|
||||
|
||||
@ -3,15 +3,17 @@
|
||||
|
||||
import type { TrackInfo } from './types';
|
||||
|
||||
import { BN, formatBalance } from '@polkadot/util';
|
||||
import { BN } from '@polkadot/util';
|
||||
|
||||
import { compareFellowshipRank, formatSpendFactory } from './util';
|
||||
|
||||
// hardcoded here since this is static (hopefully no re-denomination anytime...)
|
||||
const FMT_OPTS = {
|
||||
const formatSpend = formatSpendFactory({
|
||||
decimals: 12,
|
||||
forceUnit: '-',
|
||||
withSi: true,
|
||||
withUnit: 'KSM'
|
||||
};
|
||||
});
|
||||
|
||||
// https://github.com/paritytech/polkadot/blob/6e3f2c5b4b6e6927915de2f784e1d831717760fa/runtime/kusama/constants/src/lib.rs#L28-L32
|
||||
const UNITS = new BN(1_000_000_000_000);
|
||||
@ -28,17 +30,6 @@ const SPEND_LIMITS = {
|
||||
Treasurer: formatSpend(10_000, GRAND)
|
||||
};
|
||||
|
||||
function formatSpend (mul: number, value: BN): string {
|
||||
// We lose the decimals here... depending on chain config, this could be non-optimal
|
||||
// (A simple formatBalance(value.muln(mul), FMT_OPTS) formats to 4 decimals)
|
||||
return `${formatBalance(value.muln(mul), FMT_OPTS).split('.')[0]} ${FMT_OPTS.withUnit}`;
|
||||
}
|
||||
|
||||
function compareFellowshipRank (trackId: number): (rank: BN) => boolean {
|
||||
return (rank: BN): boolean =>
|
||||
rank.gten(trackId);
|
||||
}
|
||||
|
||||
export const kusama: Record<string, TrackInfo[]> = {
|
||||
fellowshipReferenda: [
|
||||
{
|
||||
|
||||
208
packages/apps-config/src/api/params/tracks/polkadot.ts
Normal file
208
packages/apps-config/src/api/params/tracks/polkadot.ts
Normal file
@ -0,0 +1,208 @@
|
||||
// Copyright 2017-2023 @polkadot/app-config authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { TrackInfo } from './types';
|
||||
|
||||
import { BN } from '@polkadot/util';
|
||||
|
||||
import { compareFellowshipRank, formatSpendFactory } from './util';
|
||||
|
||||
// hardcoded here since this is static (hopefully no re-denomination anytime...)
|
||||
const formatSpend = formatSpendFactory({
|
||||
decimals: 10,
|
||||
forceUnit: '-',
|
||||
withSi: true,
|
||||
withUnit: 'DOT'
|
||||
});
|
||||
|
||||
// https://github.com/paritytech/polkadot/blob/6e3f2c5b4b6e6927915de2f784e1d831717760fa/runtime/kusama/constants/src/lib.rs#L28-L32
|
||||
const UNITS = new BN(10_000_000_000);
|
||||
const DOLLARS = UNITS;
|
||||
const GRAND = DOLLARS.muln(1_000);
|
||||
|
||||
// https://github.com/paritytech/polkadot/blob/6e3f2c5b4b6e6927915de2f784e1d831717760fa/runtime/kusama/src/governance/origins.rs#L170-L179
|
||||
const SPEND_LIMITS = {
|
||||
BigSpender: formatSpend(1_000, GRAND),
|
||||
BigTipper: formatSpend(1, GRAND),
|
||||
MediumSpender: formatSpend(100, GRAND),
|
||||
SmallSpender: formatSpend(10, GRAND),
|
||||
SmallTipper: formatSpend(250, DOLLARS),
|
||||
Treasurer: formatSpend(10_000, GRAND)
|
||||
};
|
||||
|
||||
export const polkadot: Record<string, TrackInfo[]> = {
|
||||
fellowshipReferenda: [
|
||||
{
|
||||
compare: compareFellowshipRank(0),
|
||||
id: 0,
|
||||
name: 'candidates',
|
||||
origin: { Origins: 'FellowshipInitiates' },
|
||||
text: 'Origin commanded by any members of the Polkadot Fellowship (no Dan grade needed)'
|
||||
},
|
||||
{
|
||||
compare: compareFellowshipRank(1),
|
||||
id: 1,
|
||||
name: 'members',
|
||||
origin: { Origins: 'Fellowship1Dan' },
|
||||
text: 'Origin commanded by rank 1 of the Polkadot Fellowship and with a success of 1'
|
||||
},
|
||||
{
|
||||
compare: compareFellowshipRank(2),
|
||||
id: 2,
|
||||
name: 'proficients',
|
||||
origin: { Origins: 'Fellowship2Dan' },
|
||||
text: 'Origin commanded by rank 2 of the Polkadot Fellowship and with a success of 2'
|
||||
},
|
||||
{
|
||||
|
||||
compare: compareFellowshipRank(3),
|
||||
id: 3,
|
||||
name: 'fellows',
|
||||
origin: [
|
||||
{ Origins: 'Fellowship3Dan' },
|
||||
{ Origins: 'Fellows' }
|
||||
],
|
||||
text: 'Origin commanded by Polkadot Fellows (3rd Dan fellows or greater)'
|
||||
},
|
||||
{
|
||||
compare: compareFellowshipRank(4),
|
||||
id: 4,
|
||||
name: 'senior fellows',
|
||||
origin: { Origins: 'Fellowship4Dan' },
|
||||
text: 'Origin commanded by rank 4 of the Polkadot Fellowship and with a success of 4'
|
||||
},
|
||||
{
|
||||
compare: compareFellowshipRank(5),
|
||||
id: 5,
|
||||
name: 'experts',
|
||||
origin: [
|
||||
{ Origins: 'Fellowship5Dan' },
|
||||
{ Origins: 'FellowshipExperts' }
|
||||
],
|
||||
text: 'Origin commanded by Polkadot Experts (5th Dan fellows or greater)'
|
||||
},
|
||||
{
|
||||
compare: compareFellowshipRank(6),
|
||||
id: 6,
|
||||
name: 'senior experts',
|
||||
origin: { Origins: 'Fellowship6Dan' },
|
||||
text: 'Origin commanded by rank 6 of the Polkadot Fellowship and with a success of 6'
|
||||
},
|
||||
{
|
||||
compare: compareFellowshipRank(7),
|
||||
id: 7,
|
||||
name: 'masters',
|
||||
origin: [
|
||||
{ Origins: 'Fellowship7Dan' },
|
||||
{ Origins: 'FellowshipMasters' }
|
||||
],
|
||||
text: 'Origin commanded by Polkadot Masters (7th Dan fellows of greater)'
|
||||
},
|
||||
{
|
||||
compare: compareFellowshipRank(8),
|
||||
id: 8,
|
||||
name: 'senior masters',
|
||||
origin: { Origins: 'Fellowship8Dan' },
|
||||
text: 'Origin commanded by rank 8 of the Polkadot Fellowship and with a success of 8'
|
||||
},
|
||||
{
|
||||
compare: compareFellowshipRank(9),
|
||||
id: 9,
|
||||
name: 'grand masters',
|
||||
origin: { Origins: 'Fellowship9Dan' },
|
||||
text: 'Origin commanded by rank 9 of the Polkadot Fellowship and with a success of 9'
|
||||
}
|
||||
],
|
||||
referenda: [
|
||||
{
|
||||
id: 0,
|
||||
name: 'root',
|
||||
origin: { system: 'Root' },
|
||||
text: 'Origin for the system root'
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
name: 'whitelisted_caller',
|
||||
origin: { Origins: 'WhitelistedCaller' },
|
||||
text: 'Origin able to dispatch a whitelisted call'
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
name: 'staking_admin',
|
||||
origin: { Origins: 'StakingAdmin' },
|
||||
text: 'Origin for cancelling slashes'
|
||||
},
|
||||
{
|
||||
id: 11,
|
||||
name: 'treasurer',
|
||||
origin: { Origins: 'Treasurer' },
|
||||
text: 'Origin for spending (any amount of) funds'
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
name: 'lease_admin',
|
||||
origin: { Origins: 'LeaseAdmin' },
|
||||
text: 'Origin able to force slot leases'
|
||||
},
|
||||
{
|
||||
id: 13,
|
||||
name: 'fellowship_admin',
|
||||
origin: { Origins: 'FellowshipAdmin' },
|
||||
text: 'Origin for managing the composition of the fellowship'
|
||||
},
|
||||
{
|
||||
id: 14,
|
||||
name: 'general_admin',
|
||||
origin: { Origins: 'GeneralAdmin' },
|
||||
text: 'Origin for managing the registrar'
|
||||
},
|
||||
{
|
||||
id: 15,
|
||||
name: 'auction_admin',
|
||||
origin: { Origins: 'AuctionAdmin' },
|
||||
text: 'Origin for starting auctions'
|
||||
},
|
||||
{
|
||||
id: 20,
|
||||
name: 'referendum_canceller',
|
||||
origin: { Origins: 'ReferendumCanceller' },
|
||||
text: 'Origin able to cancel referenda'
|
||||
},
|
||||
{
|
||||
id: 21,
|
||||
name: 'referendum_killer',
|
||||
origin: { Origins: 'ReferendumKiller' },
|
||||
text: 'Origin able to kill referenda'
|
||||
},
|
||||
{
|
||||
id: 30,
|
||||
name: 'small_tipper',
|
||||
origin: { Origins: 'SmallTipper' },
|
||||
text: `Origin able to spend up to ${SPEND_LIMITS.SmallTipper} from the treasury at once`
|
||||
},
|
||||
{
|
||||
id: 31,
|
||||
name: 'big_tipper',
|
||||
origin: { Origins: 'BigTipper' },
|
||||
text: `Origin able to spend up to ${SPEND_LIMITS.BigTipper} from the treasury at once`
|
||||
},
|
||||
{
|
||||
id: 32,
|
||||
name: 'small_spender',
|
||||
origin: { Origins: 'SmallSpender' },
|
||||
text: `Origin able to spend up to ${SPEND_LIMITS.SmallSpender} from the treasury at once`
|
||||
},
|
||||
{
|
||||
id: 33,
|
||||
name: 'medium_spender',
|
||||
origin: { Origins: 'MediumSpender' },
|
||||
text: `Origin able to spend up to ${SPEND_LIMITS.MediumSpender} from the treasury at once`
|
||||
},
|
||||
{
|
||||
id: 34,
|
||||
name: 'big_spender',
|
||||
origin: { Origins: 'BigSpender' },
|
||||
text: `Origin able to spend up to ${SPEND_LIMITS.BigSpender} from the treasury at once`
|
||||
}
|
||||
]
|
||||
};
|
||||
24
packages/apps-config/src/api/params/tracks/util.ts
Normal file
24
packages/apps-config/src/api/params/tracks/util.ts
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2017-2023 @polkadot/app-config authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { BN, formatBalance } from '@polkadot/util';
|
||||
|
||||
interface FormatOptions {
|
||||
decimals: number;
|
||||
forceUnit: '-',
|
||||
withSi: true,
|
||||
withUnit: string;
|
||||
}
|
||||
|
||||
export function formatSpendFactory (options: FormatOptions): (mul: number, value: BN) => string {
|
||||
return (mul: number, value: BN): string => {
|
||||
// We lose the decimals here... depending on chain config, this could be non-optimal
|
||||
// (A simple formatBalance(value.muln(mul), FMT_OPTS) formats to 4 decimals)
|
||||
return `${formatBalance(value.muln(mul), options).split('.')[0]} ${options.withUnit}`;
|
||||
};
|
||||
}
|
||||
|
||||
export function compareFellowshipRank (trackId: number): (rank: BN) => boolean {
|
||||
return (rank: BN): boolean =>
|
||||
rank.gten(trackId);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user