Skip to content

Tick

The tick is a price representation of a price level. It is a 24-bit integer that is the log base 1.00001 of the price. This means that the price difference between 2 ticks is 0.1 basis points. The mathematical formula to go from tick to price is:

p=1.00001tickp = 1.00001^{tick}

And the inverse formula to go from price to tick is:

tick=log1.00001(p)=ln(p)ln(1.00001)tick = \log_{1.00001}(p) = \frac{ln(p)}{ln(1.00001)}

Computation

The price represents the ratio of the inbound token to the outbound token. This ratio is completely agnostic of the units/decimals of the tokens. For this reason, we need a wide range of prices. The price representation is a fixed point 128.128 bits integer. On-chain, the only computation we need is to convert the tick to price with binary exponentiation.

Getting the virtual wants amount

The price represents the ratio p=inboundoutboundp = \frac{inbound}{outbound}. The only conversion that has to be done on-chain is the conversion from outbound amount gives to inbound amount. This is used to compute the implicit wants amount, which is the total amount of inbound token an offer is requesting.

Given a price, the outbound amount and units, as well as the inbound units, the wants amount scaled down to the inbound units is computed as follows:

uou_o: units of the outbound token

uiu_i: units of the inbound token

inbound=outboundui×price×uoinbound = \left\lceil \frac{outbound}{u_i} \times price \times u_o \right\rceil

In essence, we round up the result of the division of the raw outbound amount times the price by the inbound units to the nearest integer (the goal is to favor the maker to avoid round downs causing 0 wants).