Skip to content

PAtrickpp33/SuiUniSwapV1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SUI UniswapV1 | SUI 上的 UniswapV1

English | 中文


中文

⚠️ 重要警告 / IMPORTANT WARNING ⚠️

当前版本存在已知问题,正在修复中:

🐛 Mint 和 Swap 功能存在 Bug:

  • 错误信息: Unable to process transaction. Dry run failed, could not automatically determine a budget: CommandArgumentError { arg_idx: 0, kind: SecondaryIndexOutOfBounds { result_idx: 0, secondary_idx: 0 } } in command 1
  • 影响功能: 代币铸造和代币交换
  • 合约单元测试正常通过,问题出现在前端交易构建

🔧 开发状态: 正在调试和修复中,请耐心等待更新


项目简介

这是一个将 以太坊 UniswapV1 协议原生移植到 Sui 区块链的完整去中心化交易所实现,包含 Move 智能合约和 React 前端应用。

项目特色

🌟 原生移植 - 从以太坊 UniswapV1 忠实转换而来
🏭 工厂合约 - 管理交易对的创建和查询
💧 交易所合约 - 处理流动性管理和代币交换
🪙 测试代币 - 两个演示用的测试代币
🌐 Web3 前端 - 完整的用户界面

功能特性

智能合约功能 (✅ 已完成)

  • ✅ 创建代币交易对
  • ✅ 添加/移除流动性
  • ✅ SUI ↔ Token 交换
  • ✅ Token ↔ Token 交换 (通过 SUI 作为中介)
  • ✅ LP 代币管理
  • ✅ 0.3% 交易手续费
  • ✅ 单元测试全部通过

前端功能 (🐛 部分存在问题)

  • ✅ 钱包连接 (Sui Wallet)
  • 🐛 代币铸造界面 (存在交易构建问题)
  • ✅ 交易对创建
  • ✅ 流动性管理
  • 🐛 代币交换界面 (存在交易构建问题)
  • ✅ 交易状态跟踪

技术架构

基于 UniswapV1 设计

本项目完全基于以太坊 UniswapV1 的设计原理:

  • 恒定乘积做市商 (x * y = k)
  • 自动化做市商 (AMM) 机制
  • 流动性提供者代币 (LP Token)
  • 0.3% 交易手续费分配给流动性提供者

Move 智能合约

  • Factory 合约 - 管理所有交易对
  • Exchange 合约 - 单个交易对的核心逻辑
  • 安全特性 - Move 语言的内存安全和资源管理

前端技术栈

  • React 18 + TypeScript
  • Sui dApp Kit - 钱包连接和交易
  • Radix UI - 现代化组件库
  • Vite - 构建工具

快速开始

前提条件

安装和运行

# 1. 克隆项目
git clone <repository-url>
cd SuiUniSwapV1

# 2. 构建智能合约
sui move build

# 3. 运行测试 (确认合约正常)
sui move test

# 4. 启动前端
cd SuiUniSwapV1-frontend
npm install
npm run dev

已知问题和解决方案

🐛 交易构建错误

错误: SecondaryIndexOutOfBounds { result_idx: 0, secondary_idx: 0 }

可能原因:

  • 前端交易构建语法问题
  • Gas budget 设置问题
  • 对象引用索引错误

临时解决方案:

  • 直接使用 Sui CLI 进行合约交互
  • 等待前端修复更新

📊 项目状态

  • 智能合约: 完全正常,测试通过
  • 🔧 前端应用: 部分功能待修复
  • 📝 文档: 持续更新中

English

⚠️ IMPORTANT WARNING ⚠️

Current version has known issues being fixed:

🐛 Mint and Swap Functions Have Bugs:

  • Error message: Unable to process transaction. Dry run failed, could not automatically determine a budget: CommandArgumentError { arg_idx: 0, kind: SecondaryIndexOutOfBounds { result_idx: 0, secondary_idx: 0 } } in command 1
  • Affected features: Token minting and token swapping
  • Smart contract unit tests pass normally - the issue is in frontend transaction construction

🔧 Development Status: Currently debugging and fixing, please wait for updates


Project Overview

This is a complete decentralized exchange implementation that natively ports Ethereum's UniswapV1 protocol to the Sui blockchain, including Move smart contracts and a React frontend application.

Key Features

🌟 Native Port - Faithfully converted from Ethereum UniswapV1
🏭 Factory Contract - Manages trading pair creation and queries
💧 Exchange Contract - Handles liquidity management and token swaps
🪙 Test Tokens - Two demonstration tokens
🌐 Web3 Frontend - Complete user interface

Functionality

Smart Contract Features (✅ Completed)

  • ✅ Create token trading pairs
  • ✅ Add/remove liquidity
  • ✅ SUI ↔ Token swaps
  • ✅ Token ↔ Token swaps (via SUI as intermediary)
  • ✅ LP token management
  • ✅ 0.3% trading fees
  • ✅ All unit tests passing

Frontend Features (🐛 Partial issues)

  • ✅ Wallet connection (Sui Wallet)
  • 🐛 Token minting interface (transaction construction issues)
  • ✅ Trading pair creation
  • ✅ Liquidity management
  • 🐛 Token swap interface (transaction construction issues)
  • ✅ Transaction status tracking

Technical Architecture

Based on UniswapV1 Design

This project is completely based on Ethereum UniswapV1's design principles:

  • Constant Product Market Maker (x * y = k)
  • Automated Market Maker (AMM) mechanism
  • Liquidity Provider Tokens (LP Tokens)
  • 0.3% trading fees distributed to liquidity providers

Move Smart Contracts

  • Factory Contract - Manages all trading pairs
  • Exchange Contract - Core logic for individual trading pairs
  • Security Features - Move language's memory safety and resource management

Frontend Tech Stack

  • React 18 + TypeScript
  • Sui dApp Kit - Wallet connection and transactions
  • Radix UI - Modern component library
  • Vite - Build tool

Quick Start

Prerequisites

Installation and Running

# 1. Clone the project
git clone <repository-url>
cd SuiUniSwapV1

# 2. Build smart contracts
sui move build

# 3. Run tests (confirm contracts work)
sui move test

# 4. Start frontend
cd SuiUniSwapV1-frontend
npm install
npm run dev

Known Issues and Solutions

🐛 Transaction Construction Error

Error: SecondaryIndexOutOfBounds { result_idx: 0, secondary_idx: 0 }

Possible Causes:

  • Frontend transaction construction syntax issues
  • Gas budget configuration problems
  • Object reference indexing errors

Temporary Solutions:

  • Use Sui CLI directly for contract interactions
  • Wait for frontend fix updates

📊 Project Status

  • Smart Contracts: Fully functional, tests passing
  • 🔧 Frontend Application: Some features under repair
  • 📝 Documentation: Continuously updating

Project Structure

SuiUniSwapV1/
├── sources/                  # Move smart contracts
│   ├── factory.move         # Factory contract
│   ├── exchange.move        # Exchange contract
│   ├── test_coin.move       # Test token 1
│   └── test_coin2.move      # Test token 2
├── SuiUniSwapV1-frontend/   # React frontend
│   ├── src/
│   │   ├── components/      # UI components
│   │   ├── utils/          # Utility functions
│   │   └── types.ts        # Type definitions
│   └── package.json
├── tests/                   # Test files
├── Move.toml               # Move project config
└── README.md

Security Considerations

  • ✅ Slippage protection (minimum output checks)
  • ✅ Access control (Capability pattern)
  • ✅ Integer overflow protection
  • ✅ Reentrancy protection (Move language features)
  • ⚠️ Note: This is a test version, do not use on mainnet

Development & Testing

Run Tests

sui move test

Local Development

# Start local Sui network (optional)
sui start --with-faucet

# Get test SUI
sui client faucet

# Deploy to local network
sui client publish --gas-budget 50000000

Contributing

Welcome to submit Issues and Pull Requests!

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Sui - High-performance blockchain platform
  • Uniswap - Decentralized exchange protocol design inspiration
  • Move Language - Secure smart contract programming language

Contact

For questions or suggestions, please contact us through GitHub Issues.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages