> For the complete documentation index, see [llms.txt](https://doc.torch.finance/dex/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.torch.finance/dex/getting-started/architecture/meesage-flows/cross-pool-operations.md).

# Cross-Pool Operations

## Deposit and Deposit

![TorchDepositDepositFlow](https://hackmd.io/_uploads/BJH2Cn1IJx.png)

Let's assume there are two pools:

1. **Base Pool** – triTON Pool (TON/tsTON/stTON)
2. **Meta Pool** – quaTON Pool (triTON LP / hTON)

### **Deposit and Deposit Process**

Suppose you currently hold **stTON** and **hTON** and want to maximize your rewards. You can achieve this through a **deposit and deposit** process.

Here’s how it works:

1. **First Deposit** – Deposit **stTON** into the **triTON Pool** to receive **triTON LP tokens**.
2. **Second Deposit** – Take the obtained **triTON LP** along with **hTON** and deposit them into the **quaTON Pool** to receive **quaTON LP tokens**.

***

### **Detailed Flow**

* The **LP Account contract** will wait until both **stTON** and **hTON** deposits are received.
* Once both assets arrive, the LP Account sends an `op::deposit_all` message to the **triTON Pool** to process the stTON deposit.
* The **triTON Pool** calculates the amount of **triTON LP** the user will receive.
* After calculation, the triTON Pool packages the **triTON LP** and **hTON** deposit information and sends an `op::deposit_between` message to the **quaTON Pool**.
* The **quaTON Pool** then calculates the final amount of **quaTON LP** the user will receive.

For a complete view of the process, please refer to the [diagram](https://hackmd.io/WUJkKbNOSeujHtjYyB73uA?view#Process-of-Deposit).

***

### **Alternative Deposit Scenarios**

This process can also be performed using only the assets within the **triTON Pool**, without the need for hTON. In such cases, users can still achieve the **deposit and deposit** operation by utilizing assets directly from the Base Pool.

***

## Deposit and Swap

![TorchDepositSwapFlow](https://hackmd.io/_uploads/Sk1d1aJIJe.png)

In the following example, the scenario typically involves users swapping Token A for Token B, a process that may involve multiple pools.

### **Deposit and Swap Process**

Continuing from the previous example, suppose you currently hold **stTON** and want to swap it for **hTON**. This can be achieved through a **deposit and swap** process.

Here’s how it works:

1. **First Step** – Deposit **stTON** into the **triTON Pool** to receive **triTON LP tokens**.
2. **Second Step** – Use the obtained **triTON LP** to perform a swap in the **quaTON Pool**, swapping the **triTON LP** for **hTON**.

***

### **Detailed Flow**

* The **deposit process** for the first step is the same as the one described earlier (refer to [this link](https://hackmd.io/WUJkKbNOSeujHtjYyB73uA?view#Process-of-Deposit) for details).
* However, after the triTON Pool completes the deposit, it does not send an `op::payout` to the LP Vault.
* Instead, the triTON Pool sends an `op::swap_between` message to the **quaTON Pool** to initiate the swap.
* Once the swap is completed, the quaTON Pool sends an `op::payout` message to the hTON vault, transferring **hTON** to the user’s designated address.

***

## Swap and Withdraw

![TorchSwapWithdrawFlow](https://hackmd.io/_uploads/HJcycTJ8Jx.png)

Continuing from the previous [Deposit and Swap](https://hackmd.io/WUJkKbNOSeujHtjYyB73uA?view#Deposit-and-Swap) example, this time we perform the reverse operation through **Swap and Withdraw** to convert assets from hTON to stTON.

### **Swap and Withdraw Process**

Suppose you currently hold **hTON** and want to swap it for **stTON**. This can be done through the following steps:

1. **Step 1 – Swap hTON for triTON LP**
   * Swap **hTON** for **triTON LP** in the **quaTON Pool**.
2. **Step 2 – Withdraw triTON LP to receive stTON**
   * Use the obtained **triTON LP** to perform a withdrawal (Withdraw One mode) in the **triTON Pool** to receive **stTON**.

***

### **Detailed Flow**

* The **swap process** is the same as the one described earlier (refer to [this link](https://hackmd.io/WUJkKbNOSeujHtjYyB73uA?view#Process-of-Swap)).
* However, after the **quaTON Pool** completes the swap, it does not send an `op::payout` to the **stTON Vault** directly.
* Instead, the **quaTON Pool** sends an `op::withdraw_between` message to the **triTON Pool** to initiate the withdrawal process.
* After the **triTON Pool** completes the withdrawal, it sends an `op::payout` message to the **stTON Vault**, transferring the assets to the user’s designated address.

***

## Withdraw and Withdraw

![TorchWithdrawWithdarwFlow](https://hackmd.io/_uploads/rk4mop1I1e.png)

Continuing from the previous **Deposit and Deposit** example, this time we perform the reverse operation through **Withdraw and Withdraw** to convert assets from quaTON LP to stTON in the triTON Pool.

### **Withdraw and Withdraw Process**

Suppose you currently hold **quaTON LP** and want to convert it to **stTON** in the triTON Pool. This can be achieved through the following steps:

1. **Step 1 – Withdraw quaTON LP for triTON LP**
   * Perform a withdrawal in the **quaTON Pool** to receive **triTON LP**.
2. **Step 2 – Withdraw triTON LP for stTON**
   * Use the obtained **triTON LP** to perform a withdrawal in the **triTON Pool** to receive **stTON**.

***

### **Detailed Flow**

* The **withdrawal process** for the first step is the same as the one described earlier (refer to [this link](https://hackmd.io/WUJkKbNOSeujHtjYyB73uA?view#Process-of-Withdraw)).
* However, after the **quaTON Pool** completes the withdrawal, it does not send an `op::payout` to the **triTON LP Vault**.
* Instead, the **quaTON Pool** sends an `op::withdraw_between` message to the **triTON Pool** to initiate the next withdrawal process.
* After the **triTON Pool** completes the withdrawal, it sends an `op::payout` message to the **stTON Vault**, transferring the assets to the user’s designated address.

***

### **Withdrawal Modes**

Since Torch supports two withdrawal modes – **Withdraw All** and **Withdraw One** – there are four possible combinations during the **Withdraw and Withdraw** process:

* **Withdraw All and Withdraw All**
* **Withdraw One and Withdraw One**
* **Withdraw All and Withdraw One**
* **Withdraw One and Withdraw All**

Users can choose the appropriate combination based on their specific needs and desired outcomes.

***
