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
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=1 . Check for further details.
APR
Add, Price Moves, Remove
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 Pi−1 to Pi .
Example Information
The event adding liquidity will happen in the instant i=0 with the following information:
Adu=100 options
Bdu=205 DAI
Owner = John
Adding liquidity
1) Calculate Factors
1.1) Calculate new price (Pi)
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 2 DAI per option for this example.
2.2) Update Pool Factor in the moment of the user's deposit
UB(F)u=1
2.3) Update total balances of the pool
TB(A)i=TB(A)i−1+Adu
TB(A)i=0+100=100
TB(B)i=TB(B)i−1+Bdu
TB(B)i=0+205=205
2.4) Update deamortized balance of the pool for each factor
DB(A)i=DB(A)i−1+FviAdu
DB(A)i=0+1100=100
DB(B)i=DB(B)i−1+FviBdu
DB(B)i=0+1205=205
Add liquidity ✅
Remove liquidity
Assuming that there were no trades, the price moved, and the user wanted to remove liquidity.
1) Calculate new price
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 3 DAI per option for this example.
Pi=3
2) Calculate the Pool's opening factor
Since TB(A)i=DB(A)i and TB(B)i=DB(B)i, Fvi+1=1
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.
ATR
Add, Trade, Remove
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=Pi−1 .
Example Information
The event adding liquidity will happen in the instant i=0 with the following information:
Adu=100 options
Bdu=205 DAI
Owner = John
Adding liquidity
1) Calculate Factors
1.1) Calculate new price (Pi)
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 2 DAI per option for this example.
2.2) Update Pool Factor in the moment of the user's deposit
UB(F)u=1
2.3) Update total balances of the pool
TB(A)i=TB(A)i−1+Adu
TB(A)i=0+100=100
TB(B)i=TB(B)i−1+Bdu
TB(B)i=0+205=205
2.4) Update deamortized balance of the pool for each factor
DB(A)i=DB(A)i−1+FviAdu
DB(A)i=0+1100=100
DB(B)i=DB(B)i−1+FviBdu
DB(B)i=0+1205=205
Add liquidity ✅
Example Information
The event trade will happen in the instant i=1 given the following information:
Adu=−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
Trade
1) Calculate Factors
1.1) Calculate new price (Pi+1)
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 4 DAI per option for this example.
Pi=4
1.2) Calculate total price based on transaction amount
a) Calculate pool amounts for each token:
poolAmountA=min(TB(A);PiTB(B))
poolAmountA=min(100;4205)
poolAmountA=51.25
poolAmountB=min(TB(B);TB(A)⋅Pi)
poolAmountB=min(205;100⋅4)
poolAmountB=205
b) Calculate product constant
k=poolAmountA⋅poolAmountB
k=51.25⋅205=10,506.25
c) Calculate total transaction price, in terms of token B
Bi=(poolAmountA−tradeAmountA)k−poolAmountB
Bi=(51.25−2)10,506.25−205
Bi=213.32−205=8.32
2) Updates
2.1) Update Total Balances
TB(A)i=TB(A)i−1+Adu
TB(A)i=100+(−2)=98
TB(B)i=TB(B)i−1+Bdu
TB(B)i=205+8.32=213.32
Trade ✅
Remove liquidity
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=1 and rb=1
1) Calculate new price
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 4 DAI per option, equal to the previous period.
Pi=4
2) Calculate the Pool's opening factor
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.
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.
ATPR
Add, Trade, Price moves, Removes
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.
Example Information
The event adding liquidity will happen in the instant i=0 with the following information:
Adu=100 options
Bdu=205 DAI
Owner = John
Adding liquidity
1) Calculate Factors
1.1) Calculate new price (Pi)
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 2 DAI per option for this example.
2.2) Update Pool Factor in the moment of the user's deposit
UB(F)u=1
2.3) Update total balances of the pool
TB(A)i=TB(A)i−1+Adu
TB(A)i=0+100=100
TB(B)i=TB(B)i−1+Bdu
TB(B)i=0+205=205
2.4) Update deamortized balance of the pool for each factor
DB(A)i=DB(A)i−1+FviAdu
DB(A)i=0+1100=100
DB(B)i=DB(B)i−1+FviBdu
DB(B)i=0+1205=205
John Add liquidity ✅
Example Information
The event trade will happen in the instant i=1 given the following information:
Adu=−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
Trade
1) Calculate Factors
1.1) Calculate new price (Pi+1)
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 4 DAI per option for this example.
Pi=4
1.2) Calculate total price based on transaction amount
a) Calculate pool amounts for each token:
poolAmountA=min(TB(A);PiTB(B))
poolAmountA=min(100;4205)
poolAmountA=51.25
poolAmountB=min(TB(B);TB(A)⋅Pi)
poolAmountB=min(205;100⋅4)
poolAmountB=205
b) Calculate product constant
k=poolAmountA⋅poolAmountB
k=51.25⋅205=10,506.25
c) Calculate total transaction price in terms of token B
Bi=(poolAmountA−tradeAmountA)k−poolAmountB
Bi=(51.25−2)10,506.25−205
Bi=213.32−205=8.32
2) Updates
2.1) Update Total Balances
TB(A)i=TB(A)i−1+Adu
TB(A)i=100+(−2)=98
TB(B)i=TB(B)i−1+Bdu
TB(B)i=205+8.32=213.32
Gui bought options
Trade ✅
Adding Liquidity (2nd time)
Consider that a second user, Bob, wants to add liquidity to the pool at this moment.
Example Information
The event adding liquidity will happen in the instant i=0 with the following information:
Adu=50 options
Bdu=30 DAI
Owner = John
1) Calculate Factors
1.1) Calculate new price (Pi)
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 3 DAI per option for this example.
Pi=3
1.2) Calculate pool's value factor
There is an inventory imbalance, and Fvi will be different from 1.
2.2) Update Pool Factor in the moment of the user's deposit
UB(F)u=1.00459406
2.3) Update total balances of the pool
TB(A)i=TB(A)i−1+Adu
TB(A)i=98+50=148
TB(B)i=TB(B)i−1+Bdu
TB(B)i=213.32+30=243.32
2.4) Update deamortized balance of the pool for each factor
DB(A)i=DB(A)i−1+FviAdu
DB(A)i=100+1.0045940650=149.7713
DB(B)i=DB(B)i−1+FviBdu
DB(B)i=205+1.0045940630=234.8628
Bob Add liquidity ✅
Remove liquidity
Assuming that John decides to remove liquidity and that the price after changed again.
1) Calculate new price
The price will be calculated by the BS contract and will return a unit price, Pi. Consider that the unit price calculated was 2 DAI per option, equal to the previous period.
Pi=2
2) Calculate the Pool's opening factor
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.
Trade followed by price moves can cause a change in the pool's value and proportion. The impermanent loss or gain is likely in this scenario, and it is fairly distributed among liquidity providers.