# Tetu Zap Solution

### Zapping

Zap solution converts a token to another using a defined route and can be used to deposit or withdraw from a vault.

![](https://316135650-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Me8Xn_pJtAjktHi3oBg%2Fuploads%2Fyg4ILpTrh5MiEOmDZ6Kw%2FScreen%20Shot%202022-02-06%20at%2007.02.15%20\(1\).png?alt=media\&token=66aa6123-e1a1-432c-bc82-e50119de0f28)

Through the Zapping Function users can enjoy the efficiency of participating in a yield farming vault with just one transaction, in general with zapping users can perform only one transaction to enter and exit a yield farming vault. Without using zapping the user would have to perform between 6 \~ 8 transactions to deposit to a yield farming vault.

Withdraw and converting to the token is also possible.

{% hint style="info" %}
The zapping function can cause slippage, when using it it is better to prioritize small amounts of deposits and withdrawals.
{% endhint %}

### Contracts

This solution included three contracts

* PriceCalculator
* MultiSwap
* ZapContract

### PriceCalculator  <a href="#pricecalculator" id="pricecalculator"></a>

In this solution Price Calculator will find the best liquidity pool across predefined Swap Platforms.

`getLargestPool(address token, address[] memory usedLps)`

For calculation price for any LiquidityPool pair using

`getPriceFromLp(address lpAddress, address token)`

### MultiSwap  <a href="#multiswap" id="multiswap"></a>

This contract has two purposes:

Find the best route for swap two tokens. The result will contain swap pairs.

&#x20; `findLpsForSwaps(address _tokenIn, address _tokenOut)`

The function should be called as a view from UI before the swap

Multi-swap will execute swaps for a given route. Used inside ZapContract but also can be used as a dedicated solution.

`multiSwap(address[] memory lps, address tokenIn, address tokenOut, uint256 amount, uint256 slippageTolerance)`

### ZapContract  <a href="#zapcontract" id="zapcontract"></a>

This contract implements all required steps for deposit/withdraw to the vault.

### Resources

Zap Feature article on [Medium](https://medium.com/@tetu.finance/zap-feature-bc43dba8b0f8).
