@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,513 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import {
10
+ combineCodec,
11
+ fixDecoderSize,
12
+ fixEncoderSize,
13
+ getAddressEncoder,
14
+ getBytesDecoder,
15
+ getBytesEncoder,
16
+ getProgramDerivedAddress,
17
+ getStructDecoder,
18
+ getStructEncoder,
19
+ transformEncoder,
20
+ type AccountMeta,
21
+ type AccountSignerMeta,
22
+ type Address,
23
+ type FixedSizeCodec,
24
+ type FixedSizeDecoder,
25
+ type FixedSizeEncoder,
26
+ type Instruction,
27
+ type InstructionWithAccounts,
28
+ type InstructionWithData,
29
+ type ReadonlyAccount,
30
+ type ReadonlyUint8Array,
31
+ type TransactionSigner,
32
+ type WritableAccount,
33
+ type WritableSignerAccount,
34
+ } from "@solana/kit";
35
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
36
+ import {
37
+ expectAddress,
38
+ getAccountMetaFactory,
39
+ type ResolvedAccount,
40
+ } from "../shared";
41
+
42
+ export const INIT_COLLATERAL_POOL_DISCRIMINATOR = new Uint8Array([
43
+ 76, 233, 1, 25, 52, 227, 208, 101,
44
+ ]);
45
+
46
+ export function getInitCollateralPoolDiscriminatorBytes() {
47
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
48
+ INIT_COLLATERAL_POOL_DISCRIMINATOR,
49
+ );
50
+ }
51
+
52
+ export type InitCollateralPoolInstruction<
53
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
54
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
55
+ TAccountOptionPool extends string | AccountMeta<string> = string,
56
+ TAccountCollateralPool extends string | AccountMeta<string> = string,
57
+ TAccountCollateralMint extends string | AccountMeta<string> = string,
58
+ TAccountCollateralVault extends string | AccountMeta<string> = string,
59
+ TAccountPayer extends string | AccountMeta<string> = string,
60
+ TAccountSystemProgram extends string | AccountMeta<string> =
61
+ "11111111111111111111111111111111",
62
+ TAccountTokenProgram extends string | AccountMeta<string> =
63
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
64
+ TAccountAssociatedTokenProgram extends string | AccountMeta<string> =
65
+ "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
66
+ TAccountRent extends string | AccountMeta<string> =
67
+ "SysvarRent111111111111111111111111111111111",
68
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
69
+ > = Instruction<TProgram> &
70
+ InstructionWithData<ReadonlyUint8Array> &
71
+ InstructionWithAccounts<
72
+ [
73
+ TAccountOptionAccount extends string
74
+ ? WritableAccount<TAccountOptionAccount>
75
+ : TAccountOptionAccount,
76
+ TAccountOptionPool extends string
77
+ ? ReadonlyAccount<TAccountOptionPool>
78
+ : TAccountOptionPool,
79
+ TAccountCollateralPool extends string
80
+ ? WritableAccount<TAccountCollateralPool>
81
+ : TAccountCollateralPool,
82
+ TAccountCollateralMint extends string
83
+ ? ReadonlyAccount<TAccountCollateralMint>
84
+ : TAccountCollateralMint,
85
+ TAccountCollateralVault extends string
86
+ ? WritableAccount<TAccountCollateralVault>
87
+ : TAccountCollateralVault,
88
+ TAccountPayer extends string
89
+ ? WritableSignerAccount<TAccountPayer> &
90
+ AccountSignerMeta<TAccountPayer>
91
+ : TAccountPayer,
92
+ TAccountSystemProgram extends string
93
+ ? ReadonlyAccount<TAccountSystemProgram>
94
+ : TAccountSystemProgram,
95
+ TAccountTokenProgram extends string
96
+ ? ReadonlyAccount<TAccountTokenProgram>
97
+ : TAccountTokenProgram,
98
+ TAccountAssociatedTokenProgram extends string
99
+ ? ReadonlyAccount<TAccountAssociatedTokenProgram>
100
+ : TAccountAssociatedTokenProgram,
101
+ TAccountRent extends string
102
+ ? ReadonlyAccount<TAccountRent>
103
+ : TAccountRent,
104
+ ...TRemainingAccounts,
105
+ ]
106
+ >;
107
+
108
+ export type InitCollateralPoolInstructionData = {
109
+ discriminator: ReadonlyUint8Array;
110
+ };
111
+
112
+ export type InitCollateralPoolInstructionDataArgs = {};
113
+
114
+ export function getInitCollateralPoolInstructionDataEncoder(): FixedSizeEncoder<InitCollateralPoolInstructionDataArgs> {
115
+ return transformEncoder(
116
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
117
+ (value) => ({
118
+ ...value,
119
+ discriminator: INIT_COLLATERAL_POOL_DISCRIMINATOR,
120
+ }),
121
+ );
122
+ }
123
+
124
+ export function getInitCollateralPoolInstructionDataDecoder(): FixedSizeDecoder<InitCollateralPoolInstructionData> {
125
+ return getStructDecoder([
126
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
127
+ ]);
128
+ }
129
+
130
+ export function getInitCollateralPoolInstructionDataCodec(): FixedSizeCodec<
131
+ InitCollateralPoolInstructionDataArgs,
132
+ InitCollateralPoolInstructionData
133
+ > {
134
+ return combineCodec(
135
+ getInitCollateralPoolInstructionDataEncoder(),
136
+ getInitCollateralPoolInstructionDataDecoder(),
137
+ );
138
+ }
139
+
140
+ export type InitCollateralPoolAsyncInput<
141
+ TAccountOptionAccount extends string = string,
142
+ TAccountOptionPool extends string = string,
143
+ TAccountCollateralPool extends string = string,
144
+ TAccountCollateralMint extends string = string,
145
+ TAccountCollateralVault extends string = string,
146
+ TAccountPayer extends string = string,
147
+ TAccountSystemProgram extends string = string,
148
+ TAccountTokenProgram extends string = string,
149
+ TAccountAssociatedTokenProgram extends string = string,
150
+ TAccountRent extends string = string,
151
+ > = {
152
+ optionAccount: Address<TAccountOptionAccount>;
153
+ optionPool: Address<TAccountOptionPool>;
154
+ collateralPool?: Address<TAccountCollateralPool>;
155
+ /** WSOL mint */
156
+ collateralMint: Address<TAccountCollateralMint>;
157
+ /** Pool's collateral vault (ATA) */
158
+ collateralVault?: Address<TAccountCollateralVault>;
159
+ payer: TransactionSigner<TAccountPayer>;
160
+ systemProgram?: Address<TAccountSystemProgram>;
161
+ tokenProgram?: Address<TAccountTokenProgram>;
162
+ associatedTokenProgram?: Address<TAccountAssociatedTokenProgram>;
163
+ rent?: Address<TAccountRent>;
164
+ };
165
+
166
+ export async function getInitCollateralPoolInstructionAsync<
167
+ TAccountOptionAccount extends string,
168
+ TAccountOptionPool extends string,
169
+ TAccountCollateralPool extends string,
170
+ TAccountCollateralMint extends string,
171
+ TAccountCollateralVault extends string,
172
+ TAccountPayer extends string,
173
+ TAccountSystemProgram extends string,
174
+ TAccountTokenProgram extends string,
175
+ TAccountAssociatedTokenProgram extends string,
176
+ TAccountRent extends string,
177
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
178
+ >(
179
+ input: InitCollateralPoolAsyncInput<
180
+ TAccountOptionAccount,
181
+ TAccountOptionPool,
182
+ TAccountCollateralPool,
183
+ TAccountCollateralMint,
184
+ TAccountCollateralVault,
185
+ TAccountPayer,
186
+ TAccountSystemProgram,
187
+ TAccountTokenProgram,
188
+ TAccountAssociatedTokenProgram,
189
+ TAccountRent
190
+ >,
191
+ config?: { programAddress?: TProgramAddress },
192
+ ): Promise<
193
+ InitCollateralPoolInstruction<
194
+ TProgramAddress,
195
+ TAccountOptionAccount,
196
+ TAccountOptionPool,
197
+ TAccountCollateralPool,
198
+ TAccountCollateralMint,
199
+ TAccountCollateralVault,
200
+ TAccountPayer,
201
+ TAccountSystemProgram,
202
+ TAccountTokenProgram,
203
+ TAccountAssociatedTokenProgram,
204
+ TAccountRent
205
+ >
206
+ > {
207
+ // Program address.
208
+ const programAddress =
209
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
210
+
211
+ // Original accounts.
212
+ const originalAccounts = {
213
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
214
+ optionPool: { value: input.optionPool ?? null, isWritable: false },
215
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
216
+ collateralMint: { value: input.collateralMint ?? null, isWritable: false },
217
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
218
+ payer: { value: input.payer ?? null, isWritable: true },
219
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
220
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
221
+ associatedTokenProgram: {
222
+ value: input.associatedTokenProgram ?? null,
223
+ isWritable: false,
224
+ },
225
+ rent: { value: input.rent ?? null, isWritable: false },
226
+ };
227
+ const accounts = originalAccounts as Record<
228
+ keyof typeof originalAccounts,
229
+ ResolvedAccount
230
+ >;
231
+
232
+ // Resolve default values.
233
+ if (!accounts.collateralPool.value) {
234
+ accounts.collateralPool.value = await getProgramDerivedAddress({
235
+ programAddress,
236
+ seeds: [
237
+ getBytesEncoder().encode(
238
+ new Uint8Array([
239
+ 99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
240
+ 108,
241
+ ]),
242
+ ),
243
+ getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
244
+ ],
245
+ });
246
+ }
247
+ if (!accounts.collateralVault.value) {
248
+ accounts.collateralVault.value = await getProgramDerivedAddress({
249
+ programAddress:
250
+ "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
251
+ seeds: [
252
+ getAddressEncoder().encode(
253
+ expectAddress(accounts.collateralPool.value),
254
+ ),
255
+ getBytesEncoder().encode(
256
+ new Uint8Array([
257
+ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
258
+ 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
259
+ 126, 255, 0, 169,
260
+ ]),
261
+ ),
262
+ getAddressEncoder().encode(
263
+ expectAddress(accounts.collateralMint.value),
264
+ ),
265
+ ],
266
+ });
267
+ }
268
+ if (!accounts.systemProgram.value) {
269
+ accounts.systemProgram.value =
270
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
271
+ }
272
+ if (!accounts.tokenProgram.value) {
273
+ accounts.tokenProgram.value =
274
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
275
+ }
276
+ if (!accounts.associatedTokenProgram.value) {
277
+ accounts.associatedTokenProgram.value =
278
+ "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
279
+ }
280
+ if (!accounts.rent.value) {
281
+ accounts.rent.value =
282
+ "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">;
283
+ }
284
+
285
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
286
+ return Object.freeze({
287
+ accounts: [
288
+ getAccountMeta(accounts.optionAccount),
289
+ getAccountMeta(accounts.optionPool),
290
+ getAccountMeta(accounts.collateralPool),
291
+ getAccountMeta(accounts.collateralMint),
292
+ getAccountMeta(accounts.collateralVault),
293
+ getAccountMeta(accounts.payer),
294
+ getAccountMeta(accounts.systemProgram),
295
+ getAccountMeta(accounts.tokenProgram),
296
+ getAccountMeta(accounts.associatedTokenProgram),
297
+ getAccountMeta(accounts.rent),
298
+ ],
299
+ data: getInitCollateralPoolInstructionDataEncoder().encode({}),
300
+ programAddress,
301
+ } as InitCollateralPoolInstruction<
302
+ TProgramAddress,
303
+ TAccountOptionAccount,
304
+ TAccountOptionPool,
305
+ TAccountCollateralPool,
306
+ TAccountCollateralMint,
307
+ TAccountCollateralVault,
308
+ TAccountPayer,
309
+ TAccountSystemProgram,
310
+ TAccountTokenProgram,
311
+ TAccountAssociatedTokenProgram,
312
+ TAccountRent
313
+ >);
314
+ }
315
+
316
+ export type InitCollateralPoolInput<
317
+ TAccountOptionAccount extends string = string,
318
+ TAccountOptionPool extends string = string,
319
+ TAccountCollateralPool extends string = string,
320
+ TAccountCollateralMint extends string = string,
321
+ TAccountCollateralVault extends string = string,
322
+ TAccountPayer extends string = string,
323
+ TAccountSystemProgram extends string = string,
324
+ TAccountTokenProgram extends string = string,
325
+ TAccountAssociatedTokenProgram extends string = string,
326
+ TAccountRent extends string = string,
327
+ > = {
328
+ optionAccount: Address<TAccountOptionAccount>;
329
+ optionPool: Address<TAccountOptionPool>;
330
+ collateralPool: Address<TAccountCollateralPool>;
331
+ /** WSOL mint */
332
+ collateralMint: Address<TAccountCollateralMint>;
333
+ /** Pool's collateral vault (ATA) */
334
+ collateralVault: Address<TAccountCollateralVault>;
335
+ payer: TransactionSigner<TAccountPayer>;
336
+ systemProgram?: Address<TAccountSystemProgram>;
337
+ tokenProgram?: Address<TAccountTokenProgram>;
338
+ associatedTokenProgram?: Address<TAccountAssociatedTokenProgram>;
339
+ rent?: Address<TAccountRent>;
340
+ };
341
+
342
+ export function getInitCollateralPoolInstruction<
343
+ TAccountOptionAccount extends string,
344
+ TAccountOptionPool extends string,
345
+ TAccountCollateralPool extends string,
346
+ TAccountCollateralMint extends string,
347
+ TAccountCollateralVault extends string,
348
+ TAccountPayer extends string,
349
+ TAccountSystemProgram extends string,
350
+ TAccountTokenProgram extends string,
351
+ TAccountAssociatedTokenProgram extends string,
352
+ TAccountRent extends string,
353
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
354
+ >(
355
+ input: InitCollateralPoolInput<
356
+ TAccountOptionAccount,
357
+ TAccountOptionPool,
358
+ TAccountCollateralPool,
359
+ TAccountCollateralMint,
360
+ TAccountCollateralVault,
361
+ TAccountPayer,
362
+ TAccountSystemProgram,
363
+ TAccountTokenProgram,
364
+ TAccountAssociatedTokenProgram,
365
+ TAccountRent
366
+ >,
367
+ config?: { programAddress?: TProgramAddress },
368
+ ): InitCollateralPoolInstruction<
369
+ TProgramAddress,
370
+ TAccountOptionAccount,
371
+ TAccountOptionPool,
372
+ TAccountCollateralPool,
373
+ TAccountCollateralMint,
374
+ TAccountCollateralVault,
375
+ TAccountPayer,
376
+ TAccountSystemProgram,
377
+ TAccountTokenProgram,
378
+ TAccountAssociatedTokenProgram,
379
+ TAccountRent
380
+ > {
381
+ // Program address.
382
+ const programAddress =
383
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
384
+
385
+ // Original accounts.
386
+ const originalAccounts = {
387
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
388
+ optionPool: { value: input.optionPool ?? null, isWritable: false },
389
+ collateralPool: { value: input.collateralPool ?? null, isWritable: true },
390
+ collateralMint: { value: input.collateralMint ?? null, isWritable: false },
391
+ collateralVault: { value: input.collateralVault ?? null, isWritable: true },
392
+ payer: { value: input.payer ?? null, isWritable: true },
393
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
394
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
395
+ associatedTokenProgram: {
396
+ value: input.associatedTokenProgram ?? null,
397
+ isWritable: false,
398
+ },
399
+ rent: { value: input.rent ?? null, isWritable: false },
400
+ };
401
+ const accounts = originalAccounts as Record<
402
+ keyof typeof originalAccounts,
403
+ ResolvedAccount
404
+ >;
405
+
406
+ // Resolve default values.
407
+ if (!accounts.systemProgram.value) {
408
+ accounts.systemProgram.value =
409
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
410
+ }
411
+ if (!accounts.tokenProgram.value) {
412
+ accounts.tokenProgram.value =
413
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
414
+ }
415
+ if (!accounts.associatedTokenProgram.value) {
416
+ accounts.associatedTokenProgram.value =
417
+ "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
418
+ }
419
+ if (!accounts.rent.value) {
420
+ accounts.rent.value =
421
+ "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">;
422
+ }
423
+
424
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
425
+ return Object.freeze({
426
+ accounts: [
427
+ getAccountMeta(accounts.optionAccount),
428
+ getAccountMeta(accounts.optionPool),
429
+ getAccountMeta(accounts.collateralPool),
430
+ getAccountMeta(accounts.collateralMint),
431
+ getAccountMeta(accounts.collateralVault),
432
+ getAccountMeta(accounts.payer),
433
+ getAccountMeta(accounts.systemProgram),
434
+ getAccountMeta(accounts.tokenProgram),
435
+ getAccountMeta(accounts.associatedTokenProgram),
436
+ getAccountMeta(accounts.rent),
437
+ ],
438
+ data: getInitCollateralPoolInstructionDataEncoder().encode({}),
439
+ programAddress,
440
+ } as InitCollateralPoolInstruction<
441
+ TProgramAddress,
442
+ TAccountOptionAccount,
443
+ TAccountOptionPool,
444
+ TAccountCollateralPool,
445
+ TAccountCollateralMint,
446
+ TAccountCollateralVault,
447
+ TAccountPayer,
448
+ TAccountSystemProgram,
449
+ TAccountTokenProgram,
450
+ TAccountAssociatedTokenProgram,
451
+ TAccountRent
452
+ >);
453
+ }
454
+
455
+ export type ParsedInitCollateralPoolInstruction<
456
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
457
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
458
+ > = {
459
+ programAddress: Address<TProgram>;
460
+ accounts: {
461
+ optionAccount: TAccountMetas[0];
462
+ optionPool: TAccountMetas[1];
463
+ collateralPool: TAccountMetas[2];
464
+ /** WSOL mint */
465
+ collateralMint: TAccountMetas[3];
466
+ /** Pool's collateral vault (ATA) */
467
+ collateralVault: TAccountMetas[4];
468
+ payer: TAccountMetas[5];
469
+ systemProgram: TAccountMetas[6];
470
+ tokenProgram: TAccountMetas[7];
471
+ associatedTokenProgram: TAccountMetas[8];
472
+ rent: TAccountMetas[9];
473
+ };
474
+ data: InitCollateralPoolInstructionData;
475
+ };
476
+
477
+ export function parseInitCollateralPoolInstruction<
478
+ TProgram extends string,
479
+ TAccountMetas extends readonly AccountMeta[],
480
+ >(
481
+ instruction: Instruction<TProgram> &
482
+ InstructionWithAccounts<TAccountMetas> &
483
+ InstructionWithData<ReadonlyUint8Array>,
484
+ ): ParsedInitCollateralPoolInstruction<TProgram, TAccountMetas> {
485
+ if (instruction.accounts.length < 10) {
486
+ // TODO: Coded error.
487
+ throw new Error("Not enough accounts");
488
+ }
489
+ let accountIndex = 0;
490
+ const getNextAccount = () => {
491
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
492
+ accountIndex += 1;
493
+ return accountMeta;
494
+ };
495
+ return {
496
+ programAddress: instruction.programAddress,
497
+ accounts: {
498
+ optionAccount: getNextAccount(),
499
+ optionPool: getNextAccount(),
500
+ collateralPool: getNextAccount(),
501
+ collateralMint: getNextAccount(),
502
+ collateralVault: getNextAccount(),
503
+ payer: getNextAccount(),
504
+ systemProgram: getNextAccount(),
505
+ tokenProgram: getNextAccount(),
506
+ associatedTokenProgram: getNextAccount(),
507
+ rent: getNextAccount(),
508
+ },
509
+ data: getInitCollateralPoolInstructionDataDecoder().decode(
510
+ instruction.data,
511
+ ),
512
+ };
513
+ }