From 16f83a990f79dae4efb7cd5dff47b0b97eb4d2a0 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 16 Feb 2023 07:39:44 +0200 Subject: [PATCH] Add Polkadot trackinfo (#9029) --- .../src/api/params/tracks/index.ts | 9 +- .../src/api/params/tracks/kusama.ts | 19 +- .../src/api/params/tracks/polkadot.ts | 208 ++++++++++++++++++ .../apps-config/src/api/params/tracks/util.ts | 24 ++ 4 files changed, 243 insertions(+), 17 deletions(-) create mode 100644 packages/apps-config/src/api/params/tracks/polkadot.ts create mode 100644 packages/apps-config/src/api/params/tracks/util.ts diff --git a/packages/apps-config/src/api/params/tracks/index.ts b/packages/apps-config/src/api/params/tracks/index.ts index db7471390b..d7a0db24aa 100644 --- a/packages/apps-config/src/api/params/tracks/index.ts +++ b/packages/apps-config/src/api/params/tracks/index.ts @@ -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> = { - [KUSAMA_GENESIS]: kusama + [KUSAMA_GENESIS]: kusama, + [POLKADOT_GENESIS]: polkadot }; const KNOWN_SPEC_TRACKS: Record> = { @@ -22,7 +24,8 @@ const KNOWN_SPEC_TRACKS: Record> = { origin: { system: 'Root' } } ] - } + }, + polkadot }; export function getGovernanceTracks (api: ApiPromise, specName: string, palletReferenda: string): TrackInfo[] | undefined { diff --git a/packages/apps-config/src/api/params/tracks/kusama.ts b/packages/apps-config/src/api/params/tracks/kusama.ts index 86023a1759..24ea4e13ad 100644 --- a/packages/apps-config/src/api/params/tracks/kusama.ts +++ b/packages/apps-config/src/api/params/tracks/kusama.ts @@ -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 = { fellowshipReferenda: [ { diff --git a/packages/apps-config/src/api/params/tracks/polkadot.ts b/packages/apps-config/src/api/params/tracks/polkadot.ts new file mode 100644 index 0000000000..f51f750ed3 --- /dev/null +++ b/packages/apps-config/src/api/params/tracks/polkadot.ts @@ -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 = { + 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` + } + ] +}; diff --git a/packages/apps-config/src/api/params/tracks/util.ts b/packages/apps-config/src/api/params/tracks/util.ts new file mode 100644 index 0000000000..1714e38b4b --- /dev/null +++ b/packages/apps-config/src/api/params/tracks/util.ts @@ -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); +}