@optionsfi/sdk 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +113 -0
- package/MIGRATION.md +56 -0
- package/README.md +227 -0
- package/dist/index.d.mts +3315 -0
- package/dist/index.d.ts +3315 -0
- package/dist/index.js +3529 -0
- package/dist/index.mjs +3457 -0
- package/package.json +74 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the OptionsFi SDK will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.2.0] - 2025-12-30
|
|
6
|
+
|
|
7
|
+
### Added - Multi-Asset Support
|
|
8
|
+
|
|
9
|
+
#### New Types
|
|
10
|
+
- `AssetType`: Classification for crypto, tokenized_stock, and tokenized_treasury
|
|
11
|
+
- `AssetDescriptor`: Complete asset metadata with price feeds and trading hours
|
|
12
|
+
- `AssetRegistryEntry`: Asset descriptor with activation status
|
|
13
|
+
- `AssetVolatility`: Volatility data structure for assets
|
|
14
|
+
- `PriceFeedSource`: Enum for pyth, yahoo, switchboard, or custom feeds
|
|
15
|
+
- `TradingHours`: Trading hours configuration for market-hours assets
|
|
16
|
+
- `CorporateAction`: Corporate action tracking for tokenized stocks
|
|
17
|
+
|
|
18
|
+
#### RFQ Enhancements
|
|
19
|
+
- `RFQParams.anonymous`: Optional anonymization of vault identity in RFQ broadcasts
|
|
20
|
+
- `RFQParams.minQuotes`: Configurable minimum number of quotes required before filling
|
|
21
|
+
- `RFQParams.quoteTimeout`: Customizable timeout for quote collection periods
|
|
22
|
+
- `Quote.validUntil`: Quote expiration timestamp for improved validation
|
|
23
|
+
|
|
24
|
+
#### Asset Utilities
|
|
25
|
+
- `createCryptoAsset()`: Helper for creating crypto asset descriptors
|
|
26
|
+
- `createTokenizedStockAsset()`: Helper for tokenized stock descriptors
|
|
27
|
+
- `createTokenizedTreasuryAsset()`: Helper for treasury descriptors
|
|
28
|
+
- `validateAssetDescriptor()`: Validate asset descriptor completeness
|
|
29
|
+
- `canCreateRFQ()`: Check if RFQ can be created (respects trading hours)
|
|
30
|
+
- `isWithinTradingHours()`: Check if asset is within trading hours
|
|
31
|
+
- `getUSEquityTradingHours()`: Default US equity market hours
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
#### RFQ System Improvements
|
|
36
|
+
- Enhanced multi-dealer quote collection with configurable thresholds
|
|
37
|
+
- Improved quote expiry validation and lifecycle management
|
|
38
|
+
- Better duplicate quote handling with automatic updates
|
|
39
|
+
- Ranked quote responses for improved price transparency
|
|
40
|
+
- Comprehensive status tracking (open, filled, expired, no_valid_quotes)
|
|
41
|
+
- New polling endpoint for asynchronous quote collection workflows
|
|
42
|
+
|
|
43
|
+
### Migration Guide
|
|
44
|
+
|
|
45
|
+
#### For Existing Users
|
|
46
|
+
|
|
47
|
+
No breaking changes. All new fields are optional and backward compatible.
|
|
48
|
+
|
|
49
|
+
**Using Multi-Asset Support:**
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import {
|
|
53
|
+
createCryptoAsset,
|
|
54
|
+
createTokenizedStockAsset,
|
|
55
|
+
canCreateRFQ
|
|
56
|
+
} from '@optionsfi/sdk';
|
|
57
|
+
|
|
58
|
+
// Create asset descriptors
|
|
59
|
+
const solAsset = createCryptoAsset({
|
|
60
|
+
assetId: 'SOL',
|
|
61
|
+
name: 'Solana',
|
|
62
|
+
ticker: 'SOL',
|
|
63
|
+
mintAddress: 'So11111111111111111111111111111111111111112',
|
|
64
|
+
decimals: 9,
|
|
65
|
+
pythFeedId: '0xef0d8...'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const nvdaAsset = createTokenizedStockAsset({
|
|
69
|
+
assetId: 'NVDAX',
|
|
70
|
+
name: 'NVIDIA Token',
|
|
71
|
+
ticker: 'NVDAX',
|
|
72
|
+
mintAddress: 'G5VWnn...',
|
|
73
|
+
decimals: 6,
|
|
74
|
+
yahooTicker: 'NVDA'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Check if RFQ can be created
|
|
78
|
+
const { allowed, reason } = canCreateRFQ(nvdaAsset);
|
|
79
|
+
if (!allowed) {
|
|
80
|
+
console.log(`Cannot create RFQ: ${reason}`);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Using Anonymous RFQs:**
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const rfqId = await rfqClient.createRFQ({
|
|
88
|
+
asset: 'NVDAX',
|
|
89
|
+
side: 'sell',
|
|
90
|
+
optionType: 'call',
|
|
91
|
+
strike: 150,
|
|
92
|
+
expiry: Math.floor(Date.now() / 1000) + 86400,
|
|
93
|
+
quantity: 100n * 10n**6n,
|
|
94
|
+
vaultAddress: myVault.toString(),
|
|
95
|
+
anonymous: true, // Vault address will be hidden from market makers
|
|
96
|
+
minQuotes: 3, // Wait for at least 3 quotes
|
|
97
|
+
quoteTimeout: 45000 // 45 second timeout
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## [0.1.0] - 2024-12-26
|
|
102
|
+
|
|
103
|
+
### Added
|
|
104
|
+
- Initial SDK release
|
|
105
|
+
- RFQClient for quote management
|
|
106
|
+
- VaultInstructions for on-chain operations
|
|
107
|
+
- OptionPricing utilities (Black-Scholes)
|
|
108
|
+
- Validation and formatting utilities
|
|
109
|
+
- TypeScript support
|
|
110
|
+
- Comprehensive test suite
|
|
111
|
+
|
|
112
|
+
[0.2.0]: https://github.com/optionsfi/optionsfi/compare/v0.1.0...v0.2.0
|
|
113
|
+
[0.1.0]: https://github.com/optionsfi/optionsfi/releases/tag/v0.1.0
|
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Migration Guide for v0.2.0
|
|
2
|
+
|
|
3
|
+
## Breaking Changes
|
|
4
|
+
|
|
5
|
+
### Renamed Constants
|
|
6
|
+
|
|
7
|
+
The following constants have been renamed for clarity:
|
|
8
|
+
|
|
9
|
+
| Old Name | New Name | Reason |
|
|
10
|
+
|----------|----------|--------|
|
|
11
|
+
| `MOCK_USDC_MINT` | `DEVNET_USDC_MINT` | Clarifies this is official devnet USDC, not a mock |
|
|
12
|
+
|
|
13
|
+
### New Exports
|
|
14
|
+
|
|
15
|
+
- `MAINNET_USDC_MINT` - Official Circle USDC mint for mainnet-beta
|
|
16
|
+
|
|
17
|
+
## Migration Steps
|
|
18
|
+
|
|
19
|
+
### If you were using MOCK_USDC_MINT
|
|
20
|
+
|
|
21
|
+
**Before (v0.1.0):**
|
|
22
|
+
```typescript
|
|
23
|
+
import { MOCK_USDC_MINT } from '@optionsfi/sdk';
|
|
24
|
+
|
|
25
|
+
const usdcMint = MOCK_USDC_MINT;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**After (v0.2.0):**
|
|
29
|
+
```typescript
|
|
30
|
+
import { DEVNET_USDC_MINT, MAINNET_USDC_MINT } from '@optionsfi/sdk';
|
|
31
|
+
|
|
32
|
+
// For devnet
|
|
33
|
+
const usdcMint = DEVNET_USDC_MINT;
|
|
34
|
+
|
|
35
|
+
// For mainnet
|
|
36
|
+
const usdcMint = MAINNET_USDC_MINT;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Repository Changes
|
|
40
|
+
|
|
41
|
+
The SDK repository has been transferred to the OptionsFi organization:
|
|
42
|
+
|
|
43
|
+
- **Old URL**: `https://github.com/feeniks01/optionsfi`
|
|
44
|
+
- **New URL**: `https://github.com/optionsfi/optionsfi`
|
|
45
|
+
|
|
46
|
+
All issue links, documentation links, and repository references have been updated.
|
|
47
|
+
|
|
48
|
+
## No Other Breaking Changes
|
|
49
|
+
|
|
50
|
+
All other APIs remain backward compatible. New features:
|
|
51
|
+
- Multi-asset support (crypto, tokenized stocks, treasuries)
|
|
52
|
+
- Anonymous RFQ support
|
|
53
|
+
- Enhanced multi-dealer quote collection
|
|
54
|
+
- Trading hours configuration (optional)
|
|
55
|
+
|
|
56
|
+
See [CHANGELOG.md](./CHANGELOG.md) for full details.
|
package/README.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# @optionsfi/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for OptionsFi, a decentralized options settlement protocol built on Solana. Enables developers to build applications with covered call vaults, RFQ-based options trading, and support for multiple asset types.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🌐 **Multi-Asset Support** - Trade options on crypto, tokenized stocks, and tokenized treasuries
|
|
8
|
+
- 🔌 **RFQ System** - Request quotes from multiple market makers with competitive pricing
|
|
9
|
+
- 📊 **Options Pricing** - Black-Scholes calculations with Greeks and volatility tools
|
|
10
|
+
- 🏦 **Vault Operations** - Interact with on-chain covered call vaults
|
|
11
|
+
- 🔒 **Anonymous RFQs** - Privacy-preserving quote requests for large institutional flows
|
|
12
|
+
- ✅ **Type-Safe** - Comprehensive TypeScript types with runtime validation
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @optionsfi/sdk
|
|
18
|
+
# or
|
|
19
|
+
yarn add @optionsfi/sdk
|
|
20
|
+
# or
|
|
21
|
+
pnpm add @optionsfi/sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Peer Dependencies:**
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @coral-xyz/anchor @solana/web3.js
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
These allow you to use your preferred versions of Anchor and Solana web3.js.
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Creating an RFQ
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { RFQClient, DEVNET_CONFIG } from '@optionsfi/sdk';
|
|
38
|
+
|
|
39
|
+
// Initialize client
|
|
40
|
+
const client = new RFQClient(DEVNET_CONFIG);
|
|
41
|
+
await client.connect();
|
|
42
|
+
|
|
43
|
+
// Create an RFQ for selling covered calls
|
|
44
|
+
const rfqId = await client.createRFQ({
|
|
45
|
+
asset: 'NVDAX',
|
|
46
|
+
side: 'sell',
|
|
47
|
+
optionType: 'call',
|
|
48
|
+
strike: 150, // $150 strike
|
|
49
|
+
expiry: Math.floor(Date.now() / 1000) + 7 * 24 * 60 * 60, // 1 week
|
|
50
|
+
quantity: BigInt(1000 * 1e6), // 1000 tokens
|
|
51
|
+
vaultAddress: 'your-vault-address',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Subscribe to quotes
|
|
55
|
+
client.subscribeToQuotes(rfqId, (quote) => {
|
|
56
|
+
console.log(`Quote from ${quote.marketMaker}: ${quote.premium} USDC`);
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Option Pricing
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { OptionPricing } from '@optionsfi/sdk';
|
|
64
|
+
|
|
65
|
+
// Calculate Black-Scholes fair value
|
|
66
|
+
const prices = OptionPricing.blackScholes({
|
|
67
|
+
spot: 145.50,
|
|
68
|
+
strike: 150,
|
|
69
|
+
timeToExpiry: 7 / 365, // 1 week
|
|
70
|
+
riskFreeRate: 0.05,
|
|
71
|
+
volatility: 0.45,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
console.log('Call price:', prices.call);
|
|
75
|
+
console.log('Put price:', prices.put);
|
|
76
|
+
console.log('Call delta:', prices.delta.call);
|
|
77
|
+
|
|
78
|
+
// Validate a quote against fair value
|
|
79
|
+
const validation = OptionPricing.validateQuote(premiumFromQuote, prices.call);
|
|
80
|
+
if (!validation.isValid) {
|
|
81
|
+
console.log('Quote rejected:', validation.reason);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Working with Vaults
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { VaultInstructions, deriveVaultPda } from '@optionsfi/sdk';
|
|
89
|
+
import { Connection } from '@solana/web3.js';
|
|
90
|
+
|
|
91
|
+
const connection = new Connection('https://api.devnet.solana.com');
|
|
92
|
+
|
|
93
|
+
// SDK includes bundled vault IDL - no need to provide it
|
|
94
|
+
const instructions = new VaultInstructions(connection);
|
|
95
|
+
await instructions.initialize();
|
|
96
|
+
|
|
97
|
+
// Fetch vault data
|
|
98
|
+
const vault = await instructions.fetchVault('NVDAX');
|
|
99
|
+
console.log('Total assets:', vault.totalAssets);
|
|
100
|
+
console.log('Current epoch:', vault.epoch);
|
|
101
|
+
|
|
102
|
+
// Check remaining capacity
|
|
103
|
+
const capacity = VaultInstructions.getRemainingCapacity(vault);
|
|
104
|
+
console.log('Remaining capacity:', capacity);
|
|
105
|
+
|
|
106
|
+
// Build transaction instruction
|
|
107
|
+
const [vaultPda] = deriveVaultPda('NVDAX');
|
|
108
|
+
const ix = await instructions.recordNotionalExposure({
|
|
109
|
+
vault: vaultPda,
|
|
110
|
+
authority: walletPublicKey,
|
|
111
|
+
notionalTokens: BigInt(1000 * 1e6),
|
|
112
|
+
premium: BigInt(50 * 1e6),
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## API Reference
|
|
117
|
+
|
|
118
|
+
### RFQClient
|
|
119
|
+
|
|
120
|
+
Main client for interacting with the RFQ infrastructure.
|
|
121
|
+
|
|
122
|
+
| Method | Description |
|
|
123
|
+
|--------|-------------|
|
|
124
|
+
| `connect()` | Connect to the RFQ router WebSocket |
|
|
125
|
+
| `disconnect()` | Disconnect from the router |
|
|
126
|
+
| `createRFQ(params)` | Create a new RFQ |
|
|
127
|
+
| `subscribeToQuotes(rfqId, callback)` | Subscribe to quotes |
|
|
128
|
+
| `executeOption(rfqId, quoteId, wallet)` | Execute an option trade |
|
|
129
|
+
| `cancelRFQ(rfqId)` | Cancel an open RFQ |
|
|
130
|
+
| `onEvent(callback)` | Subscribe to all events |
|
|
131
|
+
|
|
132
|
+
### OptionPricing
|
|
133
|
+
|
|
134
|
+
Static utilities for option pricing.
|
|
135
|
+
|
|
136
|
+
| Method | Description |
|
|
137
|
+
|--------|-------------|
|
|
138
|
+
| `blackScholes(params)` | Calculate option prices |
|
|
139
|
+
| `calculateCoveredCallPremium(params)` | Premium for covered calls |
|
|
140
|
+
| `premiumToBps(premium, spot)` | Convert premium to bps |
|
|
141
|
+
| `validateQuote(premium, fairValue)` | Validate quote against fair |
|
|
142
|
+
| `suggestStrike(spot, deltaBps)` | Suggest strike price |
|
|
143
|
+
| `calculateHistoricalVolatility(prices)` | Calculate vol from prices |
|
|
144
|
+
| `calculateImpliedVolatility(...)` | Derive IV from price |
|
|
145
|
+
|
|
146
|
+
### VaultInstructions
|
|
147
|
+
|
|
148
|
+
Build transactions for the vault program.
|
|
149
|
+
|
|
150
|
+
| Method | Description |
|
|
151
|
+
|--------|-------------|
|
|
152
|
+
| `fetchVault(assetId)` | Fetch vault account data |
|
|
153
|
+
| `recordNotionalExposure(params)` | Record option exposure |
|
|
154
|
+
| `collectPremium(params)` | Collect premium from MM |
|
|
155
|
+
| `paySettlement(params)` | Pay ITM settlement |
|
|
156
|
+
| `advanceEpoch(params)` | Advance to next epoch |
|
|
157
|
+
|
|
158
|
+
### Utilities
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import {
|
|
162
|
+
// Formatting
|
|
163
|
+
formatTokenAmount,
|
|
164
|
+
parseTokenAmount,
|
|
165
|
+
formatUSDC,
|
|
166
|
+
parseUSDC,
|
|
167
|
+
formatTimeToExpiry,
|
|
168
|
+
shortenAddress,
|
|
169
|
+
|
|
170
|
+
// Validation
|
|
171
|
+
validateRFQParams,
|
|
172
|
+
validateBlackScholesParams,
|
|
173
|
+
|
|
174
|
+
// Constants
|
|
175
|
+
VAULT_PROGRAM_ID,
|
|
176
|
+
deriveVaultPda,
|
|
177
|
+
PYTH_PRICE_FEEDS,
|
|
178
|
+
} from '@optionsfi/sdk';
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Configuration
|
|
182
|
+
|
|
183
|
+
### Networks
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import { DEVNET_CONFIG, MAINNET_CONFIG } from '@optionsfi/sdk';
|
|
187
|
+
|
|
188
|
+
// Use devnet for testing
|
|
189
|
+
const client = new RFQClient(DEVNET_CONFIG);
|
|
190
|
+
|
|
191
|
+
// Use mainnet for production
|
|
192
|
+
const client = new RFQClient(MAINNET_CONFIG);
|
|
193
|
+
|
|
194
|
+
// Custom configuration
|
|
195
|
+
const client = new RFQClient({
|
|
196
|
+
rpcUrl: 'https://my-rpc.com',
|
|
197
|
+
rfqRouterUrl: 'wss://rfq.optionsfi.xyz',
|
|
198
|
+
programId: 'A4jgqct3bwTwRmHECHdPpbH3a8ksaVb7rny9pMUGFo94',
|
|
199
|
+
network: 'mainnet-beta',
|
|
200
|
+
});
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Documentation
|
|
204
|
+
|
|
205
|
+
For comprehensive guides and API documentation, visit [docs.optionsfi.xyz](https://docs.optionsfi.xyz).
|
|
206
|
+
|
|
207
|
+
## Support
|
|
208
|
+
|
|
209
|
+
- **Issues**: [GitHub Issues](https://github.com/optionsfi/optionsfi/issues)
|
|
210
|
+
- **Documentation**: [docs.optionsfi.xyz](https://docs.optionsfi.xyz)
|
|
211
|
+
- **Website**: [optionsfi.xyz](https://optionsfi.xyz)
|
|
212
|
+
|
|
213
|
+
## Contributing
|
|
214
|
+
|
|
215
|
+
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
|
|
216
|
+
|
|
217
|
+
## Security
|
|
218
|
+
|
|
219
|
+
For security concerns, please email security@optionsfi.xyz. Do not open public issues for security vulnerabilities.
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
MIT License - see LICENSE file for details.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
Built with ❤️ by the OptionsFi team
|