Skip to content

Commit

Permalink
Hardcode inflation period start blocks (#1300)
Browse files Browse the repository at this point in the history
* Hardcode inflation period start blocks

* dApp promotions update.

* active adjustable staker part display bug fix
  • Loading branch information
bobo-k2 authored Jun 4, 2024
1 parent fbde6e9 commit e010848
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/components/common/styles/chart-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
border-radius: 6px;
@media (min-width: $xxl) {
height: 433px;
width: 560px;
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/dashboard/Inflation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export default defineComponent({
const pieSectors = ref<Sector[]>([]);
const isDarkTheme = computed<boolean>(() => 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>(() =>
Number(
(
Expand Down
12 changes: 6 additions & 6 deletions src/data/dapp_promotions.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
]
37 changes: 22 additions & 15 deletions src/hooks/useInflation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InflationConfiguration>;
Expand All @@ -21,8 +22,15 @@ type UseInflation = {
getInflationParameters: () => Promise<InflationParam>;
};

const period1StartBlocks = new Map<string, number>([
['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<number | undefined>(undefined);
Expand Down Expand Up @@ -65,17 +73,16 @@ export function useInflation(): UseInflation {

if ($api) {
try {
// Find the block when last NewInflationConfiguration event was emitted.
const subscanRepository = container.get<ISubscanRepository>(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();
Expand All @@ -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()
)
);

Expand All @@ -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,
Expand All @@ -119,7 +126,7 @@ export function useInflation(): UseInflation {
);

calculateRealizedInflationData(
initialCycleBlock,
period1StartBlock,
currentBlock.value,
slope,
eraLengths.value.standardEraLength,
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit e010848

Please sign in to comment.