Skip to content

This repository contains three main modules: an Automated Market Maker (AMM), a yield aggregator (Kai Finance), and a token distribution protocol.

License

Notifications You must be signed in to change notification settings

Vector-6/Sui_Smart_Contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sui Smart Contracts

This repository contains three main modules: an Automated Market Maker (AMM), a yield aggregator (Kai Finance), and a token distribution protocol.

📋 Table of Contents

🎯 Overview

This repository provides a suite of DeFi primitives and applications built specifically for the Sui blockchain using the Move programming language. Each module is designed to be composable, secure, and production-ready, following Sui's object-centric programming model.

Key Features

  • Modular Design: Each module can be used independently or composed together
  • Production Ready: Battle-tested contracts with comprehensive test coverage
  • Sui Optimized: Built specifically for Sui's unique object model and capabilities
  • Composable: Modules are designed to work together seamlessly
  • Secure: Implements best practices for smart contract security

🏗️ Modules

AMM

A UniswapV2-style Automated Market Maker implementation in idiomatic Sui Move.

Features:

  • Constant product curve (A × B = k)
  • Swap between any Coin<A> and Coin<B>
  • Deposit and withdraw liquidity
  • Permissionless and dynamic pool creation for any Coin pair
  • LP and admin fee support
  • Slippage protection

Key Components:

  • Pool<A, B>: Represents an AMM pool for token pair A and B
  • LP<A, B>: Liquidity provider tokens for the pool
  • PoolRegistry: Manages pool creation and ensures one pool per token pair
  • AdminCap: Administrative capabilities for fee management

Implementation Notes:

  • Uses approach (1) for pool creation: one pool per token pair
  • LP tokens are non-fungible between different pools
  • Supports configurable LP fees and admin fees
  • Implements proper slippage protection

Kai Finance

A sophisticated yield aggregator for Sui that optimizes returns across multiple DeFi strategies.

Features:

  • Multi-strategy yield optimization
  • Dynamic strategy allocation and rebalancing
  • Time-locked profit distribution to prevent sandwich attacks
  • Performance fee collection
  • TVL caps for risk management
  • Strategy-specific borrowing limits

Key Components:

  • Vault<T, YT>: Main vault contract managing multiple strategies
  • VaultAccess: Authorization for strategies to interact with vault
  • WithdrawTicket: Manages withdrawal process across strategies
  • StrategyState: Tracks strategy performance and allocation

Supported Strategies:

  • Scallop Protocol integration (lending/borrowing)
  • Yield-bearing token strategies
  • Cross-protocol yield optimization

Architecture:

  • Vault manages free balance and allocated funds across strategies
  • Strategies can borrow funds from vault based on allocation weights
  • Profits are distributed over time using time-locked balances
  • Withdrawals are processed through tickets to ensure atomicity

Token Distribution

A highly composable, flexible, and modular token distribution protocol for various use cases.

Primitives:

Time Locked Balance

  • Locks tokens with configurable unlock rate per second
  • Supports cliff periods and dynamic unlock parameters
  • Basic building block for vesting mechanisms

Time Distributor

  • Distributes tokens over time to multiple beneficiaries
  • Weight-based proportional distribution
  • Dynamic member management and weight adjustment
  • O(n) operations - suitable for smaller beneficiary sets

Accumulation Distributor

  • Instant proportional distribution to beneficiaries
  • O(1) operations - scales to unlimited beneficiaries
  • Multi-token support
  • Share-based distribution system

Farm System:

  • Farm: Manages reward distribution across pools
  • Pool: Represents liquidity mining pools
  • Multi-farm membership for pools
  • Dynamic reward token management

Use Cases:

  • Token vesting schedules
  • Liquidity mining programs
  • Team token allocations
  • Community reward distribution

🚀 Getting Started

Prerequisites

Installation

  1. Clone the repository:
git clone https://github.com/skc951201/Sui_Smart_Contracts.git
cd sui-smart-contracts
  1. Navigate to the specific module you want to work with:
cd amm  # or kai-finance, or token-distribution
  1. Build the module:
sui move build
  1. Run tests:
sui move test

🏛️ Architecture

Design Principles

  1. Object-Centric: Leverages Sui's object model for better composability
  2. Modular: Each component is self-contained and reusable
  3. Composable: Modules can be combined to create complex DeFi applications
  4. Secure: Implements defense-in-depth security patterns
  5. Gas Efficient: Optimized for Sui's gas model

Common Patterns

  • Capability-Based Access Control: Uses capability objects for administrative functions
  • Event-Driven: Comprehensive event emission for off-chain monitoring
  • Error Handling: Detailed error codes for better debugging
  • Upgrade Safety: Proper upgrade mechanisms where applicable

Integration Points

  • AMM ↔ Token Distribution: AMM pools can be used in liquidity mining farms
  • Kai Finance ↔ AMM: Vault strategies can interact with AMM pools
  • Cross-Module Composability: All modules designed to work together

🔒 Security

Security Features

  • Input Validation: Comprehensive validation of all inputs
  • Access Control: Capability-based permission system
  • Slippage Protection: Built-in slippage controls for swaps
  • Reentrancy Protection: Move's linear type system prevents reentrancy
  • Overflow Protection: Safe math operations throughout

Audit Status

  • All modules have undergone security reviews
  • Comprehensive test coverage
  • Production deployment on Sui mainnet

Best Practices

  • Always verify contract addresses before interaction
  • Use appropriate slippage tolerances
  • Monitor for events and state changes
  • Follow Sui's security guidelines

📄 License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Copyright 2023 Kuna Labs

🤝 Contributing

We welcome contributions! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

Development Guidelines

  • Follow Move best practices
  • Write comprehensive tests
  • Document public functions
  • Use meaningful variable names
  • Handle errors gracefully

Testing

Each module includes comprehensive test suites:

  • Unit tests for individual functions
  • Integration tests for complex workflows
  • Edge case testing
  • Gas optimization tests

📞 Support

  • Documentation: Check individual module READMEs for detailed documentation
  • Issues: Report bugs and feature requests via GitHub issues
  • Discord: Join our community Discord for discussions
  • Website: Visit kai.finance for Kai Finance specific information

🔗 Links


Built with ❤️ by the Kuna Labs team for the Sui ecosystem.

About

This repository contains three main modules: an Automated Market Maker (AMM), a yield aggregator (Kai Finance), and a token distribution protocol.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages