5.4 KiB
5.4 KiB
Tasks: enterprise-cryptocurrency
Change ID: enterprise-cryptocurrency
Package: @suaveplan/cryptocurrency
Target path: finance/crypto/cryptocurrency
Prerequisites on Verdaccio: zod, tslib
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Scaffold
- Create full directory tree per
proposal.md. package.jsonat0.1.0,"sideEffects": false, exports"."+ per-feature subpaths +"./chains/testnet-data".- Deps:
zod catalog:forms,tslib catalog:build. No workspace runtime deps. - DevDeps:
vitest catalog:testing,@vitest/coverage-istanbul catalog:testing,fast-check catalog:testing,mitata catalog:testing,@suaveplan/testing workspace:^. tsconfig.jsonextendinglibrary.json;vitest.config.tswithcreateTestConfig().- Scripts:
lint,typecheck,test,test:coverage,build,bench,docs:check.
2. Error hierarchy
- Implement
CryptoError,UnknownChainError,InvalidAddressError,InvalidTxHashError,UnsupportedUnitErrorinsrc/errors/crypto-error/crypto-error.ts. - Mirror
@suaveplan/errorshape (.code,.message,.cause) without importing it. - Write
crypto-error.test.ts: instanceof chain, code discrimination.
3. Address validator
- Implement
validateAddressandvalidateAddressForChaininsrc/address/validator/validator.ts:- EVM: EIP-55 checksum; hex + 0x prefix + 40 chars.
- Bitcoin: Base58Check (P2PKH/P2SH) + Bech32 (P2WPKH/P2WSH) + Bech32m (P2TR).
- Solana: Base58, 32–44 chars.
- Cardano: Bech32
addr1prefix. - Others: per-chain regex patterns from
CHAINSdata. - Auto-detect chain when not specified.
- Write
validator.test.ts(≤500 lines): valid + invalid per chain; EIP-55 case sensitivity; auto-detect.
4. Chain data + testnet data
- Implement
src/chains/chain-data/chain-data.tswith 15+ mainnet chain entries. - Implement
src/chains/testnet-data/testnet-data.tswith Sepolia, Holesky, Base Sepolia, Arbitrum Sepolia, OP Sepolia. src/chains/chain-registry/chain-registry.ts:MemoryChainRegistrywith add/remove/list.src/chains/registry/registry.ts: pure getter helpers using global registry.- Write tests for all chain registry operations.
5. Gas estimators
- Implement EIP-1559 helpers in
src/gas/gas-estimator/gas-estimator.ts. - Implement EIP-4844 blob-gas helpers in
src/gas/blob-gas-estimator/blob-gas-estimator.ts:calculateBlobGasPrice(excessBlobGas):MIN_BLOB_GWEI_PER_GAS * e^(excessBlobGas / BLOB_GAS_UPDATE_FRACTION).estimateBlobTxCost(params): include blob-fee component.
- Write tests against known EIP-4844 spec test vectors.
6. Tokens
src/tokens/token-data/token-data.ts: common ERC-20 + native tokens.src/tokens/token-registry/token-registry.ts:TokenRegistrywith get/register/list.formatTokenBalancewith locale option.- Write tests.
7. Transaction decode
- Implement ABI-aware
decodeCalldatainsrc/transaction/tx-decoder/tx-decoder.ts:- Accept
FunctionSignaturewith typed parameters; decode fixed types (uint, int, bool, address, bytes, bytesN) and dynamic types (string, bytes, array). - Keep
decodeTxHash/extractSelector/lookupSelector/KNOWN_SELECTORSfrom main.
- Accept
src/transaction/selector-resolver/selector-resolver.ts:SelectorResolverinterface with injectable async lookup.- Write
tx-decoder.test.ts: each ABI type decoded correctly against known calldata fixtures.
8. Unit converter
- Implement all unit helpers in
src/units/converter/converter.ts. - Ensure no float-precision loss for large values; use BigInt throughout for integer types.
- Write
converter.test.ts.
9. Property-based + benchmarks
tests/property.test.ts(fast-check,{ timeout: 30000 }):etherToWei/weiToEtherround-trip for arbitrary ether values (string decimal).bitcoinToSatoshi/satoshiToBitcoinround-trip.validateAddress(addr).chainis consistent withvalidateAddressForChain(addr, detected).- EIP-55 checksum is idempotent.
src/__benchmarks__/hot-paths.bench.ts: EIP-55 checksum throughput, bech32 decode, address validation throughput.
10. Docs + verify + publish
- All
.mdfiles per layout; rootREADME.mdwith chain table, quick-start validation + unit conversion + ABI decode, API table. bunx turbo lint --filter=@suaveplan/cryptocurrency— zero errors.bunx turbo typecheck --filter=@suaveplan/cryptocurrency— zero errors.bunx turbo test --filter=@suaveplan/cryptocurrency— all pass.bunx turbo test:coverage --filter=@suaveplan/cryptocurrency— 100%.bun scripts/publish.ts --package @suaveplan/cryptocurrency.- Update
CLAUDE.md; archive toopenspec/archive/2026-04-24-enterprise-cryptocurrency/.