Skip to content

Commit dd7b1d0

Browse files
authored
Merge pull request #22 from ickb/refactor/unify-forks-directory
Unify fork management under forks/ directory
2 parents 54851a3 + 3e5bb05 commit dd7b1d0

76 files changed

Lines changed: 536 additions & 1768 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/generalize-fork-management.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Clipboard support for wl-copy/wl-paste (used by CLAUDE.md)
3838
"clipboard": "sudo apt-get update -qq && sudo apt-get install -y -qq --no-install-recommends wl-clipboard",
3939
// Install vscode focus timer extension
40-
"focus-timer": "d=~/focus-timer-ext && git clone https://github.com/phroi/vscode-focus-timer.git $d && ln -sfn $d ~/.vscode-server/extensions/phroi.focus"
40+
"focus-timer": "d=~/focus-timer-ext && git clone --depth 1 https://github.com/phroi/vscode-focus-timer.git $d && ln -sfn $d ~/.vscode-server/extensions/phroi.focus"
4141
},
4242

4343
// Run each time the container starts. Ensures updated dependencies are installed inside the container user environment.

.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-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.
59+
**Local CCC dev build:** `forks/ccc/` supports using local CCC builds for testing. `.pnpmfile.cjs` transparently rewires `@ckb-ccc/*` to local packages. `forks/forker/patch.sh` rewrites exports to `.ts` source. This enables testing upstream changes before they're published.
6060

6161
## Constraints
6262

.planning/REQUIREMENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Which phases cover which requirements. Updated during roadmap creation.
8686
| SMTX-03 | Phase 6 | Pending | |
8787
| SMTX-04 | Phase 1 | Complete | getHeader()/HeaderKey removed, CCC client calls inlined |
8888
| SMTX-05 | Phase 1, 4, 5 | Complete | addUdtHandlers() replaced with tx.addCellDeps(udtHandler.cellDeps) (01-03); UdtHandler/UdtManager replacement deferred to Phase 4-5 |
89-
| SMTX-06 | Phase 1 | Complete | DAO check contributed to CCC core via ccc-fork/ (01-01) |
89+
| SMTX-06 | Phase 1 | Complete | DAO check contributed to CCC core via forks/ccc/ (01-01) |
9090
| SMTX-07 | Phase 5 | Pending | |
9191
| SMTX-08 | Phase 6 | Pending | |
9292
| SMTX-09 | Phase 7 | Pending | |

.planning/ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Decimal phases appear between their surrounding integers in numeric order.
3030
1. `SmartTransaction` class and `CapacityManager` class no longer exist in `@ickb/utils` source or exports
3131
2. `UdtHandler` interface and `UdtManager` class remain in `@ickb/utils` with method signatures updated from `SmartTransaction` to `ccc.TransactionLike` (full replacement deferred to Phase 3+)
3232
3. `getHeader()` function and `HeaderKey` type are removed from `@ickb/utils`; all call sites across dao/core/sdk inline CCC client calls (`client.getTransactionWithHeader()`, `client.getHeaderByNumber()`); `SmartTransaction.addHeaders()` call sites in DaoManager/LogicManager push to `tx.headerDeps` directly
33-
4. A 64-output NervosDAO limit check exists in CCC core (via `ccc-fork/`): `completeFee()` safety net, standalone async utility, and `ErrorNervosDaoOutputLimit` error class; all 6+ scattered checks across dao/core packages are replaced with calls to this CCC utility
33+
4. A 64-output NervosDAO limit check exists in CCC core (via `forks/ccc/`): `completeFee()` safety net, standalone async utility, and `ErrorNervosDaoOutputLimit` error class; all 6+ scattered checks across dao/core packages are replaced with calls to this CCC utility
3434
5. ALL manager method signatures across ALL 5 library packages accept `ccc.TransactionLike` instead of `SmartTransaction`, following CCC's convention (TransactionLike input, Transaction output with `Transaction.from()` conversion at entry point)
3535
6. `pnpm check:full` passes after each feature-slice removal step — no intermediate broken states
3636
**Plans**: 3 plans

.planning/STATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Recent decisions affecting current work:
4747
- [Roadmap]: Phase 1 uses feature-slice approach -- each removal chased across all packages, build stays green after every step. SMTX-01 (all signatures to TransactionLike) completed in Phase 1, not Phase 5.
4848
- [Roadmap]: UDT investigation (Phase 3) is a design phase that produces a decision document; its outcome determines UdtHandler/UdtManager replacement pattern used in Phases 4-5
4949
- [Roadmap]: Phases 4-5 reduced in scope: Phase 4 focuses on deprecated API replacement + UDT pattern finalization in dao/order; Phase 5 focuses on IckbUdt implementation + conservation law in core
50-
- [Phase 1 Context]: DAO 64-output limit check contributed to CCC core via ccc-fork/, CCC PR submitted during Phase 1
50+
- [Phase 1 Context]: DAO 64-output limit check contributed to CCC core via forks/ccc/, CCC PR submitted during Phase 1
5151
- [Phase 1 Context]: getHeader()/HeaderKey removed entirely -- inline CCC client calls at read-only call sites; addHeaders() call sites in DaoManager/LogicManager push to tx.headerDeps directly
5252
- [Phase 1 Context]: Script comparison must always use full Script.eq(), never just codeHash comparison
53-
- [01-01]: Added ccc-fork local patch mechanism for deterministic replay of CCC modifications (now multi-file format: manifest + res-N.resolution + local-*.patch)
53+
- [01-01]: Added forks/ccc local patch mechanism for deterministic replay of CCC modifications (now multi-file format: manifest + res-N.resolution + local-*.patch)
5454
- [01-01]: DaoManager.requestWithdrawal/withdraw client parameter placed before optional options for cleaner API
5555
- [01-01]: assertDaoOutputLimit uses early return when outputs <= 64 for zero-cost common case
5656
- [01-02]: Moved getHeader/HeaderKey to transaction.ts as non-exported internals (deleted alongside SmartTransaction in 01-03)
@@ -80,7 +80,7 @@ None yet.
8080
- Resolved: CCC's `Transaction.getInputsCapacity()` handles DAO profit natively via `getInputsCapacityExtra()` -> `CellInput.getExtraCapacity()` -> `Cell.getDaoProfit()` (verified in STACK.md from CCC source). No standalone utility needed.
8181
- Resolved: CCC Udt `getInputsInfo()` resolves inputs to `Cell` objects (which have `outPoint`) before passing to `infoFrom()`. `infoFrom()`'s `CellAnyLike` parameter has `outPoint?: OutPointLike | null` — optional, not absent. Input cells have outPoint (for header fetches), output cells don't. Both `infoFrom` and `getInputsInfo/getOutputsInfo` are viable override points for IckbUdt (verified during Phase 3 discuss-phase).
8282
- Resolved: STACK.md research correction applied — `client.getHeaderByTxHash()` (non-existent) replaced with `client.getTransactionWithHeader()` in STACK.md, ROADMAP.md Phase 3 success criterion #2, and REQUIREMENTS.md UDT-02.
83-
- Resolved: PR #328 stance updated during Phase 3 context — user decision is to design around PR #328 as target architecture (overrides research recommendation to "not wait for #328"). PR #328 is now integrated into `ccc-fork/ccc` via pins; FeePayer classes available at `ccc-fork/ccc/packages/core/src/signer/feePayer/`. The separate `reference/ccc-fee-payer` clone is no longer needed.
83+
- Resolved: PR #328 stance updated during Phase 3 context — user decision is to design around PR #328 as target architecture (overrides research recommendation to "not wait for #328"). PR #328 is now integrated into `forks/ccc/` via pins; FeePayer classes available at `forks/ccc/packages/core/src/signer/feePayer/`. The separate ccc-fee-payer reference clone is no longer needed.
8484
- Resolved: `CellAny` has `capacityFree` getter (CCC transaction.ts:404-405) — 03-RESEARCH.md corrected (previously claimed `CellAny` lacked it).
8585

8686
## Session Continuity

.planning/codebase/ARCHITECTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The iCKB protocol solves NervosDAO illiquidity by pooling DAO deposits and issui
4747

4848
## On-Chain Contracts (Rust)
4949

50-
Three production smart contracts (in `reference/contracts/` reference repo) implement the protocol on CKB L1. Each TS package in `packages/` corresponds to contract logic:
50+
Three production smart contracts (in `forks/contracts/` reference repo) implement the protocol on CKB L1. Each TS package in `packages/` corresponds to contract logic:
5151

5252
| Contract | Script Type | TS Package | Purpose |
5353
|---|---|---|---|
@@ -70,7 +70,7 @@ 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-fork/ccc/`)
73+
- Location: `@ckb-ccc/core` (npm or local `forks/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

.planning/codebase/CONCERNS.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +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-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).
41+
- Issue: CCC now has a dedicated `@ckb-ccc/udt` package (at `forks/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-fork/ccc/packages/udt/src/` - CCC upstream UDT package
45+
- `forks/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 `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/*/`.
52+
- Issue: The `.pnpmfile.cjs` hook and `forks/forker/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 `forks/ccc/packages/*/`.
5353
- Files:
5454
- `.pnpmfile.cjs` - pnpm hook that overrides `@ckb-ccc/*` package resolutions
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)
55+
- `forks/forker/record.sh` - generic fork record script (clones repo, merges refs, builds locally)
56+
- `forks/config.json` - CCC fork configuration (upstream URL, refs, workspace config)
57+
- `pnpm-workspace.yaml` - includes `forks/ccc/packages/*` in workspace (auto-generated section)
58+
- `forks/ccc/` - local CCC checkout (when present)
5959
- Impact: Multiple fragility points:
60-
1. The local CCC repo at `ccc-fork/ccc/` must be manually cloned and kept in sync with a specific branch/commit.
60+
1. The local CCC repo at `forks/ccc/` must be manually cloned and kept in sync with a specific branch/commit.
6161
2. The `readPackage` hook modifies `dependencies` objects at install time, which can silently break if CCC reorganizes its packages.
62-
3. CI/CD (`fork-scripts/replay.sh`) must run this setup before `pnpm install`, creating an ordering dependency.
62+
3. CI/CD (`forks/forker/replay.sh`) must run this setup before `pnpm install`, creating an ordering dependency.
6363
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`.
6464
- 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.
6565

@@ -154,7 +154,7 @@
154154
- Current capacity: Maximum 64 output cells per transaction containing NervosDAO operations.
155155
- Limit: Enforced by the NervosDAO script itself. Consolidated into CCC core in Phase 1.
156156
- Files:
157-
- `ccc-fork/ccc/packages/core/src/ckb/transaction.ts``assertDaoOutputLimit` utility + `completeFee` safety net (contributed to CCC core in Phase 1)
157+
- `forks/ccc/packages/core/src/ckb/transaction.ts``assertDaoOutputLimit` utility + `completeFee` safety net (contributed to CCC core in Phase 1)
158158
- `packages/dao/src/dao.ts` — calls `assertDaoOutputLimit`
159159
- `packages/core/src/owned_owner.ts` — calls `assertDaoOutputLimit`
160160
- `apps/bot/src/index.ts`, line 414 (limits to 58 outputs to reserve 6 for change)
@@ -217,19 +217,19 @@
217217

218218
### TS Exchange Rate Must Match Rust Contract Logic
219219

220-
- What's not tested: The TypeScript exchange rate calculation (`packages/core/src/udt.ts`) must produce identical results to the Rust contract's `deposit_to_ickb()` function (`reference/contracts/scripts/contracts/ickb_logic/src/entry.rs`). Any discrepancy would cause transactions to be rejected on-chain.
220+
- What's not tested: The TypeScript exchange rate calculation (`packages/core/src/udt.ts`) must produce identical results to the Rust contract's `deposit_to_ickb()` function (`forks/contracts/scripts/contracts/ickb_logic/src/entry.rs`). Any discrepancy would cause transactions to be rejected on-chain.
221221
- Key formula: `iCKB = capacity * AR_0 / AR_m` with soft cap penalty `amount - (amount - 100000) / 10` when `amount > ICKB_SOFT_CAP_PER_DEPOSIT`
222222
- Contract constants that TS must match:
223223
- `CKB_MINIMUM_UNOCCUPIED_CAPACITY_PER_DEPOSIT = 1,000 * 100_000_000` (1,000 CKB)
224224
- `CKB_MAXIMUM_UNOCCUPIED_CAPACITY_PER_DEPOSIT = 1,000,000 * 100_000_000` (1,000,000 CKB)
225225
- `ICKB_SOFT_CAP_PER_DEPOSIT = 100,000 * 100_000_000` (100,000 iCKB)
226226
- `GENESIS_ACCUMULATED_RATE = 10_000_000_000_000_000` (10^16)
227-
- Reference: `reference/contracts/scripts/contracts/ickb_logic/src/entry.rs` function `deposit_to_ickb()`
227+
- Reference: `forks/contracts/scripts/contracts/ickb_logic/src/entry.rs` function `deposit_to_ickb()`
228228
- Fix approach: Add cross-validation tests with known inputs/outputs derived from the Rust contract logic
229229

230230
### TS Molecule Codecs Must Match Contract Schemas
231231

232-
- What's not tested: The TypeScript Molecule codec definitions (`@ccc.codec` decorators in `packages/order/src/entities.ts`, `packages/core/src/entities.ts`) must produce byte-identical encodings to the Molecule schema at `reference/contracts/schemas/encoding.mol`. Field order, sizes, and endianness must match exactly.
232+
- What's not tested: The TypeScript Molecule codec definitions (`@ccc.codec` decorators in `packages/order/src/entities.ts`, `packages/core/src/entities.ts`) must produce byte-identical encodings to the Molecule schema at `forks/contracts/schemas/encoding.mol`. Field order, sizes, and endianness must match exactly.
233233
- Key schemas:
234234
- `ReceiptData { deposit_quantity: Uint32, deposit_amount: Uint64 }` = 12 bytes
235235
- `OwnedOwnerData { owned_distance: Int32 }` = 4 bytes

.planning/codebase/CONVENTIONS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- All `@ckb-lumos/*` packages are **DEPRECATED** -- Lumos is being replaced by CCC.
1414
- CCC PRs for UDT and Epochs have been **MERGED** upstream -- those features now exist in CCC itself.
1515
- `SmartTransaction` was **DELETED** in Phase 1 in favor of CCC's client cache for header caching. Headers are now fetched inline via CCC client calls (`client.getTransactionWithHeader()`, `client.getHeaderByNumber()`). All manager method signatures now accept `ccc.TransactionLike` and return `ccc.Transaction` directly.
16-
- CCC is sometimes overridden locally via `fork-scripts/record.sh` and `.pnpmfile.cjs` for testing unpublished changes.
16+
- CCC is sometimes overridden locally via `bash forks/forker/record.sh` and `.pnpmfile.cjs` for testing unpublished changes.
1717

1818
**When writing new code:** Use CCC (`@ckb-ccc/core`) types and patterns exclusively in `packages/`. Never introduce new Lumos dependencies.
1919

@@ -270,7 +270,7 @@ export * from "./utils.js";
270270

271271
## Molecule / Codec Patterns
272272

273-
**TS codecs must match the Molecule schema** at `reference/contracts/schemas/encoding.mol`. The on-chain contracts use Molecule for serialization; the TS packages must produce byte-identical encodings.
273+
**TS codecs must match the Molecule schema** at `forks/contracts/schemas/encoding.mol`. The on-chain contracts use Molecule for serialization; the TS packages must produce byte-identical encodings.
274274

275275
**Entity classes** use CCC's `ccc.Entity.Base` with decorator-based codec definition:
276276
```typescript

0 commit comments

Comments
 (0)