Skip to content

Latest commit

 

History

History
610 lines (419 loc) · 14.2 KB

File metadata and controls

610 lines (419 loc) · 14.2 KB

Aptos Options Protocol - TODO & Roadmap

Last Updated: December 2025 Status: Testnet MVP - Core functionality complete, ready for testing


Current State Summary

Metric Value Notes
Move Modules 15 95% complete
Tests 101 passing Good coverage including integration tests
Frontend 70% complete Full trading UI with settlement
Documentation Excellent 1,600+ lines
Deployment Devnet Fully deployed and initialized

✅ COMPLETED - Critical Bugs Fixed

1. Missing Collateral Functions ✅ FIXED

Status: Already existed in collateral.move

  • credit_collateral() - Working
  • debit_collateral() - Working
  • transfer_to_insurance() - Working

2. No Long Position Creation ✅ FIXED

Status: Implemented in options.move

  • Added buy_options() entry function
  • Added close_long_position() entry function
  • Frontend BuyOptionsForm.tsx component created
  • Full buyer flow working

3. Orderbook Matching Engine Missing ✅ RESOLVED

Status: Implemented Series Premium Pool model

Solution: Instead of a full orderbook, implemented a simpler pool-based model:

  • Writers add to series open interest when writing
  • Buyers pay premium to series pool when buying
  • Writers can claim proportional share of premiums
  • Added claim_premium() entry function

This provides writer/buyer matching without full orderbook complexity.

Files: sources/series.move, sources/options.move


✅ COMPLETED - High Priority Fixes

4. Oracle Price Staleness ✅ FIXED

Status: Fixed for devnet testing

  • Changed MAX_PRICE_AGE from 300s to 86400s (24 hours)
  • Allows testing without constant price refresh

Files: sources/oracle.move


5. Settlement Price Uses Current Spot

Priority: P1 - Settlement accuracy


5. Settlement Price Uses Current Spot

Priority: P1 - Settlement accuracy

Problem: oracle::get_settlement_price() returns current spot price, not historical price at expiry time.

Impact: Settlement not historically accurate.

Fix Required:

  • Integrate Pyth historical price lookup
  • Or store settlement price when series expires
  • Or use TWAP around expiry window

Files: sources/oracle.move, sources/settlement.move


6. Series Getter Function Access

Priority: P1 - Runtime errors possible

Problem: series::get_series() is called by margin.move but may not be properly exposed.

Verify: Ensure all cross-module function calls have correct visibility.

Files: sources/series.move, sources/margin.move


7. Protocol Pause Not Enforced

Priority: P1 - Security

Problem: config.move has pause mechanism but it's not checked in all entry functions.

Fix Required:

// Add to ALL entry functions:
assert!(!config::is_paused(), errors::protocol_paused());

Files: All entry function files


🟡 MEDIUM PRIORITY

8. Position Storage Model Limitation

Priority: P2 - UX limitation

Problem: Users can only hold one position per series (stored as resource at address).

Impact: Cannot add to existing position, must close and reopen.

Options:

  • Allow position aggregation (add amounts)
  • Use Table for multiple positions per series
  • Current model acceptable for MVP

Files: sources/types.move, sources/options.move


9. Liquidation Without Warning

Priority: P2 - User experience

Problem: Liquidation happens instantly at maintenance threshold. No margin call period.

Improvement:

  • Add margin call event when approaching threshold
  • Add grace period before liquidation
  • Add partial liquidation option

Files: sources/liquidation.move, sources/events.move


10. Insurance Fund Implementation

Priority: P2 - Protocol safety

Problem: Insurance fund referenced but not implemented.

Required:

  • Create InsuranceFund struct
  • Implement fund accumulation from fees
  • Implement shortfall coverage

Files: sources/collateral.move (new), sources/config.move


📋 TESTING GAPS

11. End-to-End Settlement Test

Priority: P1

Missing: Full lifecycle test: create series → write options → wait for expiry → settle

#[test]
fun test_full_settlement_lifecycle() {
    // 1. Setup accounts, oracle, series
    // 2. Writer deposits collateral
    // 3. Writer creates short position
    // 4. Buyer creates long position (blocked by bug #2)
    // 5. Fast-forward to expiry
    // 6. Settle positions
    // 7. Verify payouts
}

Files: tests/integration_tests.move


12. Liquidation Tests

Priority: P1

Missing: No liquidation test cases at all.

#[test]
fun test_liquidation_trigger() { ... }

#[test]
fun test_liquidation_payout() { ... }

#[test]
fun test_liquidation_insufficient_collateral() { ... }

Files: tests/liquidation_tests.move (new)


13. Collateral Operations Tests

Priority: P1

Missing: Deposit, withdraw, lock, unlock not tested.

#[test]
fun test_deposit_collateral() { ... }

#[test]
fun test_withdraw_collateral() { ... }

#[test]
fun test_insufficient_balance_withdraw() { ... }

#[test]
fun test_locked_collateral_cannot_withdraw() { ... }

Files: tests/collateral_tests.move (new)


14. Edge Case Tests

Priority: P2

Missing:

  • Max position size limits
  • Overflow scenarios in math
  • Zero amount operations
  • Expired series operations
  • Concurrent position operations

Files: Various test files


🖥️ FRONTEND WORK

15. Settlement UI

Priority: P1

Missing: Users cannot see or trigger settlement from UI.

Required:

  • Settlement status indicator per series
  • "Settle" button for expired positions
  • Payout preview before settlement
  • Settlement history

Files: frontend/src/components/SettlementPanel.tsx (new)


16. Liquidation Monitoring

Priority: P2

Missing: No visibility into liquidation risk.

Required:

  • Health factor display per position
  • Warning indicator when near liquidation
  • Liquidation history

Files: frontend/src/components/PositionsPanel.tsx


17. Price Charts

Priority: P2

Missing: No price visualization.

Required:

  • Oracle price history chart
  • Option price chart
  • Greeks visualization

Files: frontend/src/components/PriceChart.tsx (new)


18. Transaction Feedback

Priority: P2

Problem: Basic toast messages only. No transaction tracking.

Required:

  • Transaction pending state
  • Transaction confirmation with explorer link
  • Error message details

Files: All components with transactions


19. Orderbook UI

Priority: P1 (after backend)

Missing: No trading interface.

Required:

  • Order book visualization (bids/asks)
  • Place order form
  • Order history
  • Cancel order button

Files: frontend/src/components/OrderBook.tsx (new)


🔒 SECURITY CONCERNS

20. Arithmetic Overflow Review

Priority: P1

Action: Review all math operations for potential overflow with large values.

Focus Areas:

  • Settlement payout calculations
  • Collateral requirement calculations
  • Position aggregation

Files: sources/math.move, sources/settlement.move, sources/margin.move


21. Oracle Price Manipulation

Priority: P1

Problem: Admin can set arbitrary prices. No sanity checks.

Mitigations:

  • Add max price change per update (e.g., 20%)
  • Add confidence interval validation (from Pyth)
  • Add multiple oracle sources

Files: sources/oracle.move


22. Admin Key Security

Priority: P1

Problem: Single admin address is single point of failure.

Mitigations:

  • Implement multisig for admin operations
  • Add timelock for critical changes
  • Consider governance mechanism

Files: sources/config.move


23. Reentrancy Review

Priority: P2

Action: Move's resource model prevents classic reentrancy, but review for:

  • Cross-module call chains
  • External call patterns (when Hyperion integrated)

Files: All modules with external calls


24. Third-Party Audit

Priority: P0 (before mainnet)

Action: Engage security firm for comprehensive audit.

Scope:

  • All Move modules
  • Economic model review
  • Integration security

🔌 INTEGRATION WORK

25. Pyth Oracle Integration ✅ DONE

Priority: P1

Status: Fully implemented

Completed:

  • Added Pyth dependency to Move.toml
  • Aligned AptosFramework version with Pyth
  • Implemented update_prices_from_pyth() entry function
  • Implemented get_pyth_price() view function
  • Price format conversion (variable Pyth exponents to 6-decimal fixed-point)
  • Add confidence interval checks (TODO: production enhancement)
  • Test with real Pyth feeds on testnet (TODO: integration testing)

Files: Move.toml, sources/oracle.move, sources/math.move


26. Hyperion DEX Integration

Priority: P2

Status: Completely stubbed

Tasks:

  • Research Hyperion API/SDK
  • Implement market creation for series
  • Implement order routing
  • Handle fills and settlements

Files: sources/orderbook.move


27. Indexer Service

Priority: P2

Status: Events defined, no indexer

Tasks:

  • Set up event indexer (Aptos Indexer or custom)
  • Create GraphQL API for queries
  • Connect frontend to indexed data

Files: New infrastructure


📚 RESEARCH & INVESTIGATION

28. AMM vs Orderbook Model

Question: Should we use AMM for simpler implementation?

Research:

  • Study Dopex, Lyra, Premia AMM models
  • Evaluate capital efficiency tradeoffs
  • Prototype AMM pricing curve

29. Portfolio Margin System

Question: How to implement cross-position margining?

Research:

  • Study SPAN margin methodology
  • Evaluate correlation-based margin reduction
  • Design position netting logic

30. American Options Implementation

Question: How to handle early exercise?

Research:

  • Study binomial tree pricing for American options
  • Design early exercise detection and settlement
  • Evaluate gas costs of complex calculations

31. Volatility Surface

Question: How to price options at different strikes?

Research:

  • Study implied volatility smile/skew
  • Design volatility interpolation
  • Evaluate oracle solutions for IV

32. Gas Optimization

Question: Are current implementations gas-efficient?

Research:

  • Profile gas costs of all operations
  • Identify optimization opportunities
  • Consider storage vs computation tradeoffs

📝 DOCUMENTATION NEEDS

33. API Reference

Priority: P2

Missing: Function-level documentation for frontend integration.

Required:

  • All view functions with parameters and return types
  • All entry functions with required arguments
  • Error code reference

34. User Guide

Priority: P2

Missing: End-user documentation.

Required:

  • How to connect wallet
  • How to get test tokens
  • How to write options
  • How to manage positions
  • How settlement works

35. Deployment Runbook

Priority: P1

Missing: Production deployment checklist.

Required:

  • Pre-deployment checklist
  • Deployment steps
  • Post-deployment verification
  • Rollback procedures

🗓️ PHASE ROADMAP

Phase 1: Fix Critical Bugs (Current)

  • Implement missing collateral functions
  • Add long position creation
  • Fix oracle staleness for devnet
  • Add critical tests

Phase 2: Complete Testnet

  • Integrate Pyth oracle
  • Implement orderbook OR AMM
  • Complete frontend
  • Full E2E testing

Phase 3: Security & Audit

  • Internal security review
  • Third-party audit
  • Bug bounty program
  • Economic audit

Phase 4: Mainnet Launch

  • Mainnet deployment
  • Gradual rollout (caps/limits)
  • Monitoring setup
  • Incident response plan

Phase 5: Advanced Features

  • Portfolio margin
  • American options
  • Additional underlyings
  • Governance system

📊 TRACKING

Completed This Session (Latest)

  • Verified collateral functions already exist (credit/debit/transfer_to_insurance)
  • Added buy_options() entry function in options.move
  • Added close_long_position() entry function
  • Implemented Series Premium Pool for writer/buyer matching
  • Added claim_premium() function for writers
  • Fixed oracle staleness (300s → 86400s for devnet)
  • Created BuyOptionsForm.tsx component
  • Added settlement functions to useOptions hook
  • Updated PositionsPanel with settlement UI
  • Added 3 new pool integration tests (97 total passing)
  • Deployed updated contracts to devnet
  • Initialized SeriesPool resource

Previous Session

  • Mock USDC module created
  • 7 mock_usdc tests added
  • Deployment scripts created
  • TESTNET_GUIDE.md written
  • Frontend scaffolded
  • Basic UI components built
  • Deployed to devnet
  • Protocol initialized with 4 series

Completed This Session

  • Protocol pause enforcement in all entry functions (added to cancel_order)
  • Series getter function access verification (already working)
  • Added 4 liquidation tests (101 total passing)
  • Pyth oracle integration completed:
    • Added Pyth dependency to Move.toml
    • Aligned AptosFramework version with Pyth's version
    • Implemented update_prices_from_pyth() entry function
    • Implemented get_pyth_price() view function
    • Implemented convert_pyth_price_to_u64() for price format conversion
    • Added pow10() helper to math module

Remaining Work

  1. Settlement price historical lookup (currently uses current spot)
  2. Position storage model (allow multiple positions)
  3. Security audit before mainnet

🔗 Quick Links


This document should be updated as work progresses. Use checkboxes to track completion.