forked from cerc-io/cosmos-explorer
Merge pull request #574 from amimart/fix/staking-apr-formula
fix(staking): correct APR computation formula
This commit is contained in:
commit
57ad32e37a
@ -1,7 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { parseCoins } from '@cosmjs/stargate';
|
||||
import {
|
||||
useBankStore,
|
||||
useBlockchain,
|
||||
useDistributionStore,
|
||||
useFormatter,
|
||||
useMintStore,
|
||||
useStakingStore,
|
||||
@ -64,12 +66,12 @@ blockchain.rpc.getTxsBySender(addresses.value.account).then((x) => {
|
||||
});
|
||||
|
||||
const apr = computed(() => {
|
||||
const rate = v.value.commission?.commission_rates.rate || 0;
|
||||
const rate = Number(v.value.commission?.commission_rates.rate || 0);
|
||||
const inflation = useMintStore().inflation;
|
||||
if (Number(inflation)) {
|
||||
return format.percent((1 - Number(rate)) * Number(inflation));
|
||||
}
|
||||
return '-';
|
||||
const communityTax = Number(useDistributionStore().params.community_tax);
|
||||
const bondedRatio = Number(staking.pool.bonded_tokens) / Number(useBankStore().supply.amount);
|
||||
|
||||
return format.percent((1 - communityTax) * (1 - rate) * Number(inflation) / bondedRatio);
|
||||
});
|
||||
|
||||
const selfRate = computed(() => {
|
||||
|
@ -16,10 +16,11 @@ import { CosmosRestClient } from '@/libs/client';
|
||||
import {
|
||||
useBankStore,
|
||||
useBaseStore,
|
||||
useDistributionStore,
|
||||
useGovStore,
|
||||
useMintStore,
|
||||
useStakingStore,
|
||||
useWalletStore,
|
||||
useWalletStore
|
||||
} from '.';
|
||||
import { useBlockModule } from '@/modules/[chain]/block/block';
|
||||
import { DEFAULT } from '@/libs';
|
||||
@ -151,6 +152,7 @@ export const useBlockchain = defineStore('blockchain', {
|
||||
useGovStore().initial();
|
||||
useMintStore().initial();
|
||||
useBlockModule().initial();
|
||||
useDistributionStore().initial();
|
||||
},
|
||||
|
||||
randomEndpoint(chainName: string) : Endpoint | undefined {
|
||||
|
@ -3,7 +3,14 @@ import { useBlockchain } from './useBlockchain';
|
||||
|
||||
export const useDistributionStore = defineStore('distributionStore', {
|
||||
state: () => {
|
||||
return {};
|
||||
return {
|
||||
params: {} as {
|
||||
community_tax: string;
|
||||
base_proposer_reward: string;
|
||||
bonus_proposer_reward: string;
|
||||
withdraw_addr_enabled: boolean;
|
||||
},
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
blockchain() {
|
||||
@ -11,6 +18,14 @@ export const useDistributionStore = defineStore('distributionStore', {
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
initial() {
|
||||
this.fetchParams();
|
||||
},
|
||||
async fetchParams() {
|
||||
const response = await this.blockchain.rpc?.getDistributionParams();
|
||||
if (response?.params) this.params = response.params;
|
||||
return this.params;
|
||||
},
|
||||
async fetchCommunityPool() {
|
||||
return this.blockchain.rpc?.getDistributionCommunityPool();
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user