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":

{ 
  "p": "brc-20",
  "op": "deploy",
  "tick-1": "SVBL",
  "veri-1": "430602",
  "tick-2": "ordi",
  "veri-2": "xxx"
  "amt-1": "1000",
  "amt-2": "1000",
  "to": "bc1plklz3qhxuuq66tcwr7wsz2ggdlc7c4hf52d2p9w64j4nrzv35cdqjwsmpk"
}

Now, lets swap 10 "SVBL" for 10 "ordi" and see what happens.

{ 
  "p": "brc-20",
  "op": "swap",
  "input": "SVBL",
  "veri-1": "430602",
  "pool": "SVBL-ordi",
  "veri-2": "xxx"
  "amt-1": "10",
  "amt-2": "10",
  "to": "bc1plklz3qhxuuq66tcwr7wsz2ggdlc7c4hf52d2p9w64j4nrzv35cdqjwsmpk"
}

Let me explain this function:

  1. 10 "SVBL" has been taken from your balance from "input", which has been identified and verified using "veri".

  2. 10 "SVBL" has been added to "SVBL-ordi" pool.

  3. "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".

  4. 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:

{ 
  "p": "brc-20",
  "op": "swap",
  "input": "SVBL",
  "veri-1": "430602",
  "pool": "SVBL-ordi",
  "veri-2": "xxx"
  "amt-1": "10",
  "amt-2": "10",
  "to": "bc1plklz3qhxuuq66tcwr7wsz2ggdlc7c4hf52d2p9w64j4nrzv35cdqjwsmpk"
  "slip": "15"
}

In this case, a 15% slippage would be applied.

Last updated