Functions

Epoch Start

(define-private
    (init-funds-available))

The function sets init-trading-funds-available to the vault's total-underlying-active * epoch-risk ensuring that the vault can never trade with more than defined by epoch-risk.

Trading

(define-public
    (start-new-epoch
	(pnl-calculator-contract <pnl-calculator-trait>)
	(expiry uint)
  	(strike-call (optional uint))
	(strike-put (optional uint))
	(barrier-up (optional uint))
	(barrier-down (optional uint)))

The function starts a new epoch by creating a new epoch-info entry and setting the strike-call, strike-put, barrier-up and barrier-down prices.

The function is only successfully executed if no options have been registered or traded and trading-allowed is true.

The function can only be called by traders.

(define-public
    (register-trade
        (amount uint) 
        (option-price-per-underlying uint) 
        (counterparty principal)))

The function allows the traders to register options to an interested counterparty.

The function is only successfully executed if there are enough trading-funds-available, trading is allowed, the strike and barrier prices for the current epoch has been set and it's called during the registration-window.

If successfully called, the function updates the counterparty-ledger entry of the seller principal.

(define-public
    (update-registration
        (new-amount uint) 
        (new-option-price-per-underlying uint) 
        (counterparty principal)))

The function allows traders to update the registration of options to a seller principal.

If successfully called, the function updates the counterparty-ledger entry of the seller principal.

(define-public
    (confirm-trade
        (amount uint) 
        (option-price-per-underlying uint)))

The function finalizes the trade of an option by transferring the premium from the vault to the counterparty.

The function is only successfully executed if the seller principal has a valid registration for the amount and price of the options.

If successfully called, the function updates the counterparty-ledger entry of the seller principal as well as the epoch-ledger entry of the current epoch.

Settlement

(define-public
    (determine-pnl
	(pnl-calculator-contract <pnl-calculator-trait>)
        (use-oracle-price bool)
        (settlement-rate (optional uint))
        (option-asset-per-underlying (optional uint))
        (price-feed-bytes (buff 8192))
        (execution-plan {
          pyth-storage-contract: <pyth-storage-trait>,
          pyth-decoder-contract: <pyth-decoder-trait>,
          wormhole-core-contract: <wormhole-core-trait>
         }))

The function receives Pyth data packages and verifies that the data has been signed by Pyth oracle's public key.

If the provided data is verified to be from the oracle calculate-pnl is executed in the pnl-calculator-contract which determines the unit-pnl of the epoch's option.

If the option is out-of-the-money (unit-pnl is zero) settle is initialized.

If the option is in-the-money (unit-pnl > zero) the contract calls payment-requester which requests a payment for the profit from the counterparty.

The function is only successfully executed if called with data with a timestamp that fits into the settlement-window.

Note: if use-oracle-price is false the function uses the settlement-rate provided as an argument.

(define-private 
    (settle))

The function is only executed once per epoch, after the current epoch is expired. It calls a series of functions:

  • to charge fees

  • to update the epoch-info map with the settled values

  • to activate pending deposit and withdrawal claims

  • to update fees and settings

  • to initialize trading-funds-available for the next epoch.

  • to reset all temporary variables for the next epoch

(define-private 
    (make-payment
        (amount uint)))

The function allows the counterparty to make a payment to the vault for the amount-requested.

Once the payment has been made the counterparty is removed from the counterparty-list as well as the counterparty-ledger.

If the total-amount-requested after the payment was made is zero, the function triggers settle.

Last updated