deviant/scripts/chipnet-lib-balances.mjs
walerikus 599202a721 chore: checkpoint working tree — shell Tier-B retirement + accumulated WIP
Snapshot of accumulated work-in-progress on top of the baseline commit.

This session — retire Tier B from the wallet shell (single-tier model, glossary
"Tiers & trust"):
- SendFlow.tsx: BCH-only; removed the non-functional Tier-B send path, the D-4/D-5
  raw-BCH co-display, and the ADR-0013 friction ladder.
- ArtemisionScreen.tsx: Create wizard collapsed to a single 5-step on-chain genesis
  flow; tier-selection step + Tier-B branch (prepareTierBImport) deleted.
- QuickActions.tsx / SettingsScreen.tsx: receive note reworded; "Send friction
  thresholds" + "Tier explainer" rows removed; registry-trust note reworded.
- Verified: tsc clean, vitest 74/74, full preview walkthrough, no console errors.

Pre-existing uncommitted work also folded in:
- USDm -> FIATm family rename/reorg (Parameters/FIATm/, design records)
- ~130 chipnet + sim-fiatm scripts (catalytic-converter, hyperinflation backtests)
- snapshots 0153-0168; wiki updates (glossary, decisions, index); ADR-0044/0045
- mockups + additional shell screens (Agora, Apps, MainScreen, AssetDetail, ...)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 01:01:37 +02:00

93 lines
3 KiB
JavaScript

#!/usr/bin/env node
/**
* chipnet-lib-balances.mjs — balance check via the DeviantWallet library.
*
* The library counterpart to chipnet-balances.mjs. Instead of inlining the
* UTXO classification + aggregation, it loads the known token files into a
* registry and asks `DeviantWallet.getBalance()` for the presentation-ready
* DisplayBalance — exercising the full registry → classify → display path
* the production wallet uses.
*
* Run: node --import tsx scripts/chipnet-lib-balances.mjs
*
* Env: WALLET=a|b|c (default a)
*/
import { readFileSync, existsSync } from 'node:fs';
import { join } from 'node:path';
import { TestNetWallet } from 'mainnet-js';
import { InMemoryTokenRegistry } from '../src/token/registry.js';
import { connectWallet, tokenFileToTierA } from '../src/wallet/runtime.js';
const ROOT = join(import.meta.dirname, '..');
const WALLET = (process.env.WALLET ?? 'a').toLowerCase();
const KEYS = {
a: join(ROOT, '.chipnet-keys.json'),
b: join(ROOT, '.chipnet-keys-b.json'),
c: join(ROOT, '.chipnet-keys-c.json'),
};
if (!KEYS[WALLET]) throw new Error('WALLET must be a/b/c');
const TOKEN_FILES = ['ChipnetTests/.chipnet-asm-token.json', 'ChipnetTests/.chipnet-asm2-token.json'].map((f) =>
join(ROOT, f),
);
function divider() {
console.log('='.repeat(72));
}
async function main() {
const registry = new InMemoryTokenRegistry();
for (const path of TOKEN_FILES) {
if (existsSync(path)) {
registry.add(tokenFileToTierA(JSON.parse(readFileSync(path, 'utf8'))));
}
}
const { wif } = JSON.parse(readFileSync(KEYS[WALLET], 'utf8'));
const w = await TestNetWallet.fromWIF(wif);
const wallet = connectWallet({
registry,
network: 'chipnet',
privateKey: w.privateKey,
cashaddr: w.cashaddr,
tokenAddress: w.tokenaddr,
});
const balance = await wallet.getBalance();
divider();
console.log(`Wallet ${WALLET.toUpperCase()} — ${w.cashaddr}`);
divider();
console.log(` Plain BCH: ${balance.bchSats} sats (${Number(balance.bchSats) / 1e8} BCH)`);
console.log('');
for (const t of balance.tokens) {
if (t.kind === 'tier_a') {
console.log(
` [A] ${t.token.ticker} ${t.unitsRedeemable} redeemable` +
(t.unitsUnderbacked > 0n ? ` (+${t.unitsUnderbacked} underbacked)` : '') +
` [${t.verification}] ${t.assetClassLabel}`,
);
} else if (t.kind === 'tier_b') {
console.log(
` [B] ${t.token.ticker} ${t.unitsTotal} units / ${t.satsAssociated} sats (${t.authority})`,
);
} else {
console.log(` [T] ${t.token.ticker} ${t.unitsTotal} units / ${t.satsTotal} sats ${t.assetClassLabel}`);
}
}
if (balance.unknownTokens.length > 0) {
console.log('');
for (const u of balance.unknownTokens) {
console.log(` [?] ${u.category.slice(0, 16)}... FT ${u.ftAmount}, ${u.satoshis} sats`);
}
}
divider();
}
main().catch((err) => {
console.error('FAILED:', err?.message ?? err);
if (err?.stack) console.error(err.stack);
process.exit(1);
});