Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circulating supply #1363

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions src/api/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,62 @@ import request, { gql } from "graphql-request"
import { PROVIDERS, useProviderRpcUrlStore } from "./provider"
import { useRpcProvider } from "providers/rpcProvider"

interface ISubscanData {
code: number
message: string
generated_at: number
data: {
token: Array<string>
detail: {
[key: string]: {
symbol: string
unique_id: string
display_name: string
asset_type: string
token_decimals: number
price: string
price_change: string
total_issuance: string
free_balance: string
available_balance: string
locked_balance: string
reserved_balance: string
validator_bonded: string
nominator_bonded: string
bonded_locked_balance: string
unbonded_locked_balance: string
democracy_locked_balance: string
election_locked_balance: string
vesting_balance: string
inflation: string
}
}
}
}
// interface ISubscanData {
// code: number
// message: string
// generated_at: number
// data: {
// token: Array<string>
// detail: {
// [key: string]: {
// symbol: string
// unique_id: string
// display_name: string
// asset_type: string
// token_decimals: number
// price: string
// price_change: string
// total_issuance: string
// free_balance: string
// available_balance: string
// locked_balance: string
// reserved_balance: string
// validator_bonded: string
// nominator_bonded: string
// bonded_locked_balance: string
// unbonded_locked_balance: string
// democracy_locked_balance: string
// election_locked_balance: string
// vesting_balance: string
// inflation: string
// }
// }
// }
// }

export type TStakingPosition = Awaited<
ReturnType<ReturnType<typeof getStakingPosition>>
>

export const useCirculatingSupply = () => {
return useQuery(
QUERY_KEYS.circulatingSupply,
async () => {
const res = await getCirculatingSupply()()
export const CIRCULATING_SUPPLY = "2647657455182207541914"

return res.data.detail["HDX"].available_balance
},
{ retry: 0 },
)
}
// export const useCirculatingSupply = () => {
// return useQuery(
// QUERY_KEYS.circulatingSupply,
// async () => {
// return
// },
// { retry: 0 },
// )
// }

const getCirculatingSupply = () => async () => {
const res = await fetch("https://hydradx.api.subscan.io/api/scan/token")
// const getCirculatingSupply = () => async () => {
// const res = await fetch("https://hydradx.api.subscan.io/api/scan/token")

const data: Promise<ISubscanData> = res.json()
// const data: Promise<ISubscanData> = res.json()

return data
}
// return data
// }

export const useStake = (address: string | undefined) => {
const { api } = useRpcProvider()
Expand Down
9 changes: 3 additions & 6 deletions src/sections/staking/StakingPage.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import BN, { BigNumber } from "bignumber.js"
import * as wasm from "@galacticcouncil/math-staking"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import {
CIRCULATING_SUPPLY,
TAccumulatedRpsUpdated,
TStakingPosition,
useCirculatingSupply,
useStake,
useStakingConsts,
useStakingEvents,
Expand Down Expand Up @@ -73,7 +73,6 @@ export const useStakeData = () => {

const { account } = useAccount()
const stake = useStake(account?.address)
const circulatingSupply = useCirculatingSupply()
const balance = useTokenBalance(native.id, account?.address)
const locks = useTokenLocks(native.id)
const spotPrice = useDisplayPrice(native.id)
Expand Down Expand Up @@ -101,7 +100,6 @@ export const useStakeData = () => {

const queries = [
stake,
circulatingSupply,
balance,
locks,
spotPrice,
Expand All @@ -121,15 +119,15 @@ export const useStakeData = () => {
const totalStake = stake.data?.totalStake ?? 0

const supplyStaked = BN(totalStake)
.div(Number(circulatingSupply.data ?? 1))
.div(Number(CIRCULATING_SUPPLY))
.decimalPlaces(4)
.multipliedBy(100)

const stakeDollar = stake.data?.stakePosition?.stake
.multipliedBy(spotPrice.data?.spotPrice ?? 1)
.shiftedBy(-native.decimals)

const circulatingSupplyData = BN(circulatingSupply.data ?? 0).shiftedBy(
const circulatingSupplyData = BN(CIRCULATING_SUPPLY).shiftedBy(
-native.decimals,
)

Expand Down Expand Up @@ -209,7 +207,6 @@ export const useStakeData = () => {
}
}, [
availableBalance,
circulatingSupply.data,
isLoading,
positionBalances.data?.events,
referendas.data,
Expand Down
Loading