Olive Docs
Smart Contract

Options Smart Contracts

Options Smart Contracts

This page documents option instruction files in execution order.

For options:

Call option locked backing = SOL.
Put option locked backing = USDC.

open_option.rs

Current flow:

  1. Validate the option parameters, owner, pool, custodies, oracle accounts, funding account, and token accounts.
  2. Read current oracle prices.
  3. Price the option with Black-Scholes.
  4. Calculate quantity_scaled from the amount the user pays.
  5. Calculate locked_amount.
  6. For a call, locked_amount is the underlying token amount, for example SOL contracts.
  7. For a put, locked_amount is quantity * strike in USDC.
  8. Calculate the open fee.
  9. Check the user funding account has premium + fee.
  10. Check locked_custody.token_owned - locked_custody.token_locked >= locked_amount.
  11. Transfer premium + fee from the user to pay_custody.
  12. Increase pay_custody.token_owned by premium + fee.
  13. Store premium fields on the option account.
  14. Increase locked_custody.token_locked by locked_amount.
  15. Check locked_custody.token_owned >= locked_custody.token_locked.
  16. Add fixed-rate exposure for the locked custody.
  17. Store option state.

Liquidity check:

  1. The file checks free locked-custody liquidity before user payment and before increasing token_locked.
  2. User premium does not count toward the collateral needed to open the same option.
  3. The file keeps the final locked_custody.token_owned >= locked_custody.token_locked assertion after locking.

Extra detail:

  1. If pay_custody == locked_custody, the newly paid premium is still transferred after the lock-availability check.
  2. This keeps option backing strict: the pool must already have enough free backing before selling the option.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

open_limit_option.rs

Current flow:

  1. Validate the limit option parameters, owner, pool, custodies, oracle accounts, funding account, and token accounts.
  2. Read current oracle prices.
  3. Calculate the expected quantity and premium fields.
  4. Calculate the open fee.
  5. Calculate total_payment = premium + fee.
  6. Check the user funding account has total_payment.
  7. Transfer total_payment from the user to pay_custody.
  8. Increase pay_custody.token_owned by total_payment.
  9. Calculate the future locked_amount.
  10. Store the pending option with executed = false.
  11. Do not increase locked_custody.token_locked.
  12. Do not add fixed-rate exposure yet.

Liquidity check:

  1. No pool liquidity is locked at placement.
  2. Because no lock is created at placement, free-liquidity backing should be checked at execution, not placement.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

execute_limit_option.rs

Current flow:

  1. Validate the pending option account and keeper/execution authority.
  2. Check the limit trigger conditions.
  3. Recalculate the option quantity and locked amount at execution.
  4. For a call, calculate the SOL amount to lock.
  5. For a put, calculate the USDC amount to lock.
  6. Check locked_custody.token_owned - locked_custody.token_locked >= new_locked_amount.
  7. Increase locked_custody.token_locked by the new locked amount.
  8. Check locked_custody.token_owned >= locked_custody.token_locked.
  9. Add fixed-rate exposure.
  10. Mark the option as executed.
  11. Store execution fields.

Liquidity check:

  1. This file checks free liquidity before increasing token_locked.
  2. It also keeps a post-lock solvency assertion after the lock is created.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

close_option.rs

Current flow:

  1. Validate the option, owner, quantity, pool, custodies, and token accounts.
  2. Calculate the proportional amount being closed.
  3. Calculate the close premium using current Black-Scholes price.
  4. Calculate the protocol close fee.
  5. Calculate the raw refund amount from the locked backing asset.
  6. Subtract the close fee from the raw refund.
  7. Convert the refund value into the user's selected receive asset.
  8. If the receive asset matches the locked backing asset, require settlement_tokens <= unlock_amount.
  9. If the receive asset is the cross asset, require receive_custody.token_owned - receive_custody.token_locked >= settlement_tokens.
  10. Unlock the option backing.
  11. Subtract settlement_tokens from the selected receive custody token_owned.
  12. Transfer settlement_tokens to the user.
  13. Reduce or close the option account.
  14. Remove fixed-rate exposure.

Liquidity check by case:

  1. Call, receive SOL: allows payout from locked SOL, bounded by the SOL unlock amount.
  2. Call, receive USDC: checks free USDC because USDC is cross-asset.
  3. Put, receive USDC: allows payout from locked USDC, bounded by the USDC unlock amount.
  4. Put, receive SOL: checks free SOL because SOL is cross-asset.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

close_limit_option.rs

Executed option close flow:

  1. Validate the option, owner, quantity, pool, custodies, oracle accounts, and token accounts.
  2. If the option is executed and valid, calculate close premium and close fee.
  3. Calculate the refund from the locked backing asset.
  4. Convert the refund value into the selected receive asset.
  5. Check same-asset payout against unlocked backing or cross-asset payout against free liquidity.
  6. Decrease locked_custody.token_locked by the unlock amount.
  7. Subtract settlement_tokens from selected receive custody token_owned.
  8. Transfer settlement_tokens to the user.
  9. Reduce or close the option account.
  10. Remove fixed-rate exposure.

Executed option liquidity check by case:

  1. Call, receive SOL: allows payout from locked SOL, bounded by the unlock amount.
  2. Call, receive USDC: checks free USDC because USDC is cross-asset.
  3. Put, receive USDC: allows payout from locked USDC, bounded by the unlock amount.
  4. Put, receive SOL: checks free SOL because SOL is cross-asset.

Unexecuted option cancel/refund flow:

  1. If the option is not executed, validate the funding account mint matches pay_custody.
  2. Calculate the proportional premium refund.
  3. Check pay_custody.token_owned - pay_custody.token_locked >= premium_refund.
  4. Transfer the premium refund to the user.
  5. Subtract premium_refund from pay_custody.token_owned.
  6. Reduce or close the pending option account.

Unexecuted option liquidity note:

  1. This refund is not locked backing.
  2. Current code uses pay_custody.token_owned - pay_custody.token_locked >= premium_refund.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

cancel_limit_option.rs

Current flow:

  1. This file is an alias/delegation path.
  2. It calls close_limit_option.rs with the same parameters.

Liquidity check:

  1. It inherits all executed and unexecuted logic from close_limit_option.rs.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

exercise_option.rs

Current flow:

  1. Validate the option, owner, exercise quantity, pool, locked custody, and token accounts.
  2. Calculate unlock_amount proportionally.
  3. Check locked_custody.token_locked >= unlock_amount.
  4. For a call, require current price is above strike.
  5. For a call, calculate profit from current price - strike.
  6. Require call exercise profit is bounded by unlock_amount.
  7. Transfer call exercise profit from locked SOL custody to the user.
  8. For a put, require strike is above current price.
  9. For a put, calculate profit from strike - current price.
  10. Require put exercise profit is bounded by unlock_amount.
  11. Transfer put exercise profit from locked USDC custody to the user.
  12. Subtract the transferred profit from locked_custody.token_owned.
  13. Decrease locked_custody.token_locked by unlock_amount.
  14. Remove fixed-rate exposure.
  15. Update option exercise state.

Liquidity check:

  1. Same-asset payout from locked backing is allowed.
  2. The file checks locked balance is at least the unlock amount.
  3. It explicitly checks profit <= unlock_amount.

Accounting note:

  1. The file transfers profit from custody.
  2. The file reduces token_locked.
  3. The file reduces token_owned by the transferred profit amount.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

auto_exercise.rs

Current flow:

  1. Check whether an expired option is in the money.
  2. Calculate the profit amount.
  3. Require profit is bounded by the locked option amount.
  4. Transfer profit immediately from locked custody to the user.
  5. Subtract transferred profit from locked custody token_owned.
  6. Mark the option invalid/exercised.
  7. Decrease locked_custody.token_locked by the option amount.
  8. Remove fixed-rate exposure.

Liquidity check:

  1. Token transfer happens immediately in this instruction.
  2. Same-asset payout from locked backing is allowed.
  3. Profit payout must be bounded by the locked option amount.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

execute_tp_sl_order.rs Option Branch

Current flow:

  1. Validate the TP/SL order.
  2. Calculate the option settlement amount.
  3. Convert settlement into selected receive asset.
  4. Check same-asset payout against released locked backing or cross-asset payout against free liquidity.
  5. Transfer settlement to the user.
  6. Decrease locked SOL for calls or locked USDC for puts.
  7. Remove fixed-rate exposure.
  8. Subtract settlement from selected receive custody token_owned.
  9. Reduce or close the option account.

Liquidity check by case:

  1. Call TP/SL, receive SOL: checks payout is bounded by released locked SOL.
  2. Call TP/SL, receive USDC: checks free USDC.
  3. Put TP/SL, receive USDC: checks payout is bounded by released locked USDC.
  4. Put TP/SL, receive SOL: checks free SOL.

To-do / extra edits:

  1. This has been perfected and there is nothing left to do.

On this page