library / Blockchain ideas / BI0010
DAO treasury dashboard
One getMultipleAccounts call, one getSignaturesForAddress call and one logsSubscribe on Carbium give you a live board of a DAO's SOL, token balances and recent transactions, with the cost per plan, the limits and a runnable main.ts.
Who uses it
A DAO treasury is a public address, so anyone can audit it, but few members do. The questions arrive in chat: how much SOL is left, which stablecoin do we hold, did last week's payment go out. This board answers them on one screen and refreshes itself after SOL moves and outgoing spends.
Contributors check the balance before they vote on a spend. A treasury working group watches inflows and outflows and wants a failed transaction to stand out. A grant committee takes a signature from a payee and confirms it landed.
A hackathon team can point the same code at any DAO, because everything it reads is public. Give it the address that holds the funds. For a multisig, give the vault address; the configuration account holds no funds.
What it shows
| Panel | Where it comes from | Example |
|---|---|---|
| SOL balance | lamports of the treasury account in the getMultipleAccounts reply | 1,204.5 SOL |
| Token balances | the token account at the treasury's associated token address for each mint you list, or the token account you name next to the mint, parsed by the RPC | USDC 250000 |
| Recent transactions | getSignaturesForAddress, the five newest, with the error field | ok or FAILED, then the signature |
| Live activity | a logsNotification from logsSubscribe on the treasury address | a line per transaction that touches the treasury |
One call reads the wallet and every token account together, so all the figures on a refresh come from the same slot. A mint with no token account prints no token account, which is a normal state for a DAO that never held that token.
The build
The board is one file that needs @solana/kit and what Node 24 ships. It is read-only: no private key, nothing signed or sent.
- Take the treasury address and the mints from the command line. With no mints it watches USDC. An argument written MINT:TOKEN_ACCOUNT reads that token account instead of the derived one.
- Derive each mint's associated token address for the treasury with getProgramDerivedAddress. This is local arithmetic and makes no call.
- Create the RPC client once, against https://services.carbium.sh with the key in x-api-key, and reuse it.
- Call getMultipleAccounts at confirmed commitment with the treasury and the token addresses at encoding jsonParsed, then print the SOL line and one line per mint. If the call fails, print why and mark the board dirty.
- Call getSignaturesForAddress for the five newest signatures and mark each ok or FAILED. If it fails, print why and carry on.
- Open one WebSocket to wss://services.carbium.sh with the key as ?api-key= and send logsSubscribe with { mentions: [treasury] }. Print each notification and mark the board dirty.
- Every 10 seconds, if the board is dirty, read the balances again. A failed refresh, such as a 429, leaves it dirty and the next tick retries.
// BI0010 · DAO treasury dashboard// https://carbium.sh/library/blockchainideas/dao-treasury-dashboard// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressEncoder, getProgramDerivedAddress, type Address } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }const [treasuryArg, ...mintArgs] = process.argv.slice(2);if (!treasuryArg) { console.error("Usage: node main.ts <treasury address> [mint[:token account] ...]"); process.exit(1); }const treasury = address(treasuryArg);// USDC when no mint is given. MINT:TOKEN_ACCOUNT reads a token account that is not the associated one.const holdings = (mintArgs.length ? mintArgs : ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"]).map((a) => { const [mint = "", account] = a.split(":"); return { mint: address(mint), account: account ? address(account) : undefined };});const TOKEN_PROGRAM = address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");const ATA_PROGRAM = address("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");const enc = getAddressEncoder();const WS_URL = `${process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh"}/?api-key=${key}`;const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key },}));type TokenData = { parsed?: { info?: { tokenAmount?: { uiAmountString?: string } } } };const why = (e: unknown): string => (e instanceof Error ? e.message : String(e));async function main(): Promise<void> { // The token account for each mint: the one you named, else the associated address (local arithmetic, no call). const vaults: Address[] = await Promise.all(holdings.map(async ({ mint, account }) => account ?? (await getProgramDerivedAddress({ programAddress: ATA_PROGRAM, seeds: [enc.encode(treasury), enc.encode(TOKEN_PROGRAM), enc.encode(mint)], }))[0])); async function snapshot(): Promise<void> { // One call, one slot: the wallet and every token account together. const { value } = await rpc .getMultipleAccounts([treasury, ...vaults], { encoding: "jsonParsed", commitment: "confirmed" }) .send(); console.log(`--- ${new Date().toISOString()} treasury ${treasury}`); console.log(`SOL ${value[0] ? Number(value[0].lamports) / 1e9 : 0}`); holdings.forEach(({ mint }, i) => { const data = value[i + 1]?.data as unknown as TokenData | undefined; console.log(`${mint.slice(0, 8)} ${data?.parsed?.info?.tokenAmount?.uiAmountString ?? "no token account"}`); }); } // A failed snapshot is printed and leaves the board dirty, so the next tick retries it. let dirty = false; const refresh = (): Promise<void> => snapshot().catch((e) => { dirty = true; console.error("snapshot failed:", why(e)); }); await refresh(); try { const sigs = await rpc.getSignaturesForAddress(treasury, { limit: 5, commitment: "confirmed" }).send(); for (const s of sigs) console.log(`${s.err ? "FAILED" : "ok"} ${s.signature} slot ${s.slot}`); } catch (e) { console.error("signature list failed:", why(e)); } const connect = (): void => { const ws = new WebSocket(WS_URL); // Every open marks the board dirty: a change made while the socket was down is read on the next tick. ws.onopen = () => { dirty = true; ws.send(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "logsSubscribe", params: [{ mentions: [treasury] }, { commitment: "confirmed" }] })); }; ws.onmessage = (ev) => { const msg = JSON.parse(String(ev.data)); if (msg.id === 1) { console.log(msg.error ? `subscribe refused: ${msg.error.message}` : `watching, subscription ${msg.result}`); return; } if (msg.method !== "logsNotification") return; const { signature, err } = msg.params.result.value; console.log(`${err ? "FAILED" : "ok"} ${signature}`); dirty = true; }; ws.onclose = () => setTimeout(connect, 2000); ws.onerror = () => ws.close(); }; connect(); // A burst of notifications costs one refresh; a failed refresh stays dirty and retries. setInterval(() => { if (dirty) { dirty = false; void refresh(); } }, 10_000);}main().catch((e) => { console.error(why(e)); process.exit(1); });
run: CARBIUM_KEY=<YOUR_KEY> node main.ts <TREASURY_ADDRESS> [MINT_ADDRESS[:TOKEN_ACCOUNT] ...]
A burst of notifications costs one refresh. Each start-up call has its own try, so a failed one never stops the socket from opening. The close handler reconnects and subscribes again, and every open marks the board dirty, so a balance change made while the socket was down is read on the next tick.
What it costs
getMultipleAccounts charges 10 cells per pubkey and takes up to 300 pubkeys, but the 1024-cell burst caps a call at 100 pubkeys below Pro. A call for the treasury and two mints has three pubkeys, so 30 cells. A treasury with 30 mints has 31 pubkeys and costs 310 cells per refresh. getSignaturesForAddress costs 50 cells and runs once at start. Cells are the admission charge per call, and each plan has its own limit per call class in requests per second. Credits meter RPC and WebSocket work alike.
The subscription is billed in credits: a logs-mentions subscription opens at 25 credits, then costs 20 credits per MiB sent. Assume 2 KiB per notification and a treasury that appears in 100 transactions an hour. That is about 0.2 MiB an hour, or about 4 credits, and about 2,800 credits over a 720-hour month, plus 25 each time the socket opens.
The refreshes add to the monthly draw. A refresh follows a notification and runs at most once per 10 seconds, so 100 transactions an hour means at most 100 refreshes an hour, 72,000 over a 720-hour month. At 30 cells each that is about 2.16M cells, plus 50 cells for the start-up signature call and 30 for each socket open. Cells do not convert to credits, so on a new key read the credit balance after a few hours of running and scale it up.
| Plan | Credits | Account reads, req/s | getSignaturesForAddress, req/s | Subscription share at 100 transactions/hour |
|---|---|---|---|---|
| Free ($0) | 500K once, at sign-up | 0.5 | 0.24 | about 0.56% of the grant, per month |
| Dev ($20) | 10M per month | 15 | 1.2 | about 0.03% of the month |
| Business ($250) | 50M per month | 50 | 100 | about 0.006% of the month |
| Pro ($500) | 200M per month | 400 | 500 | about 0.001% of the month |
One refresh every 10 seconds weighs 3 cells a second, 0.3 account reads a second, under the 0.5 req/s of Free and the 15 of Dev. A refresh only follows a notification, so a quiet treasury draws far less, but a busy one on Free can meet 429s, and the board stays dirty and retries on the next tick. Limits are per account, so other tools on the same keys share the budget. Free carries 5 sockets and the board uses one.
What to add next
- A web page: serve the latest snapshot and the activity rows from a small HTTP server and push changes to the browser with server-sent events.
- USD values: the prices method answers on the same endpoint. The quote plane has its own plans, and a key needs the QUOTE scope.
- A spend alert: when a notification arrives, read that transaction with getTransaction (50 cells) and post to a channel if the amount passes a threshold.
- A weekly tally: page through getSignaturesForAddress and count ok and FAILED per week, within the 30-day index.
- Token-2022 mints: derive their associated addresses with that program's id in the seeds instead of the classic Token program's.
Where it ends
- You supply the mints. Listing every token account an owner holds is not part of this build.
- The code derives associated token addresses for the classic Token program. A token held at another address, or a Token-2022 mint, shows no token account until you pass its token account as MINT:TOKEN_ACCOUNT.
- The board reads the treasury's own accounts. Funds inside other programs, such as a lending position, a liquidity pool or a locked vesting account, do not appear as token balances.
- A plain SOL wallet stays silent on accountSubscribe, so the board uses logsSubscribe with a mention and then re-reads the balance. Only transactions that landed produce a notification.
- A token deposit into the treasury's existing token account names only the token accounts and the sender's authority, never the treasury. It sends no notification, so the new token balance shows on the next refresh that another notification triggers.
- A mention matches any transaction that touches the address, so a stranger's dust transfer shows in the feed and moves the balance by a few lamports.
- Recent activity reaches 30 days back at most, the extent of Carbium's address index. An empty page past that is the index's age limit and says nothing about the treasury's first transaction.
- The board shows no proposals or votes. Governance state sits in program accounts that you would decode yourself.
- main.ts prints no USD values.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The subscribe reply is an error, or the socket closes straight away. | Check CARBIUM_KEY and that the account is under its socket cap (Free carries 5). A refused subscription is free, so a retry costs nothing. |
| getMultipleAccounts answers 429. | Respect the retry-after hint. The board prints snapshot failed, marks itself dirty and retries on its next tick, and at start it still opens the socket. A failed signature list at start is not retried, so restart for it. If it repeats, lengthen the 10-second gap or trim the mint list, since each pubkey costs 10 cells and the account's keys share one limit. |
| A token the DAO holds prints no token account. | It sits at a non-associated address or under Token-2022. Find the token account in an explorer and pass it on the command line as MINT:TOKEN_ACCOUNT. |
| The program exits at start with an address error. | An argument is not a valid base58 address. Copy the treasury, mint and token account addresses again, with no spaces or quotes inside. |
| The signature list is empty for an old treasury. | The list covers the last 30 days. Check an explorer for anything older. |
| The feed prints a transaction but the balance has not moved. | The refresh runs on the next 10-second tick. Wait one tick, or shorten the gap if your plan's rate allows it. |
Questions
Does it work for a multisig treasury?
Yes. A multisig keeps its funds in a vault address, so pass that address as the treasury. The board reads public accounts only, so no member key is involved.
Do I need my own node?
No. The balances, the signature list and the live feed all come from services.carbium.sh with one key, over the HTTPS endpoint and the WebSocket.
Why logsSubscribe and not accountSubscribe?
accountSubscribe stays silent for a plain SOL wallet, which is what many treasuries are. logsSubscribe with a mention fires on every transaction that touches the address, and a re-read gives the new balance.
Can it show USD values?
Not in main.ts. The prices method answers on the same endpoint and needs a key with the QUOTE scope, so you can add a column for it.
Will it run on the Free plan?
The subscription fits: it uses about 2,800 credits a month at 100 transactions an hour against a one-time grant of 500K. A 30-cell refresh every 10 seconds weighs 0.3 account reads a second, under Free's 0.5 req/s, and a longer mint list needs a wider gap. Run it and read the credit balance.