Skip to content

Commit

Permalink
fix: holders
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Apr 23, 2024
1 parent 13f95d5 commit 0e40d32
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/pg/brc20/brc20-pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,16 @@ export class Brc20PgStore extends BasePgStoreModule {
): Promise<DbPaginatedResult<DbBrc20Holder> | undefined> {
return await this.sqlTransaction(async sql => {
const token = await sql<{ id: string; decimals: number }[]>`
SELECT id, decimals FROM brc20_deploys WHERE ticker_lower = LOWER(${args.ticker})
SELECT ticker FROM brc20_tokens WHERE ticker = LOWER(${args.ticker})
`;
if (token.count === 0) return;
const results = await sql<(DbBrc20Holder & { total: number })[]>`
SELECT
address, ${token[0].decimals}::int AS decimals, total_balance, COUNT(*) OVER() AS total
FROM brc20_total_balances
WHERE brc20_deploy_id = ${token[0].id}
ORDER BY total_balance DESC
b.address, d.decimals, b.total_balance, COUNT(*) OVER() AS total
FROM brc20_total_balances AS b
INNER JOIN brc20_tokens AS d USING (ticker)
WHERE b.ticker = LOWER(${args.ticker})
ORDER BY b.total_balance DESC
LIMIT ${args.limit}
OFFSET ${args.offset}
`;
Expand Down

0 comments on commit 0e40d32

Please sign in to comment.