@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,750 @@
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 LIQUIDATE_WRITER_POSITION_DISCRIMINATOR = new Uint8Array([
43
+ 184, 117, 16, 217, 120, 32, 16, 63,
44
+ ]);
45
+
46
+ export function getLiquidateWriterPositionDiscriminatorBytes() {
47
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
48
+ LIQUIDATE_WRITER_POSITION_DISCRIMINATOR,
49
+ );
50
+ }
51
+
52
+ export type LiquidateWriterPositionInstruction<
53
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
54
+ TAccountOptionPool extends string | AccountMeta<string> = string,
55
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
56
+ TAccountCollateralPool extends string | AccountMeta<string> = string,
57
+ TAccountWriterPosition extends string | AccountMeta<string> = string,
58
+ TAccountLongMint extends string | AccountMeta<string> = string,
59
+ TAccountEscrowLongAccount extends string | AccountMeta<string> = string,
60
+ TAccountOmlpVault extends string | AccountMeta<string> = string,
61
+ TAccountUnderlyingMint extends string | AccountMeta<string> = string,
62
+ TAccountMarketData 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
+ TAccountCollateralVault extends string | AccountMeta<string> = string,
69
+ TAccountPremiumVault extends string | AccountMeta<string> = string,
70
+ TAccountOmlpVaultTokenAccount extends string | AccountMeta<string> = string,
71
+ TAccountFeeWallet extends string | AccountMeta<string> = string,
72
+ TAccountLiquidator extends string | AccountMeta<string> = string,
73
+ TAccountTokenProgram extends string | AccountMeta<string> =
74
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
75
+ TAccountSystemProgram extends string | AccountMeta<string> =
76
+ "11111111111111111111111111111111",
77
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
78
+ > = Instruction<TProgram> &
79
+ InstructionWithData<ReadonlyUint8Array> &
80
+ InstructionWithAccounts<
81
+ [
82
+ TAccountOptionPool extends string
83
+ ? WritableAccount<TAccountOptionPool>
84
+ : TAccountOptionPool,
85
+ TAccountOptionAccount extends string
86
+ ? WritableAccount<TAccountOptionAccount>
87
+ : TAccountOptionAccount,
88
+ TAccountCollateralPool extends string
89
+ ? WritableAccount<TAccountCollateralPool>
90
+ : TAccountCollateralPool,
91
+ TAccountWriterPosition extends string
92
+ ? WritableAccount<TAccountWriterPosition>
93
+ : TAccountWriterPosition,
94
+ TAccountLongMint extends string
95
+ ? WritableAccount<TAccountLongMint>
96
+ : TAccountLongMint,
97
+ TAccountEscrowLongAccount extends string
98
+ ? WritableAccount<TAccountEscrowLongAccount>
99
+ : TAccountEscrowLongAccount,
100
+ TAccountOmlpVault extends string
101
+ ? WritableAccount<TAccountOmlpVault>
102
+ : TAccountOmlpVault,
103
+ TAccountUnderlyingMint extends string
104
+ ? ReadonlyAccount<TAccountUnderlyingMint>
105
+ : TAccountUnderlyingMint,
106
+ TAccountMarketData extends string
107
+ ? ReadonlyAccount<TAccountMarketData>
108
+ : TAccountMarketData,
109
+ TAccountSwitchboardQueue extends string
110
+ ? ReadonlyAccount<TAccountSwitchboardQueue>
111
+ : TAccountSwitchboardQueue,
112
+ TAccountSlotHashesSysvar extends string
113
+ ? ReadonlyAccount<TAccountSlotHashesSysvar>
114
+ : TAccountSlotHashesSysvar,
115
+ TAccountInstructionsSysvar extends string
116
+ ? ReadonlyAccount<TAccountInstructionsSysvar>
117
+ : TAccountInstructionsSysvar,
118
+ TAccountCollateralVault extends string
119
+ ? WritableAccount<TAccountCollateralVault>
120
+ : TAccountCollateralVault,
121
+ TAccountPremiumVault extends string
122
+ ? WritableAccount<TAccountPremiumVault>
123
+ : TAccountPremiumVault,
124
+ TAccountOmlpVaultTokenAccount extends string
125
+ ? WritableAccount<TAccountOmlpVaultTokenAccount>
126
+ : TAccountOmlpVaultTokenAccount,
127
+ TAccountFeeWallet extends string
128
+ ? WritableAccount<TAccountFeeWallet>
129
+ : TAccountFeeWallet,
130
+ TAccountLiquidator extends string
131
+ ? WritableSignerAccount<TAccountLiquidator> &
132
+ AccountSignerMeta<TAccountLiquidator>
133
+ : TAccountLiquidator,
134
+ TAccountTokenProgram extends string
135
+ ? ReadonlyAccount<TAccountTokenProgram>
136
+ : TAccountTokenProgram,
137
+ TAccountSystemProgram extends string
138
+ ? ReadonlyAccount<TAccountSystemProgram>
139
+ : TAccountSystemProgram,
140
+ ...TRemainingAccounts,
141
+ ]
142
+ >;
143
+
144
+ export type LiquidateWriterPositionInstructionData = {
145
+ discriminator: ReadonlyUint8Array;
146
+ };
147
+
148
+ export type LiquidateWriterPositionInstructionDataArgs = {};
149
+
150
+ export function getLiquidateWriterPositionInstructionDataEncoder(): FixedSizeEncoder<LiquidateWriterPositionInstructionDataArgs> {
151
+ return transformEncoder(
152
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
153
+ (value) => ({
154
+ ...value,
155
+ discriminator: LIQUIDATE_WRITER_POSITION_DISCRIMINATOR,
156
+ }),
157
+ );
158
+ }
159
+
160
+ export function getLiquidateWriterPositionInstructionDataDecoder(): FixedSizeDecoder<LiquidateWriterPositionInstructionData> {
161
+ return getStructDecoder([
162
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
163
+ ]);
164
+ }
165
+
166
+ export function getLiquidateWriterPositionInstructionDataCodec(): FixedSizeCodec<
167
+ LiquidateWriterPositionInstructionDataArgs,
168
+ LiquidateWriterPositionInstructionData
169
+ > {
170
+ return combineCodec(
171
+ getLiquidateWriterPositionInstructionDataEncoder(),
172
+ getLiquidateWriterPositionInstructionDataDecoder(),
173
+ );
174
+ }
175
+
176
+ export type LiquidateWriterPositionAsyncInput<
177
+ TAccountOptionPool extends string = string,
178
+ TAccountOptionAccount extends string = string,
179
+ TAccountCollateralPool extends string = string,
180
+ TAccountWriterPosition extends string = string,
181
+ TAccountLongMint extends string = string,
182
+ TAccountEscrowLongAccount extends string = string,
183
+ TAccountOmlpVault extends string = string,
184
+ TAccountUnderlyingMint extends string = string,
185
+ TAccountMarketData extends string = string,
186
+ TAccountSwitchboardQueue extends string = string,
187
+ TAccountSlotHashesSysvar extends string = string,
188
+ TAccountInstructionsSysvar extends string = string,
189
+ TAccountCollateralVault extends string = string,
190
+ TAccountPremiumVault extends string = string,
191
+ TAccountOmlpVaultTokenAccount extends string = string,
192
+ TAccountFeeWallet extends string = string,
193
+ TAccountLiquidator extends string = string,
194
+ TAccountTokenProgram extends string = string,
195
+ TAccountSystemProgram extends string = string,
196
+ > = {
197
+ /** The option pool */
198
+ optionPool: Address<TAccountOptionPool>;
199
+ /** The option account */
200
+ optionAccount: Address<TAccountOptionAccount>;
201
+ /** Collateral pool */
202
+ collateralPool?: Address<TAccountCollateralPool>;
203
+ /** Writer's position to liquidate */
204
+ writerPosition: Address<TAccountWriterPosition>;
205
+ /** LONG token mint (for burning unsold tokens) */
206
+ longMint: Address<TAccountLongMint>;
207
+ /** Pool's LONG escrow account (holds unsold LONG tokens to burn) */
208
+ escrowLongAccount: Address<TAccountEscrowLongAccount>;
209
+ /** OMLP Vault (for repayment tracking) */
210
+ omlpVault: Address<TAccountOmlpVault>;
211
+ /** Underlying token mint (for decimal handling) */
212
+ underlyingMint: Address<TAccountUnderlyingMint>;
213
+ /** Market data account (provides switchboard_feed_id for price check) */
214
+ marketData: Address<TAccountMarketData>;
215
+ switchboardQueue: Address<TAccountSwitchboardQueue>;
216
+ slotHashesSysvar?: Address<TAccountSlotHashesSysvar>;
217
+ instructionsSysvar?: Address<TAccountInstructionsSysvar>;
218
+ /** Collateral vault (source of collateral-side repayments) */
219
+ collateralVault: Address<TAccountCollateralVault>;
220
+ /** Pool premium vault (source of theta forfeiture + excess theta splits) */
221
+ premiumVault: Address<TAccountPremiumVault>;
222
+ /** OMLP vault token account (receives loan repayments + half of excess theta) */
223
+ omlpVaultTokenAccount: Address<TAccountOmlpVaultTokenAccount>;
224
+ /** Protocol fee wallet (receives protocol fees + half of excess theta) */
225
+ feeWallet: Address<TAccountFeeWallet>;
226
+ /** Liquidator/keeper (permissionless - anyone can call) */
227
+ liquidator: TransactionSigner<TAccountLiquidator>;
228
+ tokenProgram?: Address<TAccountTokenProgram>;
229
+ systemProgram?: Address<TAccountSystemProgram>;
230
+ };
231
+
232
+ export async function getLiquidateWriterPositionInstructionAsync<
233
+ TAccountOptionPool extends string,
234
+ TAccountOptionAccount extends string,
235
+ TAccountCollateralPool extends string,
236
+ TAccountWriterPosition extends string,
237
+ TAccountLongMint extends string,
238
+ TAccountEscrowLongAccount extends string,
239
+ TAccountOmlpVault extends string,
240
+ TAccountUnderlyingMint extends string,
241
+ TAccountMarketData extends string,
242
+ TAccountSwitchboardQueue extends string,
243
+ TAccountSlotHashesSysvar extends string,
244
+ TAccountInstructionsSysvar extends string,
245
+ TAccountCollateralVault extends string,
246
+ TAccountPremiumVault extends string,
247
+ TAccountOmlpVaultTokenAccount extends string,
248
+ TAccountFeeWallet extends string,
249
+ TAccountLiquidator extends string,
250
+ TAccountTokenProgram extends string,
251
+ TAccountSystemProgram extends string,
252
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
253
+ >(
254
+ input: LiquidateWriterPositionAsyncInput<
255
+ TAccountOptionPool,
256
+ TAccountOptionAccount,
257
+ TAccountCollateralPool,
258
+ TAccountWriterPosition,
259
+ TAccountLongMint,
260
+ TAccountEscrowLongAccount,
261
+ TAccountOmlpVault,
262
+ TAccountUnderlyingMint,
263
+ TAccountMarketData,
264
+ TAccountSwitchboardQueue,
265
+ TAccountSlotHashesSysvar,
266
+ TAccountInstructionsSysvar,
267
+ TAccountCollateralVault,
268
+ TAccountPremiumVault,
269
+ TAccountOmlpVaultTokenAccount,
270
+ TAccountFeeWallet,
271
+ TAccountLiquidator,
272
+ TAccountTokenProgram,
273
+ TAccountSystemProgram
274
+ >,
275
+ config?: { programAddress?: TProgramAddress },
276
+ ): Promise<
277
+ LiquidateWriterPositionInstruction<
278
+ TProgramAddress,
279
+ TAccountOptionPool,
280
+ TAccountOptionAccount,
281
+ TAccountCollateralPool,
282
+ TAccountWriterPosition,
283
+ TAccountLongMint,
284
+ TAccountEscrowLongAccount,
285
+ TAccountOmlpVault,
286
+ TAccountUnderlyingMint,
287
+ TAccountMarketData,
288
+ TAccountSwitchboardQueue,
289
+ TAccountSlotHashesSysvar,
290
+ TAccountInstructionsSysvar,
291
+ TAccountCollateralVault,
292
+ TAccountPremiumVault,
293
+ TAccountOmlpVaultTokenAccount,
294
+ TAccountFeeWallet,
295
+ TAccountLiquidator,
296
+ TAccountTokenProgram,
297
+ TAccountSystemProgram
298
+ >
299
+ > {
300
+ // Program address.
301
+ const programAddress =
302
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
303
+
304
+ // Original accounts.
305
+ const originalAccounts = {
306
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
307
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
308
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
309
+ writerPosition: { value: input.writerPosition ?? null, isWritable: true },
310
+ longMint: { value: input.longMint ?? null, isWritable: true },
311
+ escrowLongAccount: {
312
+ value: input.escrowLongAccount ?? null,
313
+ isWritable: true,
314
+ },
315
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
316
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
317
+ marketData: { value: input.marketData ?? null, isWritable: false },
318
+ switchboardQueue: {
319
+ value: input.switchboardQueue ?? null,
320
+ isWritable: false,
321
+ },
322
+ slotHashesSysvar: {
323
+ value: input.slotHashesSysvar ?? null,
324
+ isWritable: false,
325
+ },
326
+ instructionsSysvar: {
327
+ value: input.instructionsSysvar ?? null,
328
+ isWritable: false,
329
+ },
330
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
331
+ premiumVault: { value: input.premiumVault ?? null, isWritable: true },
332
+ omlpVaultTokenAccount: {
333
+ value: input.omlpVaultTokenAccount ?? null,
334
+ isWritable: true,
335
+ },
336
+ feeWallet: { value: input.feeWallet ?? null, isWritable: true },
337
+ liquidator: { value: input.liquidator ?? null, isWritable: true },
338
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
339
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
340
+ };
341
+ const accounts = originalAccounts as Record<
342
+ keyof typeof originalAccounts,
343
+ ResolvedAccount
344
+ >;
345
+
346
+ // Resolve default values.
347
+ if (!accounts.collateralPool.value) {
348
+ accounts.collateralPool.value = await getProgramDerivedAddress({
349
+ programAddress,
350
+ seeds: [
351
+ getBytesEncoder().encode(
352
+ new Uint8Array([
353
+ 99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
354
+ 108,
355
+ ]),
356
+ ),
357
+ getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
358
+ ],
359
+ });
360
+ }
361
+ if (!accounts.slotHashesSysvar.value) {
362
+ accounts.slotHashesSysvar.value =
363
+ "SysvarS1otHashes111111111111111111111111111" as Address<"SysvarS1otHashes111111111111111111111111111">;
364
+ }
365
+ if (!accounts.instructionsSysvar.value) {
366
+ accounts.instructionsSysvar.value =
367
+ "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">;
368
+ }
369
+ if (!accounts.tokenProgram.value) {
370
+ accounts.tokenProgram.value =
371
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
372
+ }
373
+ if (!accounts.systemProgram.value) {
374
+ accounts.systemProgram.value =
375
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
376
+ }
377
+
378
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
379
+ return Object.freeze({
380
+ accounts: [
381
+ getAccountMeta(accounts.optionPool),
382
+ getAccountMeta(accounts.optionAccount),
383
+ getAccountMeta(accounts.collateralPool),
384
+ getAccountMeta(accounts.writerPosition),
385
+ getAccountMeta(accounts.longMint),
386
+ getAccountMeta(accounts.escrowLongAccount),
387
+ getAccountMeta(accounts.omlpVault),
388
+ getAccountMeta(accounts.underlyingMint),
389
+ getAccountMeta(accounts.marketData),
390
+ getAccountMeta(accounts.switchboardQueue),
391
+ getAccountMeta(accounts.slotHashesSysvar),
392
+ getAccountMeta(accounts.instructionsSysvar),
393
+ getAccountMeta(accounts.collateralVault),
394
+ getAccountMeta(accounts.premiumVault),
395
+ getAccountMeta(accounts.omlpVaultTokenAccount),
396
+ getAccountMeta(accounts.feeWallet),
397
+ getAccountMeta(accounts.liquidator),
398
+ getAccountMeta(accounts.tokenProgram),
399
+ getAccountMeta(accounts.systemProgram),
400
+ ],
401
+ data: getLiquidateWriterPositionInstructionDataEncoder().encode({}),
402
+ programAddress,
403
+ } as LiquidateWriterPositionInstruction<
404
+ TProgramAddress,
405
+ TAccountOptionPool,
406
+ TAccountOptionAccount,
407
+ TAccountCollateralPool,
408
+ TAccountWriterPosition,
409
+ TAccountLongMint,
410
+ TAccountEscrowLongAccount,
411
+ TAccountOmlpVault,
412
+ TAccountUnderlyingMint,
413
+ TAccountMarketData,
414
+ TAccountSwitchboardQueue,
415
+ TAccountSlotHashesSysvar,
416
+ TAccountInstructionsSysvar,
417
+ TAccountCollateralVault,
418
+ TAccountPremiumVault,
419
+ TAccountOmlpVaultTokenAccount,
420
+ TAccountFeeWallet,
421
+ TAccountLiquidator,
422
+ TAccountTokenProgram,
423
+ TAccountSystemProgram
424
+ >);
425
+ }
426
+
427
+ export type LiquidateWriterPositionInput<
428
+ TAccountOptionPool extends string = string,
429
+ TAccountOptionAccount extends string = string,
430
+ TAccountCollateralPool extends string = string,
431
+ TAccountWriterPosition extends string = string,
432
+ TAccountLongMint extends string = string,
433
+ TAccountEscrowLongAccount extends string = string,
434
+ TAccountOmlpVault extends string = string,
435
+ TAccountUnderlyingMint extends string = string,
436
+ TAccountMarketData extends string = string,
437
+ TAccountSwitchboardQueue extends string = string,
438
+ TAccountSlotHashesSysvar extends string = string,
439
+ TAccountInstructionsSysvar extends string = string,
440
+ TAccountCollateralVault extends string = string,
441
+ TAccountPremiumVault extends string = string,
442
+ TAccountOmlpVaultTokenAccount extends string = string,
443
+ TAccountFeeWallet extends string = string,
444
+ TAccountLiquidator extends string = string,
445
+ TAccountTokenProgram extends string = string,
446
+ TAccountSystemProgram extends string = string,
447
+ > = {
448
+ /** The option pool */
449
+ optionPool: Address<TAccountOptionPool>;
450
+ /** The option account */
451
+ optionAccount: Address<TAccountOptionAccount>;
452
+ /** Collateral pool */
453
+ collateralPool: Address<TAccountCollateralPool>;
454
+ /** Writer's position to liquidate */
455
+ writerPosition: Address<TAccountWriterPosition>;
456
+ /** LONG token mint (for burning unsold tokens) */
457
+ longMint: Address<TAccountLongMint>;
458
+ /** Pool's LONG escrow account (holds unsold LONG tokens to burn) */
459
+ escrowLongAccount: Address<TAccountEscrowLongAccount>;
460
+ /** OMLP Vault (for repayment tracking) */
461
+ omlpVault: Address<TAccountOmlpVault>;
462
+ /** Underlying token mint (for decimal handling) */
463
+ underlyingMint: Address<TAccountUnderlyingMint>;
464
+ /** Market data account (provides switchboard_feed_id for price check) */
465
+ marketData: Address<TAccountMarketData>;
466
+ switchboardQueue: Address<TAccountSwitchboardQueue>;
467
+ slotHashesSysvar?: Address<TAccountSlotHashesSysvar>;
468
+ instructionsSysvar?: Address<TAccountInstructionsSysvar>;
469
+ /** Collateral vault (source of collateral-side repayments) */
470
+ collateralVault: Address<TAccountCollateralVault>;
471
+ /** Pool premium vault (source of theta forfeiture + excess theta splits) */
472
+ premiumVault: Address<TAccountPremiumVault>;
473
+ /** OMLP vault token account (receives loan repayments + half of excess theta) */
474
+ omlpVaultTokenAccount: Address<TAccountOmlpVaultTokenAccount>;
475
+ /** Protocol fee wallet (receives protocol fees + half of excess theta) */
476
+ feeWallet: Address<TAccountFeeWallet>;
477
+ /** Liquidator/keeper (permissionless - anyone can call) */
478
+ liquidator: TransactionSigner<TAccountLiquidator>;
479
+ tokenProgram?: Address<TAccountTokenProgram>;
480
+ systemProgram?: Address<TAccountSystemProgram>;
481
+ };
482
+
483
+ export function getLiquidateWriterPositionInstruction<
484
+ TAccountOptionPool extends string,
485
+ TAccountOptionAccount extends string,
486
+ TAccountCollateralPool extends string,
487
+ TAccountWriterPosition extends string,
488
+ TAccountLongMint extends string,
489
+ TAccountEscrowLongAccount extends string,
490
+ TAccountOmlpVault extends string,
491
+ TAccountUnderlyingMint extends string,
492
+ TAccountMarketData extends string,
493
+ TAccountSwitchboardQueue extends string,
494
+ TAccountSlotHashesSysvar extends string,
495
+ TAccountInstructionsSysvar extends string,
496
+ TAccountCollateralVault extends string,
497
+ TAccountPremiumVault extends string,
498
+ TAccountOmlpVaultTokenAccount extends string,
499
+ TAccountFeeWallet extends string,
500
+ TAccountLiquidator extends string,
501
+ TAccountTokenProgram extends string,
502
+ TAccountSystemProgram extends string,
503
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
504
+ >(
505
+ input: LiquidateWriterPositionInput<
506
+ TAccountOptionPool,
507
+ TAccountOptionAccount,
508
+ TAccountCollateralPool,
509
+ TAccountWriterPosition,
510
+ TAccountLongMint,
511
+ TAccountEscrowLongAccount,
512
+ TAccountOmlpVault,
513
+ TAccountUnderlyingMint,
514
+ TAccountMarketData,
515
+ TAccountSwitchboardQueue,
516
+ TAccountSlotHashesSysvar,
517
+ TAccountInstructionsSysvar,
518
+ TAccountCollateralVault,
519
+ TAccountPremiumVault,
520
+ TAccountOmlpVaultTokenAccount,
521
+ TAccountFeeWallet,
522
+ TAccountLiquidator,
523
+ TAccountTokenProgram,
524
+ TAccountSystemProgram
525
+ >,
526
+ config?: { programAddress?: TProgramAddress },
527
+ ): LiquidateWriterPositionInstruction<
528
+ TProgramAddress,
529
+ TAccountOptionPool,
530
+ TAccountOptionAccount,
531
+ TAccountCollateralPool,
532
+ TAccountWriterPosition,
533
+ TAccountLongMint,
534
+ TAccountEscrowLongAccount,
535
+ TAccountOmlpVault,
536
+ TAccountUnderlyingMint,
537
+ TAccountMarketData,
538
+ TAccountSwitchboardQueue,
539
+ TAccountSlotHashesSysvar,
540
+ TAccountInstructionsSysvar,
541
+ TAccountCollateralVault,
542
+ TAccountPremiumVault,
543
+ TAccountOmlpVaultTokenAccount,
544
+ TAccountFeeWallet,
545
+ TAccountLiquidator,
546
+ TAccountTokenProgram,
547
+ TAccountSystemProgram
548
+ > {
549
+ // Program address.
550
+ const programAddress =
551
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
552
+
553
+ // Original accounts.
554
+ const originalAccounts = {
555
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
556
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
557
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
558
+ writerPosition: { value: input.writerPosition ?? null, isWritable: true },
559
+ longMint: { value: input.longMint ?? null, isWritable: true },
560
+ escrowLongAccount: {
561
+ value: input.escrowLongAccount ?? null,
562
+ isWritable: true,
563
+ },
564
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
565
+ underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
566
+ marketData: { value: input.marketData ?? null, isWritable: false },
567
+ switchboardQueue: {
568
+ value: input.switchboardQueue ?? null,
569
+ isWritable: false,
570
+ },
571
+ slotHashesSysvar: {
572
+ value: input.slotHashesSysvar ?? null,
573
+ isWritable: false,
574
+ },
575
+ instructionsSysvar: {
576
+ value: input.instructionsSysvar ?? null,
577
+ isWritable: false,
578
+ },
579
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
580
+ premiumVault: { value: input.premiumVault ?? null, isWritable: true },
581
+ omlpVaultTokenAccount: {
582
+ value: input.omlpVaultTokenAccount ?? null,
583
+ isWritable: true,
584
+ },
585
+ feeWallet: { value: input.feeWallet ?? null, isWritable: true },
586
+ liquidator: { value: input.liquidator ?? null, isWritable: true },
587
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
588
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
589
+ };
590
+ const accounts = originalAccounts as Record<
591
+ keyof typeof originalAccounts,
592
+ ResolvedAccount
593
+ >;
594
+
595
+ // Resolve default values.
596
+ if (!accounts.slotHashesSysvar.value) {
597
+ accounts.slotHashesSysvar.value =
598
+ "SysvarS1otHashes111111111111111111111111111" as Address<"SysvarS1otHashes111111111111111111111111111">;
599
+ }
600
+ if (!accounts.instructionsSysvar.value) {
601
+ accounts.instructionsSysvar.value =
602
+ "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">;
603
+ }
604
+ if (!accounts.tokenProgram.value) {
605
+ accounts.tokenProgram.value =
606
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
607
+ }
608
+ if (!accounts.systemProgram.value) {
609
+ accounts.systemProgram.value =
610
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
611
+ }
612
+
613
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
614
+ return Object.freeze({
615
+ accounts: [
616
+ getAccountMeta(accounts.optionPool),
617
+ getAccountMeta(accounts.optionAccount),
618
+ getAccountMeta(accounts.collateralPool),
619
+ getAccountMeta(accounts.writerPosition),
620
+ getAccountMeta(accounts.longMint),
621
+ getAccountMeta(accounts.escrowLongAccount),
622
+ getAccountMeta(accounts.omlpVault),
623
+ getAccountMeta(accounts.underlyingMint),
624
+ getAccountMeta(accounts.marketData),
625
+ getAccountMeta(accounts.switchboardQueue),
626
+ getAccountMeta(accounts.slotHashesSysvar),
627
+ getAccountMeta(accounts.instructionsSysvar),
628
+ getAccountMeta(accounts.collateralVault),
629
+ getAccountMeta(accounts.premiumVault),
630
+ getAccountMeta(accounts.omlpVaultTokenAccount),
631
+ getAccountMeta(accounts.feeWallet),
632
+ getAccountMeta(accounts.liquidator),
633
+ getAccountMeta(accounts.tokenProgram),
634
+ getAccountMeta(accounts.systemProgram),
635
+ ],
636
+ data: getLiquidateWriterPositionInstructionDataEncoder().encode({}),
637
+ programAddress,
638
+ } as LiquidateWriterPositionInstruction<
639
+ TProgramAddress,
640
+ TAccountOptionPool,
641
+ TAccountOptionAccount,
642
+ TAccountCollateralPool,
643
+ TAccountWriterPosition,
644
+ TAccountLongMint,
645
+ TAccountEscrowLongAccount,
646
+ TAccountOmlpVault,
647
+ TAccountUnderlyingMint,
648
+ TAccountMarketData,
649
+ TAccountSwitchboardQueue,
650
+ TAccountSlotHashesSysvar,
651
+ TAccountInstructionsSysvar,
652
+ TAccountCollateralVault,
653
+ TAccountPremiumVault,
654
+ TAccountOmlpVaultTokenAccount,
655
+ TAccountFeeWallet,
656
+ TAccountLiquidator,
657
+ TAccountTokenProgram,
658
+ TAccountSystemProgram
659
+ >);
660
+ }
661
+
662
+ export type ParsedLiquidateWriterPositionInstruction<
663
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
664
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
665
+ > = {
666
+ programAddress: Address<TProgram>;
667
+ accounts: {
668
+ /** The option pool */
669
+ optionPool: TAccountMetas[0];
670
+ /** The option account */
671
+ optionAccount: TAccountMetas[1];
672
+ /** Collateral pool */
673
+ collateralPool: TAccountMetas[2];
674
+ /** Writer's position to liquidate */
675
+ writerPosition: TAccountMetas[3];
676
+ /** LONG token mint (for burning unsold tokens) */
677
+ longMint: TAccountMetas[4];
678
+ /** Pool's LONG escrow account (holds unsold LONG tokens to burn) */
679
+ escrowLongAccount: TAccountMetas[5];
680
+ /** OMLP Vault (for repayment tracking) */
681
+ omlpVault: TAccountMetas[6];
682
+ /** Underlying token mint (for decimal handling) */
683
+ underlyingMint: TAccountMetas[7];
684
+ /** Market data account (provides switchboard_feed_id for price check) */
685
+ marketData: TAccountMetas[8];
686
+ switchboardQueue: TAccountMetas[9];
687
+ slotHashesSysvar: TAccountMetas[10];
688
+ instructionsSysvar: TAccountMetas[11];
689
+ /** Collateral vault (source of collateral-side repayments) */
690
+ collateralVault: TAccountMetas[12];
691
+ /** Pool premium vault (source of theta forfeiture + excess theta splits) */
692
+ premiumVault: TAccountMetas[13];
693
+ /** OMLP vault token account (receives loan repayments + half of excess theta) */
694
+ omlpVaultTokenAccount: TAccountMetas[14];
695
+ /** Protocol fee wallet (receives protocol fees + half of excess theta) */
696
+ feeWallet: TAccountMetas[15];
697
+ /** Liquidator/keeper (permissionless - anyone can call) */
698
+ liquidator: TAccountMetas[16];
699
+ tokenProgram: TAccountMetas[17];
700
+ systemProgram: TAccountMetas[18];
701
+ };
702
+ data: LiquidateWriterPositionInstructionData;
703
+ };
704
+
705
+ export function parseLiquidateWriterPositionInstruction<
706
+ TProgram extends string,
707
+ TAccountMetas extends readonly AccountMeta[],
708
+ >(
709
+ instruction: Instruction<TProgram> &
710
+ InstructionWithAccounts<TAccountMetas> &
711
+ InstructionWithData<ReadonlyUint8Array>,
712
+ ): ParsedLiquidateWriterPositionInstruction<TProgram, TAccountMetas> {
713
+ if (instruction.accounts.length < 19) {
714
+ // TODO: Coded error.
715
+ throw new Error("Not enough accounts");
716
+ }
717
+ let accountIndex = 0;
718
+ const getNextAccount = () => {
719
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
720
+ accountIndex += 1;
721
+ return accountMeta;
722
+ };
723
+ return {
724
+ programAddress: instruction.programAddress,
725
+ accounts: {
726
+ optionPool: getNextAccount(),
727
+ optionAccount: getNextAccount(),
728
+ collateralPool: getNextAccount(),
729
+ writerPosition: getNextAccount(),
730
+ longMint: getNextAccount(),
731
+ escrowLongAccount: getNextAccount(),
732
+ omlpVault: getNextAccount(),
733
+ underlyingMint: getNextAccount(),
734
+ marketData: getNextAccount(),
735
+ switchboardQueue: getNextAccount(),
736
+ slotHashesSysvar: getNextAccount(),
737
+ instructionsSysvar: getNextAccount(),
738
+ collateralVault: getNextAccount(),
739
+ premiumVault: getNextAccount(),
740
+ omlpVaultTokenAccount: getNextAccount(),
741
+ feeWallet: getNextAccount(),
742
+ liquidator: getNextAccount(),
743
+ tokenProgram: getNextAccount(),
744
+ systemProgram: getNextAccount(),
745
+ },
746
+ data: getLiquidateWriterPositionInstructionDataDecoder().decode(
747
+ instruction.data,
748
+ ),
749
+ };
750
+ }