Price impact and sandwiches
Every trade moves the price it trades at, and someone else can try to profit from that. This page explains price impact, what a sandwich is, what protects you on GIWA and in GAMA's order books, and the one risk that remains for large orders in thin markets.
Price impact
Price impact is how far your own trade moves the price. A buy pushes the price up as it fills, so the last part of a large buy costs more than the first. The smaller the market, the bigger the move: a launch early on its curve or a pool with little liquidity moves much more than a deep pool.
- Before a swap, the app shows Price impact, including fees.
- A DCA order tells you how much each buy moves the price: "Each buy moves the price about X%."
- Your slippage sets the minimum you receive. If the price moves past it before your trade is included, the trade fails instead of filling at a worse price.
By default the app sets slippage for you: 3% on a curve and 0.5% in a pool, a little more when the trade itself moves the price a lot. It warns you when you set more than 5%: "High slippage can make your trade fill at a much worse price." See Slippage and price impact.
What a sandwich is
A sandwich is a trade wrapped around yours: someone buys just before your buy, so you pay a higher price, then sells just after it at the price your buy pushed up. Their profit is your loss.
On chains with a public waiting room for transactions, attackers watch for pending swaps and wrap trades around them. GIWA has no public mempool: transactions go straight to GIWA's sequencer, which puts them in order, higher priority fees first. Other users cannot see your swap before it is included, so they cannot aim a trade at it.
That does not freeze the price for you. Other trades can still land between your quote and your transaction, and anyone can trade right after yours. Your slippage limit is what bounds how much worse your price can be.
Market orders: what protects them
A DCA order buys on a schedule that anyone can read, so GAMA's order books add their own protections. A security review of the earlier order books showed that, without them, a market order could be sandwiched for more than half of one buy. The current release fills orders this way:
- Only keepers and you. Only GAMA's keepers and the order's owner can fill an order. A stranger cannot choose the moment of your fill.
- A random moment. The keeper starts each interval's buy at a random moment within it.
- A live price check. Just before each fill, the keeper reads the live price and sends the fill with a bound 0.5% worse. If anyone moves the price past that bound before the fill lands, the fill is refused and the keeper tries again a few seconds later. This is the live price check.
- A floor. Each fill must give you at least its value at the live price, less your slippage.
- Your price limit. If you set one, no fill goes past it, whenever it lands.
- A cap on your own impact. A single fill may move the price by at most about 1%. A larger buy is split into sub-fills within its interval.
- One price per batch. Orders with the same route are filled together in one trade at one price, a batch.
Pushing the price before the keeper reads it costs the trading fees both ways, about 2% or more each way in a main pool, and only the keeper knows when it will fill. Your price limit is the bound that holds whatever happens before a fill. See How orders fill.
The reviewed attack, refused
For example, a new wallet bought 0.055 test ETH of a fresh launch on its thin curve while a DCA order was due, then tried to fill the order itself at the price it had pushed up. The order contract refused, because the wallet is not a keeper, so it could not choose the moment of the order's buy.
What they do not stop
Trading ahead of a large, visible order. Your order's size and interval are public. A large DCA order in a thin market keeps pushing the price up with each buy, even when every fill passes the live price check and the impact cap. Anyone who bought before, and holds while your order buys, can sell afterwards at the higher price.
In the same test, the wallet kept its tokens while the order bought, then sold them about three and a half minutes later for 0.05609 test ETH: a profit of 0.00109, about 2%. The profit came from the order's own buying, not from a manipulated fill. GAMA treats this as the ordinary market impact of a large order in a thin market: orders stay public and are not changed for it.
Other limits:
- Nothing pauses a rising price. Buys go on while the price rises, even when your own buying is what raises it. A large order in a thin market can move the price fast. Before you place an order, the app shows how far the whole order would move the price at today's depth, and warns above 10%.
- Older versions. On an older version of GAMA, anyone can fill a market order at a moment they choose. The app warns about such orders and offers to cancel them.
How to protect yourself
- Check Price impact, including fees before every swap. If it is high, trade a smaller amount.
- Keep slippage low, and be wary of anything above 5%.
- Size DCA buys to the market. On a thin curve, use more, smaller buys or a longer interval, so that each buy moves the price little.
- Read what a DCA order would do to the price before you place it: "If it all fills at today's depth, it raises the price about X%, at an average price of …". Above 10%, the form says "This order is large for this market".
- Read the slippage a DCA order shows before you place it: "Each buy fills at the market price, with up to X% slippage." On a route through a pool, Auto grows with each buy's own price impact, so a large buy in a thin pool can allow far more than 5%.
- Set Stop buying above on a DCA order if you do not want to buy above a certain price.
- Remember that a large order is visible to everyone while it runs.
