Skip to content

docs: spec orchestrator-based mint/burn flows - #216

Closed
JuaniRios wants to merge 1 commit into
mainfrom
rai-1216-spec-orchestrator-mint-burn-flows
Closed

JuaniRios wants to merge 1 commit into
mainfrom
rai-1216-spec-orchestrator-mint-burn-flows

Conversation

@JuaniRios

@JuaniRios JuaniRios commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Today the issuance bot mints and burns tokens by talking to the vault contracts directly, and it does all the receipt bookkeeping itself in its own database. A new contract, the ST0x Orchestrator, is going to take that job over. It becomes the single place every mint and burn goes through, it holds the receipts, and it does the bookkeeping on-chain instead of in the bot.

That makes the bot simpler in the long run, but a lot of moving parts have to change to point at the orchestrator instead of the vault. Our rule in this repo is that we write the plan in SPEC.md before writing any code. This PR is only that plan. The actual code changes are separate tickets, starting at RAI-1217.

Solution

Docs only. This edits SPEC.md and changes no code. It writes down how minting and burning work once they go through the orchestrator, and it settles seven design decisions so the follow-up tickets have concrete answers instead of open questions. The decisions now live in the spec itself (Orchestrator Migration -> Design Decisions), so you do not have to go dig them out of Linear.

The seven decisions, in short:

  1. Mint approval (resolved): the wallet receiving the tokens has to sign each mint. The liquidity bot owns that wallet, so it signs the mint itself and hands the signature to the issuance bot over the internal connection the two bots already use (the same one that checks whether an asset is frozen). Nothing has to travel through Alpaca, which is what makes this simple.
  2. Retry safety: each mint gets one fixed number (a nonce) that we save before submitting and reuse on every retry, so "this number was already used" means "this mint already happened." Recovery then double-checks the on-chain mint matches the exact token and amount, not just the number.
  3. Code shape: the existing signing interface gets two new methods for the orchestrator path, and a per-asset setting in a new TOML config file (the same pattern the liquidity bot uses; default: old path for every asset) picks which path each asset uses, so we can ship it turned off and roll back easily.
  4. New records: five new events for the orchestrator path. Existing events stay untouched except for one new optional field. Failures reuse the machinery we already have, with a typed reason attached.
  5. Token approval: approve each token once, up front, as an ops step, plus a check right before burning so a missing approval fails with a clear error instead of a confusing revert.
  6. Dust (settled): the sub-nanotoken crumb left over after a burn stays in the bot wallet and gets recorded, rather than being sent back. Returning it would cost a whole separate transaction per redemption for less than one billionth of a token, so we keep it.
  7. Per-asset rollout: the orchestrator is switched on one asset at a time, not all at once. We can pilot it on a single low-volume asset in production while every other asset keeps the proven old path, and if something goes wrong we roll back just that one asset. The liquidity bot learns which assets need the new mint signature from the asset-status endpoint it already calls, so the two bots cannot disagree mid-rollout.

The reasoning behind each decision, and the rules for every failure case, are in the spec's Design Decisions and Failure States sections. The migration ticket breakdown, meaning who does what and in what order, stays in Linear on RAI-1215.

Anything else

This spec was hardened with several automated review passes, but the last round of edits was not independently re-reviewed, so it is worth a careful human read before the follow-up tickets build on it. The trickiest part to check is the mint recovery rule in decision 2: when a retry reports the mint was already done, we must confirm it matches the exact token and amount we meant, not just the wallet and a reused number, or we could mark the wrong mint as complete.

Sequencing note: this whole orchestrator change is meant to ship after the issuer wallet moves from Fireblocks to Turnkey (RAI-1123), so it lands once Turnkey is live and Fireblocks is gone. The plan is signer-agnostic, so the parts that mention Fireblocks just mean whatever signer is active at the time, which will be Turnkey.

Checks

By submitting this for review, I'm confirming I've done the following:

  • added comprehensive test coverage for any changes in logic
  • made this PR as small as possible
  • linked any relevant issues or PRs

Summary by CodeRabbit

  • New Features
    • Added full orchestrator-based custody, mint, and burn support alongside the existing vault-direct flow.
    • Status responses now include the active asset vault mode.
    • Documented orchestrator configuration via TOML and added guidance for an admin “close mint” action.
    • Updated user-facing mint/redemption updates and views to reflect orchestrator-mode events.
  • Bug Fixes
    • Improved mode consistency across confirm/recovery paths by using the stored mode from the original operation.
    • Strengthened protections against duplicate/replay and tightened failure reporting, including orchestrator-specific dust handling.

@linear-code

linear-code Bot commented Jul 4, 2026

Copy link
Copy Markdown

RAI-1216

RAI-1215

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • SPEC.md
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bbd6dc64-54ad-4c02-8150-70e94572e136

📥 Commits

Reviewing files that changed from the base of the PR and between d5a7e7f and 79ad55a.

📒 Files selected for processing (1)
  • SPEC.md

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

SPEC.md now documents ST0xOrchestrator as a second custody, mint, and burn path alongside vault-direct mode, including mode-scoped aggregate state, event wiring, service verification, status output, and TOML-based configuration.

Changes

Orchestrator Mode Documentation

Layer / File(s) Summary
Orchestrator contract overview
SPEC.md
Adds the ST0xOrchestrator contract section describing custody replacement scope, role-gated mint and burn entry points, emergency recovery, and per-asset dual-mode configuration.
Mint aggregate state and events
SPEC.md
Updates mint aggregate persisted state, adds the CloseMint admin command, extends mint event shapes and orchestrator-specific mappings, anchors effective mode to persisted mint history, and documents mint request validation and view wiring.
Redemption aggregate state and events
SPEC.md
Updates redemption persisted state and burn-mode derivation, refines dust handling and post-resume submission rules, extends burn failure typing, adds orchestrator burn events, and documents mode-scoped verification and view wiring.
Status and configuration surfaces
SPEC.md
Updates the per-asset status response with vault mode and documents the TOML configuration file and resolution rules for orchestrator migration settings.

Related Issues: Not specified in the provided change data.
Related PRs: Not specified in the provided change data.
Suggested labels: documentation, spec
Suggested reviewers: Not specified in the provided change data.

🐰 Two custody paths now share one spec line,
Mint and burn flows split by mode design,
Status and config now name each lane,
While orchestrator and vault-direct remain plain.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the docs-only update to orchestrator-based mint and burn flows in SPEC.md.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rai-1216-spec-orchestrator-mint-burn-flows

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

JuaniRios commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator Author

How to use the Graphite Merge Queue

Add the label add-to-gt-merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@JuaniRios JuaniRios changed the title RAI-1216: Design & SPEC: orchestrator-based mint/burn flows docs: spec orchestrator-based mint/burn flows [WIP] Jul 4, 2026
@JuaniRios
JuaniRios requested review from 0xgleb and findolor July 4, 2026 02:05
@JuaniRios JuaniRios self-assigned this Jul 4, 2026
@JuaniRios JuaniRios changed the title docs: spec orchestrator-based mint/burn flows [WIP] docs: spec orchestrator-based mint/burn flows Jul 4, 2026
@JuaniRios
JuaniRios force-pushed the rai-1216-spec-orchestrator-mint-burn-flows branch 2 times, most recently from 348050d to cc19963 Compare July 6, 2026 17:42
@JuaniRios
JuaniRios requested review from rouzwelt and removed request for findolor July 6, 2026 20:21
@JuaniRios
JuaniRios force-pushed the rai-1216-spec-orchestrator-mint-burn-flows branch 2 times, most recently from 82ce67f to bb80be2 Compare July 6, 2026 21:06
Comment thread SPEC.md Outdated
@JuaniRios
JuaniRios force-pushed the rai-1216-spec-orchestrator-mint-burn-flows branch 4 times, most recently from 7ca826e to cc91de4 Compare July 7, 2026 19:06
@JuaniRios
JuaniRios marked this pull request as ready for review July 7, 2026 19:17

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
SPEC.md (1)

2341-2353: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Show the orchestrator recovery branch in the state machine.

OrchestratorMintRecovered is documented in the mapping table, but the mint state diagram never shows that recovery success path. Add the transition here so the state machine matches the new orchestrator behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@SPEC.md` around lines 2341 - 2353, The mint state machine diagram is missing
the orchestrator recovery success path referenced by OrchestratorMintRecovered,
so update the state transitions in SPEC.md to show how the recovery branch
returns to the normal flow. Add the appropriate recovery transition alongside
the existing MintingFailed recovery paths so the diagram matches the behavior
documented in the mapping table and the OrchestratorMintRecovered flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@SPEC.md`:
- Around line 2341-2353: The mint state machine diagram is missing the
orchestrator recovery success path referenced by OrchestratorMintRecovered, so
update the state transitions in SPEC.md to show how the recovery branch returns
to the normal flow. Add the appropriate recovery transition alongside the
existing MintingFailed recovery paths so the diagram matches the behavior
documented in the mapping table and the OrchestratorMintRecovered flow.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8250777d-9a17-4f3d-b14e-7ebc5cae8a63

📥 Commits

Reviewing files that changed from the base of the PR and between e19dba3 and cc91de4.

📒 Files selected for processing (1)
  • SPEC.md
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: build
🧰 Additional context used
📓 Path-based instructions (2)
*

⚙️ CodeRabbit configuration file

Focus on providing constructive criticism. Whenever you see a suboptimal approach, suggest more idiomatic or robust alternative(s). Flag potential footguns. Suggest FP alternatives to mutable/imperative code. Point out architectural flaws like leaky abstractions, tight coupling, wrong level of abstraction, poor type modeling, over-abstraction, unclear domain boundaries. Code should generally be organized based on business concerns rather than technical aspects - suggest improvements if you find violations. Point out gaps in test coverage but suggest tests that are not too coupled to the implementation and actually test domain invariants and business logic

Files:

  • SPEC.md
**/*.md

⚙️ CodeRabbit configuration file

Focus on the contents of the docs and not on cosmetic things like markdown formatting. We use markdown files for various docs including but not limited to the north star system specification, SPEC.md, the plan for how to get there, ROADMAP.md, guidelines for AI contributors, AGENTS.md, project overview and instructions for human contributors, README.md. Think about the target audience of a document when deciding what comment to leave. For specifications and designs, suggest potential product, architectural, and UI/UX improvements. For plans, suggest changes that would make things more parallelizable and deliverable-focused. For instructions, suggest better rules and guidelines and point out missing instructions. In all cases, flag needless bloat, prefer clear concise writing, and consider the structure of the document and order of the sections

Files:

  • SPEC.md
🔇 Additional comments (2)
SPEC.md (2)

1962-1969: 🗄️ Data Integrity & Integration

Drop this comment — ORCHESTRATOR_ASSETS is already the single source of truth for vault_mode.

			> Likely an incorrect or invalid review comment.

377-386: 🎯 Functional Correctness

No issue: mint mode is already anchored at Initiated, and Recover already transitions back to CallbackPending.

			> Likely an incorrect or invalid review comment.

@JuaniRios
JuaniRios force-pushed the rai-1216-spec-orchestrator-mint-burn-flows branch 2 times, most recently from a51ce44 to d5a7e7f Compare July 7, 2026 23:32

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
SPEC.md (1)

2351-2386: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Add Closed to the persisted mint state.

The state machine now introduces Closed, but StoredMintRequest::MintStatus still has no way to represent it. That leaves the new CloseMint terminal path without a backing storage state, and the schema below still reads as if nothing changed.

Proposed doc update
 enum MintStatus {
     PendingJournal,
     JournalCompleted,
     Minting,
     CallbackPending,
     Completed,
+    Closed,
     Failed(String),
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@SPEC.md` around lines 2351 - 2386, Add persisted support for the new Closed
mint state by updating the StoredMintRequest/MintStatus documentation and schema
so it explicitly includes Closed alongside the existing terminal states. Locate
the MintStatus enum in the StoredMintRequest section and adjust the surrounding
state model text to reflect that CloseMint transitions can now persist as
Closed, ensuring the documented storage representation matches the updated state
machine.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@SPEC.md`:
- Around line 2351-2386: Add persisted support for the new Closed mint state by
updating the StoredMintRequest/MintStatus documentation and schema so it
explicitly includes Closed alongside the existing terminal states. Locate the
MintStatus enum in the StoredMintRequest section and adjust the surrounding
state model text to reflect that CloseMint transitions can now persist as
Closed, ensuring the documented storage representation matches the updated state
machine.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fa958107-2aa9-47cb-9a8a-9a1d143d4292

📥 Commits

Reviewing files that changed from the base of the PR and between cc91de4 and d5a7e7f.

📒 Files selected for processing (1)
  • SPEC.md
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: static
  • GitHub Check: test
  • GitHub Check: build
🧰 Additional context used
📓 Path-based instructions (2)
*

⚙️ CodeRabbit configuration file

Focus on providing constructive criticism. Whenever you see a suboptimal approach, suggest more idiomatic or robust alternative(s). Flag potential footguns. Suggest FP alternatives to mutable/imperative code. Point out architectural flaws like leaky abstractions, tight coupling, wrong level of abstraction, poor type modeling, over-abstraction, unclear domain boundaries. Code should generally be organized based on business concerns rather than technical aspects - suggest improvements if you find violations. Point out gaps in test coverage but suggest tests that are not too coupled to the implementation and actually test domain invariants and business logic

Files:

  • SPEC.md
**/*.md

⚙️ CodeRabbit configuration file

Focus on the contents of the docs and not on cosmetic things like markdown formatting. We use markdown files for various docs including but not limited to the north star system specification, SPEC.md, the plan for how to get there, ROADMAP.md, guidelines for AI contributors, AGENTS.md, project overview and instructions for human contributors, README.md. Think about the target audience of a document when deciding what comment to leave. For specifications and designs, suggest potential product, architectural, and UI/UX improvements. For plans, suggest changes that would make things more parallelizable and deliverable-focused. For instructions, suggest better rules and guidelines and point out missing instructions. In all cases, flag needless bloat, prefer clear concise writing, and consider the structure of the document and order of the sections

Files:

  • SPEC.md
🔇 Additional comments (1)
SPEC.md (1)

1484-1561: 🗄️ Data Integrity & Integration

Verify the burn-verification API update is landed everywhere.

This section documents a 4-argument verify_burn_tx(..., expected_proof) contract, but the supplied VaultService / BurnManager snippets still show the 3-argument form. Please confirm the implementation ticket updates the trait and every caller atomically; otherwise the mode-scoping guarantee here will drift from the code.

@JuaniRios
JuaniRios force-pushed the rai-1216-spec-orchestrator-mint-burn-flows branch from d5a7e7f to 16dc218 Compare July 7, 2026 23:49
Comment thread SPEC.md
Comment thread SPEC.md Outdated
Comment thread SPEC.md Outdated
Comment thread SPEC.md Outdated
Comment thread SPEC.md Outdated
@JuaniRios
JuaniRios force-pushed the rai-1216-spec-orchestrator-mint-burn-flows branch 4 times, most recently from 4849f1c to 9ed1fa8 Compare July 16, 2026 18:48
@rouzwelt
rouzwelt force-pushed the rai-1216-spec-orchestrator-mint-burn-flows branch from 8e89f09 to 79ad55a Compare August 13, 2026 21:34
@rouzwelt rouzwelt mentioned this pull request Aug 14, 2026
3 tasks
@graphite-app

graphite-app Bot commented Aug 14, 2026

Copy link
Copy Markdown

Merge activity

  • Aug 14, 3:24 PM UTC: rouzwelt added this pull request to the Graphite merge queue.
  • Aug 14, 3:26 PM UTC: CI is running for this pull request on a draft pull request (#337) due to your merge queue CI optimization settings.
  • Aug 14, 3:26 PM UTC: Merged by the Graphite merge queue via draft PR: #337.

@graphite-app graphite-app Bot closed this Aug 14, 2026
@github-actions github-actions Bot added the externally-merged Graphite MQ merged this PR; Linear should treat the close as a merge label Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

externally-merged Graphite MQ merged this PR; Linear should treat the close as a merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants