@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,607 @@
|
|
|
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
|
+
getArrayDecoder,
|
|
16
|
+
getArrayEncoder,
|
|
17
|
+
getBytesDecoder,
|
|
18
|
+
getBytesEncoder,
|
|
19
|
+
getI64Decoder,
|
|
20
|
+
getI64Encoder,
|
|
21
|
+
getProgramDerivedAddress,
|
|
22
|
+
getStructDecoder,
|
|
23
|
+
getStructEncoder,
|
|
24
|
+
transformEncoder,
|
|
25
|
+
type AccountMeta,
|
|
26
|
+
type AccountSignerMeta,
|
|
27
|
+
type Address,
|
|
28
|
+
type Codec,
|
|
29
|
+
type Decoder,
|
|
30
|
+
type Encoder,
|
|
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
|
+
getMintLegArgsDecoder,
|
|
49
|
+
getMintLegArgsEncoder,
|
|
50
|
+
getOptionTypeDecoder,
|
|
51
|
+
getOptionTypeEncoder,
|
|
52
|
+
type MintLegArgs,
|
|
53
|
+
type MintLegArgsArgs,
|
|
54
|
+
type OptionType,
|
|
55
|
+
type OptionTypeArgs,
|
|
56
|
+
} from "../types";
|
|
57
|
+
|
|
58
|
+
export const OPTION_MINT_MULTI_DISCRIMINATOR = new Uint8Array([
|
|
59
|
+
38, 239, 78, 165, 240, 240, 109, 227,
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
export function getOptionMintMultiDiscriminatorBytes() {
|
|
63
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
64
|
+
OPTION_MINT_MULTI_DISCRIMINATOR,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type OptionMintMultiInstruction<
|
|
69
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
70
|
+
TAccountMintAuthority extends string | AccountMeta<string> = string,
|
|
71
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
72
|
+
TAccountVolatilityQuoteAccount extends string | AccountMeta<string> = string,
|
|
73
|
+
TAccountUnderlyingMint extends string | AccountMeta<string> = string,
|
|
74
|
+
TAccountCollateralMint extends string | AccountMeta<string> = string,
|
|
75
|
+
TAccountMakerCollateralAccount extends string | AccountMeta<string> = string,
|
|
76
|
+
TAccountVault extends string | AccountMeta<string> = string,
|
|
77
|
+
TAccountEscrowState extends string | AccountMeta<string> = string,
|
|
78
|
+
TAccountEscrowAuthority extends string | AccountMeta<string> = string,
|
|
79
|
+
TAccountEscrowTokenAccount extends string | AccountMeta<string> = string,
|
|
80
|
+
TAccountMaker extends string | AccountMeta<string> = string,
|
|
81
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
82
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
83
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
84
|
+
> = Instruction<TProgram> &
|
|
85
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
86
|
+
InstructionWithAccounts<
|
|
87
|
+
[
|
|
88
|
+
TAccountMintAuthority extends string
|
|
89
|
+
? ReadonlyAccount<TAccountMintAuthority>
|
|
90
|
+
: TAccountMintAuthority,
|
|
91
|
+
TAccountMarketData extends string
|
|
92
|
+
? ReadonlyAccount<TAccountMarketData>
|
|
93
|
+
: TAccountMarketData,
|
|
94
|
+
TAccountVolatilityQuoteAccount extends string
|
|
95
|
+
? ReadonlyAccount<TAccountVolatilityQuoteAccount>
|
|
96
|
+
: TAccountVolatilityQuoteAccount,
|
|
97
|
+
TAccountUnderlyingMint extends string
|
|
98
|
+
? ReadonlyAccount<TAccountUnderlyingMint>
|
|
99
|
+
: TAccountUnderlyingMint,
|
|
100
|
+
TAccountCollateralMint extends string
|
|
101
|
+
? ReadonlyAccount<TAccountCollateralMint>
|
|
102
|
+
: TAccountCollateralMint,
|
|
103
|
+
TAccountMakerCollateralAccount extends string
|
|
104
|
+
? WritableAccount<TAccountMakerCollateralAccount>
|
|
105
|
+
: TAccountMakerCollateralAccount,
|
|
106
|
+
TAccountVault extends string
|
|
107
|
+
? WritableAccount<TAccountVault>
|
|
108
|
+
: TAccountVault,
|
|
109
|
+
TAccountEscrowState extends string
|
|
110
|
+
? WritableAccount<TAccountEscrowState>
|
|
111
|
+
: TAccountEscrowState,
|
|
112
|
+
TAccountEscrowAuthority extends string
|
|
113
|
+
? ReadonlyAccount<TAccountEscrowAuthority>
|
|
114
|
+
: TAccountEscrowAuthority,
|
|
115
|
+
TAccountEscrowTokenAccount extends string
|
|
116
|
+
? WritableAccount<TAccountEscrowTokenAccount>
|
|
117
|
+
: TAccountEscrowTokenAccount,
|
|
118
|
+
TAccountMaker extends string
|
|
119
|
+
? WritableSignerAccount<TAccountMaker> &
|
|
120
|
+
AccountSignerMeta<TAccountMaker>
|
|
121
|
+
: TAccountMaker,
|
|
122
|
+
TAccountTokenProgram extends string
|
|
123
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
124
|
+
: TAccountTokenProgram,
|
|
125
|
+
...TRemainingAccounts,
|
|
126
|
+
]
|
|
127
|
+
>;
|
|
128
|
+
|
|
129
|
+
export type OptionMintMultiInstructionData = {
|
|
130
|
+
discriminator: ReadonlyUint8Array;
|
|
131
|
+
optionType: OptionType;
|
|
132
|
+
expirationDate: bigint;
|
|
133
|
+
underlyingAsset: Address;
|
|
134
|
+
legs: Array<MintLegArgs>;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type OptionMintMultiInstructionDataArgs = {
|
|
138
|
+
optionType: OptionTypeArgs;
|
|
139
|
+
expirationDate: number | bigint;
|
|
140
|
+
underlyingAsset: Address;
|
|
141
|
+
legs: Array<MintLegArgsArgs>;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export function getOptionMintMultiInstructionDataEncoder(): Encoder<OptionMintMultiInstructionDataArgs> {
|
|
145
|
+
return transformEncoder(
|
|
146
|
+
getStructEncoder([
|
|
147
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
148
|
+
["optionType", getOptionTypeEncoder()],
|
|
149
|
+
["expirationDate", getI64Encoder()],
|
|
150
|
+
["underlyingAsset", getAddressEncoder()],
|
|
151
|
+
["legs", getArrayEncoder(getMintLegArgsEncoder())],
|
|
152
|
+
]),
|
|
153
|
+
(value) => ({ ...value, discriminator: OPTION_MINT_MULTI_DISCRIMINATOR }),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function getOptionMintMultiInstructionDataDecoder(): Decoder<OptionMintMultiInstructionData> {
|
|
158
|
+
return getStructDecoder([
|
|
159
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
160
|
+
["optionType", getOptionTypeDecoder()],
|
|
161
|
+
["expirationDate", getI64Decoder()],
|
|
162
|
+
["underlyingAsset", getAddressDecoder()],
|
|
163
|
+
["legs", getArrayDecoder(getMintLegArgsDecoder())],
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function getOptionMintMultiInstructionDataCodec(): Codec<
|
|
168
|
+
OptionMintMultiInstructionDataArgs,
|
|
169
|
+
OptionMintMultiInstructionData
|
|
170
|
+
> {
|
|
171
|
+
return combineCodec(
|
|
172
|
+
getOptionMintMultiInstructionDataEncoder(),
|
|
173
|
+
getOptionMintMultiInstructionDataDecoder(),
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export type OptionMintMultiAsyncInput<
|
|
178
|
+
TAccountMintAuthority extends string = string,
|
|
179
|
+
TAccountMarketData extends string = string,
|
|
180
|
+
TAccountVolatilityQuoteAccount extends string = string,
|
|
181
|
+
TAccountUnderlyingMint extends string = string,
|
|
182
|
+
TAccountCollateralMint extends string = string,
|
|
183
|
+
TAccountMakerCollateralAccount extends string = string,
|
|
184
|
+
TAccountVault extends string = string,
|
|
185
|
+
TAccountEscrowState extends string = string,
|
|
186
|
+
TAccountEscrowAuthority extends string = string,
|
|
187
|
+
TAccountEscrowTokenAccount extends string = string,
|
|
188
|
+
TAccountMaker extends string = string,
|
|
189
|
+
TAccountTokenProgram extends string = string,
|
|
190
|
+
> = {
|
|
191
|
+
mintAuthority?: Address<TAccountMintAuthority>;
|
|
192
|
+
marketData?: Address<TAccountMarketData>;
|
|
193
|
+
volatilityQuoteAccount: Address<TAccountVolatilityQuoteAccount>;
|
|
194
|
+
underlyingMint: Address<TAccountUnderlyingMint>;
|
|
195
|
+
collateralMint: Address<TAccountCollateralMint>;
|
|
196
|
+
/** Maker's collateral source (shared by every leg) */
|
|
197
|
+
makerCollateralAccount: Address<TAccountMakerCollateralAccount>;
|
|
198
|
+
/** OMLP vault (required when any leg borrows) */
|
|
199
|
+
vault?: Address<TAccountVault>;
|
|
200
|
+
/** Escrow state PDA — seeds-checked so only the maker's own escrow can fund borrows */
|
|
201
|
+
escrowState?: Address<TAccountEscrowState>;
|
|
202
|
+
escrowAuthority?: Address<TAccountEscrowAuthority>;
|
|
203
|
+
escrowTokenAccount?: Address<TAccountEscrowTokenAccount>;
|
|
204
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
205
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
206
|
+
optionType: OptionMintMultiInstructionDataArgs["optionType"];
|
|
207
|
+
expirationDate: OptionMintMultiInstructionDataArgs["expirationDate"];
|
|
208
|
+
underlyingAsset: OptionMintMultiInstructionDataArgs["underlyingAsset"];
|
|
209
|
+
legs: OptionMintMultiInstructionDataArgs["legs"];
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export async function getOptionMintMultiInstructionAsync<
|
|
213
|
+
TAccountMintAuthority extends string,
|
|
214
|
+
TAccountMarketData extends string,
|
|
215
|
+
TAccountVolatilityQuoteAccount extends string,
|
|
216
|
+
TAccountUnderlyingMint extends string,
|
|
217
|
+
TAccountCollateralMint extends string,
|
|
218
|
+
TAccountMakerCollateralAccount extends string,
|
|
219
|
+
TAccountVault extends string,
|
|
220
|
+
TAccountEscrowState extends string,
|
|
221
|
+
TAccountEscrowAuthority extends string,
|
|
222
|
+
TAccountEscrowTokenAccount extends string,
|
|
223
|
+
TAccountMaker extends string,
|
|
224
|
+
TAccountTokenProgram extends string,
|
|
225
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
226
|
+
>(
|
|
227
|
+
input: OptionMintMultiAsyncInput<
|
|
228
|
+
TAccountMintAuthority,
|
|
229
|
+
TAccountMarketData,
|
|
230
|
+
TAccountVolatilityQuoteAccount,
|
|
231
|
+
TAccountUnderlyingMint,
|
|
232
|
+
TAccountCollateralMint,
|
|
233
|
+
TAccountMakerCollateralAccount,
|
|
234
|
+
TAccountVault,
|
|
235
|
+
TAccountEscrowState,
|
|
236
|
+
TAccountEscrowAuthority,
|
|
237
|
+
TAccountEscrowTokenAccount,
|
|
238
|
+
TAccountMaker,
|
|
239
|
+
TAccountTokenProgram
|
|
240
|
+
>,
|
|
241
|
+
config?: { programAddress?: TProgramAddress },
|
|
242
|
+
): Promise<
|
|
243
|
+
OptionMintMultiInstruction<
|
|
244
|
+
TProgramAddress,
|
|
245
|
+
TAccountMintAuthority,
|
|
246
|
+
TAccountMarketData,
|
|
247
|
+
TAccountVolatilityQuoteAccount,
|
|
248
|
+
TAccountUnderlyingMint,
|
|
249
|
+
TAccountCollateralMint,
|
|
250
|
+
TAccountMakerCollateralAccount,
|
|
251
|
+
TAccountVault,
|
|
252
|
+
TAccountEscrowState,
|
|
253
|
+
TAccountEscrowAuthority,
|
|
254
|
+
TAccountEscrowTokenAccount,
|
|
255
|
+
TAccountMaker,
|
|
256
|
+
TAccountTokenProgram
|
|
257
|
+
>
|
|
258
|
+
> {
|
|
259
|
+
// Program address.
|
|
260
|
+
const programAddress =
|
|
261
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
262
|
+
|
|
263
|
+
// Original accounts.
|
|
264
|
+
const originalAccounts = {
|
|
265
|
+
mintAuthority: { value: input.mintAuthority ?? null, isWritable: false },
|
|
266
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
267
|
+
volatilityQuoteAccount: {
|
|
268
|
+
value: input.volatilityQuoteAccount ?? null,
|
|
269
|
+
isWritable: false,
|
|
270
|
+
},
|
|
271
|
+
underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
|
|
272
|
+
collateralMint: { value: input.collateralMint ?? null, isWritable: false },
|
|
273
|
+
makerCollateralAccount: {
|
|
274
|
+
value: input.makerCollateralAccount ?? null,
|
|
275
|
+
isWritable: true,
|
|
276
|
+
},
|
|
277
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
278
|
+
escrowState: { value: input.escrowState ?? null, isWritable: true },
|
|
279
|
+
escrowAuthority: {
|
|
280
|
+
value: input.escrowAuthority ?? null,
|
|
281
|
+
isWritable: false,
|
|
282
|
+
},
|
|
283
|
+
escrowTokenAccount: {
|
|
284
|
+
value: input.escrowTokenAccount ?? null,
|
|
285
|
+
isWritable: true,
|
|
286
|
+
},
|
|
287
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
288
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
289
|
+
};
|
|
290
|
+
const accounts = originalAccounts as Record<
|
|
291
|
+
keyof typeof originalAccounts,
|
|
292
|
+
ResolvedAccount
|
|
293
|
+
>;
|
|
294
|
+
|
|
295
|
+
// Original args.
|
|
296
|
+
const args = { ...input };
|
|
297
|
+
|
|
298
|
+
// Resolve default values.
|
|
299
|
+
if (!accounts.mintAuthority.value) {
|
|
300
|
+
accounts.mintAuthority.value = await getProgramDerivedAddress({
|
|
301
|
+
programAddress,
|
|
302
|
+
seeds: [
|
|
303
|
+
getBytesEncoder().encode(
|
|
304
|
+
new Uint8Array([
|
|
305
|
+
109, 105, 110, 116, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121,
|
|
306
|
+
]),
|
|
307
|
+
),
|
|
308
|
+
],
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
if (!accounts.marketData.value) {
|
|
312
|
+
accounts.marketData.value = await getProgramDerivedAddress({
|
|
313
|
+
programAddress,
|
|
314
|
+
seeds: [
|
|
315
|
+
getBytesEncoder().encode(
|
|
316
|
+
new Uint8Array([109, 97, 114, 107, 101, 116, 95, 100, 97, 116, 97]),
|
|
317
|
+
),
|
|
318
|
+
getAddressEncoder().encode(expectSome(args.underlyingAsset)),
|
|
319
|
+
],
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (!accounts.escrowState.value) {
|
|
323
|
+
accounts.escrowState.value = await getProgramDerivedAddress({
|
|
324
|
+
programAddress,
|
|
325
|
+
seeds: [
|
|
326
|
+
getBytesEncoder().encode(
|
|
327
|
+
new Uint8Array([101, 115, 99, 114, 111, 119, 95, 118, 50]),
|
|
328
|
+
),
|
|
329
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
330
|
+
getAddressEncoder().encode(
|
|
331
|
+
expectAddress(accounts.collateralMint.value),
|
|
332
|
+
),
|
|
333
|
+
],
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
if (!accounts.tokenProgram.value) {
|
|
337
|
+
accounts.tokenProgram.value =
|
|
338
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
342
|
+
return Object.freeze({
|
|
343
|
+
accounts: [
|
|
344
|
+
getAccountMeta(accounts.mintAuthority),
|
|
345
|
+
getAccountMeta(accounts.marketData),
|
|
346
|
+
getAccountMeta(accounts.volatilityQuoteAccount),
|
|
347
|
+
getAccountMeta(accounts.underlyingMint),
|
|
348
|
+
getAccountMeta(accounts.collateralMint),
|
|
349
|
+
getAccountMeta(accounts.makerCollateralAccount),
|
|
350
|
+
getAccountMeta(accounts.vault),
|
|
351
|
+
getAccountMeta(accounts.escrowState),
|
|
352
|
+
getAccountMeta(accounts.escrowAuthority),
|
|
353
|
+
getAccountMeta(accounts.escrowTokenAccount),
|
|
354
|
+
getAccountMeta(accounts.maker),
|
|
355
|
+
getAccountMeta(accounts.tokenProgram),
|
|
356
|
+
],
|
|
357
|
+
data: getOptionMintMultiInstructionDataEncoder().encode(
|
|
358
|
+
args as OptionMintMultiInstructionDataArgs,
|
|
359
|
+
),
|
|
360
|
+
programAddress,
|
|
361
|
+
} as OptionMintMultiInstruction<
|
|
362
|
+
TProgramAddress,
|
|
363
|
+
TAccountMintAuthority,
|
|
364
|
+
TAccountMarketData,
|
|
365
|
+
TAccountVolatilityQuoteAccount,
|
|
366
|
+
TAccountUnderlyingMint,
|
|
367
|
+
TAccountCollateralMint,
|
|
368
|
+
TAccountMakerCollateralAccount,
|
|
369
|
+
TAccountVault,
|
|
370
|
+
TAccountEscrowState,
|
|
371
|
+
TAccountEscrowAuthority,
|
|
372
|
+
TAccountEscrowTokenAccount,
|
|
373
|
+
TAccountMaker,
|
|
374
|
+
TAccountTokenProgram
|
|
375
|
+
>);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export type OptionMintMultiInput<
|
|
379
|
+
TAccountMintAuthority extends string = string,
|
|
380
|
+
TAccountMarketData extends string = string,
|
|
381
|
+
TAccountVolatilityQuoteAccount extends string = string,
|
|
382
|
+
TAccountUnderlyingMint extends string = string,
|
|
383
|
+
TAccountCollateralMint extends string = string,
|
|
384
|
+
TAccountMakerCollateralAccount extends string = string,
|
|
385
|
+
TAccountVault extends string = string,
|
|
386
|
+
TAccountEscrowState extends string = string,
|
|
387
|
+
TAccountEscrowAuthority extends string = string,
|
|
388
|
+
TAccountEscrowTokenAccount extends string = string,
|
|
389
|
+
TAccountMaker extends string = string,
|
|
390
|
+
TAccountTokenProgram extends string = string,
|
|
391
|
+
> = {
|
|
392
|
+
mintAuthority: Address<TAccountMintAuthority>;
|
|
393
|
+
marketData: Address<TAccountMarketData>;
|
|
394
|
+
volatilityQuoteAccount: Address<TAccountVolatilityQuoteAccount>;
|
|
395
|
+
underlyingMint: Address<TAccountUnderlyingMint>;
|
|
396
|
+
collateralMint: Address<TAccountCollateralMint>;
|
|
397
|
+
/** Maker's collateral source (shared by every leg) */
|
|
398
|
+
makerCollateralAccount: Address<TAccountMakerCollateralAccount>;
|
|
399
|
+
/** OMLP vault (required when any leg borrows) */
|
|
400
|
+
vault?: Address<TAccountVault>;
|
|
401
|
+
/** Escrow state PDA — seeds-checked so only the maker's own escrow can fund borrows */
|
|
402
|
+
escrowState?: Address<TAccountEscrowState>;
|
|
403
|
+
escrowAuthority?: Address<TAccountEscrowAuthority>;
|
|
404
|
+
escrowTokenAccount?: Address<TAccountEscrowTokenAccount>;
|
|
405
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
406
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
407
|
+
optionType: OptionMintMultiInstructionDataArgs["optionType"];
|
|
408
|
+
expirationDate: OptionMintMultiInstructionDataArgs["expirationDate"];
|
|
409
|
+
underlyingAsset: OptionMintMultiInstructionDataArgs["underlyingAsset"];
|
|
410
|
+
legs: OptionMintMultiInstructionDataArgs["legs"];
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
export function getOptionMintMultiInstruction<
|
|
414
|
+
TAccountMintAuthority extends string,
|
|
415
|
+
TAccountMarketData extends string,
|
|
416
|
+
TAccountVolatilityQuoteAccount extends string,
|
|
417
|
+
TAccountUnderlyingMint extends string,
|
|
418
|
+
TAccountCollateralMint extends string,
|
|
419
|
+
TAccountMakerCollateralAccount extends string,
|
|
420
|
+
TAccountVault extends string,
|
|
421
|
+
TAccountEscrowState extends string,
|
|
422
|
+
TAccountEscrowAuthority extends string,
|
|
423
|
+
TAccountEscrowTokenAccount extends string,
|
|
424
|
+
TAccountMaker extends string,
|
|
425
|
+
TAccountTokenProgram extends string,
|
|
426
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
427
|
+
>(
|
|
428
|
+
input: OptionMintMultiInput<
|
|
429
|
+
TAccountMintAuthority,
|
|
430
|
+
TAccountMarketData,
|
|
431
|
+
TAccountVolatilityQuoteAccount,
|
|
432
|
+
TAccountUnderlyingMint,
|
|
433
|
+
TAccountCollateralMint,
|
|
434
|
+
TAccountMakerCollateralAccount,
|
|
435
|
+
TAccountVault,
|
|
436
|
+
TAccountEscrowState,
|
|
437
|
+
TAccountEscrowAuthority,
|
|
438
|
+
TAccountEscrowTokenAccount,
|
|
439
|
+
TAccountMaker,
|
|
440
|
+
TAccountTokenProgram
|
|
441
|
+
>,
|
|
442
|
+
config?: { programAddress?: TProgramAddress },
|
|
443
|
+
): OptionMintMultiInstruction<
|
|
444
|
+
TProgramAddress,
|
|
445
|
+
TAccountMintAuthority,
|
|
446
|
+
TAccountMarketData,
|
|
447
|
+
TAccountVolatilityQuoteAccount,
|
|
448
|
+
TAccountUnderlyingMint,
|
|
449
|
+
TAccountCollateralMint,
|
|
450
|
+
TAccountMakerCollateralAccount,
|
|
451
|
+
TAccountVault,
|
|
452
|
+
TAccountEscrowState,
|
|
453
|
+
TAccountEscrowAuthority,
|
|
454
|
+
TAccountEscrowTokenAccount,
|
|
455
|
+
TAccountMaker,
|
|
456
|
+
TAccountTokenProgram
|
|
457
|
+
> {
|
|
458
|
+
// Program address.
|
|
459
|
+
const programAddress =
|
|
460
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
461
|
+
|
|
462
|
+
// Original accounts.
|
|
463
|
+
const originalAccounts = {
|
|
464
|
+
mintAuthority: { value: input.mintAuthority ?? null, isWritable: false },
|
|
465
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
466
|
+
volatilityQuoteAccount: {
|
|
467
|
+
value: input.volatilityQuoteAccount ?? null,
|
|
468
|
+
isWritable: false,
|
|
469
|
+
},
|
|
470
|
+
underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
|
|
471
|
+
collateralMint: { value: input.collateralMint ?? null, isWritable: false },
|
|
472
|
+
makerCollateralAccount: {
|
|
473
|
+
value: input.makerCollateralAccount ?? null,
|
|
474
|
+
isWritable: true,
|
|
475
|
+
},
|
|
476
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
477
|
+
escrowState: { value: input.escrowState ?? null, isWritable: true },
|
|
478
|
+
escrowAuthority: {
|
|
479
|
+
value: input.escrowAuthority ?? null,
|
|
480
|
+
isWritable: false,
|
|
481
|
+
},
|
|
482
|
+
escrowTokenAccount: {
|
|
483
|
+
value: input.escrowTokenAccount ?? null,
|
|
484
|
+
isWritable: true,
|
|
485
|
+
},
|
|
486
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
487
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
488
|
+
};
|
|
489
|
+
const accounts = originalAccounts as Record<
|
|
490
|
+
keyof typeof originalAccounts,
|
|
491
|
+
ResolvedAccount
|
|
492
|
+
>;
|
|
493
|
+
|
|
494
|
+
// Original args.
|
|
495
|
+
const args = { ...input };
|
|
496
|
+
|
|
497
|
+
// Resolve default values.
|
|
498
|
+
if (!accounts.tokenProgram.value) {
|
|
499
|
+
accounts.tokenProgram.value =
|
|
500
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
504
|
+
return Object.freeze({
|
|
505
|
+
accounts: [
|
|
506
|
+
getAccountMeta(accounts.mintAuthority),
|
|
507
|
+
getAccountMeta(accounts.marketData),
|
|
508
|
+
getAccountMeta(accounts.volatilityQuoteAccount),
|
|
509
|
+
getAccountMeta(accounts.underlyingMint),
|
|
510
|
+
getAccountMeta(accounts.collateralMint),
|
|
511
|
+
getAccountMeta(accounts.makerCollateralAccount),
|
|
512
|
+
getAccountMeta(accounts.vault),
|
|
513
|
+
getAccountMeta(accounts.escrowState),
|
|
514
|
+
getAccountMeta(accounts.escrowAuthority),
|
|
515
|
+
getAccountMeta(accounts.escrowTokenAccount),
|
|
516
|
+
getAccountMeta(accounts.maker),
|
|
517
|
+
getAccountMeta(accounts.tokenProgram),
|
|
518
|
+
],
|
|
519
|
+
data: getOptionMintMultiInstructionDataEncoder().encode(
|
|
520
|
+
args as OptionMintMultiInstructionDataArgs,
|
|
521
|
+
),
|
|
522
|
+
programAddress,
|
|
523
|
+
} as OptionMintMultiInstruction<
|
|
524
|
+
TProgramAddress,
|
|
525
|
+
TAccountMintAuthority,
|
|
526
|
+
TAccountMarketData,
|
|
527
|
+
TAccountVolatilityQuoteAccount,
|
|
528
|
+
TAccountUnderlyingMint,
|
|
529
|
+
TAccountCollateralMint,
|
|
530
|
+
TAccountMakerCollateralAccount,
|
|
531
|
+
TAccountVault,
|
|
532
|
+
TAccountEscrowState,
|
|
533
|
+
TAccountEscrowAuthority,
|
|
534
|
+
TAccountEscrowTokenAccount,
|
|
535
|
+
TAccountMaker,
|
|
536
|
+
TAccountTokenProgram
|
|
537
|
+
>);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export type ParsedOptionMintMultiInstruction<
|
|
541
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
542
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
543
|
+
> = {
|
|
544
|
+
programAddress: Address<TProgram>;
|
|
545
|
+
accounts: {
|
|
546
|
+
mintAuthority: TAccountMetas[0];
|
|
547
|
+
marketData: TAccountMetas[1];
|
|
548
|
+
volatilityQuoteAccount: TAccountMetas[2];
|
|
549
|
+
underlyingMint: TAccountMetas[3];
|
|
550
|
+
collateralMint: TAccountMetas[4];
|
|
551
|
+
/** Maker's collateral source (shared by every leg) */
|
|
552
|
+
makerCollateralAccount: TAccountMetas[5];
|
|
553
|
+
/** OMLP vault (required when any leg borrows) */
|
|
554
|
+
vault?: TAccountMetas[6] | undefined;
|
|
555
|
+
/** Escrow state PDA — seeds-checked so only the maker's own escrow can fund borrows */
|
|
556
|
+
escrowState?: TAccountMetas[7] | undefined;
|
|
557
|
+
escrowAuthority?: TAccountMetas[8] | undefined;
|
|
558
|
+
escrowTokenAccount?: TAccountMetas[9] | undefined;
|
|
559
|
+
maker: TAccountMetas[10];
|
|
560
|
+
tokenProgram: TAccountMetas[11];
|
|
561
|
+
};
|
|
562
|
+
data: OptionMintMultiInstructionData;
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
export function parseOptionMintMultiInstruction<
|
|
566
|
+
TProgram extends string,
|
|
567
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
568
|
+
>(
|
|
569
|
+
instruction: Instruction<TProgram> &
|
|
570
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
571
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
572
|
+
): ParsedOptionMintMultiInstruction<TProgram, TAccountMetas> {
|
|
573
|
+
if (instruction.accounts.length < 12) {
|
|
574
|
+
// TODO: Coded error.
|
|
575
|
+
throw new Error("Not enough accounts");
|
|
576
|
+
}
|
|
577
|
+
let accountIndex = 0;
|
|
578
|
+
const getNextAccount = () => {
|
|
579
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
580
|
+
accountIndex += 1;
|
|
581
|
+
return accountMeta;
|
|
582
|
+
};
|
|
583
|
+
const getNextOptionalAccount = () => {
|
|
584
|
+
const accountMeta = getNextAccount();
|
|
585
|
+
return accountMeta.address === OPTION_PROGRAM_PROGRAM_ADDRESS
|
|
586
|
+
? undefined
|
|
587
|
+
: accountMeta;
|
|
588
|
+
};
|
|
589
|
+
return {
|
|
590
|
+
programAddress: instruction.programAddress,
|
|
591
|
+
accounts: {
|
|
592
|
+
mintAuthority: getNextAccount(),
|
|
593
|
+
marketData: getNextAccount(),
|
|
594
|
+
volatilityQuoteAccount: getNextAccount(),
|
|
595
|
+
underlyingMint: getNextAccount(),
|
|
596
|
+
collateralMint: getNextAccount(),
|
|
597
|
+
makerCollateralAccount: getNextAccount(),
|
|
598
|
+
vault: getNextOptionalAccount(),
|
|
599
|
+
escrowState: getNextOptionalAccount(),
|
|
600
|
+
escrowAuthority: getNextOptionalAccount(),
|
|
601
|
+
escrowTokenAccount: getNextOptionalAccount(),
|
|
602
|
+
maker: getNextAccount(),
|
|
603
|
+
tokenProgram: getNextAccount(),
|
|
604
|
+
},
|
|
605
|
+
data: getOptionMintMultiInstructionDataDecoder().decode(instruction.data),
|
|
606
|
+
};
|
|
607
|
+
}
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
type ParsedInitConfigInstruction,
|
|
32
32
|
type ParsedInitializeMarketDataInstruction,
|
|
33
33
|
type ParsedInitOptionPoolInstruction,
|
|
34
|
+
type ParsedInitOptionSeriesInstruction,
|
|
34
35
|
type ParsedLiquidateWriterPositionInstruction,
|
|
35
36
|
type ParsedLiquidateWriterPositionRescueInstruction,
|
|
36
37
|
type ParsedMigrateCollateralPoolV1ToV2Instruction,
|
|
@@ -46,6 +47,7 @@ import {
|
|
|
46
47
|
type ParsedOmlpUpdateSupplyLimitInstruction,
|
|
47
48
|
type ParsedOptionExerciseInstruction,
|
|
48
49
|
type ParsedOptionMintInstruction,
|
|
50
|
+
type ParsedOptionMintMultiInstruction,
|
|
49
51
|
type ParsedOptionValidateInstruction,
|
|
50
52
|
type ParsedPrepareBuyerSettlementInstruction,
|
|
51
53
|
type ParsedPrepareMakerSettlementInstruction,
|
|
@@ -264,6 +266,7 @@ export enum OptionProgramInstruction {
|
|
|
264
266
|
InitCollateralPool,
|
|
265
267
|
InitConfig,
|
|
266
268
|
InitOptionPool,
|
|
269
|
+
InitOptionSeries,
|
|
267
270
|
InitializeMarketData,
|
|
268
271
|
LiquidateWriterPosition,
|
|
269
272
|
LiquidateWriterPositionRescue,
|
|
@@ -280,6 +283,7 @@ export enum OptionProgramInstruction {
|
|
|
280
283
|
OmlpUpdateSupplyLimit,
|
|
281
284
|
OptionExercise,
|
|
282
285
|
OptionMint,
|
|
286
|
+
OptionMintMulti,
|
|
283
287
|
OptionValidate,
|
|
284
288
|
PrepareBuyerSettlement,
|
|
285
289
|
PrepareMakerSettlement,
|
|
@@ -478,6 +482,17 @@ export function identifyOptionProgramInstruction(
|
|
|
478
482
|
) {
|
|
479
483
|
return OptionProgramInstruction.InitOptionPool;
|
|
480
484
|
}
|
|
485
|
+
if (
|
|
486
|
+
containsBytes(
|
|
487
|
+
data,
|
|
488
|
+
fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
489
|
+
new Uint8Array([5, 9, 41, 96, 87, 149, 105, 169]),
|
|
490
|
+
),
|
|
491
|
+
0,
|
|
492
|
+
)
|
|
493
|
+
) {
|
|
494
|
+
return OptionProgramInstruction.InitOptionSeries;
|
|
495
|
+
}
|
|
481
496
|
if (
|
|
482
497
|
containsBytes(
|
|
483
498
|
data,
|
|
@@ -654,6 +669,17 @@ export function identifyOptionProgramInstruction(
|
|
|
654
669
|
) {
|
|
655
670
|
return OptionProgramInstruction.OptionMint;
|
|
656
671
|
}
|
|
672
|
+
if (
|
|
673
|
+
containsBytes(
|
|
674
|
+
data,
|
|
675
|
+
fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
676
|
+
new Uint8Array([38, 239, 78, 165, 240, 240, 109, 227]),
|
|
677
|
+
),
|
|
678
|
+
0,
|
|
679
|
+
)
|
|
680
|
+
) {
|
|
681
|
+
return OptionProgramInstruction.OptionMintMulti;
|
|
682
|
+
}
|
|
657
683
|
if (
|
|
658
684
|
containsBytes(
|
|
659
685
|
data,
|
|
@@ -886,6 +912,9 @@ export type ParsedOptionProgramInstruction<
|
|
|
886
912
|
| ({
|
|
887
913
|
instructionType: OptionProgramInstruction.InitOptionPool;
|
|
888
914
|
} & ParsedInitOptionPoolInstruction<TProgram>)
|
|
915
|
+
| ({
|
|
916
|
+
instructionType: OptionProgramInstruction.InitOptionSeries;
|
|
917
|
+
} & ParsedInitOptionSeriesInstruction<TProgram>)
|
|
889
918
|
| ({
|
|
890
919
|
instructionType: OptionProgramInstruction.InitializeMarketData;
|
|
891
920
|
} & ParsedInitializeMarketDataInstruction<TProgram>)
|
|
@@ -934,6 +963,9 @@ export type ParsedOptionProgramInstruction<
|
|
|
934
963
|
| ({
|
|
935
964
|
instructionType: OptionProgramInstruction.OptionMint;
|
|
936
965
|
} & ParsedOptionMintInstruction<TProgram>)
|
|
966
|
+
| ({
|
|
967
|
+
instructionType: OptionProgramInstruction.OptionMintMulti;
|
|
968
|
+
} & ParsedOptionMintMultiInstruction<TProgram>)
|
|
937
969
|
| ({
|
|
938
970
|
instructionType: OptionProgramInstruction.OptionValidate;
|
|
939
971
|
} & ParsedOptionValidateInstruction<TProgram>)
|
package/generated/types/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./marketDataAuthorityTransferred";
|
|
|
13
13
|
export * from "./marketDataInitialized";
|
|
14
14
|
export * from "./marketDataSwitchboardFeedUpdated";
|
|
15
15
|
export * from "./marketDataUpdated";
|
|
16
|
+
export * from "./mintLegArgs";
|
|
16
17
|
export * from "./optionClosed";
|
|
17
18
|
export * from "./optionExercised";
|
|
18
19
|
export * from "./optionExpired";
|