Functions
Last updated
Last updated
Epoch Start
init-trading-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
start-new-epoch
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
.
register-trade
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.
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.
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
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.
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
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
.
update-registration
confirm-trade
determine-pnl
settle
make-payment