Skip to content

Resolve Token Standard V2 settlement factories#378

Open
HardlyDifficult wants to merge 26 commits into
mainfrom
codex/token-standard-settlement-factory
Open

Resolve Token Standard V2 settlement factories#378
HardlyDifficult wants to merge 26 commits into
mainfrom
codex/token-standard-settlement-factory

Conversation

@HardlyDifficult

@HardlyDifficult HardlyDifficult commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • build exact CIP-112 V2 SettlementFactory_SettleBatch arguments and commands
  • resolve the choice-specific factory through the official /registry/allocation/v2/settlement-factory endpoint
  • send canonical empty context and metadata to registry lookup, then combine returned context with caller metadata
  • return the factory ID and validated disclosed contracts as one prepared command
  • keep third-party registry requests unauthenticated and reject malformed context, disclosures, Decimal values, and settlement invariants

Stacked on #374. This is protocol-level behavior with no Fairmint contracts or business rules.

Validation

  • 43 focused allocation, settlement-factory, and Scan client tests
  • npm run build:lint
  • scoped ESLint and Prettier
  • generated client methods
  • git diff --check

The node-SDK Quickstart CI validates the package against the pinned LocalNet. A real two-token settlement using non-empty registry contexts will be covered by the downstream canton-fairmint-sdk Quickstart after the new EquityClearing package and these helpers publish.


Note

Medium Risk
Introduces protocol-level settlement command construction and trust in third-party registry responses; risk is mitigated by strict input/response validation and the same unauthenticated registry pattern as allocation factories.

Overview
Adds Token Standard V2 settlement support: callers can build SettlementFactory_SettleBatch choice arguments and ledger exercise commands, or use prepareTokenStandardV2SettlementCommand to resolve the factory in one step.

A new unauthenticated Scan/registry client operation posts to /registry/allocation/v2/settlement-factory on a caller-supplied instrument registry URL (credentials, query, and hash stripped from the URL; no Scan bearer token forwarded). prepare sends the settlement payload with empty extraArgs.context and metadata for lookup, then merges the registry-returned choice context with optional caller metadata only—caller-supplied extraArgs at prepare time is rejected.

The settlement helper layer validates settlement invariants (non-empty transfer legs and allocations, unique transferLegId, positive Daml decimals, parties/CIDs, choice context shape) and parses registry responses (factory id, disclosed contracts). Unit tests cover the Scan client call shape and the prepare/build/validation paths.

Reviewed by Cursor Bugbot for commit bbe685e. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features

    • Added Token Standard V2 settlement support for building and preparing settlement commands.
    • Added registry lookup for settlement-factory details and disclosed contracts.
    • Added validation for settlement arguments, transfer legs, amounts, metadata, and registry responses.
    • Exposed the new settlement functionality through the public API.
  • Tests

    • Added coverage for settlement command creation, validation, registry requests, error handling, and metadata safety.
  • Documentation

    • Updated the wiki reference.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a Token Standard V2 settlement-factory workflow, including registry lookup, validation, command construction, response handling, public exports, and unit tests. The wiki submodule pointer is also updated.

Changes

Settlement factory integration

Layer / File(s) Summary
Registry operation and public exports
src/clients/scan-api/operations/v0/registry/..., src/utils/token-standard/v2/index.ts
Adds validated unauthenticated settlement-factory registry requests, response types, URL normalization, and barrel exports.
Settlement normalization and command preparation
src/utils/token-standard/v2/settlement-factory.ts
Validates and normalizes settlement inputs, builds ledger ExerciseCommand values, parses registry responses, and merges factory context into prepared commands.
Settlement factory validation coverage
test/unit/clients/scan-api.test.ts, test/unit/token-standard/v2/settlement-factory.test.ts
Tests request construction, command shapes, normalization, numeric validation, cloning, context merging, malformed responses, and pre-lookup failures.

Wiki pointer update

Layer / File(s) Summary
Wiki submodule reference
wiki
Updates the wiki submodule reference to commit 81847096a8dcb794451d5d48eda8d36edc10f629.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant SettlementPreparation
  participant ScanApiClient
  participant Registry
  Caller->>SettlementPreparation: settlement parameters
  SettlementPreparation->>ScanApiClient: settlement-factory lookup request
  ScanApiClient->>Registry: unauthenticated POST
  Registry-->>ScanApiClient: factory context and disclosed contracts
  ScanApiClient-->>SettlementPreparation: registry response
  SettlementPreparation-->>Caller: prepared ExerciseCommand
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding Token Standard V2 settlement factory resolution and command preparation.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/token-standard-settlement-factory

Comment @coderabbitai help to get the list of available commands.

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Base automatically changed from codex/token-standard-allocation to main July 10, 2026 11:36
…settlement-factory

# Conflicts:
#	src/utils/token-standard/v2/allocation.ts
#	src/utils/token-standard/v2/index.ts
#	test/unit/clients/scan-api.test.ts
#	test/unit/token-standard/v2/allocation.test.ts
@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@HardlyDifficult HardlyDifficult marked this pull request as ready for review July 10, 2026 13:33
@HardlyDifficult HardlyDifficult self-assigned this Jul 10, 2026
@HardlyDifficult HardlyDifficult requested a review from Copilot July 10, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds Token Standard V2 settlement-factory support to the SDK by building the canonical SettlementFactory_SettleBatch choice argument/command, resolving the factory + per-choice context via the registry endpoint, and returning a prepared command with validated disclosures.

Changes:

  • Introduces prepareTokenStandardV2SettlementCommand (and related builders/validators) to construct CIP-112 V2 settlement factory commands and merge registry choice context with caller metadata.
  • Adds a new unauthenticated Scan API operation POST /registry/allocation/v2/settlement-factory that canonicalizes arbitrary registry URLs (strips credentials, normalizes slashes).
  • Adds focused unit coverage for settlement-factory helpers and the Scan API client behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/unit/token-standard/v2/settlement-factory.test.ts New unit tests covering settlement choice building, validation, registry lookup behavior, and disclosure handling.
test/unit/clients/scan-api.test.ts Adds coverage for the new settlement-factory registry call and verifies it’s unauthenticated + canonicalized.
src/utils/token-standard/v2/settlement-factory.ts New settlement-factory helper implementation: build/validate choice args, parse registry response, and prepare an exercise command.
src/utils/token-standard/v2/index.ts Exposes the new settlement-factory helpers from the Token Standard v2 utils barrel.
src/clients/scan-api/operations/v0/registry/index.ts Exports the new allocation registry operation group.
src/clients/scan-api/operations/v0/registry/allocation/index.ts New barrel export for allocation registry operations.
src/clients/scan-api/operations/v0/registry/allocation/v2/index.ts New barrel export for allocation v2 registry operations.
src/clients/scan-api/operations/v0/registry/allocation/v2/get-settlement-factory-from-registry.ts New Scan operation definition for resolving settlement factories from arbitrary registries without auth.

Comment thread src/utils/token-standard/v2/settlement-factory.ts Outdated
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/utils/token-standard/v2/settlement-factory.ts Outdated
Comment thread src/utils/token-standard/v2/settlement-factory.ts Outdated
Comment thread test/unit/token-standard/v2/settlement-factory.test.ts
@HardlyDifficult HardlyDifficult marked this pull request as draft July 10, 2026 17:04

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 201d148. Configure here.

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

Addressed all three exact-head Copilot findings in c5acfd9: ChoiceContext outer/values/nested objects now accept only plain or null-prototype JSON records, metadata/funding maps use the same guard, Map/custom-prototype silent data loss is covered, and the registry lookup test mock is interface-typed with jest.MockedFunction. All three threads are resolved. Validation: TypeScript 7 build/lint; scoped ESLint/Prettier; 61/61 focused tests; 69/69 unit suites (739/739 tests); package artifact 5.40 MB / 1325 files. Keeping draft/unassigned for fresh CI, then re-requesting current-head Copilot first, Cursor, and CodeRabbit.

@HardlyDifficult HardlyDifficult marked this pull request as ready for review July 10, 2026 17:17
@HardlyDifficult HardlyDifficult requested a review from Copilot July 10, 2026 17:17
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

cursor review

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c5acfd9. Configure here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/utils/token-standard/v2/settlement-factory.ts
@HardlyDifficult HardlyDifficult marked this pull request as draft July 10, 2026 17:22
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

Addressed the final exact-head Copilot boundary finding in bbe685e: buildTokenStandardV2SettlementChoiceArgument now validates top-level runtime input before field access, with undefined/null/scalar/string/array regressions producing the typed SDK input error. Thread resolved. Validation: TypeScript 7 build/lint; scoped ESLint/Prettier; 66/66 focused tests; 69/69 unit suites (744/744 tests); package artifact 5.40 MB / 1325 files. Keeping draft/unassigned for fresh CI, then re-requesting current-head Copilot first plus Cursor/CodeRabbit.

@claude

claude Bot commented Jul 10, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@HardlyDifficult HardlyDifficult marked this pull request as ready for review July 10, 2026 17:33
@HardlyDifficult HardlyDifficult requested a review from Copilot July 10, 2026 17:33
@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

cursor review

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit bbe685e. Configure here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@HardlyDifficult HardlyDifficult self-assigned this Jul 10, 2026
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.

3 participants