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