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.
- 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
- 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
- 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
- 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
- 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
- Exchange Fee: 0.3% (3 basis points)
- Provider Share: 70% of fees
- wBTC Holder Share: 30% of fees
- Maximum wBTC Participants: 500 registered holders
- Amplification Factor Range: 1 to 9,999
- Market Support: Unlimited markets (subject to blockchain limits)
(create-market asset-a asset-b curve-factor market-id)
(get-market market-id)(exchange market-id asset-a asset-b input-amount min-output-amount)(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)(register-wbtc-participant participant holdings)
(distribute-rewards market-id asset-a)- 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
AquaFlow uses the StableSwap invariant formula:
D = balance_sum * (1 + (2*A*x*y)/(D³) - A/2)
Where:
Dis the invariantAis the amplification factorx, yare the asset reserves
This curve provides:
- Low slippage for balanced pools
- Efficient capital utilization
- Stable pricing for correlated assets
| 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 |
- 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
;; Create USDC-USDT market with high amplification
(contract-call? .aquaflow create-market
'SP...USDC 'SP...USDT u1000 u1);; Add 1000 USDC and 1000 USDT to market 1
(contract-call? .aquaflow provide-liquidity
u1 'SP...USDC 'SP...USDT u1000000000 u1000000000 u900000000);; Exchange 100 USDC for USDT with 1% slippage tolerance
(contract-call? .aquaflow exchange
u1 'SP...USDC 'SP...USDT u100000000 u99000000)