Skip to content

Commit 76166b8

Browse files
committed
feat: add ops.economy.summary bridge action for currency, exchange, tax tracking
1 parent 55a83c5 commit 76166b8

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

console/api/src/duneDb.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,3 +3524,88 @@ export async function addonOpsCombatDeaths(db) {
35243524
function emptyCombatDeaths() {
35253525
return { totalDeaths: 0, pvpDeaths: 0, pveDeaths: 0, deathsByCause: [], deathsByMap: [], topHostileNpcs: [], kdRatio: null };
35263526
}
3527+
3528+
export async function addonOpsEconomySummary(db) {
3529+
let totalCurrencyHolders = 0;
3530+
let totalSupply = 0;
3531+
let currencyBreakdown = [];
3532+
3533+
try {
3534+
const currencyExists = await tableExists(db, "player_virtual_currency_balances");
3535+
if (currencyExists) {
3536+
const result = await db.query(`
3537+
select count(distinct player_controller_id)::int as holders,
3538+
coalesce(sum(balance), 0)::bigint as total_supply
3539+
from dune.player_virtual_currency_balances`);
3540+
const r = result.rows?.[0] || {};
3541+
totalCurrencyHolders = Number(r.holders || 0);
3542+
totalSupply = Number(r.total_supply || 0);
3543+
3544+
const breakdown = await db.query(`
3545+
select currency_id::text as currency_id,
3546+
count(distinct player_controller_id)::int as holders,
3547+
coalesce(sum(balance), 0)::bigint as supply,
3548+
coalesce(round(avg(balance)), 0)::bigint as avg_balance,
3549+
coalesce(min(balance), 0)::bigint as min_balance,
3550+
coalesce(max(balance), 0)::bigint as max_balance
3551+
from dune.player_virtual_currency_balances
3552+
group by currency_id
3553+
order by supply desc`);
3554+
currencyBreakdown = breakdown.rows || [];
3555+
}
3556+
} catch { }
3557+
3558+
let activeOrders = 0;
3559+
let fulfilledOrders = 0;
3560+
let topTradedItems = [];
3561+
3562+
try {
3563+
const ordersExist = await tableExists(db, "dune_exchange_orders");
3564+
const fulfilledExist = await tableExists(db, "dune_exchange_fulfilled_orders");
3565+
if (ordersExist) {
3566+
const ordersResult = await db.query(`select count(*)::int as count from dune.dune_exchange_orders`);
3567+
activeOrders = Number(ordersResult.rows?.[0]?.count || 0);
3568+
3569+
const topResult = await db.query(`
3570+
select coalesce(template_id, 'Unknown') as template_id,
3571+
count(*)::int as orders,
3572+
coalesce(round(avg(item_price)), 0)::bigint as avg_price,
3573+
coalesce(min(item_price), 0)::bigint as min_price,
3574+
coalesce(max(item_price), 0)::bigint as max_price
3575+
from dune.dune_exchange_orders
3576+
group by template_id
3577+
order by orders desc
3578+
limit 20`);
3579+
topTradedItems = topResult.rows || [];
3580+
}
3581+
if (fulfilledExist) {
3582+
const fulfilledResult = await db.query(`select count(*)::int as count from dune.dune_exchange_fulfilled_orders`);
3583+
fulfilledOrders = Number(fulfilledResult.rows?.[0]?.count || 0);
3584+
}
3585+
} catch { }
3586+
3587+
let taxCollected = 0;
3588+
try {
3589+
const taxExists = await tableExists(db, "tax_invoice");
3590+
if (taxExists) {
3591+
const taxResult = await db.query(`
3592+
select coalesce(sum(amount), 0)::bigint as total
3593+
from dune.tax_invoice`);
3594+
taxCollected = Number(taxResult.rows?.[0]?.total || 0);
3595+
}
3596+
} catch { }
3597+
3598+
return {
3599+
totalCurrencyHolders,
3600+
totalSupply,
3601+
activeOrders,
3602+
fulfilledOrders,
3603+
taxCollected,
3604+
currencyBreakdown,
3605+
topTradedItems
3606+
};
3607+
}
3608+
3609+
function emptyEconomySummary() {
3610+
return { totalCurrencyHolders: 0, totalSupply: 0, activeOrders: 0, fulfilledOrders: 0, taxCollected: 0, currencyBreakdown: [], topTradedItems: [] };
3611+
}

console/api/src/server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,12 @@ async function addonBridgeRoute(req, res, path) {
576576
audit(config, req, "addons.bridge", { id: addon.id, action, permission: addon.permission, ok: true });
577577
return json(res, 200, { ok: true, result });
578578
}
579+
if (action === "ops.economy.summary") {
580+
const addon = assertInstalledAddonPermission(config, id, "ops:read");
581+
const result = await duneDb.addonOpsEconomySummary(db);
582+
audit(config, req, "addons.bridge", { id: addon.id, action, permission: addon.permission, ok: true });
583+
return json(res, 200, { ok: true, result });
584+
}
579585
if (action === "database.query" || action === "database.execute") {
580586
const query = String(body.query || "");
581587
const readOnly = isReadOnlySql(query);

0 commit comments

Comments
 (0)