Comment on page

# 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:
$price_{asset} = \frac{price_{STABLE} * total_{STABLE} * 10 ^{decimals_{asset}}}{total_{STABLE} *10 ^{decimals_{STABLE}} }$
$price_{STABLE}$
is the price of STABLE (1\$)
$total_{STABLE}$
is a total number of STABLE in pool after SWAP
$total_{asset}$
is a total number of asset in pool after SWAP
$decimals_{asset}$
asset’s decimals
$decimals_{STABLE}$
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:
$price_A=\frac{price_B*total_B * 10^{decimals_A}}{total_A * 10^{decimals_B}}$
$price_B$
is the price of B calculated from SWAP app call in STABLE/B pool
$total_A$
is a total number of A in pool after SWAP
$total_B$
is a total number of B in pool after SWAP
$decimals_A$
is A’s decimals
$decimals_B$
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 "-".