Trade
Trade function step-by-step
Last updated
Trade function step-by-step
Last updated
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:
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.
The target price will be the input for the SigmaGuesser contract.
Note that on the contract level, for each of our 4 trade functions (exactAInput / exactAOutput / exactBInput / exactBOutput
) the functions above are slightly different.
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.
This step will update the pool's new total balances, considering the trade that just happened.
At the contract level, are usually exactAmountIIn or exactAmountAOut and
is amountBIn / amountBOut
since we do not handle negatives numbers on solidity.
Note that the trade function won't update the nor the factor.
Trade ✅