Skip to content

oyin-moh/AquaFlow--Smart-Contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

AquaFlow: Decentralized Liquidity Protocol

Overview

AquaFlow is a decentralized automated market maker (AMM) protocol built on the Stacks blockchain using Clarity smart contracts. It implements a StableSwap curve algorithm optimized for trading between assets with similar values, while distributing trading rewards to wBTC holders.

Key Features

  • StableSwap AMM: Uses a specialized curve algorithm for efficient trading of correlated assets
  • Dual Token Rewards: 70% of trading fees go to liquidity providers, 30% to registered wBTC holders
  • Multi-Market Support: Create and manage multiple trading pairs with configurable parameters
  • Low Slippage: Optimized for stable asset pairs with minimal price impact

Core Components

1. Markets

  • Market Creation: Admin can create new trading pairs with custom amplification factors
  • Reserve Management: Tracks asset reserves and maintains market invariants
  • Configurable Parameters: Each market has adjustable curve factors for optimal performance

2. Liquidity Provision

  • Add Liquidity: Deposit paired assets to earn provider tokens and trading fees
  • Remove Liquidity: Burn provider tokens to withdraw proportional asset amounts
  • Fee Distribution: Earn 70% of all trading fees proportional to your liquidity share

3. Token Exchange

  • Low-Fee Trading: 0.3% fee on all exchanges
  • Slippage Protection: Built-in minimum output amount validation
  • Efficient Pricing: StableSwap curve minimizes slippage for similar-value assets

4. wBTC Reward System

  • Holder Registration: Protocol admin registers eligible wBTC holders
  • Automatic Rewards: 30% of trading fees distributed proportionally to wBTC holdings
  • Reward Distribution: Holders can claim accumulated rewards from any market

Technical Specifications

Fee Structure

  • Exchange Fee: 0.3% (3 basis points)
  • Provider Share: 70% of fees
  • wBTC Holder Share: 30% of fees

Limits

  • Maximum wBTC Participants: 500 registered holders
  • Amplification Factor Range: 1 to 9,999
  • Market Support: Unlimited markets (subject to blockchain limits)

Core Functions

Market Management

(create-market asset-a asset-b curve-factor market-id)
(get-market market-id)

Trading

(exchange market-id asset-a asset-b input-amount min-output-amount)

Liquidity Operations

(provide-liquidity market-id asset-a asset-b amount-a amount-b min-provider-tokens)
(withdraw-liquidity market-id asset-a asset-b provider-amount min-amount-a min-amount-b)

Reward Management

(register-wbtc-participant participant holdings)
(distribute-rewards market-id asset-a)

Security Features

  • Admin Controls: Market creation restricted to protocol admin
  • Input Validation: Comprehensive checks for all user inputs
  • Slippage Protection: Minimum output amount requirements
  • Access Controls: Token contract verification for all operations
  • Zero Address Protection: Prevents operations with invalid addresses

Mathematical Model

AquaFlow uses the StableSwap invariant formula:

D = balance_sum * (1 + (2*A*x*y)/(D³) - A/2)

Where:

  • D is the invariant
  • A is the amplification factor
  • x, y are the asset reserves

This curve provides:

  • Low slippage for balanced pools
  • Efficient capital utilization
  • Stable pricing for correlated assets

Error Codes

Code Error Description
100 ERR_ADMIN_ONLY Operation restricted to protocol admin
101 ERR_INSUFFICIENT_FUNDS Insufficient token balance
102 ERR_INSUFFICIENT_RESERVES Market lacks sufficient liquidity
103 ERR_SLIPPAGE_TOO_HIGH Output below minimum threshold
104 ERR_INVALID_INPUT Invalid parameter provided
105 ERR_RESERVES_IMBALANCED Market reserves are imbalanced
106 ERR_NO_RESERVES Market has no liquidity
107 ERR_UNAUTHORIZED_ACCESS Token contract mismatch
108 ERR_REWARD_DISTRIBUTION_FAILED Reward claim failed
109 ERR_REGISTRY_FULL wBTC participant limit reached
110 ERR_INVALID_MARKET_ID Market does not exist

Deployment Requirements

  • Stacks Blockchain: Compatible with Stacks 2.0
  • SIP-010 Tokens: All assets must implement the standard fungible token trait
  • Admin Setup: Deploy with appropriate admin principal
  • Initial Markets: Create markets post-deployment with suitable amplification factors

Usage Examples

Creating a Market

;; Create USDC-USDT market with high amplification
(contract-call? .aquaflow create-market 
  'SP...USDC 'SP...USDT u1000 u1)

Providing Liquidity

;; Add 1000 USDC and 1000 USDT to market 1
(contract-call? .aquaflow provide-liquidity 
  u1 'SP...USDC 'SP...USDT u1000000000 u1000000000 u900000000)

Trading Assets

;; Exchange 100 USDC for USDT with 1% slippage tolerance
(contract-call? .aquaflow exchange 
  u1 'SP...USDC 'SP...USDT u100000000 u99000000)

About

AquaFlow is a sophisticated decentralized finance (DeFi) protocol built on the Stacks blockchain that implements an automated market maker (AMM) system specifically designed for efficient trading between correlated assets.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors