The code is based on the paper: https://www-leland.stanford.edu/~boyd/papers/pdf/cfmm.pdf and part of the source code will refer to equations from that paper.
The main design goal was to be able to create new CFMMs by simply inheriting from a base class and override 2 methods.
- evalTradeFunc - returns the value of the trading function at a speficic point
- evalTradeFuncGradient - returns the gradient vector (partial derivatives) of the trading function at a specific point
The code supports an unlimited number of assets, and also gives an example of a geometric mean AMM with 3 assets.
The code is more of a creative solution to the problem of CFMM rather than a practical one for the following reasons.
- Gas efficiency: by knowing the actual trading function like x * y = C, there could be more gas optimization done
- Security: the CFMMs base class has to rely on predefined tolerance values when checking the changes in the return value from the trading function or from the gradient vector. More analysis needs to be done about the security implication of those tolerance levels.
- Trading function evaluation: evaluating the trading function might exceed the maximum value of uin256, so it requires special care. Instead of evaluating the original trading function, the Nth root of the trading function could be considered.
Currently there are no proper unit tests, only tests that were used for manual testing. Those tests can be run by
pnpm test:mock
Please note that that this project was created based on Zama template and will fail with: Artifact for contract "fhevm/lib/ACL.sol:ACL" not found.
pnpm task:deployGeometricMeanAMM
Please note that that this project was created based on Zama template and will fail with: Artifact for contract "fhevm/lib/ACL.sol:ACL" not found.
- Tests are largely missing.
- Limited documentation.
- All the convenience classes like Router contract or Factory contract are missing.
- Only ERC20 tokens are supported, native ETH is not.
- Fees on Transfer type of ERC20 contracts are not supported.
- No multi hop swapping
- No audit was done
- The Code heavily relies on the overflow/underflow protection implmenented in the solidity compiler starting from version 0.8.