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

feat: IDXR-57 Add metrics for token infusion #1337

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
40 changes: 36 additions & 4 deletions src/prom-metrics/definitions/multiToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ export const indexer_multitokens_existential_deposit_total = new client.Gauge({
registers: [register],
})

export const indexer_multitokens_enj_infused_total = new client.Gauge({
name: 'indexer_multitokens_enj_infused_total',
labelNames: ['multitoken'],
help: 'The total ENJ infused in all tokens.',
registers: [register],
})

export const indexer_multitokens_infused_tokens_total = new client.Gauge({
name: 'indexer_multitokens_infused_tokens_total',
labelNames: ['multitoken'],
help: 'The total number of infused tokens. (Tokens with infusion > 0) including, multiplied by their supply',
registers: [register],
})

export const indexer_multitokens_infused_unique_tokens_total = new client.Gauge({
name: 'indexer_multitokens_infused_unique_tokens_total',
labelNames: ['multitoken'],
help: 'The total number of unique infused tokens. (Tokens with infusion > 0), where FTs is considered 1',
registers: [register],
})

export default async () => {
if (!connection.isInitialized) {
await connection.initialize().catch(() => {
Expand All @@ -69,14 +90,22 @@ export default async () => {
collectionTokensAvg,
accountTokensAvg,
existentialDepositTotal,
enjInfusedTotal,
infusedTokensTotal,
infusedUniqueTokensTotal,
] = await Promise.all([
em.query('SELECT COUNT(DISTINCT account_id) FROM token_account where total_balance::numeric > 0'),
em.query('SELECT COUNT(*) as count FROM collection'),
em.query('SELECT COUNT(*) FROM token'),
em.query('SELECT AVG(holders) FROM (SELECT COUNT(id) as holders FROM collection_account GROUP BY collection_id)'),
em.query('SELECT AVG(tokens) FROM (SELECT COUNT(id) as tokens FROM token GROUP BY collection_id)'),
em.query('SELECT AVG(tokens) FROM (SELECT COUNT(id) as tokens FROM token_account GROUP BY account_id)'),
em.query('SELECT COUNT(*) as count FROM token'),
em.query(
'SELECT AVG(sq.holders) as avg FROM (SELECT COUNT(id) as holders FROM collection_account GROUP BY collection_id) as sq'
),
em.query('SELECT AVG(sq.tokens) as avg FROM (SELECT COUNT(id) as tokens FROM token GROUP BY collection_id) as sq'),
em.query('SELECT AVG(sq.tokens) as avg FROM (SELECT COUNT(id) as tokens FROM token_account GROUP BY account_id) as sq'),
em.query('SELECT SUM(unit_price)::numeric / POW(10,18) as sum FROM token'),
em.query('SELECT SUM(infusion)::numeric / POW(10,18) as sum FROM token WHERE infusion::numeric > 0'),
em.query('SELECT SUM(supply::numeric) as sum FROM token WHERE infusion::numeric > 0'),
em.query('SELECT COUNT(*) as count FROM token WHERE infusion::numeric > 0'),
])

indexer_multitokens_unique_holders_total.set(Number(uniqueHolders[0].count))
Expand All @@ -86,4 +115,7 @@ export default async () => {
indexer_multitokens_collection_tokens_avg.set(parseInt(collectionTokensAvg[0].avg, 10))
indexer_multitokens_account_tokens_avg.set(parseInt(accountTokensAvg[0].avg, 10))
indexer_multitokens_existential_deposit_total.set(Number(existentialDepositTotal[0].sum))
indexer_multitokens_enj_infused_total.set(Number(enjInfusedTotal[0].sum))
indexer_multitokens_infused_tokens_total.set(Number(infusedTokensTotal[0].sum))
indexer_multitokens_infused_unique_tokens_total.set(Number(infusedUniqueTokensTotal[0].count))
}