@epicentral/sos-sdk 0.10.3-beta → 0.10.5-beta

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.
@@ -0,0 +1,577 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ combineCodec,
11
+ fixDecoderSize,
12
+ fixEncoderSize,
13
+ getAddressEncoder,
14
+ getBytesDecoder,
15
+ getBytesEncoder,
16
+ getProgramDerivedAddress,
17
+ getStructDecoder,
18
+ getStructEncoder,
19
+ transformEncoder,
20
+ type AccountMeta,
21
+ type AccountSignerMeta,
22
+ type Address,
23
+ type FixedSizeCodec,
24
+ type FixedSizeDecoder,
25
+ type FixedSizeEncoder,
26
+ type Instruction,
27
+ type InstructionWithAccounts,
28
+ type InstructionWithData,
29
+ type ReadonlyAccount,
30
+ type ReadonlyUint8Array,
31
+ type TransactionSigner,
32
+ type WritableAccount,
33
+ type WritableSignerAccount,
34
+ } from "@solana/kit";
35
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
36
+ import {
37
+ expectAddress,
38
+ getAccountMetaFactory,
39
+ type ResolvedAccount,
40
+ } from "../shared";
41
+
42
+ export const PREPARE_BUYER_SETTLEMENT_DISCRIMINATOR = new Uint8Array([
43
+ 37, 99, 218, 43, 115, 142, 111, 119,
44
+ ]);
45
+
46
+ export function getPrepareBuyerSettlementDiscriminatorBytes() {
47
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
48
+ PREPARE_BUYER_SETTLEMENT_DISCRIMINATOR,
49
+ );
50
+ }
51
+
52
+ export type PrepareBuyerSettlementInstruction<
53
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
54
+ TAccountCollateralPool extends string | AccountMeta<string> = string,
55
+ TAccountOptionPool extends string | AccountMeta<string> = string,
56
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
57
+ TAccountUnderlyingMint extends string | AccountMeta<string> = string,
58
+ TAccountCollateralMint extends string | AccountMeta<string> = string,
59
+ TAccountPositionAccount extends string | AccountMeta<string> = string,
60
+ TAccountBuyerSettlementClaim extends string | AccountMeta<string> = string,
61
+ TAccountSwitchboardQueue extends string | AccountMeta<string> = string,
62
+ TAccountSlotHashesSysvar extends string | AccountMeta<string> =
63
+ "SysvarS1otHashes111111111111111111111111111",
64
+ TAccountInstructionsSysvar extends string | AccountMeta<string> =
65
+ "Sysvar1nstructions1111111111111111111111111",
66
+ TAccountMarketData extends string | AccountMeta<string> = string,
67
+ TAccountKeeper extends string | AccountMeta<string> = string,
68
+ TAccountSystemProgram extends string | AccountMeta<string> =
69
+ "11111111111111111111111111111111",
70
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
71
+ > = Instruction<TProgram> &
72
+ InstructionWithData<ReadonlyUint8Array> &
73
+ InstructionWithAccounts<
74
+ [
75
+ TAccountCollateralPool extends string
76
+ ? WritableAccount<TAccountCollateralPool>
77
+ : TAccountCollateralPool,
78
+ TAccountOptionPool extends string
79
+ ? WritableAccount<TAccountOptionPool>
80
+ : TAccountOptionPool,
81
+ TAccountOptionAccount extends string
82
+ ? WritableAccount<TAccountOptionAccount>
83
+ : TAccountOptionAccount,
84
+ TAccountUnderlyingMint extends string
85
+ ? ReadonlyAccount<TAccountUnderlyingMint>
86
+ : TAccountUnderlyingMint,
87
+ TAccountCollateralMint extends string
88
+ ? ReadonlyAccount<TAccountCollateralMint>
89
+ : TAccountCollateralMint,
90
+ TAccountPositionAccount extends string
91
+ ? WritableAccount<TAccountPositionAccount>
92
+ : TAccountPositionAccount,
93
+ TAccountBuyerSettlementClaim extends string
94
+ ? WritableAccount<TAccountBuyerSettlementClaim>
95
+ : TAccountBuyerSettlementClaim,
96
+ TAccountSwitchboardQueue extends string
97
+ ? ReadonlyAccount<TAccountSwitchboardQueue>
98
+ : TAccountSwitchboardQueue,
99
+ TAccountSlotHashesSysvar extends string
100
+ ? ReadonlyAccount<TAccountSlotHashesSysvar>
101
+ : TAccountSlotHashesSysvar,
102
+ TAccountInstructionsSysvar extends string
103
+ ? ReadonlyAccount<TAccountInstructionsSysvar>
104
+ : TAccountInstructionsSysvar,
105
+ TAccountMarketData extends string
106
+ ? ReadonlyAccount<TAccountMarketData>
107
+ : TAccountMarketData,
108
+ TAccountKeeper extends string
109
+ ? WritableSignerAccount<TAccountKeeper> &
110
+ AccountSignerMeta<TAccountKeeper>
111
+ : TAccountKeeper,
112
+ TAccountSystemProgram extends string
113
+ ? ReadonlyAccount<TAccountSystemProgram>
114
+ : TAccountSystemProgram,
115
+ ...TRemainingAccounts,
116
+ ]
117
+ >;
118
+
119
+ export type PrepareBuyerSettlementInstructionData = {
120
+ discriminator: ReadonlyUint8Array;
121
+ };
122
+
123
+ export type PrepareBuyerSettlementInstructionDataArgs = {};
124
+
125
+ export function getPrepareBuyerSettlementInstructionDataEncoder(): FixedSizeEncoder<PrepareBuyerSettlementInstructionDataArgs> {
126
+ return transformEncoder(
127
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
128
+ (value) => ({
129
+ ...value,
130
+ discriminator: PREPARE_BUYER_SETTLEMENT_DISCRIMINATOR,
131
+ }),
132
+ );
133
+ }
134
+
135
+ export function getPrepareBuyerSettlementInstructionDataDecoder(): FixedSizeDecoder<PrepareBuyerSettlementInstructionData> {
136
+ return getStructDecoder([
137
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
138
+ ]);
139
+ }
140
+
141
+ export function getPrepareBuyerSettlementInstructionDataCodec(): FixedSizeCodec<
142
+ PrepareBuyerSettlementInstructionDataArgs,
143
+ PrepareBuyerSettlementInstructionData
144
+ > {
145
+ return combineCodec(
146
+ getPrepareBuyerSettlementInstructionDataEncoder(),
147
+ getPrepareBuyerSettlementInstructionDataDecoder(),
148
+ );
149
+ }
150
+
151
+ export type PrepareBuyerSettlementAsyncInput<
152
+ TAccountCollateralPool extends string = string,
153
+ TAccountOptionPool extends string = string,
154
+ TAccountOptionAccount extends string = string,
155
+ TAccountUnderlyingMint extends string = string,
156
+ TAccountCollateralMint extends string = string,
157
+ TAccountPositionAccount extends string = string,
158
+ TAccountBuyerSettlementClaim extends string = string,
159
+ TAccountSwitchboardQueue extends string = string,
160
+ TAccountSlotHashesSysvar extends string = string,
161
+ TAccountInstructionsSysvar extends string = string,
162
+ TAccountMarketData extends string = string,
163
+ TAccountKeeper extends string = string,
164
+ TAccountSystemProgram extends string = string,
165
+ > = {
166
+ collateralPool?: Address<TAccountCollateralPool>;
167
+ optionPool: Address<TAccountOptionPool>;
168
+ optionAccount: Address<TAccountOptionAccount>;
169
+ underlyingMint: Address<TAccountUnderlyingMint>;
170
+ collateralMint: Address<TAccountCollateralMint>;
171
+ positionAccount: Address<TAccountPositionAccount>;
172
+ buyerSettlementClaim?: Address<TAccountBuyerSettlementClaim>;
173
+ switchboardQueue: Address<TAccountSwitchboardQueue>;
174
+ slotHashesSysvar?: Address<TAccountSlotHashesSysvar>;
175
+ instructionsSysvar?: Address<TAccountInstructionsSysvar>;
176
+ marketData: Address<TAccountMarketData>;
177
+ keeper: TransactionSigner<TAccountKeeper>;
178
+ systemProgram?: Address<TAccountSystemProgram>;
179
+ };
180
+
181
+ export async function getPrepareBuyerSettlementInstructionAsync<
182
+ TAccountCollateralPool extends string,
183
+ TAccountOptionPool extends string,
184
+ TAccountOptionAccount extends string,
185
+ TAccountUnderlyingMint extends string,
186
+ TAccountCollateralMint extends string,
187
+ TAccountPositionAccount extends string,
188
+ TAccountBuyerSettlementClaim extends string,
189
+ TAccountSwitchboardQueue extends string,
190
+ TAccountSlotHashesSysvar extends string,
191
+ TAccountInstructionsSysvar extends string,
192
+ TAccountMarketData extends string,
193
+ TAccountKeeper extends string,
194
+ TAccountSystemProgram extends string,
195
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
196
+ >(
197
+ input: PrepareBuyerSettlementAsyncInput<
198
+ TAccountCollateralPool,
199
+ TAccountOptionPool,
200
+ TAccountOptionAccount,
201
+ TAccountUnderlyingMint,
202
+ TAccountCollateralMint,
203
+ TAccountPositionAccount,
204
+ TAccountBuyerSettlementClaim,
205
+ TAccountSwitchboardQueue,
206
+ TAccountSlotHashesSysvar,
207
+ TAccountInstructionsSysvar,
208
+ TAccountMarketData,
209
+ TAccountKeeper,
210
+ TAccountSystemProgram
211
+ >,
212
+ config?: { programAddress?: TProgramAddress },
213
+ ): Promise<
214
+ PrepareBuyerSettlementInstruction<
215
+ TProgramAddress,
216
+ TAccountCollateralPool,
217
+ TAccountOptionPool,
218
+ TAccountOptionAccount,
219
+ TAccountUnderlyingMint,
220
+ TAccountCollateralMint,
221
+ TAccountPositionAccount,
222
+ TAccountBuyerSettlementClaim,
223
+ TAccountSwitchboardQueue,
224
+ TAccountSlotHashesSysvar,
225
+ TAccountInstructionsSysvar,
226
+ TAccountMarketData,
227
+ TAccountKeeper,
228
+ TAccountSystemProgram
229
+ >
230
+ > {
231
+ // Program address.
232
+ const programAddress =
233
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
234
+
235
+ // Original accounts.
236
+ const originalAccounts = {
237
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
238
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
239
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
240
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
241
+ collateralMint: { value: input.collateralMint ?? null, isWritable: false },
242
+ positionAccount: { value: input.positionAccount ?? null, isWritable: true },
243
+ buyerSettlementClaim: {
244
+ value: input.buyerSettlementClaim ?? null,
245
+ isWritable: true,
246
+ },
247
+ switchboardQueue: {
248
+ value: input.switchboardQueue ?? null,
249
+ isWritable: false,
250
+ },
251
+ slotHashesSysvar: {
252
+ value: input.slotHashesSysvar ?? null,
253
+ isWritable: false,
254
+ },
255
+ instructionsSysvar: {
256
+ value: input.instructionsSysvar ?? null,
257
+ isWritable: false,
258
+ },
259
+ marketData: { value: input.marketData ?? null, isWritable: false },
260
+ keeper: { value: input.keeper ?? null, isWritable: true },
261
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
262
+ };
263
+ const accounts = originalAccounts as Record<
264
+ keyof typeof originalAccounts,
265
+ ResolvedAccount
266
+ >;
267
+
268
+ // Resolve default values.
269
+ if (!accounts.collateralPool.value) {
270
+ accounts.collateralPool.value = await getProgramDerivedAddress({
271
+ programAddress,
272
+ seeds: [
273
+ getBytesEncoder().encode(
274
+ new Uint8Array([
275
+ 99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
276
+ 108,
277
+ ]),
278
+ ),
279
+ getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
280
+ ],
281
+ });
282
+ }
283
+ if (!accounts.buyerSettlementClaim.value) {
284
+ accounts.buyerSettlementClaim.value = await getProgramDerivedAddress({
285
+ programAddress,
286
+ seeds: [
287
+ getBytesEncoder().encode(
288
+ new Uint8Array([
289
+ 98, 117, 121, 101, 114, 95, 115, 101, 116, 116, 108, 101, 109, 101,
290
+ 110, 116, 95, 99, 108, 97, 105, 109,
291
+ ]),
292
+ ),
293
+ getAddressEncoder().encode(
294
+ expectAddress(accounts.positionAccount.value),
295
+ ),
296
+ ],
297
+ });
298
+ }
299
+ if (!accounts.slotHashesSysvar.value) {
300
+ accounts.slotHashesSysvar.value =
301
+ "SysvarS1otHashes111111111111111111111111111" as Address<"SysvarS1otHashes111111111111111111111111111">;
302
+ }
303
+ if (!accounts.instructionsSysvar.value) {
304
+ accounts.instructionsSysvar.value =
305
+ "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">;
306
+ }
307
+ if (!accounts.systemProgram.value) {
308
+ accounts.systemProgram.value =
309
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
310
+ }
311
+
312
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
313
+ return Object.freeze({
314
+ accounts: [
315
+ getAccountMeta(accounts.collateralPool),
316
+ getAccountMeta(accounts.optionPool),
317
+ getAccountMeta(accounts.optionAccount),
318
+ getAccountMeta(accounts.underlyingMint),
319
+ getAccountMeta(accounts.collateralMint),
320
+ getAccountMeta(accounts.positionAccount),
321
+ getAccountMeta(accounts.buyerSettlementClaim),
322
+ getAccountMeta(accounts.switchboardQueue),
323
+ getAccountMeta(accounts.slotHashesSysvar),
324
+ getAccountMeta(accounts.instructionsSysvar),
325
+ getAccountMeta(accounts.marketData),
326
+ getAccountMeta(accounts.keeper),
327
+ getAccountMeta(accounts.systemProgram),
328
+ ],
329
+ data: getPrepareBuyerSettlementInstructionDataEncoder().encode({}),
330
+ programAddress,
331
+ } as PrepareBuyerSettlementInstruction<
332
+ TProgramAddress,
333
+ TAccountCollateralPool,
334
+ TAccountOptionPool,
335
+ TAccountOptionAccount,
336
+ TAccountUnderlyingMint,
337
+ TAccountCollateralMint,
338
+ TAccountPositionAccount,
339
+ TAccountBuyerSettlementClaim,
340
+ TAccountSwitchboardQueue,
341
+ TAccountSlotHashesSysvar,
342
+ TAccountInstructionsSysvar,
343
+ TAccountMarketData,
344
+ TAccountKeeper,
345
+ TAccountSystemProgram
346
+ >);
347
+ }
348
+
349
+ export type PrepareBuyerSettlementInput<
350
+ TAccountCollateralPool extends string = string,
351
+ TAccountOptionPool extends string = string,
352
+ TAccountOptionAccount extends string = string,
353
+ TAccountUnderlyingMint extends string = string,
354
+ TAccountCollateralMint extends string = string,
355
+ TAccountPositionAccount extends string = string,
356
+ TAccountBuyerSettlementClaim extends string = string,
357
+ TAccountSwitchboardQueue extends string = string,
358
+ TAccountSlotHashesSysvar extends string = string,
359
+ TAccountInstructionsSysvar extends string = string,
360
+ TAccountMarketData extends string = string,
361
+ TAccountKeeper extends string = string,
362
+ TAccountSystemProgram extends string = string,
363
+ > = {
364
+ collateralPool: Address<TAccountCollateralPool>;
365
+ optionPool: Address<TAccountOptionPool>;
366
+ optionAccount: Address<TAccountOptionAccount>;
367
+ underlyingMint: Address<TAccountUnderlyingMint>;
368
+ collateralMint: Address<TAccountCollateralMint>;
369
+ positionAccount: Address<TAccountPositionAccount>;
370
+ buyerSettlementClaim: Address<TAccountBuyerSettlementClaim>;
371
+ switchboardQueue: Address<TAccountSwitchboardQueue>;
372
+ slotHashesSysvar?: Address<TAccountSlotHashesSysvar>;
373
+ instructionsSysvar?: Address<TAccountInstructionsSysvar>;
374
+ marketData: Address<TAccountMarketData>;
375
+ keeper: TransactionSigner<TAccountKeeper>;
376
+ systemProgram?: Address<TAccountSystemProgram>;
377
+ };
378
+
379
+ export function getPrepareBuyerSettlementInstruction<
380
+ TAccountCollateralPool extends string,
381
+ TAccountOptionPool extends string,
382
+ TAccountOptionAccount extends string,
383
+ TAccountUnderlyingMint extends string,
384
+ TAccountCollateralMint extends string,
385
+ TAccountPositionAccount extends string,
386
+ TAccountBuyerSettlementClaim extends string,
387
+ TAccountSwitchboardQueue extends string,
388
+ TAccountSlotHashesSysvar extends string,
389
+ TAccountInstructionsSysvar extends string,
390
+ TAccountMarketData extends string,
391
+ TAccountKeeper extends string,
392
+ TAccountSystemProgram extends string,
393
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
394
+ >(
395
+ input: PrepareBuyerSettlementInput<
396
+ TAccountCollateralPool,
397
+ TAccountOptionPool,
398
+ TAccountOptionAccount,
399
+ TAccountUnderlyingMint,
400
+ TAccountCollateralMint,
401
+ TAccountPositionAccount,
402
+ TAccountBuyerSettlementClaim,
403
+ TAccountSwitchboardQueue,
404
+ TAccountSlotHashesSysvar,
405
+ TAccountInstructionsSysvar,
406
+ TAccountMarketData,
407
+ TAccountKeeper,
408
+ TAccountSystemProgram
409
+ >,
410
+ config?: { programAddress?: TProgramAddress },
411
+ ): PrepareBuyerSettlementInstruction<
412
+ TProgramAddress,
413
+ TAccountCollateralPool,
414
+ TAccountOptionPool,
415
+ TAccountOptionAccount,
416
+ TAccountUnderlyingMint,
417
+ TAccountCollateralMint,
418
+ TAccountPositionAccount,
419
+ TAccountBuyerSettlementClaim,
420
+ TAccountSwitchboardQueue,
421
+ TAccountSlotHashesSysvar,
422
+ TAccountInstructionsSysvar,
423
+ TAccountMarketData,
424
+ TAccountKeeper,
425
+ TAccountSystemProgram
426
+ > {
427
+ // Program address.
428
+ const programAddress =
429
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
430
+
431
+ // Original accounts.
432
+ const originalAccounts = {
433
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
434
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
435
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
436
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
437
+ collateralMint: { value: input.collateralMint ?? null, isWritable: false },
438
+ positionAccount: { value: input.positionAccount ?? null, isWritable: true },
439
+ buyerSettlementClaim: {
440
+ value: input.buyerSettlementClaim ?? null,
441
+ isWritable: true,
442
+ },
443
+ switchboardQueue: {
444
+ value: input.switchboardQueue ?? null,
445
+ isWritable: false,
446
+ },
447
+ slotHashesSysvar: {
448
+ value: input.slotHashesSysvar ?? null,
449
+ isWritable: false,
450
+ },
451
+ instructionsSysvar: {
452
+ value: input.instructionsSysvar ?? null,
453
+ isWritable: false,
454
+ },
455
+ marketData: { value: input.marketData ?? null, isWritable: false },
456
+ keeper: { value: input.keeper ?? null, isWritable: true },
457
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
458
+ };
459
+ const accounts = originalAccounts as Record<
460
+ keyof typeof originalAccounts,
461
+ ResolvedAccount
462
+ >;
463
+
464
+ // Resolve default values.
465
+ if (!accounts.slotHashesSysvar.value) {
466
+ accounts.slotHashesSysvar.value =
467
+ "SysvarS1otHashes111111111111111111111111111" as Address<"SysvarS1otHashes111111111111111111111111111">;
468
+ }
469
+ if (!accounts.instructionsSysvar.value) {
470
+ accounts.instructionsSysvar.value =
471
+ "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">;
472
+ }
473
+ if (!accounts.systemProgram.value) {
474
+ accounts.systemProgram.value =
475
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
476
+ }
477
+
478
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
479
+ return Object.freeze({
480
+ accounts: [
481
+ getAccountMeta(accounts.collateralPool),
482
+ getAccountMeta(accounts.optionPool),
483
+ getAccountMeta(accounts.optionAccount),
484
+ getAccountMeta(accounts.underlyingMint),
485
+ getAccountMeta(accounts.collateralMint),
486
+ getAccountMeta(accounts.positionAccount),
487
+ getAccountMeta(accounts.buyerSettlementClaim),
488
+ getAccountMeta(accounts.switchboardQueue),
489
+ getAccountMeta(accounts.slotHashesSysvar),
490
+ getAccountMeta(accounts.instructionsSysvar),
491
+ getAccountMeta(accounts.marketData),
492
+ getAccountMeta(accounts.keeper),
493
+ getAccountMeta(accounts.systemProgram),
494
+ ],
495
+ data: getPrepareBuyerSettlementInstructionDataEncoder().encode({}),
496
+ programAddress,
497
+ } as PrepareBuyerSettlementInstruction<
498
+ TProgramAddress,
499
+ TAccountCollateralPool,
500
+ TAccountOptionPool,
501
+ TAccountOptionAccount,
502
+ TAccountUnderlyingMint,
503
+ TAccountCollateralMint,
504
+ TAccountPositionAccount,
505
+ TAccountBuyerSettlementClaim,
506
+ TAccountSwitchboardQueue,
507
+ TAccountSlotHashesSysvar,
508
+ TAccountInstructionsSysvar,
509
+ TAccountMarketData,
510
+ TAccountKeeper,
511
+ TAccountSystemProgram
512
+ >);
513
+ }
514
+
515
+ export type ParsedPrepareBuyerSettlementInstruction<
516
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
517
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
518
+ > = {
519
+ programAddress: Address<TProgram>;
520
+ accounts: {
521
+ collateralPool: TAccountMetas[0];
522
+ optionPool: TAccountMetas[1];
523
+ optionAccount: TAccountMetas[2];
524
+ underlyingMint: TAccountMetas[3];
525
+ collateralMint: TAccountMetas[4];
526
+ positionAccount: TAccountMetas[5];
527
+ buyerSettlementClaim: TAccountMetas[6];
528
+ switchboardQueue: TAccountMetas[7];
529
+ slotHashesSysvar: TAccountMetas[8];
530
+ instructionsSysvar: TAccountMetas[9];
531
+ marketData: TAccountMetas[10];
532
+ keeper: TAccountMetas[11];
533
+ systemProgram: TAccountMetas[12];
534
+ };
535
+ data: PrepareBuyerSettlementInstructionData;
536
+ };
537
+
538
+ export function parsePrepareBuyerSettlementInstruction<
539
+ TProgram extends string,
540
+ TAccountMetas extends readonly AccountMeta[],
541
+ >(
542
+ instruction: Instruction<TProgram> &
543
+ InstructionWithAccounts<TAccountMetas> &
544
+ InstructionWithData<ReadonlyUint8Array>,
545
+ ): ParsedPrepareBuyerSettlementInstruction<TProgram, TAccountMetas> {
546
+ if (instruction.accounts.length < 13) {
547
+ // TODO: Coded error.
548
+ throw new Error("Not enough accounts");
549
+ }
550
+ let accountIndex = 0;
551
+ const getNextAccount = () => {
552
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
553
+ accountIndex += 1;
554
+ return accountMeta;
555
+ };
556
+ return {
557
+ programAddress: instruction.programAddress,
558
+ accounts: {
559
+ collateralPool: getNextAccount(),
560
+ optionPool: getNextAccount(),
561
+ optionAccount: getNextAccount(),
562
+ underlyingMint: getNextAccount(),
563
+ collateralMint: getNextAccount(),
564
+ positionAccount: getNextAccount(),
565
+ buyerSettlementClaim: getNextAccount(),
566
+ switchboardQueue: getNextAccount(),
567
+ slotHashesSysvar: getNextAccount(),
568
+ instructionsSysvar: getNextAccount(),
569
+ marketData: getNextAccount(),
570
+ keeper: getNextAccount(),
571
+ systemProgram: getNextAccount(),
572
+ },
573
+ data: getPrepareBuyerSettlementInstructionDataDecoder().decode(
574
+ instruction.data,
575
+ ),
576
+ };
577
+ }