# Re-add Liquidity

## Re-add Liquidity

This event can only happen for users that provided liquidity before. The event of re-adding liquidity requires the following information from the user:\
1\. $$A\_{du}$$ Amount of token A to be added\
2\. $$B\_{du}$$ Amount of token B to be added\
3\. Owner

&#x20;After the information was supplied, the `re-add liquidity` function will perform the following activities:

### 1. Calculate factors

### 1.1 Calculate Option Price&#x20;

For simplicity, let's acknowledge that the option price is a function that required a $$MarketData$$ and an internal vector ($$IV$$) as input.

$$P\_i=f\_p(IV\_{i-1},MarketData\_i)$$&#x20;

For more details about the pricing formula or its contract implementation, check [this section](https://app.gitbook.com/@pods-finance-1/s/teste/~/drafts/-MNH5EfMIG3zYkpvevUc/options-amm-overview/optionamm/pricing). .&#x20;

![ABPrice variable on \_addLiquidity at AMM.sol](/files/-MQu4nFlTcBWTvQd_jHa)

### 1.2 Calculate the Pool's Value Factor ($$F\_{v\_{i}}$$)&#x20;

Since the re-add liquidity happens in a given moment$$i≠0$$, $$F\_{v\_{i}}$$may not be equal to 1, so there should be a  $$F\_{v\_{i}}$$calculation. The following formula will trigger the calculation:

$$\displaystyle F\_{v\_{i}}= \frac{TB\_{A\_{i-1}}\cdot P\_i+TB\_{B\_{i-1}}}{DB\_{A\_{i-1}} \cdot P\_i+DB\_{B\_{i-1}}}$$&#x20;

![FimpOpening variable on \_addLiquidity function at AMM.sol](/files/-MQtoqSEnGAFHunBNDEQ)

![FImp function at AMM.sol](/files/-MQtqzKe4-6dxJBkTaVx)

### 2. Updates

### 2.1 Update Deamortized Balance of the pool for each token

In this step, the AMM saves how much it owes the user at the current Pool Value Factor "expense."&#x20;

$$\displaystyle DB\_{A\_{i}}=DB\_{A\_{i-1}} +\frac{A\_{du}}{F\_{v\_{i}}}$$&#x20;

$$\displaystyle DB\_{B\_{i}}=DB\_{B\_{i-1}} +\frac{B\_{du}}{F\_{v\_{i}}}$$&#x20;

![deamortizedBalance on \_addLiquidity at AMM.sol ](/files/-MQsUEOVd0nNa05RUkSA)

### 2.2 Update the User Balances for each token and the Pool Factor previously calculated

Updating this factor represents combining both deposits considering the time each entered the pool. $$\displaystyle UB\_{A\_{u}}=UB\_{A\_{u\_{i-1}}}\cdot \frac {F\_{v\_{i}}}{UB\_{F\_{u}}}+A\_{du}$$&#x20;

$$\displaystyle UB\_{B\_{u}}=UB\_{B\_{u\_{i-1}}}\cdot \frac {F\_{v\_{i}}}{UB\_{F\_{u}}}+B\_{du}$$&#x20;

The $$UB\_{f\_{u}}$$ works as if it was a picture of the pool's factor at the moment of this user's deposit. This factor will be updated again whenever there is a `re-add liquidity` event by the same user.&#x20;

$$UB\_{F\_{u}}=Fv\_i$$&#x20;

![Updating User Balance (userDepositSnapshot) at \_addLiquidity on AMM.sol](/files/-MQtnKp-AcxlCkVXnPWV)

### 2.3 Update Total Balance of the pool for each token

$$TB\_{A\_{i}}=TB\_{A\_{i-1}} +A\_{du}$$&#x20;

$$TB\_{B\_{i}}=TB\_{B\_{i-1}} +B\_{du}$$&#x20;

{% hint style="info" %}
At the contract level, an ERC20 transfer is happening. Total balance (TB) is just a mathematical representation. The Total balance is checked by consulting the`balanceOf()` of the pool contract of the respective token (tokenA or tokenB)
{% endhint %}

![](/files/-MQtnZCGVSnCjA2K5iuJ)

{% hint style="success" %}
Re-add liquidity ✅
{% endhint %}


---

# 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.options.pods.finance/options-amm-overview/optionamm/functions/re-add-liquidity.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.
