Trade / Swap
Trades happen by interracting with public available Cauldron Liquidity Pools on the Bitcoin Cash blockchain. A trade happens by buying and selling tokens to liquidity contracts deployed by the users of the Cauldron protocol.
There is a 0.3% fee to the liquidity providers for every trade.
Technical
Simple trade
To perform a trade with Cauldron, a transaction takes a Cauldron UTXO as one of its inputs, and then recreates in in one of its outputs.
A transaction that swaps BCH into a token may look like this:
flowchart LR
CauldronInput --> TradeTransaction --> CauldronOutput
UserBCHInput --> TradeTransaction --> UserTokenOutput
TradeTransaction --> UserBCHChangeOutput
This transaction takes a Cauldron input that contains the desired token as input, takes the wanted amount of tokens from it and adds enough BCH to pay for said tokens.
The additional outputs are the tokens that goes into the users wallet and (optionally) BCH change for the unused Bitcoin Cash.
Additional liquidity
It is possible to use multiple Cauldron contracts for additional liquidity. The contract has no limitations on how many Cauldron utxo's that are interreacted with.
flowchart LR
CauldronInput1 --> TradeTransaction --> CauldronOutput1
CauldronInput2 --> TradeTransaction --> CauldronOutput2
CauldronInput3 --> TradeTransaction --> CauldronOutput3
UserBCHInput --> TradeTransaction --> UserTokenOutput
TradeTransaction --> UserBCHChangeOutput
Requirements for a successful trade
For a Cauldron interaction to be successful; the following must hold true.
Re-create the contract The Cauldron contract is re-created in the same output index as it was used as input index.
Constant Market Maker formula must be satisfied
The contant market maker formula must be satisfied for the transaction to be valid. The Cauldron looks at the k
value for both input and output.
kInput
is calculated as follows k = tokens * satoshis
of the input.
kOutput
is calculated as follows k = tokens * (satoshis - fee)
.
Where fee is calculated as abs(satoshis of input - satoshis of outputs) * 0.03
.
The interaction must satisfy the following condition:
kOutput > kInput