Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request withdraw, all in-one #851

Open
anxolin opened this issue Jun 10, 2020 · 0 comments
Open

Request withdraw, all in-one #851

anxolin opened this issue Jun 10, 2020 · 0 comments
Labels
Version2 Proposals for the version 2 contract

Comments

@anxolin
Copy link
Contributor

anxolin commented Jun 10, 2020

Reviewing the Gelato issues, I was thinking about the claiming process, and an improvement that we might want to take into account for v2.

Example: 1 batch swap market order

So, there’s situations we want to create an order, and create "Withdraw requests" ahead of time, for example on a 1-batch-swap market order.

Since we don’t know ahead of time the price we will get, or even if we will trade, we don’t know how much of the tokens we will be withdrawing. So the overall timeline looks like this:

[batch 1]

  • Create Order: Trade 100 WETH for 0 DAI, for 1 batch
  • Create future withdraw requests: Withdraw 100 WETH and ∞ DAI in batch 3

Note:

  • 100 WETH --> we account for the possibility of the trade not happening
  • ∞ DAI --> We really don't know how much DAI we will get. So we say, I want to withdraw it all.

[batch 2]

  • Order is active. Solvers work on their solution
  • A Trade happen: 80 WETH for 16.000 DAI

[bath 3]

  • Execute the matured withdraws: Withdraw 80 WETH + 16.000 DAI

The issues

One issue with the above setup is that, because of the Withdraw Request of ∞ DAI in batch 3:

  • If the user has ANY order with DAI as a sell token, no solver will consider my orders for batch 3
  • If the user has ANY deposit of DAI for full-filling other order, it will be automatically withdrew

Possible improvements

3 possible improvements are:

  • Account for received tokens: Accumulate the received tokens in the order information. This way we know the exact amount of tokens we should actually withdraw. A nice thing that comes also from this change, is that we can get the actual price of the order (that can be superior to the limit price)
  • Allow to withdraw before the batch starts: For the example above, we could allow the user to execute the withdraw BEFORE batch 3 (1) (in the last minute of batch 2 all trades are final). This would prevent the issue with solvers/contract ignoring orders that sell DAI in batch 3.
  • Request and withdraw right away: 🚨🚨 (same as above, but to the NEXT leve) In the last minute of the batch 2 (1), we can in theory safely withdraw tokens without waiting for the request to mature.

(1) NOTE: In the above proposal, for not making it more complex, I abused the language a bit. When I wrote "in the last minute of batch 2" I meant "in the last minute of the batch that solves batch 2 that it's in fact minute 4 of batch 3 since we always are solving the previous batch, instead of the current one.

@anxolin anxolin added the Version2 Proposals for the version 2 contract label Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Version2 Proposals for the version 2 contract
Projects
None yet
Development

No branches or pull requests

1 participant