@epicentral/sos-sdk 0.15.2-beta → 0.16.0-beta
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.
- package/README.md +4 -0
- package/generated/errors/optionProgram.ts +12 -0
- package/generated/instructions/index.ts +2 -0
- package/generated/instructions/initOptionSeries.ts +971 -0
- package/generated/instructions/optionMintMulti.ts +607 -0
- package/generated/programs/optionProgram.ts +32 -0
- package/generated/types/index.ts +1 -0
- package/generated/types/mintLegArgs.ts +67 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/shared/option-program-parser.ts +12 -0
- package/short/multi-mint.ts +403 -0
|
@@ -0,0 +1,971 @@
|
|
|
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
|
+
getAddressDecoder,
|
|
14
|
+
getAddressEncoder,
|
|
15
|
+
getBytesDecoder,
|
|
16
|
+
getBytesEncoder,
|
|
17
|
+
getF64Decoder,
|
|
18
|
+
getF64Encoder,
|
|
19
|
+
getI64Decoder,
|
|
20
|
+
getI64Encoder,
|
|
21
|
+
getProgramDerivedAddress,
|
|
22
|
+
getStructDecoder,
|
|
23
|
+
getStructEncoder,
|
|
24
|
+
transformEncoder,
|
|
25
|
+
type AccountMeta,
|
|
26
|
+
type AccountSignerMeta,
|
|
27
|
+
type Address,
|
|
28
|
+
type FixedSizeCodec,
|
|
29
|
+
type FixedSizeDecoder,
|
|
30
|
+
type FixedSizeEncoder,
|
|
31
|
+
type Instruction,
|
|
32
|
+
type InstructionWithAccounts,
|
|
33
|
+
type InstructionWithData,
|
|
34
|
+
type ReadonlyAccount,
|
|
35
|
+
type ReadonlyUint8Array,
|
|
36
|
+
type TransactionSigner,
|
|
37
|
+
type WritableAccount,
|
|
38
|
+
type WritableSignerAccount,
|
|
39
|
+
} from "@solana/kit";
|
|
40
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
41
|
+
import {
|
|
42
|
+
expectAddress,
|
|
43
|
+
expectSome,
|
|
44
|
+
getAccountMetaFactory,
|
|
45
|
+
type ResolvedAccount,
|
|
46
|
+
} from "../shared";
|
|
47
|
+
import {
|
|
48
|
+
getOptionTypeDecoder,
|
|
49
|
+
getOptionTypeEncoder,
|
|
50
|
+
type OptionType,
|
|
51
|
+
type OptionTypeArgs,
|
|
52
|
+
} from "../types";
|
|
53
|
+
|
|
54
|
+
export const INIT_OPTION_SERIES_DISCRIMINATOR = new Uint8Array([
|
|
55
|
+
5, 9, 41, 96, 87, 149, 105, 169,
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
export function getInitOptionSeriesDiscriminatorBytes() {
|
|
59
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
60
|
+
INIT_OPTION_SERIES_DISCRIMINATOR,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type InitOptionSeriesInstruction<
|
|
65
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
66
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
67
|
+
TAccountLongMint extends string | AccountMeta<string> = string,
|
|
68
|
+
TAccountShortMint extends string | AccountMeta<string> = string,
|
|
69
|
+
TAccountMintAuthority extends string | AccountMeta<string> = string,
|
|
70
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
71
|
+
TAccountVolatilityQuoteAccount extends string | AccountMeta<string> = string,
|
|
72
|
+
TAccountUnderlyingMint extends string | AccountMeta<string> = string,
|
|
73
|
+
TAccountCollateralMint extends string | AccountMeta<string> = string,
|
|
74
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
75
|
+
TAccountEscrowLongAccount extends string | AccountMeta<string> = string,
|
|
76
|
+
TAccountPremiumVault extends string | AccountMeta<string> = string,
|
|
77
|
+
TAccountCollateralPool extends string | AccountMeta<string> = string,
|
|
78
|
+
TAccountCollateralVault extends string | AccountMeta<string> = string,
|
|
79
|
+
TAccountMakerShortAccount extends string | AccountMeta<string> = string,
|
|
80
|
+
TAccountWriterPosition extends string | AccountMeta<string> = string,
|
|
81
|
+
TAccountMaker extends string | AccountMeta<string> = string,
|
|
82
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
83
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
84
|
+
TAccountAssociatedTokenProgram extends string | AccountMeta<string> =
|
|
85
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
86
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
87
|
+
"11111111111111111111111111111111",
|
|
88
|
+
TAccountRent extends string | AccountMeta<string> =
|
|
89
|
+
"SysvarRent111111111111111111111111111111111",
|
|
90
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
91
|
+
> = Instruction<TProgram> &
|
|
92
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
93
|
+
InstructionWithAccounts<
|
|
94
|
+
[
|
|
95
|
+
TAccountOptionAccount extends string
|
|
96
|
+
? WritableAccount<TAccountOptionAccount>
|
|
97
|
+
: TAccountOptionAccount,
|
|
98
|
+
TAccountLongMint extends string
|
|
99
|
+
? WritableAccount<TAccountLongMint>
|
|
100
|
+
: TAccountLongMint,
|
|
101
|
+
TAccountShortMint extends string
|
|
102
|
+
? WritableAccount<TAccountShortMint>
|
|
103
|
+
: TAccountShortMint,
|
|
104
|
+
TAccountMintAuthority extends string
|
|
105
|
+
? ReadonlyAccount<TAccountMintAuthority>
|
|
106
|
+
: TAccountMintAuthority,
|
|
107
|
+
TAccountMarketData extends string
|
|
108
|
+
? ReadonlyAccount<TAccountMarketData>
|
|
109
|
+
: TAccountMarketData,
|
|
110
|
+
TAccountVolatilityQuoteAccount extends string
|
|
111
|
+
? ReadonlyAccount<TAccountVolatilityQuoteAccount>
|
|
112
|
+
: TAccountVolatilityQuoteAccount,
|
|
113
|
+
TAccountUnderlyingMint extends string
|
|
114
|
+
? ReadonlyAccount<TAccountUnderlyingMint>
|
|
115
|
+
: TAccountUnderlyingMint,
|
|
116
|
+
TAccountCollateralMint extends string
|
|
117
|
+
? ReadonlyAccount<TAccountCollateralMint>
|
|
118
|
+
: TAccountCollateralMint,
|
|
119
|
+
TAccountOptionPool extends string
|
|
120
|
+
? WritableAccount<TAccountOptionPool>
|
|
121
|
+
: TAccountOptionPool,
|
|
122
|
+
TAccountEscrowLongAccount extends string
|
|
123
|
+
? WritableAccount<TAccountEscrowLongAccount>
|
|
124
|
+
: TAccountEscrowLongAccount,
|
|
125
|
+
TAccountPremiumVault extends string
|
|
126
|
+
? WritableAccount<TAccountPremiumVault>
|
|
127
|
+
: TAccountPremiumVault,
|
|
128
|
+
TAccountCollateralPool extends string
|
|
129
|
+
? WritableAccount<TAccountCollateralPool>
|
|
130
|
+
: TAccountCollateralPool,
|
|
131
|
+
TAccountCollateralVault extends string
|
|
132
|
+
? WritableAccount<TAccountCollateralVault>
|
|
133
|
+
: TAccountCollateralVault,
|
|
134
|
+
TAccountMakerShortAccount extends string
|
|
135
|
+
? WritableAccount<TAccountMakerShortAccount>
|
|
136
|
+
: TAccountMakerShortAccount,
|
|
137
|
+
TAccountWriterPosition extends string
|
|
138
|
+
? WritableAccount<TAccountWriterPosition>
|
|
139
|
+
: TAccountWriterPosition,
|
|
140
|
+
TAccountMaker extends string
|
|
141
|
+
? WritableSignerAccount<TAccountMaker> &
|
|
142
|
+
AccountSignerMeta<TAccountMaker>
|
|
143
|
+
: TAccountMaker,
|
|
144
|
+
TAccountTokenProgram extends string
|
|
145
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
146
|
+
: TAccountTokenProgram,
|
|
147
|
+
TAccountAssociatedTokenProgram extends string
|
|
148
|
+
? ReadonlyAccount<TAccountAssociatedTokenProgram>
|
|
149
|
+
: TAccountAssociatedTokenProgram,
|
|
150
|
+
TAccountSystemProgram extends string
|
|
151
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
152
|
+
: TAccountSystemProgram,
|
|
153
|
+
TAccountRent extends string
|
|
154
|
+
? ReadonlyAccount<TAccountRent>
|
|
155
|
+
: TAccountRent,
|
|
156
|
+
...TRemainingAccounts,
|
|
157
|
+
]
|
|
158
|
+
>;
|
|
159
|
+
|
|
160
|
+
export type InitOptionSeriesInstructionData = {
|
|
161
|
+
discriminator: ReadonlyUint8Array;
|
|
162
|
+
optionType: OptionType;
|
|
163
|
+
strikePrice: number;
|
|
164
|
+
expirationDate: bigint;
|
|
165
|
+
underlyingAsset: Address;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export type InitOptionSeriesInstructionDataArgs = {
|
|
169
|
+
optionType: OptionTypeArgs;
|
|
170
|
+
strikePrice: number;
|
|
171
|
+
expirationDate: number | bigint;
|
|
172
|
+
underlyingAsset: Address;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export function getInitOptionSeriesInstructionDataEncoder(): FixedSizeEncoder<InitOptionSeriesInstructionDataArgs> {
|
|
176
|
+
return transformEncoder(
|
|
177
|
+
getStructEncoder([
|
|
178
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
179
|
+
["optionType", getOptionTypeEncoder()],
|
|
180
|
+
["strikePrice", getF64Encoder()],
|
|
181
|
+
["expirationDate", getI64Encoder()],
|
|
182
|
+
["underlyingAsset", getAddressEncoder()],
|
|
183
|
+
]),
|
|
184
|
+
(value) => ({ ...value, discriminator: INIT_OPTION_SERIES_DISCRIMINATOR }),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function getInitOptionSeriesInstructionDataDecoder(): FixedSizeDecoder<InitOptionSeriesInstructionData> {
|
|
189
|
+
return getStructDecoder([
|
|
190
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
191
|
+
["optionType", getOptionTypeDecoder()],
|
|
192
|
+
["strikePrice", getF64Decoder()],
|
|
193
|
+
["expirationDate", getI64Decoder()],
|
|
194
|
+
["underlyingAsset", getAddressDecoder()],
|
|
195
|
+
]);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function getInitOptionSeriesInstructionDataCodec(): FixedSizeCodec<
|
|
199
|
+
InitOptionSeriesInstructionDataArgs,
|
|
200
|
+
InitOptionSeriesInstructionData
|
|
201
|
+
> {
|
|
202
|
+
return combineCodec(
|
|
203
|
+
getInitOptionSeriesInstructionDataEncoder(),
|
|
204
|
+
getInitOptionSeriesInstructionDataDecoder(),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export type InitOptionSeriesAsyncInput<
|
|
209
|
+
TAccountOptionAccount extends string = string,
|
|
210
|
+
TAccountLongMint extends string = string,
|
|
211
|
+
TAccountShortMint extends string = string,
|
|
212
|
+
TAccountMintAuthority extends string = string,
|
|
213
|
+
TAccountMarketData extends string = string,
|
|
214
|
+
TAccountVolatilityQuoteAccount extends string = string,
|
|
215
|
+
TAccountUnderlyingMint extends string = string,
|
|
216
|
+
TAccountCollateralMint extends string = string,
|
|
217
|
+
TAccountOptionPool extends string = string,
|
|
218
|
+
TAccountEscrowLongAccount extends string = string,
|
|
219
|
+
TAccountPremiumVault extends string = string,
|
|
220
|
+
TAccountCollateralPool extends string = string,
|
|
221
|
+
TAccountCollateralVault extends string = string,
|
|
222
|
+
TAccountMakerShortAccount extends string = string,
|
|
223
|
+
TAccountWriterPosition extends string = string,
|
|
224
|
+
TAccountMaker extends string = string,
|
|
225
|
+
TAccountTokenProgram extends string = string,
|
|
226
|
+
TAccountAssociatedTokenProgram extends string = string,
|
|
227
|
+
TAccountSystemProgram extends string = string,
|
|
228
|
+
TAccountRent extends string = string,
|
|
229
|
+
> = {
|
|
230
|
+
optionAccount?: Address<TAccountOptionAccount>;
|
|
231
|
+
longMint?: Address<TAccountLongMint>;
|
|
232
|
+
shortMint?: Address<TAccountShortMint>;
|
|
233
|
+
mintAuthority?: Address<TAccountMintAuthority>;
|
|
234
|
+
/** Market data account — baseline historical volatility for the initial IV */
|
|
235
|
+
marketData?: Address<TAccountMarketData>;
|
|
236
|
+
volatilityQuoteAccount: Address<TAccountVolatilityQuoteAccount>;
|
|
237
|
+
/** Underlying asset mint */
|
|
238
|
+
underlyingMint: Address<TAccountUnderlyingMint>;
|
|
239
|
+
/** Collateral mint chosen for this series' collateral pool */
|
|
240
|
+
collateralMint: Address<TAccountCollateralMint>;
|
|
241
|
+
optionPool?: Address<TAccountOptionPool>;
|
|
242
|
+
/** Pool's escrow for holding LONG tokens */
|
|
243
|
+
escrowLongAccount?: Address<TAccountEscrowLongAccount>;
|
|
244
|
+
/** Pool vault for premiums */
|
|
245
|
+
premiumVault?: Address<TAccountPremiumVault>;
|
|
246
|
+
collateralPool?: Address<TAccountCollateralPool>;
|
|
247
|
+
/** Collateral vault (ATA holding collateral) */
|
|
248
|
+
collateralVault?: Address<TAccountCollateralVault>;
|
|
249
|
+
/**
|
|
250
|
+
* Maker's SHORT token ATA (pre-created so option_mint_multi can mint to it
|
|
251
|
+
* via remaining_accounts without init_if_needed)
|
|
252
|
+
*/
|
|
253
|
+
makerShortAccount?: Address<TAccountMakerShortAccount>;
|
|
254
|
+
/**
|
|
255
|
+
* Maker's writer position — allocated here (created_at stays 0 so the
|
|
256
|
+
* mint paths still treat the first mint as a new maker)
|
|
257
|
+
*/
|
|
258
|
+
writerPosition?: Address<TAccountWriterPosition>;
|
|
259
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
260
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
261
|
+
associatedTokenProgram?: Address<TAccountAssociatedTokenProgram>;
|
|
262
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
263
|
+
rent?: Address<TAccountRent>;
|
|
264
|
+
optionType: InitOptionSeriesInstructionDataArgs["optionType"];
|
|
265
|
+
strikePrice: InitOptionSeriesInstructionDataArgs["strikePrice"];
|
|
266
|
+
expirationDate: InitOptionSeriesInstructionDataArgs["expirationDate"];
|
|
267
|
+
underlyingAsset: InitOptionSeriesInstructionDataArgs["underlyingAsset"];
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export async function getInitOptionSeriesInstructionAsync<
|
|
271
|
+
TAccountOptionAccount extends string,
|
|
272
|
+
TAccountLongMint extends string,
|
|
273
|
+
TAccountShortMint extends string,
|
|
274
|
+
TAccountMintAuthority extends string,
|
|
275
|
+
TAccountMarketData extends string,
|
|
276
|
+
TAccountVolatilityQuoteAccount extends string,
|
|
277
|
+
TAccountUnderlyingMint extends string,
|
|
278
|
+
TAccountCollateralMint extends string,
|
|
279
|
+
TAccountOptionPool extends string,
|
|
280
|
+
TAccountEscrowLongAccount extends string,
|
|
281
|
+
TAccountPremiumVault extends string,
|
|
282
|
+
TAccountCollateralPool extends string,
|
|
283
|
+
TAccountCollateralVault extends string,
|
|
284
|
+
TAccountMakerShortAccount extends string,
|
|
285
|
+
TAccountWriterPosition extends string,
|
|
286
|
+
TAccountMaker extends string,
|
|
287
|
+
TAccountTokenProgram extends string,
|
|
288
|
+
TAccountAssociatedTokenProgram extends string,
|
|
289
|
+
TAccountSystemProgram extends string,
|
|
290
|
+
TAccountRent extends string,
|
|
291
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
292
|
+
>(
|
|
293
|
+
input: InitOptionSeriesAsyncInput<
|
|
294
|
+
TAccountOptionAccount,
|
|
295
|
+
TAccountLongMint,
|
|
296
|
+
TAccountShortMint,
|
|
297
|
+
TAccountMintAuthority,
|
|
298
|
+
TAccountMarketData,
|
|
299
|
+
TAccountVolatilityQuoteAccount,
|
|
300
|
+
TAccountUnderlyingMint,
|
|
301
|
+
TAccountCollateralMint,
|
|
302
|
+
TAccountOptionPool,
|
|
303
|
+
TAccountEscrowLongAccount,
|
|
304
|
+
TAccountPremiumVault,
|
|
305
|
+
TAccountCollateralPool,
|
|
306
|
+
TAccountCollateralVault,
|
|
307
|
+
TAccountMakerShortAccount,
|
|
308
|
+
TAccountWriterPosition,
|
|
309
|
+
TAccountMaker,
|
|
310
|
+
TAccountTokenProgram,
|
|
311
|
+
TAccountAssociatedTokenProgram,
|
|
312
|
+
TAccountSystemProgram,
|
|
313
|
+
TAccountRent
|
|
314
|
+
>,
|
|
315
|
+
config?: { programAddress?: TProgramAddress },
|
|
316
|
+
): Promise<
|
|
317
|
+
InitOptionSeriesInstruction<
|
|
318
|
+
TProgramAddress,
|
|
319
|
+
TAccountOptionAccount,
|
|
320
|
+
TAccountLongMint,
|
|
321
|
+
TAccountShortMint,
|
|
322
|
+
TAccountMintAuthority,
|
|
323
|
+
TAccountMarketData,
|
|
324
|
+
TAccountVolatilityQuoteAccount,
|
|
325
|
+
TAccountUnderlyingMint,
|
|
326
|
+
TAccountCollateralMint,
|
|
327
|
+
TAccountOptionPool,
|
|
328
|
+
TAccountEscrowLongAccount,
|
|
329
|
+
TAccountPremiumVault,
|
|
330
|
+
TAccountCollateralPool,
|
|
331
|
+
TAccountCollateralVault,
|
|
332
|
+
TAccountMakerShortAccount,
|
|
333
|
+
TAccountWriterPosition,
|
|
334
|
+
TAccountMaker,
|
|
335
|
+
TAccountTokenProgram,
|
|
336
|
+
TAccountAssociatedTokenProgram,
|
|
337
|
+
TAccountSystemProgram,
|
|
338
|
+
TAccountRent
|
|
339
|
+
>
|
|
340
|
+
> {
|
|
341
|
+
// Program address.
|
|
342
|
+
const programAddress =
|
|
343
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
344
|
+
|
|
345
|
+
// Original accounts.
|
|
346
|
+
const originalAccounts = {
|
|
347
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
348
|
+
longMint: { value: input.longMint ?? null, isWritable: true },
|
|
349
|
+
shortMint: { value: input.shortMint ?? null, isWritable: true },
|
|
350
|
+
mintAuthority: { value: input.mintAuthority ?? null, isWritable: false },
|
|
351
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
352
|
+
volatilityQuoteAccount: {
|
|
353
|
+
value: input.volatilityQuoteAccount ?? null,
|
|
354
|
+
isWritable: false,
|
|
355
|
+
},
|
|
356
|
+
underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
|
|
357
|
+
collateralMint: { value: input.collateralMint ?? null, isWritable: false },
|
|
358
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
359
|
+
escrowLongAccount: {
|
|
360
|
+
value: input.escrowLongAccount ?? null,
|
|
361
|
+
isWritable: true,
|
|
362
|
+
},
|
|
363
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
364
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
365
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
366
|
+
makerShortAccount: {
|
|
367
|
+
value: input.makerShortAccount ?? null,
|
|
368
|
+
isWritable: true,
|
|
369
|
+
},
|
|
370
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
371
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
372
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
373
|
+
associatedTokenProgram: {
|
|
374
|
+
value: input.associatedTokenProgram ?? null,
|
|
375
|
+
isWritable: false,
|
|
376
|
+
},
|
|
377
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
378
|
+
rent: { value: input.rent ?? null, isWritable: false },
|
|
379
|
+
};
|
|
380
|
+
const accounts = originalAccounts as Record<
|
|
381
|
+
keyof typeof originalAccounts,
|
|
382
|
+
ResolvedAccount
|
|
383
|
+
>;
|
|
384
|
+
|
|
385
|
+
// Original args.
|
|
386
|
+
const args = { ...input };
|
|
387
|
+
|
|
388
|
+
// Resolve default values.
|
|
389
|
+
if (!accounts.optionAccount.value) {
|
|
390
|
+
accounts.optionAccount.value = await getProgramDerivedAddress({
|
|
391
|
+
programAddress,
|
|
392
|
+
seeds: [
|
|
393
|
+
getBytesEncoder().encode(
|
|
394
|
+
new Uint8Array([111, 112, 116, 105, 111, 110]),
|
|
395
|
+
),
|
|
396
|
+
getAddressEncoder().encode(expectSome(args.underlyingAsset)),
|
|
397
|
+
getOptionTypeEncoder().encode(expectSome(args.optionType)),
|
|
398
|
+
getF64Encoder().encode(expectSome(args.strikePrice)),
|
|
399
|
+
getI64Encoder().encode(expectSome(args.expirationDate)),
|
|
400
|
+
],
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (!accounts.longMint.value) {
|
|
404
|
+
accounts.longMint.value = await getProgramDerivedAddress({
|
|
405
|
+
programAddress,
|
|
406
|
+
seeds: [
|
|
407
|
+
getBytesEncoder().encode(
|
|
408
|
+
new Uint8Array([108, 111, 110, 103, 95, 109, 105, 110, 116]),
|
|
409
|
+
),
|
|
410
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
411
|
+
],
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
if (!accounts.shortMint.value) {
|
|
415
|
+
accounts.shortMint.value = await getProgramDerivedAddress({
|
|
416
|
+
programAddress,
|
|
417
|
+
seeds: [
|
|
418
|
+
getBytesEncoder().encode(
|
|
419
|
+
new Uint8Array([115, 104, 111, 114, 116, 95, 109, 105, 110, 116]),
|
|
420
|
+
),
|
|
421
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
422
|
+
],
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
if (!accounts.mintAuthority.value) {
|
|
426
|
+
accounts.mintAuthority.value = await getProgramDerivedAddress({
|
|
427
|
+
programAddress,
|
|
428
|
+
seeds: [
|
|
429
|
+
getBytesEncoder().encode(
|
|
430
|
+
new Uint8Array([
|
|
431
|
+
109, 105, 110, 116, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121,
|
|
432
|
+
]),
|
|
433
|
+
),
|
|
434
|
+
],
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
if (!accounts.marketData.value) {
|
|
438
|
+
accounts.marketData.value = await getProgramDerivedAddress({
|
|
439
|
+
programAddress,
|
|
440
|
+
seeds: [
|
|
441
|
+
getBytesEncoder().encode(
|
|
442
|
+
new Uint8Array([109, 97, 114, 107, 101, 116, 95, 100, 97, 116, 97]),
|
|
443
|
+
),
|
|
444
|
+
getAddressEncoder().encode(expectSome(args.underlyingAsset)),
|
|
445
|
+
],
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
if (!accounts.optionPool.value) {
|
|
449
|
+
accounts.optionPool.value = await getProgramDerivedAddress({
|
|
450
|
+
programAddress,
|
|
451
|
+
seeds: [
|
|
452
|
+
getBytesEncoder().encode(
|
|
453
|
+
new Uint8Array([
|
|
454
|
+
111, 112, 116, 105, 111, 110, 95, 112, 111, 111, 108,
|
|
455
|
+
]),
|
|
456
|
+
),
|
|
457
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
458
|
+
],
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
if (!accounts.escrowLongAccount.value) {
|
|
462
|
+
accounts.escrowLongAccount.value = await getProgramDerivedAddress({
|
|
463
|
+
programAddress:
|
|
464
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
465
|
+
seeds: [
|
|
466
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
467
|
+
getBytesEncoder().encode(
|
|
468
|
+
new Uint8Array([
|
|
469
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
470
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
471
|
+
126, 255, 0, 169,
|
|
472
|
+
]),
|
|
473
|
+
),
|
|
474
|
+
getAddressEncoder().encode(expectAddress(accounts.longMint.value)),
|
|
475
|
+
],
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
if (!accounts.premiumVault.value) {
|
|
479
|
+
accounts.premiumVault.value = await getProgramDerivedAddress({
|
|
480
|
+
programAddress:
|
|
481
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
482
|
+
seeds: [
|
|
483
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
484
|
+
getBytesEncoder().encode(
|
|
485
|
+
new Uint8Array([
|
|
486
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
487
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
488
|
+
126, 255, 0, 169,
|
|
489
|
+
]),
|
|
490
|
+
),
|
|
491
|
+
getAddressEncoder().encode(
|
|
492
|
+
expectAddress(accounts.collateralMint.value),
|
|
493
|
+
),
|
|
494
|
+
],
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
if (!accounts.collateralPool.value) {
|
|
498
|
+
accounts.collateralPool.value = await getProgramDerivedAddress({
|
|
499
|
+
programAddress,
|
|
500
|
+
seeds: [
|
|
501
|
+
getBytesEncoder().encode(
|
|
502
|
+
new Uint8Array([
|
|
503
|
+
99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
|
|
504
|
+
108,
|
|
505
|
+
]),
|
|
506
|
+
),
|
|
507
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
508
|
+
],
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
if (!accounts.collateralVault.value) {
|
|
512
|
+
accounts.collateralVault.value = await getProgramDerivedAddress({
|
|
513
|
+
programAddress:
|
|
514
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
515
|
+
seeds: [
|
|
516
|
+
getAddressEncoder().encode(
|
|
517
|
+
expectAddress(accounts.collateralPool.value),
|
|
518
|
+
),
|
|
519
|
+
getBytesEncoder().encode(
|
|
520
|
+
new Uint8Array([
|
|
521
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
522
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
523
|
+
126, 255, 0, 169,
|
|
524
|
+
]),
|
|
525
|
+
),
|
|
526
|
+
getAddressEncoder().encode(
|
|
527
|
+
expectAddress(accounts.collateralMint.value),
|
|
528
|
+
),
|
|
529
|
+
],
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
if (!accounts.makerShortAccount.value) {
|
|
533
|
+
accounts.makerShortAccount.value = await getProgramDerivedAddress({
|
|
534
|
+
programAddress:
|
|
535
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
536
|
+
seeds: [
|
|
537
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
538
|
+
getBytesEncoder().encode(
|
|
539
|
+
new Uint8Array([
|
|
540
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
541
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
542
|
+
126, 255, 0, 169,
|
|
543
|
+
]),
|
|
544
|
+
),
|
|
545
|
+
getAddressEncoder().encode(expectAddress(accounts.shortMint.value)),
|
|
546
|
+
],
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
if (!accounts.writerPosition.value) {
|
|
550
|
+
accounts.writerPosition.value = await getProgramDerivedAddress({
|
|
551
|
+
programAddress,
|
|
552
|
+
seeds: [
|
|
553
|
+
getBytesEncoder().encode(
|
|
554
|
+
new Uint8Array([
|
|
555
|
+
119, 114, 105, 116, 101, 114, 95, 112, 111, 115, 105, 116, 105, 111,
|
|
556
|
+
110,
|
|
557
|
+
]),
|
|
558
|
+
),
|
|
559
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
560
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
561
|
+
],
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
if (!accounts.tokenProgram.value) {
|
|
565
|
+
accounts.tokenProgram.value =
|
|
566
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
567
|
+
}
|
|
568
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
569
|
+
accounts.associatedTokenProgram.value =
|
|
570
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
|
|
571
|
+
}
|
|
572
|
+
if (!accounts.systemProgram.value) {
|
|
573
|
+
accounts.systemProgram.value =
|
|
574
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
575
|
+
}
|
|
576
|
+
if (!accounts.rent.value) {
|
|
577
|
+
accounts.rent.value =
|
|
578
|
+
"SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
582
|
+
return Object.freeze({
|
|
583
|
+
accounts: [
|
|
584
|
+
getAccountMeta(accounts.optionAccount),
|
|
585
|
+
getAccountMeta(accounts.longMint),
|
|
586
|
+
getAccountMeta(accounts.shortMint),
|
|
587
|
+
getAccountMeta(accounts.mintAuthority),
|
|
588
|
+
getAccountMeta(accounts.marketData),
|
|
589
|
+
getAccountMeta(accounts.volatilityQuoteAccount),
|
|
590
|
+
getAccountMeta(accounts.underlyingMint),
|
|
591
|
+
getAccountMeta(accounts.collateralMint),
|
|
592
|
+
getAccountMeta(accounts.optionPool),
|
|
593
|
+
getAccountMeta(accounts.escrowLongAccount),
|
|
594
|
+
getAccountMeta(accounts.premiumVault),
|
|
595
|
+
getAccountMeta(accounts.collateralPool),
|
|
596
|
+
getAccountMeta(accounts.collateralVault),
|
|
597
|
+
getAccountMeta(accounts.makerShortAccount),
|
|
598
|
+
getAccountMeta(accounts.writerPosition),
|
|
599
|
+
getAccountMeta(accounts.maker),
|
|
600
|
+
getAccountMeta(accounts.tokenProgram),
|
|
601
|
+
getAccountMeta(accounts.associatedTokenProgram),
|
|
602
|
+
getAccountMeta(accounts.systemProgram),
|
|
603
|
+
getAccountMeta(accounts.rent),
|
|
604
|
+
],
|
|
605
|
+
data: getInitOptionSeriesInstructionDataEncoder().encode(
|
|
606
|
+
args as InitOptionSeriesInstructionDataArgs,
|
|
607
|
+
),
|
|
608
|
+
programAddress,
|
|
609
|
+
} as InitOptionSeriesInstruction<
|
|
610
|
+
TProgramAddress,
|
|
611
|
+
TAccountOptionAccount,
|
|
612
|
+
TAccountLongMint,
|
|
613
|
+
TAccountShortMint,
|
|
614
|
+
TAccountMintAuthority,
|
|
615
|
+
TAccountMarketData,
|
|
616
|
+
TAccountVolatilityQuoteAccount,
|
|
617
|
+
TAccountUnderlyingMint,
|
|
618
|
+
TAccountCollateralMint,
|
|
619
|
+
TAccountOptionPool,
|
|
620
|
+
TAccountEscrowLongAccount,
|
|
621
|
+
TAccountPremiumVault,
|
|
622
|
+
TAccountCollateralPool,
|
|
623
|
+
TAccountCollateralVault,
|
|
624
|
+
TAccountMakerShortAccount,
|
|
625
|
+
TAccountWriterPosition,
|
|
626
|
+
TAccountMaker,
|
|
627
|
+
TAccountTokenProgram,
|
|
628
|
+
TAccountAssociatedTokenProgram,
|
|
629
|
+
TAccountSystemProgram,
|
|
630
|
+
TAccountRent
|
|
631
|
+
>);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export type InitOptionSeriesInput<
|
|
635
|
+
TAccountOptionAccount extends string = string,
|
|
636
|
+
TAccountLongMint extends string = string,
|
|
637
|
+
TAccountShortMint extends string = string,
|
|
638
|
+
TAccountMintAuthority extends string = string,
|
|
639
|
+
TAccountMarketData extends string = string,
|
|
640
|
+
TAccountVolatilityQuoteAccount extends string = string,
|
|
641
|
+
TAccountUnderlyingMint extends string = string,
|
|
642
|
+
TAccountCollateralMint extends string = string,
|
|
643
|
+
TAccountOptionPool extends string = string,
|
|
644
|
+
TAccountEscrowLongAccount extends string = string,
|
|
645
|
+
TAccountPremiumVault extends string = string,
|
|
646
|
+
TAccountCollateralPool extends string = string,
|
|
647
|
+
TAccountCollateralVault extends string = string,
|
|
648
|
+
TAccountMakerShortAccount extends string = string,
|
|
649
|
+
TAccountWriterPosition extends string = string,
|
|
650
|
+
TAccountMaker extends string = string,
|
|
651
|
+
TAccountTokenProgram extends string = string,
|
|
652
|
+
TAccountAssociatedTokenProgram extends string = string,
|
|
653
|
+
TAccountSystemProgram extends string = string,
|
|
654
|
+
TAccountRent extends string = string,
|
|
655
|
+
> = {
|
|
656
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
657
|
+
longMint: Address<TAccountLongMint>;
|
|
658
|
+
shortMint: Address<TAccountShortMint>;
|
|
659
|
+
mintAuthority: Address<TAccountMintAuthority>;
|
|
660
|
+
/** Market data account — baseline historical volatility for the initial IV */
|
|
661
|
+
marketData: Address<TAccountMarketData>;
|
|
662
|
+
volatilityQuoteAccount: Address<TAccountVolatilityQuoteAccount>;
|
|
663
|
+
/** Underlying asset mint */
|
|
664
|
+
underlyingMint: Address<TAccountUnderlyingMint>;
|
|
665
|
+
/** Collateral mint chosen for this series' collateral pool */
|
|
666
|
+
collateralMint: Address<TAccountCollateralMint>;
|
|
667
|
+
optionPool: Address<TAccountOptionPool>;
|
|
668
|
+
/** Pool's escrow for holding LONG tokens */
|
|
669
|
+
escrowLongAccount: Address<TAccountEscrowLongAccount>;
|
|
670
|
+
/** Pool vault for premiums */
|
|
671
|
+
premiumVault: Address<TAccountPremiumVault>;
|
|
672
|
+
collateralPool: Address<TAccountCollateralPool>;
|
|
673
|
+
/** Collateral vault (ATA holding collateral) */
|
|
674
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
675
|
+
/**
|
|
676
|
+
* Maker's SHORT token ATA (pre-created so option_mint_multi can mint to it
|
|
677
|
+
* via remaining_accounts without init_if_needed)
|
|
678
|
+
*/
|
|
679
|
+
makerShortAccount: Address<TAccountMakerShortAccount>;
|
|
680
|
+
/**
|
|
681
|
+
* Maker's writer position — allocated here (created_at stays 0 so the
|
|
682
|
+
* mint paths still treat the first mint as a new maker)
|
|
683
|
+
*/
|
|
684
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
685
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
686
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
687
|
+
associatedTokenProgram?: Address<TAccountAssociatedTokenProgram>;
|
|
688
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
689
|
+
rent?: Address<TAccountRent>;
|
|
690
|
+
optionType: InitOptionSeriesInstructionDataArgs["optionType"];
|
|
691
|
+
strikePrice: InitOptionSeriesInstructionDataArgs["strikePrice"];
|
|
692
|
+
expirationDate: InitOptionSeriesInstructionDataArgs["expirationDate"];
|
|
693
|
+
underlyingAsset: InitOptionSeriesInstructionDataArgs["underlyingAsset"];
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
export function getInitOptionSeriesInstruction<
|
|
697
|
+
TAccountOptionAccount extends string,
|
|
698
|
+
TAccountLongMint extends string,
|
|
699
|
+
TAccountShortMint extends string,
|
|
700
|
+
TAccountMintAuthority extends string,
|
|
701
|
+
TAccountMarketData extends string,
|
|
702
|
+
TAccountVolatilityQuoteAccount extends string,
|
|
703
|
+
TAccountUnderlyingMint extends string,
|
|
704
|
+
TAccountCollateralMint extends string,
|
|
705
|
+
TAccountOptionPool extends string,
|
|
706
|
+
TAccountEscrowLongAccount extends string,
|
|
707
|
+
TAccountPremiumVault extends string,
|
|
708
|
+
TAccountCollateralPool extends string,
|
|
709
|
+
TAccountCollateralVault extends string,
|
|
710
|
+
TAccountMakerShortAccount extends string,
|
|
711
|
+
TAccountWriterPosition extends string,
|
|
712
|
+
TAccountMaker extends string,
|
|
713
|
+
TAccountTokenProgram extends string,
|
|
714
|
+
TAccountAssociatedTokenProgram extends string,
|
|
715
|
+
TAccountSystemProgram extends string,
|
|
716
|
+
TAccountRent extends string,
|
|
717
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
718
|
+
>(
|
|
719
|
+
input: InitOptionSeriesInput<
|
|
720
|
+
TAccountOptionAccount,
|
|
721
|
+
TAccountLongMint,
|
|
722
|
+
TAccountShortMint,
|
|
723
|
+
TAccountMintAuthority,
|
|
724
|
+
TAccountMarketData,
|
|
725
|
+
TAccountVolatilityQuoteAccount,
|
|
726
|
+
TAccountUnderlyingMint,
|
|
727
|
+
TAccountCollateralMint,
|
|
728
|
+
TAccountOptionPool,
|
|
729
|
+
TAccountEscrowLongAccount,
|
|
730
|
+
TAccountPremiumVault,
|
|
731
|
+
TAccountCollateralPool,
|
|
732
|
+
TAccountCollateralVault,
|
|
733
|
+
TAccountMakerShortAccount,
|
|
734
|
+
TAccountWriterPosition,
|
|
735
|
+
TAccountMaker,
|
|
736
|
+
TAccountTokenProgram,
|
|
737
|
+
TAccountAssociatedTokenProgram,
|
|
738
|
+
TAccountSystemProgram,
|
|
739
|
+
TAccountRent
|
|
740
|
+
>,
|
|
741
|
+
config?: { programAddress?: TProgramAddress },
|
|
742
|
+
): InitOptionSeriesInstruction<
|
|
743
|
+
TProgramAddress,
|
|
744
|
+
TAccountOptionAccount,
|
|
745
|
+
TAccountLongMint,
|
|
746
|
+
TAccountShortMint,
|
|
747
|
+
TAccountMintAuthority,
|
|
748
|
+
TAccountMarketData,
|
|
749
|
+
TAccountVolatilityQuoteAccount,
|
|
750
|
+
TAccountUnderlyingMint,
|
|
751
|
+
TAccountCollateralMint,
|
|
752
|
+
TAccountOptionPool,
|
|
753
|
+
TAccountEscrowLongAccount,
|
|
754
|
+
TAccountPremiumVault,
|
|
755
|
+
TAccountCollateralPool,
|
|
756
|
+
TAccountCollateralVault,
|
|
757
|
+
TAccountMakerShortAccount,
|
|
758
|
+
TAccountWriterPosition,
|
|
759
|
+
TAccountMaker,
|
|
760
|
+
TAccountTokenProgram,
|
|
761
|
+
TAccountAssociatedTokenProgram,
|
|
762
|
+
TAccountSystemProgram,
|
|
763
|
+
TAccountRent
|
|
764
|
+
> {
|
|
765
|
+
// Program address.
|
|
766
|
+
const programAddress =
|
|
767
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
768
|
+
|
|
769
|
+
// Original accounts.
|
|
770
|
+
const originalAccounts = {
|
|
771
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
772
|
+
longMint: { value: input.longMint ?? null, isWritable: true },
|
|
773
|
+
shortMint: { value: input.shortMint ?? null, isWritable: true },
|
|
774
|
+
mintAuthority: { value: input.mintAuthority ?? null, isWritable: false },
|
|
775
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
776
|
+
volatilityQuoteAccount: {
|
|
777
|
+
value: input.volatilityQuoteAccount ?? null,
|
|
778
|
+
isWritable: false,
|
|
779
|
+
},
|
|
780
|
+
underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
|
|
781
|
+
collateralMint: { value: input.collateralMint ?? null, isWritable: false },
|
|
782
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
783
|
+
escrowLongAccount: {
|
|
784
|
+
value: input.escrowLongAccount ?? null,
|
|
785
|
+
isWritable: true,
|
|
786
|
+
},
|
|
787
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
788
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
789
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
790
|
+
makerShortAccount: {
|
|
791
|
+
value: input.makerShortAccount ?? null,
|
|
792
|
+
isWritable: true,
|
|
793
|
+
},
|
|
794
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
795
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
796
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
797
|
+
associatedTokenProgram: {
|
|
798
|
+
value: input.associatedTokenProgram ?? null,
|
|
799
|
+
isWritable: false,
|
|
800
|
+
},
|
|
801
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
802
|
+
rent: { value: input.rent ?? null, isWritable: false },
|
|
803
|
+
};
|
|
804
|
+
const accounts = originalAccounts as Record<
|
|
805
|
+
keyof typeof originalAccounts,
|
|
806
|
+
ResolvedAccount
|
|
807
|
+
>;
|
|
808
|
+
|
|
809
|
+
// Original args.
|
|
810
|
+
const args = { ...input };
|
|
811
|
+
|
|
812
|
+
// Resolve default values.
|
|
813
|
+
if (!accounts.tokenProgram.value) {
|
|
814
|
+
accounts.tokenProgram.value =
|
|
815
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
816
|
+
}
|
|
817
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
818
|
+
accounts.associatedTokenProgram.value =
|
|
819
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
|
|
820
|
+
}
|
|
821
|
+
if (!accounts.systemProgram.value) {
|
|
822
|
+
accounts.systemProgram.value =
|
|
823
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
824
|
+
}
|
|
825
|
+
if (!accounts.rent.value) {
|
|
826
|
+
accounts.rent.value =
|
|
827
|
+
"SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
831
|
+
return Object.freeze({
|
|
832
|
+
accounts: [
|
|
833
|
+
getAccountMeta(accounts.optionAccount),
|
|
834
|
+
getAccountMeta(accounts.longMint),
|
|
835
|
+
getAccountMeta(accounts.shortMint),
|
|
836
|
+
getAccountMeta(accounts.mintAuthority),
|
|
837
|
+
getAccountMeta(accounts.marketData),
|
|
838
|
+
getAccountMeta(accounts.volatilityQuoteAccount),
|
|
839
|
+
getAccountMeta(accounts.underlyingMint),
|
|
840
|
+
getAccountMeta(accounts.collateralMint),
|
|
841
|
+
getAccountMeta(accounts.optionPool),
|
|
842
|
+
getAccountMeta(accounts.escrowLongAccount),
|
|
843
|
+
getAccountMeta(accounts.premiumVault),
|
|
844
|
+
getAccountMeta(accounts.collateralPool),
|
|
845
|
+
getAccountMeta(accounts.collateralVault),
|
|
846
|
+
getAccountMeta(accounts.makerShortAccount),
|
|
847
|
+
getAccountMeta(accounts.writerPosition),
|
|
848
|
+
getAccountMeta(accounts.maker),
|
|
849
|
+
getAccountMeta(accounts.tokenProgram),
|
|
850
|
+
getAccountMeta(accounts.associatedTokenProgram),
|
|
851
|
+
getAccountMeta(accounts.systemProgram),
|
|
852
|
+
getAccountMeta(accounts.rent),
|
|
853
|
+
],
|
|
854
|
+
data: getInitOptionSeriesInstructionDataEncoder().encode(
|
|
855
|
+
args as InitOptionSeriesInstructionDataArgs,
|
|
856
|
+
),
|
|
857
|
+
programAddress,
|
|
858
|
+
} as InitOptionSeriesInstruction<
|
|
859
|
+
TProgramAddress,
|
|
860
|
+
TAccountOptionAccount,
|
|
861
|
+
TAccountLongMint,
|
|
862
|
+
TAccountShortMint,
|
|
863
|
+
TAccountMintAuthority,
|
|
864
|
+
TAccountMarketData,
|
|
865
|
+
TAccountVolatilityQuoteAccount,
|
|
866
|
+
TAccountUnderlyingMint,
|
|
867
|
+
TAccountCollateralMint,
|
|
868
|
+
TAccountOptionPool,
|
|
869
|
+
TAccountEscrowLongAccount,
|
|
870
|
+
TAccountPremiumVault,
|
|
871
|
+
TAccountCollateralPool,
|
|
872
|
+
TAccountCollateralVault,
|
|
873
|
+
TAccountMakerShortAccount,
|
|
874
|
+
TAccountWriterPosition,
|
|
875
|
+
TAccountMaker,
|
|
876
|
+
TAccountTokenProgram,
|
|
877
|
+
TAccountAssociatedTokenProgram,
|
|
878
|
+
TAccountSystemProgram,
|
|
879
|
+
TAccountRent
|
|
880
|
+
>);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
export type ParsedInitOptionSeriesInstruction<
|
|
884
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
885
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
886
|
+
> = {
|
|
887
|
+
programAddress: Address<TProgram>;
|
|
888
|
+
accounts: {
|
|
889
|
+
optionAccount: TAccountMetas[0];
|
|
890
|
+
longMint: TAccountMetas[1];
|
|
891
|
+
shortMint: TAccountMetas[2];
|
|
892
|
+
mintAuthority: TAccountMetas[3];
|
|
893
|
+
/** Market data account — baseline historical volatility for the initial IV */
|
|
894
|
+
marketData: TAccountMetas[4];
|
|
895
|
+
volatilityQuoteAccount: TAccountMetas[5];
|
|
896
|
+
/** Underlying asset mint */
|
|
897
|
+
underlyingMint: TAccountMetas[6];
|
|
898
|
+
/** Collateral mint chosen for this series' collateral pool */
|
|
899
|
+
collateralMint: TAccountMetas[7];
|
|
900
|
+
optionPool: TAccountMetas[8];
|
|
901
|
+
/** Pool's escrow for holding LONG tokens */
|
|
902
|
+
escrowLongAccount: TAccountMetas[9];
|
|
903
|
+
/** Pool vault for premiums */
|
|
904
|
+
premiumVault: TAccountMetas[10];
|
|
905
|
+
collateralPool: TAccountMetas[11];
|
|
906
|
+
/** Collateral vault (ATA holding collateral) */
|
|
907
|
+
collateralVault: TAccountMetas[12];
|
|
908
|
+
/**
|
|
909
|
+
* Maker's SHORT token ATA (pre-created so option_mint_multi can mint to it
|
|
910
|
+
* via remaining_accounts without init_if_needed)
|
|
911
|
+
*/
|
|
912
|
+
makerShortAccount: TAccountMetas[13];
|
|
913
|
+
/**
|
|
914
|
+
* Maker's writer position — allocated here (created_at stays 0 so the
|
|
915
|
+
* mint paths still treat the first mint as a new maker)
|
|
916
|
+
*/
|
|
917
|
+
writerPosition: TAccountMetas[14];
|
|
918
|
+
maker: TAccountMetas[15];
|
|
919
|
+
tokenProgram: TAccountMetas[16];
|
|
920
|
+
associatedTokenProgram: TAccountMetas[17];
|
|
921
|
+
systemProgram: TAccountMetas[18];
|
|
922
|
+
rent: TAccountMetas[19];
|
|
923
|
+
};
|
|
924
|
+
data: InitOptionSeriesInstructionData;
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
export function parseInitOptionSeriesInstruction<
|
|
928
|
+
TProgram extends string,
|
|
929
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
930
|
+
>(
|
|
931
|
+
instruction: Instruction<TProgram> &
|
|
932
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
933
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
934
|
+
): ParsedInitOptionSeriesInstruction<TProgram, TAccountMetas> {
|
|
935
|
+
if (instruction.accounts.length < 20) {
|
|
936
|
+
// TODO: Coded error.
|
|
937
|
+
throw new Error("Not enough accounts");
|
|
938
|
+
}
|
|
939
|
+
let accountIndex = 0;
|
|
940
|
+
const getNextAccount = () => {
|
|
941
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
942
|
+
accountIndex += 1;
|
|
943
|
+
return accountMeta;
|
|
944
|
+
};
|
|
945
|
+
return {
|
|
946
|
+
programAddress: instruction.programAddress,
|
|
947
|
+
accounts: {
|
|
948
|
+
optionAccount: getNextAccount(),
|
|
949
|
+
longMint: getNextAccount(),
|
|
950
|
+
shortMint: getNextAccount(),
|
|
951
|
+
mintAuthority: getNextAccount(),
|
|
952
|
+
marketData: getNextAccount(),
|
|
953
|
+
volatilityQuoteAccount: getNextAccount(),
|
|
954
|
+
underlyingMint: getNextAccount(),
|
|
955
|
+
collateralMint: getNextAccount(),
|
|
956
|
+
optionPool: getNextAccount(),
|
|
957
|
+
escrowLongAccount: getNextAccount(),
|
|
958
|
+
premiumVault: getNextAccount(),
|
|
959
|
+
collateralPool: getNextAccount(),
|
|
960
|
+
collateralVault: getNextAccount(),
|
|
961
|
+
makerShortAccount: getNextAccount(),
|
|
962
|
+
writerPosition: getNextAccount(),
|
|
963
|
+
maker: getNextAccount(),
|
|
964
|
+
tokenProgram: getNextAccount(),
|
|
965
|
+
associatedTokenProgram: getNextAccount(),
|
|
966
|
+
systemProgram: getNextAccount(),
|
|
967
|
+
rent: getNextAccount(),
|
|
968
|
+
},
|
|
969
|
+
data: getInitOptionSeriesInstructionDataDecoder().decode(instruction.data),
|
|
970
|
+
};
|
|
971
|
+
}
|