Skip to content

Enforce stock issuance reference integrity - #239

Closed
HardlyDifficult wants to merge 3 commits into
codex/ocf-stock-class-share-ceilingfrom
codex/ocf-stock-issuance-reference-integrity
Closed

Enforce stock issuance reference integrity#239
HardlyDifficult wants to merge 3 commits into
codex/ocf-stock-class-share-ceilingfrom
codex/ocf-stock-issuance-reference-integrity

Conversation

@HardlyDifficult

@HardlyDifficult HardlyDifficult commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #238.

This adds contract-level reference validation for StockIssuance nested references that were previously accepted as arbitrary IDs:

  • stock_legend_ids[] must reference existing StockLegendTemplate contracts when provided.
  • stock_plan_id must reference an existing StockPlan when present.
  • vesting_terms_id must reference existing VestingTerms when present.
  • The same checks run on create and edit paths.

The generator now supports validation config syntax for array references (field_ids[]:map_name) and optional references (field_id?:map_name), then applies those to StockIssuance in captable-config.yaml.

OCF documentation

Tests

  • Added TestStockIssuanceReferences covering missing legend, missing plan, missing vesting terms, valid same-batch references, and edit-time missing-reference rejection.
  • Updated default stock issuance fixtures so unrelated tests no longer depend on placeholder legend IDs.
  • Kept the existing StockIssuance optional-fields test populated by creating the referenced plan, vesting terms, and legends.

Validation

  • NODE_PATH=/Users/fairnick/Documents/code/fairmint/open-captable-protocol-daml/node_modules PATH="/Users/fairnick/Documents/code/fairmint/open-captable-protocol-daml/node_modules/.bin:$HOME/.dpm/bin:$PATH" npm run build
  • From Test/: JAVA_HOME=/opt/homebrew/opt/openjdk@17 PATH="/opt/homebrew/opt/openjdk@17/bin:$HOME/.dpm/bin:$PATH" dpm test --show-coverage --color --coverage-ignore-choice 'splice-amulet:.*'

Note

Medium Risk
Tightens on-chain cap table validation for a core issuance type; updates that previously slipped through with invalid plan/legend/vesting IDs will now fail at create or edit.

Overview
Stock issuance create and edit paths now reject dangling references: every stock_legend_ids entry must exist in stock_legend_templates, and optional stock_plan_id / vesting_terms_id must resolve when set.

The CapTable codegen gains config-driven rules for array (field_ids[]:map) and optional (field_id?:map) lookups; create/edit templates emit the matching assertMsg / mapA_ / case … Some checks. captable-config.yaml wires those rules to StockIssuance, and the packaged OpenCapTable-v34 DAR / lockfile are refreshed.

Tests add TestStockIssuanceReferences (missing refs, same-batch success, edit failure) and stop using placeholder legend IDs in defaults—fixtures now create legends, plans, and vesting terms when tests need them.

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

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 41 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 28357c85-bf3b-47ff-bf5c-779d4031b548

📥 Commits

Reviewing files that changed from the base of the PR and between 76fb636 and b5f8bbc.

⛔ Files ignored due to path filters (1)
  • dars/dars.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • Test/daml/OpenCapTable/TestHelpers.daml
  • Test/daml/OpenCapTable/TestStockAcceptance.daml
  • Test/daml/OpenCapTable/TestStockCancellation.daml
  • Test/daml/OpenCapTable/TestStockIssuance.daml
  • Test/daml/OpenCapTable/TestStockIssuanceReferences.daml
  • Test/daml/OpenCapTable/TestStockRetraction.daml
  • dars/OpenCapTable-v34/0.0.2/OpenCapTable-v34.dar
  • scripts/codegen/captable-config.yaml
  • scripts/codegen/generate-captable.ts
  • scripts/codegen/templates/loops/create-case.daml
  • scripts/codegen/templates/loops/edit-case.daml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ocf-stock-issuance-reference-integrity

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

@HardlyDifficult
HardlyDifficult marked this pull request as ready for review July 8, 2026 23:48
@HardlyDifficult
HardlyDifficult requested a review from Copilot July 8, 2026 23:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds generated CapTable validation for StockIssuance nested reference fields so that referenced IDs must exist at the contract level (on both create and edit), and updates tests/fixtures to create real referenced objects instead of relying on placeholder IDs.

Changes:

  • Extended codegen validation syntax to support array references (field_ids[]:map) and optional references (field_id?:map) and emitted the corresponding DAML checks in create/edit loops.
  • Enabled reference integrity checks for StockIssuance.stock_legend_ids, stock_plan_id, and vesting_terms_id via captable-config.yaml.
  • Updated/added DAML Script tests and helpers to create StockLegendTemplate, StockPlan, and VestingTerms records as prerequisites.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Test/daml/OpenCapTable/TestStockRetraction.daml Updates stock issuance fixture to avoid referencing a non-existent legend ID.
Test/daml/OpenCapTable/TestStockIssuanceReferences.daml Adds reference-integrity tests for missing/valid legend/plan/vesting terms and edit-time rejection.
Test/daml/OpenCapTable/TestStockIssuance.daml Ensures referenced legend/plan/vesting terms are created before exercising optional fields.
Test/daml/OpenCapTable/TestStockCancellation.daml Updates stock issuance fixture to avoid referencing a non-existent legend ID.
Test/daml/OpenCapTable/TestStockAcceptance.daml Updates stock issuance fixture to avoid referencing a non-existent legend ID.
Test/daml/OpenCapTable/TestHelpers.daml Defaults stock legend IDs to empty and adds helper constructors for new prerequisite OCF objects.
scripts/codegen/templates/loops/edit-case.daml Emits generated validation for optional reference fields during edits.
scripts/codegen/templates/loops/create-case.daml Emits generated validation for optional reference fields during creates.
scripts/codegen/generate-captable.ts Parses new [] / ? validation syntax and propagates flags into templates.
scripts/codegen/captable-config.yaml Applies new validations to StockIssuance for legend/plan/vesting-term references.
dars/OpenCapTable-v34/0.0.2/OpenCapTable-v34.dar Updates compiled DAR artifact to include the regenerated CapTable logic.
dars/dars.lock Updates DAR checksum/size metadata to match the new artifact.

@HardlyDifficult

Copy link
Copy Markdown
Collaborator Author

Superseded by #251, which consolidates the reference-integrity work into one PR. Before closing this stack PR, I rechecked the live review comments and folded the actionable improvements into #251: StockPlan create-tier ordering, document related-object error messages, stock-class conversion source IDs, warrant conversion validation across all OcfAnyConversionRight variants, WarrantIssuance same-batch vesting-term edits, and immutable DAR backup versioning.

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.

2 participants