Skip to content

michaelmary-mm/CurveDEX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

CurveDEX Smart Contract

A decentralized curve-based Automated Market Maker (AMM) protocol built on Stacks that enables efficient trading of stablecoins and similar assets while distributing rewards to wBTC holders.

Overview

CurveDEX implements a StableSwap-style AMM that uses curve mathematics to minimize slippage for trades between assets with similar values. The protocol generates trading fees that are split between liquidity providers (70%) and wBTC holders (30%), creating an innovative reward distribution mechanism.

Key Features

  • Curve-Based AMM: Optimized for low-slippage trading between similar-value assets
  • Dual Reward System: Trading fees distributed between liquidity providers and wBTC holders
  • Multi-Market Support: Support for multiple trading pairs with independent configurations
  • SIP-010 Compatible: Works with any SIP-010 compliant fungible tokens

Contract Architecture

Core Components

  • Trading Markets: Independent liquidity pools with configurable curve parameters
  • Liquidity Provision: Users can provide liquidity to earn fees and LP tokens
  • Reward Distribution: Automated fee splitting and reward accumulation
  • wBTC Holder Registry: Tracks wBTC holders for reward distribution

Fee Structure

  • Trading Fee: 0.3% (3 basis points) on all trades
  • Provider Share: 70% of fees go to liquidity providers
  • wBTC Reward Share: 30% of fees distributed to registered wBTC holders

Main Functions

Market Management

  • create-market: Create a new trading market (admin only)
  • get-market-info: View market details and reserves

Trading

  • execute-trade: Swap tokens with slippage protection
  • provide-liquidity: Add liquidity to earn fees and LP tokens
  • withdraw-liquidity: Remove liquidity and burn LP tokens

Reward System

  • register-wbtc-participant: Register wBTC holder for rewards (admin only)
  • claim-distribution: Claim accumulated trading fee rewards

Read-Only Functions

  • get-wbtc-holdings: Check registered wBTC holdings
  • participant-exists: Verify if address is registered for rewards

Usage Examples

Creating a Market

(contract-call? .curvedex create-market 
  'SP1H1733V5MZ3SZ9XRW9FKYGEZT0JDGEB8Y634C7R.usdc-token
  'SP1H1733V5MZ3SZ9XRW9FKYGEZT0JDGEB8Y634C7R.usdt-token
  u100  ;; curve factor
  u1)   ;; market ID

Adding Liquidity

(contract-call? .curvedex provide-liquidity
  u1         ;; market ID
  .usdc-token
  .usdt-token
  u1000000   ;; 1 USDC (6 decimals)
  u1000000   ;; 1 USDT (6 decimals) 
  u900000)   ;; minimum LP tokens

Executing a Trade

(contract-call? .curvedex execute-trade
  u1         ;; market ID
  .usdc-token
  .usdt-token  
  u1000000   ;; 1 USDC input
  u990000)   ;; minimum 0.99 USDT output

Error Codes

Code Name Description
u100 ERR_ADMIN_ONLY Function restricted to protocol admin
u101 ERR_BALANCE_TOO_LOW Insufficient token balance
u102 ERR_RESERVES_TOO_LOW Insufficient market reserves
u103 ERR_SLIPPAGE_TOO_HIGH Trade exceeds slippage tolerance
u104 ERR_INVALID_INPUT Invalid input parameters
u105 ERR_RESERVES_IMBALANCED Market reserves are imbalanced
u110 ERR_INVALID_MARKET_ID Market does not exist
u113 ERR_INVALID_ADDRESS Invalid principal address

Security Features

  • Input Validation: Comprehensive validation of all parameters
  • Slippage Protection: Minimum output amounts prevent sandwich attacks
  • Access Control: Admin-only functions for market creation and registrations
  • Safe Math: Overflow protection in mathematical operations
  • Principal Validation: Prevents zero-address interactions

Mathematical Model

CurveDEX uses a modified constant product formula with amplification factor:

D = invariant(x, y, A)

Where:

  • x, y are token reserves
  • A is the amplification/curve factor
  • Higher A values create flatter curves (less slippage)

Deployment Requirements

  • Stacks blockchain compatible environment
  • SIP-010 fungible tokens for trading pairs
  • Admin account for market creation and wBTC holder registration

About

CurveDEX is a sophisticated decentralized exchange (DEX) smart contract built on the Stacks blockchain that implements a curve-based Automated Market Maker (AMM) protocol.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors