Applied Math
There could be countless combinations of events. Let's see their impact in the pool with a few examples.

The examples below aim to highlight a few properties that the AMM pools currently hold and their effects on the pool and liquidity providers.
For simplicity, consider the following information about the pool and the option:
input name
Description Pool
asset pair
ETH:DAI
option type
Put
exercise type
European
strike price
$400
spot price (Chainlink)
$500
expiration
31 Dec 2020
current day
21 Nov 2020
FviFv_i
1
Please consider that the function "add" in this context stands for adding liquidity for the first time in a pool or when the pool has no imbalance, meaning, in both cases
Fvi=1Fv_i=1
. Check add liquidity for further details.

This example explores the scenario where a user adds liquidity for the first time. The option price was updated mostly based on external factors (time passed and time to maturity changed or spot price of the underlying asset changed). There are no trades during the period the user kept liquidity in the pool, and the user removes liquidity without losing value on its initial deposit.
In this scenario, we'll see that the user will withdraw the same amount of assets it deposited initially, even if the price changed from
Pi1P_{i-1}
to
PiP_i
.

The event adding liquidity will happen in the instant
i=0i= 0
with the following information:
  • Adu=100A_{du}=100
    options
  • Bdu=205B_{du}= 205
    DAI
  • Owner = John

The price will be calculated by the BS contract and will return a unit price,
PiP_i
. Consider that the unit price calculated was 2 DAI per option for this example.
Pi=2P_i=2

No inventory imbalance means
Fvi=1Fv_i=1
:
Fvi=(TB(A)i1Pi+TB(B)i1)(DB(A)i1Pi+DB(B)i1)\displaystyle Fv_i= \frac{(TB(A)_{i-1}\cdot P_i+TB(B)_{i-1})}{(DB(A)_{i-1} \cdot P_i+DB(B)_{i-1})}
TB(A)i1=DB(A)i1TB(A)_{i-1}=DB(A)_{i-1}
TB(B)i1=DB(B)i1TB(B)_{i-1}=DB(B)_{i-1}

UB(A)u=AiUB(A)_u=A_i
100=Ai100 = A_i
UB(B)u=BiUB(B)_u=B_i
205=Bi205=B_i

UB(F)u=1UB(F)_u=1

TB(A)i=TB(A)i1+AduTB(A)_i=TB(A)_i-_1 +A_{du}
TB(A)i=0+100=100TB(A)_i=0+100 = 100
TB(B)i=TB(B)i1+BduTB(B)_i=TB(B)_{i-1} +B_{du}
TB(B)i=0+205=205TB(B)_i=0 +205=205

DB(A)i=DB(A)i1+AduFvi\displaystyle DB(A)_i=DB(A)_{i-1} + \frac{A_{du}}{Fv_i}
DB(A)i=0+1001=100\displaystyle DB(A)_i=0+\frac{100}{1}=100
DB(B)i=DB(B)i1+BduFvi\displaystyle DB(B)_i=DB(B)_{i-1} +\frac{B_{du}}{Fv_i}
DB(B)i=0+2051=205\displaystyle DB(B)_i=0+\frac{205}{1}=205
Add liquidity ✅

Assuming that there were no trades, the price moved, and the user wanted to remove liquidity.

The price will be calculated by the BS contract and will return a unit price,
PiP_i
. Consider that the unit price calculated was 3 DAI per option for this example.
Pi=3P_i=3

Since
TB(A)i=DB(A)iTB(A)_i= DB(A)_i
and
TB(B)i=DB(B)iTB(B)_i= DB(B)_i
,
Fvi+1=1Fv_{i+1}=1
Fvi=(TB(A)i1Pi+TB(B)i1)(DB(A)i1Pi+DB(B)i1)=1\displaystyle Fv_i= \frac{(TB(A)_{i-1}\cdot P_i+TB(B)_{i-1})}{(DB(A)_{i-1} \cdot P_i+DB(B)_{i-1})}= 1

mAAi=min(FviDB(A)i1;TB(A)i1)DB(A)i1=1\displaystyle mAA_i= \frac{min(Fv_i\cdot DB(A)_{i-1};TB(A)_{i-1})}{DB(A)_{i-1}}=1
mAAi=1mAA_i=1
mBBi=min(FviDB(B)i1;TB(B)i1)DB(B)i1=1\displaystyle mBB_i= \frac{min(Fv_i\cdot DB(B)_{i-1};TB(B)_{i-1})}{DB(B)_{i-1}} =1
mBBi=1mBB_i=1

The following will happen for a 100% withdrawal in both tokens:
Ai=[mAAiraUB(A)uFvdu+mBAirbUB(B)uFvdu]\displaystyle A_i=-[mAA_i\cdot r_a\cdot \frac{UB(A)u}{Fv_{du}}+mBA_i\cdot r_b\cdot \frac {UB(B)u}{Fv_{du}}]
UB(A)u=Ai-UB(A)_u =-A_i
UB(A)u=100-UB(A)_u=-100
Bi=[mBBirbUB(B)uFvdu+mABiraUB(A)uFvdu]\displaystyle B_i=-[mBB_i\cdot r_b\cdot \frac{UB(B)u}{Fv_{du}} + mAB_i \cdot r_a\cdot \frac {UB(A)_u}{Fv_{du}}]
UB(B)u=Bi-UB(B)_u =-B_i
UB(B)u=205-UB(B)_u=-205
Therefore, the users in this scenario will withdraw the same amount of tokens in the same proportion they provided initially.
There are further steps on the remove liquidity function, but after calculating the withdrawal amount for each token, it is possible to see that the user won't lose value if there is a price change with no trades.
Price moves without trade won't impact liquidity providers' withdrawal value amount either the proportion of assets.

This example explores the scenario where a user adds liquidity for the first time, and the option price was updated. There are trades followed by immediate withdraw of funds.
In this scenario, we'll see that the user will withdraw a different amount of assets from what it had deposited originally. Still, its withdrawal value is not impacted since
Pi=Pi1P_i = P_{i-1}
.

The event adding liquidity will happen in the instant
i=0i= 0
with the following information:
  • Adu=100A_{du}=100
    options
  • Bdu=205B_{du}= 205
    DAI
  • Owner = John

The price will be calculated by the BS contract and will return a unit price,
PiP_i
. Consider that the unit price calculated was 2 DAI per option for this example.
Pi=2P_i=2

No inventory imbalance means
Fvi=1Fv_i=1
:
Fvi=(TB(A)i1Pi+TB(B)i1)(DB(A)i1Pi+DB(B)i1)=1\displaystyle Fv_i= \frac{(TB(A)_{i-1}\cdot P_i+TB(B)_{i-1})}{(DB(A)_{i-1} \cdot P_i+DB(B)_{i-1})}= 1
TB(A)i1=DB(A)i1TB(A)_{i-1}=DB(A)_{i-1}
TB(B)i1=DB(B)i1TB(B)_{i-1}=DB(B)_{i-1}

UB(A)u=AiUB(A)_u=A_i
100=Ai100 = A_i
UB(B)u=BiUB(B)_u=B_i
205=Bi205=B_i

UB(F)u=1UB(F)_u=1

TB(A)i=TB(A)i1+AduTB(A)_i=TB(A)_{i-1} +A_{du}
TB(A)i=0+100=100TB(A)_i=0+100 = 100
TB(B)i=TB(B)i1+BduTB(B)_i=TB(B)_{i-1} +B_{du}
TB(B)i=0+205=205TB(B)_i=0 +205=205

DB(A)i=DB(A)i1+AduFvi\displaystyle DB(A)_i=DB(A)_{i-1} +\frac{A_{du}}{Fv_i}
DB(A)i=0+1001=100\displaystyle DB(A)_i=0+\frac{100}{1}=100
DB(B)i=DB(B)i1+BduFvi\displaystyle DB(B)_i=DB(B)_{i-1} +\frac{B_{du}}{Fv_i}
DB(B)i=0+2051=205\displaystyle DB(B)_i=0+\frac{205}{1}=205
Add liquidity ✅

The event trade will happen in the instant
i=1i= 1
given the following information:
  • Adu=2A_{du}=-2
    options (negative to show that the options will leave the contract)
  • Trade direction = user wants to receive exact amount of token A (trade function will follow the exactAOutput setup)
  • Max price slippage 20%
  • Owner = Gui

The price will be calculated by the BS contract and will return a unit price,
PiP_i
. Consider that the unit price calculated was 4 DAI per option for this example.
Pi=4P_i=4

poolAmountA=min(TB(A);TB(B)Pi)\displaystyle poolAmountA = min(TB(A);\frac{TB(B)}{P_i})
poolAmountA=min(100;2054)\displaystyle poolAmountA=min(100;\frac{205}{4})
poolAmountA=51.25poolAmount A=51.25
poolAmountB=min(TB(B);TB(A)Pi)poolAmountB=min(TB(B);TB(A)\cdot P_i)
poolAmountB=min(205;1004)poolAmountB=min(205;100\cdot 4)
poolAmountB=205poolAmountB=205

k=poolAmountApoolAmountBk=poolAmountA\cdot poolAmountB
k=51.25205=10,506.25k=51.25\cdot 205= 10,506.25

Bi=10,506.25(51.252)205\displaystyle B_i= \frac{10,506.25}{(51.25-2)}-205
Bi=213.32205=8.32B_i=213.32-205= 8.32

TB(A)i=TB(A)i1+AduTB(A)_i=TB(A)_i-_1 +A_{du}
TB(A)i=100+(2)=98TB(A)_i=100+ (-2)=98
TB(B)i=TB(B)i1+BduTB(B)_i=TB(B)_i-_1 +B_{du}
TB(B)i=205+8.32=213.32TB(B)_i=205+8.32= 213.32
Trade ✅

Assuming that John decides to remove the total liquidity immediately after the trade, considering that there were no changes in the price after the trade and removing liquidity events.
ra=1r_a=1
and
rb=1r_b=1

The price will be calculated by the BS contract and will return a unit price,
PiP_i
. Consider that the unit price calculated was 4 DAI per option, equal to the previous period.
Pi=4P_i=4

Since there was a trade, the factors TB(A) and TB(B) are no longer equal to DB(a) and DB(B). Therefore, the pool's opening factor will be different from 1.
Fvi=(TB(A)i1Pi+TB(B)i1)(DB(A)i1Pi+DB(B)i1)\displaystyle Fv_i= \frac{(TB(A)_{i-1}\cdot P_i+TB(B)_{i-1})}{(DB(A)_{i-1} \cdot P_i+DB(B)_{i-1})}
Fvi=(984+213.32)(1004+205)Fv_i=\frac{(98 \cdot 4+213.32)}{(100\cdot 4+205)}
Fvi=605.32/605=1.00052893Fv_i= 605.32/605=1.00052893

mAAi=min(FviDB(A)i1;TB(A)i1)DB(A)i1\displaystyle mAA_i= \frac{min(Fv_i\cdot DB(A)_{i-1};TB(A)_{i-1})}{DB(A)_{i-1}}
mAAi=min(100.0528;0.98)=0.98mAA_i=min(100.0528;0.98)=0.98
mBBi=min(FviDB(B)i1;TB(B)i1)DB(B)i1\displaystyle mBB_i= \frac{min(Fv_i\cdot DB(B)_{i-1};TB(B)_{i-1})}{DB(B)_{i-1}}
mBBi=min(205.1082;1.0405)=1.0405mBB_i=min(205.1082;1.0405)=1.0405
mABi=TB(B)i1mBBiDB(B)i1DB(A)i1\displaystyle mAB_i= \frac{TB(B)_{i-1}-mBB_i\cdot DB(B)_{i-1}}{DB(A)_{i-1}}
mABi=213.32(1.0405205)100=0.000175\displaystyle mAB_i=\frac{213.32-(1.0405\cdot 205)}{100}=0.000175
mBAi=TB(A)i1mAAiDB(A)i1DB(B)i1\displaystyle mBA_i= \frac{TB(A)_{i-1}-mAA_i\cdot DB(A)_{i-1}}{DB(B)_{i-1}}
mBAi=98(0.98100)205=0\displaystyle mBA_i=\frac{98-(0.98*100)}{205}=0

The following will happen considering a withdrawal of 100% of the initial liquidity provided on both tokens:
Ai=[mAAiraUB(A)uFvdu+mBAirbUB(B)uFvdu]\displaystyle A_i=-[mAA_i\cdot r_a\cdot \frac{UB(A)u}{Fv_{du}}+mBA_i\cdot r_b\cdot \frac {UB(B)u}{Fv_{du}}]
Ai=[0.981(1001)+0]=98A_i=-[0.98\cdot 1\cdot (\frac{100}{1})+0]=-98
Bi=[mBBirbUB(B)uFvdu+mABiraUB(A)uFvdu]\displaystyle B_i=-[mBB_i\cdot r_b\cdot \frac{UB(B)u}{Fv_{du}} + mAB_i \cdot r_a\cdot \frac {UB(A)_u}{Fv_{du}}]
Bi=[1.04051(2051)+0.0001751(1001)]=213.32B_i=-[1.0405\cdot1\cdot (\frac{205}{1})+0.000175\cdot 1\cdot (\frac{100}{1})]=-213.32
Therefore, in this scenario, the user had an impermanent gain expressed in the amount of token B in the withdrawal.
There are further steps on the remove liquidity function, but after calculating the withdrawal amount for each token, it is possible to verify the property exposed.
Trade followed by withdrawal with no price move from the trade moment doesn't incur different value to be withdrawn but different proportions between assets, reflecting the trade.

This example explores the scenario where a user adds liquidity for the first time, the option price was updated, there are trades in the pool, e price moved again, and the user withdraws funds.
In this scenario, we'll see that the user will withdraw a different amount of assets from what it had deposited originally. They may reflect an impermanent loss or gain, the trade position, and the latest price movements.

The event adding liquidity will happen in the instant
i=0i= 0
with the following information:
  • Adu=100A_{du}=100
    options
  • Bdu=205B_{du}= 205
    DAI
  • Owner = John

The price will be calculated by the BS contract and will return a unit price,
PiP_i
. Consider that the unit price calculated was 2 DAI per option for this example.
Pi=2P_i=2

No inventory imbalance means
Fvi=1Fv_i=1
:
Fvi=(TB(A)i1Pi+TB(B)i1)(DB(A)i1Pi+DB(B)i1)=1\displaystyle Fv_i= \frac{(TB(A)_{i-1}\cdot P_i+TB(B)_{i-1})}{(DB(A)_{i-1} \cdot P_i+DB(B)_{i-1})}= 1
TB(A)i1=DB(A)i1TB(A)_{i-1}=DB(A)_{i-1}
TB(B)i1=DB(B)i1TB(B)_{i-1}=DB(B)_{i-1}

UB(A)u=AiUB(A)_u=A_i
100=Ai100 = A_i
UB(B)u=BiUB(B)_u=B_i
205=Bi205=B_i

UB(F)u=1UB(F)_u=1

TB(A)i=TB(A)i1+AduTB(A)_i=TB(A)_{i-1} +A_{du}
TB(A)i=0+100=100TB(A)_i=0+100 = 100
TB(B)i=TB(B)i1+BduTB(B)_i=TB(B)_{i-1} +B_{du}
TB(B)i=0+205=205TB(B)_i=0 +205=205

DB(A)i=DB(A)i1+AduFvi\displaystyle DB(A)_i=DB(A)_{i-1} +\frac{A_{du}}{Fv_i}
DB(A)i=0+1001=100DB(A)_i=0+\frac{100}{1}=100
DB(B)i=DB(B)i1+BduFvi\displaystyle DB(B)_i=DB(B)_{i-1} +\frac{B_{du}}{Fv_i}
DB(B)i=0+2051=205DB(B)_i=0+\frac{205}{1}=205
John Add liquidity ✅

The event trade will happen in the instant
i=1i= 1
given the following information:
  • Adu=2A_du=-2
    options (negative to show that the options will leave the contract)
  • Trade direction = user wants to receive exact amount of token A (trade function will follow the exactAOutput setup)
  • Max price slippage 20%
  • Owner = Gui

The price will be calculated by the BS contract and will return a unit price,
PiP_i
. Consider that the unit price calculated was 4 DAI per option for this example.
Pi=4P_i=4

poolAmountA=min(TB(A);TB(B)Pi)\displaystyle poolAmountA = min(TB(A);\frac{TB(B)}{P_i})
poolAmountA=min(100;2054)poolAmountA=min(100;\frac{205}{4})
poolAmountA=51.25poolAmount A=51.25
poolAmountB=min(TB(B);TB(A)Pi)poolAmountB=min(TB(B);TB(A)\cdot P_i)
poolAmountB=min(205;1004)poolAmountB=min(205;100\cdot 4)
poolAmountB=205poolAmountB=205

k=poolAmountApoolAmountBk=poolAmountA\cdot poolAmountB
k=51.25205=10,506.25k=51.25\cdot 205= 10,506.25

Bi=10,506.25(51.252)205B_i= \frac{10,506.25}{(51.25-2)}-205
Bi=213.32205=8.32B_i=213.32-205= 8.32

TB(A)i=TB(A)i1+AduTB(A)_i=TB(A)_{i-1} +A_{du}
TB(A)i=100+(2)=98TB(A)_i=100+ (-2)=98
TB(B)i=TB(B)i1+BduTB(B)_i=TB(B)_{i-1} +B_{du}
TB(B)i=205+8.32=213.32TB(B)_i=205+8.32= 213.32
Gui bought options Trade ✅

Consider that a second user, Bob, wants to add liquidity to the pool at this moment.

The event adding liquidity will happen in the instant
i=0i= 0
with the following information:
  • Adu=50A_{du}=50
    options
  • Bdu=30B_{du}= 30
    DAI
  • Owner = John

The price will be calculated by the BS contract and will return a unit price,
PiP_i
. Consider that the unit price calculated was 3 DAI per option for this example.
Pi=3P_i=3

There is an inventory imbalance, and
FviFv_i
will be different from 1.
Fvi=(TB(A)i1Pi+TB(B)i1)(DB(A)i1Pi+DB(B)i1)\displaystyle Fv_i= \frac{(TB(A)_{i-1}\cdot P_i+TB(B)_{i-1})}{(DB(A)_{i-1} \cdot P_i+DB(B)_{i-1})}
Fvi=(983+213.32)(1003+205)=1.00459406Fv_i=\frac{(98\cdot3+213.32)}{(100\cdot 3+205)}= 1.00459406

UB(A)u=AiUB(A)_u=A_i
50=Ai50 = A_i
UB(B)u=BiUB(B)_u=B_i
30=Bi30=B_i

UB(F)u=1.00459406UB(F)_u=1.00459406

TB(A)i=TB(A)i1+AduTB(A)_i=TB(A)_{i-1} +A_{du}
TB(A)i=98+50=148TB(A)_i=98+50 = 148
TB(B)i=TB(B)i1+BduTB(B)_i=TB(B)_{i-1} +B_{du}
TB(B)i=213.32+30=243.32TB(B)_i=213.32+30=243.32

DB(A)i=DB(A)i1+AduFvi\displaystyle DB(A)_i=DB(A)_{i-1} +\frac{A_{du}}{Fv_i}