# Examples

Practical examples for interacting with STON.fi v2 smart contracts.

## Available Examples

### [Swap Examples](/developer-section/dex/smart-contracts/v2/examples/swap.md)

* Basic token swaps
* Multi-hop swaps
* Slippage protection
* Custom routes

### [LP Provide Examples](/developer-section/dex/smart-contracts/v2/examples/lp-provide.md)

* Balanced liquidity provision
* Single-sided liquidity
* Optimal amounts calculation
* Gas optimization

### [Vault Examples](/developer-section/dex/smart-contracts/v2/examples/vault.md)

* Fee collection
* Vault withdrawals
* Permission management
* Batch operations

## Usage Guidelines

### Best Practices

1. Always simulate transactions first
2. Use appropriate gas limits
3. Handle all error cases
4. Validate inputs thoroughly

### Common Patterns

```func
;; Check minimum output
throw_unless(error::insufficient_output, 
    output_amount >= min_output);

;; Validate addresses
throw_unless(error::invalid_address, 
    equal_slices(sender, expected_sender));

;; Handle timeouts
throw_if(error::expired, 
    now() > deadline);
```

### Testing

* Use testnet for development
* Test edge cases thoroughly
* Monitor gas consumption
* Verify state changes

## Integration Tips

1. **Start Simple**: Begin with basic examples
2. **Add Complexity**: Gradually add features
3. **Error Handling**: Implement comprehensive error handling
4. **Gas Optimization**: Profile and optimize gas usage
5. **Security**: Follow security best practices

## Need Help?

* Review the [v2 documentation](/developer-section/dex/smart-contracts/v2.md)
* Check [op codes reference](/developer-section/dex/smart-contracts/v2/op-codes.md)
* Ask in [developer chat](https://t.me/stonfidex)


---

# 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/v2/examples.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.
