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

k = xy Automated Market Maker #7

Open
alcueca opened this issue Aug 13, 2021 · 0 comments
Open

k = xy Automated Market Maker #7

alcueca opened this issue Aug 13, 2021 · 0 comments

Comments

@alcueca
Copy link
Owner

alcueca commented Aug 13, 2021

An Automated Market Maker facilitates trade between two ERC20 tokens, supplied on construction. The AMM itself is an ERC20 token as well.

5 functions:

  • Init: Supply any amount of x and y to the contract. Store a k value as x * y. Mint k AMM tokens to sender. Can only be called once.
  • Mint: x and y are supplied to the contract in the same proportion as the x and y balances of the contract. Mint AMM tokens to sender as the proportion of their deposit to the AMM reserves. (minted = x_supplied / x_reserves). Update k as x_reserves * y_reserves.
  • Burn: AMM tokens are burned. The AMM sends x and y tokens to the caller in the proportion of tokens burned to AMM total supply. Adjust k as usual.
  • Sell x: The user provides x. The AMM sends y to the user so that x_reserves * y_reserves remains at k.
  • Sell y: The user provides y. The AMM sends x to the user so that x_reserves * y_reserves remains at k.

Bonus track: Instead of using transferFrom, make the AMM keep its last known reserves in two state variables. The user transfer into the AMM and then triggers one of the functions. The AMM recognizes the divergence between stored reserve values and actual balances, and infers the surplus came from the user.

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

1 participant