A decentralized exchange (DEX) smart contract implementation for Stacks blockchain that enables automated market making, liquidity provision, and token swaps. This contract implements standard AMM (Automated Market Maker) functionality with additional cross-chain capabilities.
- Automated Market Maker (AMM) functionality
- Liquidity pool creation and management
- Token swapping with configurable slippage protection
- Liquidity provider (LP) token minting and management
- Emergency shutdown capability
- Protocol fee mechanism (0.3% total fee, split between protocol and LP)
- NFT trait implementation for LP tokens
- Total Fee: 0.3% (30 basis points)
- Protocol Fee: 0.03% (3 basis points)
- LP Fee: 0.27% (27 basis points)
create-pool
: Create a new liquidity pool for a token pairadd-liquidity
: Add liquidity to an existing poolget-pool-details
: Retrieve pool informationget-provider-shares
: Get LP token information for a provider
swap-exact-tokens
: Execute a token swap with slippage protectioncalculate-swap-output
: Calculate expected output for a swap
set-contract-owner
: Transfer contract ownershiptoggle-emergency-shutdown
: Enable/disable emergency shutdown
Code | Description |
---|---|
u100 | Not authorized |
u101 | Invalid amount |
u102 | Insufficient balance |
u103 | Pool not found |
u104 | Slippage too high |
u105 | Invalid token pair |
u106 | Zero liquidity |
(contract-call? .dex create-pool token-x token-y initial-x-amount initial-y-amount)
(contract-call? .dex add-liquidity
pool-id
token-x
token-y
amount-x
amount-y
min-shares)
(contract-call? .dex swap-exact-tokens
pool-id
token-in
token-out
amount-in
min-amount-out
is-x-to-y)
- The contract implements slippage protection to prevent front-running
- Emergency shutdown mechanism for crisis management
- Access control for administrative functions
- Minimum liquidity requirements to prevent manipulation
- Contract owner permissions are limited to essential functions
- SIP-010 Fungible Token Trait
- NFT Trait Implementation
To deploy and test this contract:
- Ensure you have the Clarity CLI installed
- Deploy required trait contracts first
- Deploy this contract
- Run test suite
This smart contract is open source and available under the MIT license.
Contributions are welcome! Please submit pull requests with:
- Detailed description of changes
- Updated tests
- Documentation updates