@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,623 @@
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 AUTO_EXERCISE_EXPIRED_DISCRIMINATOR = new Uint8Array([
43
+ 93, 222, 81, 8, 181, 25, 68, 25,
44
+ ]);
45
+
46
+ export function getAutoExerciseExpiredDiscriminatorBytes() {
47
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
48
+ AUTO_EXERCISE_EXPIRED_DISCRIMINATOR,
49
+ );
50
+ }
51
+
52
+ export type AutoExerciseExpiredInstruction<
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
+ TAccountPositionAccount extends string | AccountMeta<string> = string,
59
+ TAccountCollateralVault extends string | AccountMeta<string> = string,
60
+ TAccountBuyerPaymentAccount extends string | AccountMeta<string> = string,
61
+ TAccountBuyerOptionAccount extends string | AccountMeta<string> = string,
62
+ TAccountOptionMint extends string | AccountMeta<string> = string,
63
+ TAccountPriceUpdate extends string | AccountMeta<string> = string,
64
+ TAccountMarketData extends string | AccountMeta<string> = string,
65
+ TAccountOmlpVault extends string | AccountMeta<string> = string,
66
+ TAccountKeeper extends string | AccountMeta<string> = string,
67
+ TAccountTokenProgram extends string | AccountMeta<string> =
68
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
69
+ TAccountSystemProgram extends string | AccountMeta<string> =
70
+ "11111111111111111111111111111111",
71
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
72
+ > = Instruction<TProgram> &
73
+ InstructionWithData<ReadonlyUint8Array> &
74
+ InstructionWithAccounts<
75
+ [
76
+ TAccountCollateralPool extends string
77
+ ? WritableAccount<TAccountCollateralPool>
78
+ : TAccountCollateralPool,
79
+ TAccountOptionPool extends string
80
+ ? WritableAccount<TAccountOptionPool>
81
+ : TAccountOptionPool,
82
+ TAccountOptionAccount extends string
83
+ ? WritableAccount<TAccountOptionAccount>
84
+ : TAccountOptionAccount,
85
+ TAccountUnderlyingMint extends string
86
+ ? ReadonlyAccount<TAccountUnderlyingMint>
87
+ : TAccountUnderlyingMint,
88
+ TAccountPositionAccount extends string
89
+ ? WritableAccount<TAccountPositionAccount>
90
+ : TAccountPositionAccount,
91
+ TAccountCollateralVault extends string
92
+ ? WritableAccount<TAccountCollateralVault>
93
+ : TAccountCollateralVault,
94
+ TAccountBuyerPaymentAccount extends string
95
+ ? WritableAccount<TAccountBuyerPaymentAccount>
96
+ : TAccountBuyerPaymentAccount,
97
+ TAccountBuyerOptionAccount extends string
98
+ ? WritableAccount<TAccountBuyerOptionAccount>
99
+ : TAccountBuyerOptionAccount,
100
+ TAccountOptionMint extends string
101
+ ? WritableAccount<TAccountOptionMint>
102
+ : TAccountOptionMint,
103
+ TAccountPriceUpdate extends string
104
+ ? ReadonlyAccount<TAccountPriceUpdate>
105
+ : TAccountPriceUpdate,
106
+ TAccountMarketData extends string
107
+ ? ReadonlyAccount<TAccountMarketData>
108
+ : TAccountMarketData,
109
+ TAccountOmlpVault extends string
110
+ ? WritableAccount<TAccountOmlpVault>
111
+ : TAccountOmlpVault,
112
+ TAccountKeeper extends string
113
+ ? WritableSignerAccount<TAccountKeeper> &
114
+ AccountSignerMeta<TAccountKeeper>
115
+ : TAccountKeeper,
116
+ TAccountTokenProgram extends string
117
+ ? ReadonlyAccount<TAccountTokenProgram>
118
+ : TAccountTokenProgram,
119
+ TAccountSystemProgram extends string
120
+ ? ReadonlyAccount<TAccountSystemProgram>
121
+ : TAccountSystemProgram,
122
+ ...TRemainingAccounts,
123
+ ]
124
+ >;
125
+
126
+ export type AutoExerciseExpiredInstructionData = {
127
+ discriminator: ReadonlyUint8Array;
128
+ };
129
+
130
+ export type AutoExerciseExpiredInstructionDataArgs = {};
131
+
132
+ export function getAutoExerciseExpiredInstructionDataEncoder(): FixedSizeEncoder<AutoExerciseExpiredInstructionDataArgs> {
133
+ return transformEncoder(
134
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
135
+ (value) => ({
136
+ ...value,
137
+ discriminator: AUTO_EXERCISE_EXPIRED_DISCRIMINATOR,
138
+ }),
139
+ );
140
+ }
141
+
142
+ export function getAutoExerciseExpiredInstructionDataDecoder(): FixedSizeDecoder<AutoExerciseExpiredInstructionData> {
143
+ return getStructDecoder([
144
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
145
+ ]);
146
+ }
147
+
148
+ export function getAutoExerciseExpiredInstructionDataCodec(): FixedSizeCodec<
149
+ AutoExerciseExpiredInstructionDataArgs,
150
+ AutoExerciseExpiredInstructionData
151
+ > {
152
+ return combineCodec(
153
+ getAutoExerciseExpiredInstructionDataEncoder(),
154
+ getAutoExerciseExpiredInstructionDataDecoder(),
155
+ );
156
+ }
157
+
158
+ export type AutoExerciseExpiredAsyncInput<
159
+ TAccountCollateralPool extends string = string,
160
+ TAccountOptionPool extends string = string,
161
+ TAccountOptionAccount extends string = string,
162
+ TAccountUnderlyingMint extends string = string,
163
+ TAccountPositionAccount extends string = string,
164
+ TAccountCollateralVault extends string = string,
165
+ TAccountBuyerPaymentAccount extends string = string,
166
+ TAccountBuyerOptionAccount extends string = string,
167
+ TAccountOptionMint extends string = string,
168
+ TAccountPriceUpdate extends string = string,
169
+ TAccountMarketData extends string = string,
170
+ TAccountOmlpVault extends string = string,
171
+ TAccountKeeper extends string = string,
172
+ TAccountTokenProgram extends string = string,
173
+ TAccountSystemProgram extends string = string,
174
+ > = {
175
+ collateralPool?: Address<TAccountCollateralPool>;
176
+ optionPool: Address<TAccountOptionPool>;
177
+ optionAccount: Address<TAccountOptionAccount>;
178
+ /** Underlying token mint (for dynamic decimal handling - supports any SPL token) */
179
+ underlyingMint: Address<TAccountUnderlyingMint>;
180
+ /**
181
+ * Buyer's position (tracks quantity owned)
182
+ * Note: NO signer constraint - keeper exercises on behalf of buyer
183
+ */
184
+ positionAccount: Address<TAccountPositionAccount>;
185
+ /** Pool's collateral vault (source of payout) */
186
+ collateralVault: Address<TAccountCollateralVault>;
187
+ /** Buyer's WSOL account (receives intrinsic value) */
188
+ buyerPaymentAccount: Address<TAccountBuyerPaymentAccount>;
189
+ /** Buyer's option token account (burns tokens) */
190
+ buyerOptionAccount: Address<TAccountBuyerOptionAccount>;
191
+ /** Option mint (for burning) */
192
+ optionMint: Address<TAccountOptionMint>;
193
+ /** Pyth price update account (ownership validated by Anchor) */
194
+ priceUpdate: Address<TAccountPriceUpdate>;
195
+ /** Market data for this underlying asset (contains pyth_feed_id) */
196
+ marketData: Address<TAccountMarketData>;
197
+ /** OMLP Vault token account to receive repayments */
198
+ omlpVault: Address<TAccountOmlpVault>;
199
+ /** Keeper who pays for gas - anyone can call this after expiration */
200
+ keeper: TransactionSigner<TAccountKeeper>;
201
+ tokenProgram?: Address<TAccountTokenProgram>;
202
+ systemProgram?: Address<TAccountSystemProgram>;
203
+ };
204
+
205
+ export async function getAutoExerciseExpiredInstructionAsync<
206
+ TAccountCollateralPool extends string,
207
+ TAccountOptionPool extends string,
208
+ TAccountOptionAccount extends string,
209
+ TAccountUnderlyingMint extends string,
210
+ TAccountPositionAccount extends string,
211
+ TAccountCollateralVault extends string,
212
+ TAccountBuyerPaymentAccount extends string,
213
+ TAccountBuyerOptionAccount extends string,
214
+ TAccountOptionMint extends string,
215
+ TAccountPriceUpdate extends string,
216
+ TAccountMarketData extends string,
217
+ TAccountOmlpVault extends string,
218
+ TAccountKeeper extends string,
219
+ TAccountTokenProgram extends string,
220
+ TAccountSystemProgram extends string,
221
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
222
+ >(
223
+ input: AutoExerciseExpiredAsyncInput<
224
+ TAccountCollateralPool,
225
+ TAccountOptionPool,
226
+ TAccountOptionAccount,
227
+ TAccountUnderlyingMint,
228
+ TAccountPositionAccount,
229
+ TAccountCollateralVault,
230
+ TAccountBuyerPaymentAccount,
231
+ TAccountBuyerOptionAccount,
232
+ TAccountOptionMint,
233
+ TAccountPriceUpdate,
234
+ TAccountMarketData,
235
+ TAccountOmlpVault,
236
+ TAccountKeeper,
237
+ TAccountTokenProgram,
238
+ TAccountSystemProgram
239
+ >,
240
+ config?: { programAddress?: TProgramAddress },
241
+ ): Promise<
242
+ AutoExerciseExpiredInstruction<
243
+ TProgramAddress,
244
+ TAccountCollateralPool,
245
+ TAccountOptionPool,
246
+ TAccountOptionAccount,
247
+ TAccountUnderlyingMint,
248
+ TAccountPositionAccount,
249
+ TAccountCollateralVault,
250
+ TAccountBuyerPaymentAccount,
251
+ TAccountBuyerOptionAccount,
252
+ TAccountOptionMint,
253
+ TAccountPriceUpdate,
254
+ TAccountMarketData,
255
+ TAccountOmlpVault,
256
+ TAccountKeeper,
257
+ TAccountTokenProgram,
258
+ TAccountSystemProgram
259
+ >
260
+ > {
261
+ // Program address.
262
+ const programAddress =
263
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
264
+
265
+ // Original accounts.
266
+ const originalAccounts = {
267
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
268
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
269
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
270
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
271
+ positionAccount: { value: input.positionAccount ?? null, isWritable: true },
272
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
273
+ buyerPaymentAccount: {
274
+ value: input.buyerPaymentAccount ?? null,
275
+ isWritable: true,
276
+ },
277
+ buyerOptionAccount: {
278
+ value: input.buyerOptionAccount ?? null,
279
+ isWritable: true,
280
+ },
281
+ optionMint: { value: input.optionMint ?? null, isWritable: true },
282
+ priceUpdate: { value: input.priceUpdate ?? null, isWritable: false },
283
+ marketData: { value: input.marketData ?? null, isWritable: false },
284
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
285
+ keeper: { value: input.keeper ?? null, isWritable: true },
286
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
287
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
288
+ };
289
+ const accounts = originalAccounts as Record<
290
+ keyof typeof originalAccounts,
291
+ ResolvedAccount
292
+ >;
293
+
294
+ // Resolve default values.
295
+ if (!accounts.collateralPool.value) {
296
+ accounts.collateralPool.value = await getProgramDerivedAddress({
297
+ programAddress,
298
+ seeds: [
299
+ getBytesEncoder().encode(
300
+ new Uint8Array([
301
+ 99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
302
+ 108,
303
+ ]),
304
+ ),
305
+ getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
306
+ ],
307
+ });
308
+ }
309
+ if (!accounts.tokenProgram.value) {
310
+ accounts.tokenProgram.value =
311
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
312
+ }
313
+ if (!accounts.systemProgram.value) {
314
+ accounts.systemProgram.value =
315
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
316
+ }
317
+
318
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
319
+ return Object.freeze({
320
+ accounts: [
321
+ getAccountMeta(accounts.collateralPool),
322
+ getAccountMeta(accounts.optionPool),
323
+ getAccountMeta(accounts.optionAccount),
324
+ getAccountMeta(accounts.underlyingMint),
325
+ getAccountMeta(accounts.positionAccount),
326
+ getAccountMeta(accounts.collateralVault),
327
+ getAccountMeta(accounts.buyerPaymentAccount),
328
+ getAccountMeta(accounts.buyerOptionAccount),
329
+ getAccountMeta(accounts.optionMint),
330
+ getAccountMeta(accounts.priceUpdate),
331
+ getAccountMeta(accounts.marketData),
332
+ getAccountMeta(accounts.omlpVault),
333
+ getAccountMeta(accounts.keeper),
334
+ getAccountMeta(accounts.tokenProgram),
335
+ getAccountMeta(accounts.systemProgram),
336
+ ],
337
+ data: getAutoExerciseExpiredInstructionDataEncoder().encode({}),
338
+ programAddress,
339
+ } as AutoExerciseExpiredInstruction<
340
+ TProgramAddress,
341
+ TAccountCollateralPool,
342
+ TAccountOptionPool,
343
+ TAccountOptionAccount,
344
+ TAccountUnderlyingMint,
345
+ TAccountPositionAccount,
346
+ TAccountCollateralVault,
347
+ TAccountBuyerPaymentAccount,
348
+ TAccountBuyerOptionAccount,
349
+ TAccountOptionMint,
350
+ TAccountPriceUpdate,
351
+ TAccountMarketData,
352
+ TAccountOmlpVault,
353
+ TAccountKeeper,
354
+ TAccountTokenProgram,
355
+ TAccountSystemProgram
356
+ >);
357
+ }
358
+
359
+ export type AutoExerciseExpiredInput<
360
+ TAccountCollateralPool extends string = string,
361
+ TAccountOptionPool extends string = string,
362
+ TAccountOptionAccount extends string = string,
363
+ TAccountUnderlyingMint extends string = string,
364
+ TAccountPositionAccount extends string = string,
365
+ TAccountCollateralVault extends string = string,
366
+ TAccountBuyerPaymentAccount extends string = string,
367
+ TAccountBuyerOptionAccount extends string = string,
368
+ TAccountOptionMint extends string = string,
369
+ TAccountPriceUpdate extends string = string,
370
+ TAccountMarketData extends string = string,
371
+ TAccountOmlpVault extends string = string,
372
+ TAccountKeeper extends string = string,
373
+ TAccountTokenProgram extends string = string,
374
+ TAccountSystemProgram extends string = string,
375
+ > = {
376
+ collateralPool: Address<TAccountCollateralPool>;
377
+ optionPool: Address<TAccountOptionPool>;
378
+ optionAccount: Address<TAccountOptionAccount>;
379
+ /** Underlying token mint (for dynamic decimal handling - supports any SPL token) */
380
+ underlyingMint: Address<TAccountUnderlyingMint>;
381
+ /**
382
+ * Buyer's position (tracks quantity owned)
383
+ * Note: NO signer constraint - keeper exercises on behalf of buyer
384
+ */
385
+ positionAccount: Address<TAccountPositionAccount>;
386
+ /** Pool's collateral vault (source of payout) */
387
+ collateralVault: Address<TAccountCollateralVault>;
388
+ /** Buyer's WSOL account (receives intrinsic value) */
389
+ buyerPaymentAccount: Address<TAccountBuyerPaymentAccount>;
390
+ /** Buyer's option token account (burns tokens) */
391
+ buyerOptionAccount: Address<TAccountBuyerOptionAccount>;
392
+ /** Option mint (for burning) */
393
+ optionMint: Address<TAccountOptionMint>;
394
+ /** Pyth price update account (ownership validated by Anchor) */
395
+ priceUpdate: Address<TAccountPriceUpdate>;
396
+ /** Market data for this underlying asset (contains pyth_feed_id) */
397
+ marketData: Address<TAccountMarketData>;
398
+ /** OMLP Vault token account to receive repayments */
399
+ omlpVault: Address<TAccountOmlpVault>;
400
+ /** Keeper who pays for gas - anyone can call this after expiration */
401
+ keeper: TransactionSigner<TAccountKeeper>;
402
+ tokenProgram?: Address<TAccountTokenProgram>;
403
+ systemProgram?: Address<TAccountSystemProgram>;
404
+ };
405
+
406
+ export function getAutoExerciseExpiredInstruction<
407
+ TAccountCollateralPool extends string,
408
+ TAccountOptionPool extends string,
409
+ TAccountOptionAccount extends string,
410
+ TAccountUnderlyingMint extends string,
411
+ TAccountPositionAccount extends string,
412
+ TAccountCollateralVault extends string,
413
+ TAccountBuyerPaymentAccount extends string,
414
+ TAccountBuyerOptionAccount extends string,
415
+ TAccountOptionMint extends string,
416
+ TAccountPriceUpdate extends string,
417
+ TAccountMarketData extends string,
418
+ TAccountOmlpVault extends string,
419
+ TAccountKeeper extends string,
420
+ TAccountTokenProgram extends string,
421
+ TAccountSystemProgram extends string,
422
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
423
+ >(
424
+ input: AutoExerciseExpiredInput<
425
+ TAccountCollateralPool,
426
+ TAccountOptionPool,
427
+ TAccountOptionAccount,
428
+ TAccountUnderlyingMint,
429
+ TAccountPositionAccount,
430
+ TAccountCollateralVault,
431
+ TAccountBuyerPaymentAccount,
432
+ TAccountBuyerOptionAccount,
433
+ TAccountOptionMint,
434
+ TAccountPriceUpdate,
435
+ TAccountMarketData,
436
+ TAccountOmlpVault,
437
+ TAccountKeeper,
438
+ TAccountTokenProgram,
439
+ TAccountSystemProgram
440
+ >,
441
+ config?: { programAddress?: TProgramAddress },
442
+ ): AutoExerciseExpiredInstruction<
443
+ TProgramAddress,
444
+ TAccountCollateralPool,
445
+ TAccountOptionPool,
446
+ TAccountOptionAccount,
447
+ TAccountUnderlyingMint,
448
+ TAccountPositionAccount,
449
+ TAccountCollateralVault,
450
+ TAccountBuyerPaymentAccount,
451
+ TAccountBuyerOptionAccount,
452
+ TAccountOptionMint,
453
+ TAccountPriceUpdate,
454
+ TAccountMarketData,
455
+ TAccountOmlpVault,
456
+ TAccountKeeper,
457
+ TAccountTokenProgram,
458
+ TAccountSystemProgram
459
+ > {
460
+ // Program address.
461
+ const programAddress =
462
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
463
+
464
+ // Original accounts.
465
+ const originalAccounts = {
466
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
467
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
468
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
469
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
470
+ positionAccount: { value: input.positionAccount ?? null, isWritable: true },
471
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
472
+ buyerPaymentAccount: {
473
+ value: input.buyerPaymentAccount ?? null,
474
+ isWritable: true,
475
+ },
476
+ buyerOptionAccount: {
477
+ value: input.buyerOptionAccount ?? null,
478
+ isWritable: true,
479
+ },
480
+ optionMint: { value: input.optionMint ?? null, isWritable: true },
481
+ priceUpdate: { value: input.priceUpdate ?? null, isWritable: false },
482
+ marketData: { value: input.marketData ?? null, isWritable: false },
483
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
484
+ keeper: { value: input.keeper ?? null, isWritable: true },
485
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
486
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
487
+ };
488
+ const accounts = originalAccounts as Record<
489
+ keyof typeof originalAccounts,
490
+ ResolvedAccount
491
+ >;
492
+
493
+ // Resolve default values.
494
+ if (!accounts.tokenProgram.value) {
495
+ accounts.tokenProgram.value =
496
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
497
+ }
498
+ if (!accounts.systemProgram.value) {
499
+ accounts.systemProgram.value =
500
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
501
+ }
502
+
503
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
504
+ return Object.freeze({
505
+ accounts: [
506
+ getAccountMeta(accounts.collateralPool),
507
+ getAccountMeta(accounts.optionPool),
508
+ getAccountMeta(accounts.optionAccount),
509
+ getAccountMeta(accounts.underlyingMint),
510
+ getAccountMeta(accounts.positionAccount),
511
+ getAccountMeta(accounts.collateralVault),
512
+ getAccountMeta(accounts.buyerPaymentAccount),
513
+ getAccountMeta(accounts.buyerOptionAccount),
514
+ getAccountMeta(accounts.optionMint),
515
+ getAccountMeta(accounts.priceUpdate),
516
+ getAccountMeta(accounts.marketData),
517
+ getAccountMeta(accounts.omlpVault),
518
+ getAccountMeta(accounts.keeper),
519
+ getAccountMeta(accounts.tokenProgram),
520
+ getAccountMeta(accounts.systemProgram),
521
+ ],
522
+ data: getAutoExerciseExpiredInstructionDataEncoder().encode({}),
523
+ programAddress,
524
+ } as AutoExerciseExpiredInstruction<
525
+ TProgramAddress,
526
+ TAccountCollateralPool,
527
+ TAccountOptionPool,
528
+ TAccountOptionAccount,
529
+ TAccountUnderlyingMint,
530
+ TAccountPositionAccount,
531
+ TAccountCollateralVault,
532
+ TAccountBuyerPaymentAccount,
533
+ TAccountBuyerOptionAccount,
534
+ TAccountOptionMint,
535
+ TAccountPriceUpdate,
536
+ TAccountMarketData,
537
+ TAccountOmlpVault,
538
+ TAccountKeeper,
539
+ TAccountTokenProgram,
540
+ TAccountSystemProgram
541
+ >);
542
+ }
543
+
544
+ export type ParsedAutoExerciseExpiredInstruction<
545
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
546
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
547
+ > = {
548
+ programAddress: Address<TProgram>;
549
+ accounts: {
550
+ collateralPool: TAccountMetas[0];
551
+ optionPool: TAccountMetas[1];
552
+ optionAccount: TAccountMetas[2];
553
+ /** Underlying token mint (for dynamic decimal handling - supports any SPL token) */
554
+ underlyingMint: TAccountMetas[3];
555
+ /**
556
+ * Buyer's position (tracks quantity owned)
557
+ * Note: NO signer constraint - keeper exercises on behalf of buyer
558
+ */
559
+ positionAccount: TAccountMetas[4];
560
+ /** Pool's collateral vault (source of payout) */
561
+ collateralVault: TAccountMetas[5];
562
+ /** Buyer's WSOL account (receives intrinsic value) */
563
+ buyerPaymentAccount: TAccountMetas[6];
564
+ /** Buyer's option token account (burns tokens) */
565
+ buyerOptionAccount: TAccountMetas[7];
566
+ /** Option mint (for burning) */
567
+ optionMint: TAccountMetas[8];
568
+ /** Pyth price update account (ownership validated by Anchor) */
569
+ priceUpdate: TAccountMetas[9];
570
+ /** Market data for this underlying asset (contains pyth_feed_id) */
571
+ marketData: TAccountMetas[10];
572
+ /** OMLP Vault token account to receive repayments */
573
+ omlpVault: TAccountMetas[11];
574
+ /** Keeper who pays for gas - anyone can call this after expiration */
575
+ keeper: TAccountMetas[12];
576
+ tokenProgram: TAccountMetas[13];
577
+ systemProgram: TAccountMetas[14];
578
+ };
579
+ data: AutoExerciseExpiredInstructionData;
580
+ };
581
+
582
+ export function parseAutoExerciseExpiredInstruction<
583
+ TProgram extends string,
584
+ TAccountMetas extends readonly AccountMeta[],
585
+ >(
586
+ instruction: Instruction<TProgram> &
587
+ InstructionWithAccounts<TAccountMetas> &
588
+ InstructionWithData<ReadonlyUint8Array>,
589
+ ): ParsedAutoExerciseExpiredInstruction<TProgram, TAccountMetas> {
590
+ if (instruction.accounts.length < 15) {
591
+ // TODO: Coded error.
592
+ throw new Error("Not enough accounts");
593
+ }
594
+ let accountIndex = 0;
595
+ const getNextAccount = () => {
596
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
597
+ accountIndex += 1;
598
+ return accountMeta;
599
+ };
600
+ return {
601
+ programAddress: instruction.programAddress,
602
+ accounts: {
603
+ collateralPool: getNextAccount(),
604
+ optionPool: getNextAccount(),
605
+ optionAccount: getNextAccount(),
606
+ underlyingMint: getNextAccount(),
607
+ positionAccount: getNextAccount(),
608
+ collateralVault: getNextAccount(),
609
+ buyerPaymentAccount: getNextAccount(),
610
+ buyerOptionAccount: getNextAccount(),
611
+ optionMint: getNextAccount(),
612
+ priceUpdate: getNextAccount(),
613
+ marketData: getNextAccount(),
614
+ omlpVault: getNextAccount(),
615
+ keeper: getNextAccount(),
616
+ tokenProgram: getNextAccount(),
617
+ systemProgram: getNextAccount(),
618
+ },
619
+ data: getAutoExerciseExpiredInstructionDataDecoder().decode(
620
+ instruction.data,
621
+ ),
622
+ };
623
+ }