Calculation Methodologies
Exchange Rate Calculation
We use the formula below to calculate the exchange rate:
rcv = a * B / (A + a)
rcv_net = rcv * (1 - fee)
where a
is the amount of token X sent by swapper and A
is the total amount of tokens X in the pool before the swap
Then, the exchange rate is simply lim a -> 0 (rcv / a)
which equates to B/A
.
In terms of how much a user shall receive b
given a
supplied:
b = a * B / (A + a) * (1 - fee)
Asset Price Calculation
Internally, a fixed pricing algorithm is used to calculate the spot $USD price of assets swapped via the Pact AMM pools. To achieve this the algorithm tracks every SWAP pool call, distinguishing between swaps with:
Stablecoin Swaps (USDT or USDC) and;
General Swaps (all other assets)
Stablecoin Swaps
For swaps with either USDT or USDC (let’s call them STABLE), it assumes the stablecoin has price of $1 and uses the following formula:
is the price of STABLE (1$)
is a total number of STABLE in pool after SWAP
is a total number of asset in pool after SWAP
asset’s decimals
STABLE’s decimals
General Swaps
For swaps between other assets, the price will only be calculated if there has been a prior SWAP app call to the STABLE/A
or STABLE/B
pool, because in this case A/B
already have an implicit price calculated. From here, the formula is similar:
is the price of B
calculated from SWAP app call in STABLE/B
pool
is a total number of A
in pool after SWAP
is a total number of B
in pool after SWAP
is A
’s decimals
is B
’s decimals
Note: If there are no STABLE/A
or STABLE/B
pools, then the price won't be calculated and the value will be set to "-".
Last updated