How hatif03/movefwd-amm works
Project Type and Purpose
• This is a full-stack decentralized application (dApp) comprising:
• On-chain Move smart contracts (AMM, NFT LP positions, fee logic, stable swap) deployed to the Sui blockchain.
• A Next.js 14 frontend (React, TypeScript) that interacts with those contracts via the Sui SDK and @mysten/dapp-kit.
• Shell scripts for contract deployment and demo workflows.
• Purpose: Provide a Uniswap-style AMM on Sui with NFT-based liquidity positions, multi-fee tiers, slippage protection, and a DeFi-styled UI.
File Structure Analysis
• contracts/ – Move smart contracts (sources/, tests/, Move.toml).
• sources/: module files organized by domain (constants, math, pool_factory, stable_swap_pool, lp_position_nft, fee_distributor, slippage_protection, events, errors, demo_tokens).
• tests/: unit & integration tests per module.
• frontend/ – Next.js app using the App Router.
• src/app/: page routes (dashboard, swap, pools, positions, faucet).
• src/components/: UI (shadcn/ui), layout, providers (Sui wallet context).
• src/lib/sui/: on-chain abstractions (constants, queries, transactions).
• scripts/ – deploy.sh (publish contracts), demo.sh (interactive demo).
README Insights
• Tech stack: Move language on Sui, Next.js, Tailwind CSS, @mysten/sui & dapp-kit, shadcn/ui, TanStack Query.
• Architecture described: constant product AMM, stable swap invariant, NFT LP positions, fee distributor, slippage protections.
• No off-chain database – all state lives on chain; UI pulls directly via RPC.
a. Main Components
• User Browser (React UI)
• Next.js Frontend (App Router, UI Components)
• Sui SDK & Dapp-Kit Layer (RPC client, tx builders, queries)
• Sui Wallet (user key management, transaction signing)
• Sui Testnet Full Node / RPC Endpoint
• Move Contracts on Sui (PoolFactory, StableSwapPool, LPPositionNFT, FeeDistributor, SlippageProtection, Math, Events, Errors)
• Shell Scripts (deploy.sh, demo.sh)
b. Relationships / Interactions
1. User interacts with React UI.
2. UI calls Sui SDK / dapp-kit to perform on-chain queries or build transactions.
3. Sui Wallet pops up for signature.
4. Signed tx hits Sui Testnet RPC.
5. RPC routes to Full Node, which executes Move contracts.
6. Move modules update on-chain state, emit events.
7. UI polls or listens for events/queries to update real-time data.
8. Scripts use Sui CLI to build, test, publish Move modules.
c. Architectural Patterns & Principles
• Modular Move contracts per domain (single responsibility).
• Layered architecture: UI → SDK/dapp-kit → RPC → Move modules.
• NFT as LP position for composability (extensibility).
• Fee distribution and slippage protection abstracted into dedicated modules.
d. Key Technologies
• Move & Sui Move framework
• Next.js 14 (App Router) & React
• @mysten/sui, @mysten/dapp-kit for blockchain interaction
• Tailwind CSS, shadcn/ui for styling
• TanStack Query for data fetching