How an AMM works
Every trading pair on RivrDEX has a liquidity pool — a smart contract holding reserves of two tokens (call them X and Y). The price of each token is determined entirely by how much of each token is in the pool at any moment. When you swap token X for token Y:- You deposit X into the pool.
- The pool releases Y to you.
- The ratio of X to Y shifts, which changes the price.
The constant product formula
RivrDEX uses the same formula that Uniswap v2 pioneered, adapted for Vara Network’s WASM runtime:x— reserve of token X in the pooly— reserve of token Y in the poolk— a constant that must hold before and after every tradedx— amount of token X you send indy— amount of token Y you receive
x * y must always equal k. This means the pool can never be fully drained of either token — the price of the scarcer token rises asymptotically as supply falls.
Price impact
The larger your trade relative to the pool’s total liquidity, the more you shift the token ratio — and the worse your effective price becomes. This is called price impact.A trade that is 1% of the pool’s reserves will have noticeably worse pricing than a trade that is 0.1%. For large trades, consider splitting your order into smaller chunks.
Slippage
Between the time you submit a transaction and the time it is executed on-chain, other trades may occur and shift the price. The difference between your expected price and the executed price is slippage. You can set a slippage tolerance in the RivrDEX interface. If the price moves beyond your tolerance before your transaction is included, the swap will revert rather than fill at an unfavorable rate.Price impact vs. slippage
| Concept | Cause | When it happens |
|---|---|---|
| Price impact | Your trade size relative to pool depth | Always — built into the formula |
| Slippage | Other trades moving the price between submission and execution | Only when the chain is active between your submit and confirmation |