0xMiden / 0xMiden/protocol

Make standard `SWAP` note "in-flight" fillable

Abierto
#2,536 3 comentarios 0 reacciones 0 asignados Ver en GitHub
standards
Lenguaje dominante
Rust
Estrellas
132
Forks
167
Merge medio
1 d 23 h
PR fusionados (30 d)
110

Descripción

### Feature description

## Background:

Currently for an `Account` to consume the standard `SWAP` note, the `Account` must have the `REQUESTED_ASSET` amount in the account's asset vault.

This is suboptimal from a liquidity point of view, since it is possible for `SWAP` notes to use their liquidity to fill each other.

Say there are two "complimentary" `SWAP` notes:
* `SWAP` note 1: 10 token A for 5 token B
* `SWAP` note 2: 2.5 token B for 5 token A

These two `SWAP` notes can be filled against each other using the liquidity of the other `SWAP` note. These two `SWAP` notes agree on the same price. If they did not agree on the price, the would not be complementary. Additionally, it is also possible for the sell price of one `SWAP` note to be lower than the buy price of another `SWAP` note. This would result in a potential arbitrage opportunity for the solver matching these two `SWAP` notes.

With the current `SWAP` note, the `Account` which consumes these two `SWAP` notes must have 5 tokens B and 5 tokens A, when their net asset delta will be 0 if they fill these two notes against each other.

Filling `SWAP` notes 1 & 2 against each other would produce the following notes:
```mermaid
flowchart LR
I1[SWAP1
offer 10A / want 5B] --> TX((Maker Account))
I2[SWAP2
offer 2.5B / want 5A] --> TX

TX --> O3[SWAP1'
offer 5A / want 2.5B]
TX --> O1[P2ID: 2.5B -> SWAP1 owner]
TX --> O2[P2ID: 5A -> SWAP2 owner]

```

It is not necessary for the `Maker Account` to have any assets at all in their asset vault to fill these two `SWAP` notes against each other. The ability to fill `SWAP` notes against each other, is what I refer to as "in-flight" `SWAP` note filling.

________

## Proposal:

Make it possible for `SWAP` notes to be filled "in-flight` against each other. [I opened a PR](https://github.com/0xMiden/protocol/pull/1904) a while back which implemented this.

Since we are moving closer to audits, I propose we add this feature to the standard SWAP note. This adds an `if / else` branch to the `SWAP` note which checks if the consuming `Account` has sufficient liquidity in its asset vault to fill the `SWAP` note. If not, the `SWAP` note assumes it is being filled in the context of a batch of `SWAP` notes.

#1904 will need to be refactored to be updated to the latest state of `next`

### Why is this feature needed?

The current `SWAP` note implementation is not flexible for solvers.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.