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