OniSwap

Overview

OniSwap is an exchange on Solana where every pool carries a hook, a separate program that the pool calls before and after each swap. The hook can answer with the fee for that trade and record what happened in its own account. This page describes the shape we tested on a local validator on 17 November 2026, with the numbers we measured.

The hook interface

The pool calls the hook with a plain invoke, never with the pool's signature. The call carries exactly one account and a short instruction.

PartWhat it is
AccountThe hook's own state account, writable, not a signer
Instruction dataA phase byte (before or after the swap) and the swap amount as an unsigned 64-bit integer
AnswerOptional return data with a fee in basis points. The pool rejects any fee above 10 percent
call  hook(state_account)  data = [phase: u8, amount: u64]
answer  return_data = fee_bps: u16   // the pool refuses fee_bps > 1000

Attaching a hook

Security shape

A program on Solana can only touch the accounts named in its own instruction. OniSwap hands the hook one account, so the hook has nothing else to work with. The pool state, the vault, the vault's authority, the token program and the trader's wallet all stay out of its reach.

Attack by the hookIn OniSwap's shapeIf the pool forwarded everything
Overwrite the reservesFails, the hook sees one accountFails, the runtime blocks writes to accounts a program does not own
Move vault coins to an attackerFails, vault stays at 1,000,000,000Succeeds, 500,000,000 taken
Call back into the poolFails, the pool program is out of reachFails, the runtime rejects the reentry
Return a 100 percent feeRefused, error 0x109Not tested

The rule that follows is simple. The pool never signs for a hook and never forwards its vaults, its authority or the trader's accounts. All 17 tests and their logs are in the project's spike evidence.

Compute cost

SwapCompute units
Test swap with no hook825
Test swap with a hook called before and after4,772
The two hook calls alone3,947
Swap in the tested security shape with an honest dynamic-fee hook5,439

The test swap moves no SPL tokens, so a production swap costs more. The hook pair stays in the same few thousand units either way, against a 1,400,000 unit ceiling per transaction.

What a hook can still do

A hook can stop swaps in its own pool. In our test an honest hook switched to an endless loop after creation, and every later swap failed. It cannot reach the coins, so the design keeps withdrawing liquidity free of any hook call, and shows each pool's hook upgrade authority. A looping hook fails only its own transaction; another pool swapped right after it in 5,439 units.