library / Use cases / Stablecoin treasury and B2B settlement / UC0146
Stablecoin exposure by issuer
Build a treasury view of stablecoin exposure on Solana: read the supply and mint authority of each token in your list in one call, group them by issuer, and see where the balance sits. A read-only Node script.
A stablecoin is a mint account
On Solana a stablecoin is a token mint. The mint account holds the total supply, the number of decimal places and the mint authority, the key allowed to issue more units. A wallet's balance sits in a separate token account, so the list you start from is a set of mint addresses.
The script reads those accounts with one account read call. Its jsonParsed encoding returns the SPL Token and Token-2022 mint layouts as named fields, so the script needs no byte offsets. These are the fields it uses.
| Field | Read from | Used for |
|---|---|---|
| supply | mint account | units issued, before decimals |
| decimals | mint account | scales raw units into token units |
| mintAuthority | mint account | groups mints into issuers |
The parsed view also carries the freeze authority. The script does not group by it, so a freeze key does not change any line in the output.
Issuer means mint authority
A mint authority is the key that signs new issuance. Mints launched from one authority share it, so grouping by that field gives one line per issuing key, labelled with the authority address and the mints it holds. A mint with no authority has a fixed supply, and the view keeps those in a line of their own.
The label records who can mint on chain. Which company stands behind that key is a separate question the chain does not answer. Map each address to an issuer from the issuer's own published pages before a report leaves your team.
An authority can be a multisig or a program account, so one line may hold mints that different parties manage. Re-check the map at each review, because an issuer can change its authority.
Two mints that share an authority line up under one key even when they are different products. Check the mint list line by line before you read a share as one company's total.
One call for the whole list
The script sends one getMultipleAccounts call with every mint in the list. The method charges 10 cells per pubkey, so three mints cost 30 cells in a single request. Below Pro, the 1024-cell burst caps a call at 100 pubkeys, and the script stops with a message above that. Pro takes up to 300 in one call.
The reply keeps the order of the request. An address that holds no account comes back as null, and the script reports it as a skipped line, so one bad address does not stop the rest of the list.
Account reads are rate-limited by plan: 0.5 req/s on Free, 15 on Dev, 50 on Business and 400 on Pro. Limits are per account, and every key on the account draws from the same budget. One run per schedule tick sits far inside that, even on Free.
The read uses the confirmed commitment, which the script sets in its config. @solana/kit also uses confirmed when a call leaves commitment out, so the choice matches the default and is stated in the code. A supply at confirmed can move with a block that finalizes a moment later, which is fine for a daily view.
Call it from a scheduler, not from a loop. A call over its rate waits once and is served if its cells refill within 1 s. Past that it gets 429 with a retry-after hint, and the script does not retry on its own.
The script
The script takes mint addresses as arguments and falls back to USDC, USDT and PYUSD when none are given. It sends the key in the x-api-key header to https://services.carbium.sh, or to CARBIUM_RPC_URL when that is set. A missing key prints a message and exits.
// UC0146 · Stablecoin exposure by issuer// https://carbium.sh/library/usecase/stablecoin-exposure-by-issuer// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Read-only: reads the mint accounts of a stablecoin list and groups their supply by mint authority.import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } 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 url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";// USDC, USDT and PYUSD mints, used when no arguments are given.const DEFAULT_MINTS = [ "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB", "2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo",];const args = process.argv.slice(2);const mints = args.length ? args : DEFAULT_MINTS;if (mints.length > 100) { console.error("Below Pro, one getMultipleAccounts call takes at most 100 mints."); process.exit(1);}type MintInfo = { supply: string; decimals: number; mintAuthority: string | null };type Parsed = { parsed?: { type: string; info: MintInfo } };const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url, headers: { "x-api-key": key } }),);async function main() { const { value } = await rpc .getMultipleAccounts(mints.map((m) => address(m)), { encoding: "jsonParsed", commitment: "confirmed" }) .send(); const groups = new Map<string, { units: number; mints: string[] }>(); value.forEach((account, i) => { const info = (account?.data as unknown as Parsed | undefined)?.parsed?.info; if (!info) { console.log(`${mints[i]}: not a readable token mint, skipped`); return; } const issuer = info.mintAuthority ?? "fixed supply (no mint authority)"; const g = groups.get(issuer) ?? { units: 0, mints: [] }; g.units += Number(info.supply) / 10 ** info.decimals; g.mints.push(mints[i]); groups.set(issuer, g); }); const total = [...groups.values()].reduce((n, g) => n + g.units, 0); console.log(`read at confirmed: ${mints.length} mints, ${total.toFixed(0)} token units counted`); for (const [issuer, g] of [...groups].sort((a, b) => b[1].units - a[1].units)) { const share = total ? (g.units / total) * 100 : 0; console.log(`${share.toFixed(2)}% ${g.units.toFixed(0)} units authority ${issuer} mints ${g.mints.join(", ")}`); }}main().catch((e: unknown) => { console.error("read failed:", e instanceof Error ? e.message : e); process.exit(1);});
run: CARBIUM_KEY=$CARBIUM_KEY node main.ts EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB 2b1kV6DkPAnxd5ixfnxCpjxmKwqjjaYmCZfHsFu24GXo
Each output line is one authority, sorted by share. The shares sum to 100% over the mints that could be read. The sum counts tokens, so it reads as dollars only while each token holds its peg. Use the shares to see concentration by issuer, and check the pegs separately.
The total is printed to the nearest unit and each share to two decimal places. A run where no mint can be read prints a zero total, and its shares print as zero instead of dividing by it.
Where it ends
- Supply is the amount issued on chain. It says nothing about the assets behind a stablecoin, which sit off chain, so the view cannot show backing.
- The totals add token units in floating point. For an accounting figure, sum the raw integers with BigInt for each mint and convert once.
- Only the mints in your list are read. A new stablecoin appears in the view once someone adds its mint address.
- Wallet balances are a different read. This script does not sum holdings across wallets; see wallet token holdings for that.
- An authority can be set to none later, so a mint can move from its issuer's line to the fixed-supply line between runs.
- The script reads the chain at one moment. To see change over time, store each run and compare the runs.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The run prints UNKNOWN_KEY and exits. | Carbium refuses an unknown key with 401 at the door. Set CARBIUM_KEY to the whole key, from the account it belongs to, and send it in the x-api-key header. |
| A mint line reads 'not a readable token mint, skipped'. | The address is wrong, the account is closed, or it holds no token mint. Check it on a block explorer and remove it from the list. |
| Runs start failing with 429 after a loop was added. | A call over its rate waits once, and past 1 s it gets 429 with a retry-after hint. Wait for that long before the next run, and schedule runs instead of looping. |
| The totals look far off after a mint is added. | Each supply is divided by its own power of ten before the sum. If a total is far off, look for a copy of the code that sums raw supplies. |
Questions
Is the list the same as the stablecoins my wallets hold?
No. The list holds mint addresses you choose to watch. A wallet's holdings are token accounts, which wallet token holdings reads.
Who issued each stablecoin in the list?
The chain shows the mint authority, which is the key that can issue. Map that key to an issuer from the issuer's own published pages, because the chain does not name the company.
Does this show the reserves behind each token?
It does not. The read covers supply and authority on chain, and reserves are held off chain. Use the issuer's own attestation for reserves.
Can I run it every minute?
Every minute is more than a daily treasury view needs. Free allows 0.5 account reads per second, so a schedule with a few minutes between runs stays inside the limit.