# Smart Contracts

Direct smart contract interaction documentation for the STON.fi DEX protocol.

> **Important**: These docs describe the low-level smart contract architecture, methods, and opcodes. For **production applications**, we **strongly recommend** using the [official SDK](https://docs.ston.fi/developer-section/dex/sdk/v2) + [TonConnect](https://docs.ton.org/develop/dapps/ton-connect/overview) instead of manually compiling BOCs and sending transactions. The SDK provides better developer experience, handles edge cases, and receives official support. Custom BOC compilation should only be used for specialized/advanced use cases.

## Contract Architecture

The DEX consists of four main contract types:

* **Router**: Entry point for all operations
* **Pool**: Manages liquidity and swaps for token pairs
* **Account**: Tracks user liquidity positions
* **Wallet**: Handles LP token operations

## Versions

### [v2](https://docs.ston.fi/developer-section/dex/smart-contracts/v2)

Latest contract implementation with:

* Enhanced liquidity management
* Vault system for fee collection
* Optimized gas consumption

### [v1](https://docs.ston.fi/developer-section/dex/smart-contracts/v1)

Original contract implementation:

* Standard AMM functionality
* Proven security and reliability

## Key Differences Between Versions

| Feature         | v1       | v2        |
| --------------- | -------- | --------- |
| Single-sided LP | ❌        | ✅         |
| Vault System    | ❌        | ✅         |
| Gas Efficiency  | Standard | Optimized |
| LP Token Burns  | Manual   | Automatic |

## Integration Considerations

* Use the SDK for most integrations
* Direct contract calls for advanced use cases
* Always test on testnet first
* Consider gas optimization strategies

## Security

All contracts are:

* Open source
* Audited
* Immutable (pools)
* Time-locked (router upgrades)
