How swaps work
Now we have some sort of 'pool' - we need to transact with it.
Good to know: The accounting process will have to be calculated off-chain. The pool ratio would get incredibly complex for the average user. But with further advances this could be workable.
The 'swap' function will have to be added to the protocol.
The swap function will be a variant of 'transfer' but with some changes.
For example lets add 1,000 "SVBL" and 1,000 "ordi":
Now, lets swap 10 "SVBL" for 10 "ordi" and see what happens.
Let me explain this function:
10 "SVBL" has been taken from your balance from "input", which has been identified and verified using "veri".
10 "SVBL" has been added to "SVBL-ordi" pool.
"amt-2" has been set to 10, which is the output amount, no need to verify or identify the "tick" is this case as it has already been verified using the pool inscription number "veri-2".
10 "ordi" will be returned to the user.
The "SVBL-ordi" pool now contains 1010 "SVBL" and 990 "ordi", the 1:1 ratio has been changed. This will have to be calculated off-chain which could have issues in itself, such as latency.
Another issue could be input to the pool first then a swap, could skew the ratio and render the transaction invalid.
Two transactions in the same block would cause the first one to be prioritized, which would possibly cause the seconds tx invalid.
In these early iterations of possible functions, a generous slippage would have to be applied off-chain. Unless specified with another function.
For example:
In this case, a 15% slippage would be applied.
Last updated