# 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](/developer-section/dex/sdk/v2.md) + [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](/developer-section/dex/smart-contracts/v2.md)

Latest contract implementation with:

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

### [v1](/developer-section/dex/smart-contracts/v1.md)

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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ston.fi/developer-section/dex/smart-contracts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
