library / Blockchain ideas / BI0059
Multisig approval watcher
Decode multisig proposal accounts directly, read the threshold from the multisig account, and print one row per proposal: its status, how many members approved out of how many are needed, and which members have not voted yet.
Who uses it
A multisig wallet holds a treasury, a vault or a program's upgrade authority behind several keys. A transfer, a configuration change or an upgrade becomes a proposal, and nothing moves until enough members approve it. The state the team cares about is short: which proposals are open, how many approvals each one has, and who has not voted.
A treasury lead uses the list to chase the members whose vote is missing. A DAO operations person gets a view of what is stuck. A hackathon team gets a read-only dashboard that needs no wallet and signs nothing, with a table of proposals and a named list of members still to vote.
The watcher reads Squads v4, a widely used multisig program on Solana. It decodes the accounts the program writes, so the printed counts come from the chain state.
The two accounts and what each holds
Squads v4 keeps the rules and the votes in separate accounts. The multisig account holds the rules: the member list, each member's permissions and the approval threshold. A proposal account holds one decision: its status and the lists of members who approved, rejected or cancelled. Each proposal also records the multisig it belongs to and its transaction index, a counter the multisig raises with every new transaction.
| Account | Bytes | Content |
|---|---|---|
| Proposal | 0 to 7 | Anchor discriminator |
| Proposal | 8 to 39 | address of the multisig it belongs to |
| Proposal | 40 to 47 | transaction index, u64 little-endian |
| Proposal | 48 | status tag: 0 Draft, 1 Active, 2 Rejected, 3 Approved, 4 Executing, 5 Executed, 6 Cancelled |
| Proposal | 49 to 56 | status timestamp, absent for Executing |
| Proposal | after the status | 1 byte bump, then approved, rejected and cancelled, each a u32 count followed by 32-byte keys |
| Multisig | 0 to 7 | Anchor discriminator |
| Multisig | 72 to 73 | approval threshold, u16 little-endian |
| Multisig | 86 to 93 | stale transaction index, u64 little-endian |
| Multisig | 94 onward | rent collector option (1 or 33 bytes), 1 byte bump, then members: a u32 count, each a 32-byte key and one permissions byte |
The permissions byte is a bit mask: 1 to initiate, 2 to vote and 4 to execute. Only members with the vote bit count as voters, so a member who can only initiate is never listed as someone the proposal waits on. The threshold is the number of approvals a proposal needs. A proposal turns Rejected when enough voters reject it that the threshold can no longer be reached, and an approved proposal can carry a time lock that delays execution.
Finding proposals
The program's newest transactions already name the accounts that matter. Creating a proposal and casting a vote both write to the proposal account, so a proposal that moved lately is among the writable accounts of those transactions.
That gives a candidate list with multisig, vault, proposal and fee accounts mixed together. Every account Anchor creates starts with an 8-byte discriminator: the first 8 bytes of the SHA-256 of account: followed by the type name. Hash account:Proposal once with node:crypto, compare it with the first 8 bytes of each candidate, and the proposals are what is left. An account whose owner is another program is dropped before the compare, so a lookalike account is never decoded.
Position in the key list cannot pick the proposal. In a create transaction the multisig account is writable too, because its transaction index goes up, so it sits next to the new proposal and looks like one. The discriminator tells the two apart, and every proposal prints under its own address.
The build
The watcher is one file on @solana/kit and Node 24. It is read-only: no private key, nothing signed or sent. Pass a program id as the first argument to point it at another deployment of the same program.
- Read the 20 newest signatures of the program with getSignaturesForAddress at confirmed and drop the failed ones.
- Call getTransaction for the first 10 with jsonParsed and maxSupportedTransactionVersion: 1. Each call settles on its own, so an error or a null prints a line and the rest carry on.
- Collect the writable account keys, remove the program id, cap the list at 100 and read them in one getMultipleAccounts call with base64 data.
- Keep the accounts the program owns whose first 8 bytes equal the Proposal discriminator, and decode status, approved and rejected.
- Read the distinct multisig accounts in a second getMultipleAccounts call and decode the threshold, the stale index and the voters.
- Print one row per distinct proposal.
// BI0059 · Multisig approval watcher// https://carbium.sh/library/blockchainideas/multisig-approval-watcher// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MITimport { createHash } from "node:crypto";import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder, 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 PROGRAM = process.argv[2] ?? "SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf"; // Squads v4const rpc = createSolanaRpcFromTransport( createDefaultRpcTransport({ url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh", headers: { "x-api-key": key }, }),);const dec = getAddressDecoder();const disc = (name: string) => createHash("sha256").update(`account:${name}`).digest().subarray(0, 8);const PROPOSAL = disc("Proposal");const MULTISIG = disc("Multisig");const STATUS = ["Draft", "Active", "Rejected", "Approved", "Executing", "Executed", "Cancelled"];const why = (e: unknown) => (e instanceof Error ? e.message : String(e));type Parsed = { transaction: { message: { accountKeys: { pubkey: string; writable: boolean }[] } } };const base = { commitment: "confirmed", encoding: "base64" } as const;// Accounts the program owns whose first 8 bytes match an Anchor discriminator.async function owned(keys: Address[], tag: Buffer, what: string): Promise<{ addr: Address; b: Buffer }[]> { try { const res = await rpc.getMultipleAccounts(keys, base).send(); return res.value.flatMap((a, i) => { const b = a && a.owner === PROGRAM ? Buffer.from(a.data[0], "base64") : null; return b && b.subarray(0, 8).equals(tag) ? [{ addr: keys[i], b }] : []; }); } catch (e) { console.log(`${what} read failed: ${why(e)}`); return []; }}// Proposal: discriminator, multisig, u64 index, status tag + i64 timestamp (none for Executing), bump, approved and rejected key lists.function readProposal(b: Buffer) { const tag = b[48]; let p = (tag === 4 ? 49 : 57) + 1; const lists = [0, 1].map(() => { const n = b.readUInt32LE(p); const keys = Array.from({ length: n }, (_, j) => dec.decode(b.subarray(p + 4 + 32 * j, p + 36 + 32 * j)) as string); p += 4 + 32 * n; return keys; }); return { multisig: dec.decode(b.subarray(8, 40)) as string, index: b.readBigUInt64LE(40), status: STATUS[tag] ?? `tag ${tag}`, approved: lists[0], rejected: lists[1] };}// Multisig: discriminator, create key, config authority, u16 threshold, u32 time lock, u64 index, u64 stale index, rent collector option, bump, members.function readMultisig(b: Buffer) { let p = 94; p += (b[p] === 1 ? 33 : 1) + 1; const n = b.readUInt32LE(p); const voters = Array.from({ length: n }, (_, j) => p + 4 + 33 * j) .filter((o) => (b[o + 32] & 2) !== 0) // permission bit 2 is vote .map((o) => dec.decode(b.subarray(o, o + 32)) as string); return { threshold: b.readUInt16LE(72), stale: b.readBigUInt64LE(86), voters };}const sigs = await rpc.getSignaturesForAddress(address(PROGRAM), { limit: 20, commitment: "confirmed" }).send().catch((e) => { console.error("getSignaturesForAddress failed:", why(e)); return process.exit(1);});const picked = sigs.filter((s) => !s.err).slice(0, 10);const cfg = { commitment: "confirmed", encoding: "jsonParsed", maxSupportedTransactionVersion: 1 } as const;const txs = await Promise.allSettled(picked.map((s) => rpc.getTransaction(s.signature, cfg).send()));const writable = new Set<string>();txs.forEach((r, i) => { const sig = picked[i].signature; if (r.status === "rejected") console.log(`getTransaction failed for ${sig}: ${why(r.reason)}`); else if (!r.value) console.log(`getTransaction returned null for ${sig} (below the ledger floor)`); else for (const k of (r.value as unknown as Parsed).transaction.message.accountKeys) if (k.writable) writable.add(k.pubkey);});writable.delete(PROGRAM);const cands = [...writable].slice(0, 100).map((a) => address(a));console.log(`${picked.length} transactions, ${cands.length} writable accounts to check`);const props = (await owned(cands, PROPOSAL, "proposal")).map(({ addr, b }) => ({ addr, ...readProposal(b) }));const ids = [...new Set(props.map((p) => p.multisig))].map((a) => address(a));const ms = new Map((await owned(ids, MULTISIG, "multisig")).map(({ addr, b }) => [addr as string, readMultisig(b)] as const));for (const p of props) { const m = ms.get(p.multisig); if (!m) { console.log(`${p.addr} multisig ${p.multisig} #${p.index} ${p.status} multisig unreadable`); continue; } const status = p.status === "Active" && p.index <= m.stale ? "Stale" : p.status; const waiting = status === "Active" ? m.voters.filter((v) => !p.approved.includes(v) && !p.rejected.includes(v)) : []; const who = waiting.length > 5 ? `${waiting.slice(0, 5).join(" ")} +${waiting.length - 5} more` : waiting.join(" ") || "nobody"; console.log(`${p.addr} multisig ${p.multisig} #${p.index} ${status} ${p.approved.length} of ${m.threshold} approved, ${p.rejected.length} rejected, waiting on ${who}`);}console.log(`${props.length} proposals`);
run: CARBIUM_KEY=<YOUR_KEY> node main.ts [<PROGRAM_ID>]
A row reads like <proposal> multisig <multisig> #42 Active 2 of 3 approved, 0 rejected, waiting on <key>. For an Active proposal the waiting list is every voter whose key sits in neither the approved nor the rejected list. Other statuses print nobody. An Active proposal at or below the multisig's stale index prints Stale. Approved and Executed proposals print under their own status.
getTransaction can answer null for an older signature that the address index still lists, because that index reaches below the ledger floor. The run prints a line for each null, and the newest signatures are the ones it reads. The key list of a jsonParsed transaction carries a writable flag per account, which saves decoding the message header by hand.
What it costs
A run is one getSignaturesForAddress call at 50 cells, up to 10 getTransaction calls at 50 cells each, and two getMultipleAccounts calls at 10 cells per pubkey. Cells are the admission charge per call. With 100 candidates the first account read costs 1000 cells, or 1001 when the request body passes 4 KiB. That is the largest call a key below Pro can send, because the 1024-cell burst caps it there. Pro takes up to 300 pubkeys in a call, and this code never sends more than 100. The multisig read holds a handful of pubkeys.
| Plan | getSignaturesForAddress | getTransaction | getMultipleAccounts |
|---|---|---|---|
| Free | 0.24 req/s | 0.24 req/s | 0.5 req/s |
| Dev | 1.2 req/s | 1.2 req/s | 15 req/s |
| Business | 100 req/s | 5 req/s | 50 req/s |
| Pro | 500 req/s | 25 req/s | 400 req/s |
The three methods sit in separate classes: getSignaturesForAddress in the address-signatures class, getTransaction in the ledger and transaction lookup class, and getMultipleAccounts in the account-read class. Each draws on its own budget. Limits are per account, so other tools on the same keys draw on the same budgets.
The run settles each call and prints what failed, so a 429 on one call leaves the others intact.
Alerting when a count changes
One run is a snapshot. To get a message when a count moves, keep the last rows in node:sqlite, keyed by proposal address with the status, the approved count and the rejected count. A later run differs from the stored row when a vote arrived, when a status moved from Active to Approved, or when a new proposal appeared. Post the changed rows to a chat webhook with fetch.
For a push signal, open a logsSubscribe with mentions set to the multisig address. It costs 25 credits to open, then 20 credits per MiB sent. On each notification, read only the proposal addresses you stored with one getMultipleAccounts call and compare them with the saved rows.
To see what a proposal would do, decode the instructions of the transaction that created it with the Anchor instruction decoder. A token-weighted DAO has no fixed member list, and the Governance proposal tracker reads that model.
Where it ends
- One program. The layouts and discriminators are Squads v4's. Another multisig program has its own, and its accounts fail the owner check and are skipped.
- Discovery covers 20 signatures and reads 10 transactions. A proposal with no vote or creation in them does not appear, however long it has waited. The signature address index keeps up to 30 days, and an empty page past that marks its age limit while the address may have older transactions.
- The rows list keys. The approved list says a key voted. It does not say which transaction carried the vote, and the run does not name who signed any transaction.
- A proposal holds the votes, and what it would do sits in the vault or config transaction account with the same index. The watcher does not read that account.
- Reads run at confirmed, so a vote that lands after the read shows at the next run.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| The run prints 0 proposals although transactions were read. | The 10 newest transactions wrote to no proposal account. The count line shows how many candidates were read. Raise the signature limit and the number of transactions read, or pass another program id. |
| A line says getTransaction returned null for a signature. | The address index lists signatures below the validator's ledger floor, so an older signature can come back null. The run skips it. Prove the code on the newest signatures. |
| A line says the multisig read failed, or a row ends in unreadable. | The second getMultipleAccounts call failed or the multisig account no longer exists. The error text is printed next to the call. Run again after a 429 and check that the account is still owned by the program. |
| getTransaction answers -32015. | The call lacks maxSupportedTransactionVersion. The code sets it to 1 so v1 transactions decode. Keep it on any copy of the call. |
| A call comes back with 429. | The first account read spends nearly the whole 1024-cell burst when it holds 100 candidates. Follow the retry-after hint, or shorten the candidate list in the slice. |
Questions
How do I see pending proposals on a Solana multisig?
A Squads v4 proposal is an account with a status and lists of voters. Decode it and compare its approved list with the threshold on the multisig account. The members absent from the approved and rejected lists are the ones it waits on.
Where is the approval threshold stored?
On the multisig account, as a u16 at bytes 72 and 73. Every proposal of that multisig counts against it.
Does it work for other multisig programs?
Only with new layouts. Change the program id, the discriminator names and the offsets to the other program's account types. The owner check keeps accounts of other programs out.
Why read accounts when the transaction logs show each vote?
A log line shows one vote in one transaction. The proposal account holds every vote cast so far, including votes in transactions the run never read.