Buy

Taking a OTC deal using deposited token balance.

To buy a hedge the msg.sender must have a sufficient balance of the tokens being hedged, under the userBalanceMap[msg.sender] storage.

All deals on our platform are collateralized fully by both parties, amounts and type of collateral to be put up for each deal depend on the parties.

Types of deals to buy:

  • Call Option

  • Put Option

  • Equity Swap

  • Loan

Buying a deal (hedge or loan) utilizes the lockedinuse storage under userBalanceMap[msg.sender] as described in the below topic.

LockedInUse

Buying conditions:

  • A deal can be taken as long as its listed and available or unexpired.

  • Only the paired currency of the underlying assets or tokens can be used to purchase a hedge.

  • For loaning, the requested token is not strict but determined by the writer.

  • Buyer must have enough sufficient balance of the required token deposited to Vault.

  • Hedge writer always has to provide collateral, thus the payoff (if any) to the taker is always in underlying assets.

  • Hedge taker collateral type is determined by the type of deal. Options taker collateral is asked in the form of underlying tokens paired currency. Swap taker collateral is asked in the form of underlying tokens being hedged.

buyHedge Function

This function is unified to handle the taking of all hedge types (options and swaps) and will also handle loans.

All deals taken will have their storage structs, under the mapping hedgeMap updated. hedge.status is updated from 0 (available) to 1 (taken), hedge.taker is wallet address of signer or msg.sender.

// For Call and Put Options cost is premium, lockedinuse here but paid out on settlement
// For Equity Swaps cost is equal to underlying value as 100% collateral is required. There is no premium

Two helper functions are used in the process getUserTokenBalances to check if taker has sufficient balance, and getUnderlyingValue to determine the startValue of the deal in its paired currency.

The global hedge taken arrays are updated with the ID of the hedge to help with filtering. myoptionsTaken stores wallet specific trades taken. We then update the protocol volume storage hedgesTakenVolume.

The takers collateral, or available balance is then added to lockedInUse. Depending on type of deal it can be credited to the writer immediately or only handled on settlement.

All inputs should meet requirement and if successful, a hedgePurchased event is emitted to signify the writing of the deal.

Last updated

Logo

Xeon Protocol ÂĐ 2024