This project implements a simple Automated Market Maker (AMM) with a vault-pool structure. To accommodate multi-token trading requirements, the pool utilizes Balancer's algorithm. The system is designed with future scalability in mind, allowing for potential iterations to support multiple pool types.
Key features:
- Vault-pool architecture for enhanced security and flexibility
- Multi-token support using Balancer's weighted pool algorithm
- Upgradeable design for future improvements
The AMM consists of three main components:
-
Vault:
- Acts as the central hub for all funds
- Serves as the entry point for user transactions
- Manages global system parameters and security features
-
Pool:
- Implements trading algorithm logic
- Handles LP token minting and burning
- Calculates swap amounts and fees
-
PoolFactory:
- Enables permissionless creation of new pools
- Registers newly created pools with the Vault
- Manages pool deployment and initialization
-
swapExactIn(SwapParams memory params) external payable returns (uint256)
- Performs a token swap with an exact input amount
- Supports multi-hop swaps (up to 3 hops)
-
swapExactOut(SwapParams memory params) external payable returns (uint256)
- Performs a token swap with an exact output amount
- Supports multi-hop swaps (up to 3 hops)
-
addLiquidity(address _pool, uint256[] memory amounts, uint256 minToMint, uint256 deadline) external payable returns (uint256)
- Adds liquidity to a specified pool
- Returns the amount of LP tokens minted
-
removeLiquidity(address _pool, uint256 lpTokenAmount, uint256[] memory minAmountsOut, uint256 deadline) external returns (uint256[] memory)
- Removes liquidity from a specified pool
- Returns the amounts of tokens received
-
setGlobalPause(bool _pause) external onlyOwner
- Pauses or unpauses all operations in the Vault
-
setPoolLock(address _pool, bool _lock) external onlyOwner
- Locks or unlocks a specific pool
-
addFactory(address factory) external onlyOwner
- Adds a new authorized factory
-
removeFactory(address factory) external onlyOwner
- Removes an authorized factory
note: The operation to delete the pool is not currently provided, considering that the pool does not manage funds independently, and therefore should not be deleted by the admin.
To run tests using Forge:
-
Install Forge if you haven't already:
curl -L https://foundry.paradigm.xyz | bash foundryup
-
Install dependencies:
forge install
-
Run tests:
forge test
-
Deploy
forge script script/Deploy.s.sol:Deploy --rpc-url https://rpc.ankr.com/eth_sepolia --broadcast --slow
For more information on Forge and its features, refer to the Forge Book.