Prerequisites
- Authenticated with M2M token (Authentication)
- A DvP settlement template available
- Both parties have wallet addresses on a supported chain
- You know the repo economics: tenor, rate, and haircut
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 withtrade_type: "repo_open" and matching repo_terms. 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 is derived, not passed: the closing settlement is due tenor_days after the opening settlement is created.
The closing leg’s repayment amount is also derived - from tenor_days, rate_bps, and the opening payment-leg quantity - so you never pass it explicitly.Step 2: Repo-specific instruction fields
Step 3: Opening settlement processes
The matched instructions create a settlement with:trade_type: "repo_open"repo_termsstored on the settlement- Standard DvP flow: compliance screening, escrow deposits, atomic swap
Step 4: Await maturity
The opening settlement finalizes. KeyStone derives the maturity as the opening settlement’s creation time plustenor_days and checks it on a schedule. 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, KeyStone auto-creates two matching instructions for the closing leg (reversed roles and directions) - no party action is required to create it. The closing settlement then goes through the full flow: 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: The closing payment leg is derived from
tenor_days,rate_bps, and the opening payment quantity (principal + interest) - Linked:
linked_settlement_idties the closing settlement to its opening (andrepo_terms.close_leg_settlement_idon the opening points forward)
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:/related on either leg returns the same pair.)
Error scenarios
See Webhooks for setup instructions.