@epicentral/sos-sdk 0.9.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +1 -0
- package/AGENTS.md +7 -0
- package/LICENSE +21 -0
- package/README.md +568 -0
- package/accounts/fetchers.ts +196 -0
- package/accounts/list.ts +184 -0
- package/accounts/pdas.ts +325 -0
- package/accounts/resolve-option.ts +104 -0
- package/client/lookup-table.ts +114 -0
- package/client/program.ts +13 -0
- package/client/types.ts +9 -0
- package/generated/accounts/collateralPool.ts +217 -0
- package/generated/accounts/config.ts +156 -0
- package/generated/accounts/escrowState.ts +183 -0
- package/generated/accounts/index.ts +20 -0
- package/generated/accounts/lenderPosition.ts +211 -0
- package/generated/accounts/makerCollateralShare.ts +229 -0
- package/generated/accounts/marketDataAccount.ts +176 -0
- package/generated/accounts/optionAccount.ts +247 -0
- package/generated/accounts/optionPool.ts +285 -0
- package/generated/accounts/poolLoan.ts +232 -0
- package/generated/accounts/positionAccount.ts +201 -0
- package/generated/accounts/vault.ts +366 -0
- package/generated/accounts/writerPosition.ts +327 -0
- package/generated/errors/index.ts +9 -0
- package/generated/errors/optionProgram.ts +476 -0
- package/generated/index.ts +13 -0
- package/generated/instructions/acceptAdmin.ts +230 -0
- package/generated/instructions/autoExerciseAllExpired.ts +685 -0
- package/generated/instructions/autoExerciseExpired.ts +754 -0
- package/generated/instructions/borrowFromPool.ts +619 -0
- package/generated/instructions/buyFromPool.ts +761 -0
- package/generated/instructions/closeLongToPool.ts +762 -0
- package/generated/instructions/closeOption.ts +235 -0
- package/generated/instructions/createEscrowV2.ts +518 -0
- package/generated/instructions/depositCollateral.ts +624 -0
- package/generated/instructions/depositToPosition.ts +429 -0
- package/generated/instructions/index.ts +47 -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 +750 -0
- package/generated/instructions/liquidateWriterPositionRescue.ts +623 -0
- package/generated/instructions/omlpCreateVault.ts +553 -0
- package/generated/instructions/omlpUpdateFeeWallet.ts +473 -0
- package/generated/instructions/omlpUpdateInterestModel.ts +322 -0
- package/generated/instructions/omlpUpdateLiquidationThreshold.ts +304 -0
- package/generated/instructions/omlpUpdateMaintenanceBuffer.ts +304 -0
- package/generated/instructions/omlpUpdateMaxBorrowCap.ts +304 -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 +617 -0
- package/generated/instructions/optionMint.ts +1373 -0
- package/generated/instructions/optionValidate.ts +302 -0
- package/generated/instructions/repayPoolLoan.ts +558 -0
- package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
- package/generated/instructions/repayPoolLoanFromWallet.ts +542 -0
- package/generated/instructions/settleMakerCollateral.ts +509 -0
- package/generated/instructions/syncWriterPosition.ts +206 -0
- package/generated/instructions/transferAdmin.ts +245 -0
- package/generated/instructions/unwindWriterUnsold.ts +764 -0
- package/generated/instructions/updateImpliedVolatility.ts +226 -0
- package/generated/instructions/updateMarketData.ts +315 -0
- package/generated/instructions/withdrawFromPosition.ts +405 -0
- package/generated/instructions/writeToPool.ts +619 -0
- package/generated/programs/index.ts +9 -0
- package/generated/programs/optionProgram.ts +1144 -0
- package/generated/shared/index.ts +164 -0
- package/generated/types/impliedVolatilityUpdated.ts +73 -0
- package/generated/types/index.ts +28 -0
- package/generated/types/liquidationExecuted.ts +73 -0
- package/generated/types/liquidationRescueEvent.ts +82 -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/protocolFeeUpdated.ts +69 -0
- package/generated/types/vaultCreated.ts +60 -0
- package/generated/types/vaultFeeWalletUpdated.ts +67 -0
- package/generated/types/vaultInterestModelUpdated.ts +77 -0
- package/generated/types/vaultLiquidationThresholdUpdated.ts +69 -0
- package/index.ts +68 -0
- package/long/builders.ts +690 -0
- package/long/exercise.ts +123 -0
- package/long/preflight.ts +214 -0
- package/long/quotes.ts +48 -0
- package/long/remaining-accounts.ts +111 -0
- package/omlp/builders.ts +94 -0
- package/omlp/service.ts +136 -0
- package/oracle/switchboard.ts +315 -0
- package/package.json +34 -0
- package/shared/amounts.ts +53 -0
- package/shared/balances.ts +57 -0
- package/shared/errors.ts +12 -0
- package/shared/remaining-accounts.ts +41 -0
- package/shared/trade-config.ts +27 -0
- package/shared/transactions.ts +121 -0
- package/short/builders.ts +874 -0
- package/short/close-option.ts +34 -0
- package/short/pool.ts +189 -0
- package/short/preflight.ts +619 -0
- package/tsconfig.json +13 -0
- package/wsol/instructions.ts +247 -0
|
@@ -0,0 +1,623 @@
|
|
|
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 LIQUIDATE_WRITER_POSITION_RESCUE_DISCRIMINATOR = new Uint8Array([
|
|
43
|
+
210, 74, 45, 13, 187, 151, 90, 190,
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export function getLiquidateWriterPositionRescueDiscriminatorBytes() {
|
|
47
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
48
|
+
LIQUIDATE_WRITER_POSITION_RESCUE_DISCRIMINATOR,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type LiquidateWriterPositionRescueInstruction<
|
|
53
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
54
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
55
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountCollateralPool extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountWriterPosition extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountLongMint extends string | AccountMeta<string> = string,
|
|
60
|
+
TAccountEscrowLongAccount extends string | AccountMeta<string> = string,
|
|
61
|
+
TAccountOmlpVault extends string | AccountMeta<string> = string,
|
|
62
|
+
TAccountCollateralVault extends string | AccountMeta<string> = string,
|
|
63
|
+
TAccountPremiumVault extends string | AccountMeta<string> = string,
|
|
64
|
+
TAccountOmlpVaultTokenAccount extends string | AccountMeta<string> = string,
|
|
65
|
+
TAccountFeeWallet extends string | AccountMeta<string> = string,
|
|
66
|
+
TAccountKeeper extends string | AccountMeta<string> = string,
|
|
67
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
68
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
69
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
70
|
+
"11111111111111111111111111111111",
|
|
71
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
72
|
+
> = Instruction<TProgram> &
|
|
73
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
74
|
+
InstructionWithAccounts<
|
|
75
|
+
[
|
|
76
|
+
TAccountOptionPool extends string
|
|
77
|
+
? WritableAccount<TAccountOptionPool>
|
|
78
|
+
: TAccountOptionPool,
|
|
79
|
+
TAccountOptionAccount extends string
|
|
80
|
+
? WritableAccount<TAccountOptionAccount>
|
|
81
|
+
: TAccountOptionAccount,
|
|
82
|
+
TAccountMarketData extends string
|
|
83
|
+
? ReadonlyAccount<TAccountMarketData>
|
|
84
|
+
: TAccountMarketData,
|
|
85
|
+
TAccountCollateralPool extends string
|
|
86
|
+
? WritableAccount<TAccountCollateralPool>
|
|
87
|
+
: TAccountCollateralPool,
|
|
88
|
+
TAccountWriterPosition extends string
|
|
89
|
+
? WritableAccount<TAccountWriterPosition>
|
|
90
|
+
: TAccountWriterPosition,
|
|
91
|
+
TAccountLongMint extends string
|
|
92
|
+
? WritableAccount<TAccountLongMint>
|
|
93
|
+
: TAccountLongMint,
|
|
94
|
+
TAccountEscrowLongAccount extends string
|
|
95
|
+
? WritableAccount<TAccountEscrowLongAccount>
|
|
96
|
+
: TAccountEscrowLongAccount,
|
|
97
|
+
TAccountOmlpVault extends string
|
|
98
|
+
? WritableAccount<TAccountOmlpVault>
|
|
99
|
+
: TAccountOmlpVault,
|
|
100
|
+
TAccountCollateralVault extends string
|
|
101
|
+
? WritableAccount<TAccountCollateralVault>
|
|
102
|
+
: TAccountCollateralVault,
|
|
103
|
+
TAccountPremiumVault extends string
|
|
104
|
+
? WritableAccount<TAccountPremiumVault>
|
|
105
|
+
: TAccountPremiumVault,
|
|
106
|
+
TAccountOmlpVaultTokenAccount extends string
|
|
107
|
+
? WritableAccount<TAccountOmlpVaultTokenAccount>
|
|
108
|
+
: TAccountOmlpVaultTokenAccount,
|
|
109
|
+
TAccountFeeWallet extends string
|
|
110
|
+
? WritableAccount<TAccountFeeWallet>
|
|
111
|
+
: TAccountFeeWallet,
|
|
112
|
+
TAccountKeeper extends string
|
|
113
|
+
? WritableSignerAccount<TAccountKeeper> &
|
|
114
|
+
AccountSignerMeta<TAccountKeeper>
|
|
115
|
+
: TAccountKeeper,
|
|
116
|
+
TAccountTokenProgram extends string
|
|
117
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
118
|
+
: TAccountTokenProgram,
|
|
119
|
+
TAccountSystemProgram extends string
|
|
120
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
121
|
+
: TAccountSystemProgram,
|
|
122
|
+
...TRemainingAccounts,
|
|
123
|
+
]
|
|
124
|
+
>;
|
|
125
|
+
|
|
126
|
+
export type LiquidateWriterPositionRescueInstructionData = {
|
|
127
|
+
discriminator: ReadonlyUint8Array;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type LiquidateWriterPositionRescueInstructionDataArgs = {};
|
|
131
|
+
|
|
132
|
+
export function getLiquidateWriterPositionRescueInstructionDataEncoder(): FixedSizeEncoder<LiquidateWriterPositionRescueInstructionDataArgs> {
|
|
133
|
+
return transformEncoder(
|
|
134
|
+
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
|
135
|
+
(value) => ({
|
|
136
|
+
...value,
|
|
137
|
+
discriminator: LIQUIDATE_WRITER_POSITION_RESCUE_DISCRIMINATOR,
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function getLiquidateWriterPositionRescueInstructionDataDecoder(): FixedSizeDecoder<LiquidateWriterPositionRescueInstructionData> {
|
|
143
|
+
return getStructDecoder([
|
|
144
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function getLiquidateWriterPositionRescueInstructionDataCodec(): FixedSizeCodec<
|
|
149
|
+
LiquidateWriterPositionRescueInstructionDataArgs,
|
|
150
|
+
LiquidateWriterPositionRescueInstructionData
|
|
151
|
+
> {
|
|
152
|
+
return combineCodec(
|
|
153
|
+
getLiquidateWriterPositionRescueInstructionDataEncoder(),
|
|
154
|
+
getLiquidateWriterPositionRescueInstructionDataDecoder(),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export type LiquidateWriterPositionRescueAsyncInput<
|
|
159
|
+
TAccountOptionPool extends string = string,
|
|
160
|
+
TAccountOptionAccount extends string = string,
|
|
161
|
+
TAccountMarketData extends string = string,
|
|
162
|
+
TAccountCollateralPool extends string = string,
|
|
163
|
+
TAccountWriterPosition extends string = string,
|
|
164
|
+
TAccountLongMint extends string = string,
|
|
165
|
+
TAccountEscrowLongAccount extends string = string,
|
|
166
|
+
TAccountOmlpVault extends string = string,
|
|
167
|
+
TAccountCollateralVault extends string = string,
|
|
168
|
+
TAccountPremiumVault extends string = string,
|
|
169
|
+
TAccountOmlpVaultTokenAccount extends string = string,
|
|
170
|
+
TAccountFeeWallet extends string = string,
|
|
171
|
+
TAccountKeeper extends string = string,
|
|
172
|
+
TAccountTokenProgram extends string = string,
|
|
173
|
+
TAccountSystemProgram extends string = string,
|
|
174
|
+
> = {
|
|
175
|
+
/** The option pool */
|
|
176
|
+
optionPool: Address<TAccountOptionPool>;
|
|
177
|
+
/** The option account */
|
|
178
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
179
|
+
/** Market data (historical vol baseline for IV kink) */
|
|
180
|
+
marketData: Address<TAccountMarketData>;
|
|
181
|
+
/** Collateral pool */
|
|
182
|
+
collateralPool?: Address<TAccountCollateralPool>;
|
|
183
|
+
/** Writer's position to rescue */
|
|
184
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
185
|
+
/** LONG token mint (for burning unsold tokens) */
|
|
186
|
+
longMint: Address<TAccountLongMint>;
|
|
187
|
+
/** Pool's LONG escrow account (holds unsold LONG tokens to burn) */
|
|
188
|
+
escrowLongAccount: Address<TAccountEscrowLongAccount>;
|
|
189
|
+
/** OMLP Vault (mut: updates `total_loans`, `total_liquidity`, `bad_debt_lamports`) */
|
|
190
|
+
omlpVault: Address<TAccountOmlpVault>;
|
|
191
|
+
/** Collateral vault (source of partial collateral-side repayment) */
|
|
192
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
193
|
+
/** Pool premium vault (source of theta forfeiture) */
|
|
194
|
+
premiumVault: Address<TAccountPremiumVault>;
|
|
195
|
+
/** OMLP vault token account (receives what we can recover) */
|
|
196
|
+
omlpVaultTokenAccount: Address<TAccountOmlpVaultTokenAccount>;
|
|
197
|
+
/** Protocol fee wallet */
|
|
198
|
+
feeWallet: Address<TAccountFeeWallet>;
|
|
199
|
+
/** Vault keeper (permissioned rescue caller) */
|
|
200
|
+
keeper: TransactionSigner<TAccountKeeper>;
|
|
201
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
202
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export async function getLiquidateWriterPositionRescueInstructionAsync<
|
|
206
|
+
TAccountOptionPool extends string,
|
|
207
|
+
TAccountOptionAccount extends string,
|
|
208
|
+
TAccountMarketData extends string,
|
|
209
|
+
TAccountCollateralPool extends string,
|
|
210
|
+
TAccountWriterPosition extends string,
|
|
211
|
+
TAccountLongMint extends string,
|
|
212
|
+
TAccountEscrowLongAccount extends string,
|
|
213
|
+
TAccountOmlpVault extends string,
|
|
214
|
+
TAccountCollateralVault extends string,
|
|
215
|
+
TAccountPremiumVault extends string,
|
|
216
|
+
TAccountOmlpVaultTokenAccount extends string,
|
|
217
|
+
TAccountFeeWallet extends string,
|
|
218
|
+
TAccountKeeper extends string,
|
|
219
|
+
TAccountTokenProgram extends string,
|
|
220
|
+
TAccountSystemProgram extends string,
|
|
221
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
222
|
+
>(
|
|
223
|
+
input: LiquidateWriterPositionRescueAsyncInput<
|
|
224
|
+
TAccountOptionPool,
|
|
225
|
+
TAccountOptionAccount,
|
|
226
|
+
TAccountMarketData,
|
|
227
|
+
TAccountCollateralPool,
|
|
228
|
+
TAccountWriterPosition,
|
|
229
|
+
TAccountLongMint,
|
|
230
|
+
TAccountEscrowLongAccount,
|
|
231
|
+
TAccountOmlpVault,
|
|
232
|
+
TAccountCollateralVault,
|
|
233
|
+
TAccountPremiumVault,
|
|
234
|
+
TAccountOmlpVaultTokenAccount,
|
|
235
|
+
TAccountFeeWallet,
|
|
236
|
+
TAccountKeeper,
|
|
237
|
+
TAccountTokenProgram,
|
|
238
|
+
TAccountSystemProgram
|
|
239
|
+
>,
|
|
240
|
+
config?: { programAddress?: TProgramAddress },
|
|
241
|
+
): Promise<
|
|
242
|
+
LiquidateWriterPositionRescueInstruction<
|
|
243
|
+
TProgramAddress,
|
|
244
|
+
TAccountOptionPool,
|
|
245
|
+
TAccountOptionAccount,
|
|
246
|
+
TAccountMarketData,
|
|
247
|
+
TAccountCollateralPool,
|
|
248
|
+
TAccountWriterPosition,
|
|
249
|
+
TAccountLongMint,
|
|
250
|
+
TAccountEscrowLongAccount,
|
|
251
|
+
TAccountOmlpVault,
|
|
252
|
+
TAccountCollateralVault,
|
|
253
|
+
TAccountPremiumVault,
|
|
254
|
+
TAccountOmlpVaultTokenAccount,
|
|
255
|
+
TAccountFeeWallet,
|
|
256
|
+
TAccountKeeper,
|
|
257
|
+
TAccountTokenProgram,
|
|
258
|
+
TAccountSystemProgram
|
|
259
|
+
>
|
|
260
|
+
> {
|
|
261
|
+
// Program address.
|
|
262
|
+
const programAddress =
|
|
263
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
264
|
+
|
|
265
|
+
// Original accounts.
|
|
266
|
+
const originalAccounts = {
|
|
267
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
268
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
269
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
270
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
271
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
272
|
+
longMint: { value: input.longMint ?? null, isWritable: true },
|
|
273
|
+
escrowLongAccount: {
|
|
274
|
+
value: input.escrowLongAccount ?? null,
|
|
275
|
+
isWritable: true,
|
|
276
|
+
},
|
|
277
|
+
omlpVault: { value: input.omlpVault ?? null, isWritable: true },
|
|
278
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
279
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
280
|
+
omlpVaultTokenAccount: {
|
|
281
|
+
value: input.omlpVaultTokenAccount ?? null,
|
|
282
|
+
isWritable: true,
|
|
283
|
+
},
|
|
284
|
+
feeWallet: { value: input.feeWallet ?? null, isWritable: true },
|
|
285
|
+
keeper: { value: input.keeper ?? null, isWritable: true },
|
|
286
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
287
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
288
|
+
};
|
|
289
|
+
const accounts = originalAccounts as Record<
|
|
290
|
+
keyof typeof originalAccounts,
|
|
291
|
+
ResolvedAccount
|
|
292
|
+
>;
|
|
293
|
+
|
|
294
|
+
// Resolve default values.
|
|
295
|
+
if (!accounts.collateralPool.value) {
|
|
296
|
+
accounts.collateralPool.value = await getProgramDerivedAddress({
|
|
297
|
+
programAddress,
|
|
298
|
+
seeds: [
|
|
299
|
+
getBytesEncoder().encode(
|
|
300
|
+
new Uint8Array([
|
|
301
|
+
99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
|
|
302
|
+
108,
|
|
303
|
+
]),
|
|
304
|
+
),
|
|
305
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
306
|
+
],
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (!accounts.tokenProgram.value) {
|
|
310
|
+
accounts.tokenProgram.value =
|
|
311
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
312
|
+
}
|
|
313
|
+
if (!accounts.systemProgram.value) {
|
|
314
|
+
accounts.systemProgram.value =
|
|
315
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
319
|
+
return Object.freeze({
|
|
320
|
+
accounts: [
|
|
321
|
+
getAccountMeta(accounts.optionPool),
|
|
322
|
+
getAccountMeta(accounts.optionAccount),
|
|
323
|
+
getAccountMeta(accounts.marketData),
|
|
324
|
+
getAccountMeta(accounts.collateralPool),
|
|
325
|
+
getAccountMeta(accounts.writerPosition),
|
|
326
|
+
getAccountMeta(accounts.longMint),
|
|
327
|
+
getAccountMeta(accounts.escrowLongAccount),
|
|
328
|
+
getAccountMeta(accounts.omlpVault),
|
|
329
|
+
getAccountMeta(accounts.collateralVault),
|
|
330
|
+
getAccountMeta(accounts.premiumVault),
|
|
331
|
+
getAccountMeta(accounts.omlpVaultTokenAccount),
|
|
332
|
+
getAccountMeta(accounts.feeWallet),
|
|
333
|
+
getAccountMeta(accounts.keeper),
|
|
334
|
+
getAccountMeta(accounts.tokenProgram),
|
|
335
|
+
getAccountMeta(accounts.systemProgram),
|
|
336
|
+
],
|
|
337
|
+
data: getLiquidateWriterPositionRescueInstructionDataEncoder().encode({}),
|
|
338
|
+
programAddress,
|
|
339
|
+
} as LiquidateWriterPositionRescueInstruction<
|
|
340
|
+
TProgramAddress,
|
|
341
|
+
TAccountOptionPool,
|
|
342
|
+
TAccountOptionAccount,
|
|
343
|
+
TAccountMarketData,
|
|
344
|
+
TAccountCollateralPool,
|
|
345
|
+
TAccountWriterPosition,
|
|
346
|
+
TAccountLongMint,
|
|
347
|
+
TAccountEscrowLongAccount,
|
|
348
|
+
TAccountOmlpVault,
|
|
349
|
+
TAccountCollateralVault,
|
|
350
|
+
TAccountPremiumVault,
|
|
351
|
+
TAccountOmlpVaultTokenAccount,
|
|
352
|
+
TAccountFeeWallet,
|
|
353
|
+
TAccountKeeper,
|
|
354
|
+
TAccountTokenProgram,
|
|
355
|
+
TAccountSystemProgram
|
|
356
|
+
>);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export type LiquidateWriterPositionRescueInput<
|
|
360
|
+
TAccountOptionPool extends string = string,
|
|
361
|
+
TAccountOptionAccount extends string = string,
|
|
362
|
+
TAccountMarketData extends string = string,
|
|
363
|
+
TAccountCollateralPool extends string = string,
|
|
364
|
+
TAccountWriterPosition extends string = string,
|
|
365
|
+
TAccountLongMint extends string = string,
|
|
366
|
+
TAccountEscrowLongAccount extends string = string,
|
|
367
|
+
TAccountOmlpVault extends string = string,
|
|
368
|
+
TAccountCollateralVault extends string = string,
|
|
369
|
+
TAccountPremiumVault extends string = string,
|
|
370
|
+
TAccountOmlpVaultTokenAccount extends string = string,
|
|
371
|
+
TAccountFeeWallet extends string = string,
|
|
372
|
+
TAccountKeeper extends string = string,
|
|
373
|
+
TAccountTokenProgram extends string = string,
|
|
374
|
+
TAccountSystemProgram extends string = string,
|
|
375
|
+
> = {
|
|
376
|
+
/** The option pool */
|
|
377
|
+
optionPool: Address<TAccountOptionPool>;
|
|
378
|
+
/** The option account */
|
|
379
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
380
|
+
/** Market data (historical vol baseline for IV kink) */
|
|
381
|
+
marketData: Address<TAccountMarketData>;
|
|
382
|
+
/** Collateral pool */
|
|
383
|
+
collateralPool: Address<TAccountCollateralPool>;
|
|
384
|
+
/** Writer's position to rescue */
|
|
385
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
386
|
+
/** LONG token mint (for burning unsold tokens) */
|
|
387
|
+
longMint: Address<TAccountLongMint>;
|
|
388
|
+
/** Pool's LONG escrow account (holds unsold LONG tokens to burn) */
|
|
389
|
+
escrowLongAccount: Address<TAccountEscrowLongAccount>;
|
|
390
|
+
/** OMLP Vault (mut: updates `total_loans`, `total_liquidity`, `bad_debt_lamports`) */
|
|
391
|
+
omlpVault: Address<TAccountOmlpVault>;
|
|
392
|
+
/** Collateral vault (source of partial collateral-side repayment) */
|
|
393
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
394
|
+
/** Pool premium vault (source of theta forfeiture) */
|
|
395
|
+
premiumVault: Address<TAccountPremiumVault>;
|
|
396
|
+
/** OMLP vault token account (receives what we can recover) */
|
|
397
|
+
omlpVaultTokenAccount: Address<TAccountOmlpVaultTokenAccount>;
|
|
398
|
+
/** Protocol fee wallet */
|
|
399
|
+
feeWallet: Address<TAccountFeeWallet>;
|
|
400
|
+
/** Vault keeper (permissioned rescue caller) */
|
|
401
|
+
keeper: TransactionSigner<TAccountKeeper>;
|
|
402
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
403
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
export function getLiquidateWriterPositionRescueInstruction<
|
|
407
|
+
TAccountOptionPool extends string,
|
|
408
|
+
TAccountOptionAccount extends string,
|
|
409
|
+
TAccountMarketData extends string,
|
|
410
|
+
TAccountCollateralPool extends string,
|
|
411
|
+
TAccountWriterPosition extends string,
|
|
412
|
+
TAccountLongMint extends string,
|
|
413
|
+
TAccountEscrowLongAccount extends string,
|
|
414
|
+
TAccountOmlpVault extends string,
|
|
415
|
+
TAccountCollateralVault extends string,
|
|
416
|
+
TAccountPremiumVault extends string,
|
|
417
|
+
TAccountOmlpVaultTokenAccount extends string,
|
|
418
|
+
TAccountFeeWallet extends string,
|
|
419
|
+
TAccountKeeper extends string,
|
|
420
|
+
TAccountTokenProgram extends string,
|
|
421
|
+
TAccountSystemProgram extends string,
|
|
422
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
423
|
+
>(
|
|
424
|
+
input: LiquidateWriterPositionRescueInput<
|
|
425
|
+
TAccountOptionPool,
|
|
426
|
+
TAccountOptionAccount,
|
|
427
|
+
TAccountMarketData,
|
|
428
|
+
TAccountCollateralPool,
|
|
429
|
+
TAccountWriterPosition,
|
|
430
|
+
TAccountLongMint,
|
|
431
|
+
TAccountEscrowLongAccount,
|
|
432
|
+
TAccountOmlpVault,
|
|
433
|
+
TAccountCollateralVault,
|
|
434
|
+
TAccountPremiumVault,
|
|
435
|
+
TAccountOmlpVaultTokenAccount,
|
|
436
|
+
TAccountFeeWallet,
|
|
437
|
+
TAccountKeeper,
|
|
438
|
+
TAccountTokenProgram,
|
|
439
|
+
TAccountSystemProgram
|
|
440
|
+
>,
|
|
441
|
+
config?: { programAddress?: TProgramAddress },
|
|
442
|
+
): LiquidateWriterPositionRescueInstruction<
|
|
443
|
+
TProgramAddress,
|
|
444
|
+
TAccountOptionPool,
|
|
445
|
+
TAccountOptionAccount,
|
|
446
|
+
TAccountMarketData,
|
|
447
|
+
TAccountCollateralPool,
|
|
448
|
+
TAccountWriterPosition,
|
|
449
|
+
TAccountLongMint,
|
|
450
|
+
TAccountEscrowLongAccount,
|
|
451
|
+
TAccountOmlpVault,
|
|
452
|
+
TAccountCollateralVault,
|
|
453
|
+
TAccountPremiumVault,
|
|
454
|
+
TAccountOmlpVaultTokenAccount,
|
|
455
|
+
TAccountFeeWallet,
|
|
456
|
+
TAccountKeeper,
|
|
457
|
+
TAccountTokenProgram,
|
|
458
|
+
TAccountSystemProgram
|
|
459
|
+
> {
|
|
460
|
+
// Program address.
|
|
461
|
+
const programAddress =
|
|
462
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
463
|
+
|
|
464
|
+
// Original accounts.
|
|
465
|
+
const originalAccounts = {
|
|
466
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
467
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
468
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
469
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
470
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
471
|
+
longMint: { value: input.longMint ?? null, isWritable: true },
|
|
472
|
+
escrowLongAccount: {
|
|
473
|
+
value: input.escrowLongAccount ?? null,
|
|
474
|
+
isWritable: true,
|
|
475
|
+
},
|
|
476
|
+
omlpVault: { value: input.omlpVault ?? null, isWritable: true },
|
|
477
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
478
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
479
|
+
omlpVaultTokenAccount: {
|
|
480
|
+
value: input.omlpVaultTokenAccount ?? null,
|
|
481
|
+
isWritable: true,
|
|
482
|
+
},
|
|
483
|
+
feeWallet: { value: input.feeWallet ?? null, isWritable: true },
|
|
484
|
+
keeper: { value: input.keeper ?? null, isWritable: true },
|
|
485
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
486
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
487
|
+
};
|
|
488
|
+
const accounts = originalAccounts as Record<
|
|
489
|
+
keyof typeof originalAccounts,
|
|
490
|
+
ResolvedAccount
|
|
491
|
+
>;
|
|
492
|
+
|
|
493
|
+
// Resolve default values.
|
|
494
|
+
if (!accounts.tokenProgram.value) {
|
|
495
|
+
accounts.tokenProgram.value =
|
|
496
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
497
|
+
}
|
|
498
|
+
if (!accounts.systemProgram.value) {
|
|
499
|
+
accounts.systemProgram.value =
|
|
500
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
504
|
+
return Object.freeze({
|
|
505
|
+
accounts: [
|
|
506
|
+
getAccountMeta(accounts.optionPool),
|
|
507
|
+
getAccountMeta(accounts.optionAccount),
|
|
508
|
+
getAccountMeta(accounts.marketData),
|
|
509
|
+
getAccountMeta(accounts.collateralPool),
|
|
510
|
+
getAccountMeta(accounts.writerPosition),
|
|
511
|
+
getAccountMeta(accounts.longMint),
|
|
512
|
+
getAccountMeta(accounts.escrowLongAccount),
|
|
513
|
+
getAccountMeta(accounts.omlpVault),
|
|
514
|
+
getAccountMeta(accounts.collateralVault),
|
|
515
|
+
getAccountMeta(accounts.premiumVault),
|
|
516
|
+
getAccountMeta(accounts.omlpVaultTokenAccount),
|
|
517
|
+
getAccountMeta(accounts.feeWallet),
|
|
518
|
+
getAccountMeta(accounts.keeper),
|
|
519
|
+
getAccountMeta(accounts.tokenProgram),
|
|
520
|
+
getAccountMeta(accounts.systemProgram),
|
|
521
|
+
],
|
|
522
|
+
data: getLiquidateWriterPositionRescueInstructionDataEncoder().encode({}),
|
|
523
|
+
programAddress,
|
|
524
|
+
} as LiquidateWriterPositionRescueInstruction<
|
|
525
|
+
TProgramAddress,
|
|
526
|
+
TAccountOptionPool,
|
|
527
|
+
TAccountOptionAccount,
|
|
528
|
+
TAccountMarketData,
|
|
529
|
+
TAccountCollateralPool,
|
|
530
|
+
TAccountWriterPosition,
|
|
531
|
+
TAccountLongMint,
|
|
532
|
+
TAccountEscrowLongAccount,
|
|
533
|
+
TAccountOmlpVault,
|
|
534
|
+
TAccountCollateralVault,
|
|
535
|
+
TAccountPremiumVault,
|
|
536
|
+
TAccountOmlpVaultTokenAccount,
|
|
537
|
+
TAccountFeeWallet,
|
|
538
|
+
TAccountKeeper,
|
|
539
|
+
TAccountTokenProgram,
|
|
540
|
+
TAccountSystemProgram
|
|
541
|
+
>);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export type ParsedLiquidateWriterPositionRescueInstruction<
|
|
545
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
546
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
547
|
+
> = {
|
|
548
|
+
programAddress: Address<TProgram>;
|
|
549
|
+
accounts: {
|
|
550
|
+
/** The option pool */
|
|
551
|
+
optionPool: TAccountMetas[0];
|
|
552
|
+
/** The option account */
|
|
553
|
+
optionAccount: TAccountMetas[1];
|
|
554
|
+
/** Market data (historical vol baseline for IV kink) */
|
|
555
|
+
marketData: TAccountMetas[2];
|
|
556
|
+
/** Collateral pool */
|
|
557
|
+
collateralPool: TAccountMetas[3];
|
|
558
|
+
/** Writer's position to rescue */
|
|
559
|
+
writerPosition: TAccountMetas[4];
|
|
560
|
+
/** LONG token mint (for burning unsold tokens) */
|
|
561
|
+
longMint: TAccountMetas[5];
|
|
562
|
+
/** Pool's LONG escrow account (holds unsold LONG tokens to burn) */
|
|
563
|
+
escrowLongAccount: TAccountMetas[6];
|
|
564
|
+
/** OMLP Vault (mut: updates `total_loans`, `total_liquidity`, `bad_debt_lamports`) */
|
|
565
|
+
omlpVault: TAccountMetas[7];
|
|
566
|
+
/** Collateral vault (source of partial collateral-side repayment) */
|
|
567
|
+
collateralVault: TAccountMetas[8];
|
|
568
|
+
/** Pool premium vault (source of theta forfeiture) */
|
|
569
|
+
premiumVault: TAccountMetas[9];
|
|
570
|
+
/** OMLP vault token account (receives what we can recover) */
|
|
571
|
+
omlpVaultTokenAccount: TAccountMetas[10];
|
|
572
|
+
/** Protocol fee wallet */
|
|
573
|
+
feeWallet: TAccountMetas[11];
|
|
574
|
+
/** Vault keeper (permissioned rescue caller) */
|
|
575
|
+
keeper: TAccountMetas[12];
|
|
576
|
+
tokenProgram: TAccountMetas[13];
|
|
577
|
+
systemProgram: TAccountMetas[14];
|
|
578
|
+
};
|
|
579
|
+
data: LiquidateWriterPositionRescueInstructionData;
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
export function parseLiquidateWriterPositionRescueInstruction<
|
|
583
|
+
TProgram extends string,
|
|
584
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
585
|
+
>(
|
|
586
|
+
instruction: Instruction<TProgram> &
|
|
587
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
588
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
589
|
+
): ParsedLiquidateWriterPositionRescueInstruction<TProgram, TAccountMetas> {
|
|
590
|
+
if (instruction.accounts.length < 15) {
|
|
591
|
+
// TODO: Coded error.
|
|
592
|
+
throw new Error("Not enough accounts");
|
|
593
|
+
}
|
|
594
|
+
let accountIndex = 0;
|
|
595
|
+
const getNextAccount = () => {
|
|
596
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
597
|
+
accountIndex += 1;
|
|
598
|
+
return accountMeta;
|
|
599
|
+
};
|
|
600
|
+
return {
|
|
601
|
+
programAddress: instruction.programAddress,
|
|
602
|
+
accounts: {
|
|
603
|
+
optionPool: getNextAccount(),
|
|
604
|
+
optionAccount: getNextAccount(),
|
|
605
|
+
marketData: getNextAccount(),
|
|
606
|
+
collateralPool: getNextAccount(),
|
|
607
|
+
writerPosition: getNextAccount(),
|
|
608
|
+
longMint: getNextAccount(),
|
|
609
|
+
escrowLongAccount: getNextAccount(),
|
|
610
|
+
omlpVault: getNextAccount(),
|
|
611
|
+
collateralVault: getNextAccount(),
|
|
612
|
+
premiumVault: getNextAccount(),
|
|
613
|
+
omlpVaultTokenAccount: getNextAccount(),
|
|
614
|
+
feeWallet: getNextAccount(),
|
|
615
|
+
keeper: getNextAccount(),
|
|
616
|
+
tokenProgram: getNextAccount(),
|
|
617
|
+
systemProgram: getNextAccount(),
|
|
618
|
+
},
|
|
619
|
+
data: getLiquidateWriterPositionRescueInstructionDataDecoder().decode(
|
|
620
|
+
instruction.data,
|
|
621
|
+
),
|
|
622
|
+
};
|
|
623
|
+
}
|