This repository contains a demonstration of an Automated Market Maker (AMM) system implemented in C++. The AMM system allows users to connect their wallets, check balances, check public ledger, add liquidity, remove liquidity, and perform currency exchanges between U.S. dollars (USD) and Japanese yen (JPY).
The AMM system is designed to facilitate decentralized currency exchanges between USD and JPY using a liquidity pool. It utilizes a block-based approach to record transactions and calculate liquidity, providing a transparent and efficient trading mechanism.
The system includes the following components:
Player
: Represents a user's wallet with balances and staking information.Block
: Stores information about a transaction, including sender, receiver, and amounts.Connect Wallet
: Allows users to connect their wallets and set initial balances.Add Liquidity
: Enables users to become liquidity providers by staking equal amounts of USD and JPY to the pool.Remove Liquidity
: Allows liquidity providers to unstake their funds from the pool.Buy USD
andBuy JPY
: Enables users to exchange currencies based on the current market price.Track Record
: Provides a transaction history of the system.
The AMM system provides the following features:
- Displaying the pool size and market price.
- Connecting a wallet and setting balances.
- Checking balances of wallets and the pool.
- Adding liquidity to the pool.
- Removing liquidity from the pool.
- Buying USD with JPY.
- Buying JPY with USD.
- Tracking transaction records.
To run the AMM system locally, follow these steps:
-
Clone the repository:
git clone https://github.com/clchinkc/amm_system.git
-
Compile the C++ code using a C++ compiler (e.g., g++):
g++ -o amm_system amm_system.cpp
After compiling the code and generating the executable file, run the AMM system by executing the following command:
./amm_system.exe
Or if you want to use the input file to test the system, run the AMM system by executing the following command:
On Mac:
./amm_system.exe < input1.txt
On Windows:
Get-Content .\input1.txt | .\amm_system.exe
On Linux:
cat input1.txt | ./amm_system.exe
The output would be the same as the output1.txt file.
Limitations of the Existing AMM System:
-
Simplistic Market Model: The existing system overlooks market depth, order matching, and liquidity provision strategies. It only supports USD and JPY. A robust system incorporating all fiat currencies is needed for a realistic decentralized exchange.
-
Centralization: The system depends on a central liquidity pool, which contradicts the decentralized exchange ethos. Ideally, control should be evenly spread among multiple liquidity providers on-chain.
Potential Improvements:
-
Multi-token Support: The system should support trading between numerous tokens, including cryptocurrencies and stablecoins, to broaden its utility.
-
Advanced Price Calculation: Rather than using a rudimentary formula for price determination, implementing advanced pricing models, possibly using oracles or external price feeds, would improve accuracy and stability.
-
Improved User Interface: A user-friendly interface providing real-time market data, easy trading interfaces, and portfolio management tools could attract more users and improve their experience.
-
Decentralization: Transition to a decentralized model using smart contracts and blockchain technology to distribute control among liquidity providers, thereby eliminating the central authority dependency.
-
Platform token Issuance: In the later stages of our platform development, we plan to issue a platform token linked to various fiat currencies. This coin will be used as a medium of exchange for trading and will be backed by the liquidity pool. Details can be found in the DUMMY coin whitepaper.
Contributions to this project are welcome. To contribute, follow these steps:
- Fork this repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push the branch to your fork.
- Submit a pull request to the main repository.
The AMM system is inspired by the following sources:
- Uniswap V3 Whitepaper
- Uniswap Whitepaper
- Uniswap Documentation
- Uniswap Liquidity Provision: An Online Learning Approach
- Bancor V2.1 Protocol Health Report
- Bancor Whitepaper
- SoK: Decentralized Exchanges (DEX) with Automated Market Maker (AMM) Protocols
This project is licensed under the MIT License.