@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.
- package/LICENSE +21 -0
- package/README.md +239 -0
- package/accounts/fetchers.ts +140 -0
- package/accounts/list.ts +152 -0
- package/accounts/pdas.ts +308 -0
- package/client/lookup-table.ts +32 -0
- package/client/program.ts +13 -0
- package/client/types.ts +8 -0
- package/generated/accounts/collateralPool.ts +217 -0
- package/generated/accounts/config.ts +156 -0
- package/generated/accounts/dualSourceContract.ts +235 -0
- package/generated/accounts/escrowState.ts +183 -0
- package/generated/accounts/index.ts +24 -0
- package/generated/accounts/lenderPosition.ts +211 -0
- package/generated/accounts/liquidityRouter.ts +223 -0
- package/generated/accounts/makerCollateralShare.ts +229 -0
- package/generated/accounts/makerPoolShare.ts +203 -0
- package/generated/accounts/marketDataAccount.ts +176 -0
- package/generated/accounts/optionAccount.ts +247 -0
- package/generated/accounts/optionPool.ts +253 -0
- package/generated/accounts/poolLoan.ts +220 -0
- package/generated/accounts/positionAccount.ts +187 -0
- package/generated/accounts/priceUpdateV2.ts +163 -0
- package/generated/accounts/vault.ts +304 -0
- package/generated/accounts/writerPosition.ts +297 -0
- package/generated/errors/index.ts +9 -0
- package/generated/errors/optionProgram.ts +392 -0
- package/generated/index.ts +13 -0
- package/generated/instructions/acceptAdmin.ts +230 -0
- package/generated/instructions/autoExerciseAllExpired.ts +523 -0
- package/generated/instructions/autoExerciseExpired.ts +623 -0
- package/generated/instructions/borrowFromPool.ts +554 -0
- package/generated/instructions/buyFromPool.ts +684 -0
- package/generated/instructions/claimPremium.ts +377 -0
- package/generated/instructions/closeLongToPool.ts +716 -0
- package/generated/instructions/closeOption.ts +235 -0
- package/generated/instructions/createEscrowV2.ts +518 -0
- package/generated/instructions/createLiquidityRouter.ts +361 -0
- package/generated/instructions/depositCollateral.ts +624 -0
- package/generated/instructions/depositToPool.ts +497 -0
- package/generated/instructions/depositToPosition.ts +429 -0
- package/generated/instructions/index.ts +45 -0
- package/generated/instructions/initCollateralPool.ts +513 -0
- package/generated/instructions/initConfig.ts +279 -0
- package/generated/instructions/initOptionPool.ts +587 -0
- package/generated/instructions/initializeMarketData.ts +359 -0
- package/generated/instructions/liquidateWriterPosition.ts +592 -0
- package/generated/instructions/omlpCreateVault.ts +547 -0
- package/generated/instructions/omlpTakeOfferWithFailover.ts +606 -0
- package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
- package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
- package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
- package/generated/instructions/optionExercise.ts +540 -0
- package/generated/instructions/optionMint.ts +1349 -0
- package/generated/instructions/optionValidate.ts +255 -0
- package/generated/instructions/repayPoolLoan.ts +499 -0
- package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
- package/generated/instructions/settleMakerCollateral.ts +472 -0
- package/generated/instructions/syncWriterPosition.ts +206 -0
- package/generated/instructions/transferAdmin.ts +245 -0
- package/generated/instructions/unwindWriterUnsold.ts +668 -0
- package/generated/instructions/updateImpliedVolatility.ts +226 -0
- package/generated/instructions/updateMarketData.ts +315 -0
- package/generated/instructions/withdrawFromPool.ts +429 -0
- package/generated/instructions/withdrawFromPosition.ts +405 -0
- package/generated/instructions/writeToPool.ts +594 -0
- package/generated/programs/index.ts +9 -0
- package/generated/programs/optionProgram.ts +832 -0
- package/generated/shared/index.ts +164 -0
- package/generated/types/borrowedFromSAP1.ts +75 -0
- package/generated/types/borrowedFromSAP2.ts +83 -0
- package/generated/types/failoverTriggered.ts +85 -0
- package/generated/types/impliedVolatilityUpdated.ts +73 -0
- package/generated/types/index.ts +32 -0
- package/generated/types/liquidationExecuted.ts +73 -0
- package/generated/types/liquidityMetrics.ts +69 -0
- package/generated/types/liquidityRouterCreated.ts +79 -0
- package/generated/types/marketDataInitialized.ts +61 -0
- package/generated/types/marketDataUpdated.ts +69 -0
- package/generated/types/optionClosed.ts +56 -0
- package/generated/types/optionExercised.ts +62 -0
- package/generated/types/optionExpired.ts +49 -0
- package/generated/types/optionMinted.ts +78 -0
- package/generated/types/optionType.ts +38 -0
- package/generated/types/optionValidated.ts +82 -0
- package/generated/types/poolLoanCreated.ts +74 -0
- package/generated/types/poolLoanRepaid.ts +74 -0
- package/generated/types/positionDeposited.ts +73 -0
- package/generated/types/positionWithdrawn.ts +81 -0
- package/generated/types/priceFeedMessage.ts +117 -0
- package/generated/types/protocolFeeUpdated.ts +69 -0
- package/generated/types/sap2Provider.ts +38 -0
- package/generated/types/vaultCreated.ts +60 -0
- package/generated/types/verificationLevel.ts +95 -0
- package/index.ts +25 -0
- package/long/builders.ts +126 -0
- package/long/exercise.ts +49 -0
- package/long/quotes.ts +48 -0
- package/omlp/builders.ts +74 -0
- package/omlp/service.ts +94 -0
- package/package.json +22 -0
- package/shared/amounts.ts +32 -0
- package/shared/errors.ts +12 -0
- package/shared/remaining-accounts.ts +41 -0
- package/shared/transactions.ts +49 -0
- package/short/builders.ts +268 -0
- package/short/claim-premium.ts +37 -0
- package/short/close-option.ts +34 -0
- package/short/pool.ts +224 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,1349 @@
|
|
|
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
|
+
addDecoderSizePrefix,
|
|
11
|
+
addEncoderSizePrefix,
|
|
12
|
+
combineCodec,
|
|
13
|
+
fixDecoderSize,
|
|
14
|
+
fixEncoderSize,
|
|
15
|
+
getAddressDecoder,
|
|
16
|
+
getAddressEncoder,
|
|
17
|
+
getBytesDecoder,
|
|
18
|
+
getBytesEncoder,
|
|
19
|
+
getF64Decoder,
|
|
20
|
+
getF64Encoder,
|
|
21
|
+
getI64Decoder,
|
|
22
|
+
getI64Encoder,
|
|
23
|
+
getProgramDerivedAddress,
|
|
24
|
+
getStructDecoder,
|
|
25
|
+
getStructEncoder,
|
|
26
|
+
getU32Decoder,
|
|
27
|
+
getU32Encoder,
|
|
28
|
+
getU64Decoder,
|
|
29
|
+
getU64Encoder,
|
|
30
|
+
getUtf8Decoder,
|
|
31
|
+
getUtf8Encoder,
|
|
32
|
+
transformEncoder,
|
|
33
|
+
type AccountMeta,
|
|
34
|
+
type AccountSignerMeta,
|
|
35
|
+
type Address,
|
|
36
|
+
type Codec,
|
|
37
|
+
type Decoder,
|
|
38
|
+
type Encoder,
|
|
39
|
+
type Instruction,
|
|
40
|
+
type InstructionWithAccounts,
|
|
41
|
+
type InstructionWithData,
|
|
42
|
+
type ReadonlyAccount,
|
|
43
|
+
type ReadonlyUint8Array,
|
|
44
|
+
type TransactionSigner,
|
|
45
|
+
type WritableAccount,
|
|
46
|
+
type WritableSignerAccount,
|
|
47
|
+
} from "@solana/kit";
|
|
48
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
49
|
+
import {
|
|
50
|
+
expectAddress,
|
|
51
|
+
expectSome,
|
|
52
|
+
getAccountMetaFactory,
|
|
53
|
+
type ResolvedAccount,
|
|
54
|
+
} from "../shared";
|
|
55
|
+
import {
|
|
56
|
+
getOptionTypeDecoder,
|
|
57
|
+
getOptionTypeEncoder,
|
|
58
|
+
type OptionType,
|
|
59
|
+
type OptionTypeArgs,
|
|
60
|
+
} from "../types";
|
|
61
|
+
|
|
62
|
+
export const OPTION_MINT_DISCRIMINATOR = new Uint8Array([
|
|
63
|
+
210, 192, 217, 89, 138, 0, 94, 90,
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
export function getOptionMintDiscriminatorBytes() {
|
|
67
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(OPTION_MINT_DISCRIMINATOR);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type OptionMintInstruction<
|
|
71
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
72
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
73
|
+
TAccountLongMint extends string | AccountMeta<string> = string,
|
|
74
|
+
TAccountShortMint extends string | AccountMeta<string> = string,
|
|
75
|
+
TAccountMintAuthority extends string | AccountMeta<string> = string,
|
|
76
|
+
TAccountMakerLongAccount extends string | AccountMeta<string> = string,
|
|
77
|
+
TAccountMakerShortAccount extends string | AccountMeta<string> = string,
|
|
78
|
+
TAccountLongMetadataAccount extends string | AccountMeta<string> = string,
|
|
79
|
+
TAccountShortMetadataAccount extends string | AccountMeta<string> = string,
|
|
80
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
81
|
+
TAccountUnderlyingMint extends string | AccountMeta<string> = string,
|
|
82
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
83
|
+
TAccountEscrowLongAccount extends string | AccountMeta<string> = string,
|
|
84
|
+
TAccountPremiumVault extends string | AccountMeta<string> = string,
|
|
85
|
+
TAccountCollateralPool extends string | AccountMeta<string> = string,
|
|
86
|
+
TAccountCollateralVault extends string | AccountMeta<string> = string,
|
|
87
|
+
TAccountMakerCollateralAccount extends string | AccountMeta<string> = string,
|
|
88
|
+
TAccountWriterPosition extends string | AccountMeta<string> = string,
|
|
89
|
+
TAccountVault extends string | AccountMeta<string> = string,
|
|
90
|
+
TAccountVaultTokenAccount extends string | AccountMeta<string> = string,
|
|
91
|
+
TAccountEscrowState extends string | AccountMeta<string> = string,
|
|
92
|
+
TAccountEscrowAuthority extends string | AccountMeta<string> = string,
|
|
93
|
+
TAccountEscrowTokenAccount extends string | AccountMeta<string> = string,
|
|
94
|
+
TAccountPoolLoan extends string | AccountMeta<string> = string,
|
|
95
|
+
TAccountLiquidityRouter extends string | AccountMeta<string> = string,
|
|
96
|
+
TAccountMaker extends string | AccountMeta<string> = string,
|
|
97
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
98
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
99
|
+
TAccountAssociatedTokenProgram extends string | AccountMeta<string> =
|
|
100
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
101
|
+
TAccountTokenMetadataProgram extends string | AccountMeta<string> =
|
|
102
|
+
"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
|
|
103
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
104
|
+
"11111111111111111111111111111111",
|
|
105
|
+
TAccountRent extends string | AccountMeta<string> =
|
|
106
|
+
"SysvarRent111111111111111111111111111111111",
|
|
107
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
108
|
+
> = Instruction<TProgram> &
|
|
109
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
110
|
+
InstructionWithAccounts<
|
|
111
|
+
[
|
|
112
|
+
TAccountOptionAccount extends string
|
|
113
|
+
? WritableAccount<TAccountOptionAccount>
|
|
114
|
+
: TAccountOptionAccount,
|
|
115
|
+
TAccountLongMint extends string
|
|
116
|
+
? WritableAccount<TAccountLongMint>
|
|
117
|
+
: TAccountLongMint,
|
|
118
|
+
TAccountShortMint extends string
|
|
119
|
+
? WritableAccount<TAccountShortMint>
|
|
120
|
+
: TAccountShortMint,
|
|
121
|
+
TAccountMintAuthority extends string
|
|
122
|
+
? ReadonlyAccount<TAccountMintAuthority>
|
|
123
|
+
: TAccountMintAuthority,
|
|
124
|
+
TAccountMakerLongAccount extends string
|
|
125
|
+
? WritableAccount<TAccountMakerLongAccount>
|
|
126
|
+
: TAccountMakerLongAccount,
|
|
127
|
+
TAccountMakerShortAccount extends string
|
|
128
|
+
? WritableAccount<TAccountMakerShortAccount>
|
|
129
|
+
: TAccountMakerShortAccount,
|
|
130
|
+
TAccountLongMetadataAccount extends string
|
|
131
|
+
? WritableAccount<TAccountLongMetadataAccount>
|
|
132
|
+
: TAccountLongMetadataAccount,
|
|
133
|
+
TAccountShortMetadataAccount extends string
|
|
134
|
+
? WritableAccount<TAccountShortMetadataAccount>
|
|
135
|
+
: TAccountShortMetadataAccount,
|
|
136
|
+
TAccountMarketData extends string
|
|
137
|
+
? ReadonlyAccount<TAccountMarketData>
|
|
138
|
+
: TAccountMarketData,
|
|
139
|
+
TAccountUnderlyingMint extends string
|
|
140
|
+
? ReadonlyAccount<TAccountUnderlyingMint>
|
|
141
|
+
: TAccountUnderlyingMint,
|
|
142
|
+
TAccountOptionPool extends string
|
|
143
|
+
? WritableAccount<TAccountOptionPool>
|
|
144
|
+
: TAccountOptionPool,
|
|
145
|
+
TAccountEscrowLongAccount extends string
|
|
146
|
+
? WritableAccount<TAccountEscrowLongAccount>
|
|
147
|
+
: TAccountEscrowLongAccount,
|
|
148
|
+
TAccountPremiumVault extends string
|
|
149
|
+
? WritableAccount<TAccountPremiumVault>
|
|
150
|
+
: TAccountPremiumVault,
|
|
151
|
+
TAccountCollateralPool extends string
|
|
152
|
+
? WritableAccount<TAccountCollateralPool>
|
|
153
|
+
: TAccountCollateralPool,
|
|
154
|
+
TAccountCollateralVault extends string
|
|
155
|
+
? WritableAccount<TAccountCollateralVault>
|
|
156
|
+
: TAccountCollateralVault,
|
|
157
|
+
TAccountMakerCollateralAccount extends string
|
|
158
|
+
? WritableAccount<TAccountMakerCollateralAccount>
|
|
159
|
+
: TAccountMakerCollateralAccount,
|
|
160
|
+
TAccountWriterPosition extends string
|
|
161
|
+
? WritableAccount<TAccountWriterPosition>
|
|
162
|
+
: TAccountWriterPosition,
|
|
163
|
+
TAccountVault extends string
|
|
164
|
+
? WritableAccount<TAccountVault>
|
|
165
|
+
: TAccountVault,
|
|
166
|
+
TAccountVaultTokenAccount extends string
|
|
167
|
+
? WritableAccount<TAccountVaultTokenAccount>
|
|
168
|
+
: TAccountVaultTokenAccount,
|
|
169
|
+
TAccountEscrowState extends string
|
|
170
|
+
? WritableAccount<TAccountEscrowState>
|
|
171
|
+
: TAccountEscrowState,
|
|
172
|
+
TAccountEscrowAuthority extends string
|
|
173
|
+
? ReadonlyAccount<TAccountEscrowAuthority>
|
|
174
|
+
: TAccountEscrowAuthority,
|
|
175
|
+
TAccountEscrowTokenAccount extends string
|
|
176
|
+
? WritableAccount<TAccountEscrowTokenAccount>
|
|
177
|
+
: TAccountEscrowTokenAccount,
|
|
178
|
+
TAccountPoolLoan extends string
|
|
179
|
+
? WritableAccount<TAccountPoolLoan>
|
|
180
|
+
: TAccountPoolLoan,
|
|
181
|
+
TAccountLiquidityRouter extends string
|
|
182
|
+
? WritableAccount<TAccountLiquidityRouter>
|
|
183
|
+
: TAccountLiquidityRouter,
|
|
184
|
+
TAccountMaker extends string
|
|
185
|
+
? WritableSignerAccount<TAccountMaker> &
|
|
186
|
+
AccountSignerMeta<TAccountMaker>
|
|
187
|
+
: TAccountMaker,
|
|
188
|
+
TAccountTokenProgram extends string
|
|
189
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
190
|
+
: TAccountTokenProgram,
|
|
191
|
+
TAccountAssociatedTokenProgram extends string
|
|
192
|
+
? ReadonlyAccount<TAccountAssociatedTokenProgram>
|
|
193
|
+
: TAccountAssociatedTokenProgram,
|
|
194
|
+
TAccountTokenMetadataProgram extends string
|
|
195
|
+
? ReadonlyAccount<TAccountTokenMetadataProgram>
|
|
196
|
+
: TAccountTokenMetadataProgram,
|
|
197
|
+
TAccountSystemProgram extends string
|
|
198
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
199
|
+
: TAccountSystemProgram,
|
|
200
|
+
TAccountRent extends string
|
|
201
|
+
? ReadonlyAccount<TAccountRent>
|
|
202
|
+
: TAccountRent,
|
|
203
|
+
...TRemainingAccounts,
|
|
204
|
+
]
|
|
205
|
+
>;
|
|
206
|
+
|
|
207
|
+
export type OptionMintInstructionData = {
|
|
208
|
+
discriminator: ReadonlyUint8Array;
|
|
209
|
+
optionType: OptionType;
|
|
210
|
+
strikePrice: number;
|
|
211
|
+
expirationDate: bigint;
|
|
212
|
+
quantity: bigint;
|
|
213
|
+
underlyingAsset: Address;
|
|
214
|
+
underlyingSymbol: string;
|
|
215
|
+
makerCollateralAmount: bigint;
|
|
216
|
+
borrowedAmount: bigint;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export type OptionMintInstructionDataArgs = {
|
|
220
|
+
optionType: OptionTypeArgs;
|
|
221
|
+
strikePrice: number;
|
|
222
|
+
expirationDate: number | bigint;
|
|
223
|
+
quantity: number | bigint;
|
|
224
|
+
underlyingAsset: Address;
|
|
225
|
+
underlyingSymbol: string;
|
|
226
|
+
makerCollateralAmount: number | bigint;
|
|
227
|
+
borrowedAmount: number | bigint;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export function getOptionMintInstructionDataEncoder(): Encoder<OptionMintInstructionDataArgs> {
|
|
231
|
+
return transformEncoder(
|
|
232
|
+
getStructEncoder([
|
|
233
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
234
|
+
["optionType", getOptionTypeEncoder()],
|
|
235
|
+
["strikePrice", getF64Encoder()],
|
|
236
|
+
["expirationDate", getI64Encoder()],
|
|
237
|
+
["quantity", getU64Encoder()],
|
|
238
|
+
["underlyingAsset", getAddressEncoder()],
|
|
239
|
+
[
|
|
240
|
+
"underlyingSymbol",
|
|
241
|
+
addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()),
|
|
242
|
+
],
|
|
243
|
+
["makerCollateralAmount", getU64Encoder()],
|
|
244
|
+
["borrowedAmount", getU64Encoder()],
|
|
245
|
+
]),
|
|
246
|
+
(value) => ({ ...value, discriminator: OPTION_MINT_DISCRIMINATOR }),
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function getOptionMintInstructionDataDecoder(): Decoder<OptionMintInstructionData> {
|
|
251
|
+
return getStructDecoder([
|
|
252
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
253
|
+
["optionType", getOptionTypeDecoder()],
|
|
254
|
+
["strikePrice", getF64Decoder()],
|
|
255
|
+
["expirationDate", getI64Decoder()],
|
|
256
|
+
["quantity", getU64Decoder()],
|
|
257
|
+
["underlyingAsset", getAddressDecoder()],
|
|
258
|
+
[
|
|
259
|
+
"underlyingSymbol",
|
|
260
|
+
addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder()),
|
|
261
|
+
],
|
|
262
|
+
["makerCollateralAmount", getU64Decoder()],
|
|
263
|
+
["borrowedAmount", getU64Decoder()],
|
|
264
|
+
]);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function getOptionMintInstructionDataCodec(): Codec<
|
|
268
|
+
OptionMintInstructionDataArgs,
|
|
269
|
+
OptionMintInstructionData
|
|
270
|
+
> {
|
|
271
|
+
return combineCodec(
|
|
272
|
+
getOptionMintInstructionDataEncoder(),
|
|
273
|
+
getOptionMintInstructionDataDecoder(),
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export type OptionMintAsyncInput<
|
|
278
|
+
TAccountOptionAccount extends string = string,
|
|
279
|
+
TAccountLongMint extends string = string,
|
|
280
|
+
TAccountShortMint extends string = string,
|
|
281
|
+
TAccountMintAuthority extends string = string,
|
|
282
|
+
TAccountMakerLongAccount extends string = string,
|
|
283
|
+
TAccountMakerShortAccount extends string = string,
|
|
284
|
+
TAccountLongMetadataAccount extends string = string,
|
|
285
|
+
TAccountShortMetadataAccount extends string = string,
|
|
286
|
+
TAccountMarketData extends string = string,
|
|
287
|
+
TAccountUnderlyingMint extends string = string,
|
|
288
|
+
TAccountOptionPool extends string = string,
|
|
289
|
+
TAccountEscrowLongAccount extends string = string,
|
|
290
|
+
TAccountPremiumVault extends string = string,
|
|
291
|
+
TAccountCollateralPool extends string = string,
|
|
292
|
+
TAccountCollateralVault extends string = string,
|
|
293
|
+
TAccountMakerCollateralAccount extends string = string,
|
|
294
|
+
TAccountWriterPosition extends string = string,
|
|
295
|
+
TAccountVault extends string = string,
|
|
296
|
+
TAccountVaultTokenAccount extends string = string,
|
|
297
|
+
TAccountEscrowState extends string = string,
|
|
298
|
+
TAccountEscrowAuthority extends string = string,
|
|
299
|
+
TAccountEscrowTokenAccount extends string = string,
|
|
300
|
+
TAccountPoolLoan extends string = string,
|
|
301
|
+
TAccountLiquidityRouter extends string = string,
|
|
302
|
+
TAccountMaker extends string = string,
|
|
303
|
+
TAccountTokenProgram extends string = string,
|
|
304
|
+
TAccountAssociatedTokenProgram extends string = string,
|
|
305
|
+
TAccountTokenMetadataProgram extends string = string,
|
|
306
|
+
TAccountSystemProgram extends string = string,
|
|
307
|
+
TAccountRent extends string = string,
|
|
308
|
+
> = {
|
|
309
|
+
/**
|
|
310
|
+
* Option account - derived from option parameters (NOT maker)
|
|
311
|
+
* Uses init_if_needed so multiple makers can use the same option
|
|
312
|
+
*/
|
|
313
|
+
optionAccount?: Address<TAccountOptionAccount>;
|
|
314
|
+
/**
|
|
315
|
+
* LONG token mint - one per unique option parameters (buyers hold these)
|
|
316
|
+
* Uses init_if_needed so multiple makers share the same token
|
|
317
|
+
*/
|
|
318
|
+
longMint?: Address<TAccountLongMint>;
|
|
319
|
+
/**
|
|
320
|
+
* SHORT token mint - one per unique option parameters (writers hold these)
|
|
321
|
+
* Uses init_if_needed so multiple makers share the same token
|
|
322
|
+
*/
|
|
323
|
+
shortMint?: Address<TAccountShortMint>;
|
|
324
|
+
mintAuthority?: Address<TAccountMintAuthority>;
|
|
325
|
+
/** Maker's LONG token account (receives LONG tokens to deposit in pool) */
|
|
326
|
+
makerLongAccount?: Address<TAccountMakerLongAccount>;
|
|
327
|
+
/** Maker's SHORT token account (receives SHORT tokens as proof of writing) */
|
|
328
|
+
makerShortAccount?: Address<TAccountMakerShortAccount>;
|
|
329
|
+
longMetadataAccount: Address<TAccountLongMetadataAccount>;
|
|
330
|
+
shortMetadataAccount: Address<TAccountShortMetadataAccount>;
|
|
331
|
+
/** Market data account - provides baseline historical volatility for initial IV */
|
|
332
|
+
marketData?: Address<TAccountMarketData>;
|
|
333
|
+
/** Underlying asset mint (e.g., WSOL) - required for collateral and pool initialization */
|
|
334
|
+
underlyingMint: Address<TAccountUnderlyingMint>;
|
|
335
|
+
/** Option pool - aggregated liquidity pool for this option */
|
|
336
|
+
optionPool?: Address<TAccountOptionPool>;
|
|
337
|
+
/** Pool's escrow for holding LONG tokens (for buyers to purchase) */
|
|
338
|
+
escrowLongAccount?: Address<TAccountEscrowLongAccount>;
|
|
339
|
+
/** Pool's vault for collecting premiums (in underlying asset) */
|
|
340
|
+
premiumVault?: Address<TAccountPremiumVault>;
|
|
341
|
+
/** Collateral pool for this option */
|
|
342
|
+
collateralPool?: Address<TAccountCollateralPool>;
|
|
343
|
+
/** Collateral vault (ATA holding collateral) */
|
|
344
|
+
collateralVault?: Address<TAccountCollateralVault>;
|
|
345
|
+
/** Maker's collateral account (source of maker's own collateral) */
|
|
346
|
+
makerCollateralAccount: Address<TAccountMakerCollateralAccount>;
|
|
347
|
+
/** Writer's unified position account (single source of truth) */
|
|
348
|
+
writerPosition?: Address<TAccountWriterPosition>;
|
|
349
|
+
/** OMLP vault (optional - only required if borrowing) */
|
|
350
|
+
vault?: Address<TAccountVault>;
|
|
351
|
+
/** Vault's token account (optional - only required if borrowing) */
|
|
352
|
+
vaultTokenAccount?: Address<TAccountVaultTokenAccount>;
|
|
353
|
+
/** Escrow state PDA (optional - only required if borrowing) */
|
|
354
|
+
escrowState?: Address<TAccountEscrowState>;
|
|
355
|
+
/** Escrow authority PDA (optional - only required if borrowing) */
|
|
356
|
+
escrowAuthority?: Address<TAccountEscrowAuthority>;
|
|
357
|
+
/** Escrow token account (optional - only required if borrowing) */
|
|
358
|
+
escrowTokenAccount?: Address<TAccountEscrowTokenAccount>;
|
|
359
|
+
/** Pool loan account (optional - only required if borrowing) */
|
|
360
|
+
poolLoan?: Address<TAccountPoolLoan>;
|
|
361
|
+
/** Liquidity router (optional - only required if borrowing with SAP1/SAP2 failover) */
|
|
362
|
+
liquidityRouter?: Address<TAccountLiquidityRouter>;
|
|
363
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
364
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
365
|
+
associatedTokenProgram?: Address<TAccountAssociatedTokenProgram>;
|
|
366
|
+
tokenMetadataProgram?: Address<TAccountTokenMetadataProgram>;
|
|
367
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
368
|
+
rent?: Address<TAccountRent>;
|
|
369
|
+
optionType: OptionMintInstructionDataArgs["optionType"];
|
|
370
|
+
strikePrice: OptionMintInstructionDataArgs["strikePrice"];
|
|
371
|
+
expirationDate: OptionMintInstructionDataArgs["expirationDate"];
|
|
372
|
+
quantity: OptionMintInstructionDataArgs["quantity"];
|
|
373
|
+
underlyingAsset: OptionMintInstructionDataArgs["underlyingAsset"];
|
|
374
|
+
underlyingSymbol: OptionMintInstructionDataArgs["underlyingSymbol"];
|
|
375
|
+
makerCollateralAmount: OptionMintInstructionDataArgs["makerCollateralAmount"];
|
|
376
|
+
borrowedAmount: OptionMintInstructionDataArgs["borrowedAmount"];
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
export async function getOptionMintInstructionAsync<
|
|
380
|
+
TAccountOptionAccount extends string,
|
|
381
|
+
TAccountLongMint extends string,
|
|
382
|
+
TAccountShortMint extends string,
|
|
383
|
+
TAccountMintAuthority extends string,
|
|
384
|
+
TAccountMakerLongAccount extends string,
|
|
385
|
+
TAccountMakerShortAccount extends string,
|
|
386
|
+
TAccountLongMetadataAccount extends string,
|
|
387
|
+
TAccountShortMetadataAccount extends string,
|
|
388
|
+
TAccountMarketData extends string,
|
|
389
|
+
TAccountUnderlyingMint extends string,
|
|
390
|
+
TAccountOptionPool extends string,
|
|
391
|
+
TAccountEscrowLongAccount extends string,
|
|
392
|
+
TAccountPremiumVault extends string,
|
|
393
|
+
TAccountCollateralPool extends string,
|
|
394
|
+
TAccountCollateralVault extends string,
|
|
395
|
+
TAccountMakerCollateralAccount extends string,
|
|
396
|
+
TAccountWriterPosition extends string,
|
|
397
|
+
TAccountVault extends string,
|
|
398
|
+
TAccountVaultTokenAccount extends string,
|
|
399
|
+
TAccountEscrowState extends string,
|
|
400
|
+
TAccountEscrowAuthority extends string,
|
|
401
|
+
TAccountEscrowTokenAccount extends string,
|
|
402
|
+
TAccountPoolLoan extends string,
|
|
403
|
+
TAccountLiquidityRouter extends string,
|
|
404
|
+
TAccountMaker extends string,
|
|
405
|
+
TAccountTokenProgram extends string,
|
|
406
|
+
TAccountAssociatedTokenProgram extends string,
|
|
407
|
+
TAccountTokenMetadataProgram extends string,
|
|
408
|
+
TAccountSystemProgram extends string,
|
|
409
|
+
TAccountRent extends string,
|
|
410
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
411
|
+
>(
|
|
412
|
+
input: OptionMintAsyncInput<
|
|
413
|
+
TAccountOptionAccount,
|
|
414
|
+
TAccountLongMint,
|
|
415
|
+
TAccountShortMint,
|
|
416
|
+
TAccountMintAuthority,
|
|
417
|
+
TAccountMakerLongAccount,
|
|
418
|
+
TAccountMakerShortAccount,
|
|
419
|
+
TAccountLongMetadataAccount,
|
|
420
|
+
TAccountShortMetadataAccount,
|
|
421
|
+
TAccountMarketData,
|
|
422
|
+
TAccountUnderlyingMint,
|
|
423
|
+
TAccountOptionPool,
|
|
424
|
+
TAccountEscrowLongAccount,
|
|
425
|
+
TAccountPremiumVault,
|
|
426
|
+
TAccountCollateralPool,
|
|
427
|
+
TAccountCollateralVault,
|
|
428
|
+
TAccountMakerCollateralAccount,
|
|
429
|
+
TAccountWriterPosition,
|
|
430
|
+
TAccountVault,
|
|
431
|
+
TAccountVaultTokenAccount,
|
|
432
|
+
TAccountEscrowState,
|
|
433
|
+
TAccountEscrowAuthority,
|
|
434
|
+
TAccountEscrowTokenAccount,
|
|
435
|
+
TAccountPoolLoan,
|
|
436
|
+
TAccountLiquidityRouter,
|
|
437
|
+
TAccountMaker,
|
|
438
|
+
TAccountTokenProgram,
|
|
439
|
+
TAccountAssociatedTokenProgram,
|
|
440
|
+
TAccountTokenMetadataProgram,
|
|
441
|
+
TAccountSystemProgram,
|
|
442
|
+
TAccountRent
|
|
443
|
+
>,
|
|
444
|
+
config?: { programAddress?: TProgramAddress },
|
|
445
|
+
): Promise<
|
|
446
|
+
OptionMintInstruction<
|
|
447
|
+
TProgramAddress,
|
|
448
|
+
TAccountOptionAccount,
|
|
449
|
+
TAccountLongMint,
|
|
450
|
+
TAccountShortMint,
|
|
451
|
+
TAccountMintAuthority,
|
|
452
|
+
TAccountMakerLongAccount,
|
|
453
|
+
TAccountMakerShortAccount,
|
|
454
|
+
TAccountLongMetadataAccount,
|
|
455
|
+
TAccountShortMetadataAccount,
|
|
456
|
+
TAccountMarketData,
|
|
457
|
+
TAccountUnderlyingMint,
|
|
458
|
+
TAccountOptionPool,
|
|
459
|
+
TAccountEscrowLongAccount,
|
|
460
|
+
TAccountPremiumVault,
|
|
461
|
+
TAccountCollateralPool,
|
|
462
|
+
TAccountCollateralVault,
|
|
463
|
+
TAccountMakerCollateralAccount,
|
|
464
|
+
TAccountWriterPosition,
|
|
465
|
+
TAccountVault,
|
|
466
|
+
TAccountVaultTokenAccount,
|
|
467
|
+
TAccountEscrowState,
|
|
468
|
+
TAccountEscrowAuthority,
|
|
469
|
+
TAccountEscrowTokenAccount,
|
|
470
|
+
TAccountPoolLoan,
|
|
471
|
+
TAccountLiquidityRouter,
|
|
472
|
+
TAccountMaker,
|
|
473
|
+
TAccountTokenProgram,
|
|
474
|
+
TAccountAssociatedTokenProgram,
|
|
475
|
+
TAccountTokenMetadataProgram,
|
|
476
|
+
TAccountSystemProgram,
|
|
477
|
+
TAccountRent
|
|
478
|
+
>
|
|
479
|
+
> {
|
|
480
|
+
// Program address.
|
|
481
|
+
const programAddress =
|
|
482
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
483
|
+
|
|
484
|
+
// Original accounts.
|
|
485
|
+
const originalAccounts = {
|
|
486
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
487
|
+
longMint: { value: input.longMint ?? null, isWritable: true },
|
|
488
|
+
shortMint: { value: input.shortMint ?? null, isWritable: true },
|
|
489
|
+
mintAuthority: { value: input.mintAuthority ?? null, isWritable: false },
|
|
490
|
+
makerLongAccount: {
|
|
491
|
+
value: input.makerLongAccount ?? null,
|
|
492
|
+
isWritable: true,
|
|
493
|
+
},
|
|
494
|
+
makerShortAccount: {
|
|
495
|
+
value: input.makerShortAccount ?? null,
|
|
496
|
+
isWritable: true,
|
|
497
|
+
},
|
|
498
|
+
longMetadataAccount: {
|
|
499
|
+
value: input.longMetadataAccount ?? null,
|
|
500
|
+
isWritable: true,
|
|
501
|
+
},
|
|
502
|
+
shortMetadataAccount: {
|
|
503
|
+
value: input.shortMetadataAccount ?? null,
|
|
504
|
+
isWritable: true,
|
|
505
|
+
},
|
|
506
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
507
|
+
underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
|
|
508
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
509
|
+
escrowLongAccount: {
|
|
510
|
+
value: input.escrowLongAccount ?? null,
|
|
511
|
+
isWritable: true,
|
|
512
|
+
},
|
|
513
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
514
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
515
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
516
|
+
makerCollateralAccount: {
|
|
517
|
+
value: input.makerCollateralAccount ?? null,
|
|
518
|
+
isWritable: true,
|
|
519
|
+
},
|
|
520
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
521
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
522
|
+
vaultTokenAccount: {
|
|
523
|
+
value: input.vaultTokenAccount ?? null,
|
|
524
|
+
isWritable: true,
|
|
525
|
+
},
|
|
526
|
+
escrowState: { value: input.escrowState ?? null, isWritable: true },
|
|
527
|
+
escrowAuthority: {
|
|
528
|
+
value: input.escrowAuthority ?? null,
|
|
529
|
+
isWritable: false,
|
|
530
|
+
},
|
|
531
|
+
escrowTokenAccount: {
|
|
532
|
+
value: input.escrowTokenAccount ?? null,
|
|
533
|
+
isWritable: true,
|
|
534
|
+
},
|
|
535
|
+
poolLoan: { value: input.poolLoan ?? null, isWritable: true },
|
|
536
|
+
liquidityRouter: { value: input.liquidityRouter ?? null, isWritable: true },
|
|
537
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
538
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
539
|
+
associatedTokenProgram: {
|
|
540
|
+
value: input.associatedTokenProgram ?? null,
|
|
541
|
+
isWritable: false,
|
|
542
|
+
},
|
|
543
|
+
tokenMetadataProgram: {
|
|
544
|
+
value: input.tokenMetadataProgram ?? null,
|
|
545
|
+
isWritable: false,
|
|
546
|
+
},
|
|
547
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
548
|
+
rent: { value: input.rent ?? null, isWritable: false },
|
|
549
|
+
};
|
|
550
|
+
const accounts = originalAccounts as Record<
|
|
551
|
+
keyof typeof originalAccounts,
|
|
552
|
+
ResolvedAccount
|
|
553
|
+
>;
|
|
554
|
+
|
|
555
|
+
// Original args.
|
|
556
|
+
const args = { ...input };
|
|
557
|
+
|
|
558
|
+
// Resolve default values.
|
|
559
|
+
if (!accounts.optionAccount.value) {
|
|
560
|
+
accounts.optionAccount.value = await getProgramDerivedAddress({
|
|
561
|
+
programAddress,
|
|
562
|
+
seeds: [
|
|
563
|
+
getBytesEncoder().encode(
|
|
564
|
+
new Uint8Array([111, 112, 116, 105, 111, 110]),
|
|
565
|
+
),
|
|
566
|
+
getAddressEncoder().encode(expectSome(args.underlyingAsset)),
|
|
567
|
+
getOptionTypeEncoder().encode(expectSome(args.optionType)),
|
|
568
|
+
getF64Encoder().encode(expectSome(args.strikePrice)),
|
|
569
|
+
getI64Encoder().encode(expectSome(args.expirationDate)),
|
|
570
|
+
],
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
if (!accounts.longMint.value) {
|
|
574
|
+
accounts.longMint.value = await getProgramDerivedAddress({
|
|
575
|
+
programAddress,
|
|
576
|
+
seeds: [
|
|
577
|
+
getBytesEncoder().encode(
|
|
578
|
+
new Uint8Array([108, 111, 110, 103, 95, 109, 105, 110, 116]),
|
|
579
|
+
),
|
|
580
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
581
|
+
],
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
if (!accounts.shortMint.value) {
|
|
585
|
+
accounts.shortMint.value = await getProgramDerivedAddress({
|
|
586
|
+
programAddress,
|
|
587
|
+
seeds: [
|
|
588
|
+
getBytesEncoder().encode(
|
|
589
|
+
new Uint8Array([115, 104, 111, 114, 116, 95, 109, 105, 110, 116]),
|
|
590
|
+
),
|
|
591
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
592
|
+
],
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
if (!accounts.mintAuthority.value) {
|
|
596
|
+
accounts.mintAuthority.value = await getProgramDerivedAddress({
|
|
597
|
+
programAddress,
|
|
598
|
+
seeds: [
|
|
599
|
+
getBytesEncoder().encode(
|
|
600
|
+
new Uint8Array([
|
|
601
|
+
109, 105, 110, 116, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121,
|
|
602
|
+
]),
|
|
603
|
+
),
|
|
604
|
+
],
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
if (!accounts.makerLongAccount.value) {
|
|
608
|
+
accounts.makerLongAccount.value = await getProgramDerivedAddress({
|
|
609
|
+
programAddress:
|
|
610
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
611
|
+
seeds: [
|
|
612
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
613
|
+
getBytesEncoder().encode(
|
|
614
|
+
new Uint8Array([
|
|
615
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
616
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
617
|
+
126, 255, 0, 169,
|
|
618
|
+
]),
|
|
619
|
+
),
|
|
620
|
+
getAddressEncoder().encode(expectAddress(accounts.longMint.value)),
|
|
621
|
+
],
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
if (!accounts.makerShortAccount.value) {
|
|
625
|
+
accounts.makerShortAccount.value = await getProgramDerivedAddress({
|
|
626
|
+
programAddress:
|
|
627
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
628
|
+
seeds: [
|
|
629
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
630
|
+
getBytesEncoder().encode(
|
|
631
|
+
new Uint8Array([
|
|
632
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
633
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
634
|
+
126, 255, 0, 169,
|
|
635
|
+
]),
|
|
636
|
+
),
|
|
637
|
+
getAddressEncoder().encode(expectAddress(accounts.shortMint.value)),
|
|
638
|
+
],
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
if (!accounts.marketData.value) {
|
|
642
|
+
accounts.marketData.value = await getProgramDerivedAddress({
|
|
643
|
+
programAddress,
|
|
644
|
+
seeds: [
|
|
645
|
+
getBytesEncoder().encode(
|
|
646
|
+
new Uint8Array([109, 97, 114, 107, 101, 116, 95, 100, 97, 116, 97]),
|
|
647
|
+
),
|
|
648
|
+
getAddressEncoder().encode(expectSome(args.underlyingAsset)),
|
|
649
|
+
],
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
if (!accounts.optionPool.value) {
|
|
653
|
+
accounts.optionPool.value = await getProgramDerivedAddress({
|
|
654
|
+
programAddress,
|
|
655
|
+
seeds: [
|
|
656
|
+
getBytesEncoder().encode(
|
|
657
|
+
new Uint8Array([
|
|
658
|
+
111, 112, 116, 105, 111, 110, 95, 112, 111, 111, 108,
|
|
659
|
+
]),
|
|
660
|
+
),
|
|
661
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
662
|
+
],
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
if (!accounts.escrowLongAccount.value) {
|
|
666
|
+
accounts.escrowLongAccount.value = await getProgramDerivedAddress({
|
|
667
|
+
programAddress:
|
|
668
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
669
|
+
seeds: [
|
|
670
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
671
|
+
getBytesEncoder().encode(
|
|
672
|
+
new Uint8Array([
|
|
673
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
674
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
675
|
+
126, 255, 0, 169,
|
|
676
|
+
]),
|
|
677
|
+
),
|
|
678
|
+
getAddressEncoder().encode(expectAddress(accounts.longMint.value)),
|
|
679
|
+
],
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
if (!accounts.premiumVault.value) {
|
|
683
|
+
accounts.premiumVault.value = await getProgramDerivedAddress({
|
|
684
|
+
programAddress:
|
|
685
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
686
|
+
seeds: [
|
|
687
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
688
|
+
getBytesEncoder().encode(
|
|
689
|
+
new Uint8Array([
|
|
690
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
691
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
692
|
+
126, 255, 0, 169,
|
|
693
|
+
]),
|
|
694
|
+
),
|
|
695
|
+
getAddressEncoder().encode(
|
|
696
|
+
expectAddress(accounts.underlyingMint.value),
|
|
697
|
+
),
|
|
698
|
+
],
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
if (!accounts.collateralPool.value) {
|
|
702
|
+
accounts.collateralPool.value = await getProgramDerivedAddress({
|
|
703
|
+
programAddress,
|
|
704
|
+
seeds: [
|
|
705
|
+
getBytesEncoder().encode(
|
|
706
|
+
new Uint8Array([
|
|
707
|
+
99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
|
|
708
|
+
108,
|
|
709
|
+
]),
|
|
710
|
+
),
|
|
711
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
712
|
+
],
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
if (!accounts.collateralVault.value) {
|
|
716
|
+
accounts.collateralVault.value = await getProgramDerivedAddress({
|
|
717
|
+
programAddress:
|
|
718
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">,
|
|
719
|
+
seeds: [
|
|
720
|
+
getAddressEncoder().encode(
|
|
721
|
+
expectAddress(accounts.collateralPool.value),
|
|
722
|
+
),
|
|
723
|
+
getBytesEncoder().encode(
|
|
724
|
+
new Uint8Array([
|
|
725
|
+
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235,
|
|
726
|
+
121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133,
|
|
727
|
+
126, 255, 0, 169,
|
|
728
|
+
]),
|
|
729
|
+
),
|
|
730
|
+
getAddressEncoder().encode(
|
|
731
|
+
expectAddress(accounts.underlyingMint.value),
|
|
732
|
+
),
|
|
733
|
+
],
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
if (!accounts.writerPosition.value) {
|
|
737
|
+
accounts.writerPosition.value = await getProgramDerivedAddress({
|
|
738
|
+
programAddress,
|
|
739
|
+
seeds: [
|
|
740
|
+
getBytesEncoder().encode(
|
|
741
|
+
new Uint8Array([
|
|
742
|
+
119, 114, 105, 116, 101, 114, 95, 112, 111, 115, 105, 116, 105, 111,
|
|
743
|
+
110,
|
|
744
|
+
]),
|
|
745
|
+
),
|
|
746
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
747
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
748
|
+
],
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
if (!accounts.tokenProgram.value) {
|
|
752
|
+
accounts.tokenProgram.value =
|
|
753
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
754
|
+
}
|
|
755
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
756
|
+
accounts.associatedTokenProgram.value =
|
|
757
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
|
|
758
|
+
}
|
|
759
|
+
if (!accounts.tokenMetadataProgram.value) {
|
|
760
|
+
accounts.tokenMetadataProgram.value =
|
|
761
|
+
"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" as Address<"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s">;
|
|
762
|
+
}
|
|
763
|
+
if (!accounts.systemProgram.value) {
|
|
764
|
+
accounts.systemProgram.value =
|
|
765
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
766
|
+
}
|
|
767
|
+
if (!accounts.rent.value) {
|
|
768
|
+
accounts.rent.value =
|
|
769
|
+
"SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
773
|
+
return Object.freeze({
|
|
774
|
+
accounts: [
|
|
775
|
+
getAccountMeta(accounts.optionAccount),
|
|
776
|
+
getAccountMeta(accounts.longMint),
|
|
777
|
+
getAccountMeta(accounts.shortMint),
|
|
778
|
+
getAccountMeta(accounts.mintAuthority),
|
|
779
|
+
getAccountMeta(accounts.makerLongAccount),
|
|
780
|
+
getAccountMeta(accounts.makerShortAccount),
|
|
781
|
+
getAccountMeta(accounts.longMetadataAccount),
|
|
782
|
+
getAccountMeta(accounts.shortMetadataAccount),
|
|
783
|
+
getAccountMeta(accounts.marketData),
|
|
784
|
+
getAccountMeta(accounts.underlyingMint),
|
|
785
|
+
getAccountMeta(accounts.optionPool),
|
|
786
|
+
getAccountMeta(accounts.escrowLongAccount),
|
|
787
|
+
getAccountMeta(accounts.premiumVault),
|
|
788
|
+
getAccountMeta(accounts.collateralPool),
|
|
789
|
+
getAccountMeta(accounts.collateralVault),
|
|
790
|
+
getAccountMeta(accounts.makerCollateralAccount),
|
|
791
|
+
getAccountMeta(accounts.writerPosition),
|
|
792
|
+
getAccountMeta(accounts.vault),
|
|
793
|
+
getAccountMeta(accounts.vaultTokenAccount),
|
|
794
|
+
getAccountMeta(accounts.escrowState),
|
|
795
|
+
getAccountMeta(accounts.escrowAuthority),
|
|
796
|
+
getAccountMeta(accounts.escrowTokenAccount),
|
|
797
|
+
getAccountMeta(accounts.poolLoan),
|
|
798
|
+
getAccountMeta(accounts.liquidityRouter),
|
|
799
|
+
getAccountMeta(accounts.maker),
|
|
800
|
+
getAccountMeta(accounts.tokenProgram),
|
|
801
|
+
getAccountMeta(accounts.associatedTokenProgram),
|
|
802
|
+
getAccountMeta(accounts.tokenMetadataProgram),
|
|
803
|
+
getAccountMeta(accounts.systemProgram),
|
|
804
|
+
getAccountMeta(accounts.rent),
|
|
805
|
+
],
|
|
806
|
+
data: getOptionMintInstructionDataEncoder().encode(
|
|
807
|
+
args as OptionMintInstructionDataArgs,
|
|
808
|
+
),
|
|
809
|
+
programAddress,
|
|
810
|
+
} as OptionMintInstruction<
|
|
811
|
+
TProgramAddress,
|
|
812
|
+
TAccountOptionAccount,
|
|
813
|
+
TAccountLongMint,
|
|
814
|
+
TAccountShortMint,
|
|
815
|
+
TAccountMintAuthority,
|
|
816
|
+
TAccountMakerLongAccount,
|
|
817
|
+
TAccountMakerShortAccount,
|
|
818
|
+
TAccountLongMetadataAccount,
|
|
819
|
+
TAccountShortMetadataAccount,
|
|
820
|
+
TAccountMarketData,
|
|
821
|
+
TAccountUnderlyingMint,
|
|
822
|
+
TAccountOptionPool,
|
|
823
|
+
TAccountEscrowLongAccount,
|
|
824
|
+
TAccountPremiumVault,
|
|
825
|
+
TAccountCollateralPool,
|
|
826
|
+
TAccountCollateralVault,
|
|
827
|
+
TAccountMakerCollateralAccount,
|
|
828
|
+
TAccountWriterPosition,
|
|
829
|
+
TAccountVault,
|
|
830
|
+
TAccountVaultTokenAccount,
|
|
831
|
+
TAccountEscrowState,
|
|
832
|
+
TAccountEscrowAuthority,
|
|
833
|
+
TAccountEscrowTokenAccount,
|
|
834
|
+
TAccountPoolLoan,
|
|
835
|
+
TAccountLiquidityRouter,
|
|
836
|
+
TAccountMaker,
|
|
837
|
+
TAccountTokenProgram,
|
|
838
|
+
TAccountAssociatedTokenProgram,
|
|
839
|
+
TAccountTokenMetadataProgram,
|
|
840
|
+
TAccountSystemProgram,
|
|
841
|
+
TAccountRent
|
|
842
|
+
>);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
export type OptionMintInput<
|
|
846
|
+
TAccountOptionAccount extends string = string,
|
|
847
|
+
TAccountLongMint extends string = string,
|
|
848
|
+
TAccountShortMint extends string = string,
|
|
849
|
+
TAccountMintAuthority extends string = string,
|
|
850
|
+
TAccountMakerLongAccount extends string = string,
|
|
851
|
+
TAccountMakerShortAccount extends string = string,
|
|
852
|
+
TAccountLongMetadataAccount extends string = string,
|
|
853
|
+
TAccountShortMetadataAccount extends string = string,
|
|
854
|
+
TAccountMarketData extends string = string,
|
|
855
|
+
TAccountUnderlyingMint extends string = string,
|
|
856
|
+
TAccountOptionPool extends string = string,
|
|
857
|
+
TAccountEscrowLongAccount extends string = string,
|
|
858
|
+
TAccountPremiumVault extends string = string,
|
|
859
|
+
TAccountCollateralPool extends string = string,
|
|
860
|
+
TAccountCollateralVault extends string = string,
|
|
861
|
+
TAccountMakerCollateralAccount extends string = string,
|
|
862
|
+
TAccountWriterPosition extends string = string,
|
|
863
|
+
TAccountVault extends string = string,
|
|
864
|
+
TAccountVaultTokenAccount extends string = string,
|
|
865
|
+
TAccountEscrowState extends string = string,
|
|
866
|
+
TAccountEscrowAuthority extends string = string,
|
|
867
|
+
TAccountEscrowTokenAccount extends string = string,
|
|
868
|
+
TAccountPoolLoan extends string = string,
|
|
869
|
+
TAccountLiquidityRouter extends string = string,
|
|
870
|
+
TAccountMaker extends string = string,
|
|
871
|
+
TAccountTokenProgram extends string = string,
|
|
872
|
+
TAccountAssociatedTokenProgram extends string = string,
|
|
873
|
+
TAccountTokenMetadataProgram extends string = string,
|
|
874
|
+
TAccountSystemProgram extends string = string,
|
|
875
|
+
TAccountRent extends string = string,
|
|
876
|
+
> = {
|
|
877
|
+
/**
|
|
878
|
+
* Option account - derived from option parameters (NOT maker)
|
|
879
|
+
* Uses init_if_needed so multiple makers can use the same option
|
|
880
|
+
*/
|
|
881
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
882
|
+
/**
|
|
883
|
+
* LONG token mint - one per unique option parameters (buyers hold these)
|
|
884
|
+
* Uses init_if_needed so multiple makers share the same token
|
|
885
|
+
*/
|
|
886
|
+
longMint: Address<TAccountLongMint>;
|
|
887
|
+
/**
|
|
888
|
+
* SHORT token mint - one per unique option parameters (writers hold these)
|
|
889
|
+
* Uses init_if_needed so multiple makers share the same token
|
|
890
|
+
*/
|
|
891
|
+
shortMint: Address<TAccountShortMint>;
|
|
892
|
+
mintAuthority: Address<TAccountMintAuthority>;
|
|
893
|
+
/** Maker's LONG token account (receives LONG tokens to deposit in pool) */
|
|
894
|
+
makerLongAccount: Address<TAccountMakerLongAccount>;
|
|
895
|
+
/** Maker's SHORT token account (receives SHORT tokens as proof of writing) */
|
|
896
|
+
makerShortAccount: Address<TAccountMakerShortAccount>;
|
|
897
|
+
longMetadataAccount: Address<TAccountLongMetadataAccount>;
|
|
898
|
+
shortMetadataAccount: Address<TAccountShortMetadataAccount>;
|
|
899
|
+
/** Market data account - provides baseline historical volatility for initial IV */
|
|
900
|
+
marketData: Address<TAccountMarketData>;
|
|
901
|
+
/** Underlying asset mint (e.g., WSOL) - required for collateral and pool initialization */
|
|
902
|
+
underlyingMint: Address<TAccountUnderlyingMint>;
|
|
903
|
+
/** Option pool - aggregated liquidity pool for this option */
|
|
904
|
+
optionPool: Address<TAccountOptionPool>;
|
|
905
|
+
/** Pool's escrow for holding LONG tokens (for buyers to purchase) */
|
|
906
|
+
escrowLongAccount: Address<TAccountEscrowLongAccount>;
|
|
907
|
+
/** Pool's vault for collecting premiums (in underlying asset) */
|
|
908
|
+
premiumVault: Address<TAccountPremiumVault>;
|
|
909
|
+
/** Collateral pool for this option */
|
|
910
|
+
collateralPool: Address<TAccountCollateralPool>;
|
|
911
|
+
/** Collateral vault (ATA holding collateral) */
|
|
912
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
913
|
+
/** Maker's collateral account (source of maker's own collateral) */
|
|
914
|
+
makerCollateralAccount: Address<TAccountMakerCollateralAccount>;
|
|
915
|
+
/** Writer's unified position account (single source of truth) */
|
|
916
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
917
|
+
/** OMLP vault (optional - only required if borrowing) */
|
|
918
|
+
vault?: Address<TAccountVault>;
|
|
919
|
+
/** Vault's token account (optional - only required if borrowing) */
|
|
920
|
+
vaultTokenAccount?: Address<TAccountVaultTokenAccount>;
|
|
921
|
+
/** Escrow state PDA (optional - only required if borrowing) */
|
|
922
|
+
escrowState?: Address<TAccountEscrowState>;
|
|
923
|
+
/** Escrow authority PDA (optional - only required if borrowing) */
|
|
924
|
+
escrowAuthority?: Address<TAccountEscrowAuthority>;
|
|
925
|
+
/** Escrow token account (optional - only required if borrowing) */
|
|
926
|
+
escrowTokenAccount?: Address<TAccountEscrowTokenAccount>;
|
|
927
|
+
/** Pool loan account (optional - only required if borrowing) */
|
|
928
|
+
poolLoan?: Address<TAccountPoolLoan>;
|
|
929
|
+
/** Liquidity router (optional - only required if borrowing with SAP1/SAP2 failover) */
|
|
930
|
+
liquidityRouter?: Address<TAccountLiquidityRouter>;
|
|
931
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
932
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
933
|
+
associatedTokenProgram?: Address<TAccountAssociatedTokenProgram>;
|
|
934
|
+
tokenMetadataProgram?: Address<TAccountTokenMetadataProgram>;
|
|
935
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
936
|
+
rent?: Address<TAccountRent>;
|
|
937
|
+
optionType: OptionMintInstructionDataArgs["optionType"];
|
|
938
|
+
strikePrice: OptionMintInstructionDataArgs["strikePrice"];
|
|
939
|
+
expirationDate: OptionMintInstructionDataArgs["expirationDate"];
|
|
940
|
+
quantity: OptionMintInstructionDataArgs["quantity"];
|
|
941
|
+
underlyingAsset: OptionMintInstructionDataArgs["underlyingAsset"];
|
|
942
|
+
underlyingSymbol: OptionMintInstructionDataArgs["underlyingSymbol"];
|
|
943
|
+
makerCollateralAmount: OptionMintInstructionDataArgs["makerCollateralAmount"];
|
|
944
|
+
borrowedAmount: OptionMintInstructionDataArgs["borrowedAmount"];
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
export function getOptionMintInstruction<
|
|
948
|
+
TAccountOptionAccount extends string,
|
|
949
|
+
TAccountLongMint extends string,
|
|
950
|
+
TAccountShortMint extends string,
|
|
951
|
+
TAccountMintAuthority extends string,
|
|
952
|
+
TAccountMakerLongAccount extends string,
|
|
953
|
+
TAccountMakerShortAccount extends string,
|
|
954
|
+
TAccountLongMetadataAccount extends string,
|
|
955
|
+
TAccountShortMetadataAccount extends string,
|
|
956
|
+
TAccountMarketData extends string,
|
|
957
|
+
TAccountUnderlyingMint extends string,
|
|
958
|
+
TAccountOptionPool extends string,
|
|
959
|
+
TAccountEscrowLongAccount extends string,
|
|
960
|
+
TAccountPremiumVault extends string,
|
|
961
|
+
TAccountCollateralPool extends string,
|
|
962
|
+
TAccountCollateralVault extends string,
|
|
963
|
+
TAccountMakerCollateralAccount extends string,
|
|
964
|
+
TAccountWriterPosition extends string,
|
|
965
|
+
TAccountVault extends string,
|
|
966
|
+
TAccountVaultTokenAccount extends string,
|
|
967
|
+
TAccountEscrowState extends string,
|
|
968
|
+
TAccountEscrowAuthority extends string,
|
|
969
|
+
TAccountEscrowTokenAccount extends string,
|
|
970
|
+
TAccountPoolLoan extends string,
|
|
971
|
+
TAccountLiquidityRouter extends string,
|
|
972
|
+
TAccountMaker extends string,
|
|
973
|
+
TAccountTokenProgram extends string,
|
|
974
|
+
TAccountAssociatedTokenProgram extends string,
|
|
975
|
+
TAccountTokenMetadataProgram extends string,
|
|
976
|
+
TAccountSystemProgram extends string,
|
|
977
|
+
TAccountRent extends string,
|
|
978
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
979
|
+
>(
|
|
980
|
+
input: OptionMintInput<
|
|
981
|
+
TAccountOptionAccount,
|
|
982
|
+
TAccountLongMint,
|
|
983
|
+
TAccountShortMint,
|
|
984
|
+
TAccountMintAuthority,
|
|
985
|
+
TAccountMakerLongAccount,
|
|
986
|
+
TAccountMakerShortAccount,
|
|
987
|
+
TAccountLongMetadataAccount,
|
|
988
|
+
TAccountShortMetadataAccount,
|
|
989
|
+
TAccountMarketData,
|
|
990
|
+
TAccountUnderlyingMint,
|
|
991
|
+
TAccountOptionPool,
|
|
992
|
+
TAccountEscrowLongAccount,
|
|
993
|
+
TAccountPremiumVault,
|
|
994
|
+
TAccountCollateralPool,
|
|
995
|
+
TAccountCollateralVault,
|
|
996
|
+
TAccountMakerCollateralAccount,
|
|
997
|
+
TAccountWriterPosition,
|
|
998
|
+
TAccountVault,
|
|
999
|
+
TAccountVaultTokenAccount,
|
|
1000
|
+
TAccountEscrowState,
|
|
1001
|
+
TAccountEscrowAuthority,
|
|
1002
|
+
TAccountEscrowTokenAccount,
|
|
1003
|
+
TAccountPoolLoan,
|
|
1004
|
+
TAccountLiquidityRouter,
|
|
1005
|
+
TAccountMaker,
|
|
1006
|
+
TAccountTokenProgram,
|
|
1007
|
+
TAccountAssociatedTokenProgram,
|
|
1008
|
+
TAccountTokenMetadataProgram,
|
|
1009
|
+
TAccountSystemProgram,
|
|
1010
|
+
TAccountRent
|
|
1011
|
+
>,
|
|
1012
|
+
config?: { programAddress?: TProgramAddress },
|
|
1013
|
+
): OptionMintInstruction<
|
|
1014
|
+
TProgramAddress,
|
|
1015
|
+
TAccountOptionAccount,
|
|
1016
|
+
TAccountLongMint,
|
|
1017
|
+
TAccountShortMint,
|
|
1018
|
+
TAccountMintAuthority,
|
|
1019
|
+
TAccountMakerLongAccount,
|
|
1020
|
+
TAccountMakerShortAccount,
|
|
1021
|
+
TAccountLongMetadataAccount,
|
|
1022
|
+
TAccountShortMetadataAccount,
|
|
1023
|
+
TAccountMarketData,
|
|
1024
|
+
TAccountUnderlyingMint,
|
|
1025
|
+
TAccountOptionPool,
|
|
1026
|
+
TAccountEscrowLongAccount,
|
|
1027
|
+
TAccountPremiumVault,
|
|
1028
|
+
TAccountCollateralPool,
|
|
1029
|
+
TAccountCollateralVault,
|
|
1030
|
+
TAccountMakerCollateralAccount,
|
|
1031
|
+
TAccountWriterPosition,
|
|
1032
|
+
TAccountVault,
|
|
1033
|
+
TAccountVaultTokenAccount,
|
|
1034
|
+
TAccountEscrowState,
|
|
1035
|
+
TAccountEscrowAuthority,
|
|
1036
|
+
TAccountEscrowTokenAccount,
|
|
1037
|
+
TAccountPoolLoan,
|
|
1038
|
+
TAccountLiquidityRouter,
|
|
1039
|
+
TAccountMaker,
|
|
1040
|
+
TAccountTokenProgram,
|
|
1041
|
+
TAccountAssociatedTokenProgram,
|
|
1042
|
+
TAccountTokenMetadataProgram,
|
|
1043
|
+
TAccountSystemProgram,
|
|
1044
|
+
TAccountRent
|
|
1045
|
+
> {
|
|
1046
|
+
// Program address.
|
|
1047
|
+
const programAddress =
|
|
1048
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
1049
|
+
|
|
1050
|
+
// Original accounts.
|
|
1051
|
+
const originalAccounts = {
|
|
1052
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
1053
|
+
longMint: { value: input.longMint ?? null, isWritable: true },
|
|
1054
|
+
shortMint: { value: input.shortMint ?? null, isWritable: true },
|
|
1055
|
+
mintAuthority: { value: input.mintAuthority ?? null, isWritable: false },
|
|
1056
|
+
makerLongAccount: {
|
|
1057
|
+
value: input.makerLongAccount ?? null,
|
|
1058
|
+
isWritable: true,
|
|
1059
|
+
},
|
|
1060
|
+
makerShortAccount: {
|
|
1061
|
+
value: input.makerShortAccount ?? null,
|
|
1062
|
+
isWritable: true,
|
|
1063
|
+
},
|
|
1064
|
+
longMetadataAccount: {
|
|
1065
|
+
value: input.longMetadataAccount ?? null,
|
|
1066
|
+
isWritable: true,
|
|
1067
|
+
},
|
|
1068
|
+
shortMetadataAccount: {
|
|
1069
|
+
value: input.shortMetadataAccount ?? null,
|
|
1070
|
+
isWritable: true,
|
|
1071
|
+
},
|
|
1072
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
1073
|
+
underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
|
|
1074
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
1075
|
+
escrowLongAccount: {
|
|
1076
|
+
value: input.escrowLongAccount ?? null,
|
|
1077
|
+
isWritable: true,
|
|
1078
|
+
},
|
|
1079
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
1080
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
1081
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
1082
|
+
makerCollateralAccount: {
|
|
1083
|
+
value: input.makerCollateralAccount ?? null,
|
|
1084
|
+
isWritable: true,
|
|
1085
|
+
},
|
|
1086
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
1087
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
1088
|
+
vaultTokenAccount: {
|
|
1089
|
+
value: input.vaultTokenAccount ?? null,
|
|
1090
|
+
isWritable: true,
|
|
1091
|
+
},
|
|
1092
|
+
escrowState: { value: input.escrowState ?? null, isWritable: true },
|
|
1093
|
+
escrowAuthority: {
|
|
1094
|
+
value: input.escrowAuthority ?? null,
|
|
1095
|
+
isWritable: false,
|
|
1096
|
+
},
|
|
1097
|
+
escrowTokenAccount: {
|
|
1098
|
+
value: input.escrowTokenAccount ?? null,
|
|
1099
|
+
isWritable: true,
|
|
1100
|
+
},
|
|
1101
|
+
poolLoan: { value: input.poolLoan ?? null, isWritable: true },
|
|
1102
|
+
liquidityRouter: { value: input.liquidityRouter ?? null, isWritable: true },
|
|
1103
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
1104
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
1105
|
+
associatedTokenProgram: {
|
|
1106
|
+
value: input.associatedTokenProgram ?? null,
|
|
1107
|
+
isWritable: false,
|
|
1108
|
+
},
|
|
1109
|
+
tokenMetadataProgram: {
|
|
1110
|
+
value: input.tokenMetadataProgram ?? null,
|
|
1111
|
+
isWritable: false,
|
|
1112
|
+
},
|
|
1113
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
1114
|
+
rent: { value: input.rent ?? null, isWritable: false },
|
|
1115
|
+
};
|
|
1116
|
+
const accounts = originalAccounts as Record<
|
|
1117
|
+
keyof typeof originalAccounts,
|
|
1118
|
+
ResolvedAccount
|
|
1119
|
+
>;
|
|
1120
|
+
|
|
1121
|
+
// Original args.
|
|
1122
|
+
const args = { ...input };
|
|
1123
|
+
|
|
1124
|
+
// Resolve default values.
|
|
1125
|
+
if (!accounts.tokenProgram.value) {
|
|
1126
|
+
accounts.tokenProgram.value =
|
|
1127
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
1128
|
+
}
|
|
1129
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
1130
|
+
accounts.associatedTokenProgram.value =
|
|
1131
|
+
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">;
|
|
1132
|
+
}
|
|
1133
|
+
if (!accounts.tokenMetadataProgram.value) {
|
|
1134
|
+
accounts.tokenMetadataProgram.value =
|
|
1135
|
+
"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" as Address<"metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s">;
|
|
1136
|
+
}
|
|
1137
|
+
if (!accounts.systemProgram.value) {
|
|
1138
|
+
accounts.systemProgram.value =
|
|
1139
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
1140
|
+
}
|
|
1141
|
+
if (!accounts.rent.value) {
|
|
1142
|
+
accounts.rent.value =
|
|
1143
|
+
"SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
1147
|
+
return Object.freeze({
|
|
1148
|
+
accounts: [
|
|
1149
|
+
getAccountMeta(accounts.optionAccount),
|
|
1150
|
+
getAccountMeta(accounts.longMint),
|
|
1151
|
+
getAccountMeta(accounts.shortMint),
|
|
1152
|
+
getAccountMeta(accounts.mintAuthority),
|
|
1153
|
+
getAccountMeta(accounts.makerLongAccount),
|
|
1154
|
+
getAccountMeta(accounts.makerShortAccount),
|
|
1155
|
+
getAccountMeta(accounts.longMetadataAccount),
|
|
1156
|
+
getAccountMeta(accounts.shortMetadataAccount),
|
|
1157
|
+
getAccountMeta(accounts.marketData),
|
|
1158
|
+
getAccountMeta(accounts.underlyingMint),
|
|
1159
|
+
getAccountMeta(accounts.optionPool),
|
|
1160
|
+
getAccountMeta(accounts.escrowLongAccount),
|
|
1161
|
+
getAccountMeta(accounts.premiumVault),
|
|
1162
|
+
getAccountMeta(accounts.collateralPool),
|
|
1163
|
+
getAccountMeta(accounts.collateralVault),
|
|
1164
|
+
getAccountMeta(accounts.makerCollateralAccount),
|
|
1165
|
+
getAccountMeta(accounts.writerPosition),
|
|
1166
|
+
getAccountMeta(accounts.vault),
|
|
1167
|
+
getAccountMeta(accounts.vaultTokenAccount),
|
|
1168
|
+
getAccountMeta(accounts.escrowState),
|
|
1169
|
+
getAccountMeta(accounts.escrowAuthority),
|
|
1170
|
+
getAccountMeta(accounts.escrowTokenAccount),
|
|
1171
|
+
getAccountMeta(accounts.poolLoan),
|
|
1172
|
+
getAccountMeta(accounts.liquidityRouter),
|
|
1173
|
+
getAccountMeta(accounts.maker),
|
|
1174
|
+
getAccountMeta(accounts.tokenProgram),
|
|
1175
|
+
getAccountMeta(accounts.associatedTokenProgram),
|
|
1176
|
+
getAccountMeta(accounts.tokenMetadataProgram),
|
|
1177
|
+
getAccountMeta(accounts.systemProgram),
|
|
1178
|
+
getAccountMeta(accounts.rent),
|
|
1179
|
+
],
|
|
1180
|
+
data: getOptionMintInstructionDataEncoder().encode(
|
|
1181
|
+
args as OptionMintInstructionDataArgs,
|
|
1182
|
+
),
|
|
1183
|
+
programAddress,
|
|
1184
|
+
} as OptionMintInstruction<
|
|
1185
|
+
TProgramAddress,
|
|
1186
|
+
TAccountOptionAccount,
|
|
1187
|
+
TAccountLongMint,
|
|
1188
|
+
TAccountShortMint,
|
|
1189
|
+
TAccountMintAuthority,
|
|
1190
|
+
TAccountMakerLongAccount,
|
|
1191
|
+
TAccountMakerShortAccount,
|
|
1192
|
+
TAccountLongMetadataAccount,
|
|
1193
|
+
TAccountShortMetadataAccount,
|
|
1194
|
+
TAccountMarketData,
|
|
1195
|
+
TAccountUnderlyingMint,
|
|
1196
|
+
TAccountOptionPool,
|
|
1197
|
+
TAccountEscrowLongAccount,
|
|
1198
|
+
TAccountPremiumVault,
|
|
1199
|
+
TAccountCollateralPool,
|
|
1200
|
+
TAccountCollateralVault,
|
|
1201
|
+
TAccountMakerCollateralAccount,
|
|
1202
|
+
TAccountWriterPosition,
|
|
1203
|
+
TAccountVault,
|
|
1204
|
+
TAccountVaultTokenAccount,
|
|
1205
|
+
TAccountEscrowState,
|
|
1206
|
+
TAccountEscrowAuthority,
|
|
1207
|
+
TAccountEscrowTokenAccount,
|
|
1208
|
+
TAccountPoolLoan,
|
|
1209
|
+
TAccountLiquidityRouter,
|
|
1210
|
+
TAccountMaker,
|
|
1211
|
+
TAccountTokenProgram,
|
|
1212
|
+
TAccountAssociatedTokenProgram,
|
|
1213
|
+
TAccountTokenMetadataProgram,
|
|
1214
|
+
TAccountSystemProgram,
|
|
1215
|
+
TAccountRent
|
|
1216
|
+
>);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
export type ParsedOptionMintInstruction<
|
|
1220
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
1221
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
1222
|
+
> = {
|
|
1223
|
+
programAddress: Address<TProgram>;
|
|
1224
|
+
accounts: {
|
|
1225
|
+
/**
|
|
1226
|
+
* Option account - derived from option parameters (NOT maker)
|
|
1227
|
+
* Uses init_if_needed so multiple makers can use the same option
|
|
1228
|
+
*/
|
|
1229
|
+
optionAccount: TAccountMetas[0];
|
|
1230
|
+
/**
|
|
1231
|
+
* LONG token mint - one per unique option parameters (buyers hold these)
|
|
1232
|
+
* Uses init_if_needed so multiple makers share the same token
|
|
1233
|
+
*/
|
|
1234
|
+
longMint: TAccountMetas[1];
|
|
1235
|
+
/**
|
|
1236
|
+
* SHORT token mint - one per unique option parameters (writers hold these)
|
|
1237
|
+
* Uses init_if_needed so multiple makers share the same token
|
|
1238
|
+
*/
|
|
1239
|
+
shortMint: TAccountMetas[2];
|
|
1240
|
+
mintAuthority: TAccountMetas[3];
|
|
1241
|
+
/** Maker's LONG token account (receives LONG tokens to deposit in pool) */
|
|
1242
|
+
makerLongAccount: TAccountMetas[4];
|
|
1243
|
+
/** Maker's SHORT token account (receives SHORT tokens as proof of writing) */
|
|
1244
|
+
makerShortAccount: TAccountMetas[5];
|
|
1245
|
+
longMetadataAccount: TAccountMetas[6];
|
|
1246
|
+
shortMetadataAccount: TAccountMetas[7];
|
|
1247
|
+
/** Market data account - provides baseline historical volatility for initial IV */
|
|
1248
|
+
marketData: TAccountMetas[8];
|
|
1249
|
+
/** Underlying asset mint (e.g., WSOL) - required for collateral and pool initialization */
|
|
1250
|
+
underlyingMint: TAccountMetas[9];
|
|
1251
|
+
/** Option pool - aggregated liquidity pool for this option */
|
|
1252
|
+
optionPool: TAccountMetas[10];
|
|
1253
|
+
/** Pool's escrow for holding LONG tokens (for buyers to purchase) */
|
|
1254
|
+
escrowLongAccount: TAccountMetas[11];
|
|
1255
|
+
/** Pool's vault for collecting premiums (in underlying asset) */
|
|
1256
|
+
premiumVault: TAccountMetas[12];
|
|
1257
|
+
/** Collateral pool for this option */
|
|
1258
|
+
collateralPool: TAccountMetas[13];
|
|
1259
|
+
/** Collateral vault (ATA holding collateral) */
|
|
1260
|
+
collateralVault: TAccountMetas[14];
|
|
1261
|
+
/** Maker's collateral account (source of maker's own collateral) */
|
|
1262
|
+
makerCollateralAccount: TAccountMetas[15];
|
|
1263
|
+
/** Writer's unified position account (single source of truth) */
|
|
1264
|
+
writerPosition: TAccountMetas[16];
|
|
1265
|
+
/** OMLP vault (optional - only required if borrowing) */
|
|
1266
|
+
vault?: TAccountMetas[17] | undefined;
|
|
1267
|
+
/** Vault's token account (optional - only required if borrowing) */
|
|
1268
|
+
vaultTokenAccount?: TAccountMetas[18] | undefined;
|
|
1269
|
+
/** Escrow state PDA (optional - only required if borrowing) */
|
|
1270
|
+
escrowState?: TAccountMetas[19] | undefined;
|
|
1271
|
+
/** Escrow authority PDA (optional - only required if borrowing) */
|
|
1272
|
+
escrowAuthority?: TAccountMetas[20] | undefined;
|
|
1273
|
+
/** Escrow token account (optional - only required if borrowing) */
|
|
1274
|
+
escrowTokenAccount?: TAccountMetas[21] | undefined;
|
|
1275
|
+
/** Pool loan account (optional - only required if borrowing) */
|
|
1276
|
+
poolLoan?: TAccountMetas[22] | undefined;
|
|
1277
|
+
/** Liquidity router (optional - only required if borrowing with SAP1/SAP2 failover) */
|
|
1278
|
+
liquidityRouter?: TAccountMetas[23] | undefined;
|
|
1279
|
+
maker: TAccountMetas[24];
|
|
1280
|
+
tokenProgram: TAccountMetas[25];
|
|
1281
|
+
associatedTokenProgram: TAccountMetas[26];
|
|
1282
|
+
tokenMetadataProgram: TAccountMetas[27];
|
|
1283
|
+
systemProgram: TAccountMetas[28];
|
|
1284
|
+
rent: TAccountMetas[29];
|
|
1285
|
+
};
|
|
1286
|
+
data: OptionMintInstructionData;
|
|
1287
|
+
};
|
|
1288
|
+
|
|
1289
|
+
export function parseOptionMintInstruction<
|
|
1290
|
+
TProgram extends string,
|
|
1291
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
1292
|
+
>(
|
|
1293
|
+
instruction: Instruction<TProgram> &
|
|
1294
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
1295
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
1296
|
+
): ParsedOptionMintInstruction<TProgram, TAccountMetas> {
|
|
1297
|
+
if (instruction.accounts.length < 30) {
|
|
1298
|
+
// TODO: Coded error.
|
|
1299
|
+
throw new Error("Not enough accounts");
|
|
1300
|
+
}
|
|
1301
|
+
let accountIndex = 0;
|
|
1302
|
+
const getNextAccount = () => {
|
|
1303
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
1304
|
+
accountIndex += 1;
|
|
1305
|
+
return accountMeta;
|
|
1306
|
+
};
|
|
1307
|
+
const getNextOptionalAccount = () => {
|
|
1308
|
+
const accountMeta = getNextAccount();
|
|
1309
|
+
return accountMeta.address === OPTION_PROGRAM_PROGRAM_ADDRESS
|
|
1310
|
+
? undefined
|
|
1311
|
+
: accountMeta;
|
|
1312
|
+
};
|
|
1313
|
+
return {
|
|
1314
|
+
programAddress: instruction.programAddress,
|
|
1315
|
+
accounts: {
|
|
1316
|
+
optionAccount: getNextAccount(),
|
|
1317
|
+
longMint: getNextAccount(),
|
|
1318
|
+
shortMint: getNextAccount(),
|
|
1319
|
+
mintAuthority: getNextAccount(),
|
|
1320
|
+
makerLongAccount: getNextAccount(),
|
|
1321
|
+
makerShortAccount: getNextAccount(),
|
|
1322
|
+
longMetadataAccount: getNextAccount(),
|
|
1323
|
+
shortMetadataAccount: getNextAccount(),
|
|
1324
|
+
marketData: getNextAccount(),
|
|
1325
|
+
underlyingMint: getNextAccount(),
|
|
1326
|
+
optionPool: getNextAccount(),
|
|
1327
|
+
escrowLongAccount: getNextAccount(),
|
|
1328
|
+
premiumVault: getNextAccount(),
|
|
1329
|
+
collateralPool: getNextAccount(),
|
|
1330
|
+
collateralVault: getNextAccount(),
|
|
1331
|
+
makerCollateralAccount: getNextAccount(),
|
|
1332
|
+
writerPosition: getNextAccount(),
|
|
1333
|
+
vault: getNextOptionalAccount(),
|
|
1334
|
+
vaultTokenAccount: getNextOptionalAccount(),
|
|
1335
|
+
escrowState: getNextOptionalAccount(),
|
|
1336
|
+
escrowAuthority: getNextOptionalAccount(),
|
|
1337
|
+
escrowTokenAccount: getNextOptionalAccount(),
|
|
1338
|
+
poolLoan: getNextOptionalAccount(),
|
|
1339
|
+
liquidityRouter: getNextOptionalAccount(),
|
|
1340
|
+
maker: getNextAccount(),
|
|
1341
|
+
tokenProgram: getNextAccount(),
|
|
1342
|
+
associatedTokenProgram: getNextAccount(),
|
|
1343
|
+
tokenMetadataProgram: getNextAccount(),
|
|
1344
|
+
systemProgram: getNextAccount(),
|
|
1345
|
+
rent: getNextAccount(),
|
|
1346
|
+
},
|
|
1347
|
+
data: getOptionMintInstructionDataDecoder().decode(instruction.data),
|
|
1348
|
+
};
|
|
1349
|
+
}
|