@epicentral/sos-sdk 0.9.0-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.
Files changed (113) hide show
  1. package/.env.example +1 -0
  2. package/AGENTS.md +7 -0
  3. package/LICENSE +21 -0
  4. package/README.md +568 -0
  5. package/accounts/fetchers.ts +196 -0
  6. package/accounts/list.ts +184 -0
  7. package/accounts/pdas.ts +325 -0
  8. package/accounts/resolve-option.ts +104 -0
  9. package/client/lookup-table.ts +114 -0
  10. package/client/program.ts +13 -0
  11. package/client/types.ts +9 -0
  12. package/generated/accounts/collateralPool.ts +217 -0
  13. package/generated/accounts/config.ts +156 -0
  14. package/generated/accounts/escrowState.ts +183 -0
  15. package/generated/accounts/index.ts +20 -0
  16. package/generated/accounts/lenderPosition.ts +211 -0
  17. package/generated/accounts/makerCollateralShare.ts +229 -0
  18. package/generated/accounts/marketDataAccount.ts +176 -0
  19. package/generated/accounts/optionAccount.ts +247 -0
  20. package/generated/accounts/optionPool.ts +285 -0
  21. package/generated/accounts/poolLoan.ts +232 -0
  22. package/generated/accounts/positionAccount.ts +201 -0
  23. package/generated/accounts/vault.ts +366 -0
  24. package/generated/accounts/writerPosition.ts +327 -0
  25. package/generated/errors/index.ts +9 -0
  26. package/generated/errors/optionProgram.ts +476 -0
  27. package/generated/index.ts +13 -0
  28. package/generated/instructions/acceptAdmin.ts +230 -0
  29. package/generated/instructions/autoExerciseAllExpired.ts +685 -0
  30. package/generated/instructions/autoExerciseExpired.ts +754 -0
  31. package/generated/instructions/borrowFromPool.ts +619 -0
  32. package/generated/instructions/buyFromPool.ts +761 -0
  33. package/generated/instructions/closeLongToPool.ts +762 -0
  34. package/generated/instructions/closeOption.ts +235 -0
  35. package/generated/instructions/createEscrowV2.ts +518 -0
  36. package/generated/instructions/depositCollateral.ts +624 -0
  37. package/generated/instructions/depositToPosition.ts +429 -0
  38. package/generated/instructions/index.ts +47 -0
  39. package/generated/instructions/initCollateralPool.ts +513 -0
  40. package/generated/instructions/initConfig.ts +279 -0
  41. package/generated/instructions/initOptionPool.ts +587 -0
  42. package/generated/instructions/initializeMarketData.ts +359 -0
  43. package/generated/instructions/liquidateWriterPosition.ts +750 -0
  44. package/generated/instructions/liquidateWriterPositionRescue.ts +623 -0
  45. package/generated/instructions/omlpCreateVault.ts +553 -0
  46. package/generated/instructions/omlpUpdateFeeWallet.ts +473 -0
  47. package/generated/instructions/omlpUpdateInterestModel.ts +322 -0
  48. package/generated/instructions/omlpUpdateLiquidationThreshold.ts +304 -0
  49. package/generated/instructions/omlpUpdateMaintenanceBuffer.ts +304 -0
  50. package/generated/instructions/omlpUpdateMaxBorrowCap.ts +304 -0
  51. package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
  52. package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
  53. package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
  54. package/generated/instructions/optionExercise.ts +617 -0
  55. package/generated/instructions/optionMint.ts +1373 -0
  56. package/generated/instructions/optionValidate.ts +302 -0
  57. package/generated/instructions/repayPoolLoan.ts +558 -0
  58. package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
  59. package/generated/instructions/repayPoolLoanFromWallet.ts +542 -0
  60. package/generated/instructions/settleMakerCollateral.ts +509 -0
  61. package/generated/instructions/syncWriterPosition.ts +206 -0
  62. package/generated/instructions/transferAdmin.ts +245 -0
  63. package/generated/instructions/unwindWriterUnsold.ts +764 -0
  64. package/generated/instructions/updateImpliedVolatility.ts +226 -0
  65. package/generated/instructions/updateMarketData.ts +315 -0
  66. package/generated/instructions/withdrawFromPosition.ts +405 -0
  67. package/generated/instructions/writeToPool.ts +619 -0
  68. package/generated/programs/index.ts +9 -0
  69. package/generated/programs/optionProgram.ts +1144 -0
  70. package/generated/shared/index.ts +164 -0
  71. package/generated/types/impliedVolatilityUpdated.ts +73 -0
  72. package/generated/types/index.ts +28 -0
  73. package/generated/types/liquidationExecuted.ts +73 -0
  74. package/generated/types/liquidationRescueEvent.ts +82 -0
  75. package/generated/types/marketDataInitialized.ts +61 -0
  76. package/generated/types/marketDataUpdated.ts +69 -0
  77. package/generated/types/optionClosed.ts +56 -0
  78. package/generated/types/optionExercised.ts +62 -0
  79. package/generated/types/optionExpired.ts +49 -0
  80. package/generated/types/optionMinted.ts +78 -0
  81. package/generated/types/optionType.ts +38 -0
  82. package/generated/types/optionValidated.ts +82 -0
  83. package/generated/types/poolLoanCreated.ts +74 -0
  84. package/generated/types/poolLoanRepaid.ts +74 -0
  85. package/generated/types/positionDeposited.ts +73 -0
  86. package/generated/types/positionWithdrawn.ts +81 -0
  87. package/generated/types/protocolFeeUpdated.ts +69 -0
  88. package/generated/types/vaultCreated.ts +60 -0
  89. package/generated/types/vaultFeeWalletUpdated.ts +67 -0
  90. package/generated/types/vaultInterestModelUpdated.ts +77 -0
  91. package/generated/types/vaultLiquidationThresholdUpdated.ts +69 -0
  92. package/index.ts +68 -0
  93. package/long/builders.ts +690 -0
  94. package/long/exercise.ts +123 -0
  95. package/long/preflight.ts +214 -0
  96. package/long/quotes.ts +48 -0
  97. package/long/remaining-accounts.ts +111 -0
  98. package/omlp/builders.ts +94 -0
  99. package/omlp/service.ts +136 -0
  100. package/oracle/switchboard.ts +315 -0
  101. package/package.json +34 -0
  102. package/shared/amounts.ts +53 -0
  103. package/shared/balances.ts +57 -0
  104. package/shared/errors.ts +12 -0
  105. package/shared/remaining-accounts.ts +41 -0
  106. package/shared/trade-config.ts +27 -0
  107. package/shared/transactions.ts +121 -0
  108. package/short/builders.ts +874 -0
  109. package/short/close-option.ts +34 -0
  110. package/short/pool.ts +189 -0
  111. package/short/preflight.ts +619 -0
  112. package/tsconfig.json +13 -0
  113. package/wsol/instructions.ts +247 -0
@@ -0,0 +1,754 @@
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
+ TAccountSwitchboardQueue extends string | AccountMeta<string> = string,
64
+ TAccountSlotHashesSysvar extends string | AccountMeta<string> =
65
+ "SysvarS1otHashes111111111111111111111111111",
66
+ TAccountInstructionsSysvar extends string | AccountMeta<string> =
67
+ "Sysvar1nstructions1111111111111111111111111",
68
+ TAccountMarketData extends string | AccountMeta<string> = string,
69
+ TAccountOmlpVault extends string | AccountMeta<string> = string,
70
+ TAccountOmlpVaultState extends string | AccountMeta<string> = string,
71
+ TAccountKeeper extends string | AccountMeta<string> = string,
72
+ TAccountTokenProgram extends string | AccountMeta<string> =
73
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
74
+ TAccountSystemProgram extends string | AccountMeta<string> =
75
+ "11111111111111111111111111111111",
76
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
77
+ > = Instruction<TProgram> &
78
+ InstructionWithData<ReadonlyUint8Array> &
79
+ InstructionWithAccounts<
80
+ [
81
+ TAccountCollateralPool extends string
82
+ ? WritableAccount<TAccountCollateralPool>
83
+ : TAccountCollateralPool,
84
+ TAccountOptionPool extends string
85
+ ? WritableAccount<TAccountOptionPool>
86
+ : TAccountOptionPool,
87
+ TAccountOptionAccount extends string
88
+ ? WritableAccount<TAccountOptionAccount>
89
+ : TAccountOptionAccount,
90
+ TAccountUnderlyingMint extends string
91
+ ? ReadonlyAccount<TAccountUnderlyingMint>
92
+ : TAccountUnderlyingMint,
93
+ TAccountPositionAccount extends string
94
+ ? WritableAccount<TAccountPositionAccount>
95
+ : TAccountPositionAccount,
96
+ TAccountCollateralVault extends string
97
+ ? WritableAccount<TAccountCollateralVault>
98
+ : TAccountCollateralVault,
99
+ TAccountBuyerPaymentAccount extends string
100
+ ? WritableAccount<TAccountBuyerPaymentAccount>
101
+ : TAccountBuyerPaymentAccount,
102
+ TAccountBuyerOptionAccount extends string
103
+ ? WritableAccount<TAccountBuyerOptionAccount>
104
+ : TAccountBuyerOptionAccount,
105
+ TAccountOptionMint extends string
106
+ ? WritableAccount<TAccountOptionMint>
107
+ : TAccountOptionMint,
108
+ TAccountSwitchboardQueue extends string
109
+ ? ReadonlyAccount<TAccountSwitchboardQueue>
110
+ : TAccountSwitchboardQueue,
111
+ TAccountSlotHashesSysvar extends string
112
+ ? ReadonlyAccount<TAccountSlotHashesSysvar>
113
+ : TAccountSlotHashesSysvar,
114
+ TAccountInstructionsSysvar extends string
115
+ ? ReadonlyAccount<TAccountInstructionsSysvar>
116
+ : TAccountInstructionsSysvar,
117
+ TAccountMarketData extends string
118
+ ? ReadonlyAccount<TAccountMarketData>
119
+ : TAccountMarketData,
120
+ TAccountOmlpVault extends string
121
+ ? WritableAccount<TAccountOmlpVault>
122
+ : TAccountOmlpVault,
123
+ TAccountOmlpVaultState extends string
124
+ ? WritableAccount<TAccountOmlpVaultState>
125
+ : TAccountOmlpVaultState,
126
+ TAccountKeeper extends string
127
+ ? WritableSignerAccount<TAccountKeeper> &
128
+ AccountSignerMeta<TAccountKeeper>
129
+ : TAccountKeeper,
130
+ TAccountTokenProgram extends string
131
+ ? ReadonlyAccount<TAccountTokenProgram>
132
+ : TAccountTokenProgram,
133
+ TAccountSystemProgram extends string
134
+ ? ReadonlyAccount<TAccountSystemProgram>
135
+ : TAccountSystemProgram,
136
+ ...TRemainingAccounts,
137
+ ]
138
+ >;
139
+
140
+ export type AutoExerciseExpiredInstructionData = {
141
+ discriminator: ReadonlyUint8Array;
142
+ };
143
+
144
+ export type AutoExerciseExpiredInstructionDataArgs = {};
145
+
146
+ export function getAutoExerciseExpiredInstructionDataEncoder(): FixedSizeEncoder<AutoExerciseExpiredInstructionDataArgs> {
147
+ return transformEncoder(
148
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
149
+ (value) => ({
150
+ ...value,
151
+ discriminator: AUTO_EXERCISE_EXPIRED_DISCRIMINATOR,
152
+ }),
153
+ );
154
+ }
155
+
156
+ export function getAutoExerciseExpiredInstructionDataDecoder(): FixedSizeDecoder<AutoExerciseExpiredInstructionData> {
157
+ return getStructDecoder([
158
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
159
+ ]);
160
+ }
161
+
162
+ export function getAutoExerciseExpiredInstructionDataCodec(): FixedSizeCodec<
163
+ AutoExerciseExpiredInstructionDataArgs,
164
+ AutoExerciseExpiredInstructionData
165
+ > {
166
+ return combineCodec(
167
+ getAutoExerciseExpiredInstructionDataEncoder(),
168
+ getAutoExerciseExpiredInstructionDataDecoder(),
169
+ );
170
+ }
171
+
172
+ export type AutoExerciseExpiredAsyncInput<
173
+ TAccountCollateralPool extends string = string,
174
+ TAccountOptionPool extends string = string,
175
+ TAccountOptionAccount extends string = string,
176
+ TAccountUnderlyingMint extends string = string,
177
+ TAccountPositionAccount extends string = string,
178
+ TAccountCollateralVault extends string = string,
179
+ TAccountBuyerPaymentAccount extends string = string,
180
+ TAccountBuyerOptionAccount extends string = string,
181
+ TAccountOptionMint extends string = string,
182
+ TAccountSwitchboardQueue extends string = string,
183
+ TAccountSlotHashesSysvar extends string = string,
184
+ TAccountInstructionsSysvar extends string = string,
185
+ TAccountMarketData extends string = string,
186
+ TAccountOmlpVault extends string = string,
187
+ TAccountOmlpVaultState extends string = string,
188
+ TAccountKeeper extends string = string,
189
+ TAccountTokenProgram extends string = string,
190
+ TAccountSystemProgram extends string = string,
191
+ > = {
192
+ collateralPool?: Address<TAccountCollateralPool>;
193
+ optionPool: Address<TAccountOptionPool>;
194
+ optionAccount: Address<TAccountOptionAccount>;
195
+ /** Underlying token mint (for dynamic decimal handling - supports any SPL token) */
196
+ underlyingMint: Address<TAccountUnderlyingMint>;
197
+ /**
198
+ * Buyer's position (tracks quantity owned)
199
+ * Note: NO signer constraint - keeper exercises on behalf of buyer
200
+ */
201
+ positionAccount: Address<TAccountPositionAccount>;
202
+ /** Pool's collateral vault (source of payout) */
203
+ collateralVault: Address<TAccountCollateralVault>;
204
+ /** Buyer's WSOL account (receives intrinsic value) */
205
+ buyerPaymentAccount: Address<TAccountBuyerPaymentAccount>;
206
+ /** Buyer's option token account (burns tokens) */
207
+ buyerOptionAccount: Address<TAccountBuyerOptionAccount>;
208
+ /** Option mint (for burning) */
209
+ optionMint: Address<TAccountOptionMint>;
210
+ switchboardQueue: Address<TAccountSwitchboardQueue>;
211
+ slotHashesSysvar?: Address<TAccountSlotHashesSysvar>;
212
+ instructionsSysvar?: Address<TAccountInstructionsSysvar>;
213
+ /** Market data for this underlying asset (contains switchboard_feed_id) */
214
+ marketData: Address<TAccountMarketData>;
215
+ /** OMLP Vault token account to receive repayments */
216
+ omlpVault: Address<TAccountOmlpVault>;
217
+ /**
218
+ * OMLP Vault state PDA (mut: keeps `total_loans`, `total_liquidity`,
219
+ * and `acc_interest_per_share_fp` consistent via `add_interest_to_index`
220
+ * so auto-exercised lender repayments actually realize interest to LPs).
221
+ * Constrained to the vault matching `underlying_mint` — same mint the
222
+ * collateral vault settles in.
223
+ */
224
+ omlpVaultState?: Address<TAccountOmlpVaultState>;
225
+ /** Keeper who pays for gas - anyone can call this after expiration */
226
+ keeper: TransactionSigner<TAccountKeeper>;
227
+ tokenProgram?: Address<TAccountTokenProgram>;
228
+ systemProgram?: Address<TAccountSystemProgram>;
229
+ };
230
+
231
+ export async function getAutoExerciseExpiredInstructionAsync<
232
+ TAccountCollateralPool extends string,
233
+ TAccountOptionPool extends string,
234
+ TAccountOptionAccount extends string,
235
+ TAccountUnderlyingMint extends string,
236
+ TAccountPositionAccount extends string,
237
+ TAccountCollateralVault extends string,
238
+ TAccountBuyerPaymentAccount extends string,
239
+ TAccountBuyerOptionAccount extends string,
240
+ TAccountOptionMint extends string,
241
+ TAccountSwitchboardQueue extends string,
242
+ TAccountSlotHashesSysvar extends string,
243
+ TAccountInstructionsSysvar extends string,
244
+ TAccountMarketData extends string,
245
+ TAccountOmlpVault extends string,
246
+ TAccountOmlpVaultState extends string,
247
+ TAccountKeeper extends string,
248
+ TAccountTokenProgram extends string,
249
+ TAccountSystemProgram extends string,
250
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
251
+ >(
252
+ input: AutoExerciseExpiredAsyncInput<
253
+ TAccountCollateralPool,
254
+ TAccountOptionPool,
255
+ TAccountOptionAccount,
256
+ TAccountUnderlyingMint,
257
+ TAccountPositionAccount,
258
+ TAccountCollateralVault,
259
+ TAccountBuyerPaymentAccount,
260
+ TAccountBuyerOptionAccount,
261
+ TAccountOptionMint,
262
+ TAccountSwitchboardQueue,
263
+ TAccountSlotHashesSysvar,
264
+ TAccountInstructionsSysvar,
265
+ TAccountMarketData,
266
+ TAccountOmlpVault,
267
+ TAccountOmlpVaultState,
268
+ TAccountKeeper,
269
+ TAccountTokenProgram,
270
+ TAccountSystemProgram
271
+ >,
272
+ config?: { programAddress?: TProgramAddress },
273
+ ): Promise<
274
+ AutoExerciseExpiredInstruction<
275
+ TProgramAddress,
276
+ TAccountCollateralPool,
277
+ TAccountOptionPool,
278
+ TAccountOptionAccount,
279
+ TAccountUnderlyingMint,
280
+ TAccountPositionAccount,
281
+ TAccountCollateralVault,
282
+ TAccountBuyerPaymentAccount,
283
+ TAccountBuyerOptionAccount,
284
+ TAccountOptionMint,
285
+ TAccountSwitchboardQueue,
286
+ TAccountSlotHashesSysvar,
287
+ TAccountInstructionsSysvar,
288
+ TAccountMarketData,
289
+ TAccountOmlpVault,
290
+ TAccountOmlpVaultState,
291
+ TAccountKeeper,
292
+ TAccountTokenProgram,
293
+ TAccountSystemProgram
294
+ >
295
+ > {
296
+ // Program address.
297
+ const programAddress =
298
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
299
+
300
+ // Original accounts.
301
+ const originalAccounts = {
302
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
303
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
304
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
305
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
306
+ positionAccount: { value: input.positionAccount ?? null, isWritable: true },
307
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
308
+ buyerPaymentAccount: {
309
+ value: input.buyerPaymentAccount ?? null,
310
+ isWritable: true,
311
+ },
312
+ buyerOptionAccount: {
313
+ value: input.buyerOptionAccount ?? null,
314
+ isWritable: true,
315
+ },
316
+ optionMint: { value: input.optionMint ?? null, isWritable: true },
317
+ switchboardQueue: {
318
+ value: input.switchboardQueue ?? null,
319
+ isWritable: false,
320
+ },
321
+ slotHashesSysvar: {
322
+ value: input.slotHashesSysvar ?? null,
323
+ isWritable: false,
324
+ },
325
+ instructionsSysvar: {
326
+ value: input.instructionsSysvar ?? null,
327
+ isWritable: false,
328
+ },
329
+ marketData: { value: input.marketData ?? null, isWritable: false },
330
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
331
+ omlpVaultState: { value: input.omlpVaultState ?? null, isWritable: true },
332
+ keeper: { value: input.keeper ?? null, isWritable: true },
333
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
334
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
335
+ };
336
+ const accounts = originalAccounts as Record<
337
+ keyof typeof originalAccounts,
338
+ ResolvedAccount
339
+ >;
340
+
341
+ // Resolve default values.
342
+ if (!accounts.collateralPool.value) {
343
+ accounts.collateralPool.value = await getProgramDerivedAddress({
344
+ programAddress,
345
+ seeds: [
346
+ getBytesEncoder().encode(
347
+ new Uint8Array([
348
+ 99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
349
+ 108,
350
+ ]),
351
+ ),
352
+ getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
353
+ ],
354
+ });
355
+ }
356
+ if (!accounts.slotHashesSysvar.value) {
357
+ accounts.slotHashesSysvar.value =
358
+ "SysvarS1otHashes111111111111111111111111111" as Address<"SysvarS1otHashes111111111111111111111111111">;
359
+ }
360
+ if (!accounts.instructionsSysvar.value) {
361
+ accounts.instructionsSysvar.value =
362
+ "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">;
363
+ }
364
+ if (!accounts.omlpVaultState.value) {
365
+ accounts.omlpVaultState.value = await getProgramDerivedAddress({
366
+ programAddress,
367
+ seeds: [
368
+ getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
369
+ getAddressEncoder().encode(
370
+ expectAddress(accounts.underlyingMint.value),
371
+ ),
372
+ ],
373
+ });
374
+ }
375
+ if (!accounts.tokenProgram.value) {
376
+ accounts.tokenProgram.value =
377
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
378
+ }
379
+ if (!accounts.systemProgram.value) {
380
+ accounts.systemProgram.value =
381
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
382
+ }
383
+
384
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
385
+ return Object.freeze({
386
+ accounts: [
387
+ getAccountMeta(accounts.collateralPool),
388
+ getAccountMeta(accounts.optionPool),
389
+ getAccountMeta(accounts.optionAccount),
390
+ getAccountMeta(accounts.underlyingMint),
391
+ getAccountMeta(accounts.positionAccount),
392
+ getAccountMeta(accounts.collateralVault),
393
+ getAccountMeta(accounts.buyerPaymentAccount),
394
+ getAccountMeta(accounts.buyerOptionAccount),
395
+ getAccountMeta(accounts.optionMint),
396
+ getAccountMeta(accounts.switchboardQueue),
397
+ getAccountMeta(accounts.slotHashesSysvar),
398
+ getAccountMeta(accounts.instructionsSysvar),
399
+ getAccountMeta(accounts.marketData),
400
+ getAccountMeta(accounts.omlpVault),
401
+ getAccountMeta(accounts.omlpVaultState),
402
+ getAccountMeta(accounts.keeper),
403
+ getAccountMeta(accounts.tokenProgram),
404
+ getAccountMeta(accounts.systemProgram),
405
+ ],
406
+ data: getAutoExerciseExpiredInstructionDataEncoder().encode({}),
407
+ programAddress,
408
+ } as AutoExerciseExpiredInstruction<
409
+ TProgramAddress,
410
+ TAccountCollateralPool,
411
+ TAccountOptionPool,
412
+ TAccountOptionAccount,
413
+ TAccountUnderlyingMint,
414
+ TAccountPositionAccount,
415
+ TAccountCollateralVault,
416
+ TAccountBuyerPaymentAccount,
417
+ TAccountBuyerOptionAccount,
418
+ TAccountOptionMint,
419
+ TAccountSwitchboardQueue,
420
+ TAccountSlotHashesSysvar,
421
+ TAccountInstructionsSysvar,
422
+ TAccountMarketData,
423
+ TAccountOmlpVault,
424
+ TAccountOmlpVaultState,
425
+ TAccountKeeper,
426
+ TAccountTokenProgram,
427
+ TAccountSystemProgram
428
+ >);
429
+ }
430
+
431
+ export type AutoExerciseExpiredInput<
432
+ TAccountCollateralPool extends string = string,
433
+ TAccountOptionPool extends string = string,
434
+ TAccountOptionAccount extends string = string,
435
+ TAccountUnderlyingMint extends string = string,
436
+ TAccountPositionAccount extends string = string,
437
+ TAccountCollateralVault extends string = string,
438
+ TAccountBuyerPaymentAccount extends string = string,
439
+ TAccountBuyerOptionAccount extends string = string,
440
+ TAccountOptionMint extends string = string,
441
+ TAccountSwitchboardQueue extends string = string,
442
+ TAccountSlotHashesSysvar extends string = string,
443
+ TAccountInstructionsSysvar extends string = string,
444
+ TAccountMarketData extends string = string,
445
+ TAccountOmlpVault extends string = string,
446
+ TAccountOmlpVaultState extends string = string,
447
+ TAccountKeeper extends string = string,
448
+ TAccountTokenProgram extends string = string,
449
+ TAccountSystemProgram extends string = string,
450
+ > = {
451
+ collateralPool: Address<TAccountCollateralPool>;
452
+ optionPool: Address<TAccountOptionPool>;
453
+ optionAccount: Address<TAccountOptionAccount>;
454
+ /** Underlying token mint (for dynamic decimal handling - supports any SPL token) */
455
+ underlyingMint: Address<TAccountUnderlyingMint>;
456
+ /**
457
+ * Buyer's position (tracks quantity owned)
458
+ * Note: NO signer constraint - keeper exercises on behalf of buyer
459
+ */
460
+ positionAccount: Address<TAccountPositionAccount>;
461
+ /** Pool's collateral vault (source of payout) */
462
+ collateralVault: Address<TAccountCollateralVault>;
463
+ /** Buyer's WSOL account (receives intrinsic value) */
464
+ buyerPaymentAccount: Address<TAccountBuyerPaymentAccount>;
465
+ /** Buyer's option token account (burns tokens) */
466
+ buyerOptionAccount: Address<TAccountBuyerOptionAccount>;
467
+ /** Option mint (for burning) */
468
+ optionMint: Address<TAccountOptionMint>;
469
+ switchboardQueue: Address<TAccountSwitchboardQueue>;
470
+ slotHashesSysvar?: Address<TAccountSlotHashesSysvar>;
471
+ instructionsSysvar?: Address<TAccountInstructionsSysvar>;
472
+ /** Market data for this underlying asset (contains switchboard_feed_id) */
473
+ marketData: Address<TAccountMarketData>;
474
+ /** OMLP Vault token account to receive repayments */
475
+ omlpVault: Address<TAccountOmlpVault>;
476
+ /**
477
+ * OMLP Vault state PDA (mut: keeps `total_loans`, `total_liquidity`,
478
+ * and `acc_interest_per_share_fp` consistent via `add_interest_to_index`
479
+ * so auto-exercised lender repayments actually realize interest to LPs).
480
+ * Constrained to the vault matching `underlying_mint` — same mint the
481
+ * collateral vault settles in.
482
+ */
483
+ omlpVaultState: Address<TAccountOmlpVaultState>;
484
+ /** Keeper who pays for gas - anyone can call this after expiration */
485
+ keeper: TransactionSigner<TAccountKeeper>;
486
+ tokenProgram?: Address<TAccountTokenProgram>;
487
+ systemProgram?: Address<TAccountSystemProgram>;
488
+ };
489
+
490
+ export function getAutoExerciseExpiredInstruction<
491
+ TAccountCollateralPool extends string,
492
+ TAccountOptionPool extends string,
493
+ TAccountOptionAccount extends string,
494
+ TAccountUnderlyingMint extends string,
495
+ TAccountPositionAccount extends string,
496
+ TAccountCollateralVault extends string,
497
+ TAccountBuyerPaymentAccount extends string,
498
+ TAccountBuyerOptionAccount extends string,
499
+ TAccountOptionMint extends string,
500
+ TAccountSwitchboardQueue extends string,
501
+ TAccountSlotHashesSysvar extends string,
502
+ TAccountInstructionsSysvar extends string,
503
+ TAccountMarketData extends string,
504
+ TAccountOmlpVault extends string,
505
+ TAccountOmlpVaultState extends string,
506
+ TAccountKeeper extends string,
507
+ TAccountTokenProgram extends string,
508
+ TAccountSystemProgram extends string,
509
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
510
+ >(
511
+ input: AutoExerciseExpiredInput<
512
+ TAccountCollateralPool,
513
+ TAccountOptionPool,
514
+ TAccountOptionAccount,
515
+ TAccountUnderlyingMint,
516
+ TAccountPositionAccount,
517
+ TAccountCollateralVault,
518
+ TAccountBuyerPaymentAccount,
519
+ TAccountBuyerOptionAccount,
520
+ TAccountOptionMint,
521
+ TAccountSwitchboardQueue,
522
+ TAccountSlotHashesSysvar,
523
+ TAccountInstructionsSysvar,
524
+ TAccountMarketData,
525
+ TAccountOmlpVault,
526
+ TAccountOmlpVaultState,
527
+ TAccountKeeper,
528
+ TAccountTokenProgram,
529
+ TAccountSystemProgram
530
+ >,
531
+ config?: { programAddress?: TProgramAddress },
532
+ ): AutoExerciseExpiredInstruction<
533
+ TProgramAddress,
534
+ TAccountCollateralPool,
535
+ TAccountOptionPool,
536
+ TAccountOptionAccount,
537
+ TAccountUnderlyingMint,
538
+ TAccountPositionAccount,
539
+ TAccountCollateralVault,
540
+ TAccountBuyerPaymentAccount,
541
+ TAccountBuyerOptionAccount,
542
+ TAccountOptionMint,
543
+ TAccountSwitchboardQueue,
544
+ TAccountSlotHashesSysvar,
545
+ TAccountInstructionsSysvar,
546
+ TAccountMarketData,
547
+ TAccountOmlpVault,
548
+ TAccountOmlpVaultState,
549
+ TAccountKeeper,
550
+ TAccountTokenProgram,
551
+ TAccountSystemProgram
552
+ > {
553
+ // Program address.
554
+ const programAddress =
555
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
556
+
557
+ // Original accounts.
558
+ const originalAccounts = {
559
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
560
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
561
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
562
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
563
+ positionAccount: { value: input.positionAccount ?? null, isWritable: true },
564
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
565
+ buyerPaymentAccount: {
566
+ value: input.buyerPaymentAccount ?? null,
567
+ isWritable: true,
568
+ },
569
+ buyerOptionAccount: {
570
+ value: input.buyerOptionAccount ?? null,
571
+ isWritable: true,
572
+ },
573
+ optionMint: { value: input.optionMint ?? null, isWritable: true },
574
+ switchboardQueue: {
575
+ value: input.switchboardQueue ?? null,
576
+ isWritable: false,
577
+ },
578
+ slotHashesSysvar: {
579
+ value: input.slotHashesSysvar ?? null,
580
+ isWritable: false,
581
+ },
582
+ instructionsSysvar: {
583
+ value: input.instructionsSysvar ?? null,
584
+ isWritable: false,
585
+ },
586
+ marketData: { value: input.marketData ?? null, isWritable: false },
587
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
588
+ omlpVaultState: { value: input.omlpVaultState ?? null, isWritable: true },
589
+ keeper: { value: input.keeper ?? null, isWritable: true },
590
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
591
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
592
+ };
593
+ const accounts = originalAccounts as Record<
594
+ keyof typeof originalAccounts,
595
+ ResolvedAccount
596
+ >;
597
+
598
+ // Resolve default values.
599
+ if (!accounts.slotHashesSysvar.value) {
600
+ accounts.slotHashesSysvar.value =
601
+ "SysvarS1otHashes111111111111111111111111111" as Address<"SysvarS1otHashes111111111111111111111111111">;
602
+ }
603
+ if (!accounts.instructionsSysvar.value) {
604
+ accounts.instructionsSysvar.value =
605
+ "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">;
606
+ }
607
+ if (!accounts.tokenProgram.value) {
608
+ accounts.tokenProgram.value =
609
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
610
+ }
611
+ if (!accounts.systemProgram.value) {
612
+ accounts.systemProgram.value =
613
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
614
+ }
615
+
616
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
617
+ return Object.freeze({
618
+ accounts: [
619
+ getAccountMeta(accounts.collateralPool),
620
+ getAccountMeta(accounts.optionPool),
621
+ getAccountMeta(accounts.optionAccount),
622
+ getAccountMeta(accounts.underlyingMint),
623
+ getAccountMeta(accounts.positionAccount),
624
+ getAccountMeta(accounts.collateralVault),
625
+ getAccountMeta(accounts.buyerPaymentAccount),
626
+ getAccountMeta(accounts.buyerOptionAccount),
627
+ getAccountMeta(accounts.optionMint),
628
+ getAccountMeta(accounts.switchboardQueue),
629
+ getAccountMeta(accounts.slotHashesSysvar),
630
+ getAccountMeta(accounts.instructionsSysvar),
631
+ getAccountMeta(accounts.marketData),
632
+ getAccountMeta(accounts.omlpVault),
633
+ getAccountMeta(accounts.omlpVaultState),
634
+ getAccountMeta(accounts.keeper),
635
+ getAccountMeta(accounts.tokenProgram),
636
+ getAccountMeta(accounts.systemProgram),
637
+ ],
638
+ data: getAutoExerciseExpiredInstructionDataEncoder().encode({}),
639
+ programAddress,
640
+ } as AutoExerciseExpiredInstruction<
641
+ TProgramAddress,
642
+ TAccountCollateralPool,
643
+ TAccountOptionPool,
644
+ TAccountOptionAccount,
645
+ TAccountUnderlyingMint,
646
+ TAccountPositionAccount,
647
+ TAccountCollateralVault,
648
+ TAccountBuyerPaymentAccount,
649
+ TAccountBuyerOptionAccount,
650
+ TAccountOptionMint,
651
+ TAccountSwitchboardQueue,
652
+ TAccountSlotHashesSysvar,
653
+ TAccountInstructionsSysvar,
654
+ TAccountMarketData,
655
+ TAccountOmlpVault,
656
+ TAccountOmlpVaultState,
657
+ TAccountKeeper,
658
+ TAccountTokenProgram,
659
+ TAccountSystemProgram
660
+ >);
661
+ }
662
+
663
+ export type ParsedAutoExerciseExpiredInstruction<
664
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
665
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
666
+ > = {
667
+ programAddress: Address<TProgram>;
668
+ accounts: {
669
+ collateralPool: TAccountMetas[0];
670
+ optionPool: TAccountMetas[1];
671
+ optionAccount: TAccountMetas[2];
672
+ /** Underlying token mint (for dynamic decimal handling - supports any SPL token) */
673
+ underlyingMint: TAccountMetas[3];
674
+ /**
675
+ * Buyer's position (tracks quantity owned)
676
+ * Note: NO signer constraint - keeper exercises on behalf of buyer
677
+ */
678
+ positionAccount: TAccountMetas[4];
679
+ /** Pool's collateral vault (source of payout) */
680
+ collateralVault: TAccountMetas[5];
681
+ /** Buyer's WSOL account (receives intrinsic value) */
682
+ buyerPaymentAccount: TAccountMetas[6];
683
+ /** Buyer's option token account (burns tokens) */
684
+ buyerOptionAccount: TAccountMetas[7];
685
+ /** Option mint (for burning) */
686
+ optionMint: TAccountMetas[8];
687
+ switchboardQueue: TAccountMetas[9];
688
+ slotHashesSysvar: TAccountMetas[10];
689
+ instructionsSysvar: TAccountMetas[11];
690
+ /** Market data for this underlying asset (contains switchboard_feed_id) */
691
+ marketData: TAccountMetas[12];
692
+ /** OMLP Vault token account to receive repayments */
693
+ omlpVault: TAccountMetas[13];
694
+ /**
695
+ * OMLP Vault state PDA (mut: keeps `total_loans`, `total_liquidity`,
696
+ * and `acc_interest_per_share_fp` consistent via `add_interest_to_index`
697
+ * so auto-exercised lender repayments actually realize interest to LPs).
698
+ * Constrained to the vault matching `underlying_mint` — same mint the
699
+ * collateral vault settles in.
700
+ */
701
+ omlpVaultState: TAccountMetas[14];
702
+ /** Keeper who pays for gas - anyone can call this after expiration */
703
+ keeper: TAccountMetas[15];
704
+ tokenProgram: TAccountMetas[16];
705
+ systemProgram: TAccountMetas[17];
706
+ };
707
+ data: AutoExerciseExpiredInstructionData;
708
+ };
709
+
710
+ export function parseAutoExerciseExpiredInstruction<
711
+ TProgram extends string,
712
+ TAccountMetas extends readonly AccountMeta[],
713
+ >(
714
+ instruction: Instruction<TProgram> &
715
+ InstructionWithAccounts<TAccountMetas> &
716
+ InstructionWithData<ReadonlyUint8Array>,
717
+ ): ParsedAutoExerciseExpiredInstruction<TProgram, TAccountMetas> {
718
+ if (instruction.accounts.length < 18) {
719
+ // TODO: Coded error.
720
+ throw new Error("Not enough accounts");
721
+ }
722
+ let accountIndex = 0;
723
+ const getNextAccount = () => {
724
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
725
+ accountIndex += 1;
726
+ return accountMeta;
727
+ };
728
+ return {
729
+ programAddress: instruction.programAddress,
730
+ accounts: {
731
+ collateralPool: getNextAccount(),
732
+ optionPool: getNextAccount(),
733
+ optionAccount: getNextAccount(),
734
+ underlyingMint: getNextAccount(),
735
+ positionAccount: getNextAccount(),
736
+ collateralVault: getNextAccount(),
737
+ buyerPaymentAccount: getNextAccount(),
738
+ buyerOptionAccount: getNextAccount(),
739
+ optionMint: getNextAccount(),
740
+ switchboardQueue: getNextAccount(),
741
+ slotHashesSysvar: getNextAccount(),
742
+ instructionsSysvar: getNextAccount(),
743
+ marketData: getNextAccount(),
744
+ omlpVault: getNextAccount(),
745
+ omlpVaultState: getNextAccount(),
746
+ keeper: getNextAccount(),
747
+ tokenProgram: getNextAccount(),
748
+ systemProgram: getNextAccount(),
749
+ },
750
+ data: getAutoExerciseExpiredInstructionDataDecoder().decode(
751
+ instruction.data,
752
+ ),
753
+ };
754
+ }