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