psyoptions 0.0.5

Bindings for interacting with the PsyOptions protocol on the Solana blockchain
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
use crate::fees::fee_owner_key;
use arrayref::array_ref;
use solana_program::{
    clock::UnixTimestamp,
    instruction::{AccountMeta, Instruction},
    program_error::ProgramError,
    pubkey::Pubkey,
    system_program, sysvar,
};
use spl_associated_token_account::get_associated_token_address;
use spl_token;
use std::mem::size_of;

/// Instructions supported by the Options program
#[repr(C)]
#[derive(Debug, PartialEq)]
pub enum OptionsInstruction {
    /// Initializes a new OptionMarket
    ///
    ///
    /// Accounts expected by this instruction:
    ///
    ///   0. `[]` Underlying Asset Mint
    ///   1. `[]` Quote Asset Mint
    ///   2. `[writeable]` Option Mint (uninitialized)
    ///   3. `[writeable]` Writer Token Mint (uninitialized)
    ///   4. `[writeable]` Option Market
    ///   5. `[]` Option Mint Authority
    ///   6. `[writeable]` Underlying Asset Pool (uninitialized)
    ///   7. `[writeable]` Quote Asset Pool (uninitialized)
    ///   8. `[]` Fee Owner Account - should match declaration in fees.rs
    ///   9. `[]` Mint Fee Key - An SPL Token account that recieves fees in the underlying asset
    ///   10. `[]` Rent Sysvar
    ///   11. `[]` SPL Token Program Account
    ///   12. `[]` System Program
    ///   13. `[]` SPL Associated Token Program Account
    InitializeMarket {
        /// The amount of the **underlying asset** that derives a single contract
        underlying_amount_per_contract: u64,
        /// Pre-computed quote amount for the new market, equal to strike price * amount_per_contract
        quote_amount_per_contract: u64,
        /// The Unix timestamp at which the contracts in this market expire
        expiration_unix_timestamp: UnixTimestamp,
        /// Bump Seed for the [Program Derived Address](https://docs.solana.com/developing/programming-model/calling-between-programs#program-derived-addresses)
        bump_seed: u8,
    },
    /// Mints an Options token to represent a Covered Call
    ///
    ///
    ///   0. `[writeable]` Funding Account
    ///   1. `[writeable]` Option Mint
    ///   2. `[writeable]` Destination account for minted Option
    ///   3. `[writeable]` Writer Token Mint
    ///   4. `[writeable]` Destination account for minted Writer Token
    ///   5. `[writeable]` Source account for `OptionWriter`'s underlying asset
    ///   6. `[writeable]` Destination account for underlying asset pool
    ///   7. `[writeable]` `OptionMarket` data account
    ///   8. `[writeable]` Mint fee account (associated token address derived from the `fee_owner_key`)
    ///   9. `[]` Fee owner key
    ///   10. `[signer]` Authority account for underlying asset source
    ///   11. `[]` SPL Token Program
    ///   12. `[]` Program Derived Address for the authority over the Option Mint
    ///   13. `[]` SysVar clock account
    ///   14. `[]` System Program account
    ///   
    MintCoveredCall { size: u64 },
    /// Exercise an Options token representing a Covered Call
    ///
    ///   0. `[]` Sysvar clock
    ///   1. `[]` SPL Token Program
    ///   2. `[]` Option Market
    ///   3. `[writeable]` Exerciser Quote Asset Source
    ///   4. `[signer]` Exerciser Authority
    ///   5. `[writeable]` Exerciser Underlying Asset Source
    ///   6. `[writeable]` Underlying Asset Pool
    ///   7. `[writeable]` Quote Asset Pool
    ///   8. `[]` Option Mint Authority
    ///   9. `[writeable]` Option Mint
    ///   10. `[writeable]` Option Token Account
    ///   11. `[signer]` Option Token Account Authority
    ExerciseCoveredCall { size: u64 },
    /// Close a single option contract post expiration.
    /// Transfers the underlying asset back to the Option Writer
    ///
    /// 0. `[]` Option Market
    /// 1. `[]` Option Mint
    /// 2. `[]` Option Mint Authority
    /// 3. `[writeable]` Writer Token Mint
    /// 4. `[writeable]` Writer Token Source (to be burned)
    /// 5. `[signer]` Writer Token Source Authority
    /// 6. `[writeable]` Option Writer Underlying Asset Destination
    /// 7. `[writeable]` Underlying Asset Pool
    /// 8. `[]` Sysvar clock
    /// 9. `[]` SPL Token Program
    ClosePostExpiration { size: u64 },
    /// Close a single option contract prior to expiration.
    /// Burns the _option token_ and the _writer token_ and returns the
    /// underlying asset back to the writer (or address specified).
    ///
    /// 0. `[]` SPL Token porgram
    /// 1. `[]` Option Market
    /// 2. `[writable]` Option Mint
    /// 3. `[]` Option Mint Authority
    /// 4. `[writable]` Option Token Source
    /// 5. `[signer]` Option Token Source Authority
    /// 6. `[writable]` Writer Token Mint
    /// 7. `[writable]` Writer Token Source
    /// 8. `[]` Writer Token Source Authority
    /// 9. `[writable]` Underlying Asset Destination
    /// 10. `[writable]` Underlying Asset Pool
    ClosePosition { size: u64 },
    /// Allow a user to exchange their Writer Token for Quote Asset.
    /// Burns the Writer Token and transfers the Quote Asset amount
    /// relative to the option market
    ///
    /// 0. `[]` Option Market
    /// 1. `[]` Option Mint
    /// 2. `[]` Option Market Authority
    /// 3. `[writeable]` Writer Token Mint
    /// 4. `[writeable]` Writer Token Source (to be burned)
    /// 5. `[signer]` Writer Token Source Authority
    /// 6. `[writeable]` Quote Asset Destination
    /// 7. `[writeable]` Quote Asset Pool
    /// 8. `[]` SPL token program
    ExchangeWriterTokenForQuote { size: u64 },
}

impl OptionsInstruction {
    /// Unpacks a byte buffer into a [TokenInstruction](enum.TokenInstruction.html).
    pub fn unpack(input: &[u8]) -> Result<Self, ProgramError> {
        let (&tag, rest) = input
            .split_first()
            .ok_or(ProgramError::InvalidInstructionData)?;
        Ok(match tag {
            0 => {
                let (underlying_amount_per_contract, rest) = Self::unpack_u64(rest)?;
                let (quote_amount_per_contract, rest) = Self::unpack_u64(rest)?;
                let (expiration_unix_timestamp, rest) = Self::unpack_timestamp(rest)?;
                let (bump_seed, _rest) = Self::unpack_u8(rest)?;
                Self::InitializeMarket {
                    underlying_amount_per_contract,
                    quote_amount_per_contract,
                    expiration_unix_timestamp,
                    bump_seed,
                }
            }
            1 => {
                let (size, _) = Self::unpack_u64(rest)?;
                Self::MintCoveredCall { size }
            }
            2 => {
                let (size, _) = Self::unpack_u64(rest)?;
                Self::ExerciseCoveredCall { size }
            }
            3 => {
                let (size, _) = Self::unpack_u64(rest)?;
                Self::ClosePostExpiration { size }
            }
            4 => {
                let (size, _) = Self::unpack_u64(rest)?;
                Self::ClosePosition { size }
            }
            5 => {
                let (size, _) = Self::unpack_u64(rest)?;
                Self::ExchangeWriterTokenForQuote { size }
            }
            _ => return Err(ProgramError::InvalidInstructionData.into()),
        })
    }

    /// Packs a OptionInstruction into a byte buffer.
    pub fn pack(&self) -> Vec<u8> {
        let mut buf = Vec::with_capacity(size_of::<Self>());
        match self {
            &Self::InitializeMarket {
                ref underlying_amount_per_contract,
                ref quote_amount_per_contract,
                ref expiration_unix_timestamp,
                ref bump_seed,
            } => {
                buf.push(0);
                buf.extend_from_slice(&underlying_amount_per_contract.to_le_bytes());
                buf.extend_from_slice(&quote_amount_per_contract.to_le_bytes());
                buf.extend_from_slice(&expiration_unix_timestamp.to_le_bytes());
                buf.extend_from_slice(&bump_seed.to_le_bytes());
            }
            &Self::MintCoveredCall { size } => {
                buf.push(1);
                buf.extend_from_slice(&size.to_le_bytes());
            }
            &Self::ExerciseCoveredCall { size } => {
                buf.push(2);
                buf.extend_from_slice(&size.to_le_bytes());
            }
            &Self::ClosePostExpiration { size } => {
                buf.push(3);
                buf.extend_from_slice(&size.to_le_bytes());
            }
            &Self::ClosePosition { size } => {
                buf.push(4);
                buf.extend_from_slice(&size.to_le_bytes());
            }
            &Self::ExchangeWriterTokenForQuote { size } => {
                buf.push(5);
                buf.extend_from_slice(&size.to_le_bytes());
            }
        };
        buf
    }

    fn unpack_timestamp(input: &[u8]) -> Result<(i64, &[u8]), ProgramError> {
        if input.len() >= 8 {
            let (num_buf, rest) = input.split_at(8);
            let num_arr = array_ref![num_buf, 0, 8];
            let num = UnixTimestamp::from_le_bytes(*num_arr);
            Ok((num, rest))
        } else {
            Err(ProgramError::InvalidInstructionData)
        }
    }
    fn unpack_u64(input: &[u8]) -> Result<(u64, &[u8]), ProgramError> {
        if input.len() >= 8 {
            let (num_buf, rest) = input.split_at(8);
            let num_arr = array_ref![num_buf, 0, 8];
            let num = u64::from_le_bytes(*num_arr);
            Ok((num, rest))
        } else {
            Err(ProgramError::InvalidInstructionData)
        }
    }
    fn unpack_u8(input: &[u8]) -> Result<(u8, &[u8]), ProgramError> {
        if input.len() >= 1 {
            let (num_buf, rest) = input.split_at(1);
            let num_arr = array_ref![num_buf, 0, 1];
            let num = u8::from_le_bytes(*num_arr);
            Ok((num, rest))
        } else {
            Err(ProgramError::InvalidInstructionData)
        }
    }
}

/// Creates an `InitializeMarket` instruction
pub fn initialize_market(
    program_id: &Pubkey,
    underlying_asset_mint: &Pubkey,
    quote_asset_mint: &Pubkey,
    option_mint: &Pubkey,
    writer_token_mint: &Pubkey,
    underlying_asset_pool: &Pubkey,
    quote_asset_pool: &Pubkey,
    funding_account: &Pubkey,
    underlying_amount_per_contract: u64,
    quote_amount_per_contract: u64,
    expiration_unix_timestamp: UnixTimestamp,
) -> Result<Instruction, ProgramError> {
    let (options_market_key, _no_duplication_bump) = Pubkey::find_program_address(
        &[
            &underlying_asset_mint.to_bytes(),
            &quote_asset_mint.to_bytes(),
            &underlying_amount_per_contract.to_le_bytes(),
            &quote_amount_per_contract.to_le_bytes(),
            &expiration_unix_timestamp.to_le_bytes(),
        ],
        &program_id,
    );
    let (market_authority, bump_seed) =
        Pubkey::find_program_address(&[&options_market_key.to_bytes()[..32]], &program_id);

    let data = OptionsInstruction::InitializeMarket {
        underlying_amount_per_contract,
        quote_amount_per_contract,
        expiration_unix_timestamp,
        bump_seed,
    }
    .pack();

    let mint_fee_key = get_associated_token_address(&fee_owner_key::ID, underlying_asset_mint);
    let exercise_fee_key = get_associated_token_address(&fee_owner_key::ID, quote_asset_mint);

    let accounts = vec![
        AccountMeta::new_readonly(*underlying_asset_mint, false),
        AccountMeta::new_readonly(*quote_asset_mint, false),
        AccountMeta::new(*option_mint, false),
        AccountMeta::new(*writer_token_mint, false),
        AccountMeta::new_readonly(market_authority, false),
        AccountMeta::new(*underlying_asset_pool, false),
        AccountMeta::new(*quote_asset_pool, false),
        AccountMeta::new(*funding_account, true),
        AccountMeta::new_readonly(fee_owner_key::ID, false),
        AccountMeta::new(mint_fee_key, false),
        AccountMeta::new(exercise_fee_key, false),
        AccountMeta::new(options_market_key, false),
        AccountMeta::new_readonly(sysvar::rent::id(), false),
        AccountMeta::new_readonly(spl_token::id(), false),
        AccountMeta::new_readonly(system_program::id(), false),
        AccountMeta::new_readonly(spl_associated_token_account::id(), false),
    ];
    Ok(Instruction {
        program_id: *program_id,
        accounts,
        data,
    })
}

/// Creates a `MintCoveredCall` instruction
pub fn mint_covered_call(
    program_id: &Pubkey,
    funding_account: &Pubkey,
    option_mint: &Pubkey,
    minted_option_dest: &Pubkey,
    writer_token_mint: &Pubkey,
    minted_writer_token_dest: &Pubkey,
    underyling_asset_src: &Pubkey,
    underlying_asset_pool: &Pubkey,
    option_market: &Pubkey,
    underlying_asset_mint: &Pubkey,
    authority_pubkey: &Pubkey,
    size: u64,
) -> Result<Instruction, ProgramError> {
    let fee_key = get_associated_token_address(&fee_owner_key::ID, underlying_asset_mint);

    let mut accounts = Vec::with_capacity(15);
    accounts.push(AccountMeta::new(*funding_account, false));
    accounts.push(AccountMeta::new(*option_mint, false));
    accounts.push(AccountMeta::new(*minted_option_dest, false));
    accounts.push(AccountMeta::new(*writer_token_mint, false));
    accounts.push(AccountMeta::new(*minted_writer_token_dest, false));
    accounts.push(AccountMeta::new(*underyling_asset_src, false));
    accounts.push(AccountMeta::new(*underlying_asset_pool, false));
    accounts.push(AccountMeta::new_readonly(*option_market, false));
    accounts.push(AccountMeta::new(fee_key, false));
    accounts.push(AccountMeta::new(fee_owner_key::ID, false));
    accounts.push(AccountMeta::new_readonly(*authority_pubkey, true));
    accounts.push(AccountMeta::new_readonly(spl_token::id(), false));

    let (market_authority, _bump_seed) =
        Pubkey::find_program_address(&[&option_market.to_bytes()[..32]], &program_id);
    accounts.push(AccountMeta::new_readonly(market_authority, false));
    accounts.push(AccountMeta::new_readonly(sysvar::clock::id(), false));
    accounts.push(AccountMeta::new_readonly(system_program::id(), false));

    let data = OptionsInstruction::MintCoveredCall { size }.pack();
    Ok(Instruction {
        program_id: *program_id,
        data,
        accounts,
    })
}

/// Creates a `ClosePosition` instruction
pub fn close_position(
    program_id: &Pubkey,
    options_market: &Pubkey,
    underlying_asset_pool: &Pubkey,
    option_mint_key: &Pubkey,
    option_token_source: &Pubkey,
    option_token_source_authority: &Pubkey,
    writer_token_mint: &Pubkey,
    writer_token_source: &Pubkey,
    writer_token_source_authority: &Pubkey,
    underlying_asset_dest: &Pubkey,
    size: u64,
) -> Result<Instruction, ProgramError> {
    let (market_authority, _bump_seed) =
        Pubkey::find_program_address(&[&options_market.to_bytes()[..32]], &program_id);

    let data = OptionsInstruction::ClosePosition { size }.pack();

    let mut accounts = Vec::with_capacity(11);
    accounts.push(AccountMeta::new_readonly(spl_token::id(), false));
    accounts.push(AccountMeta::new_readonly(*options_market, false));
    accounts.push(AccountMeta::new(*option_mint_key, false));
    accounts.push(AccountMeta::new_readonly(market_authority, false));
    accounts.push(AccountMeta::new(*option_token_source, false));
    accounts.push(AccountMeta::new_readonly(
        *option_token_source_authority,
        true,
    ));
    accounts.push(AccountMeta::new(*writer_token_mint, false));
    accounts.push(AccountMeta::new(*writer_token_source, false));
    accounts.push(AccountMeta::new_readonly(
        *writer_token_source_authority,
        true,
    ));
    accounts.push(AccountMeta::new(*underlying_asset_dest, false));
    accounts.push(AccountMeta::new(*underlying_asset_pool, false));

    Ok(Instruction {
        program_id: *program_id,
        data,
        accounts,
    })
}

/// Creates a `ClosePostExpiration` instruction
pub fn close_post_expiration(
    program_id: &Pubkey,
    options_market: &Pubkey,
    underlying_asset_pool: &Pubkey,
    writer_token_mint: &Pubkey,
    writer_token_source: &Pubkey,
    writer_token_source_authority: &Pubkey,
    underlying_asset_dest: &Pubkey,
    size: u64,
) -> Result<Instruction, ProgramError> {
    let (market_authority, _bump_seed) =
        Pubkey::find_program_address(&[&options_market.to_bytes()[..32]], &program_id);
    let data = OptionsInstruction::ClosePostExpiration { size }.pack();

    let mut accounts = Vec::with_capacity(9);
    accounts.push(AccountMeta::new_readonly(*options_market, false));
    accounts.push(AccountMeta::new_readonly(market_authority, false));
    accounts.push(AccountMeta::new(*writer_token_mint, false));
    accounts.push(AccountMeta::new(*writer_token_source, false));
    accounts.push(AccountMeta::new_readonly(
        *writer_token_source_authority,
        true,
    ));
    accounts.push(AccountMeta::new(*underlying_asset_dest, false));
    accounts.push(AccountMeta::new(*underlying_asset_pool, false));
    accounts.push(AccountMeta::new_readonly(spl_token::id(), false));
    accounts.push(AccountMeta::new_readonly(sysvar::clock::id(), false));

    Ok(Instruction {
        program_id: *program_id,
        data,
        accounts,
    })
}

/// Creates a `ExerciseCoveredCall` instruction
pub fn exercise_covered_call(
    program_id: &Pubkey,
    funding_account: &Pubkey,
    option_mint: &Pubkey,
    options_market: &Pubkey,
    quote_asset_mint: &Pubkey,
    exerciser_quote_asset: &Pubkey,
    exerciser_underlying_asset: &Pubkey,
    exerciser_authority: &Pubkey,
    underlying_asset_pool: &Pubkey,
    quote_asset_pool: &Pubkey,
    option_token_key: &Pubkey,
    option_token_authority: &Pubkey,
    size: u64,
) -> Result<Instruction, ProgramError> {
    let (options_spl_authority_pubkey, _bump_seed) =
        Pubkey::find_program_address(&[&options_market.to_bytes()[..32]], &program_id);
    let data = OptionsInstruction::ExerciseCoveredCall { size }.pack();
    let exercise_fee_key = get_associated_token_address(&fee_owner_key::ID, quote_asset_mint);

    let mut accounts = Vec::with_capacity(12);
    accounts.push(AccountMeta::new(*funding_account, false));
    accounts.push(AccountMeta::new_readonly(*options_market, false));
    accounts.push(AccountMeta::new(*exerciser_quote_asset, false));
    accounts.push(AccountMeta::new_readonly(*exerciser_authority, true));
    accounts.push(AccountMeta::new(*exerciser_underlying_asset, false));
    accounts.push(AccountMeta::new(*underlying_asset_pool, false));
    accounts.push(AccountMeta::new(*quote_asset_pool, false));
    accounts.push(AccountMeta::new_readonly(
        options_spl_authority_pubkey,
        false,
    ));
    accounts.push(AccountMeta::new(*option_mint, false));
    accounts.push(AccountMeta::new(*option_token_key, false));
    accounts.push(AccountMeta::new_readonly(*option_token_authority, true));
    accounts.push(AccountMeta::new_readonly(*quote_asset_mint, false));
    accounts.push(AccountMeta::new(exercise_fee_key, false));
    accounts.push(AccountMeta::new(fee_owner_key::ID, false));
    accounts.push(AccountMeta::new_readonly(system_program::id(), false));
    accounts.push(AccountMeta::new_readonly(sysvar::clock::id(), false));
    accounts.push(AccountMeta::new_readonly(spl_token::id(), false));

    Ok(Instruction {
        program_id: *program_id,
        data,
        accounts,
    })
}

/// Creates a `ExchangeWriterTokenForQuote` instructions
pub fn exchange_writer_token_for_quote(
    program_id: &Pubkey,
    options_market: &Pubkey,
    writer_token_mint: &Pubkey,
    writer_token_source: &Pubkey,
    writer_token_source_authority: &Pubkey,
    quote_asset_dest: &Pubkey,
    quote_asset_pool: &Pubkey,
    size: u64,
) -> Result<Instruction, ProgramError> {
    let (option_market_authority, _bump_seed) =
        Pubkey::find_program_address(&[&options_market.to_bytes()[..32]], &program_id);
    let data = OptionsInstruction::ExchangeWriterTokenForQuote { size }.pack();

    let mut accounts = Vec::with_capacity(8);
    accounts.push(AccountMeta::new_readonly(*options_market, false));
    accounts.push(AccountMeta::new_readonly(option_market_authority, false));
    accounts.push(AccountMeta::new(*writer_token_mint, false));
    accounts.push(AccountMeta::new(*writer_token_source, false));
    accounts.push(AccountMeta::new_readonly(
        *writer_token_source_authority,
        true,
    ));
    accounts.push(AccountMeta::new(*quote_asset_dest, false));
    accounts.push(AccountMeta::new(*quote_asset_pool, false));
    accounts.push(AccountMeta::new_readonly(spl_token::id(), false));

    Ok(Instruction {
        program_id: *program_id,
        data,
        accounts,
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_pack_unpack_init_market() {
        let underlying_amount_per_contract: u64 = 100;
        let quote_amount_per_contract: u64 = 500; // strike price of 5
        let expiration_unix_timestamp: UnixTimestamp = 1607743435;
        let bump_seed: u8 = 1;
        let check = OptionsInstruction::InitializeMarket {
            underlying_amount_per_contract,
            quote_amount_per_contract,
            expiration_unix_timestamp,
            bump_seed,
        };
        let packed = check.pack();
        // add the tag to the expected buffer
        let mut expect = Vec::from([0u8]);
        // add the other instruction inputs to expected buffer
        expect.extend_from_slice(&underlying_amount_per_contract.to_le_bytes());
        expect.extend_from_slice(&quote_amount_per_contract.to_le_bytes());
        expect.extend_from_slice(&expiration_unix_timestamp.to_le_bytes());
        expect.extend_from_slice(&bump_seed.to_le_bytes());
        assert_eq!(packed, expect);
        let unpacked = OptionsInstruction::unpack(&expect).unwrap();
        assert_eq!(unpacked, check);
    }

    #[test]
    fn test_pack_unpack_mint_covered_call() {
        let size = 2;
        let check = OptionsInstruction::MintCoveredCall { size };
        let packed = check.pack();
        // add the tag to the expected buffer
        let expect = Vec::from([1, 2, 0, 0, 0, 0, 0, 0, 0]);
        assert_eq!(packed, expect);
        let unpacked = OptionsInstruction::unpack(&expect).unwrap();
        assert_eq!(unpacked, check);
    }

    #[test]
    fn test_pack_unpack_exercise_covered_call() {
        let size = 2;
        let check = OptionsInstruction::ExerciseCoveredCall { size };
        let packed = check.pack();
        // add the tag to the expected buffer
        let expect = Vec::from([2, 2, 0, 0, 0, 0, 0, 0, 0]);
        assert_eq!(packed, expect);
        let unpacked = OptionsInstruction::unpack(&expect).unwrap();
        assert_eq!(unpacked, check);
    }

    #[test]
    fn test_pack_unpack_close_post_expiration() {
        let size = 2;
        let check = OptionsInstruction::ClosePostExpiration { size };
        let packed = check.pack();
        // add the tag to the expected buffer
        let expect = Vec::from([3, 2, 0, 0, 0, 0, 0, 0, 0]);
        assert_eq!(packed, expect);
        let unpacked = OptionsInstruction::unpack(&expect).unwrap();
        assert_eq!(unpacked, check);
    }

    #[test]
    fn test_pack_unpack_close_position() {
        let size = 2;
        let check = OptionsInstruction::ClosePosition { size };
        let packed = check.pack();
        // add the tag to the expected buffer
        let expect = Vec::from([4, 2, 0, 0, 0, 0, 0, 0, 0]);
        assert_eq!(packed, expect);
        let unpacked = OptionsInstruction::unpack(&expect).unwrap();
        assert_eq!(unpacked, check);
    }

    #[test]
    fn test_pack_unpack_exchange_writer_token_for_quote() {
        let size = 2;
        let check = OptionsInstruction::ExchangeWriterTokenForQuote { size };
        let packed = check.pack();
        // add the tag to the expected buffer
        let expect = Vec::from([5, 2, 0, 0, 0, 0, 0, 0, 0]);
        assert_eq!(packed, expect);
        let unpacked = OptionsInstruction::unpack(&expect).unwrap();
        assert_eq!(unpacked, check);
    }
}