Mint

Understanding the minting function step-by-step.

Mint

The event of minting an option requires the following initial information: 1. Option Amount 2. Owner

After the information was supplied to the contract, the mint function will perform the following activities:

1) Required Collateral Amount

Calculate the number of assets the user has to send to the contract to lock as collateral.

If this is a put option:

AmountToTransfer=OptionsAmountStrikePriceAmountToTransfer=OptionsAmount\cdot StrikePrice

If this is a call option:

AmountToTransfer=OptionsAmountUnderlyingAssetAmountToTransfer=OptionsAmount\cdot UnderlyingAsset

2) Consult Balances

2.1) Consult Current StrikeReservesnStrikeReserves_n

StrikeReservesnStrikeReserves_n is a variable where we store the current amount of the strike asset. If the strike asset is an interest-bearing token, it is expected that StrikeReservesnStrikeReserves_n will have accrued some interest since the last period. We are calling balanceOf() from ERC20 strike asset to check option contract strike asset balance.

StrikeReservesn=StrikeReservesi1+aTokensYieldStrikeReserves_n=StrikeReserves_{i-1}+aTokensYield

2.2) Consult Current UnderlyingReservesnUnderlyingReserves_n

UnderlyingReservesnUnderlyingReserves_nis a variable where we store the total amount of underlying assets currently locked in the protocol. This function has a precise fit with call options since in call options, the underlying asset is the asset locked as collateral. We are calling balanceOf() from ERC20 an underlying asset to check option contract strike asset balance.

3) Calculate OwnerSharesiOwnerShares_i

OwnerSharesiOwnerShares_i is a variable that stores the shares of the user based on the current option contract situation.

If i=0,OwnerSharesi=AmountToTransferi=0, OwnerShares_i=AmountToTransfer

If i0,i≠0,we identify the following cases:

If this is a put option:

OwnerSharesi=AmountToTransferTotalSharesi1StrikeReservesn+(UnderlyingReservesiStrikePrice)\displaystyle OwnerShares_i=\frac{AmountToTransfer\cdot TotalShares_{i-1}}{StrikeReserves_n+(UnderlyingReserves_i \cdot StrikePrice)}

If this is a call option:

OwnerSharesi=AmountToTransferTotalSharesi1UnderlyingReservesi+StrikeReservesiStrikePrice\displaystyle OwnerShares_i=\frac{{AmountToTransfer\cdot TotalShares_{i-1}}}{UnderlyingReserves_i+\frac{StrikeReserves_i}{StrikePrice}}

4) Updates

4.1) Update TotalSharesiTotalShares_i

TotalSharesTotalShares is the sum of all the owner's individual factor of OwnerSharesOwnerShares.

TotalSharesi=TotalSharesi1+OwnerSharesiTotalShares_i = TotalShares_{i-1} +OwnerShares_i

4.2) Update UserMintedOptionsiUserMintedOptions_i

Update the current number of outstanding options minted by the same user on the same option series.

UserMintedOptions=UserMintedOptionsi1+OptionsAmountUserMintedOptions=UserMintedOptions_{i-1}+OptionsAmount

4.3) Update OwnerSharesiOwnerShares_i

This factor updates the current owner shares. Important: If the user had previously minted options, those would be accounted for as one factor.

OwnerSharest=OwnerSharesi1+OwnerSharesiOwnerShares_t =OwnerShares_{i -1}+OwnerShares_i

4.4) Update StrikeReservesiStrikeReserves_i

UsingStrikeReservesnStrikeReserves_n (accrued with interest from the last period) we'll add the AmountToTransferAmountToTransfer to transfer used while minting this option.

StrikeReservesi=StrikeReservesn+AmountToTransferStrikeReserves_i=StrikeReserves_n+AmountToTransfer

This session described mathematically how the contract logic works. It is not needed to update the total ERC20 balances at the code level since tokens transfer to or from the contract is automatically updated with the ERC20 implementation.

Minting options ✅

Last updated