Applied Math
There could be countless combinations of events. Let's see their impact in the pool with a few examples.
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
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 . Check add liquidity
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 to .
Example Information
The event adding liquidity
will happen in the instant with the following information:
options
DAI
Owner = John
Adding liquidity
1) Calculate Factors
1.1) Calculate new price ()
The price will be calculated by the BS contract and will return a unit price, . Consider that the unit price calculated was 2 DAI per option for this example.
1.2) Calculate pool's value factor
No inventory imbalance means :
2) Updates
2.1) Update User Balance
2.2) Update Pool Factor in the moment of the user's deposit
2.3) Update total balances of the pool
2.4) Update deamortized balance of the pool for each factor
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, . Consider that the unit price calculated was 3 DAI per option for this example.
2) Calculate the Pool's opening factor
Since and ,
2.2) Calculate multipliers
2.3) Calculate withdraw amount of each token
The following will happen for a 100% withdrawal in both tokens:
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 .
Example Information
The event adding liquidity
will happen in the instant with the following information:
options
DAI
Owner = John
Adding liquidity
1) Calculate Factors
1.1) Calculate new price ()
The price will be calculated by the BS contract and will return a unit price, . Consider that the unit price calculated was 2 DAI per option for this example.
1.2) Calculate pool's value factor
No inventory imbalance means :
2) Updates
2.1) Update User Balance
2.2) Update Pool Factor in the moment of the user's deposit
2.3) Update total balances of the pool
2.4) Update deamortized balance of the pool for each factor
Add liquidity ✅
Example Information
The event trade
will happen in the instant given the following information:
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 ()
The price will be calculated by the BS contract and will return a unit price, . Consider that the unit price calculated was 4 DAI per option for this example.
1.2) Calculate total price based on transaction amount
a) Calculate pool amounts for each token:
b) Calculate product constant
c) Calculate total transaction price, in terms of token B
2) Updates
2.1) Update Total Balances
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.
and
1) Calculate new price
The price will be calculated by the BS contract and will return a unit price, . Consider that the unit price calculated was 4 DAI per option, equal to the previous period.
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.
2.2) Calculate multipliers
2.3) Calculate withdrawal amount of each token
The following will happen considering a withdrawal of 100% of the initial liquidity provided on both tokens:
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 with the following information:
options
DAI
Owner = John
Adding liquidity
1) Calculate Factors
1.1) Calculate new price ()
The price will be calculated by the BS contract and will return a unit price, . Consider that the unit price calculated was 2 DAI per option for this example.
1.2) Calculate pool's value factor
No inventory imbalance means :
2) Updates
2.1) Update User Balance
2.2) Update Pool Factor in the moment of the user's deposit
2.3) Update total balances of the pool
2.4) Update deamortized balance of the pool for each factor
John Add liquidity ✅
Example Information
The event trade
will happen in the instant given the following information:
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 ()
The price will be calculated by the BS contract and will return a unit price, . Consider that the unit price calculated was 4 DAI per option for this example.
1.2) Calculate total price based on transaction amount
a) Calculate pool amounts for each token:
b) Calculate product constant
c) Calculate total transaction price in terms of token B
2) Updates
2.1) Update Total Balances
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 with the following information:
options
DAI
Owner = John
1) Calculate Factors
1.1) Calculate new price ()
The price will be calculated by the BS contract and will return a unit price, . Consider that the unit price calculated was 3 DAI per option for this example.
1.2) Calculate pool's value factor
There is an inventory imbalance, and will be different from 1.
2) Updates
2.1) Update User Balance
2.2) Update Pool Factor in the moment of the user's deposit
2.3) Update total balances of the pool
2.4) Update deamortized balance of the pool for each factor
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, . Consider that the unit price calculated was 2 DAI per option, equal to the previous period.
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.
2.2) Calculate multipliers
2.3) Calculate the withdrawal amount of each token
The following will happen considering a 100% withdrawal of the liquidity provided initially on both tokens:
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.
Last updated