A secure and flexible smart contract platform for trading call and put options on the Stacks blockchain. This platform enables users to write, buy, and exercise options contracts using SIP-010 compliant tokens as collateral.
- Write and trade both CALL and PUT options
- SIP-010 token support with whitelisting
- Built-in price oracle integration
- Collateral management system
- Position tracking for writers and holders
- Protocol fee management
- Comprehensive error handling and input validation
- Option Writing: Create new options contracts by locking collateral
- Option Trading: Buy existing options by paying the premium
- Option Exercise: Exercise options before expiry if conditions are favorable
- Position Management: Track written and held options for each user
- Price Feeds: Oracle integration for accurate price data
- Protocol Governance: Fee management and token whitelisting
- Comprehensive input validation
- Protected admin functions
- Collateral requirement checks
- Critical token/symbol protection
- Expiry validation
- Authorization checks
{
writer: principal,
holder: (optional principal),
collateral-amount: uint,
strike-price: uint,
premium: uint,
expiry: uint,
is-exercised: bool,
option-type: (string-ascii 4), // "CALL" or "PUT"
state: (string-ascii 9) // Current state of the option
}
{
written-options: (list 10 uint),
held-options: (list 10 uint),
total-collateral-locked: uint
}
Code | Description |
---|---|
1000 | Not authorized |
1001 | Insufficient balance |
1002 | Invalid expiry |
1003 | Invalid strike price |
1004 | Option not found |
1005 | Option expired |
1006 | Insufficient collateral |
1007 | Already exercised |
1008 | Invalid premium |
1009 | Invalid token |
1010 | Invalid symbol |
1011 | Invalid timestamp |
1012 | Invalid address |
1013 | Zero address |
1014 | Empty symbol |
(write-option
token ;; SIP-010 token used as collateral
collateral-amount ;; Amount of collateral to lock
strike-price ;; Strike price of the option
premium ;; Premium charged for the option
expiry ;; Block height at which option expires
option-type) ;; "CALL" or "PUT"
(buy-option
token ;; SIP-010 token for premium payment
option-id) ;; ID of the option to purchase
(exercise-option
token ;; SIP-010 token for settlement
option-id) ;; ID of the option to exercise
set-protocol-fee-rate
: Update the protocol fee rateset-approved-token
: Whitelist or remove tokensset-allowed-symbol
: Manage allowed price feed symbolsupdate-price-feed
: Update price data for supported trading pairs
-
Collateral Management
- Collateral is locked in the contract
- Automatic collateral return after exercise
- Protected against unauthorized withdrawals
-
Price Feed Security
- Only owner can update price feeds
- Timestamp validation
- Symbol whitelist
-
Token Safety
- SIP-010 compliance requirement
- Token whitelist
- Critical token protection
- Clarity CLI
- Stacks blockchain node (optional for testing)
- SIP-010 compliant tokens for testing
- Deploy contract
- Set initial protocol fee rate
- Whitelist accepted tokens
- Configure allowed price feed symbols
- Set up initial price feeds
- Maximum of 10 options per user position list
- Only supports SIP-010 compliant tokens
- Price feeds must be manually updated by contract owner
- Options cannot be cancelled once written
- No partial exercise functionality
- Secondary market for options trading
- Automated price feed updates
- Partial exercise functionality
- Option cancellation mechanism
- Dynamic collateral requirements
- Multi-asset options
- American vs European option types
This project is licensed under the MIT License. See the LICENSE file for details.