Build a Price Provider
A Price Provider implements the pool's pricing logic and returns bid, ask and reference price.
1. Choose your logic
afterSwap extension to report fills; read pool state to respond to liquidity imbalance.Identify required updates, including for onchain strategies. See Oracles for update infrastructure and anchored pricing for constrained custom pricing in public pools.
2. Implement the interface
interface IPriceProvider {
function token0() external view returns (address);
function token1() external view returns (address);
function getQuote() external returns (
uint128 bidPrice,
uint128 askPrice,
uint128 referencePrice
);
}Tokens: token0 and token1 must match the pool's tokens, in the same order.<br>
Units: Prices are whole token1 per whole token0, as Q64.64 (× 2⁶⁴), whatever the token decimals. With token0 = WETH and token1 = USDC, 2,000 USDC per WETH is 2000 << 64.<br>
Validity: Each quote must satisfy:
0 < bid < askbid < referencePrice < ask(strictly between)- the pool's asymmetry limit: with
r₁ = ref/bid − 1,r₂ = ask/ref − 1andM = 1 + bidAskRefAsymmetryX8/256, the pool requires1/M ≤ r₁/r₂ ≤ M.
bidAskRefAsymmetryX8 can't be 0. At creation it can be at most the factory's creation cap; only the factory owner can set a higher value later. If it is type(uint16).max, the asymmetry check is off and the reference may equal bid or ask.\ \ Failures: If an input is stale or missing, revert. The pool wraps the revert in PriceProviderFailed and the swap fails. An invalid quote makes the pool revert with a specific error. See Price Providers for quote semantics.\ \ State: getQuote() is not view. The pool calls it with a normal call, so it can update state, for example to refresh a cached price or a TWAP. Custom sources read by an APP through staticcall must be static.
Reference price
Use the geometric mid, sqrt(bid \* ask), or your best estimate of fair price.
{% hint style="warning" %} Report an honest reference. LPs' spread on each side and their markouts are measured from it, and so are the curator's and Relatick's fees. Misreporting it can get the pool deprioritized or frozen. {% endhint %}
The reference price must stay within the pool's bidAskRefAsymmetryX8 limit.
3. Test and deploy
Test unequal decimals, rounding, stale or missing inputs, quoting, halt/recovery and both swap directions.
Use the provider's address when you create the pool.
For Relatick routing, keep quotes caller-independent and support zero-origin simulation.
Next: Build an extension.
Last updated 29 days ago
Relatick