How cetusprotocol/cetus-amm works
Based on your provided file tree and the brief README, it’s clear that this project implements an Automated Market Maker (“AMM”) specifically tailored for blockchain platforms using the Move language. In this case, the project is set up to deploy on two distinct chains: Aptos and Sui. Each blockchain-specific implementation is isolated within its own directory (aptos and sui), and each contains a comparable set of Move source files to implement the core AMM functionalities.
Main Components
• Two primary modules representing the blockchain implementations:
• Aptos AMM Module
• Sui AMM Module
• Within each module, key components include:
• amm_config: Handles configuration parameters for the AMM.
• amm_math: Provides mathematical functions (e.g., pricing curves) needed by the AMM.
• amm_router: Manages routing of swap orders or trade flows.
• amm_script: Likely provides orchestration scripts for executing AMM transactions.
• amm_swap: Core logic for performing swap operations.
• amm_utils: Utility functions supporting other modules.
• For Aptos, note that there is a unique file called u256.move which may deal with a custom 256-bit arithmetic implementation.
Relationships and Interactions
• Both Aptos and Sui modules function largely in parallel—each one encapsulating its blockchain-specific AMM logic.
• Within each module, components would interact in a sequential or coordinated manner:
• The amm_config sets initial parameters that other modules refer to.
• The amm_math functions support the computational needs of the swap operations.
• The amm_router directs calls between front-end trading commands and the actual execution logic found in amm_swap.
• The amm_utils provide helper routines that might be needed by all the above functions.
• For Aptos, the specialized u256 arithmetic support is used by the math module for operations needing high precision.
• There is an overall separation between the two modules, emphasizing that even though the core AMM functionalities are parallel, the deployment context and perhaps nuances in blockchain paradigms require distinct implementations.
Architectural Patterns and Design Principles
• Modularization: The project is clearly organized into modules based on the target blockchain (Aptos vs. Sui), ensuring that business logic does not mix between contexts.
• Separation of Concerns: Each file (or component) handles a specific set of tasks (configuration, math operations, routing, executing swaps, etc.), which makes the code maintainable and testable.
• Abstraction: The design abstracts blockchain-specific details into their respective modules.
• Reusability: Common logic (such as core AMM functions and utility routines) is implemented in similar ways across platforms, illustrating reuse in design, allowing parallel improvements.