This guide walks through a complete tokenised repo lifecycle - from opening to maturity to closing - using bilateral instructions and autonomous on-chain execution.Documentation Index
Fetch the complete documentation index at: https://docs.keystoneos.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Authenticated with M2M token (Authentication)
- A DvP settlement template available
- Both parties have wallet addresses on a supported chain
- You know the maturity date and repayment amount for the repo
Flow overview
A repo consists of two linked settlements:- Opening: Both parties submit
repo_openinstructions that match to create the opening settlement - Closing: KeyStone auto-creates a
repo_closesettlement when maturity arrives
Step 1: Submit opening instructions
Both counterparties submit instructions withsettlement_category: "repo_open". The first party receives a trade reference, the second party includes it to trigger matching.
Seller submits first:
trade_reference:
trade_reference:
status: "matched" and includes the settlement_id.
timeout_at controls when the opening settlement times out if not completed.
maturity_at controls when the closing settlement is created after the opening finalizes.
repayment_amount is the exact amount for the closing leg’s payment (principal + interest).Step 2: Repo-specific instruction fields
| Field | Required for repo_open | Description |
|---|---|---|
settlement_category | Yes | Must be "repo_open" |
maturity_at | Yes | When the closing leg should trigger (must be in the future) |
repayment_amount | Yes | Exact closing leg cash amount (principal + interest) |
repo_rate | No | Interest rate (informational, stored in metadata) |
Step 3: Opening settlement processes
The matched instructions create a settlement with:settlement_category: "repo_open"maturity_atandrepo_metadatastored on the settlement- Standard DvP flow: compliance screening, escrow deposits, atomic swap
Step 4: Await maturity
The opening settlement finalizes. KeyStone monitors thematurity_at timestamp. When maturity arrives, the system automatically creates the closing settlement.
Triggering maturity early (admin only)
Administrators can trigger maturity before the scheduled date:Step 5: Closing settlement auto-created
At maturity, both parties submit new instructions for the closing leg (reversed directions). The closing settlement goes through the full flow: matching, compliance re-screening, deposits to escrow, autonomous execution.- Reversed roles: Opening seller becomes closing buyer, and vice versa
- Reversed directions: Deliver becomes receive, receive becomes deliver
- Repayment amount: Payment leg uses
repayment_amountinstead of original price - Linked:
parent_settlement_idpoints to the opening settlement
Step 6: Closing settlement completes
The closing settlement follows the same standard DvP flow:- Compliance screening
- Escrow deposits (buyer deposits bonds, seller deposits USDC with interest)
- Atomic swap (bonds return to seller, USDC + interest returns to buyer)
- Settlement finalizes
settlement.state.finalized for the closing settlement.
Step 7: Query related settlements
At any point, you can query both legs of a repo:Error scenarios
| Scenario | Result |
|---|---|
| Opening compliance rejection | Opening settlement rolls back. No closing settlement is created. |
| Opening deposit timeout | Opening settlement times out. Deposits returned. No closing created. |
| Closing compliance rejection | Closing settlement rolls back. Opening remains finalized. |
| Closing deposit timeout | Closing settlement times out. Deposits returned. Manual resolution needed. |