Skip to content

Comments

refactor: replace local utility functions with CCC equivalents#19

Merged
phroi merged 8 commits intomasterfrom
refactor/v1-02-ccc-utility-adoption
Feb 23, 2026
Merged

refactor: replace local utility functions with CCC equivalents#19
phroi merged 8 commits intomasterfrom
refactor/v1-02-ccc-utility-adoption

Conversation

@phroi
Copy link
Member

@phroi phroi commented Feb 23, 2026

Why

The local max, min, gcd, hexFrom, and isHex utilities in @ickb/utils duplicate functionality now provided by CCC. Removing them reduces maintenance surface and aligns the codebase with upstream.

Changes

  • Delete max, min, gcd, hexFrom, isHex from @ickb/utils public API
  • Replace gcd() with ccc.gcd() and max() with Math.max() at call sites operating on number types
  • Replace hexFrom(entity) with entity.toHex() and hexFrom(bytes) with ccc.hexFrom()
  • Update unique() internals to use toHex() directly
  • Includes changeset with major bumps for @ickb/utils, @ickb/order, @ickb/sdk

…t all call sites

- Replace max() with Number(ccc.numMax()) at 2 call sites (entities.ts, codec.ts)
- Replace gcd() with ccc.gcd() at 1 call site (entities.ts)
- Replace hexFrom(entity) with entity.toHex() at 4 call sites (order.ts, sdk.ts)
- Replace hexFrom(bytes) with ccc.hexFrom() at 1 call site (faucet main.ts)
- Remove max/gcd/hexFrom from @ickb/utils imports in all modified files
…e() internals

- Delete max, min, gcd, hexFrom, isHex from @ickb/utils
- Update unique() to use i.toHex() instead of local hexFrom(i)
- Preserve all iCKB-unique utilities (binarySearch, asyncBinarySearch, shuffle, collect, BufferedGenerator, MinHeap, sum)
- Add changeset documenting the breaking API removal
- pnpm check:full passes with zero errors
- Create 02-01-SUMMARY.md documenting utility function replacement
- Update STATE.md: Phase 02 complete, plan 1/1 done, decisions recorded
- Update ROADMAP.md: Phase 2 marked complete with 1/1 plans done
- Update REQUIREMENTS.md: DEDUP-01 through DEDUP-05 marked complete
@gemini-code-assist
Copy link

Summary of Changes

Hello @phroi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the codebase by removing redundant utility functions from @ickb/utils that duplicate functionality already provided by the CCC core library. The change aims to reduce maintenance overhead and improve alignment with upstream dependencies. All instances where these local utilities were used have been updated to leverage the corresponding CCC functions or native JavaScript methods, ensuring a leaner and more consistent utility layer across the project. This completes a significant phase in the project's development roadmap.

Highlights

  • Utility Function Deduplication: Removed five local utility functions (max, min, gcd, hexFrom, isHex) from @ickb/utils to eliminate duplicated functionality with the CCC core library.
  • Call Site Migration: Replaced all external call sites of the removed utility functions with their CCC equivalents (e.g., ccc.gcd(), ccc.hexFrom(), entity.toHex()) or standard JavaScript functions (Math.max()).
  • Internal unique() Update: Modified the internal implementation of the unique() utility in @ickb/utils to use entity.toHex() directly, aligning with the new CCC-centric approach.
  • Roadmap Progress: Completed 'Phase 2: CCC Utility Adoption' of the project roadmap, marking all associated requirements (DEDUP-01 through DEDUP-05) as satisfied.
  • Dependency Updates: Updated various development dependencies and their resolutions in pnpm-lock.yaml.
Changelog
  • .changeset/remove-local-utility-functions.md
    • Added a new changeset entry detailing the removal of local utility functions and their replacement with CCC equivalents.
    • Specified major version bumps for @ickb/utils, @ickb/order, and @ickb/sdk due to breaking API changes.
  • .planning/REQUIREMENTS.md
    • Marked DEDUP-01 through DEDUP-05 requirements as completed.
    • Updated the 'Last updated' date to reflect the completion of Phase 2 requirements.
  • .planning/ROADMAP.md
    • Marked 'Phase 2: CCC Utility Adoption' as completed.
    • Updated the plan completion count for Phase 2.
  • .planning/STATE.md
    • Updated the current project focus to 'Phase 2: CCC Utility Adoption'.
    • Reflected the completion of Phase 2 and readiness for Phase 3.
    • Updated performance metrics including total plans completed, average duration, and total execution time.
    • Added recent decisions regarding the use of Number(ccc.numMax()) and entity.toHex().
  • .planning/phases/02-ccc-utility-adoption/02-01-PLAN.md
    • Added a new plan document outlining the objective, tasks, and verification for the utility function deduplication.
  • .planning/phases/02-ccc-utility-adoption/02-01-SUMMARY.md
    • Added a summary report for the completed plan, detailing accomplishments, task commits, and key decisions.
  • .planning/phases/02-ccc-utility-adoption/02-RESEARCH.md
    • Added a research document providing a detailed analysis of the utility function deduplication, including rationale, patterns, and potential pitfalls.
  • .planning/phases/02-ccc-utility-adoption/02-VERIFICATION.md
    • Added a verification report confirming the successful execution and validation of the utility function replacement plan.
  • apps/faucet/src/main.ts
    • Removed the hexFrom import from @ickb/utils.
    • Replaced hexFrom(getRandomValues(...)) with ccc.hexFrom(getRandomValues(...)).
  • packages/order/src/entities.ts
    • Removed gcd and max imports from @ickb/utils.
    • Replaced gcd(aScale, bScale) with ccc.gcd(aScale, bScale).
    • Replaced max(aScale.toString(2).length, bScale.toString(2).length) with Math.max(aScale.toString(2).length, bScale.toString(2).length).
  • packages/order/src/order.ts
    • Removed the hexFrom import from @ickb/utils.
    • Replaced hexFrom(master.cell.outPoint) with master.cell.outPoint.toHex().
    • Replaced hexFrom(master) with master.toHex().
  • packages/sdk/src/codec.ts
    • Removed the max import from @ickb/utils.
    • Replaced max(1, ...bins) with Math.max(1, ...bins).
  • packages/sdk/src/sdk.ts
    • Removed the hexFrom import from @ickb/utils.
    • Replaced hexFrom(cell.cellOutput.lock) with cell.cellOutput.lock.toHex().
    • Replaced hexFrom(wr.owner.cell.cellOutput.lock) with wr.owner.cell.cellOutput.lock.toHex().
  • packages/utils/src/utils.ts
    • Removed the max, min, gcd, hexFrom, and isHex function definitions.
    • Updated the internal implementation of unique() to use i.toHex() instead of the deleted hexFrom(i).
  • pnpm-lock.yaml
    • Updated various dependency versions, including @typescript/native-preview, @rollup/*, balanced-match, brace-expansion, caniuse-lite, minimatch, rollup, test-exclude, and tsdown.
Activity
  • A new plan, '02-01-PLAN.md', was created to detail the objective and tasks for replacing local utility functions with CCC equivalents.
  • Research was conducted and documented in '02-RESEARCH.md' to identify appropriate CCC replacements and potential pitfalls.
  • The project roadmap and requirements documents were updated to reflect the completion of 'Phase 2: CCC Utility Adoption'.
  • Performance metrics and recent decisions were logged in the project state document.
  • A summary of the completed plan, '02-01-SUMMARY.md', was generated, detailing accomplishments and key decisions.
  • A verification report, '02-VERIFICATION.md', was created, confirming that all must-have truths and requirements were satisfied.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great step towards aligning the codebase with CCC by removing duplicated utility functions. The refactoring is well-documented through extensive planning and research files. The changes in most files correctly replace local utilities with their CCC equivalents (ccc.gcd, entity.toHex, ccc.hexFrom). However, I've found two instances where Math.max() was used instead of the documented choice of Number(ccc.numMax()). Using the CCC-provided function would ensure consistency with the PR's stated goal. Please see the specific comments for details.

ccc.numMax() converts number args to bigint and returns bigint,
requiring a Number() wrapper to convert back. These call sites
operate entirely on number types, so Math.max() is the correct
replacement for the old generic max<T>().

Also downgrade @ickb/order and @ickb/sdk changeset bumps from major
to patch — the only change in those packages is an internal swap
of one standard-library call for another, with no public API change.
The implementation was changed from hexFrom()/toBytes() to toHex(),
but the JSDoc still referenced "byte representation" and mol.Entity.
@phroi phroi force-pushed the refactor/v1-02-ccc-utility-adoption branch from 9333d26 to a4015fc Compare February 23, 2026 20:15
@phroi
Copy link
Member Author

phroi commented Feb 23, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request completes Phase 2 of the project roadmap, focusing on 'CCC Utility Adoption'. It involves replacing five local utility functions (max, min, gcd, hexFrom, isHex) in @ickb/utils with their CCC equivalents or native JavaScript functions, and subsequently deleting the local implementations. Specifically, max() and min() are replaced with Math.max() and Math.min() for number-typed contexts to avoid unnecessary bigint conversions, gcd() is replaced with ccc.gcd(), hexFrom(entity) calls are updated to entity.toHex(), and hexFrom(bytes) calls are updated to ccc.hexFrom(). The internal implementation of the unique() utility function is also updated to use entity.toHex(). All relevant planning documents (REQUIREMENTS.md, ROADMAP.md, STATE.md, and phase-specific plan/summary/research/verification files) have been updated to reflect the completion of these tasks and the rationale behind specific implementation choices, such as using Math.max() over ccc.numMax() and entity.toHex() over ccc.hexFrom(entity.toBytes()). A changeset entry has been added to document the breaking API changes in @ickb/utils.

@phroi
Copy link
Member Author

phroi commented Feb 23, 2026

LGTM

Phroi %74

@phroi phroi merged commit 4ebfaf6 into master Feb 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant