Skip to main content
This guide walks through the complete lifecycle of a Delivery vs. Payment (DvP) settlement, from instruction submission to autonomous on-chain finalization.

What we are building

A tokenized private credit settlement where:
  • Seller delivers 100 tokens of a private credit fund
  • Buyer pays 50,000 USDC
  • Both legs settle atomically - either both complete or neither does

1. Browse available templates

Templates define the settlement workflow and are pre-configured by KeyStone. Browse the available templates to find the right one for your use case.
Pick the template that matches your settlement type. For a standard DvP settlement, use the dvp-standard template. Note the slug field - you will reference it when submitting instructions.
Templates are managed by KeyStone admins. If you need a custom template for your use case, contact your KeyStone representative.

2. Submit the seller instruction

The seller’s platform submits their side of the trade:
Save the returned trade_reference (e.g. KS-abc123...).

3. Submit the buyer instruction

The buyer’s platform submits the counterpart instruction:
The idempotency_key ensures safe retries. If you send the same key twice, the API returns the existing instruction instead of creating a duplicate. Keys starting with match- are reserved for keys KeyStone derives and are refused with 422.
The response includes status: "matched" and a settlement_id. The settlement is created automatically; it is registered on-chain once compliance clears.

4. Watch compliance run

After confirmation, the settlement engine screens all parties through LSEG World-Check (entity) and CipherOwl (wallet). Results are attested to the ComplianceRegistry on-chain, and the contract enforces that compliance must pass before the settlement can advance. If a party is flagged, the settlement pauses at COMPLIANCE_CHECKING. A compliance officer reviews and submits a decision:
If rejected, the settlement transitions to ROLLED_BACK.

5. Deposit to escrow

When the settlement reaches AWAITING_DEPOSITS, both parties deposit their assets directly to the escrow smart contract on-chain. For each deliver leg, call POST /v1/settlements/{id}/legs/{leg_index}/deposit-calldata to obtain pre-encoded depositLeg calldata with the deposit secret embedded, plus the ERC-20 approval calldata. Your platform submits both transactions through its custody provider (such as MPC wallets or any signing infrastructure). Settlement reads never include the deposit secret; the calldata endpoint is the only place it leaves the API. KeyStone is not involved in the deposit step. The escrow contract verifies keccak256(abi.encode(msg.sender, depositSecret)) == depositKey to authorize the deposit - the key binds both the depositor wallet and the secret, so a leaked secret is useless from any other wallet.

6. Contracts handle the rest

Once every leg is deposited, the KeystoneSettlement contract takes over autonomously:
  1. The last required deposit executes the settlement inline, provided the on-chain compliance gate has passed
  2. The contract pays every leg to its recipient bound at registration - one atomic transaction, all-or-nothing
  3. Tokens go to the buyer’s wallet, USDC goes to the seller’s wallet
  4. Settlement transitions to FINALIZED

7. Check the result

Track progress in the KeyStone Dashboard under Settlements, or via the API:

What if something goes wrong?

  • Compliance rejection - Settlement ends in REJECTED. No deposits were made at that point.
  • Deposit timeout - If deposits are not received by timeout_at, the settlement transitions to TIMED_OUT and partial deposits become reclaimable. The operator or any depositor can trigger the timeout on-chain; it cannot be paused.
  • Execution failure - The escrow contract rolls back, returning all deposits to their original owners.
Every failure path is deterministic and recorded in the event history. No funds are ever locked indefinitely.

Core Concepts

Deep dive into settlements, templates, and the state machine.

Submitting Instructions

Full guide to instruction submission, confirmation, and cancellation.