@epicentral/sos-sdk 0.1.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.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +239 -0
  3. package/accounts/fetchers.ts +140 -0
  4. package/accounts/list.ts +152 -0
  5. package/accounts/pdas.ts +308 -0
  6. package/client/lookup-table.ts +32 -0
  7. package/client/program.ts +13 -0
  8. package/client/types.ts +8 -0
  9. package/generated/accounts/collateralPool.ts +217 -0
  10. package/generated/accounts/config.ts +156 -0
  11. package/generated/accounts/dualSourceContract.ts +235 -0
  12. package/generated/accounts/escrowState.ts +183 -0
  13. package/generated/accounts/index.ts +24 -0
  14. package/generated/accounts/lenderPosition.ts +211 -0
  15. package/generated/accounts/liquidityRouter.ts +223 -0
  16. package/generated/accounts/makerCollateralShare.ts +229 -0
  17. package/generated/accounts/makerPoolShare.ts +203 -0
  18. package/generated/accounts/marketDataAccount.ts +176 -0
  19. package/generated/accounts/optionAccount.ts +247 -0
  20. package/generated/accounts/optionPool.ts +253 -0
  21. package/generated/accounts/poolLoan.ts +220 -0
  22. package/generated/accounts/positionAccount.ts +187 -0
  23. package/generated/accounts/priceUpdateV2.ts +163 -0
  24. package/generated/accounts/vault.ts +304 -0
  25. package/generated/accounts/writerPosition.ts +297 -0
  26. package/generated/errors/index.ts +9 -0
  27. package/generated/errors/optionProgram.ts +392 -0
  28. package/generated/index.ts +13 -0
  29. package/generated/instructions/acceptAdmin.ts +230 -0
  30. package/generated/instructions/autoExerciseAllExpired.ts +523 -0
  31. package/generated/instructions/autoExerciseExpired.ts +623 -0
  32. package/generated/instructions/borrowFromPool.ts +554 -0
  33. package/generated/instructions/buyFromPool.ts +684 -0
  34. package/generated/instructions/claimPremium.ts +377 -0
  35. package/generated/instructions/closeLongToPool.ts +716 -0
  36. package/generated/instructions/closeOption.ts +235 -0
  37. package/generated/instructions/createEscrowV2.ts +518 -0
  38. package/generated/instructions/createLiquidityRouter.ts +361 -0
  39. package/generated/instructions/depositCollateral.ts +624 -0
  40. package/generated/instructions/depositToPool.ts +497 -0
  41. package/generated/instructions/depositToPosition.ts +429 -0
  42. package/generated/instructions/index.ts +45 -0
  43. package/generated/instructions/initCollateralPool.ts +513 -0
  44. package/generated/instructions/initConfig.ts +279 -0
  45. package/generated/instructions/initOptionPool.ts +587 -0
  46. package/generated/instructions/initializeMarketData.ts +359 -0
  47. package/generated/instructions/liquidateWriterPosition.ts +592 -0
  48. package/generated/instructions/omlpCreateVault.ts +547 -0
  49. package/generated/instructions/omlpTakeOfferWithFailover.ts +606 -0
  50. package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
  51. package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
  52. package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
  53. package/generated/instructions/optionExercise.ts +540 -0
  54. package/generated/instructions/optionMint.ts +1349 -0
  55. package/generated/instructions/optionValidate.ts +255 -0
  56. package/generated/instructions/repayPoolLoan.ts +499 -0
  57. package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
  58. package/generated/instructions/settleMakerCollateral.ts +472 -0
  59. package/generated/instructions/syncWriterPosition.ts +206 -0
  60. package/generated/instructions/transferAdmin.ts +245 -0
  61. package/generated/instructions/unwindWriterUnsold.ts +668 -0
  62. package/generated/instructions/updateImpliedVolatility.ts +226 -0
  63. package/generated/instructions/updateMarketData.ts +315 -0
  64. package/generated/instructions/withdrawFromPool.ts +429 -0
  65. package/generated/instructions/withdrawFromPosition.ts +405 -0
  66. package/generated/instructions/writeToPool.ts +594 -0
  67. package/generated/programs/index.ts +9 -0
  68. package/generated/programs/optionProgram.ts +832 -0
  69. package/generated/shared/index.ts +164 -0
  70. package/generated/types/borrowedFromSAP1.ts +75 -0
  71. package/generated/types/borrowedFromSAP2.ts +83 -0
  72. package/generated/types/failoverTriggered.ts +85 -0
  73. package/generated/types/impliedVolatilityUpdated.ts +73 -0
  74. package/generated/types/index.ts +32 -0
  75. package/generated/types/liquidationExecuted.ts +73 -0
  76. package/generated/types/liquidityMetrics.ts +69 -0
  77. package/generated/types/liquidityRouterCreated.ts +79 -0
  78. package/generated/types/marketDataInitialized.ts +61 -0
  79. package/generated/types/marketDataUpdated.ts +69 -0
  80. package/generated/types/optionClosed.ts +56 -0
  81. package/generated/types/optionExercised.ts +62 -0
  82. package/generated/types/optionExpired.ts +49 -0
  83. package/generated/types/optionMinted.ts +78 -0
  84. package/generated/types/optionType.ts +38 -0
  85. package/generated/types/optionValidated.ts +82 -0
  86. package/generated/types/poolLoanCreated.ts +74 -0
  87. package/generated/types/poolLoanRepaid.ts +74 -0
  88. package/generated/types/positionDeposited.ts +73 -0
  89. package/generated/types/positionWithdrawn.ts +81 -0
  90. package/generated/types/priceFeedMessage.ts +117 -0
  91. package/generated/types/protocolFeeUpdated.ts +69 -0
  92. package/generated/types/sap2Provider.ts +38 -0
  93. package/generated/types/vaultCreated.ts +60 -0
  94. package/generated/types/verificationLevel.ts +95 -0
  95. package/index.ts +25 -0
  96. package/long/builders.ts +126 -0
  97. package/long/exercise.ts +49 -0
  98. package/long/quotes.ts +48 -0
  99. package/omlp/builders.ts +74 -0
  100. package/omlp/service.ts +94 -0
  101. package/package.json +22 -0
  102. package/shared/amounts.ts +32 -0
  103. package/shared/errors.ts +12 -0
  104. package/shared/remaining-accounts.ts +41 -0
  105. package/shared/transactions.ts +49 -0
  106. package/short/builders.ts +268 -0
  107. package/short/claim-premium.ts +37 -0
  108. package/short/close-option.ts +34 -0
  109. package/short/pool.ts +224 -0
  110. package/tsconfig.json +12 -0
@@ -0,0 +1,523 @@
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
+ getU8Decoder,
20
+ getU8Encoder,
21
+ transformEncoder,
22
+ type AccountMeta,
23
+ type AccountSignerMeta,
24
+ type Address,
25
+ type FixedSizeCodec,
26
+ type FixedSizeDecoder,
27
+ type FixedSizeEncoder,
28
+ type Instruction,
29
+ type InstructionWithAccounts,
30
+ type InstructionWithData,
31
+ type ReadonlyAccount,
32
+ type ReadonlyUint8Array,
33
+ type TransactionSigner,
34
+ type WritableAccount,
35
+ type WritableSignerAccount,
36
+ } from "@solana/kit";
37
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
38
+ import {
39
+ expectAddress,
40
+ getAccountMetaFactory,
41
+ type ResolvedAccount,
42
+ } from "../shared";
43
+
44
+ export const AUTO_EXERCISE_ALL_EXPIRED_DISCRIMINATOR = new Uint8Array([
45
+ 114, 241, 93, 137, 214, 147, 43, 57,
46
+ ]);
47
+
48
+ export function getAutoExerciseAllExpiredDiscriminatorBytes() {
49
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
50
+ AUTO_EXERCISE_ALL_EXPIRED_DISCRIMINATOR,
51
+ );
52
+ }
53
+
54
+ export type AutoExerciseAllExpiredInstruction<
55
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
56
+ TAccountCollateralPool extends string | AccountMeta<string> = string,
57
+ TAccountOptionPool extends string | AccountMeta<string> = string,
58
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
59
+ TAccountCollateralVault extends string | AccountMeta<string> = string,
60
+ TAccountOmlpVault extends string | AccountMeta<string> = string,
61
+ TAccountOptionMint extends string | AccountMeta<string> = string,
62
+ TAccountPriceUpdate extends string | AccountMeta<string> = string,
63
+ TAccountMarketData extends string | AccountMeta<string> = string,
64
+ TAccountKeeper extends string | AccountMeta<string> = string,
65
+ TAccountTokenProgram extends string | AccountMeta<string> =
66
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
67
+ TAccountSystemProgram extends string | AccountMeta<string> =
68
+ "11111111111111111111111111111111",
69
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
70
+ > = Instruction<TProgram> &
71
+ InstructionWithData<ReadonlyUint8Array> &
72
+ InstructionWithAccounts<
73
+ [
74
+ TAccountCollateralPool extends string
75
+ ? WritableAccount<TAccountCollateralPool>
76
+ : TAccountCollateralPool,
77
+ TAccountOptionPool extends string
78
+ ? WritableAccount<TAccountOptionPool>
79
+ : TAccountOptionPool,
80
+ TAccountOptionAccount extends string
81
+ ? WritableAccount<TAccountOptionAccount>
82
+ : TAccountOptionAccount,
83
+ TAccountCollateralVault extends string
84
+ ? WritableAccount<TAccountCollateralVault>
85
+ : TAccountCollateralVault,
86
+ TAccountOmlpVault extends string
87
+ ? WritableAccount<TAccountOmlpVault>
88
+ : TAccountOmlpVault,
89
+ TAccountOptionMint extends string
90
+ ? WritableAccount<TAccountOptionMint>
91
+ : TAccountOptionMint,
92
+ TAccountPriceUpdate extends string
93
+ ? ReadonlyAccount<TAccountPriceUpdate>
94
+ : TAccountPriceUpdate,
95
+ TAccountMarketData extends string
96
+ ? ReadonlyAccount<TAccountMarketData>
97
+ : TAccountMarketData,
98
+ TAccountKeeper extends string
99
+ ? WritableSignerAccount<TAccountKeeper> &
100
+ AccountSignerMeta<TAccountKeeper>
101
+ : TAccountKeeper,
102
+ TAccountTokenProgram extends string
103
+ ? ReadonlyAccount<TAccountTokenProgram>
104
+ : TAccountTokenProgram,
105
+ TAccountSystemProgram extends string
106
+ ? ReadonlyAccount<TAccountSystemProgram>
107
+ : TAccountSystemProgram,
108
+ ...TRemainingAccounts,
109
+ ]
110
+ >;
111
+
112
+ export type AutoExerciseAllExpiredInstructionData = {
113
+ discriminator: ReadonlyUint8Array;
114
+ maxPositions: number;
115
+ };
116
+
117
+ export type AutoExerciseAllExpiredInstructionDataArgs = {
118
+ maxPositions: number;
119
+ };
120
+
121
+ export function getAutoExerciseAllExpiredInstructionDataEncoder(): FixedSizeEncoder<AutoExerciseAllExpiredInstructionDataArgs> {
122
+ return transformEncoder(
123
+ getStructEncoder([
124
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
125
+ ["maxPositions", getU8Encoder()],
126
+ ]),
127
+ (value) => ({
128
+ ...value,
129
+ discriminator: AUTO_EXERCISE_ALL_EXPIRED_DISCRIMINATOR,
130
+ }),
131
+ );
132
+ }
133
+
134
+ export function getAutoExerciseAllExpiredInstructionDataDecoder(): FixedSizeDecoder<AutoExerciseAllExpiredInstructionData> {
135
+ return getStructDecoder([
136
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
137
+ ["maxPositions", getU8Decoder()],
138
+ ]);
139
+ }
140
+
141
+ export function getAutoExerciseAllExpiredInstructionDataCodec(): FixedSizeCodec<
142
+ AutoExerciseAllExpiredInstructionDataArgs,
143
+ AutoExerciseAllExpiredInstructionData
144
+ > {
145
+ return combineCodec(
146
+ getAutoExerciseAllExpiredInstructionDataEncoder(),
147
+ getAutoExerciseAllExpiredInstructionDataDecoder(),
148
+ );
149
+ }
150
+
151
+ export type AutoExerciseAllExpiredAsyncInput<
152
+ TAccountCollateralPool extends string = string,
153
+ TAccountOptionPool extends string = string,
154
+ TAccountOptionAccount extends string = string,
155
+ TAccountCollateralVault extends string = string,
156
+ TAccountOmlpVault extends string = string,
157
+ TAccountOptionMint extends string = string,
158
+ TAccountPriceUpdate extends string = string,
159
+ TAccountMarketData extends string = string,
160
+ TAccountKeeper extends string = string,
161
+ TAccountTokenProgram extends string = string,
162
+ TAccountSystemProgram extends string = string,
163
+ > = {
164
+ collateralPool?: Address<TAccountCollateralPool>;
165
+ optionPool: Address<TAccountOptionPool>;
166
+ optionAccount: Address<TAccountOptionAccount>;
167
+ /** Pool's collateral vault (source of payout) */
168
+ collateralVault: Address<TAccountCollateralVault>;
169
+ /** OMLP Vault token account to receive repayments */
170
+ omlpVault: Address<TAccountOmlpVault>;
171
+ /** Option mint (for burning) */
172
+ optionMint: Address<TAccountOptionMint>;
173
+ /** Pyth price update account (ownership validated by Anchor) */
174
+ priceUpdate: Address<TAccountPriceUpdate>;
175
+ /** Market data for this underlying asset (contains pyth_feed_id) */
176
+ marketData: Address<TAccountMarketData>;
177
+ /** Keeper who pays for gas - anyone can call this after expiration */
178
+ keeper: TransactionSigner<TAccountKeeper>;
179
+ tokenProgram?: Address<TAccountTokenProgram>;
180
+ systemProgram?: Address<TAccountSystemProgram>;
181
+ maxPositions: AutoExerciseAllExpiredInstructionDataArgs["maxPositions"];
182
+ };
183
+
184
+ export async function getAutoExerciseAllExpiredInstructionAsync<
185
+ TAccountCollateralPool extends string,
186
+ TAccountOptionPool extends string,
187
+ TAccountOptionAccount extends string,
188
+ TAccountCollateralVault extends string,
189
+ TAccountOmlpVault extends string,
190
+ TAccountOptionMint extends string,
191
+ TAccountPriceUpdate extends string,
192
+ TAccountMarketData extends string,
193
+ TAccountKeeper extends string,
194
+ TAccountTokenProgram extends string,
195
+ TAccountSystemProgram extends string,
196
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
197
+ >(
198
+ input: AutoExerciseAllExpiredAsyncInput<
199
+ TAccountCollateralPool,
200
+ TAccountOptionPool,
201
+ TAccountOptionAccount,
202
+ TAccountCollateralVault,
203
+ TAccountOmlpVault,
204
+ TAccountOptionMint,
205
+ TAccountPriceUpdate,
206
+ TAccountMarketData,
207
+ TAccountKeeper,
208
+ TAccountTokenProgram,
209
+ TAccountSystemProgram
210
+ >,
211
+ config?: { programAddress?: TProgramAddress },
212
+ ): Promise<
213
+ AutoExerciseAllExpiredInstruction<
214
+ TProgramAddress,
215
+ TAccountCollateralPool,
216
+ TAccountOptionPool,
217
+ TAccountOptionAccount,
218
+ TAccountCollateralVault,
219
+ TAccountOmlpVault,
220
+ TAccountOptionMint,
221
+ TAccountPriceUpdate,
222
+ TAccountMarketData,
223
+ TAccountKeeper,
224
+ TAccountTokenProgram,
225
+ TAccountSystemProgram
226
+ >
227
+ > {
228
+ // Program address.
229
+ const programAddress =
230
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
231
+
232
+ // Original accounts.
233
+ const originalAccounts = {
234
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
235
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
236
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
237
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
238
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
239
+ optionMint: { value: input.optionMint ?? null, isWritable: true },
240
+ priceUpdate: { value: input.priceUpdate ?? null, isWritable: false },
241
+ marketData: { value: input.marketData ?? null, isWritable: false },
242
+ keeper: { value: input.keeper ?? null, isWritable: true },
243
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
244
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
245
+ };
246
+ const accounts = originalAccounts as Record<
247
+ keyof typeof originalAccounts,
248
+ ResolvedAccount
249
+ >;
250
+
251
+ // Original args.
252
+ const args = { ...input };
253
+
254
+ // Resolve default values.
255
+ if (!accounts.collateralPool.value) {
256
+ accounts.collateralPool.value = await getProgramDerivedAddress({
257
+ programAddress,
258
+ seeds: [
259
+ getBytesEncoder().encode(
260
+ new Uint8Array([
261
+ 99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
262
+ 108,
263
+ ]),
264
+ ),
265
+ getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
266
+ ],
267
+ });
268
+ }
269
+ if (!accounts.tokenProgram.value) {
270
+ accounts.tokenProgram.value =
271
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
272
+ }
273
+ if (!accounts.systemProgram.value) {
274
+ accounts.systemProgram.value =
275
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
276
+ }
277
+
278
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
279
+ return Object.freeze({
280
+ accounts: [
281
+ getAccountMeta(accounts.collateralPool),
282
+ getAccountMeta(accounts.optionPool),
283
+ getAccountMeta(accounts.optionAccount),
284
+ getAccountMeta(accounts.collateralVault),
285
+ getAccountMeta(accounts.omlpVault),
286
+ getAccountMeta(accounts.optionMint),
287
+ getAccountMeta(accounts.priceUpdate),
288
+ getAccountMeta(accounts.marketData),
289
+ getAccountMeta(accounts.keeper),
290
+ getAccountMeta(accounts.tokenProgram),
291
+ getAccountMeta(accounts.systemProgram),
292
+ ],
293
+ data: getAutoExerciseAllExpiredInstructionDataEncoder().encode(
294
+ args as AutoExerciseAllExpiredInstructionDataArgs,
295
+ ),
296
+ programAddress,
297
+ } as AutoExerciseAllExpiredInstruction<
298
+ TProgramAddress,
299
+ TAccountCollateralPool,
300
+ TAccountOptionPool,
301
+ TAccountOptionAccount,
302
+ TAccountCollateralVault,
303
+ TAccountOmlpVault,
304
+ TAccountOptionMint,
305
+ TAccountPriceUpdate,
306
+ TAccountMarketData,
307
+ TAccountKeeper,
308
+ TAccountTokenProgram,
309
+ TAccountSystemProgram
310
+ >);
311
+ }
312
+
313
+ export type AutoExerciseAllExpiredInput<
314
+ TAccountCollateralPool extends string = string,
315
+ TAccountOptionPool extends string = string,
316
+ TAccountOptionAccount extends string = string,
317
+ TAccountCollateralVault extends string = string,
318
+ TAccountOmlpVault extends string = string,
319
+ TAccountOptionMint extends string = string,
320
+ TAccountPriceUpdate extends string = string,
321
+ TAccountMarketData extends string = string,
322
+ TAccountKeeper extends string = string,
323
+ TAccountTokenProgram extends string = string,
324
+ TAccountSystemProgram extends string = string,
325
+ > = {
326
+ collateralPool: Address<TAccountCollateralPool>;
327
+ optionPool: Address<TAccountOptionPool>;
328
+ optionAccount: Address<TAccountOptionAccount>;
329
+ /** Pool's collateral vault (source of payout) */
330
+ collateralVault: Address<TAccountCollateralVault>;
331
+ /** OMLP Vault token account to receive repayments */
332
+ omlpVault: Address<TAccountOmlpVault>;
333
+ /** Option mint (for burning) */
334
+ optionMint: Address<TAccountOptionMint>;
335
+ /** Pyth price update account (ownership validated by Anchor) */
336
+ priceUpdate: Address<TAccountPriceUpdate>;
337
+ /** Market data for this underlying asset (contains pyth_feed_id) */
338
+ marketData: Address<TAccountMarketData>;
339
+ /** Keeper who pays for gas - anyone can call this after expiration */
340
+ keeper: TransactionSigner<TAccountKeeper>;
341
+ tokenProgram?: Address<TAccountTokenProgram>;
342
+ systemProgram?: Address<TAccountSystemProgram>;
343
+ maxPositions: AutoExerciseAllExpiredInstructionDataArgs["maxPositions"];
344
+ };
345
+
346
+ export function getAutoExerciseAllExpiredInstruction<
347
+ TAccountCollateralPool extends string,
348
+ TAccountOptionPool extends string,
349
+ TAccountOptionAccount extends string,
350
+ TAccountCollateralVault extends string,
351
+ TAccountOmlpVault extends string,
352
+ TAccountOptionMint extends string,
353
+ TAccountPriceUpdate extends string,
354
+ TAccountMarketData extends string,
355
+ TAccountKeeper extends string,
356
+ TAccountTokenProgram extends string,
357
+ TAccountSystemProgram extends string,
358
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
359
+ >(
360
+ input: AutoExerciseAllExpiredInput<
361
+ TAccountCollateralPool,
362
+ TAccountOptionPool,
363
+ TAccountOptionAccount,
364
+ TAccountCollateralVault,
365
+ TAccountOmlpVault,
366
+ TAccountOptionMint,
367
+ TAccountPriceUpdate,
368
+ TAccountMarketData,
369
+ TAccountKeeper,
370
+ TAccountTokenProgram,
371
+ TAccountSystemProgram
372
+ >,
373
+ config?: { programAddress?: TProgramAddress },
374
+ ): AutoExerciseAllExpiredInstruction<
375
+ TProgramAddress,
376
+ TAccountCollateralPool,
377
+ TAccountOptionPool,
378
+ TAccountOptionAccount,
379
+ TAccountCollateralVault,
380
+ TAccountOmlpVault,
381
+ TAccountOptionMint,
382
+ TAccountPriceUpdate,
383
+ TAccountMarketData,
384
+ TAccountKeeper,
385
+ TAccountTokenProgram,
386
+ TAccountSystemProgram
387
+ > {
388
+ // Program address.
389
+ const programAddress =
390
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
391
+
392
+ // Original accounts.
393
+ const originalAccounts = {
394
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
395
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
396
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
397
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
398
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
399
+ optionMint: { value: input.optionMint ?? null, isWritable: true },
400
+ priceUpdate: { value: input.priceUpdate ?? null, isWritable: false },
401
+ marketData: { value: input.marketData ?? null, isWritable: false },
402
+ keeper: { value: input.keeper ?? null, isWritable: true },
403
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
404
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
405
+ };
406
+ const accounts = originalAccounts as Record<
407
+ keyof typeof originalAccounts,
408
+ ResolvedAccount
409
+ >;
410
+
411
+ // Original args.
412
+ const args = { ...input };
413
+
414
+ // Resolve default values.
415
+ if (!accounts.tokenProgram.value) {
416
+ accounts.tokenProgram.value =
417
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
418
+ }
419
+ if (!accounts.systemProgram.value) {
420
+ accounts.systemProgram.value =
421
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
422
+ }
423
+
424
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
425
+ return Object.freeze({
426
+ accounts: [
427
+ getAccountMeta(accounts.collateralPool),
428
+ getAccountMeta(accounts.optionPool),
429
+ getAccountMeta(accounts.optionAccount),
430
+ getAccountMeta(accounts.collateralVault),
431
+ getAccountMeta(accounts.omlpVault),
432
+ getAccountMeta(accounts.optionMint),
433
+ getAccountMeta(accounts.priceUpdate),
434
+ getAccountMeta(accounts.marketData),
435
+ getAccountMeta(accounts.keeper),
436
+ getAccountMeta(accounts.tokenProgram),
437
+ getAccountMeta(accounts.systemProgram),
438
+ ],
439
+ data: getAutoExerciseAllExpiredInstructionDataEncoder().encode(
440
+ args as AutoExerciseAllExpiredInstructionDataArgs,
441
+ ),
442
+ programAddress,
443
+ } as AutoExerciseAllExpiredInstruction<
444
+ TProgramAddress,
445
+ TAccountCollateralPool,
446
+ TAccountOptionPool,
447
+ TAccountOptionAccount,
448
+ TAccountCollateralVault,
449
+ TAccountOmlpVault,
450
+ TAccountOptionMint,
451
+ TAccountPriceUpdate,
452
+ TAccountMarketData,
453
+ TAccountKeeper,
454
+ TAccountTokenProgram,
455
+ TAccountSystemProgram
456
+ >);
457
+ }
458
+
459
+ export type ParsedAutoExerciseAllExpiredInstruction<
460
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
461
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
462
+ > = {
463
+ programAddress: Address<TProgram>;
464
+ accounts: {
465
+ collateralPool: TAccountMetas[0];
466
+ optionPool: TAccountMetas[1];
467
+ optionAccount: TAccountMetas[2];
468
+ /** Pool's collateral vault (source of payout) */
469
+ collateralVault: TAccountMetas[3];
470
+ /** OMLP Vault token account to receive repayments */
471
+ omlpVault: TAccountMetas[4];
472
+ /** Option mint (for burning) */
473
+ optionMint: TAccountMetas[5];
474
+ /** Pyth price update account (ownership validated by Anchor) */
475
+ priceUpdate: TAccountMetas[6];
476
+ /** Market data for this underlying asset (contains pyth_feed_id) */
477
+ marketData: TAccountMetas[7];
478
+ /** Keeper who pays for gas - anyone can call this after expiration */
479
+ keeper: TAccountMetas[8];
480
+ tokenProgram: TAccountMetas[9];
481
+ systemProgram: TAccountMetas[10];
482
+ };
483
+ data: AutoExerciseAllExpiredInstructionData;
484
+ };
485
+
486
+ export function parseAutoExerciseAllExpiredInstruction<
487
+ TProgram extends string,
488
+ TAccountMetas extends readonly AccountMeta[],
489
+ >(
490
+ instruction: Instruction<TProgram> &
491
+ InstructionWithAccounts<TAccountMetas> &
492
+ InstructionWithData<ReadonlyUint8Array>,
493
+ ): ParsedAutoExerciseAllExpiredInstruction<TProgram, TAccountMetas> {
494
+ if (instruction.accounts.length < 11) {
495
+ // TODO: Coded error.
496
+ throw new Error("Not enough accounts");
497
+ }
498
+ let accountIndex = 0;
499
+ const getNextAccount = () => {
500
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
501
+ accountIndex += 1;
502
+ return accountMeta;
503
+ };
504
+ return {
505
+ programAddress: instruction.programAddress,
506
+ accounts: {
507
+ collateralPool: getNextAccount(),
508
+ optionPool: getNextAccount(),
509
+ optionAccount: getNextAccount(),
510
+ collateralVault: getNextAccount(),
511
+ omlpVault: getNextAccount(),
512
+ optionMint: getNextAccount(),
513
+ priceUpdate: getNextAccount(),
514
+ marketData: getNextAccount(),
515
+ keeper: getNextAccount(),
516
+ tokenProgram: getNextAccount(),
517
+ systemProgram: getNextAccount(),
518
+ },
519
+ data: getAutoExerciseAllExpiredInstructionDataDecoder().decode(
520
+ instruction.data,
521
+ ),
522
+ };
523
+ }