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

Use CoW in auto_deposit and auto_withdraw #397

Open
kongzii opened this issue Sep 11, 2024 · 1 comment
Open

Use CoW in auto_deposit and auto_withdraw #397

kongzii opened this issue Sep 11, 2024 · 1 comment

Comments

@kongzii
Copy link
Contributor

kongzii commented Sep 11, 2024

Now, as there is a CoW Python client, we should be able to use it for auto-deposit/withdraw.

Currently, it works by using native contract methods. Each agent starts with N xDai in his wallet and then:

  1. If it's betting on wxDai market, it uses wxDai contract's deposit function to get them.
  2. If it's betting on the sDai market, it first needs to get some wxDai as in (1) and then use sDai contract's deposit function to further convert wxDai into sDai.

After the market is closed, agent keeps the funds in wxDai (so on wxDai markets, it will do nothing, on sDai markets, it will withdraw sDai into wxDai).

This logic is fine as far as there are only wxDai and sDai markets, but fails on other tokens (as xDai can not be just deposited into wETH for example).

To fix it, we could just use CoW swap.

Agent would keep all his funds in xDai, and when betting on some market, it will use CoW to get that market's tokens. After the market is closed, it can use CoW again to convert it back to xDai.

This way, we can support any collateral token if it's available on CoW.

Good property of this is that we can keep the bet amount-logic in xDai. E.g. we can decide how many xDai we want to bet, then CoW will get us an equivalent amount of the other token, and then we can just bet it.

This should simplify auto_deposit and auto_withdraw functions a lot.

One thing to keep in mind is that we should have some token whitelist to prevent attackers stealing of agent's funds by creating markets in fake tokens, and then forcing the agents to buy them with a real-valued xDai.

@gabrielfior
Copy link
Contributor

Reference to Cow client
https://github.com/cowdao-grants/cow-py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants