This Decentralized Exchange (DEX) presented here is based on the Uniswap-like exchange presented in this paper. The principle is the one of automated market maker (AMM), that is that the exchange rate from token A to token B is computed automatically.
To exchange qA tokens A against qB tokens B, the DEX establishes a pool of tokens A and a pool of tokens B, from which tokens are withdrawn or credited; if pA and pB are the numbers of tokens A and B in the pools, then the quantity qB of token B received in exchange of a quantity qA of token A is given by the following formula:
This principle is explained in more details in the DEX DApp example.
Caller provides qA tokens tA and the corresponding amount of XTZ is transferred.Liquidity tokens are minted and affected to caller so that it reflects the proportion of transferred XTZ towards the XTZ pool.
Caller redeems qL liquidity token for token tA; 2 transactions are generated :
transfer of XTZ in proportion of the token XTZ pool
transfer of tA tokens in proportion of the token pool