TONSWAP Risk Engine

Fri Nov 07 2025

TONSWAP Risk Engine

First-release designπŸ”—

Updated September 17, 2026. This article describes the first-release implementation. Full release qualification and a fresh testnet deployment are in progress; source code and Sandbox tests alone do not establish a working public deployment.

TONSWAP combines a DLMM DEX, a stableswap DEX, a launchpad, perpetuals and fully funded options. These products have different financial obligations. Its risk engine adds shared controls where a product can create liabilities, while each product continues to enforce its own custody, pricing and settlement rules.

Three contracts divide that work. The Risk Controller accepts authenticated observations, computes a Global Risk Index and grants bounded admission allowances. The Control Mesh computes and delivers parameter updates. The RiskVault holds actual collateral and reserves it for accepted liabilities. A risk score or an authorization can never replace funded backing.

The decisions and their checks run on-chain. Progress depends on funded incoming messages, product activity and permissionless sponsors. TON contracts do not wake themselves on a timer, and messages between contracts can be delayed, bounce or arrive out of order. Automation therefore has explicit funding, bounded work and durable recovery paths.

Independent observations and freshnessπŸ”—

The Risk Controller supports a bounded registry of scalar sources. Each registered source has its own producer identity, sequence number, observation time and freshness limit. A spot report updates its registered metric; it cannot erase a previously reported perps or insurance observation by supplying zeros for other products.

Missing and expired observations remain distinguishable from fresh low stress. In particular, a zero Global Risk Index is meaningful only when the required observations are current. New exposure is denied when a policy's required sources are missing, stale or acutely stressed.

Smoothing and posture transitions depend on elapsed chain time. Repeated messages in the same second cannot skip the configured smoothing or escalation window. Recovery has separate hysteresis and timing requirements. The five postures are Green, Amber, Orange, Red and Black. Acute stress can deny new exposure immediately while the smoothed global posture changes according to its time window.

Read-only getters expose source clocks, freshness and acute flags, scores, posture and configuration. A dashboard must display those conditions alongside the score; a cached green label cannot establish current admission eligibility.

Finite admission backed by real collateralπŸ”—

Production Perps and Cover use finite policy leases. A lease binds the controller, product, scope, relevant versions, fixed time epoch and gross notional allowance. Refreshing a lease during the same epoch cannot restore spent allowance or loosen a denial. A direction flip consumes gross new exposure instead of hiding it behind a net position change.

Admission also requires the product's own checks and an accepted RiskVault reservation. Perps revalidates the current oracle, policy, market and user limits when asynchronous replies arrive. A request that cannot complete retains an exact refund and reservation-release path. Duplicate or reordered replies cannot activate an unbacked position or pay the same user twice.

Risk reductions, settlement, maintenance closes and margin additions do not require a new exposure allowance. They still follow their own pricing, custody and funding rules. Margin withdrawals that leave a position open must satisfy current admission collateral requirements and a live policy. Full-close withdrawals remain available without a new lease.

This replaces the earlier generic intent/authorization-receipt description. The first release does not centrally approve every swap or burn a generic capability token for each fully funded option purchase.

Perpetuals: isolated trader and LP fundsπŸ”—

Each position has isolated trader margin and a separately funded LP allocation in the RiskVault. One position cannot spend another position's margin. Price profits and funding claims are paid from that position's LP allocation, rather than being credited as imaginary cash in the engine.

The initial market is configured with a 0.5Γ— maximum leverage and an LP maintenance floor of 15% of remaining entry notional. A position requires a full close when trader equity falls below maintenance, funding remains unpaid, or its LP allocation reaches the maintenance floor. An oracle gap can exhaust an allocation; a payment cannot exceed its remaining funded backing. These termination and payment limits are part of the market's trading terms.

Collected trader losses reach LP collateral only after an actual token transfer and its authenticated deposit receipt. Profit payments likewise require the beneficiary's actual wallet settlement. An emitted message or an updated accounting counter is insufficient evidence of payment.

Funding accrues at the previous authenticated rate only through that observation's remaining validity, at most 600 seconds in the first-release configuration. A new observation installs a rate for future time; it cannot charge that new rate across an earlier idle period. Missing observation intervals accrue zero. Opposite funding claims cancel before cash collection, and unpaid funding offsets the bounded LP claim and forces a full close.

The engine admits at most 128 live positions. A funded maintenance call visits at most four positions and attempts at most one full close, then retains its cursor for the next call. This keeps expensive settlement work within the qualified execution budget. Progress still requires timely oracle observations, delivered messages and sufficient funding.

Higher leverage, larger exposure limits or a different market structure require fresh economic qualification. These initial limits do not establish safety for arbitrary assets or liquidity depths.

How the other products participateπŸ”—

ProductFirst-release risk integration
T3Authenticated controls for mint quotas, fees, collateral haircuts and redemption throttling, plus local custody and reserve checks. Two configured relative TWAP checks, USDT/T3 and USDC/T3, can deny minting when their observations are missing or outside limits. KUSD has no relative-price coverage in this release.
Spot routerAuthenticated scalar telemetry with local settlement, slippage and route limits. Spot swaps do not consume a central risk lease, and the router does not receive a central TWAP-slicing directive.
OptionsFully funded writer custody and local reservation limits. A purchase can reserve only available writer backing, and payout is bounded by its locked collateral.
CoverActual premium custody, scoped controller admission and funded RiskVault liability reservations. The configured issuer still attests LP ownership and range facts; public permissionless LP-NFT underwriting is not established by this release.
GasVaultFunds registered, bounded jobs, including the canonical Control Mesh heartbeat, and records dispatch and refund accounting.
Insurance and fee distributionReceive authenticated, bounded Mesh controls with exact delivery receipts where required.

T3's pool observations compare T3 with its collateral tokens. They are not an independent external USD oracle and cannot detect all collateral tokens declining together against USD. Local collateral checks and a shared risk index do not remove that economic dependency.

Funded control and asynchronous recoveryπŸ”—

A Mesh heartbeat reads its current inputs, applies deterministic solvers and hard clamps, records a sequence and dispatches the relevant messages. GasVault and Mesh use the same tested heartbeat wire format. Callers obtain the required native funding from the current on-chain quote, including destination escrows. There is no universal 0.04 TON heartbeat price.

Updates to separate contracts are asynchronous, even when they share a control epoch. Pre-funding pays for execution; it does not make every product update simultaneous or guarantee delivery. Typed receipts, exact replay checks and durable journals track which actions have completed. Independent safety updates can continue while a monetary transfer remains uncertain. Unfunded automatic product issuance is excluded.

Unused native value can return to its sponsor. Attached TON is therefore a funding envelope, not a measurement of gas burned. Execution limits and fee assumptions must be checked against the chain configuration used for the release.

Governance configures authenticated producers, policy scopes and bounded control parameters. Validation rejects invalid configurations. This is an authority boundary: deterministic execution does not make every governance choice economically sound. Tightening an admission limit does not retroactively alter maintenance margin or manufacture a liquidation, and operators cannot inject arbitrary manual control messages as a substitute for the authenticated control path.

What establishes a working deploymentπŸ”—

Verification must cover both contract behavior and the deployed application. Contract tests exercise source isolation, timing, stale and acute denial, lease exhaustion, reservation acceptance and rejection, replay, delayed replies, refunds, physical token conservation and bounded maintenance. These tests include real product contracts; constructed oracle histories remain test inputs.

A release additionally needs freshly compiled and qualified code, real funded buckets, a genuine oracle observation period, fresh required sources, and actual user admission and exit transactions. The same original transaction graphs must support settlement readers. The published manifest, indexer, frontend and deployed contract hashes must identify the same release.

Live getters can show current wiring and balances. They cannot by themselves prove that a product consumed its allowance, that a profit was paid, or that a dropped-message recovery path works. Release evidence must keep those claims separate.

The engine limits accepted exposure and enforces funded settlement. It cannot guarantee the absence of market loss, oracle manipulation, network delay or implementation defects. Its practical safety depends on the specific qualified markets, collateral, configuration and operating conditions.

We use only necessary cookies to give you the most relevant experience.

LearnΒ more