Resolve Token Standard V2 settlement factories#378
Conversation
📝 WalkthroughWalkthroughAdds 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. ChangesSettlement factory integration
Wiki pointer update
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
…ard-settlement-factory # Conflicts: # test/unit/clients/scan-api.test.ts
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
…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 encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
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-factorythat 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. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
✅ 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 encountered an error —— View job I'll analyze this and get back to you. |
|
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. |
|
cursor review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
✅ 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.
|
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 encountered an error —— View job I'll analyze this and get back to you. |
|
cursor review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
✅ 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.
Summary
Stacked on #374. This is protocol-level behavior with no Fairmint contracts or business rules.
Validation
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_SettleBatchchoice arguments and ledger exercise commands, or useprepareTokenStandardV2SettlementCommandto resolve the factory in one step.A new unauthenticated Scan/registry client operation posts to
/registry/allocation/v2/settlement-factoryon a caller-supplied instrument registry URL (credentials, query, and hash stripped from the URL; no Scan bearer token forwarded).preparesends the settlement payload with emptyextraArgs.contextand metadata for lookup, then merges the registry-returned choice context with optional caller metadata only—caller-suppliedextraArgsat 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
Tests
Documentation