# SOAP

### What is SOAP?

SOAP, or Sum of All Payoffs, is essentially a snapshot view of the unrealized P\&L of all open positions against the pool. It is the amount that the Liquidity Pool would be liable to payout should all the swaps be closed immediately.&#x20;

### How is SOAP calculated?

#### Fixed Interest Rate

Tracking multiple portfolio positions using traditional computation is pretty straightforward. However, doing it on the blockchain requires a different approach due to computational cost. The IPOR AMM keeps track of each derivative by bundling all derivatives from a given leg into one virtual derivative. Every time the swap is opened or closed, its fixed interest rate is added to the "virtual" swap interest rate. Its notional value is used to calculate the weight of the interest rate.&#x20;

$$
I\_{n} = \frac{I\_{n-1} \* N\_{n-1} + I\_{s} \* N\_{s}}{N\_{n-1} + N\_{s}}
$$

Where

I - is the interest rate of the "virtual" swap at the time of "n"

N - is notional of the "virtual" swap at the time of "n"

Is - is the interest rate of the newly opened swap&#x20;

Ns - is the notional amount of freshly opened derivative&#x20;

Calculating a "virtual" swap after closing a swap is the same, only + changes to -.

Once the attributes of the "virtual swap" are calculated, we can then move to the floating rate as each IPOR swap is a difference in the cash flow between fixed and floating interest rates.&#x20;

#### Floating Interest Rate

Monitoring the floating interest rate is done through "IBT" or Interest Bearing Token. IBT is not a token that you can own; instead, it accounts for the floating interest rate over time. All interest rate swaps have their notional amount denominated in IBT to account for the floating interest rate.&#x20;

$$
IBT\_{new} = IBT\_{old} \cdot e ^{\frac{IPOR \cdot \Delta T}{T\_{Year}}}
$$

Where IPOR is the IPOR rate at the time of calculating the IBT value adjusted for delta time.&#x20;

Every time the swap is opened or closed, it gets assigned with the amount of IBT reflecting its notional size.

$$
N\_{IBT} = \frac{N}{IBT}
$$

A swap's notional denominated in IBT will grow with the floating rate. Thanks to this mechanism, the floating rate part of each swap are straightforward to calculate. We multiply IBT token count specific to a given derivative. Because in SOAP, we want to calculate the "aggregate" swap to track the whole portfolio; we have to add all of the IBT tokens together for a given leg - this represents the floating leg.

#### Putting it all together

The net payout would be the difference between interest generated by the fixed and floating legs in the delta time. It is, however, a little problematic to efficiently calculate it. We would need to track somehow the "average" entry-level of IBT for all derivatives, similar to what is done with the fixed rate. Alternatively, we could follow the interest accrued between each rebalance triggered every time swap is opened or closed. It then becomes a lot easier:&#x20;

$$
SOAP\_{payFixed\_{n}} = SOAP\_{n-1} + N\_{IBT} \cdot IBT\_{price} - N\_{n-1} \cdot e^{\frac{R \* \Delta T}{T\_{year}}}
$$

$$
SOAP\_{receiveFixed\_n} = SOAP\_{n-1} + N \cdot e^{\frac{R \* \Delta T}{T\_{year}}} - N\_{IBT} \cdot IBT\_{price}
$$

$$
SOAP = SOAP\_{payFixed\_{N}} + SOAP\_{receiveFixed\_{n}}
$$

Where

**N** is the amount of notional from the last rebalancing&#x20;

**R** is the average fixed rate at the time of the previous rebalancing&#x20;

This simple calculation allows us to count the liability of opened swaps at the time of rebalancing. The interest "accrued"  on the floating rate is cached and updated at each rebalancing.

The last step is to account for the interest generated in between each rebalancing, but at this point, it is pretty straightforward. Since the IBT calculation is done in the same way, the fixed interest rate can be easily calculated for any given moment; we can then recycle the same formula to know precisely the state of the liabilities at any given moment.&#x20;

### Use of SOAP

Currently, SOAP is used in two places:&#x20;

* when calculating the worth of liquidity tokens (seem more in the [liquidity section](/ipor-derivatives/automated-market-maker/liquidity-provisioning.md))
* when assessing the risk of the liquidity pool&#x20;


---

# 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.ipor.io/ipor-derivatives/automated-market-maker/soap.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.
