@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,619 @@
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
+ getU64Decoder,
20
+ getU64Encoder,
21
+ transformEncoder,
22
+ type AccountMeta,
23
+ type AccountSignerMeta,
24
+ type Address,
25
+ type FixedSizeCodec,
26
+ type FixedSizeDecoder,
27
+ type FixedSizeEncoder,
28
+ type Instruction,
29
+ type InstructionWithAccounts,
30
+ type InstructionWithData,
31
+ type ReadonlyAccount,
32
+ type ReadonlyUint8Array,
33
+ type TransactionSigner,
34
+ type WritableAccount,
35
+ type WritableSignerAccount,
36
+ } from "@solana/kit";
37
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
38
+ import {
39
+ expectAddress,
40
+ getAccountMetaFactory,
41
+ type ResolvedAccount,
42
+ } from "../shared";
43
+
44
+ export const WRITE_TO_POOL_DISCRIMINATOR = new Uint8Array([
45
+ 169, 94, 104, 228, 81, 205, 147, 71,
46
+ ]);
47
+
48
+ export function getWriteToPoolDiscriminatorBytes() {
49
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
50
+ WRITE_TO_POOL_DISCRIMINATOR,
51
+ );
52
+ }
53
+
54
+ export type WriteToPoolInstruction<
55
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
56
+ TAccountOptionPool extends string | AccountMeta<string> = string,
57
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
58
+ TAccountMarketData extends string | AccountMeta<string> = string,
59
+ TAccountCollateralPool extends string | AccountMeta<string> = string,
60
+ TAccountWriterPosition extends string | AccountMeta<string> = string,
61
+ TAccountWriterLongAccount extends string | AccountMeta<string> = string,
62
+ TAccountWriterShortAccount extends string | AccountMeta<string> = string,
63
+ TAccountWriterCollateralAccount extends string | AccountMeta<string> = string,
64
+ TAccountEscrowLongAccount extends string | AccountMeta<string> = string,
65
+ TAccountCollateralVault extends string | AccountMeta<string> = string,
66
+ TAccountWriter 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
+ TAccountOptionPool extends string
77
+ ? WritableAccount<TAccountOptionPool>
78
+ : TAccountOptionPool,
79
+ TAccountOptionAccount extends string
80
+ ? WritableAccount<TAccountOptionAccount>
81
+ : TAccountOptionAccount,
82
+ TAccountMarketData extends string
83
+ ? ReadonlyAccount<TAccountMarketData>
84
+ : TAccountMarketData,
85
+ TAccountCollateralPool extends string
86
+ ? WritableAccount<TAccountCollateralPool>
87
+ : TAccountCollateralPool,
88
+ TAccountWriterPosition extends string
89
+ ? WritableAccount<TAccountWriterPosition>
90
+ : TAccountWriterPosition,
91
+ TAccountWriterLongAccount extends string
92
+ ? WritableAccount<TAccountWriterLongAccount>
93
+ : TAccountWriterLongAccount,
94
+ TAccountWriterShortAccount extends string
95
+ ? ReadonlyAccount<TAccountWriterShortAccount>
96
+ : TAccountWriterShortAccount,
97
+ TAccountWriterCollateralAccount extends string
98
+ ? WritableAccount<TAccountWriterCollateralAccount>
99
+ : TAccountWriterCollateralAccount,
100
+ TAccountEscrowLongAccount extends string
101
+ ? WritableAccount<TAccountEscrowLongAccount>
102
+ : TAccountEscrowLongAccount,
103
+ TAccountCollateralVault extends string
104
+ ? WritableAccount<TAccountCollateralVault>
105
+ : TAccountCollateralVault,
106
+ TAccountWriter extends string
107
+ ? WritableSignerAccount<TAccountWriter> &
108
+ AccountSignerMeta<TAccountWriter>
109
+ : TAccountWriter,
110
+ TAccountTokenProgram extends string
111
+ ? ReadonlyAccount<TAccountTokenProgram>
112
+ : TAccountTokenProgram,
113
+ TAccountSystemProgram extends string
114
+ ? ReadonlyAccount<TAccountSystemProgram>
115
+ : TAccountSystemProgram,
116
+ ...TRemainingAccounts,
117
+ ]
118
+ >;
119
+
120
+ export type WriteToPoolInstructionData = {
121
+ discriminator: ReadonlyUint8Array;
122
+ longQty: bigint;
123
+ collateralAmount: bigint;
124
+ };
125
+
126
+ export type WriteToPoolInstructionDataArgs = {
127
+ longQty: number | bigint;
128
+ collateralAmount: number | bigint;
129
+ };
130
+
131
+ export function getWriteToPoolInstructionDataEncoder(): FixedSizeEncoder<WriteToPoolInstructionDataArgs> {
132
+ return transformEncoder(
133
+ getStructEncoder([
134
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
135
+ ["longQty", getU64Encoder()],
136
+ ["collateralAmount", getU64Encoder()],
137
+ ]),
138
+ (value) => ({ ...value, discriminator: WRITE_TO_POOL_DISCRIMINATOR }),
139
+ );
140
+ }
141
+
142
+ export function getWriteToPoolInstructionDataDecoder(): FixedSizeDecoder<WriteToPoolInstructionData> {
143
+ return getStructDecoder([
144
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
145
+ ["longQty", getU64Decoder()],
146
+ ["collateralAmount", getU64Decoder()],
147
+ ]);
148
+ }
149
+
150
+ export function getWriteToPoolInstructionDataCodec(): FixedSizeCodec<
151
+ WriteToPoolInstructionDataArgs,
152
+ WriteToPoolInstructionData
153
+ > {
154
+ return combineCodec(
155
+ getWriteToPoolInstructionDataEncoder(),
156
+ getWriteToPoolInstructionDataDecoder(),
157
+ );
158
+ }
159
+
160
+ export type WriteToPoolAsyncInput<
161
+ TAccountOptionPool extends string = string,
162
+ TAccountOptionAccount extends string = string,
163
+ TAccountMarketData extends string = string,
164
+ TAccountCollateralPool extends string = string,
165
+ TAccountWriterPosition extends string = string,
166
+ TAccountWriterLongAccount extends string = string,
167
+ TAccountWriterShortAccount extends string = string,
168
+ TAccountWriterCollateralAccount extends string = string,
169
+ TAccountEscrowLongAccount extends string = string,
170
+ TAccountCollateralVault extends string = string,
171
+ TAccountWriter extends string = string,
172
+ TAccountTokenProgram extends string = string,
173
+ TAccountSystemProgram extends string = string,
174
+ > = {
175
+ /** The pool to write into */
176
+ optionPool: Address<TAccountOptionPool>;
177
+ /** The option account */
178
+ optionAccount: Address<TAccountOptionAccount>;
179
+ /** Market data (historical vol baseline for IV kink) */
180
+ marketData: Address<TAccountMarketData>;
181
+ /** Collateral pool for this option */
182
+ collateralPool?: Address<TAccountCollateralPool>;
183
+ /** Writer's unified position account (single source of truth) */
184
+ writerPosition?: Address<TAccountWriterPosition>;
185
+ /** Writer's LONG token account (source - depositing to pool) */
186
+ writerLongAccount: Address<TAccountWriterLongAccount>;
187
+ /** Writer's SHORT token account (already holds SHORT from minting) */
188
+ writerShortAccount: Address<TAccountWriterShortAccount>;
189
+ /** Writer's collateral account (source of own collateral) */
190
+ writerCollateralAccount: Address<TAccountWriterCollateralAccount>;
191
+ /** Pool's LONG escrow (destination for LONG tokens) */
192
+ escrowLongAccount: Address<TAccountEscrowLongAccount>;
193
+ /** Pool's collateral vault (destination for collateral) */
194
+ collateralVault: Address<TAccountCollateralVault>;
195
+ writer: TransactionSigner<TAccountWriter>;
196
+ tokenProgram?: Address<TAccountTokenProgram>;
197
+ systemProgram?: Address<TAccountSystemProgram>;
198
+ longQty: WriteToPoolInstructionDataArgs["longQty"];
199
+ collateralAmount: WriteToPoolInstructionDataArgs["collateralAmount"];
200
+ };
201
+
202
+ export async function getWriteToPoolInstructionAsync<
203
+ TAccountOptionPool extends string,
204
+ TAccountOptionAccount extends string,
205
+ TAccountMarketData extends string,
206
+ TAccountCollateralPool extends string,
207
+ TAccountWriterPosition extends string,
208
+ TAccountWriterLongAccount extends string,
209
+ TAccountWriterShortAccount extends string,
210
+ TAccountWriterCollateralAccount extends string,
211
+ TAccountEscrowLongAccount extends string,
212
+ TAccountCollateralVault extends string,
213
+ TAccountWriter extends string,
214
+ TAccountTokenProgram extends string,
215
+ TAccountSystemProgram extends string,
216
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
217
+ >(
218
+ input: WriteToPoolAsyncInput<
219
+ TAccountOptionPool,
220
+ TAccountOptionAccount,
221
+ TAccountMarketData,
222
+ TAccountCollateralPool,
223
+ TAccountWriterPosition,
224
+ TAccountWriterLongAccount,
225
+ TAccountWriterShortAccount,
226
+ TAccountWriterCollateralAccount,
227
+ TAccountEscrowLongAccount,
228
+ TAccountCollateralVault,
229
+ TAccountWriter,
230
+ TAccountTokenProgram,
231
+ TAccountSystemProgram
232
+ >,
233
+ config?: { programAddress?: TProgramAddress },
234
+ ): Promise<
235
+ WriteToPoolInstruction<
236
+ TProgramAddress,
237
+ TAccountOptionPool,
238
+ TAccountOptionAccount,
239
+ TAccountMarketData,
240
+ TAccountCollateralPool,
241
+ TAccountWriterPosition,
242
+ TAccountWriterLongAccount,
243
+ TAccountWriterShortAccount,
244
+ TAccountWriterCollateralAccount,
245
+ TAccountEscrowLongAccount,
246
+ TAccountCollateralVault,
247
+ TAccountWriter,
248
+ TAccountTokenProgram,
249
+ TAccountSystemProgram
250
+ >
251
+ > {
252
+ // Program address.
253
+ const programAddress =
254
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
255
+
256
+ // Original accounts.
257
+ const originalAccounts = {
258
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
259
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
260
+ marketData: { value: input.marketData ?? null, isWritable: false },
261
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
262
+ writerPosition: { value: input.writerPosition ?? null, isWritable: true },
263
+ writerLongAccount: {
264
+ value: input.writerLongAccount ?? null,
265
+ isWritable: true,
266
+ },
267
+ writerShortAccount: {
268
+ value: input.writerShortAccount ?? null,
269
+ isWritable: false,
270
+ },
271
+ writerCollateralAccount: {
272
+ value: input.writerCollateralAccount ?? null,
273
+ isWritable: true,
274
+ },
275
+ escrowLongAccount: {
276
+ value: input.escrowLongAccount ?? null,
277
+ isWritable: true,
278
+ },
279
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
280
+ writer: { value: input.writer ?? null, isWritable: true },
281
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
282
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
283
+ };
284
+ const accounts = originalAccounts as Record<
285
+ keyof typeof originalAccounts,
286
+ ResolvedAccount
287
+ >;
288
+
289
+ // Original args.
290
+ const args = { ...input };
291
+
292
+ // Resolve default values.
293
+ if (!accounts.collateralPool.value) {
294
+ accounts.collateralPool.value = await getProgramDerivedAddress({
295
+ programAddress,
296
+ seeds: [
297
+ getBytesEncoder().encode(
298
+ new Uint8Array([
299
+ 99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
300
+ 108,
301
+ ]),
302
+ ),
303
+ getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
304
+ ],
305
+ });
306
+ }
307
+ if (!accounts.writerPosition.value) {
308
+ accounts.writerPosition.value = await getProgramDerivedAddress({
309
+ programAddress,
310
+ seeds: [
311
+ getBytesEncoder().encode(
312
+ new Uint8Array([
313
+ 119, 114, 105, 116, 101, 114, 95, 112, 111, 115, 105, 116, 105, 111,
314
+ 110,
315
+ ]),
316
+ ),
317
+ getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
318
+ getAddressEncoder().encode(expectAddress(accounts.writer.value)),
319
+ ],
320
+ });
321
+ }
322
+ if (!accounts.tokenProgram.value) {
323
+ accounts.tokenProgram.value =
324
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
325
+ }
326
+ if (!accounts.systemProgram.value) {
327
+ accounts.systemProgram.value =
328
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
329
+ }
330
+
331
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
332
+ return Object.freeze({
333
+ accounts: [
334
+ getAccountMeta(accounts.optionPool),
335
+ getAccountMeta(accounts.optionAccount),
336
+ getAccountMeta(accounts.marketData),
337
+ getAccountMeta(accounts.collateralPool),
338
+ getAccountMeta(accounts.writerPosition),
339
+ getAccountMeta(accounts.writerLongAccount),
340
+ getAccountMeta(accounts.writerShortAccount),
341
+ getAccountMeta(accounts.writerCollateralAccount),
342
+ getAccountMeta(accounts.escrowLongAccount),
343
+ getAccountMeta(accounts.collateralVault),
344
+ getAccountMeta(accounts.writer),
345
+ getAccountMeta(accounts.tokenProgram),
346
+ getAccountMeta(accounts.systemProgram),
347
+ ],
348
+ data: getWriteToPoolInstructionDataEncoder().encode(
349
+ args as WriteToPoolInstructionDataArgs,
350
+ ),
351
+ programAddress,
352
+ } as WriteToPoolInstruction<
353
+ TProgramAddress,
354
+ TAccountOptionPool,
355
+ TAccountOptionAccount,
356
+ TAccountMarketData,
357
+ TAccountCollateralPool,
358
+ TAccountWriterPosition,
359
+ TAccountWriterLongAccount,
360
+ TAccountWriterShortAccount,
361
+ TAccountWriterCollateralAccount,
362
+ TAccountEscrowLongAccount,
363
+ TAccountCollateralVault,
364
+ TAccountWriter,
365
+ TAccountTokenProgram,
366
+ TAccountSystemProgram
367
+ >);
368
+ }
369
+
370
+ export type WriteToPoolInput<
371
+ TAccountOptionPool extends string = string,
372
+ TAccountOptionAccount extends string = string,
373
+ TAccountMarketData extends string = string,
374
+ TAccountCollateralPool extends string = string,
375
+ TAccountWriterPosition extends string = string,
376
+ TAccountWriterLongAccount extends string = string,
377
+ TAccountWriterShortAccount extends string = string,
378
+ TAccountWriterCollateralAccount extends string = string,
379
+ TAccountEscrowLongAccount extends string = string,
380
+ TAccountCollateralVault extends string = string,
381
+ TAccountWriter extends string = string,
382
+ TAccountTokenProgram extends string = string,
383
+ TAccountSystemProgram extends string = string,
384
+ > = {
385
+ /** The pool to write into */
386
+ optionPool: Address<TAccountOptionPool>;
387
+ /** The option account */
388
+ optionAccount: Address<TAccountOptionAccount>;
389
+ /** Market data (historical vol baseline for IV kink) */
390
+ marketData: Address<TAccountMarketData>;
391
+ /** Collateral pool for this option */
392
+ collateralPool: Address<TAccountCollateralPool>;
393
+ /** Writer's unified position account (single source of truth) */
394
+ writerPosition: Address<TAccountWriterPosition>;
395
+ /** Writer's LONG token account (source - depositing to pool) */
396
+ writerLongAccount: Address<TAccountWriterLongAccount>;
397
+ /** Writer's SHORT token account (already holds SHORT from minting) */
398
+ writerShortAccount: Address<TAccountWriterShortAccount>;
399
+ /** Writer's collateral account (source of own collateral) */
400
+ writerCollateralAccount: Address<TAccountWriterCollateralAccount>;
401
+ /** Pool's LONG escrow (destination for LONG tokens) */
402
+ escrowLongAccount: Address<TAccountEscrowLongAccount>;
403
+ /** Pool's collateral vault (destination for collateral) */
404
+ collateralVault: Address<TAccountCollateralVault>;
405
+ writer: TransactionSigner<TAccountWriter>;
406
+ tokenProgram?: Address<TAccountTokenProgram>;
407
+ systemProgram?: Address<TAccountSystemProgram>;
408
+ longQty: WriteToPoolInstructionDataArgs["longQty"];
409
+ collateralAmount: WriteToPoolInstructionDataArgs["collateralAmount"];
410
+ };
411
+
412
+ export function getWriteToPoolInstruction<
413
+ TAccountOptionPool extends string,
414
+ TAccountOptionAccount extends string,
415
+ TAccountMarketData extends string,
416
+ TAccountCollateralPool extends string,
417
+ TAccountWriterPosition extends string,
418
+ TAccountWriterLongAccount extends string,
419
+ TAccountWriterShortAccount extends string,
420
+ TAccountWriterCollateralAccount extends string,
421
+ TAccountEscrowLongAccount extends string,
422
+ TAccountCollateralVault extends string,
423
+ TAccountWriter extends string,
424
+ TAccountTokenProgram extends string,
425
+ TAccountSystemProgram extends string,
426
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
427
+ >(
428
+ input: WriteToPoolInput<
429
+ TAccountOptionPool,
430
+ TAccountOptionAccount,
431
+ TAccountMarketData,
432
+ TAccountCollateralPool,
433
+ TAccountWriterPosition,
434
+ TAccountWriterLongAccount,
435
+ TAccountWriterShortAccount,
436
+ TAccountWriterCollateralAccount,
437
+ TAccountEscrowLongAccount,
438
+ TAccountCollateralVault,
439
+ TAccountWriter,
440
+ TAccountTokenProgram,
441
+ TAccountSystemProgram
442
+ >,
443
+ config?: { programAddress?: TProgramAddress },
444
+ ): WriteToPoolInstruction<
445
+ TProgramAddress,
446
+ TAccountOptionPool,
447
+ TAccountOptionAccount,
448
+ TAccountMarketData,
449
+ TAccountCollateralPool,
450
+ TAccountWriterPosition,
451
+ TAccountWriterLongAccount,
452
+ TAccountWriterShortAccount,
453
+ TAccountWriterCollateralAccount,
454
+ TAccountEscrowLongAccount,
455
+ TAccountCollateralVault,
456
+ TAccountWriter,
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
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
467
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
468
+ marketData: { value: input.marketData ?? null, isWritable: false },
469
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
470
+ writerPosition: { value: input.writerPosition ?? null, isWritable: true },
471
+ writerLongAccount: {
472
+ value: input.writerLongAccount ?? null,
473
+ isWritable: true,
474
+ },
475
+ writerShortAccount: {
476
+ value: input.writerShortAccount ?? null,
477
+ isWritable: false,
478
+ },
479
+ writerCollateralAccount: {
480
+ value: input.writerCollateralAccount ?? null,
481
+ isWritable: true,
482
+ },
483
+ escrowLongAccount: {
484
+ value: input.escrowLongAccount ?? null,
485
+ isWritable: true,
486
+ },
487
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
488
+ writer: { value: input.writer ?? null, isWritable: true },
489
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
490
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
491
+ };
492
+ const accounts = originalAccounts as Record<
493
+ keyof typeof originalAccounts,
494
+ ResolvedAccount
495
+ >;
496
+
497
+ // Original args.
498
+ const args = { ...input };
499
+
500
+ // Resolve default values.
501
+ if (!accounts.tokenProgram.value) {
502
+ accounts.tokenProgram.value =
503
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
504
+ }
505
+ if (!accounts.systemProgram.value) {
506
+ accounts.systemProgram.value =
507
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
508
+ }
509
+
510
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
511
+ return Object.freeze({
512
+ accounts: [
513
+ getAccountMeta(accounts.optionPool),
514
+ getAccountMeta(accounts.optionAccount),
515
+ getAccountMeta(accounts.marketData),
516
+ getAccountMeta(accounts.collateralPool),
517
+ getAccountMeta(accounts.writerPosition),
518
+ getAccountMeta(accounts.writerLongAccount),
519
+ getAccountMeta(accounts.writerShortAccount),
520
+ getAccountMeta(accounts.writerCollateralAccount),
521
+ getAccountMeta(accounts.escrowLongAccount),
522
+ getAccountMeta(accounts.collateralVault),
523
+ getAccountMeta(accounts.writer),
524
+ getAccountMeta(accounts.tokenProgram),
525
+ getAccountMeta(accounts.systemProgram),
526
+ ],
527
+ data: getWriteToPoolInstructionDataEncoder().encode(
528
+ args as WriteToPoolInstructionDataArgs,
529
+ ),
530
+ programAddress,
531
+ } as WriteToPoolInstruction<
532
+ TProgramAddress,
533
+ TAccountOptionPool,
534
+ TAccountOptionAccount,
535
+ TAccountMarketData,
536
+ TAccountCollateralPool,
537
+ TAccountWriterPosition,
538
+ TAccountWriterLongAccount,
539
+ TAccountWriterShortAccount,
540
+ TAccountWriterCollateralAccount,
541
+ TAccountEscrowLongAccount,
542
+ TAccountCollateralVault,
543
+ TAccountWriter,
544
+ TAccountTokenProgram,
545
+ TAccountSystemProgram
546
+ >);
547
+ }
548
+
549
+ export type ParsedWriteToPoolInstruction<
550
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
551
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
552
+ > = {
553
+ programAddress: Address<TProgram>;
554
+ accounts: {
555
+ /** The pool to write into */
556
+ optionPool: TAccountMetas[0];
557
+ /** The option account */
558
+ optionAccount: TAccountMetas[1];
559
+ /** Market data (historical vol baseline for IV kink) */
560
+ marketData: TAccountMetas[2];
561
+ /** Collateral pool for this option */
562
+ collateralPool: TAccountMetas[3];
563
+ /** Writer's unified position account (single source of truth) */
564
+ writerPosition: TAccountMetas[4];
565
+ /** Writer's LONG token account (source - depositing to pool) */
566
+ writerLongAccount: TAccountMetas[5];
567
+ /** Writer's SHORT token account (already holds SHORT from minting) */
568
+ writerShortAccount: TAccountMetas[6];
569
+ /** Writer's collateral account (source of own collateral) */
570
+ writerCollateralAccount: TAccountMetas[7];
571
+ /** Pool's LONG escrow (destination for LONG tokens) */
572
+ escrowLongAccount: TAccountMetas[8];
573
+ /** Pool's collateral vault (destination for collateral) */
574
+ collateralVault: TAccountMetas[9];
575
+ writer: TAccountMetas[10];
576
+ tokenProgram: TAccountMetas[11];
577
+ systemProgram: TAccountMetas[12];
578
+ };
579
+ data: WriteToPoolInstructionData;
580
+ };
581
+
582
+ export function parseWriteToPoolInstruction<
583
+ TProgram extends string,
584
+ TAccountMetas extends readonly AccountMeta[],
585
+ >(
586
+ instruction: Instruction<TProgram> &
587
+ InstructionWithAccounts<TAccountMetas> &
588
+ InstructionWithData<ReadonlyUint8Array>,
589
+ ): ParsedWriteToPoolInstruction<TProgram, TAccountMetas> {
590
+ if (instruction.accounts.length < 13) {
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
+ optionPool: getNextAccount(),
604
+ optionAccount: getNextAccount(),
605
+ marketData: getNextAccount(),
606
+ collateralPool: getNextAccount(),
607
+ writerPosition: getNextAccount(),
608
+ writerLongAccount: getNextAccount(),
609
+ writerShortAccount: getNextAccount(),
610
+ writerCollateralAccount: getNextAccount(),
611
+ escrowLongAccount: getNextAccount(),
612
+ collateralVault: getNextAccount(),
613
+ writer: getNextAccount(),
614
+ tokenProgram: getNextAccount(),
615
+ systemProgram: getNextAccount(),
616
+ },
617
+ data: getWriteToPoolInstructionDataDecoder().decode(instruction.data),
618
+ };
619
+ }
@@ -0,0 +1,9 @@
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
+ export * from "./optionProgram";