2023-04-26 12:30:21 +00:00
|
|
|
import { defineStore } from "pinia";
|
|
|
|
import { useBlockchain } from "./useBlockchain";
|
2023-04-26 16:18:50 +00:00
|
|
|
import { percent,formatNumber,formatTokenAmount } from '@/libs/utils'
|
2023-04-26 12:30:21 +00:00
|
|
|
export interface stakingItem {
|
|
|
|
unbonding_time: string
|
|
|
|
max_validators: number
|
|
|
|
max_entries:number
|
|
|
|
historical_entries:number
|
|
|
|
bond_denom: string
|
|
|
|
min_commission_rate: string
|
|
|
|
min_self_delegation:string
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useParamStore = defineStore("paramstore", {
|
|
|
|
state: () => ({
|
|
|
|
latestTime: '',
|
|
|
|
chain: {
|
|
|
|
title: '',
|
|
|
|
class: 'border-primary',
|
|
|
|
items: [
|
2023-04-27 06:05:45 +00:00
|
|
|
{ subtitle: 'height', icon: 'BoxIcon', color: 'light-success', value: '-' },
|
|
|
|
{ subtitle: 'bonded_and_supply', icon: 'DollarSignIcon', color: 'light-danger', value: '-' },
|
|
|
|
{ subtitle: 'bonded_ratio', icon: 'PercentIcon', color: 'light-warning', value: '-' },
|
|
|
|
{ subtitle: 'inflation', icon: 'TrendingUpIcon', color: 'light-primary', value: '-' },
|
2023-04-26 12:30:21 +00:00
|
|
|
],
|
|
|
|
},
|
2023-04-26 16:18:50 +00:00
|
|
|
mint: {
|
|
|
|
title: 'Mint Parameters',
|
|
|
|
items: [] as Array<any>,
|
|
|
|
},
|
2023-04-26 12:30:21 +00:00
|
|
|
staking: {
|
|
|
|
title: 'Staking Parameters',
|
|
|
|
items: [] as Array<any>,
|
|
|
|
},
|
|
|
|
distribution: {
|
|
|
|
title: 'Distribution Parameters',
|
2023-04-26 16:18:50 +00:00
|
|
|
items: [] as Array<any>,
|
2023-04-26 12:30:21 +00:00
|
|
|
},
|
|
|
|
slashing: {
|
|
|
|
title: 'Slashing Parameters',
|
2023-04-26 16:18:50 +00:00
|
|
|
items: [] as Array<any>,
|
2023-04-26 12:30:21 +00:00
|
|
|
},
|
|
|
|
gov: {
|
|
|
|
title: 'Governance Parameters',
|
2023-04-26 16:18:50 +00:00
|
|
|
items: [] as Array<any>,
|
2023-04-26 12:30:21 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
getters: {
|
|
|
|
blockchain() {
|
|
|
|
return useBlockchain()
|
2023-04-27 06:05:45 +00:00
|
|
|
},
|
2023-04-26 12:30:21 +00:00
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
initial() {
|
|
|
|
this.handleBaseBlockLatest()
|
2023-04-27 06:05:45 +00:00
|
|
|
// this.handleMintParam()
|
2023-04-26 12:30:21 +00:00
|
|
|
this.handleStakingParams()
|
2023-04-27 06:05:45 +00:00
|
|
|
this.handleSlashingParams()
|
|
|
|
this.handleDistributionParams()
|
2023-04-27 06:24:31 +00:00
|
|
|
this.handleGovernanceParams()
|
2023-04-26 12:30:21 +00:00
|
|
|
},
|
|
|
|
async handleBaseBlockLatest() {
|
|
|
|
try {
|
|
|
|
const res = await this.getBaseTendermintBlockLatest()
|
|
|
|
const height = this.chain.items.findIndex(x => x.subtitle === 'height')
|
|
|
|
this.chain.title = `Chain ID: ${res.block.header.chain_id}`
|
|
|
|
this.chain.items[height].value = res.block.header.height
|
2023-04-26 16:18:50 +00:00
|
|
|
console.log(res, 999)
|
2023-04-26 12:30:21 +00:00
|
|
|
// if (timeIn(res.block.header.time, 3, 'm')) {
|
|
|
|
// this.syncing = true
|
|
|
|
// } else {
|
|
|
|
// this.syncing = false
|
|
|
|
// }
|
|
|
|
// this.latestTime = toDay(res.block.header.time, 'long')
|
|
|
|
this.latestTime = res.block.header.time
|
|
|
|
} catch (error) {
|
|
|
|
console.warn(error)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async handleStakingParams() {
|
2023-04-26 13:05:20 +00:00
|
|
|
const res = await this.getStakingParams()
|
2023-04-26 16:18:50 +00:00
|
|
|
const bond_denom = res?.params.bond_denom
|
2023-04-26 13:05:20 +00:00
|
|
|
this.staking.items = Object.entries(res.params).map(([key, value]) => ({ subtitle:key,
|
2023-04-26 16:18:50 +00:00
|
|
|
value: value })).filter((item: any) => {
|
|
|
|
if (!['min_commission_rate','min_self_delegation'].includes(item.subtitle)) return item
|
|
|
|
})
|
|
|
|
Promise.all([this.getStakingPool(), this.getBankTotal(bond_denom)])
|
2023-04-26 13:05:20 +00:00
|
|
|
.then(resArr => {
|
2023-04-26 16:18:50 +00:00
|
|
|
const pool = resArr[0]?.pool
|
|
|
|
const amount =resArr[1]?.amount?.amount
|
|
|
|
const assets = this.blockchain.current?.assets
|
|
|
|
const bondedAndSupply = this.chain.items.findIndex(x => x.subtitle === 'bonded_and_supply')
|
|
|
|
this.chain.items[bondedAndSupply].value = `${formatNumber(formatTokenAmount(assets,pool.bonded_tokens, 2, bond_denom, false), true, 0)}/${formatNumber(formatTokenAmount(assets,amount, 2, bond_denom, false), true, 0)}`
|
|
|
|
const bondedRatio = this.chain.items.findIndex(x => x.subtitle === 'bonded_ratio')
|
|
|
|
this.chain.items[bondedRatio].value = `${percent(Number(pool.bonded_tokens) /Number(amount)) }%`
|
2023-04-26 13:05:20 +00:00
|
|
|
})
|
2023-04-26 12:30:21 +00:00
|
|
|
},
|
2023-04-26 16:18:50 +00:00
|
|
|
async handleMintParam() {
|
2023-04-27 06:05:45 +00:00
|
|
|
const excludes = this.blockchain.current?.excludes
|
|
|
|
if(excludes && excludes.indexOf('mint') > -1){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// this.getMintingInflation().then(res => {
|
|
|
|
// const chainIndex = this.chain.items.findIndex(x => x.subtitle === 'inflation')
|
|
|
|
// this.chain.items[chainIndex].value = `${percent(res)}%`
|
|
|
|
// })
|
2023-04-26 16:18:50 +00:00
|
|
|
const res = await this.getMintParam()
|
|
|
|
console.log(res, 'mint')
|
2023-04-27 06:05:45 +00:00
|
|
|
},
|
|
|
|
async handleSlashingParams(){
|
|
|
|
const res = await this.getSlashingParams()
|
|
|
|
this.slashing.items = Object.entries(res.params).map(([key, value]) => ({ subtitle:key,
|
|
|
|
value: value }))
|
|
|
|
console.log('Slashing', res)
|
|
|
|
},
|
|
|
|
async handleDistributionParams(){
|
|
|
|
const res = await this.getDistributionParams()
|
|
|
|
this.distribution.items = Object.entries(res.params).map(([key, value]) => ({ subtitle: key,
|
|
|
|
value: value }))
|
|
|
|
},
|
|
|
|
async handleGovernanceParams() {
|
2023-04-27 06:24:31 +00:00
|
|
|
const excludes = this.blockchain.current?.excludes
|
|
|
|
if(excludes && excludes.indexOf('governance') > -1){
|
2023-04-27 06:05:45 +00:00
|
|
|
return
|
|
|
|
}
|
2023-04-27 06:24:31 +00:00
|
|
|
Promise.all([this.getGovParamsVoting(),this.getGovParamsDeposit(),this.getGovParamsTally()]).then((resArr) => {
|
|
|
|
console.log(resArr, 'resArrr')
|
|
|
|
const govParams = {...resArr[0]?.voting_params,...resArr[1]?.deposit_params,...resArr[2]?.tally_params}
|
|
|
|
this.gov.items = Object.entries(govParams).map(([key, value]) => ({ subtitle:key,
|
|
|
|
value: value }))
|
|
|
|
})
|
2023-04-27 06:05:45 +00:00
|
|
|
|
2023-04-26 16:18:50 +00:00
|
|
|
},
|
2023-04-26 12:30:21 +00:00
|
|
|
async getBaseTendermintBlockLatest() {
|
|
|
|
return await this.blockchain.rpc.getBaseBlockLatest()
|
|
|
|
},
|
2023-04-26 16:18:50 +00:00
|
|
|
async getMintParam() {
|
|
|
|
return await this.blockchain.rpc.getMintParam()
|
|
|
|
},
|
2023-04-26 12:30:21 +00:00
|
|
|
async getStakingParams() {
|
|
|
|
return await this.blockchain.rpc.getStakingParams()
|
|
|
|
},
|
|
|
|
async getStakingPool(){
|
|
|
|
return await this.blockchain.rpc.getStakingPool()
|
|
|
|
},
|
|
|
|
async getBankTotal(denom: string){
|
2023-04-26 13:05:20 +00:00
|
|
|
return await this.blockchain.rpc.getBankSupplyByDenom(denom)
|
|
|
|
// if (compareVersions(this.config.sdk_version, '0.46.2') > 0) {
|
|
|
|
// return this.get(`/cosmos/bank/v1beta1/supply/by_denom?denom=${denom}`).then(data => commonProcess(data).amount)
|
|
|
|
// }
|
|
|
|
// if (compareVersions(this.config.sdk_version, '0.40') < 0) {
|
|
|
|
// return this.get(`/supply/total/${denom}`).then(data => ({ amount: commonProcess(data), denom }))
|
|
|
|
// }
|
|
|
|
// return this.get(`/cosmos/bank/v1beta1/supply/${denom}`).then(data => commonProcess(data).amount)
|
2023-04-27 06:05:45 +00:00
|
|
|
},
|
|
|
|
async getSlashingParams() {
|
|
|
|
return await this.blockchain.rpc.getSlashingParams()
|
|
|
|
},
|
|
|
|
async getDistributionParams() {
|
|
|
|
return await this.blockchain.rpc.getDistributionParams()
|
|
|
|
},
|
|
|
|
async getGovParamsVoting() {
|
|
|
|
return await this.blockchain.rpc.getGovParamsVoting()
|
|
|
|
},
|
|
|
|
async getGovParamsDeposit() {
|
|
|
|
return await this.blockchain.rpc.getGovParamsDeposit()
|
|
|
|
},
|
|
|
|
async getGovParamsTally() {
|
|
|
|
return await this.blockchain.rpc.getGovParamsTally()
|
|
|
|
},
|
2023-04-27 06:24:31 +00:00
|
|
|
|
2023-04-27 06:05:45 +00:00
|
|
|
|
2023-04-26 12:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|