Pools are calculated using the formula X * Y = K, where X is one side of the equilibrium pool, Y is the other side of the equilibrium pool, coefficient K is the product of the two sides of the pool. We know that during trading, the coefficient K remains unchanged, which means that when the user sells / buys an asset X, we can draw up the equation:
If the user sells asset X, he accordingly sends asset X to the contract, the amount of the asset X sent will be Z, and the amount he will receive will be H
(X + Z) * (Y - H) = K
We know the sums X (the size of the equilibrium pool from the X side), Z (the amount of token that entered the equilibrium pool from the X side), Y (the size of the equilibrium pool from the Y side), and K (the equilibrium coefficient of the pool). This means we can always calculate how many tokens H the user will receive.
The same when buying token X:
(X - Z) * (Y + H) = K
In this equation, we know X (the size of the equilibrium pool from the X side), Y (the size of the equilibrium pool from the Y side), H (the amount of token that entered the equilibrium pool from the Y side), and K (the pool equilibrium coefficient), which means we can always calculate how many Z the user will get.
Listing of all coins on the COFFE SWAP exchange is carried out to the CFF network token, which means that y will always be a CFF coin. Thanks to this, the user has the ability to change any asset for any in just one operation for the user, in fact, two operations will take place in the contract - the first operation is the exchange of the user's asset for CFF, the second operation is the exchange of CFF for the target asset of your choice.
More details about the mathematical model can be found in the technical documentation of the exchange and on the exchange website https://coffe.one