Trade
Trade function step-by-step
When, in a given instant , a trade is initiated and the contract will check the following parameters to proceed:
Trade direction (from token A to token B or the opposite).
The number of tokens the user wants to buy or sell (
exactAInput
orexactBoutput
). The amounts considered in the trade will be called and , and they will be represented with the sign of the trade from the pool's point of view. If purchases options tokens, will be negative (options tokens are leaving the pool), and will be positive (stablecoins are entering the pool).The total price slippage the user allows.
Owner.
Once the contract gathered this information, it will start performing the following trade functions:
1. Calculate factors
1.1 Calculate Option Unit Theoretical Price
The contract will supply our BS implementation with the following data:
the current spot price of the underlying asset
time to maturity
strike price
risk-free rate
last sigma ()
And will get in return the updated option price ( based on the current market scenario.

1.2 Calculate total price based on the transaction amount
a) Calculate pool amounts for each token:

b) Calculate product constant
c) Calculate total transaction price, in terms of B

d) Calculate new option unit price (aka target price)
The target price will be the input for the SigmaGuesser contract.

3. Find new IV correspondent to the new unit price
At this point, the pool's inventory changed, and it represents a new "virtual price." The IV corresponding to this new virtual price reflects market information of supply and demand for this option.
So the AMM will input the new target price in the Black Scholes formula and find the new correspondent IV for this price. It uses a specific numerical method applied to Black Scholes. If you want to deep dive into how it works, explore Find next IV.
The IV found will be stored in the contracts to later feed the Weighted Average with 25% weight.

4. Updates
4.1 Update Total Balances
This step will update the pool's new total balances, considering the trade that just happened.

Note that the trade function won't update the nor the factor.
Trade ✅
Last updated
Was this helpful?