> For the complete documentation index, see [llms.txt](https://ston-fi.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ston-fi.gitbook.io/docs/developer-section/dex/smart-contracts/v2/examples.md).

# Examples

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

## Available Examples

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

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

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

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

### [Vault Examples](/docs/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](/docs/developer-section/dex/smart-contracts/v2.md)
* Check [op codes reference](/docs/developer-section/dex/smart-contracts/v2/op-codes.md)
* Ask in [developer chat](https://t.me/stonfidex)
