@epicentral/sos-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +239 -0
  3. package/accounts/fetchers.ts +140 -0
  4. package/accounts/list.ts +152 -0
  5. package/accounts/pdas.ts +308 -0
  6. package/client/lookup-table.ts +32 -0
  7. package/client/program.ts +13 -0
  8. package/client/types.ts +8 -0
  9. package/generated/accounts/collateralPool.ts +217 -0
  10. package/generated/accounts/config.ts +156 -0
  11. package/generated/accounts/dualSourceContract.ts +235 -0
  12. package/generated/accounts/escrowState.ts +183 -0
  13. package/generated/accounts/index.ts +24 -0
  14. package/generated/accounts/lenderPosition.ts +211 -0
  15. package/generated/accounts/liquidityRouter.ts +223 -0
  16. package/generated/accounts/makerCollateralShare.ts +229 -0
  17. package/generated/accounts/makerPoolShare.ts +203 -0
  18. package/generated/accounts/marketDataAccount.ts +176 -0
  19. package/generated/accounts/optionAccount.ts +247 -0
  20. package/generated/accounts/optionPool.ts +253 -0
  21. package/generated/accounts/poolLoan.ts +220 -0
  22. package/generated/accounts/positionAccount.ts +187 -0
  23. package/generated/accounts/priceUpdateV2.ts +163 -0
  24. package/generated/accounts/vault.ts +304 -0
  25. package/generated/accounts/writerPosition.ts +297 -0
  26. package/generated/errors/index.ts +9 -0
  27. package/generated/errors/optionProgram.ts +392 -0
  28. package/generated/index.ts +13 -0
  29. package/generated/instructions/acceptAdmin.ts +230 -0
  30. package/generated/instructions/autoExerciseAllExpired.ts +523 -0
  31. package/generated/instructions/autoExerciseExpired.ts +623 -0
  32. package/generated/instructions/borrowFromPool.ts +554 -0
  33. package/generated/instructions/buyFromPool.ts +684 -0
  34. package/generated/instructions/claimPremium.ts +377 -0
  35. package/generated/instructions/closeLongToPool.ts +716 -0
  36. package/generated/instructions/closeOption.ts +235 -0
  37. package/generated/instructions/createEscrowV2.ts +518 -0
  38. package/generated/instructions/createLiquidityRouter.ts +361 -0
  39. package/generated/instructions/depositCollateral.ts +624 -0
  40. package/generated/instructions/depositToPool.ts +497 -0
  41. package/generated/instructions/depositToPosition.ts +429 -0
  42. package/generated/instructions/index.ts +45 -0
  43. package/generated/instructions/initCollateralPool.ts +513 -0
  44. package/generated/instructions/initConfig.ts +279 -0
  45. package/generated/instructions/initOptionPool.ts +587 -0
  46. package/generated/instructions/initializeMarketData.ts +359 -0
  47. package/generated/instructions/liquidateWriterPosition.ts +592 -0
  48. package/generated/instructions/omlpCreateVault.ts +547 -0
  49. package/generated/instructions/omlpTakeOfferWithFailover.ts +606 -0
  50. package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
  51. package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
  52. package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
  53. package/generated/instructions/optionExercise.ts +540 -0
  54. package/generated/instructions/optionMint.ts +1349 -0
  55. package/generated/instructions/optionValidate.ts +255 -0
  56. package/generated/instructions/repayPoolLoan.ts +499 -0
  57. package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
  58. package/generated/instructions/settleMakerCollateral.ts +472 -0
  59. package/generated/instructions/syncWriterPosition.ts +206 -0
  60. package/generated/instructions/transferAdmin.ts +245 -0
  61. package/generated/instructions/unwindWriterUnsold.ts +668 -0
  62. package/generated/instructions/updateImpliedVolatility.ts +226 -0
  63. package/generated/instructions/updateMarketData.ts +315 -0
  64. package/generated/instructions/withdrawFromPool.ts +429 -0
  65. package/generated/instructions/withdrawFromPosition.ts +405 -0
  66. package/generated/instructions/writeToPool.ts +594 -0
  67. package/generated/programs/index.ts +9 -0
  68. package/generated/programs/optionProgram.ts +832 -0
  69. package/generated/shared/index.ts +164 -0
  70. package/generated/types/borrowedFromSAP1.ts +75 -0
  71. package/generated/types/borrowedFromSAP2.ts +83 -0
  72. package/generated/types/failoverTriggered.ts +85 -0
  73. package/generated/types/impliedVolatilityUpdated.ts +73 -0
  74. package/generated/types/index.ts +32 -0
  75. package/generated/types/liquidationExecuted.ts +73 -0
  76. package/generated/types/liquidityMetrics.ts +69 -0
  77. package/generated/types/liquidityRouterCreated.ts +79 -0
  78. package/generated/types/marketDataInitialized.ts +61 -0
  79. package/generated/types/marketDataUpdated.ts +69 -0
  80. package/generated/types/optionClosed.ts +56 -0
  81. package/generated/types/optionExercised.ts +62 -0
  82. package/generated/types/optionExpired.ts +49 -0
  83. package/generated/types/optionMinted.ts +78 -0
  84. package/generated/types/optionType.ts +38 -0
  85. package/generated/types/optionValidated.ts +82 -0
  86. package/generated/types/poolLoanCreated.ts +74 -0
  87. package/generated/types/poolLoanRepaid.ts +74 -0
  88. package/generated/types/positionDeposited.ts +73 -0
  89. package/generated/types/positionWithdrawn.ts +81 -0
  90. package/generated/types/priceFeedMessage.ts +117 -0
  91. package/generated/types/protocolFeeUpdated.ts +69 -0
  92. package/generated/types/sap2Provider.ts +38 -0
  93. package/generated/types/vaultCreated.ts +60 -0
  94. package/generated/types/verificationLevel.ts +95 -0
  95. package/index.ts +25 -0
  96. package/long/builders.ts +126 -0
  97. package/long/exercise.ts +49 -0
  98. package/long/quotes.ts +48 -0
  99. package/omlp/builders.ts +74 -0
  100. package/omlp/service.ts +94 -0
  101. package/package.json +22 -0
  102. package/shared/amounts.ts +32 -0
  103. package/shared/errors.ts +12 -0
  104. package/shared/remaining-accounts.ts +41 -0
  105. package/shared/transactions.ts +49 -0
  106. package/short/builders.ts +268 -0
  107. package/short/claim-premium.ts +37 -0
  108. package/short/close-option.ts +34 -0
  109. package/short/pool.ts +224 -0
  110. package/tsconfig.json +12 -0
@@ -0,0 +1,472 @@
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 Address,
22
+ type FixedSizeCodec,
23
+ type FixedSizeDecoder,
24
+ type FixedSizeEncoder,
25
+ type Instruction,
26
+ type InstructionWithAccounts,
27
+ type InstructionWithData,
28
+ type ReadonlyAccount,
29
+ type ReadonlyUint8Array,
30
+ type WritableAccount,
31
+ } from "@solana/kit";
32
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
33
+ import {
34
+ expectAddress,
35
+ getAccountMetaFactory,
36
+ type ResolvedAccount,
37
+ } from "../shared";
38
+
39
+ export const SETTLE_MAKER_COLLATERAL_DISCRIMINATOR = new Uint8Array([
40
+ 47, 169, 97, 199, 29, 197, 115, 148,
41
+ ]);
42
+
43
+ export function getSettleMakerCollateralDiscriminatorBytes() {
44
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
45
+ SETTLE_MAKER_COLLATERAL_DISCRIMINATOR,
46
+ );
47
+ }
48
+
49
+ export type SettleMakerCollateralInstruction<
50
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
51
+ TAccountCollateralPool extends string | AccountMeta<string> = string,
52
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
53
+ TAccountMakerCollateralShare extends string | AccountMeta<string> = string,
54
+ TAccountCollateralVault extends string | AccountMeta<string> = string,
55
+ TAccountMakerCollateralAccount extends string | AccountMeta<string> = string,
56
+ TAccountOmlpVault extends string | AccountMeta<string> = string,
57
+ TAccountPoolLoan extends string | AccountMeta<string> = string,
58
+ TAccountTokenProgram extends string | AccountMeta<string> =
59
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
60
+ TAccountSystemProgram extends string | AccountMeta<string> =
61
+ "11111111111111111111111111111111",
62
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
63
+ > = Instruction<TProgram> &
64
+ InstructionWithData<ReadonlyUint8Array> &
65
+ InstructionWithAccounts<
66
+ [
67
+ TAccountCollateralPool extends string
68
+ ? WritableAccount<TAccountCollateralPool>
69
+ : TAccountCollateralPool,
70
+ TAccountOptionAccount extends string
71
+ ? ReadonlyAccount<TAccountOptionAccount>
72
+ : TAccountOptionAccount,
73
+ TAccountMakerCollateralShare extends string
74
+ ? WritableAccount<TAccountMakerCollateralShare>
75
+ : TAccountMakerCollateralShare,
76
+ TAccountCollateralVault extends string
77
+ ? WritableAccount<TAccountCollateralVault>
78
+ : TAccountCollateralVault,
79
+ TAccountMakerCollateralAccount extends string
80
+ ? WritableAccount<TAccountMakerCollateralAccount>
81
+ : TAccountMakerCollateralAccount,
82
+ TAccountOmlpVault extends string
83
+ ? WritableAccount<TAccountOmlpVault>
84
+ : TAccountOmlpVault,
85
+ TAccountPoolLoan extends string
86
+ ? WritableAccount<TAccountPoolLoan>
87
+ : TAccountPoolLoan,
88
+ TAccountTokenProgram extends string
89
+ ? ReadonlyAccount<TAccountTokenProgram>
90
+ : TAccountTokenProgram,
91
+ TAccountSystemProgram extends string
92
+ ? ReadonlyAccount<TAccountSystemProgram>
93
+ : TAccountSystemProgram,
94
+ ...TRemainingAccounts,
95
+ ]
96
+ >;
97
+
98
+ export type SettleMakerCollateralInstructionData = {
99
+ discriminator: ReadonlyUint8Array;
100
+ };
101
+
102
+ export type SettleMakerCollateralInstructionDataArgs = {};
103
+
104
+ export function getSettleMakerCollateralInstructionDataEncoder(): FixedSizeEncoder<SettleMakerCollateralInstructionDataArgs> {
105
+ return transformEncoder(
106
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
107
+ (value) => ({
108
+ ...value,
109
+ discriminator: SETTLE_MAKER_COLLATERAL_DISCRIMINATOR,
110
+ }),
111
+ );
112
+ }
113
+
114
+ export function getSettleMakerCollateralInstructionDataDecoder(): FixedSizeDecoder<SettleMakerCollateralInstructionData> {
115
+ return getStructDecoder([
116
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
117
+ ]);
118
+ }
119
+
120
+ export function getSettleMakerCollateralInstructionDataCodec(): FixedSizeCodec<
121
+ SettleMakerCollateralInstructionDataArgs,
122
+ SettleMakerCollateralInstructionData
123
+ > {
124
+ return combineCodec(
125
+ getSettleMakerCollateralInstructionDataEncoder(),
126
+ getSettleMakerCollateralInstructionDataDecoder(),
127
+ );
128
+ }
129
+
130
+ export type SettleMakerCollateralAsyncInput<
131
+ TAccountCollateralPool extends string = string,
132
+ TAccountOptionAccount extends string = string,
133
+ TAccountMakerCollateralShare extends string = string,
134
+ TAccountCollateralVault extends string = string,
135
+ TAccountMakerCollateralAccount extends string = string,
136
+ TAccountOmlpVault extends string = string,
137
+ TAccountPoolLoan extends string = string,
138
+ TAccountTokenProgram extends string = string,
139
+ TAccountSystemProgram extends string = string,
140
+ > = {
141
+ collateralPool?: Address<TAccountCollateralPool>;
142
+ /** The option account (needed for PDA derivation) */
143
+ optionAccount: Address<TAccountOptionAccount>;
144
+ makerCollateralShare: Address<TAccountMakerCollateralShare>;
145
+ /** Pool's collateral vault */
146
+ collateralVault: Address<TAccountCollateralVault>;
147
+ /** Maker's WSOL account (receives remaining collateral) */
148
+ makerCollateralAccount: Address<TAccountMakerCollateralAccount>;
149
+ /** OMLP Vault to repay lender */
150
+ omlpVault: Address<TAccountOmlpVault>;
151
+ /**
152
+ * The OMLP Pool Loan to mark as repaid (V2 pooled system)
153
+ * Must belong to the same maker as the collateral share
154
+ */
155
+ poolLoan: Address<TAccountPoolLoan>;
156
+ tokenProgram?: Address<TAccountTokenProgram>;
157
+ systemProgram?: Address<TAccountSystemProgram>;
158
+ };
159
+
160
+ export async function getSettleMakerCollateralInstructionAsync<
161
+ TAccountCollateralPool extends string,
162
+ TAccountOptionAccount extends string,
163
+ TAccountMakerCollateralShare extends string,
164
+ TAccountCollateralVault extends string,
165
+ TAccountMakerCollateralAccount extends string,
166
+ TAccountOmlpVault extends string,
167
+ TAccountPoolLoan extends string,
168
+ TAccountTokenProgram extends string,
169
+ TAccountSystemProgram extends string,
170
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
171
+ >(
172
+ input: SettleMakerCollateralAsyncInput<
173
+ TAccountCollateralPool,
174
+ TAccountOptionAccount,
175
+ TAccountMakerCollateralShare,
176
+ TAccountCollateralVault,
177
+ TAccountMakerCollateralAccount,
178
+ TAccountOmlpVault,
179
+ TAccountPoolLoan,
180
+ TAccountTokenProgram,
181
+ TAccountSystemProgram
182
+ >,
183
+ config?: { programAddress?: TProgramAddress },
184
+ ): Promise<
185
+ SettleMakerCollateralInstruction<
186
+ TProgramAddress,
187
+ TAccountCollateralPool,
188
+ TAccountOptionAccount,
189
+ TAccountMakerCollateralShare,
190
+ TAccountCollateralVault,
191
+ TAccountMakerCollateralAccount,
192
+ TAccountOmlpVault,
193
+ TAccountPoolLoan,
194
+ TAccountTokenProgram,
195
+ TAccountSystemProgram
196
+ >
197
+ > {
198
+ // Program address.
199
+ const programAddress =
200
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
201
+
202
+ // Original accounts.
203
+ const originalAccounts = {
204
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
205
+ optionAccount: { value: input.optionAccount ?? null, isWritable: false },
206
+ makerCollateralShare: {
207
+ value: input.makerCollateralShare ?? null,
208
+ isWritable: true,
209
+ },
210
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
211
+ makerCollateralAccount: {
212
+ value: input.makerCollateralAccount ?? null,
213
+ isWritable: true,
214
+ },
215
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
216
+ poolLoan: { value: input.poolLoan ?? null, isWritable: true },
217
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
218
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
219
+ };
220
+ const accounts = originalAccounts as Record<
221
+ keyof typeof originalAccounts,
222
+ ResolvedAccount
223
+ >;
224
+
225
+ // Resolve default values.
226
+ if (!accounts.collateralPool.value) {
227
+ accounts.collateralPool.value = await getProgramDerivedAddress({
228
+ programAddress,
229
+ seeds: [
230
+ getBytesEncoder().encode(
231
+ new Uint8Array([
232
+ 99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
233
+ 108,
234
+ ]),
235
+ ),
236
+ getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
237
+ ],
238
+ });
239
+ }
240
+ if (!accounts.tokenProgram.value) {
241
+ accounts.tokenProgram.value =
242
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
243
+ }
244
+ if (!accounts.systemProgram.value) {
245
+ accounts.systemProgram.value =
246
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
247
+ }
248
+
249
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
250
+ return Object.freeze({
251
+ accounts: [
252
+ getAccountMeta(accounts.collateralPool),
253
+ getAccountMeta(accounts.optionAccount),
254
+ getAccountMeta(accounts.makerCollateralShare),
255
+ getAccountMeta(accounts.collateralVault),
256
+ getAccountMeta(accounts.makerCollateralAccount),
257
+ getAccountMeta(accounts.omlpVault),
258
+ getAccountMeta(accounts.poolLoan),
259
+ getAccountMeta(accounts.tokenProgram),
260
+ getAccountMeta(accounts.systemProgram),
261
+ ],
262
+ data: getSettleMakerCollateralInstructionDataEncoder().encode({}),
263
+ programAddress,
264
+ } as SettleMakerCollateralInstruction<
265
+ TProgramAddress,
266
+ TAccountCollateralPool,
267
+ TAccountOptionAccount,
268
+ TAccountMakerCollateralShare,
269
+ TAccountCollateralVault,
270
+ TAccountMakerCollateralAccount,
271
+ TAccountOmlpVault,
272
+ TAccountPoolLoan,
273
+ TAccountTokenProgram,
274
+ TAccountSystemProgram
275
+ >);
276
+ }
277
+
278
+ export type SettleMakerCollateralInput<
279
+ TAccountCollateralPool extends string = string,
280
+ TAccountOptionAccount extends string = string,
281
+ TAccountMakerCollateralShare extends string = string,
282
+ TAccountCollateralVault extends string = string,
283
+ TAccountMakerCollateralAccount extends string = string,
284
+ TAccountOmlpVault extends string = string,
285
+ TAccountPoolLoan extends string = string,
286
+ TAccountTokenProgram extends string = string,
287
+ TAccountSystemProgram extends string = string,
288
+ > = {
289
+ collateralPool: Address<TAccountCollateralPool>;
290
+ /** The option account (needed for PDA derivation) */
291
+ optionAccount: Address<TAccountOptionAccount>;
292
+ makerCollateralShare: Address<TAccountMakerCollateralShare>;
293
+ /** Pool's collateral vault */
294
+ collateralVault: Address<TAccountCollateralVault>;
295
+ /** Maker's WSOL account (receives remaining collateral) */
296
+ makerCollateralAccount: Address<TAccountMakerCollateralAccount>;
297
+ /** OMLP Vault to repay lender */
298
+ omlpVault: Address<TAccountOmlpVault>;
299
+ /**
300
+ * The OMLP Pool Loan to mark as repaid (V2 pooled system)
301
+ * Must belong to the same maker as the collateral share
302
+ */
303
+ poolLoan: Address<TAccountPoolLoan>;
304
+ tokenProgram?: Address<TAccountTokenProgram>;
305
+ systemProgram?: Address<TAccountSystemProgram>;
306
+ };
307
+
308
+ export function getSettleMakerCollateralInstruction<
309
+ TAccountCollateralPool extends string,
310
+ TAccountOptionAccount extends string,
311
+ TAccountMakerCollateralShare extends string,
312
+ TAccountCollateralVault extends string,
313
+ TAccountMakerCollateralAccount extends string,
314
+ TAccountOmlpVault extends string,
315
+ TAccountPoolLoan extends string,
316
+ TAccountTokenProgram extends string,
317
+ TAccountSystemProgram extends string,
318
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
319
+ >(
320
+ input: SettleMakerCollateralInput<
321
+ TAccountCollateralPool,
322
+ TAccountOptionAccount,
323
+ TAccountMakerCollateralShare,
324
+ TAccountCollateralVault,
325
+ TAccountMakerCollateralAccount,
326
+ TAccountOmlpVault,
327
+ TAccountPoolLoan,
328
+ TAccountTokenProgram,
329
+ TAccountSystemProgram
330
+ >,
331
+ config?: { programAddress?: TProgramAddress },
332
+ ): SettleMakerCollateralInstruction<
333
+ TProgramAddress,
334
+ TAccountCollateralPool,
335
+ TAccountOptionAccount,
336
+ TAccountMakerCollateralShare,
337
+ TAccountCollateralVault,
338
+ TAccountMakerCollateralAccount,
339
+ TAccountOmlpVault,
340
+ TAccountPoolLoan,
341
+ TAccountTokenProgram,
342
+ TAccountSystemProgram
343
+ > {
344
+ // Program address.
345
+ const programAddress =
346
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
347
+
348
+ // Original accounts.
349
+ const originalAccounts = {
350
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
351
+ optionAccount: { value: input.optionAccount ?? null, isWritable: false },
352
+ makerCollateralShare: {
353
+ value: input.makerCollateralShare ?? null,
354
+ isWritable: true,
355
+ },
356
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
357
+ makerCollateralAccount: {
358
+ value: input.makerCollateralAccount ?? null,
359
+ isWritable: true,
360
+ },
361
+ omlpVault: { value: input.omlpVault ?? null, isWritable: true },
362
+ poolLoan: { value: input.poolLoan ?? null, isWritable: true },
363
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
364
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
365
+ };
366
+ const accounts = originalAccounts as Record<
367
+ keyof typeof originalAccounts,
368
+ ResolvedAccount
369
+ >;
370
+
371
+ // Resolve default values.
372
+ if (!accounts.tokenProgram.value) {
373
+ accounts.tokenProgram.value =
374
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
375
+ }
376
+ if (!accounts.systemProgram.value) {
377
+ accounts.systemProgram.value =
378
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
379
+ }
380
+
381
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
382
+ return Object.freeze({
383
+ accounts: [
384
+ getAccountMeta(accounts.collateralPool),
385
+ getAccountMeta(accounts.optionAccount),
386
+ getAccountMeta(accounts.makerCollateralShare),
387
+ getAccountMeta(accounts.collateralVault),
388
+ getAccountMeta(accounts.makerCollateralAccount),
389
+ getAccountMeta(accounts.omlpVault),
390
+ getAccountMeta(accounts.poolLoan),
391
+ getAccountMeta(accounts.tokenProgram),
392
+ getAccountMeta(accounts.systemProgram),
393
+ ],
394
+ data: getSettleMakerCollateralInstructionDataEncoder().encode({}),
395
+ programAddress,
396
+ } as SettleMakerCollateralInstruction<
397
+ TProgramAddress,
398
+ TAccountCollateralPool,
399
+ TAccountOptionAccount,
400
+ TAccountMakerCollateralShare,
401
+ TAccountCollateralVault,
402
+ TAccountMakerCollateralAccount,
403
+ TAccountOmlpVault,
404
+ TAccountPoolLoan,
405
+ TAccountTokenProgram,
406
+ TAccountSystemProgram
407
+ >);
408
+ }
409
+
410
+ export type ParsedSettleMakerCollateralInstruction<
411
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
412
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
413
+ > = {
414
+ programAddress: Address<TProgram>;
415
+ accounts: {
416
+ collateralPool: TAccountMetas[0];
417
+ /** The option account (needed for PDA derivation) */
418
+ optionAccount: TAccountMetas[1];
419
+ makerCollateralShare: TAccountMetas[2];
420
+ /** Pool's collateral vault */
421
+ collateralVault: TAccountMetas[3];
422
+ /** Maker's WSOL account (receives remaining collateral) */
423
+ makerCollateralAccount: TAccountMetas[4];
424
+ /** OMLP Vault to repay lender */
425
+ omlpVault: TAccountMetas[5];
426
+ /**
427
+ * The OMLP Pool Loan to mark as repaid (V2 pooled system)
428
+ * Must belong to the same maker as the collateral share
429
+ */
430
+ poolLoan: TAccountMetas[6];
431
+ tokenProgram: TAccountMetas[7];
432
+ systemProgram: TAccountMetas[8];
433
+ };
434
+ data: SettleMakerCollateralInstructionData;
435
+ };
436
+
437
+ export function parseSettleMakerCollateralInstruction<
438
+ TProgram extends string,
439
+ TAccountMetas extends readonly AccountMeta[],
440
+ >(
441
+ instruction: Instruction<TProgram> &
442
+ InstructionWithAccounts<TAccountMetas> &
443
+ InstructionWithData<ReadonlyUint8Array>,
444
+ ): ParsedSettleMakerCollateralInstruction<TProgram, TAccountMetas> {
445
+ if (instruction.accounts.length < 9) {
446
+ // TODO: Coded error.
447
+ throw new Error("Not enough accounts");
448
+ }
449
+ let accountIndex = 0;
450
+ const getNextAccount = () => {
451
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
452
+ accountIndex += 1;
453
+ return accountMeta;
454
+ };
455
+ return {
456
+ programAddress: instruction.programAddress,
457
+ accounts: {
458
+ collateralPool: getNextAccount(),
459
+ optionAccount: getNextAccount(),
460
+ makerCollateralShare: getNextAccount(),
461
+ collateralVault: getNextAccount(),
462
+ makerCollateralAccount: getNextAccount(),
463
+ omlpVault: getNextAccount(),
464
+ poolLoan: getNextAccount(),
465
+ tokenProgram: getNextAccount(),
466
+ systemProgram: getNextAccount(),
467
+ },
468
+ data: getSettleMakerCollateralInstructionDataDecoder().decode(
469
+ instruction.data,
470
+ ),
471
+ };
472
+ }
@@ -0,0 +1,206 @@
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
+ getBytesDecoder,
14
+ getBytesEncoder,
15
+ getStructDecoder,
16
+ getStructEncoder,
17
+ transformEncoder,
18
+ type AccountMeta,
19
+ type Address,
20
+ type FixedSizeCodec,
21
+ type FixedSizeDecoder,
22
+ type FixedSizeEncoder,
23
+ type Instruction,
24
+ type InstructionWithAccounts,
25
+ type InstructionWithData,
26
+ type ReadonlyAccount,
27
+ type ReadonlyUint8Array,
28
+ type WritableAccount,
29
+ } from "@solana/kit";
30
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
31
+ import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
32
+
33
+ export const SYNC_WRITER_POSITION_DISCRIMINATOR = new Uint8Array([
34
+ 57, 19, 103, 217, 187, 66, 3, 4,
35
+ ]);
36
+
37
+ export function getSyncWriterPositionDiscriminatorBytes() {
38
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
39
+ SYNC_WRITER_POSITION_DISCRIMINATOR,
40
+ );
41
+ }
42
+
43
+ export type SyncWriterPositionInstruction<
44
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
45
+ TAccountOptionPool extends string | AccountMeta<string> = string,
46
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
47
+ TAccountWriterPosition extends string | AccountMeta<string> = string,
48
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
49
+ > = Instruction<TProgram> &
50
+ InstructionWithData<ReadonlyUint8Array> &
51
+ InstructionWithAccounts<
52
+ [
53
+ TAccountOptionPool extends string
54
+ ? ReadonlyAccount<TAccountOptionPool>
55
+ : TAccountOptionPool,
56
+ TAccountOptionAccount extends string
57
+ ? ReadonlyAccount<TAccountOptionAccount>
58
+ : TAccountOptionAccount,
59
+ TAccountWriterPosition extends string
60
+ ? WritableAccount<TAccountWriterPosition>
61
+ : TAccountWriterPosition,
62
+ ...TRemainingAccounts,
63
+ ]
64
+ >;
65
+
66
+ export type SyncWriterPositionInstructionData = {
67
+ discriminator: ReadonlyUint8Array;
68
+ };
69
+
70
+ export type SyncWriterPositionInstructionDataArgs = {};
71
+
72
+ export function getSyncWriterPositionInstructionDataEncoder(): FixedSizeEncoder<SyncWriterPositionInstructionDataArgs> {
73
+ return transformEncoder(
74
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
75
+ (value) => ({
76
+ ...value,
77
+ discriminator: SYNC_WRITER_POSITION_DISCRIMINATOR,
78
+ }),
79
+ );
80
+ }
81
+
82
+ export function getSyncWriterPositionInstructionDataDecoder(): FixedSizeDecoder<SyncWriterPositionInstructionData> {
83
+ return getStructDecoder([
84
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
85
+ ]);
86
+ }
87
+
88
+ export function getSyncWriterPositionInstructionDataCodec(): FixedSizeCodec<
89
+ SyncWriterPositionInstructionDataArgs,
90
+ SyncWriterPositionInstructionData
91
+ > {
92
+ return combineCodec(
93
+ getSyncWriterPositionInstructionDataEncoder(),
94
+ getSyncWriterPositionInstructionDataDecoder(),
95
+ );
96
+ }
97
+
98
+ export type SyncWriterPositionInput<
99
+ TAccountOptionPool extends string = string,
100
+ TAccountOptionAccount extends string = string,
101
+ TAccountWriterPosition extends string = string,
102
+ > = {
103
+ /** The option pool */
104
+ optionPool: Address<TAccountOptionPool>;
105
+ /** The option account */
106
+ optionAccount: Address<TAccountOptionAccount>;
107
+ /** Writer's position to sync */
108
+ writerPosition: Address<TAccountWriterPosition>;
109
+ };
110
+
111
+ export function getSyncWriterPositionInstruction<
112
+ TAccountOptionPool extends string,
113
+ TAccountOptionAccount extends string,
114
+ TAccountWriterPosition extends string,
115
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
116
+ >(
117
+ input: SyncWriterPositionInput<
118
+ TAccountOptionPool,
119
+ TAccountOptionAccount,
120
+ TAccountWriterPosition
121
+ >,
122
+ config?: { programAddress?: TProgramAddress },
123
+ ): SyncWriterPositionInstruction<
124
+ TProgramAddress,
125
+ TAccountOptionPool,
126
+ TAccountOptionAccount,
127
+ TAccountWriterPosition
128
+ > {
129
+ // Program address.
130
+ const programAddress =
131
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
132
+
133
+ // Original accounts.
134
+ const originalAccounts = {
135
+ optionPool: { value: input.optionPool ?? null, isWritable: false },
136
+ optionAccount: { value: input.optionAccount ?? null, isWritable: false },
137
+ writerPosition: { value: input.writerPosition ?? null, isWritable: true },
138
+ };
139
+ const accounts = originalAccounts as Record<
140
+ keyof typeof originalAccounts,
141
+ ResolvedAccount
142
+ >;
143
+
144
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
145
+ return Object.freeze({
146
+ accounts: [
147
+ getAccountMeta(accounts.optionPool),
148
+ getAccountMeta(accounts.optionAccount),
149
+ getAccountMeta(accounts.writerPosition),
150
+ ],
151
+ data: getSyncWriterPositionInstructionDataEncoder().encode({}),
152
+ programAddress,
153
+ } as SyncWriterPositionInstruction<
154
+ TProgramAddress,
155
+ TAccountOptionPool,
156
+ TAccountOptionAccount,
157
+ TAccountWriterPosition
158
+ >);
159
+ }
160
+
161
+ export type ParsedSyncWriterPositionInstruction<
162
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
163
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
164
+ > = {
165
+ programAddress: Address<TProgram>;
166
+ accounts: {
167
+ /** The option pool */
168
+ optionPool: TAccountMetas[0];
169
+ /** The option account */
170
+ optionAccount: TAccountMetas[1];
171
+ /** Writer's position to sync */
172
+ writerPosition: TAccountMetas[2];
173
+ };
174
+ data: SyncWriterPositionInstructionData;
175
+ };
176
+
177
+ export function parseSyncWriterPositionInstruction<
178
+ TProgram extends string,
179
+ TAccountMetas extends readonly AccountMeta[],
180
+ >(
181
+ instruction: Instruction<TProgram> &
182
+ InstructionWithAccounts<TAccountMetas> &
183
+ InstructionWithData<ReadonlyUint8Array>,
184
+ ): ParsedSyncWriterPositionInstruction<TProgram, TAccountMetas> {
185
+ if (instruction.accounts.length < 3) {
186
+ // TODO: Coded error.
187
+ throw new Error("Not enough accounts");
188
+ }
189
+ let accountIndex = 0;
190
+ const getNextAccount = () => {
191
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
192
+ accountIndex += 1;
193
+ return accountMeta;
194
+ };
195
+ return {
196
+ programAddress: instruction.programAddress,
197
+ accounts: {
198
+ optionPool: getNextAccount(),
199
+ optionAccount: getNextAccount(),
200
+ writerPosition: getNextAccount(),
201
+ },
202
+ data: getSyncWriterPositionInstructionDataDecoder().decode(
203
+ instruction.data,
204
+ ),
205
+ };
206
+ }