feat: CashToken USD pricing and Cauldron DEX swaps - #3
Conversation
Add src/utils/prices.ts (fetchAssetPrices, getUsdPerToken, getBchUsdPrice, tokenAmountToUsd, formatUsd) mirroring paytaca-app's market price handling. Show USD value in `token list` and `token info`, and add a new `token price <category> [amount]` command that prices a given amount (defaults to wallet balance). Unpriced tokens fall back gracefully.
Generic token <-> BCH swap via the Cauldron DEX (mirrors paytaca-app): - fetch active pools + token data from the riften indexer - best-rate trade quoting with attemptTrade (ExchangeLab) - signed trade tx built via createTradeTx and broadcast via watchtower - new 'paytaca swap' command (sell token for BCH / buy token with BCH)
|
Build and tests pass (88 tests, clean stderr). Here is my review: Security & Correctness🟡 Medium:
|
Security & Correctness ReviewBuild & Test Verification
Fix Verification (from previous review)All previously flagged medium/low issues have been addressed:
New / Remaining Findings🟢 Minor: Typo in variable nameFile:
🟢 Minor: Missing "insufficient BCH" guard in
|
Security & Correctness ReviewBuild & Test Verification
Fix Verification (from previous reviews)All previously flagged issues have been addressed:
New Findings🟡 Medium: Missing insufficient tokens guard in
|
Security & Correctness ReviewBuild & Test Verification
Fix Verification (from previous reviews)All previously flagged issues have been addressed and verified in the current code:
New / Remaining Findings🟢 Minor: Defensive check against negative price responsesFile: if (!isFinite(raw) || raw === 0) continueIf the API returns a negative if (!isFinite(raw) || raw <= 0) continuePositive Findings
VerdictApprove. The functional code is solid, well-tested, and all prior security issues have been resolved. The only remaining suggestion is the trivial |




Summary
Adds USD pricing for CashTokens and a Cauldron DEX swap flow to the Paytaca CLI, plus CI/docs/test housekeeping.
Features
CashToken USD pricing
src/utils/prices.ts— client for the Watchtower/api/asset-prices/endpoint (batched, mirrors paytaca-app's market price handling).paytaca token listandpaytaca token infonow show USD values per token and a portfolio total.paytaca token price <category> [amount]command to look up a token's USD price and value an amount (defaults to wallet balance).src/utils/prices.test.ts.Cauldron DEX swap
New
paytaca swap <tokenId> <amount>command to trade CashTokens against BCH through Cauldron liquidity pools.Two directions:
sell(default) — sell tokens for BCHbuy— spend BCH to buy tokensShows a quote (rate, amounts, transfer fee), asks for confirmation, then builds, signs, and broadcasts the trade transaction.
Internals under
src/wallet/cauldron/:api.ts— Cauldron / riften indexer REST client (globalfetch, Node 20+).pools.ts(+ tests) — active-pool discovery and pricing math.swap.ts— swap estimation/execution orchestration.transact.ts— trade transaction construction via@cashlab/cauldronExchangeLab(libauth templates).src/wallet/bch.ts— newgetUtxos()helper for token/UTXO selection.New dependency:
@cashlab/cauldron.Housekeeping
src/nostr/store.test.ts— reset rejected mocks after the "handles errors gracefully" test so receding failures don't leak stderr noise into other tests..github/workflows/opencode.yml— bump opencode GitHub workflow model toopencode/kimi-k2.6.AGENTS.md— added, adapted frompaytaca-appfor this CLI (security review checklist, OS-keychain storage model, CLI conventions).Docs
token priceandswapcommands, architecture summary, and dependencies.Test
npm test— 88 tests pass across 5 files, clean stderr.npm run build(tsc) — clean.