-
Notifications
You must be signed in to change notification settings - Fork 265
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
feat: AMM #8644
feat: AMM #8644
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
e81e65b
to
b6ec0d9
Compare
18388c1
to
a7f547c
Compare
d33c3fe
to
577e834
Compare
2e4ece6
to
d4c437e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't have sufficient time to also look at the swap fns, so only left some initial comments.
let amount_in_with_fee = amount_in * 997; | ||
let numerator = amount_in_with_fee * reserve_out; | ||
let denominator = reserve_in * 1000 + amount_in_with_fee; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we're hardcoding the 0.3% swap fee here. It'd be better to receive this as a fouth param (univ2 doesn't do this because their swap fee is immutable, but even if we kept ours immutable I really don't like this way of handling out).
We can do this in a follow up issue if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to keep it immutable as we want to implement here a minimal AMM.
but even if we kept ours immutable I really don't like this way of handling out
Would you like me to store the fee as a constant instead?
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/amm_contract/src/main.nr
Outdated
Show resolved
Hide resolved
417f074
to
0d483c9
Compare
348ab77
to
3b21a31
Compare
7dbd0ad
to
5677cd6
Compare
5677cd6
to
06f429e
Compare
3075b32
to
a404b58
Compare
Superceded by #8644 |
Opening in favor of #8644 due to @benesjan being away on vacation, and that PR using Graphite. Work here starts from commit a404b58, which has been squashed into 81d7607. This is the first implementation of Uniswap v2 style AMM that provides identity privacy. The contract is a single pool for two tokens with a fixed 0.3% swap fee. Adding and removing liquidity is done proportionally to the current ratio, resulting in no price impact and therefore no fees. Swaps can be performed by specifying either the amount in or the amount out. All three operations are completed in a single transaction each by leveraging partial notes. I created #10225 to track pending work. Some of the tasks in that epic are only work that arises from the AMM, but are not technically required to have a fully functioning system: this PR already achieves that. Only a happy-path end to end test is included here, since TXE currently lacks some of the features required in order to properly deal with partial notes. We should later write those as this will be a good test of TXE's capabilities and user experience, given the complexity of the setup. --- I added the e2e to be run on CI on all branches since it combines multiple complex features, and likely contains our largest transactions yet.
Opening in favor of AztecProtocol/aztec-packages#8644 due to @benesjan being away on vacation, and that PR using Graphite. Work here starts from commit a404b58e7d049ee7a56310702046f03a624fd1ee, which has been squashed into 81d7607d9d551aea4d6de78ec3ff535ec5d5a29a. This is the first implementation of Uniswap v2 style AMM that provides identity privacy. The contract is a single pool for two tokens with a fixed 0.3% swap fee. Adding and removing liquidity is done proportionally to the current ratio, resulting in no price impact and therefore no fees. Swaps can be performed by specifying either the amount in or the amount out. All three operations are completed in a single transaction each by leveraging partial notes. I created AztecProtocol/aztec-packages#10225 to track pending work. Some of the tasks in that epic are only work that arises from the AMM, but are not technically required to have a fully functioning system: this PR already achieves that. Only a happy-path end to end test is included here, since TXE currently lacks some of the features required in order to properly deal with partial notes. We should later write those as this will be a good test of TXE's capabilities and user experience, given the complexity of the setup. --- I added the e2e to be run on CI on all branches since it combines multiple complex features, and likely contains our largest transactions yet.
This is an implementation of a Uni v2 style DEX pool. One of the main goals of this PR was to figure out what kind of token flows we will need.
Note for reviewers
I put a lot of comments and some questions in the code. The code does not yet compile as the token is not yet updated with the flows we need but I have a high confidence that it's very close to final.
Problems
There were a couple problems I have stumbled upon:
U128
is too cumbersome to use because of #8271). I currently useu64
everywhere but that is not sufficiently large for DeFi.