CenturionDEX
Launch App

Pricing

Last modified:

How prices are determined

Each CenturionDEX v2 pair is a liquidity pool — a smart contract holding balances of two tokens and enforcing rules around deposits and withdrawals via the constant product formula. When a token is withdrawn (bought), a proportional amount of the other must be deposited (sold) to maintain the invariant. The ratio of tokens in the pool, combined with this formula, determines the execution price of every swap.

Pricing in V2

V2 core contracts do not contain pricing functions. Instead, pairs verify the invariant directly (accounting for fees) after each trade. This clean separation of concerns means the core simply enforces its own safety, while all price calculation lives in the periphery.

The Library provides functions for computing prices, and the Router uses them in every swap method.

Safe swap execution

A naive contract that looks up the current reserve ratio and trades against it is vulnerable to sandwich attacks: an attacker inserts transactions before and after the victim's trade, profiting from the artificially moved price. The attack is cheap and low-risk unless the pool is very liquid or the trade is very small.

The defense is straightforward: use a price oracle to bound acceptable execution prices. The simplest oracle is an off-chain observation of the current market price, passed into the transaction as a minimum output. This is how the CenturionDEX frontend works — it quotes a price, applies a user-configurable slippage tolerance (default 0.5%), and submits the trade through the Router with a minimum output guarantee.

For programmatic integrations without access to off-chain prices, CenturionDEX V2's native TWAP oracle provides manipulation-resistant on-chain prices.

Exact input

To send an exact amount of input tokens and receive as many output tokens as possible, use getAmountsOut. SDK equivalent: getOutputAmount or minimumAmountOut for slippage calculations.

Exact output

To receive an exact amount of output tokens while spending as few input tokens as possible, use getAmountsIn. SDK equivalent: getInputAmount or maximumAmountIn for slippage calculations.

Swap to price

For advanced use cases where you want to trade a pool to a target price, see ExampleSwapToPrice.sol.