@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,497 @@
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 DEPOSIT_TO_POOL_DISCRIMINATOR = new Uint8Array([
45
+ 99, 136, 15, 66, 85, 146, 24, 89,
46
+ ]);
47
+
48
+ export function getDepositToPoolDiscriminatorBytes() {
49
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
50
+ DEPOSIT_TO_POOL_DISCRIMINATOR,
51
+ );
52
+ }
53
+
54
+ export type DepositToPoolInstruction<
55
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
56
+ TAccountOptionPool extends string | AccountMeta<string> = string,
57
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
58
+ TAccountMakerPoolShare extends string | AccountMeta<string> = string,
59
+ TAccountMakerOptionAccount extends string | AccountMeta<string> = string,
60
+ TAccountEscrowLongAccount extends string | AccountMeta<string> = string,
61
+ TAccountMaker extends string | AccountMeta<string> = string,
62
+ TAccountTokenProgram extends string | AccountMeta<string> =
63
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
64
+ TAccountAssociatedTokenProgram extends string | AccountMeta<string> =
65
+ "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
66
+ TAccountSystemProgram extends string | AccountMeta<string> =
67
+ "11111111111111111111111111111111",
68
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
69
+ > = Instruction<TProgram> &
70
+ InstructionWithData<ReadonlyUint8Array> &
71
+ InstructionWithAccounts<
72
+ [
73
+ TAccountOptionPool extends string
74
+ ? WritableAccount<TAccountOptionPool>
75
+ : TAccountOptionPool,
76
+ TAccountOptionAccount extends string
77
+ ? ReadonlyAccount<TAccountOptionAccount>
78
+ : TAccountOptionAccount,
79
+ TAccountMakerPoolShare extends string
80
+ ? WritableAccount<TAccountMakerPoolShare>
81
+ : TAccountMakerPoolShare,
82
+ TAccountMakerOptionAccount extends string
83
+ ? WritableAccount<TAccountMakerOptionAccount>
84
+ : TAccountMakerOptionAccount,
85
+ TAccountEscrowLongAccount extends string
86
+ ? WritableAccount<TAccountEscrowLongAccount>
87
+ : TAccountEscrowLongAccount,
88
+ TAccountMaker extends string
89
+ ? WritableSignerAccount<TAccountMaker> &
90
+ AccountSignerMeta<TAccountMaker>
91
+ : TAccountMaker,
92
+ TAccountTokenProgram extends string
93
+ ? ReadonlyAccount<TAccountTokenProgram>
94
+ : TAccountTokenProgram,
95
+ TAccountAssociatedTokenProgram extends string
96
+ ? ReadonlyAccount<TAccountAssociatedTokenProgram>
97
+ : TAccountAssociatedTokenProgram,
98
+ TAccountSystemProgram extends string
99
+ ? ReadonlyAccount<TAccountSystemProgram>
100
+ : TAccountSystemProgram,
101
+ ...TRemainingAccounts,
102
+ ]
103
+ >;
104
+
105
+ export type DepositToPoolInstructionData = {
106
+ discriminator: ReadonlyUint8Array;
107
+ amount: bigint;
108
+ };
109
+
110
+ export type DepositToPoolInstructionDataArgs = { amount: number | bigint };
111
+
112
+ export function getDepositToPoolInstructionDataEncoder(): FixedSizeEncoder<DepositToPoolInstructionDataArgs> {
113
+ return transformEncoder(
114
+ getStructEncoder([
115
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
116
+ ["amount", getU64Encoder()],
117
+ ]),
118
+ (value) => ({ ...value, discriminator: DEPOSIT_TO_POOL_DISCRIMINATOR }),
119
+ );
120
+ }
121
+
122
+ export function getDepositToPoolInstructionDataDecoder(): FixedSizeDecoder<DepositToPoolInstructionData> {
123
+ return getStructDecoder([
124
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
125
+ ["amount", getU64Decoder()],
126
+ ]);
127
+ }
128
+
129
+ export function getDepositToPoolInstructionDataCodec(): FixedSizeCodec<
130
+ DepositToPoolInstructionDataArgs,
131
+ DepositToPoolInstructionData
132
+ > {
133
+ return combineCodec(
134
+ getDepositToPoolInstructionDataEncoder(),
135
+ getDepositToPoolInstructionDataDecoder(),
136
+ );
137
+ }
138
+
139
+ export type DepositToPoolAsyncInput<
140
+ TAccountOptionPool extends string = string,
141
+ TAccountOptionAccount extends string = string,
142
+ TAccountMakerPoolShare extends string = string,
143
+ TAccountMakerOptionAccount extends string = string,
144
+ TAccountEscrowLongAccount extends string = string,
145
+ TAccountMaker extends string = string,
146
+ TAccountTokenProgram extends string = string,
147
+ TAccountAssociatedTokenProgram extends string = string,
148
+ TAccountSystemProgram extends string = string,
149
+ > = {
150
+ /** The pool to deposit into */
151
+ optionPool: Address<TAccountOptionPool>;
152
+ /** The option account */
153
+ optionAccount: Address<TAccountOptionAccount>;
154
+ /** Maker's share account (created if first deposit) */
155
+ makerPoolShare?: Address<TAccountMakerPoolShare>;
156
+ /** Maker's LONG token account (source of tokens) */
157
+ makerOptionAccount: Address<TAccountMakerOptionAccount>;
158
+ /** Pool's LONG escrow (destination for tokens) */
159
+ escrowLongAccount: Address<TAccountEscrowLongAccount>;
160
+ maker: TransactionSigner<TAccountMaker>;
161
+ tokenProgram?: Address<TAccountTokenProgram>;
162
+ associatedTokenProgram?: Address<TAccountAssociatedTokenProgram>;
163
+ systemProgram?: Address<TAccountSystemProgram>;
164
+ amount: DepositToPoolInstructionDataArgs["amount"];
165
+ };
166
+
167
+ export async function getDepositToPoolInstructionAsync<
168
+ TAccountOptionPool extends string,
169
+ TAccountOptionAccount extends string,
170
+ TAccountMakerPoolShare extends string,
171
+ TAccountMakerOptionAccount extends string,
172
+ TAccountEscrowLongAccount extends string,
173
+ TAccountMaker extends string,
174
+ TAccountTokenProgram extends string,
175
+ TAccountAssociatedTokenProgram extends string,
176
+ TAccountSystemProgram extends string,
177
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
178
+ >(
179
+ input: DepositToPoolAsyncInput<
180
+ TAccountOptionPool,
181
+ TAccountOptionAccount,
182
+ TAccountMakerPoolShare,
183
+ TAccountMakerOptionAccount,
184
+ TAccountEscrowLongAccount,
185
+ TAccountMaker,
186
+ TAccountTokenProgram,
187
+ TAccountAssociatedTokenProgram,
188
+ TAccountSystemProgram
189
+ >,
190
+ config?: { programAddress?: TProgramAddress },
191
+ ): Promise<
192
+ DepositToPoolInstruction<
193
+ TProgramAddress,
194
+ TAccountOptionPool,
195
+ TAccountOptionAccount,
196
+ TAccountMakerPoolShare,
197
+ TAccountMakerOptionAccount,
198
+ TAccountEscrowLongAccount,
199
+ TAccountMaker,
200
+ TAccountTokenProgram,
201
+ TAccountAssociatedTokenProgram,
202
+ TAccountSystemProgram
203
+ >
204
+ > {
205
+ // Program address.
206
+ const programAddress =
207
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
208
+
209
+ // Original accounts.
210
+ const originalAccounts = {
211
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
212
+ optionAccount: { value: input.optionAccount ?? null, isWritable: false },
213
+ makerPoolShare: { value: input.makerPoolShare ?? null, isWritable: true },
214
+ makerOptionAccount: {
215
+ value: input.makerOptionAccount ?? null,
216
+ isWritable: true,
217
+ },
218
+ escrowLongAccount: {
219
+ value: input.escrowLongAccount ?? null,
220
+ isWritable: true,
221
+ },
222
+ maker: { value: input.maker ?? null, isWritable: true },
223
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
224
+ associatedTokenProgram: {
225
+ value: input.associatedTokenProgram ?? null,
226
+ isWritable: false,
227
+ },
228
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
229
+ };
230
+ const accounts = originalAccounts as Record<
231
+ keyof typeof originalAccounts,
232
+ ResolvedAccount
233
+ >;
234
+
235
+ // Original args.
236
+ const args = { ...input };
237
+
238
+ // Resolve default values.
239
+ if (!accounts.makerPoolShare.value) {
240
+ accounts.makerPoolShare.value = await getProgramDerivedAddress({
241
+ programAddress,
242
+ seeds: [
243
+ getBytesEncoder().encode(
244
+ new Uint8Array([
245
+ 109, 97, 107, 101, 114, 95, 112, 111, 111, 108, 95, 115, 104, 97,
246
+ 114, 101,
247
+ ]),
248
+ ),
249
+ getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
250
+ getAddressEncoder().encode(expectAddress(accounts.maker.value)),
251
+ ],
252
+ });
253
+ }
254
+ if (!accounts.tokenProgram.value) {
255
+ accounts.tokenProgram.value =
256
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
257
+ }
258
+ if (!accounts.associatedTokenProgram.value) {
259
+ accounts.associatedTokenProgram.value =
260
+ "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
261
+ }
262
+ if (!accounts.systemProgram.value) {
263
+ accounts.systemProgram.value =
264
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
265
+ }
266
+
267
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
268
+ return Object.freeze({
269
+ accounts: [
270
+ getAccountMeta(accounts.optionPool),
271
+ getAccountMeta(accounts.optionAccount),
272
+ getAccountMeta(accounts.makerPoolShare),
273
+ getAccountMeta(accounts.makerOptionAccount),
274
+ getAccountMeta(accounts.escrowLongAccount),
275
+ getAccountMeta(accounts.maker),
276
+ getAccountMeta(accounts.tokenProgram),
277
+ getAccountMeta(accounts.associatedTokenProgram),
278
+ getAccountMeta(accounts.systemProgram),
279
+ ],
280
+ data: getDepositToPoolInstructionDataEncoder().encode(
281
+ args as DepositToPoolInstructionDataArgs,
282
+ ),
283
+ programAddress,
284
+ } as DepositToPoolInstruction<
285
+ TProgramAddress,
286
+ TAccountOptionPool,
287
+ TAccountOptionAccount,
288
+ TAccountMakerPoolShare,
289
+ TAccountMakerOptionAccount,
290
+ TAccountEscrowLongAccount,
291
+ TAccountMaker,
292
+ TAccountTokenProgram,
293
+ TAccountAssociatedTokenProgram,
294
+ TAccountSystemProgram
295
+ >);
296
+ }
297
+
298
+ export type DepositToPoolInput<
299
+ TAccountOptionPool extends string = string,
300
+ TAccountOptionAccount extends string = string,
301
+ TAccountMakerPoolShare extends string = string,
302
+ TAccountMakerOptionAccount extends string = string,
303
+ TAccountEscrowLongAccount extends string = string,
304
+ TAccountMaker extends string = string,
305
+ TAccountTokenProgram extends string = string,
306
+ TAccountAssociatedTokenProgram extends string = string,
307
+ TAccountSystemProgram extends string = string,
308
+ > = {
309
+ /** The pool to deposit into */
310
+ optionPool: Address<TAccountOptionPool>;
311
+ /** The option account */
312
+ optionAccount: Address<TAccountOptionAccount>;
313
+ /** Maker's share account (created if first deposit) */
314
+ makerPoolShare: Address<TAccountMakerPoolShare>;
315
+ /** Maker's LONG token account (source of tokens) */
316
+ makerOptionAccount: Address<TAccountMakerOptionAccount>;
317
+ /** Pool's LONG escrow (destination for tokens) */
318
+ escrowLongAccount: Address<TAccountEscrowLongAccount>;
319
+ maker: TransactionSigner<TAccountMaker>;
320
+ tokenProgram?: Address<TAccountTokenProgram>;
321
+ associatedTokenProgram?: Address<TAccountAssociatedTokenProgram>;
322
+ systemProgram?: Address<TAccountSystemProgram>;
323
+ amount: DepositToPoolInstructionDataArgs["amount"];
324
+ };
325
+
326
+ export function getDepositToPoolInstruction<
327
+ TAccountOptionPool extends string,
328
+ TAccountOptionAccount extends string,
329
+ TAccountMakerPoolShare extends string,
330
+ TAccountMakerOptionAccount extends string,
331
+ TAccountEscrowLongAccount extends string,
332
+ TAccountMaker extends string,
333
+ TAccountTokenProgram extends string,
334
+ TAccountAssociatedTokenProgram extends string,
335
+ TAccountSystemProgram extends string,
336
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
337
+ >(
338
+ input: DepositToPoolInput<
339
+ TAccountOptionPool,
340
+ TAccountOptionAccount,
341
+ TAccountMakerPoolShare,
342
+ TAccountMakerOptionAccount,
343
+ TAccountEscrowLongAccount,
344
+ TAccountMaker,
345
+ TAccountTokenProgram,
346
+ TAccountAssociatedTokenProgram,
347
+ TAccountSystemProgram
348
+ >,
349
+ config?: { programAddress?: TProgramAddress },
350
+ ): DepositToPoolInstruction<
351
+ TProgramAddress,
352
+ TAccountOptionPool,
353
+ TAccountOptionAccount,
354
+ TAccountMakerPoolShare,
355
+ TAccountMakerOptionAccount,
356
+ TAccountEscrowLongAccount,
357
+ TAccountMaker,
358
+ TAccountTokenProgram,
359
+ TAccountAssociatedTokenProgram,
360
+ TAccountSystemProgram
361
+ > {
362
+ // Program address.
363
+ const programAddress =
364
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
365
+
366
+ // Original accounts.
367
+ const originalAccounts = {
368
+ optionPool: { value: input.optionPool ?? null, isWritable: true },
369
+ optionAccount: { value: input.optionAccount ?? null, isWritable: false },
370
+ makerPoolShare: { value: input.makerPoolShare ?? null, isWritable: true },
371
+ makerOptionAccount: {
372
+ value: input.makerOptionAccount ?? null,
373
+ isWritable: true,
374
+ },
375
+ escrowLongAccount: {
376
+ value: input.escrowLongAccount ?? null,
377
+ isWritable: true,
378
+ },
379
+ maker: { value: input.maker ?? null, isWritable: true },
380
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
381
+ associatedTokenProgram: {
382
+ value: input.associatedTokenProgram ?? null,
383
+ isWritable: false,
384
+ },
385
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
386
+ };
387
+ const accounts = originalAccounts as Record<
388
+ keyof typeof originalAccounts,
389
+ ResolvedAccount
390
+ >;
391
+
392
+ // Original args.
393
+ const args = { ...input };
394
+
395
+ // Resolve default values.
396
+ if (!accounts.tokenProgram.value) {
397
+ accounts.tokenProgram.value =
398
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
399
+ }
400
+ if (!accounts.associatedTokenProgram.value) {
401
+ accounts.associatedTokenProgram.value =
402
+ "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
403
+ }
404
+ if (!accounts.systemProgram.value) {
405
+ accounts.systemProgram.value =
406
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
407
+ }
408
+
409
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
410
+ return Object.freeze({
411
+ accounts: [
412
+ getAccountMeta(accounts.optionPool),
413
+ getAccountMeta(accounts.optionAccount),
414
+ getAccountMeta(accounts.makerPoolShare),
415
+ getAccountMeta(accounts.makerOptionAccount),
416
+ getAccountMeta(accounts.escrowLongAccount),
417
+ getAccountMeta(accounts.maker),
418
+ getAccountMeta(accounts.tokenProgram),
419
+ getAccountMeta(accounts.associatedTokenProgram),
420
+ getAccountMeta(accounts.systemProgram),
421
+ ],
422
+ data: getDepositToPoolInstructionDataEncoder().encode(
423
+ args as DepositToPoolInstructionDataArgs,
424
+ ),
425
+ programAddress,
426
+ } as DepositToPoolInstruction<
427
+ TProgramAddress,
428
+ TAccountOptionPool,
429
+ TAccountOptionAccount,
430
+ TAccountMakerPoolShare,
431
+ TAccountMakerOptionAccount,
432
+ TAccountEscrowLongAccount,
433
+ TAccountMaker,
434
+ TAccountTokenProgram,
435
+ TAccountAssociatedTokenProgram,
436
+ TAccountSystemProgram
437
+ >);
438
+ }
439
+
440
+ export type ParsedDepositToPoolInstruction<
441
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
442
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
443
+ > = {
444
+ programAddress: Address<TProgram>;
445
+ accounts: {
446
+ /** The pool to deposit into */
447
+ optionPool: TAccountMetas[0];
448
+ /** The option account */
449
+ optionAccount: TAccountMetas[1];
450
+ /** Maker's share account (created if first deposit) */
451
+ makerPoolShare: TAccountMetas[2];
452
+ /** Maker's LONG token account (source of tokens) */
453
+ makerOptionAccount: TAccountMetas[3];
454
+ /** Pool's LONG escrow (destination for tokens) */
455
+ escrowLongAccount: TAccountMetas[4];
456
+ maker: TAccountMetas[5];
457
+ tokenProgram: TAccountMetas[6];
458
+ associatedTokenProgram: TAccountMetas[7];
459
+ systemProgram: TAccountMetas[8];
460
+ };
461
+ data: DepositToPoolInstructionData;
462
+ };
463
+
464
+ export function parseDepositToPoolInstruction<
465
+ TProgram extends string,
466
+ TAccountMetas extends readonly AccountMeta[],
467
+ >(
468
+ instruction: Instruction<TProgram> &
469
+ InstructionWithAccounts<TAccountMetas> &
470
+ InstructionWithData<ReadonlyUint8Array>,
471
+ ): ParsedDepositToPoolInstruction<TProgram, TAccountMetas> {
472
+ if (instruction.accounts.length < 9) {
473
+ // TODO: Coded error.
474
+ throw new Error("Not enough accounts");
475
+ }
476
+ let accountIndex = 0;
477
+ const getNextAccount = () => {
478
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
479
+ accountIndex += 1;
480
+ return accountMeta;
481
+ };
482
+ return {
483
+ programAddress: instruction.programAddress,
484
+ accounts: {
485
+ optionPool: getNextAccount(),
486
+ optionAccount: getNextAccount(),
487
+ makerPoolShare: getNextAccount(),
488
+ makerOptionAccount: getNextAccount(),
489
+ escrowLongAccount: getNextAccount(),
490
+ maker: getNextAccount(),
491
+ tokenProgram: getNextAccount(),
492
+ associatedTokenProgram: getNextAccount(),
493
+ systemProgram: getNextAccount(),
494
+ },
495
+ data: getDepositToPoolInstructionDataDecoder().decode(instruction.data),
496
+ };
497
+ }