From 777584eaad43c3ae6a46799e2fb7557221e6dc38 Mon Sep 17 00:00:00 2001 From: Jaco Date: Sun, 11 Jul 2021 08:28:25 +0300 Subject: [PATCH] Add config for fast-track thresholds (#5801) * Add config for fast-track thresholds * Update packages/apps-config/src/api/params/proposalThresholds.ts --- .../src/api/params/proposalThresholds.ts | 48 ++++++++++++------- .../page-democracy/src/Overview/Fasttrack.tsx | 7 +-- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/packages/apps-config/src/api/params/proposalThresholds.ts b/packages/apps-config/src/api/params/proposalThresholds.ts index 02ee75bbea..78faa903a7 100644 --- a/packages/apps-config/src/api/params/proposalThresholds.ts +++ b/packages/apps-config/src/api/params/proposalThresholds.ts @@ -5,34 +5,50 @@ import type { ApiPromise } from '@polkadot/api'; import { KULUPU_GENESIS, KUSAMA_GENESIS, POLKADOT_GENESIS } from '../constants'; -const PROPOSE_THRESHOLDS: Record = { +// normal fast-track proposals +const FAST_TRACK: Record = { + default: 2 / 3 +}; + +// in the case where block < fastTrackVotingPeriod +const FAST_TRACK_NO_DELAY: Record = { + default: 1 +}; + +const PROPOSE: Record = { [KULUPU_GENESIS]: 1, - [KUSAMA_GENESIS]: 0.5, - [POLKADOT_GENESIS]: 0.6, - default: 0.5 + [KUSAMA_GENESIS]: 1 / 2, + [POLKADOT_GENESIS]: 3 / 5, + default: 1 / 2 }; -const SLASH_THRESHOLDS: Record = { - [KUSAMA_GENESIS]: 0.5, - [POLKADOT_GENESIS]: 0.75, - default: 0.5 +const SLASH: Record = { + [KUSAMA_GENESIS]: 1 / 2, + [POLKADOT_GENESIS]: 3 / 4, + default: 1 / 2 }; -const TREASURY_THRESHOLDS: Record = { - [KULUPU_GENESIS]: 0.5, - [KUSAMA_GENESIS]: 0.6, - [POLKADOT_GENESIS]: 0.6, - default: 0.6 +const TREASURY: Record = { + [KULUPU_GENESIS]: 1 / 2, + [KUSAMA_GENESIS]: 3 / 5, + [POLKADOT_GENESIS]: 3 / 5, + default: 3 / 5 }; +export function getFastTrackThreshold (api: ApiPromise, isDefault: boolean): number { + return isDefault + ? (FAST_TRACK[api.genesisHash.toHex()] || FAST_TRACK.default) + : (FAST_TRACK_NO_DELAY[api.genesisHash.toHex()] || FAST_TRACK_NO_DELAY.default); +} + export function getProposalThreshold (api: ApiPromise): number { - return PROPOSE_THRESHOLDS[api.genesisHash.toHex()] || PROPOSE_THRESHOLDS.default; + return PROPOSE[api.genesisHash.toHex()] || PROPOSE.default; } export function getSlashProposalThreshold (api: ApiPromise): number { - return SLASH_THRESHOLDS[api.genesisHash.toHex()] || SLASH_THRESHOLDS.default; + return SLASH[api.genesisHash.toHex()] || SLASH.default; } export function getTreasuryProposalThreshold (api: ApiPromise): number { - return TREASURY_THRESHOLDS[api.genesisHash.toHex()] || TREASURY_THRESHOLDS.default; + return TREASURY[api.genesisHash.toHex()] || TREASURY.default; } diff --git a/packages/page-democracy/src/Overview/Fasttrack.tsx b/packages/page-democracy/src/Overview/Fasttrack.tsx index a6cda6ac3c..b121f0f1a6 100644 --- a/packages/page-democracy/src/Overview/Fasttrack.tsx +++ b/packages/page-democracy/src/Overview/Fasttrack.tsx @@ -7,6 +7,7 @@ import type { Hash, VoteThreshold } from '@polkadot/types/interfaces'; import BN from 'bn.js'; import React, { useEffect, useMemo, useState } from 'react'; +import { getFastTrackThreshold } from '@polkadot/apps-config'; import { Button, Input, InputAddress, InputNumber, Modal, TxButton } from '@polkadot/react-components'; import { useApi, useCollectiveInstance, useToggle } from '@polkadot/react-hooks'; @@ -40,9 +41,9 @@ function Fasttrack ({ imageHash, members, threshold }: Props): React.ReactElemen const memberThreshold = useMemo( () => new BN( - !votingBlocks || api.consts.democracy.fastTrackVotingPeriod.lte(votingBlocks) - ? Math.ceil(members.length * 0.66) - : members.length + Math.ceil( + members.length * getFastTrackThreshold(api, !votingBlocks || api.consts.democracy.fastTrackVotingPeriod.lte(votingBlocks)) + ) ), [api, members, votingBlocks] );