From e0108488253bf365db45a47d29fb8b58a2ca0ba1 Mon Sep 17 00:00:00 2001 From: Bobo Date: Tue, 4 Jun 2024 09:50:23 +0200 Subject: [PATCH] Hardcode inflation period start blocks (#1300) * Hardcode inflation period start blocks * dApp promotions update. * active adjustable staker part display bug fix --- src/components/common/styles/chart-panel.scss | 1 - src/components/dashboard/Inflation.vue | 4 +- src/data/dapp_promotions.json | 12 +++--- src/hooks/useInflation.ts | 37 +++++++++++-------- src/i18n/en-US/index.ts | 1 + 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/components/common/styles/chart-panel.scss b/src/components/common/styles/chart-panel.scss index 32beb0117..5ee81ddd2 100644 --- a/src/components/common/styles/chart-panel.scss +++ b/src/components/common/styles/chart-panel.scss @@ -28,7 +28,6 @@ border-radius: 6px; @media (min-width: $xxl) { height: 433px; - width: 560px; } } diff --git a/src/components/dashboard/Inflation.vue b/src/components/dashboard/Inflation.vue index 397cd6a66..1e1a134fe 100644 --- a/src/components/dashboard/Inflation.vue +++ b/src/components/dashboard/Inflation.vue @@ -85,7 +85,9 @@ export default defineComponent({ const pieSectors = ref([]); const isDarkTheme = computed(() => store.getters['general/theme'] === 'DARK'); - const numberFromPercentage = (value?: number): number | string => (value ? value * 100 : '--'); + const numberFromPercentage = (value?: number): number | string => + value !== undefined ? value * 100 : '--'; + const adjustableStakersPercentage = computed(() => Number( ( diff --git a/src/data/dapp_promotions.json b/src/data/dapp_promotions.json index 07da0b670..6d4ca0bd4 100644 --- a/src/data/dapp_promotions.json +++ b/src/data/dapp_promotions.json @@ -1,4 +1,10 @@ [ + { + "name": "Archisinal", + "shortDescription": "Pioneering Real-World-Assets in the built environment", + "link": "https://www.archisinal.io/", + "img": "images/dapp_promotions/Archisinal.png" + }, { "name": "DeStore", "shortDescription": "Web3 Shopify Powered by Astar", @@ -46,11 +52,5 @@ "shortDescription": "#1 Cross-chain Social Fitness App on iOS & Android, Apple Watch", "link": "https://app.moonfit.xyz/astar-reward", "img": "images/dapp_promotions/moonfit.png" - }, - { - "name": "Archisinal", - "shortDescription": "Pioneering Real-World-Assets in the built environment", - "link": "https://www.archisinal.io/", - "img": "images/dapp_promotions/Archisinal.png" } ] diff --git a/src/hooks/useInflation.ts b/src/hooks/useInflation.ts index 9eb0de11d..dee90d1f6 100644 --- a/src/hooks/useInflation.ts +++ b/src/hooks/useInflation.ts @@ -8,6 +8,7 @@ import { $api } from 'src/boot/api'; import { InflationParam, useDappStaking } from 'src/staking-v3'; import { ethers } from 'ethers'; import { useNetworkInfo } from './useNetworkInfo'; +import { useI18n } from 'vue-i18n'; type UseInflation = { activeInflationConfiguration: ComputedRef; @@ -21,8 +22,15 @@ type UseInflation = { getInflationParameters: () => Promise; }; +const period1StartBlocks = new Map([ + ['astar', 5514935], + ['shiden', 5876079], + ['shibuya', 5335616], +]); + export function useInflation(): UseInflation { const store = useStore(); + const { t } = useI18n(); const { eraLengths, currentEraInfo } = useDappStaking(); const { networkNameSubstrate } = useNetworkInfo(); const estimatedInflation = ref(undefined); @@ -65,17 +73,16 @@ export function useInflation(): UseInflation { if ($api) { try { - // Find the block when last NewInflationConfiguration event was emitted. - const subscanRepository = container.get(Symbols.SubscanRepository); - const response = await subscanRepository.getEvents( - networkNameSubstrate.value.toLowerCase(), - 'inflation', - 'NewInflationConfiguration' - ); - // Latest item in array is for the current inflation cycle. - const initialCycleBlock = response.events[response.events.length - 1].block; + const period1StartBlock = period1StartBlocks.get(networkNameSubstrate.value.toLowerCase()); + + if (!period1StartBlock) { + console.warn( + t('dashboard.inflation.wrongNetwork', { network: networkNameSubstrate.value }) + ); + return; + } - const initialIssuanceBlockHash = await $api.rpc.chain.getBlockHash(initialCycleBlock - 1); + const initialIssuanceBlockHash = await $api.rpc.chain.getBlockHash(period1StartBlock - 1); const apiAt = await $api.at(initialIssuanceBlockHash); const initialTotalIssuance = await apiAt.query.balances.totalIssuance(); const realizedTotalIssuance = await $api.query.balances.totalIssuance(); @@ -89,15 +96,15 @@ export function useInflation(): UseInflation { standardEraLength * periodsPerCycle * (standardErasPerBuildAndEarnPeriod + standardErasPerVotingPeriod); - const blockDifference = BigInt(currentBlock.value - initialCycleBlock); + const blockDifference = BigInt(currentBlock.value - period1StartBlock); const slope = BigInt(realizedTotalIssuance.sub(initialTotalIssuance).toString()) / blockDifference; // Estimate total issuance at the end of the current cycle. - const endOfCycleBlock = initialCycleBlock + cycleLengthInBlocks; + const endOfCycleBlock = period1StartBlock + cycleLengthInBlocks; const endOfCycleTotalIssuance = Number( ethers.utils.formatEther( - slope * BigInt(endOfCycleBlock - initialCycleBlock) + initialTotalIssuance.toBigInt() + slope * BigInt(endOfCycleBlock - period1StartBlock) + initialTotalIssuance.toBigInt() ) ); @@ -110,7 +117,7 @@ export function useInflation(): UseInflation { // Calculate maximum and realized inflation for each era in the cycle. calculateMaximumInflationData( - initialCycleBlock, + period1StartBlock, endOfCycleBlock, initialTotalIssuance.toBigInt(), cycleLengthInBlocks, @@ -119,7 +126,7 @@ export function useInflation(): UseInflation { ); calculateRealizedInflationData( - initialCycleBlock, + period1StartBlock, currentBlock.value, slope, eraLengths.value.standardEraLength, diff --git a/src/i18n/en-US/index.ts b/src/i18n/en-US/index.ts index 49c0677b3..4cc3a906a 100644 --- a/src/i18n/en-US/index.ts +++ b/src/i18n/en-US/index.ts @@ -695,6 +695,7 @@ export default { currentInflationRate: 'Current inflation rate', maximumInflation: 'Maximum inflation ({rate}%)', realizedInflation: 'Realized inflation', + wrongNetwork: 'Period 1 start block is not defined for the current network {network}.', }, }, chart: {