Skip to content

Commit

Permalink
feat(analytics): new circulation api
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleydon committed Feb 29, 2024
1 parent ad6d69e commit 03cdbaf
Show file tree
Hide file tree
Showing 5 changed files with 329 additions and 355 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"cSpell.words": [
"biomejs",
"bunx",
"crowdloan",
"fontawesome",
"fortawesome",
"karura",
Expand All @@ -36,6 +37,7 @@
"staker",
"stakers",
"subbridge",
"Subscan",
"subsquid",
"svgs",
"sygma",
Expand Down
262 changes: 121 additions & 141 deletions apps/analytics/src/lib/ChainCirculation.svelte
Original file line number Diff line number Diff line change
@@ -1,150 +1,130 @@
<script lang="ts">
import {toCurrency, toPercentage} from '@phala/lib'
import Decimal from 'decimal.js'
import {derived} from 'svelte/store'
import {getCirculation} from '~/stores/circulation'
import Tooltip from './Tooltip.svelte'
import {toCurrency, toPercentage} from '@phala/lib'
import Decimal from 'decimal.js'
import {derived} from 'svelte/store'
import {getCirculation} from '~/stores/circulation'
import Tooltip from './Tooltip.svelte'
export let className = ''
export let chain: 'Phala' | 'Khala' | 'Ethereum'
export let className = ''
export let chain: 'Phala' | 'Khala' | 'Ethereum'
const ETHEREUM_SYGMA_BRIDGE_ADDRESS =
'0xC832588193cd5ED2185daDA4A531e0B26eC5B830'
const PHALA_CROWDLOAN_ADDRESS =
'42fy3tTMPbgxbRqkQCyvLoSoPHwUPM3Dy5iqHYhF9RvD5XAP'
const PHALA_REWARD_ADDRESS = '436H4jat7TobTbNYLdSJ3cmNy9K4frmE4Yuc4R2nNnaf56DL'
const PHALA_SYGMA_BRIDGE_ADDRESS =
'436H4jatj6ntHTVm3wh9zs1Mqa8p1ykfcdkNH7txmjmohTu3'
const ETHEREUM_SYGMA_BRIDGE_ADDRESS =
'0xC832588193cd5ED2185daDA4A531e0B26eC5B830'
const PHALA_CROWDLOAN_ADDRESS =
'42fy3tTMPbgxbRqkQCyvLoSoPHwUPM3Dy5iqHYhF9RvD5XAP'
const PHALA_REWARD_ADDRESS =
'436H4jat7TobTbNYLdSJ3cmNy9K4frmE4Yuc4R2nNnaf56DL'
const PHALA_SYGMA_BRIDGE_ADDRESS =
'436H4jatj6ntHTVm3wh9zs1Mqa8p1ykfcdkNH7txmjmohTu3'
const getEtherscanLink = (address: string) =>
`<a href="https://etherscan.io/address/${address}" target="_blank">${address}</a>`
const getSubscanLink = (chain: 'Phala' | 'Khala', address: string) =>
`<a href="https://${chain.toLowerCase()}.subscan.io/account/${address}" target="_blank">${address}</a>`
const getEtherscanLink = (address: string) =>
`<a href="https://etherscan.io/address/${address}" target="_blank">${address}</a>`
const getSubscanLink = (chain: 'Phala' | 'Khala', address: string) =>
`<a href="https://${chain.toLowerCase()}.subscan.io/account/${address}" target="_blank">${address}</a>`
const display = derived(getCirculation(), ({data: circulation}) => {
if (chain === 'Ethereum') {
let circulatingSupply = ''
let sygmaBridgeLocked = ''
let totalSupply = ''
if (circulation != null) {
const {
ethereumTotalSupply,
ethereumSygmaBridge,
ethereumCirculation,
totalCirculation,
} = circulation
let percentage =
toPercentage(new Decimal(ethereumCirculation).div(totalCirculation)) ??
''
circulatingSupply = `${percentage} / ${toCurrency(
new Decimal(ethereumCirculation),
0,
)} PHA`
sygmaBridgeLocked = `${toCurrency(
new Decimal(ethereumSygmaBridge),
0,
)} PHA`
totalSupply = `${toCurrency(new Decimal(ethereumTotalSupply), 0)} PHA`
const display = derived(getCirculation(), ({data: circulation}) => {
if (chain === 'Ethereum') {
let circulatingSupply = ''
let sygmaBridgeLocked = ''
let totalSupply = ''
if (circulation != null) {
const {ethereum, totalCirculation} = circulation
let percentage =
toPercentage(
new Decimal(ethereum.circulation).div(totalCirculation)
) ?? ''
circulatingSupply = `${percentage} / ${toCurrency(
new Decimal(ethereum.circulation),
0
)} PHA`
sygmaBridgeLocked = `${toCurrency(
new Decimal(ethereum.sygmaBridge),
0
)} PHA`
totalSupply = `${toCurrency(new Decimal(ethereum.totalSupply), 0)} PHA`
}
return [
['Circulating Supply', circulatingSupply],
[
'Sygma bridge locked',
sygmaBridgeLocked,
getEtherscanLink(ETHEREUM_SYGMA_BRIDGE_ADDRESS),
],
['Total Supply', totalSupply],
]
} else if (chain === 'Phala') {
let circulatingSupply = ''
let crowdloanLocked = ''
let sygmaBridgeLocked = ''
let computationLocked = ''
let totalIssuance = ''
if (circulation != null) {
const {phala, totalCirculation} = circulation
let percentage =
toPercentage(new Decimal(phala.circulation).div(totalCirculation)) ??
''
circulatingSupply = `${percentage} / ${toCurrency(
new Decimal(phala.circulation),
0
)} PHA`
sygmaBridgeLocked = `${toCurrency(new Decimal(phala.sygmaBridge), 0)} PHA`
crowdloanLocked = `${toCurrency(new Decimal(phala.crowdloan), 0)} PHA`
computationLocked = `${toCurrency(new Decimal(phala.reward), 0)} PHA`
totalIssuance = `${toCurrency(new Decimal(phala.totalIssuance), 0)} PHA`
}
return [
['Circulating Supply', circulatingSupply],
[
'Sygma bridge locked',
sygmaBridgeLocked,
getSubscanLink(chain, PHALA_SYGMA_BRIDGE_ADDRESS),
],
[
'Crowdloan locked',
crowdloanLocked,
getSubscanLink(chain, PHALA_CROWDLOAN_ADDRESS),
],
[
'Computation locked',
computationLocked,
getSubscanLink(chain, PHALA_REWARD_ADDRESS),
],
['Total Issuance', totalIssuance],
]
} else {
let circulatingSupply = ''
let sygmaBridgeLocked = ''
let computationLocked = ''
let totalIssuance = ''
if (circulation != null) {
const {khala, totalCirculation} = circulation
let percentage =
toPercentage(new Decimal(khala.circulation).div(totalCirculation)) ??
''
circulatingSupply = `${percentage} / ${toCurrency(
new Decimal(khala.circulation),
0
)} PHA`
sygmaBridgeLocked = `${toCurrency(new Decimal(khala.sygmaBridge), 0)} PHA`
computationLocked = `${toCurrency(new Decimal(khala.reward), 0)} PHA`
totalIssuance = `${toCurrency(new Decimal(khala.totalIssuance), 0)} PHA`
}
return [
['Circulating Supply', circulatingSupply],
[
'Sygma bridge locked',
sygmaBridgeLocked,
getSubscanLink(chain, PHALA_SYGMA_BRIDGE_ADDRESS),
],
[
'Computation locked',
computationLocked,
getSubscanLink(chain, PHALA_REWARD_ADDRESS),
],
['Total Issuance', totalIssuance],
]
}
return [
['Circulating Supply', circulatingSupply],
[
'Sygma bridge locked',
sygmaBridgeLocked,
getEtherscanLink(ETHEREUM_SYGMA_BRIDGE_ADDRESS),
],
['Total Supply', totalSupply],
]
} else if (chain === 'Phala') {
let circulatingSupply = ''
let crowdloanLocked = ''
let sygmaBridgeLocked = ''
let computationLocked = ''
let totalIssuance = ''
if (circulation != null) {
const {
phalaCrowdloan,
phalaMiningRewards,
phalaCirculation,
phalaSygmaBridge,
phalaTotalIssuance,
totalCirculation,
} = circulation
let percentage =
toPercentage(new Decimal(phalaCirculation).div(totalCirculation)) ?? ''
circulatingSupply = `${percentage} / ${toCurrency(
new Decimal(phalaCirculation),
0,
)} PHA`
sygmaBridgeLocked = `${toCurrency(new Decimal(phalaSygmaBridge), 0)} PHA`
crowdloanLocked = `${toCurrency(new Decimal(phalaCrowdloan), 0)} PHA`
computationLocked = `${toCurrency(
new Decimal(phalaMiningRewards),
0,
)} PHA`
totalIssuance = `${toCurrency(new Decimal(phalaTotalIssuance), 0)} PHA`
}
return [
['Circulating Supply', circulatingSupply],
[
'Sygma bridge locked',
sygmaBridgeLocked,
getSubscanLink(chain, PHALA_SYGMA_BRIDGE_ADDRESS),
],
[
'Crowdloan locked',
crowdloanLocked,
getSubscanLink(chain, PHALA_CROWDLOAN_ADDRESS),
],
[
'Computation locked',
computationLocked,
getSubscanLink(chain, PHALA_REWARD_ADDRESS),
],
['Total Issuance', totalIssuance],
]
} else {
let circulatingSupply = ''
let sygmaBridgeLocked = ''
let computationLocked = ''
let totalIssuance = ''
if (circulation != null) {
const {
khalaMiningRewards,
khalaSygmaBridge,
khalaCirculation,
khalaTotalIssuance,
totalCirculation,
} = circulation
let percentage =
toPercentage(new Decimal(khalaCirculation).div(totalCirculation)) ?? ''
circulatingSupply = `${percentage} / ${toCurrency(
new Decimal(khalaCirculation),
0,
)} PHA`
sygmaBridgeLocked = `${toCurrency(new Decimal(khalaSygmaBridge), 0)} PHA`
computationLocked = `${toCurrency(
new Decimal(khalaMiningRewards),
0,
)} PHA`
totalIssuance = `${toCurrency(new Decimal(khalaTotalIssuance), 0)} PHA`
}
return [
['Circulating Supply', circulatingSupply],
[
'Sygma bridge locked',
sygmaBridgeLocked,
getSubscanLink(chain, PHALA_SYGMA_BRIDGE_ADDRESS),
],
[
'Computation locked',
computationLocked,
getSubscanLink(chain, PHALA_REWARD_ADDRESS),
],
['Total Issuance', totalIssuance],
]
}
})
})
</script>

<section class="card {className}">
Expand Down
Loading

0 comments on commit 03cdbaf

Please sign in to comment.