mentorship2022
mentorship2022 copied to clipboard
Automated Market Maker
Exercise name: Automated Market Maker
Assignment #: 7
Track: Smart contracts
Testing framework: Foundry
Deployment framework: Foundry (forge create)
Node provider:
Target network:
Assignment summary
An Automated Market Maker facilitates trade between two ERC20 tokens (X and Y), supplied on construction. The AMM itself is an ERC20 token as well.
There are five user-facing functions, and no privileged accounts:
- Init: Supply x tokens of X and y tokens of Y to the contract. Mint z AMM tokens to sender, with
z = x * y
. Can only be called once. - Mint: x and y are supplied to the contract in the same proportion as the respective reserves of the contract, called x_0 and y_0. This can be expressed as
x_0 / x == y_0 / y
. Mint z AMM tokens to sender as the proportion of their deposit to the AMM reserves, which can be expressed asz = x / x_0
. - Burn: z AMM tokens are burned. The AMM sends x and y tokens to the caller in the proportion of tokens burned to AMM total supply.
- Sell x: The user provides x tokens of X. If x_0 and y_0 are the AMM balances of X and Y, the AMM sends y to the user so that
x_0 * y_0 == (x_0 + x) * (y_0 - y)
. - Sell y: The user provides y tokens of Y. If x_0 and y_0 are the AMM balances of X and Y, the AMM sends y to the user so that
x_0 * y_0 == (x_0 - x) * (y_0 + y)
.
Additional Details
Peripheral Goals