From 039223433c9943f344b47905ebebc9fd1e3c7551 Mon Sep 17 00:00:00 2001 From: Leouarz Date: Thu, 19 Oct 2023 08:15:34 +0200 Subject: [PATCH] update metadata and inflation (#38) --- packages/apps-config/src/api/constants.ts | 2 ++ .../apps-config/src/api/params/inflation.ts | 8 +++++--- packages/page-settings/src/useExtensions.ts | 19 ++++++++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/apps-config/src/api/constants.ts b/packages/apps-config/src/api/constants.ts index e2a741edca6b..d67cb3b12bed 100644 --- a/packages/apps-config/src/api/constants.ts +++ b/packages/apps-config/src/api/constants.ts @@ -36,3 +36,5 @@ export const NFTMART_GENESIS = '0xfcf9074303d8f319ad1bf0195b145871977e7c375883b8 export const CERE_NETWORK_GENESIS = '0x81443836a9a24caaa23f1241897d1235717535711d1d3fe24eae4fdc942c092c'; export const CERE_NETWORK_TESTNET_GENESIS = '0x42b9b44b4950b6c1edae543a7696caf8d0a160e9bc0424ab4ab217f7a8ba30dc'; + +export const KATE_NETWORK_TESTNET_GENESIS = '0xd12003ac837853b062aaccca5ce87ac4838c48447e41db4a3dcfb5bf312350c6' diff --git a/packages/apps-config/src/api/params/inflation.ts b/packages/apps-config/src/api/params/inflation.ts index c18426632535..b4a0fa9b97ec 100644 --- a/packages/apps-config/src/api/params/inflation.ts +++ b/packages/apps-config/src/api/params/inflation.ts @@ -3,7 +3,7 @@ import type { ApiPromise } from '@polkadot/api'; -import { CERE_NETWORK_GENESIS, CERE_NETWORK_TESTNET_GENESIS, DOCK_POS_TESTNET_GENESIS, KUSAMA_GENESIS, NEATCOIN_GENESIS, NFTMART_GENESIS, POLKADOT_GENESIS } from '../constants.js'; +import { CERE_NETWORK_GENESIS, CERE_NETWORK_TESTNET_GENESIS, DOCK_POS_TESTNET_GENESIS, KATE_NETWORK_TESTNET_GENESIS, KUSAMA_GENESIS, NEATCOIN_GENESIS, NFTMART_GENESIS, POLKADOT_GENESIS } from '../constants.js'; interface InflationParams { auctionAdjust: number; @@ -28,6 +28,7 @@ const DEFAULT_PARAMS: InflationParams = { }; const CERE_NETWORK_INFLATION_PARAMS = { ...DEFAULT_PARAMS, maxInflation: 0.05, minInflation: 0.0001, stakeTarget: 0.2 }; +const AVAIL_NETWORK_INFLATION_PARAMS = { ...DEFAULT_PARAMS, minInflation: 0.01, maxInflation: 0.05 } const KNOWN_PARAMS: Record = { [CERE_NETWORK_GENESIS]: CERE_NETWORK_INFLATION_PARAMS, @@ -40,9 +41,10 @@ const KNOWN_PARAMS: Record = { [KUSAMA_GENESIS]: { ...DEFAULT_PARAMS, auctionAdjust: (0.3 / 60), auctionMax: 60, stakeTarget: 0.75 }, [NEATCOIN_GENESIS]: { ...DEFAULT_PARAMS, stakeTarget: 0.75 }, [NFTMART_GENESIS]: { ...DEFAULT_PARAMS, falloff: 0.04, stakeTarget: 0.60 }, - [POLKADOT_GENESIS]: { ...DEFAULT_PARAMS, stakeTarget: 0.75 } + [POLKADOT_GENESIS]: { ...DEFAULT_PARAMS, stakeTarget: 0.75 }, + [KATE_NETWORK_TESTNET_GENESIS]: AVAIL_NETWORK_INFLATION_PARAMS }; -export function getInflationParams (api: ApiPromise): InflationParams { +export function getInflationParams(api: ApiPromise): InflationParams { return KNOWN_PARAMS[api.genesisHash.toHex()] || DEFAULT_PARAMS; } diff --git a/packages/page-settings/src/useExtensions.ts b/packages/page-settings/src/useExtensions.ts index 3f68bd5d8375..a3959d8ac3dc 100644 --- a/packages/page-settings/src/useExtensions.ts +++ b/packages/page-settings/src/useExtensions.ts @@ -29,7 +29,7 @@ interface ExtensionProperties { tokenDecimals: number; tokenSymbol: string; ss58Format?: number; - userExtensionsLoaded?: boolean + userExtensionsLoadedOnSpec?: number } interface SavedProperties { @@ -46,7 +46,7 @@ function triggerAll (): void { } // save the properties for a specific extension -function saveProperties (api: ApiPromise, { name, version }: InjectedExtension, hasLoadedUserExtensions: boolean): void { +function saveProperties (api: ApiPromise, { name, version }: InjectedExtension, hasLoadedUserExtensionsOnSpec: number): void { const storeKey = `properties:${api.genesisHash.toHex()}`; const allProperties = store.get(storeKey, {}) as SavedProperties; @@ -55,7 +55,7 @@ function saveProperties (api: ApiPromise, { name, version }: InjectedExtension, ss58Format: api.registry.chainSS58, tokenDecimals: api.registry.chainDecimals[0], tokenSymbol: api.registry.chainTokens[0], - userExtensionsLoaded: hasLoadedUserExtensions + userExtensionsLoadedOnSpec: hasLoadedUserExtensionsOnSpec }; store.set(storeKey, allProperties); @@ -67,17 +67,17 @@ function hasCurrentProperties (api: ApiPromise, { extension }: ExtensionKnown): // when we don't have properties yet, assume nothing has changed and store if (!allProperties[extension.name]) { - saveProperties(api, extension, false); + saveProperties(api, extension, 0); return true; } - const { ss58Format, tokenDecimals, tokenSymbol, userExtensionsLoaded } = allProperties[extension.name]; + const { ss58Format, tokenDecimals, tokenSymbol, userExtensionsLoadedOnSpec } = allProperties[extension.name]; return ss58Format === api.registry.chainSS58 && tokenDecimals === api.registry.chainDecimals[0] && tokenSymbol === api.registry.chainTokens[0] && - (tokenSymbol !== 'AVL' || Boolean(userExtensionsLoaded)); + (tokenSymbol !== 'AVL' || (userExtensionsLoadedOnSpec !== undefined && userExtensionsLoadedOnSpec > 0)); } // filter extensions based on the properties we have available @@ -117,9 +117,14 @@ async function getExtensionInfo (api: ApiPromise, extension: InjectedExtension): try { isOk = await metadata.provide(def); const hasLoadedUserExtensions = !!def.userExtensions; + const maybeSpec = await api.query.system.lastRuntimeUpgrade() + let spec = 0 + if (maybeSpec.isSome) { + spec = maybeSpec.unwrap().specVersion.toNumber() + } if (isOk) { - saveProperties(api, extension, hasLoadedUserExtensions); + saveProperties(api, extension, hasLoadedUserExtensions ? spec : 0); triggerAll(); } } catch {