Skip to content

Commit 4fb9e20

Browse files
committed
docs: refresh codebase docs for post-phase-1 state
- Update all SmartTransaction/CapacityManager references to note deletion in Phase 1 (ARCHITECTURE, CONCERNS, CONVENTIONS) - Update fork-scripts paths from ccc-fork/*.sh to fork-scripts/*.sh (PROJECT, CONCERNS, CONVENTIONS, STACK, STRUCTURE) - Add fork-scripts/ directory tree and @generated markers (STRUCTURE) - Mark resolved concerns as RESOLVED (CONCERNS) - Update code examples to current APIs: findUdts, isUdt, collect (CONVENTIONS) - Update 64-output DAO limit references to CCC core (CONCERNS)
1 parent 3694442 commit 4fb9e20

6 files changed

Lines changed: 146 additions & 137 deletions

File tree

.planning/PROJECT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Clean, CCC-aligned library packages published to npm that frontends can depend o
5656

5757
**Migration status:** Library packages are on CCC. Apps split: faucet/sampler already migrated; bot/interface/tester still on legacy Lumos (`@ckb-lumos/*`, `@ickb/lumos-utils@1.4.2`, `@ickb/v1-core@1.4.2`).
5858

59-
**Local CCC dev build:** `ccc-dev/` supports using local CCC builds for testing. `.pnpmfile.cjs` transparently rewires `@ckb-ccc/*` to local packages. `ccc-dev/patch.sh` rewrites exports to `.ts` source. This enables testing upstream changes before they're published.
59+
**Local CCC dev build:** `ccc-fork/` supports using local CCC builds for testing. `.pnpmfile.cjs` transparently rewires `@ckb-ccc/*` to local packages. `fork-scripts/patch.sh` rewrites exports to `.ts` source. This enables testing upstream changes before they're published.
6060

6161
## Constraints
6262

.planning/codebase/ARCHITECTURE.md

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- Manager-based pattern encapsulating script operations with uniform `ScriptDeps` interface
1212
- Async-first cell discovery via generator functions with lazy evaluation
1313
- TypeScript ESM modules with strict null checks and type safety
14-
- SmartTransaction builder for automatic fee/change calculation
14+
- CCC-native transaction building with TransactionLike pattern (SmartTransaction deleted in Phase 1)
1515
- Cell wrapper abstractions extending raw blockchain data with domain logic
1616

1717
**Migration Status:**
@@ -21,7 +21,7 @@
2121
- Apps split: `faucet` and `sampler` already use new packages; `bot`, `tester`, `interface` still on legacy Lumos
2222
- CCC PRs for UDT and Epoch support have been MERGED upstream -- local Epoch class has been deleted (replaced by `ccc.Epoch`); some local UDT handling may still overlap with CCC's `@ckb-ccc/udt`
2323
- Custom `mol.union` codec and deprecated `mol.*` APIs have been replaced with CCC's `mol.union`, `ccc.Entity.Base`, and `@ccc.codec` decorator
24-
- SmartTransaction was ABANDONED as an ecosystem-wide concept (no adoption), but the class itself remains used locally; headers are now cached in CCC Client Cache
24+
- SmartTransaction was DELETED in Phase 1; all managers now accept `ccc.TransactionLike` and return `ccc.Transaction` directly; headers cached by CCC Client Cache
2525

2626
## Protocol Design (from whitepaper)
2727

@@ -70,21 +70,22 @@ Receipts convert to UDT; deposits stay as deposits or convert to UDT. No iCKB ca
7070

7171
**Foundation: CCC Framework**
7272
- Purpose: Provide blockchain primitives and client interface
73-
- Location: `@ckb-ccc/core` (npm or local `ccc-dev/ccc/`)
73+
- Location: `@ckb-ccc/core` (npm or local `ccc-fork/ccc/`)
7474
- Contains: CKB RPC clients, transaction builders, signers, Molecule codec, UDT support, Epoch handling
7575
- Used by: All packages and applications
7676
- Note: CCC now includes UDT and Epoch features contributed by this project's maintainer
7777

7878
**Utilities Layer (`packages/utils/src/`)**
79-
- Purpose: Reusable blockchain primitives and transaction helpers
80-
- Key exports: `SmartTransaction`, `CapacityManager`, codec/heap utilities, UDT handlers
79+
- Purpose: Reusable blockchain primitives and UDT handlers
80+
- Key exports: `UdtManager`, `UdtHandler`, codec/heap utilities
8181
- Key files:
82-
- `transaction.ts` (517 lines): SmartTransaction builder with fee completion and UDT balancing
83-
- `capacity.ts` (221 lines): CapacityManager for cell discovery and collection
84-
- `udt.ts` (393 lines): UDT token value calculations and handlers
85-
- `utils.ts` (458 lines): General utilities (binary search, collectors, script helpers)
82+
- `udt.ts` (407 lines): UDT token value calculations and handlers
83+
- `utils.ts` (292 lines): General utilities (binary search, collectors, helpers)
84+
- `codec.ts` (21 lines): CheckedInt32LE codec
85+
- `heap.ts` (175 lines): MinHeap implementation
8686
- Depends on: `@ckb-ccc/core`
8787
- Used by: All domain packages
88+
- Note: `SmartTransaction`, `CapacityManager`, `transaction.ts`, `capacity.ts` were deleted in Phase 1
8889

8990
**Domain Layer - DAO (`packages/dao/src/`)**
9091
- Purpose: Abstract Nervos DAO operations (deposit, withdraw, requestWithdrawal)
@@ -154,7 +155,7 @@ Receipts convert to UDT; deposits stay as deposits or convert to UDT. No iCKB ca
154155
- Location: `apps/faucet/src/main.ts` (88 lines), entry via `apps/faucet/src/index.ts`
155156
- Entry: `main()` async function
156157
- Pattern: Infinite loop with 2-minute poll interval
157-
- Uses: CCC client, CapacityManager, SmartTransaction
158+
- Uses: CCC client, ccc.Transaction
158159
- Flow: Discover faucet funds → transfer to user account → log JSON results
159160

160161
**Sampler (Migrated to CCC):**
@@ -198,7 +199,7 @@ Receipts convert to UDT; deposits stay as deposits or convert to UDT. No iCKB ca
198199

199200
1. User calls `IckbSdk.request(tx, user, info, amounts)` via app
200201
2. `OrderManager.mint()` creates order cell with `Info` metadata (ratio, direction, fee info)
201-
3. `SmartTransaction` adds cell deps, outputs, UDT handlers
202+
3. Transaction adds cell deps, outputs via `tx.addCellDeps()` / `tx.addOutput()`
202203
4. User signs and broadcasts transaction
203204

204205
**Order Discovery and Matching (Bot Flow):**
@@ -213,7 +214,7 @@ Receipts convert to UDT; deposits stay as deposits or convert to UDT. No iCKB ca
213214
8. Bot identifies orders where CKB/UDT supply exists for matching
214215
9. Calls `OrderManager.satisfy()` to process matched orders
215216
10. Builds transaction with satisfied order cells and input/output witnesses
216-
11. Completes fees via `SmartTransaction.completeFeeChangeToLock()`
217+
11. Completes fees via `tx.completeFeeChangeToLock()`
217218
12. Signs and broadcasts
218219

219220
**Maturity Estimation (Supporting Calculation):**
@@ -241,13 +242,13 @@ Receipts convert to UDT; deposits stay as deposits or convert to UDT. No iCKB ca
241242
2. Receipt cell minted containing deposit metadata
242243
3. Bot fetches deposits via `LogicManager.findDeposits()`
243244
4. After maturity, bot calls `LogicManager.withdraw()` to extract funds
244-
5. Change cells automatically added by SmartTransaction
245+
5. Change cells added via CCC fee completion pipeline
245246

246247
**State Management:**
247248

248249
- L1 state: Immutable snapshots fetched per query with configurable refresh intervals
249-
- Transaction state: Built incrementally via `SmartTransaction.add*` methods
250-
- UDT balances: Tracked per UDT handler in `SmartTransaction.udtHandlers` map
250+
- Transaction state: Built incrementally via `ccc.Transaction` methods (`addInput`, `addOutput`, `addCellDeps`)
251+
- UDT balances: Tracked via `UdtHandler` interface implementations
251252
- Maturing CKB: Cumulative array sorted by maturity timestamp
252253

253254
## Key Abstractions
@@ -260,7 +261,7 @@ Receipts convert to UDT; deposits stay as deposits or convert to UDT. No iCKB ca
260261

261262
**Manager Classes (Pattern):**
262263
- Purpose: Encapsulate entity-specific operations
263-
- Pattern: Stateless managers with methods that operate on SmartTransaction
264+
- Pattern: Stateless managers with methods that accept `ccc.TransactionLike` and return `ccc.Transaction`
264265
- Examples:
265266
- `DaoManager.deposit(tx, capacities, lock)`: Add DAO deposit cells
266267
- `OrderManager.mint(tx, user, info, amounts)`: Create order cell
@@ -277,16 +278,12 @@ Receipts convert to UDT; deposits stay as deposits or convert to UDT. No iCKB ca
277278
- `WithdrawalGroup`: Pairs owned (withdrawal request) + owner cell with value aggregation
278279
- Construction: Async factories via `daoCellFrom()`, `ickbDepositCellFrom()`, `receiptCellFrom()`
279280

280-
**SmartTransaction (Builder):**
281-
- Purpose: Extends ccc.Transaction with UDT-aware balancing
282-
- Pattern: Incremental builder with state accumulation
283-
- Key state: `inputs`, `outputs`, `outputsData`, `cellDeps`, `headerDeps`, `witnesses`, `udtHandlers` map
284-
- Automatic operations:
285-
- `completeFeeChangeToLock()`: Calculate and add change cells for CKB
286-
- `addUdtChange()`: Add change cells for each tracked UDT
287-
- `addCellDeps()`: Deduplicate and append cell dependencies
288-
- Used by: All managers to build transactions atomically
289-
- Note: The "SmartTransaction" ecosystem concept was ABANDONED (no CKB ecosystem adoption). However, this class is still actively used throughout all new packages. The name is a vestige. Header caching has moved to CCC's Client Cache.
281+
**Transaction Building (ccc.Transaction):**
282+
- Purpose: All managers use plain `ccc.Transaction` (SmartTransaction was deleted in Phase 1)
283+
- Pattern: Managers accept `ccc.TransactionLike` and return `ccc.Transaction` (TransactionLike pattern)
284+
- Key operations: `tx.addCellDeps()`, `tx.addInput()`, `tx.addOutput()`, `tx.headerDeps.push()`
285+
- Fee completion: CCC-native `completeFeeBy()` / `completeFeeChangeToLock()` with DAO-aware 64-output limit check (contributed to CCC core)
286+
- Header caching: Transparently handled by CCC Client Cache (no explicit header map)
290287

291288
**Value Types (Domain Models):**
292289
- `ValueComponents`: `{ ckbValue: ccc.FixedPoint; udtValue: ccc.FixedPoint }`
@@ -371,14 +368,14 @@ Receipts convert to UDT; deposits stay as deposits or convert to UDT. No iCKB ca
371368
- Pattern: CCC signers abstract wallet implementation
372369

373370
**Capacity & Fee Management:**
374-
- `CapacityManager`: Discovers and collects cells for capacity
375-
- `SmartTransaction`: Auto-calculates fees from transaction size
376-
- Pattern: Add-then-complete flow (add inputs/outputs, then complete fee)
371+
- CCC-native: `tx.completeFeeBy()` / `tx.completeFeeChangeToLock()` with DAO-aware 64-output limit
372+
- Pattern: Add-then-complete flow (add inputs/outputs, then complete fee via CCC pipeline)
373+
- Note: `CapacityManager` was deleted in Phase 1; capacity discovery uses `client.findCellsOnChain()` directly
377374

378375
**UDT Handling:**
379-
- `UdtHandler`: Encapsulates token script + type script pair
380-
- Pattern: Managers create handlers; SmartTransaction tracks per-UDT changes
381-
- Automatic change: `SmartTransaction.addUdtChange()` for balancing
376+
- `UdtHandler`: Interface encapsulating token script + cell deps
377+
- `UdtManager`: Base implementation with `isUdt()`, `findUdts()`, `completeInputsByUdt()`
378+
- Pattern: Managers hold `UdtHandler` reference; cell deps added via `tx.addCellDeps(udtHandler.cellDeps)`
382379

383380
---
384381

.planning/codebase/CONCERNS.md

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,28 @@
3838

3939
### Local UDT Handling May Overlap CCC Upstream (Medium)
4040

41-
- Issue: CCC now has a dedicated `@ckb-ccc/udt` package (at `ccc-dev/ccc/packages/udt/`). The local `packages/utils/src/udt.ts` and `packages/core/src/udt.ts` implement custom UDT handling (`UdtHandler` interface, `IckbUdtManager` class). While the local UDT handling is iCKB-specific (custom balance calculation accounting for DAO deposits), the generic UDT operations like `ccc.udtBalanceFrom()` are still being used from CCC upstream in `packages/utils/src/udt.ts` (4 locations).
41+
- Issue: CCC now has a dedicated `@ckb-ccc/udt` package (at `ccc-fork/ccc/packages/udt/`). The local `packages/utils/src/udt.ts` and `packages/core/src/udt.ts` implement custom UDT handling (`UdtHandler` interface, `IckbUdtManager` class). While the local UDT handling is iCKB-specific (custom balance calculation accounting for DAO deposits), the generic UDT operations like `ccc.udtBalanceFrom()` are still being used from CCC upstream in `packages/utils/src/udt.ts` (4 locations).
4242
- Files:
4343
- `packages/utils/src/udt.ts` - `UdtHandler` interface, `UdtManager` class (~370 lines)
4444
- `packages/core/src/udt.ts` - `IckbUdtManager` extending UDT handling for iCKB-specific logic
45-
- `ccc-dev/ccc/packages/udt/src/` - CCC upstream UDT package
45+
- `ccc-fork/ccc/packages/udt/src/` - CCC upstream UDT package
4646
- Usage of `ccc.udtBalanceFrom()`: `packages/utils/src/udt.ts` lines 169, 197, 323, 368
4747
- Impact: There may be duplicated utility code for standard UDT operations (finding cells, calculating balances). The iCKB-specific extensions (e.g., `IckbUdtManager` which modifies balance calculations based on DAO deposit/withdrawal state) are domain-specific and unlikely to be in CCC.
4848
- Fix approach: Audit the CCC `@ckb-ccc/udt` package to identify which local utilities can be replaced. Keep iCKB-specific extensions but delegate standard UDT operations (cell finding, basic balance) to CCC where possible.
4949

5050
### Fragile CCC Local Override Mechanism (Medium)
5151

52-
- Issue: The `.pnpmfile.cjs` hook and `ccc-dev/record.sh` script create a fragile mechanism for overriding published CCC packages with local builds. The `.pnpmfile.cjs` `readPackage` hook intercepts pnpm's dependency resolution to redirect `@ckb-ccc/*` packages to local paths under `ccc-dev/ccc/packages/*/`.
52+
- Issue: The `.pnpmfile.cjs` hook and `fork-scripts/record.sh` script create a fragile mechanism for overriding published CCC packages with local builds. The `.pnpmfile.cjs` `readPackage` hook intercepts pnpm's dependency resolution to redirect `@ckb-ccc/*` packages to local paths under `ccc-fork/ccc/packages/*/`.
5353
- Files:
5454
- `.pnpmfile.cjs` - pnpm hook that overrides `@ckb-ccc/*` package resolutions
55-
- `ccc-dev/record.sh` - clones CCC repo, merges refs, and builds it locally
56-
- `pnpm-workspace.yaml` - includes `ccc-dev/ccc/packages/*` in workspace
57-
- `ccc-dev/ccc/` - local CCC checkout (when present)
55+
- `fork-scripts/record.sh` - generic fork record script (clones repo, merges refs, builds locally)
56+
- `ccc-fork/config.json` - CCC fork configuration (upstream URL, refs, workspace config)
57+
- `pnpm-workspace.yaml` - includes `ccc-fork/ccc/packages/*` in workspace (auto-generated section)
58+
- `ccc-fork/ccc/` - local CCC checkout (when present)
5859
- Impact: Multiple fragility points:
59-
1. The local CCC repo at `ccc-dev/ccc/` must be manually cloned and kept in sync with a specific branch/commit.
60+
1. The local CCC repo at `ccc-fork/ccc/` must be manually cloned and kept in sync with a specific branch/commit.
6061
2. The `readPackage` hook modifies `dependencies` objects at install time, which can silently break if CCC reorganizes its packages.
61-
3. CI/CD (`ccc-dev/replay.sh`) must run this setup before `pnpm install`, creating an ordering dependency.
62+
3. CI/CD (`fork-scripts/replay.sh`) must run this setup before `pnpm install`, creating an ordering dependency.
6263
4. The override mechanism is invisible to developers who don't read `.pnpmfile.cjs`, leading to confusion when packages resolve differently than expected from `package.json`.
6364
- Fix approach: Now that UDT and Epoch PRs have been merged into CCC upstream, evaluate whether the local overrides are still needed. If CCC publishes releases containing the merged features, switch to published versions and remove the override mechanism.
6465

@@ -107,7 +108,7 @@
107108
- `packages/dao/src/dao.ts`, lines 326-334 (called in async generator loop)
108109
- `packages/core/src/owned_owner.ts`, lines 229-234 (same pattern)
109110
- Cause: Each `daoCellFrom()` call makes 1-2 RPC calls that cannot be parallelized within a single cell construction.
110-
- Improvement path: The `SmartTransaction.headers` cache in `packages/utils/src/transaction.ts` partially mitigates this by caching fetched headers. For batch operations, consider prefetching all needed headers in parallel before constructing DAO cells.
111+
- Improvement path: CCC's Client Cache transparently caches fetched headers (SmartTransaction's header cache was deleted in Phase 1). For batch operations, consider prefetching all needed headers in parallel before constructing DAO cells.
111112

112113
### Duplicated RPC Batching Code in Legacy Apps
113114

@@ -128,12 +129,9 @@
128129

129130
## Fragile Areas
130131

131-
### SmartTransaction Class Extending ccc.Transaction
132+
### SmartTransaction Class Extending ccc.Transaction (RESOLVED)
132133

133-
- Files: `packages/utils/src/transaction.ts` (517 lines)
134-
- Why fragile: `SmartTransaction` extends `ccc.Transaction` and overrides 8 methods: `completeFee`, `getInputsUdtBalance`, `getOutputsUdtBalance`, `getInputsCapacity`, `clone`, `copy`, `from`, `default`, and `fromLumosSkeleton`. Changes to `ccc.Transaction`'s interface or behavior upstream can silently break `SmartTransaction`.
135-
- Safe modification: When updating CCC dependency, review `ccc.Transaction` changelog for breaking changes to overridden methods. The `completeFee` override (lines 63-98) is particularly fragile as it calls `super.completeFee()` and also queries the client for the NervosDAO script to check the 64-output limit.
136-
- Test coverage: No tests for `SmartTransaction`.
134+
- Status: **Resolved in Phase 1** — SmartTransaction class and CapacityManager were fully deleted from `@ickb/utils`. All manager methods now accept `ccc.TransactionLike` and return `ccc.Transaction` directly. Header caching is handled by CCC Client Cache. The 64-output DAO limit check was contributed to CCC core.
137135

138136
### Bot Order Matching Algorithm
139137

@@ -154,11 +152,11 @@
154152
### 64 Output Cell Limit for NervosDAO Transactions
155153

156154
- Current capacity: Maximum 64 output cells per transaction containing NervosDAO operations.
157-
- Limit: Enforced by the NervosDAO script itself. Checked in 6 locations throughout the codebase.
155+
- Limit: Enforced by the NervosDAO script itself. Consolidated into CCC core in Phase 1.
158156
- Files:
159-
- `packages/dao/src/dao.ts`, lines 99-103, 174-177, 244-248
160-
- `packages/core/src/owned_owner.ts`, lines 102-106, 144-148
161-
- `packages/utils/src/transaction.ts`, lines 85-95
157+
- `ccc-fork/ccc/packages/core/src/ckb/transaction.ts``assertDaoOutputLimit` utility + `completeFee` safety net (contributed to CCC core in Phase 1)
158+
- `packages/dao/src/dao.ts` — calls `assertDaoOutputLimit`
159+
- `packages/core/src/owned_owner.ts` — calls `assertDaoOutputLimit`
162160
- `apps/bot/src/index.ts`, line 414 (limits to 58 outputs to reserve 6 for change)
163161
- Scaling path: Protocol-level constraint. The bot works around it by limiting deposit/withdrawal operations per transaction. Future NervosDAO script updates may relax this.
164162

@@ -242,19 +240,13 @@
242240

243241
## Dead Code
244242

245-
### `fromLumosSkeleton` in SmartTransaction
243+
### `fromLumosSkeleton` in SmartTransaction (RESOLVED)
246244

247-
- Issue: `SmartTransaction.fromLumosSkeleton()` at `packages/utils/src/transaction.ts` line 432 provides Lumos interoperability. Since the new packages do not use Lumos, this method is only needed if external code passes Lumos skeletons to the new packages.
248-
- Files: `packages/utils/src/transaction.ts`, lines 432-436
249-
- Impact: Low. The method is a thin wrapper delegating to the superclass.
250-
- Fix approach: Remove after all apps are migrated away from Lumos.
245+
- Status: **Resolved in Phase 1** — SmartTransaction class was fully deleted, including `fromLumosSkeleton()`.
251246

252-
### SmartTransaction Name is Misleading (Not Dead)
247+
### SmartTransaction Name is Misleading (RESOLVED)
253248

254-
- Issue: Despite the original "SmartTransaction" concept being abandoned ecosystem-wide, the `SmartTransaction` class in `packages/utils/src/transaction.ts` is actively used throughout the new packages. It extends `ccc.Transaction` with UDT handler management and header caching (which is what replaced the abandoned SmartTransaction headers concept). The name is a vestige but the code is alive and critical.
255-
- Files: `packages/utils/src/transaction.ts` - definition (517 lines). Used in: `packages/sdk/src/sdk.ts`, `packages/order/src/order.ts`, `packages/dao/src/dao.ts`, `packages/core/src/owned_owner.ts`, `packages/core/src/logic.ts`, `apps/faucet/src/main.ts`
256-
- Impact: The name `SmartTransaction` may confuse developers familiar with the abandoned ecosystem concept.
257-
- Fix approach: Consider renaming to `IckbTransaction` or `EnhancedTransaction`. Low priority since the class is internal to the monorepo.
249+
- Status: **Resolved in Phase 1** — SmartTransaction class was fully deleted from `@ickb/utils`. All manager methods now accept `ccc.TransactionLike` directly.
258250

259251
---
260252

0 commit comments

Comments
 (0)