Open pools (PairPool)
PairPool (bridge/kaspa/contracts/pair_pool.ag) is a constant-product pool between kUSDT and any standard KCC-20
token. Anyone can create one and open it. It has no admin, no guardian, no pause, no circuit breaker and no list of
allowed tokens. One program serves every pool; what differs between pools is their state.
It is a separate program from KasPool, the KAS⇄kUSDT pool, which it does not change.
| Actor | What it is |
|---|---|
PairPool |
A singleton. Its UTXO holds a fixed KAS deposit and nothing else. Its state names the two tokens, both reserves, the shares, the fee owed, the fee key and the opener |
PairPosition |
One per liquidity deposit: a number of shares and an owner key |
The two reserves are one KCC20 state in kUSDT’s family and one in the token’s family, each owned by the pool’s
covenant ID (owner scheme 0x04), with borrowing disabled and a zero extension commitment. The kUSDT reserve’s state
holds the reserve plus the fee owed.
Entries
Section titled “Entries”| Entry | Who | Does | Checks (exact, with 128-bit products) |
|---|---|---|---|
open |
The opener, once | The first deposit: sets the price | The opener’s signature; an empty pool; S = quote_in; the position gets quote_in − 1000 shares, and the 1000 unowned shares stay for good |
buy |
Anyone | kUSDT in, token out | (Q + 0.995·in) · T′ ≥ Q · T; 0.05 % of the input accrues to the fee key |
sell |
Anyone | Token in, kUSDT out | (T + in) · (Q − gross) ≥ Q · T; the fee, 0.50 % of gross rounded up, is kept; the seller’s state holds exactly the rest |
add |
Anyone | Both tokens in, a new position | shares · Q ≤ quote_in · S and shares · T ≤ tokens_in · S |
remove |
The position’s owner | Burns a position | quote_out · S ≤ shares · Q, tokens_out · S ≤ shares · T; S stays ≥ 1000; something of each reserve stays |
sweep |
Anyone | Pays the fee owed to the fee key’s own state | At least 1 kUSDT owed; the reserve itself is untouched; no state of the other token in the transaction |
PairPosition.transfer |
The owner | A new owner | No state of either token in the transaction |
A swap spends the exact pool UTXO it was built on: a competing swap makes it invalid, never worse. Every rounding is in the pool’s favour. Reserves, shares and amounts are at most 2^61 − 1, so a token with any supply and any number of decimals fits.
The fee
Section titled “The fee”0.50 % of every swap, the same as KasPool, always taken in kUSDT: 0.45 % stays in the reserves for the liquidity providers, 0.05 % accrues to the fee key. Adding and removing liquidity pay no pool fee. The fee key has no other power: it cannot change the fee, pause the pool or touch a reserve.
What keeps it safe
Section titled “What keeps it safe”- Both token families are observed exhaustively. Each entry states which states of the two families may be spent and created, and forces each reserve’s successor. An observed state is always on the standard KCC-20 program, so a token on any other holder program cannot be put in a pool: that is the whole listing rule, and the contract applies it.
- Every input of the transaction is checked. Each asks no relative lock and, but for the pool’s own coin, is already in a block; and each is of the pool’s family, a state of one of the two tokens, or a plain Schnorr P2PK coin. So a pool transaction a node’s mempool accepts is one a block can take: no spend can hold the pool’s coin in mempools without ever landing.
- Membership of the pool’s family authorizes nothing by itself. A position’s own entries refuse any token state beside them, and a sweep refuses the other token’s.
A genuine pool
Section titled “A genuine pool”A covenant’s program runs when an output is spent, not when it is made, so a pool cannot check its own genesis. Somebody could publish a PairPool beside positions that were never paid for, and withdraw later deposits with them. The rule is therefore public:
A PairPool is genuine when its genesis transaction made exactly one output of its covenant ID, and that output is a PairPool with zero reserves, zero shares and zero fee owed.
It is checked with one hash. A covenant ID is the hash of the outpoint its genesis spent and of every output that
genesis authorized, with each output’s index, value and script. So pair-check-genesis (see
kusdt-tx) computes the ID that an empty pool alone would have at that outpoint, and
compares. A genesis that also made positions, or a pool born with shares, has another ID. Whoever supplies the
outpoint and the state need not be trusted: wrong numbers give another hash.
The web app, the wallets and the pools index make this check, with two more conditions that make a pool ours: its quote token is kUSDT’s covenant ID, and its fee key is Trestly’s. A pool that fails is never shown.
Several pools for one pair are allowed. Nothing ranks them; a reader shows them all.
The pools index finds a new pool by its genesis. A pool it missed (it started later, or its list of new pools was filled by others) is proven to it instead: anyone hands it the pool’s genesis, state and coins, and the index makes the same check and finds the coins on its own node before it lists the pool. The web app tells the index of a pool before its first deposit, so the index follows it from there, and hands over the proof again afterwards for every pool made in that browser.
What nobody can do
Section titled “What nobody can do”| Pause, stop or close a pool | Nobody. Liquidity providers can always withdraw |
| Change its fee, its tokens or its fee key | Nobody: they are fixed at the genesis |
| Fix a bug in it | Nobody. A flawed pool is left by withdrawing from it |
| Remove a token from the list | Nobody: there is no list |
Limits to know
Section titled “Limits to know”- Anyone can make a token and a pool for it. A token whose maker can mint more can be sold into its pool without limit. A token’s name is what its maker wrote; only its covenant ID identifies it.
- No circuit breaker. kUSDT minted with stolen bridge keys would be real kUSDT to these pools and could buy out their tokens until the bridge is paused on its own side. KasPool has a breaker for that case; open pools do not.
- The unowned shares. 1000 shares belong to nobody, so that much of both reserves stays in a pool for good. A pool’s own output (2 KAS when the web app makes it) and the 1 KAS in each reserve stay too.
- A sweep and a swap in one block. A sweep spends only the kUSDT reserve, so right after an unconfirmed sweep of an unconfirmed swap the two reserves come from two unconfirmed transactions, and the next trade waits for a block (about a second).
- A state sent to a pool’s covenant ID by mistake is not the pool’s reserve: the next trader may take it.
- Small trades can outrun large ones, as in any pool that is one coin: each spend makes the others built on the same coin invalid, and they are built again. The web app tries five times. A pool that somebody moves in every block (it costs them a network fee each time) can keep the web app’s trades and withdrawals from landing for as long as they pay; a transaction built straight from the chain still competes on equal terms.
- An empty token state. Selling all of a token state leaves a state of amount 0 that holds its 1.5 KAS. The web app shows it on the pool’s page and frees the KAS together with another state of the same token.
- More than 200 states of one token. The web app asks the token indexer for a wallet’s first 200 states of a token. A wallet holding more may see less than it holds there.
- Not audited. Internal review rounds are not an audit. See Audit status.
KAS ⇄ token
Section titled “KAS ⇄ token”Two transactions, a second apart: KasPool, then the open pool. They cannot share a transaction (KasPool admits no other covenant’s input) and the second cannot spend the first’s kUSDT before a block has it.