@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,592 @@
|
|
|
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_DISCRIMINATOR = new Uint8Array([
|
|
43
|
+
184, 117, 16, 217, 120, 32, 16, 63,
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export function getLiquidateWriterPositionDiscriminatorBytes() {
|
|
47
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
48
|
+
LIQUIDATE_WRITER_POSITION_DISCRIMINATOR,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type LiquidateWriterPositionInstruction<
|
|
53
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
54
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
55
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountCollateralPool extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountWriterPosition extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountOmlpVault extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountUnderlyingMint extends string | AccountMeta<string> = string,
|
|
60
|
+
TAccountMarketData extends string | AccountMeta<string> = string,
|
|
61
|
+
TAccountPriceUpdate extends string | AccountMeta<string> = string,
|
|
62
|
+
TAccountCollateralVault extends string | AccountMeta<string> = string,
|
|
63
|
+
TAccountOmlpVaultTokenAccount extends string | AccountMeta<string> = string,
|
|
64
|
+
TAccountFeeWallet extends string | AccountMeta<string> = string,
|
|
65
|
+
TAccountLiquidator extends string | AccountMeta<string> = string,
|
|
66
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
67
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
68
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
69
|
+
"11111111111111111111111111111111",
|
|
70
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
71
|
+
> = Instruction<TProgram> &
|
|
72
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
73
|
+
InstructionWithAccounts<
|
|
74
|
+
[
|
|
75
|
+
TAccountOptionPool extends string
|
|
76
|
+
? WritableAccount<TAccountOptionPool>
|
|
77
|
+
: TAccountOptionPool,
|
|
78
|
+
TAccountOptionAccount extends string
|
|
79
|
+
? WritableAccount<TAccountOptionAccount>
|
|
80
|
+
: TAccountOptionAccount,
|
|
81
|
+
TAccountCollateralPool extends string
|
|
82
|
+
? WritableAccount<TAccountCollateralPool>
|
|
83
|
+
: TAccountCollateralPool,
|
|
84
|
+
TAccountWriterPosition extends string
|
|
85
|
+
? WritableAccount<TAccountWriterPosition>
|
|
86
|
+
: TAccountWriterPosition,
|
|
87
|
+
TAccountOmlpVault extends string
|
|
88
|
+
? WritableAccount<TAccountOmlpVault>
|
|
89
|
+
: TAccountOmlpVault,
|
|
90
|
+
TAccountUnderlyingMint extends string
|
|
91
|
+
? ReadonlyAccount<TAccountUnderlyingMint>
|
|
92
|
+
: TAccountUnderlyingMint,
|
|
93
|
+
TAccountMarketData extends string
|
|
94
|
+
? ReadonlyAccount<TAccountMarketData>
|
|
95
|
+
: TAccountMarketData,
|
|
96
|
+
TAccountPriceUpdate extends string
|
|
97
|
+
? ReadonlyAccount<TAccountPriceUpdate>
|
|
98
|
+
: TAccountPriceUpdate,
|
|
99
|
+
TAccountCollateralVault extends string
|
|
100
|
+
? WritableAccount<TAccountCollateralVault>
|
|
101
|
+
: TAccountCollateralVault,
|
|
102
|
+
TAccountOmlpVaultTokenAccount extends string
|
|
103
|
+
? WritableAccount<TAccountOmlpVaultTokenAccount>
|
|
104
|
+
: TAccountOmlpVaultTokenAccount,
|
|
105
|
+
TAccountFeeWallet extends string
|
|
106
|
+
? WritableAccount<TAccountFeeWallet>
|
|
107
|
+
: TAccountFeeWallet,
|
|
108
|
+
TAccountLiquidator extends string
|
|
109
|
+
? WritableSignerAccount<TAccountLiquidator> &
|
|
110
|
+
AccountSignerMeta<TAccountLiquidator>
|
|
111
|
+
: TAccountLiquidator,
|
|
112
|
+
TAccountTokenProgram extends string
|
|
113
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
114
|
+
: TAccountTokenProgram,
|
|
115
|
+
TAccountSystemProgram extends string
|
|
116
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
117
|
+
: TAccountSystemProgram,
|
|
118
|
+
...TRemainingAccounts,
|
|
119
|
+
]
|
|
120
|
+
>;
|
|
121
|
+
|
|
122
|
+
export type LiquidateWriterPositionInstructionData = {
|
|
123
|
+
discriminator: ReadonlyUint8Array;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type LiquidateWriterPositionInstructionDataArgs = {};
|
|
127
|
+
|
|
128
|
+
export function getLiquidateWriterPositionInstructionDataEncoder(): FixedSizeEncoder<LiquidateWriterPositionInstructionDataArgs> {
|
|
129
|
+
return transformEncoder(
|
|
130
|
+
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
|
131
|
+
(value) => ({
|
|
132
|
+
...value,
|
|
133
|
+
discriminator: LIQUIDATE_WRITER_POSITION_DISCRIMINATOR,
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getLiquidateWriterPositionInstructionDataDecoder(): FixedSizeDecoder<LiquidateWriterPositionInstructionData> {
|
|
139
|
+
return getStructDecoder([
|
|
140
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function getLiquidateWriterPositionInstructionDataCodec(): FixedSizeCodec<
|
|
145
|
+
LiquidateWriterPositionInstructionDataArgs,
|
|
146
|
+
LiquidateWriterPositionInstructionData
|
|
147
|
+
> {
|
|
148
|
+
return combineCodec(
|
|
149
|
+
getLiquidateWriterPositionInstructionDataEncoder(),
|
|
150
|
+
getLiquidateWriterPositionInstructionDataDecoder(),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export type LiquidateWriterPositionAsyncInput<
|
|
155
|
+
TAccountOptionPool extends string = string,
|
|
156
|
+
TAccountOptionAccount extends string = string,
|
|
157
|
+
TAccountCollateralPool extends string = string,
|
|
158
|
+
TAccountWriterPosition extends string = string,
|
|
159
|
+
TAccountOmlpVault extends string = string,
|
|
160
|
+
TAccountUnderlyingMint extends string = string,
|
|
161
|
+
TAccountMarketData extends string = string,
|
|
162
|
+
TAccountPriceUpdate extends string = string,
|
|
163
|
+
TAccountCollateralVault extends string = string,
|
|
164
|
+
TAccountOmlpVaultTokenAccount extends string = string,
|
|
165
|
+
TAccountFeeWallet extends string = string,
|
|
166
|
+
TAccountLiquidator extends string = string,
|
|
167
|
+
TAccountTokenProgram extends string = string,
|
|
168
|
+
TAccountSystemProgram extends string = string,
|
|
169
|
+
> = {
|
|
170
|
+
/** The option pool */
|
|
171
|
+
optionPool: Address<TAccountOptionPool>;
|
|
172
|
+
/** The option account */
|
|
173
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
174
|
+
/** Collateral pool */
|
|
175
|
+
collateralPool?: Address<TAccountCollateralPool>;
|
|
176
|
+
/** Writer's position to liquidate */
|
|
177
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
178
|
+
/** OMLP Vault (for repayment tracking) */
|
|
179
|
+
omlpVault: Address<TAccountOmlpVault>;
|
|
180
|
+
/** Underlying token mint (for decimal handling) */
|
|
181
|
+
underlyingMint: Address<TAccountUnderlyingMint>;
|
|
182
|
+
/** Market data account (provides pyth_feed_id for price check) */
|
|
183
|
+
marketData: Address<TAccountMarketData>;
|
|
184
|
+
/** Pyth price update account for current underlying price */
|
|
185
|
+
priceUpdate: Address<TAccountPriceUpdate>;
|
|
186
|
+
/** Collateral vault (source of repayments) */
|
|
187
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
188
|
+
/** OMLP vault token account (receives loan repayments) */
|
|
189
|
+
omlpVaultTokenAccount: Address<TAccountOmlpVaultTokenAccount>;
|
|
190
|
+
/** Protocol fee wallet (receives liquidation fees) */
|
|
191
|
+
feeWallet: Address<TAccountFeeWallet>;
|
|
192
|
+
/** Liquidator/keeper (permissionless - anyone can call) */
|
|
193
|
+
liquidator: TransactionSigner<TAccountLiquidator>;
|
|
194
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
195
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export async function getLiquidateWriterPositionInstructionAsync<
|
|
199
|
+
TAccountOptionPool extends string,
|
|
200
|
+
TAccountOptionAccount extends string,
|
|
201
|
+
TAccountCollateralPool extends string,
|
|
202
|
+
TAccountWriterPosition extends string,
|
|
203
|
+
TAccountOmlpVault extends string,
|
|
204
|
+
TAccountUnderlyingMint extends string,
|
|
205
|
+
TAccountMarketData extends string,
|
|
206
|
+
TAccountPriceUpdate extends string,
|
|
207
|
+
TAccountCollateralVault extends string,
|
|
208
|
+
TAccountOmlpVaultTokenAccount extends string,
|
|
209
|
+
TAccountFeeWallet extends string,
|
|
210
|
+
TAccountLiquidator extends string,
|
|
211
|
+
TAccountTokenProgram extends string,
|
|
212
|
+
TAccountSystemProgram extends string,
|
|
213
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
214
|
+
>(
|
|
215
|
+
input: LiquidateWriterPositionAsyncInput<
|
|
216
|
+
TAccountOptionPool,
|
|
217
|
+
TAccountOptionAccount,
|
|
218
|
+
TAccountCollateralPool,
|
|
219
|
+
TAccountWriterPosition,
|
|
220
|
+
TAccountOmlpVault,
|
|
221
|
+
TAccountUnderlyingMint,
|
|
222
|
+
TAccountMarketData,
|
|
223
|
+
TAccountPriceUpdate,
|
|
224
|
+
TAccountCollateralVault,
|
|
225
|
+
TAccountOmlpVaultTokenAccount,
|
|
226
|
+
TAccountFeeWallet,
|
|
227
|
+
TAccountLiquidator,
|
|
228
|
+
TAccountTokenProgram,
|
|
229
|
+
TAccountSystemProgram
|
|
230
|
+
>,
|
|
231
|
+
config?: { programAddress?: TProgramAddress },
|
|
232
|
+
): Promise<
|
|
233
|
+
LiquidateWriterPositionInstruction<
|
|
234
|
+
TProgramAddress,
|
|
235
|
+
TAccountOptionPool,
|
|
236
|
+
TAccountOptionAccount,
|
|
237
|
+
TAccountCollateralPool,
|
|
238
|
+
TAccountWriterPosition,
|
|
239
|
+
TAccountOmlpVault,
|
|
240
|
+
TAccountUnderlyingMint,
|
|
241
|
+
TAccountMarketData,
|
|
242
|
+
TAccountPriceUpdate,
|
|
243
|
+
TAccountCollateralVault,
|
|
244
|
+
TAccountOmlpVaultTokenAccount,
|
|
245
|
+
TAccountFeeWallet,
|
|
246
|
+
TAccountLiquidator,
|
|
247
|
+
TAccountTokenProgram,
|
|
248
|
+
TAccountSystemProgram
|
|
249
|
+
>
|
|
250
|
+
> {
|
|
251
|
+
// Program address.
|
|
252
|
+
const programAddress =
|
|
253
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
254
|
+
|
|
255
|
+
// Original accounts.
|
|
256
|
+
const originalAccounts = {
|
|
257
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
258
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
259
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
260
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
261
|
+
omlpVault: { value: input.omlpVault ?? null, isWritable: true },
|
|
262
|
+
underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
|
|
263
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
264
|
+
priceUpdate: { value: input.priceUpdate ?? null, isWritable: false },
|
|
265
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
266
|
+
omlpVaultTokenAccount: {
|
|
267
|
+
value: input.omlpVaultTokenAccount ?? null,
|
|
268
|
+
isWritable: true,
|
|
269
|
+
},
|
|
270
|
+
feeWallet: { value: input.feeWallet ?? null, isWritable: true },
|
|
271
|
+
liquidator: { value: input.liquidator ?? null, isWritable: true },
|
|
272
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
273
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
274
|
+
};
|
|
275
|
+
const accounts = originalAccounts as Record<
|
|
276
|
+
keyof typeof originalAccounts,
|
|
277
|
+
ResolvedAccount
|
|
278
|
+
>;
|
|
279
|
+
|
|
280
|
+
// Resolve default values.
|
|
281
|
+
if (!accounts.collateralPool.value) {
|
|
282
|
+
accounts.collateralPool.value = await getProgramDerivedAddress({
|
|
283
|
+
programAddress,
|
|
284
|
+
seeds: [
|
|
285
|
+
getBytesEncoder().encode(
|
|
286
|
+
new Uint8Array([
|
|
287
|
+
99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
|
|
288
|
+
108,
|
|
289
|
+
]),
|
|
290
|
+
),
|
|
291
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
292
|
+
],
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (!accounts.tokenProgram.value) {
|
|
296
|
+
accounts.tokenProgram.value =
|
|
297
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
298
|
+
}
|
|
299
|
+
if (!accounts.systemProgram.value) {
|
|
300
|
+
accounts.systemProgram.value =
|
|
301
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
305
|
+
return Object.freeze({
|
|
306
|
+
accounts: [
|
|
307
|
+
getAccountMeta(accounts.optionPool),
|
|
308
|
+
getAccountMeta(accounts.optionAccount),
|
|
309
|
+
getAccountMeta(accounts.collateralPool),
|
|
310
|
+
getAccountMeta(accounts.writerPosition),
|
|
311
|
+
getAccountMeta(accounts.omlpVault),
|
|
312
|
+
getAccountMeta(accounts.underlyingMint),
|
|
313
|
+
getAccountMeta(accounts.marketData),
|
|
314
|
+
getAccountMeta(accounts.priceUpdate),
|
|
315
|
+
getAccountMeta(accounts.collateralVault),
|
|
316
|
+
getAccountMeta(accounts.omlpVaultTokenAccount),
|
|
317
|
+
getAccountMeta(accounts.feeWallet),
|
|
318
|
+
getAccountMeta(accounts.liquidator),
|
|
319
|
+
getAccountMeta(accounts.tokenProgram),
|
|
320
|
+
getAccountMeta(accounts.systemProgram),
|
|
321
|
+
],
|
|
322
|
+
data: getLiquidateWriterPositionInstructionDataEncoder().encode({}),
|
|
323
|
+
programAddress,
|
|
324
|
+
} as LiquidateWriterPositionInstruction<
|
|
325
|
+
TProgramAddress,
|
|
326
|
+
TAccountOptionPool,
|
|
327
|
+
TAccountOptionAccount,
|
|
328
|
+
TAccountCollateralPool,
|
|
329
|
+
TAccountWriterPosition,
|
|
330
|
+
TAccountOmlpVault,
|
|
331
|
+
TAccountUnderlyingMint,
|
|
332
|
+
TAccountMarketData,
|
|
333
|
+
TAccountPriceUpdate,
|
|
334
|
+
TAccountCollateralVault,
|
|
335
|
+
TAccountOmlpVaultTokenAccount,
|
|
336
|
+
TAccountFeeWallet,
|
|
337
|
+
TAccountLiquidator,
|
|
338
|
+
TAccountTokenProgram,
|
|
339
|
+
TAccountSystemProgram
|
|
340
|
+
>);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export type LiquidateWriterPositionInput<
|
|
344
|
+
TAccountOptionPool extends string = string,
|
|
345
|
+
TAccountOptionAccount extends string = string,
|
|
346
|
+
TAccountCollateralPool extends string = string,
|
|
347
|
+
TAccountWriterPosition extends string = string,
|
|
348
|
+
TAccountOmlpVault extends string = string,
|
|
349
|
+
TAccountUnderlyingMint extends string = string,
|
|
350
|
+
TAccountMarketData extends string = string,
|
|
351
|
+
TAccountPriceUpdate extends string = string,
|
|
352
|
+
TAccountCollateralVault extends string = string,
|
|
353
|
+
TAccountOmlpVaultTokenAccount extends string = string,
|
|
354
|
+
TAccountFeeWallet extends string = string,
|
|
355
|
+
TAccountLiquidator extends string = string,
|
|
356
|
+
TAccountTokenProgram extends string = string,
|
|
357
|
+
TAccountSystemProgram extends string = string,
|
|
358
|
+
> = {
|
|
359
|
+
/** The option pool */
|
|
360
|
+
optionPool: Address<TAccountOptionPool>;
|
|
361
|
+
/** The option account */
|
|
362
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
363
|
+
/** Collateral pool */
|
|
364
|
+
collateralPool: Address<TAccountCollateralPool>;
|
|
365
|
+
/** Writer's position to liquidate */
|
|
366
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
367
|
+
/** OMLP Vault (for repayment tracking) */
|
|
368
|
+
omlpVault: Address<TAccountOmlpVault>;
|
|
369
|
+
/** Underlying token mint (for decimal handling) */
|
|
370
|
+
underlyingMint: Address<TAccountUnderlyingMint>;
|
|
371
|
+
/** Market data account (provides pyth_feed_id for price check) */
|
|
372
|
+
marketData: Address<TAccountMarketData>;
|
|
373
|
+
/** Pyth price update account for current underlying price */
|
|
374
|
+
priceUpdate: Address<TAccountPriceUpdate>;
|
|
375
|
+
/** Collateral vault (source of repayments) */
|
|
376
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
377
|
+
/** OMLP vault token account (receives loan repayments) */
|
|
378
|
+
omlpVaultTokenAccount: Address<TAccountOmlpVaultTokenAccount>;
|
|
379
|
+
/** Protocol fee wallet (receives liquidation fees) */
|
|
380
|
+
feeWallet: Address<TAccountFeeWallet>;
|
|
381
|
+
/** Liquidator/keeper (permissionless - anyone can call) */
|
|
382
|
+
liquidator: TransactionSigner<TAccountLiquidator>;
|
|
383
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
384
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
export function getLiquidateWriterPositionInstruction<
|
|
388
|
+
TAccountOptionPool extends string,
|
|
389
|
+
TAccountOptionAccount extends string,
|
|
390
|
+
TAccountCollateralPool extends string,
|
|
391
|
+
TAccountWriterPosition extends string,
|
|
392
|
+
TAccountOmlpVault extends string,
|
|
393
|
+
TAccountUnderlyingMint extends string,
|
|
394
|
+
TAccountMarketData extends string,
|
|
395
|
+
TAccountPriceUpdate extends string,
|
|
396
|
+
TAccountCollateralVault extends string,
|
|
397
|
+
TAccountOmlpVaultTokenAccount extends string,
|
|
398
|
+
TAccountFeeWallet extends string,
|
|
399
|
+
TAccountLiquidator extends string,
|
|
400
|
+
TAccountTokenProgram extends string,
|
|
401
|
+
TAccountSystemProgram extends string,
|
|
402
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
403
|
+
>(
|
|
404
|
+
input: LiquidateWriterPositionInput<
|
|
405
|
+
TAccountOptionPool,
|
|
406
|
+
TAccountOptionAccount,
|
|
407
|
+
TAccountCollateralPool,
|
|
408
|
+
TAccountWriterPosition,
|
|
409
|
+
TAccountOmlpVault,
|
|
410
|
+
TAccountUnderlyingMint,
|
|
411
|
+
TAccountMarketData,
|
|
412
|
+
TAccountPriceUpdate,
|
|
413
|
+
TAccountCollateralVault,
|
|
414
|
+
TAccountOmlpVaultTokenAccount,
|
|
415
|
+
TAccountFeeWallet,
|
|
416
|
+
TAccountLiquidator,
|
|
417
|
+
TAccountTokenProgram,
|
|
418
|
+
TAccountSystemProgram
|
|
419
|
+
>,
|
|
420
|
+
config?: { programAddress?: TProgramAddress },
|
|
421
|
+
): LiquidateWriterPositionInstruction<
|
|
422
|
+
TProgramAddress,
|
|
423
|
+
TAccountOptionPool,
|
|
424
|
+
TAccountOptionAccount,
|
|
425
|
+
TAccountCollateralPool,
|
|
426
|
+
TAccountWriterPosition,
|
|
427
|
+
TAccountOmlpVault,
|
|
428
|
+
TAccountUnderlyingMint,
|
|
429
|
+
TAccountMarketData,
|
|
430
|
+
TAccountPriceUpdate,
|
|
431
|
+
TAccountCollateralVault,
|
|
432
|
+
TAccountOmlpVaultTokenAccount,
|
|
433
|
+
TAccountFeeWallet,
|
|
434
|
+
TAccountLiquidator,
|
|
435
|
+
TAccountTokenProgram,
|
|
436
|
+
TAccountSystemProgram
|
|
437
|
+
> {
|
|
438
|
+
// Program address.
|
|
439
|
+
const programAddress =
|
|
440
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
441
|
+
|
|
442
|
+
// Original accounts.
|
|
443
|
+
const originalAccounts = {
|
|
444
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
445
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
446
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
447
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
448
|
+
omlpVault: { value: input.omlpVault ?? null, isWritable: true },
|
|
449
|
+
underlyingMint: { value: input.underlyingMint ?? null, isWritable: false },
|
|
450
|
+
marketData: { value: input.marketData ?? null, isWritable: false },
|
|
451
|
+
priceUpdate: { value: input.priceUpdate ?? null, isWritable: false },
|
|
452
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
453
|
+
omlpVaultTokenAccount: {
|
|
454
|
+
value: input.omlpVaultTokenAccount ?? null,
|
|
455
|
+
isWritable: true,
|
|
456
|
+
},
|
|
457
|
+
feeWallet: { value: input.feeWallet ?? null, isWritable: true },
|
|
458
|
+
liquidator: { value: input.liquidator ?? null, isWritable: true },
|
|
459
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
460
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
461
|
+
};
|
|
462
|
+
const accounts = originalAccounts as Record<
|
|
463
|
+
keyof typeof originalAccounts,
|
|
464
|
+
ResolvedAccount
|
|
465
|
+
>;
|
|
466
|
+
|
|
467
|
+
// Resolve default values.
|
|
468
|
+
if (!accounts.tokenProgram.value) {
|
|
469
|
+
accounts.tokenProgram.value =
|
|
470
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
471
|
+
}
|
|
472
|
+
if (!accounts.systemProgram.value) {
|
|
473
|
+
accounts.systemProgram.value =
|
|
474
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
478
|
+
return Object.freeze({
|
|
479
|
+
accounts: [
|
|
480
|
+
getAccountMeta(accounts.optionPool),
|
|
481
|
+
getAccountMeta(accounts.optionAccount),
|
|
482
|
+
getAccountMeta(accounts.collateralPool),
|
|
483
|
+
getAccountMeta(accounts.writerPosition),
|
|
484
|
+
getAccountMeta(accounts.omlpVault),
|
|
485
|
+
getAccountMeta(accounts.underlyingMint),
|
|
486
|
+
getAccountMeta(accounts.marketData),
|
|
487
|
+
getAccountMeta(accounts.priceUpdate),
|
|
488
|
+
getAccountMeta(accounts.collateralVault),
|
|
489
|
+
getAccountMeta(accounts.omlpVaultTokenAccount),
|
|
490
|
+
getAccountMeta(accounts.feeWallet),
|
|
491
|
+
getAccountMeta(accounts.liquidator),
|
|
492
|
+
getAccountMeta(accounts.tokenProgram),
|
|
493
|
+
getAccountMeta(accounts.systemProgram),
|
|
494
|
+
],
|
|
495
|
+
data: getLiquidateWriterPositionInstructionDataEncoder().encode({}),
|
|
496
|
+
programAddress,
|
|
497
|
+
} as LiquidateWriterPositionInstruction<
|
|
498
|
+
TProgramAddress,
|
|
499
|
+
TAccountOptionPool,
|
|
500
|
+
TAccountOptionAccount,
|
|
501
|
+
TAccountCollateralPool,
|
|
502
|
+
TAccountWriterPosition,
|
|
503
|
+
TAccountOmlpVault,
|
|
504
|
+
TAccountUnderlyingMint,
|
|
505
|
+
TAccountMarketData,
|
|
506
|
+
TAccountPriceUpdate,
|
|
507
|
+
TAccountCollateralVault,
|
|
508
|
+
TAccountOmlpVaultTokenAccount,
|
|
509
|
+
TAccountFeeWallet,
|
|
510
|
+
TAccountLiquidator,
|
|
511
|
+
TAccountTokenProgram,
|
|
512
|
+
TAccountSystemProgram
|
|
513
|
+
>);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export type ParsedLiquidateWriterPositionInstruction<
|
|
517
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
518
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
519
|
+
> = {
|
|
520
|
+
programAddress: Address<TProgram>;
|
|
521
|
+
accounts: {
|
|
522
|
+
/** The option pool */
|
|
523
|
+
optionPool: TAccountMetas[0];
|
|
524
|
+
/** The option account */
|
|
525
|
+
optionAccount: TAccountMetas[1];
|
|
526
|
+
/** Collateral pool */
|
|
527
|
+
collateralPool: TAccountMetas[2];
|
|
528
|
+
/** Writer's position to liquidate */
|
|
529
|
+
writerPosition: TAccountMetas[3];
|
|
530
|
+
/** OMLP Vault (for repayment tracking) */
|
|
531
|
+
omlpVault: TAccountMetas[4];
|
|
532
|
+
/** Underlying token mint (for decimal handling) */
|
|
533
|
+
underlyingMint: TAccountMetas[5];
|
|
534
|
+
/** Market data account (provides pyth_feed_id for price check) */
|
|
535
|
+
marketData: TAccountMetas[6];
|
|
536
|
+
/** Pyth price update account for current underlying price */
|
|
537
|
+
priceUpdate: TAccountMetas[7];
|
|
538
|
+
/** Collateral vault (source of repayments) */
|
|
539
|
+
collateralVault: TAccountMetas[8];
|
|
540
|
+
/** OMLP vault token account (receives loan repayments) */
|
|
541
|
+
omlpVaultTokenAccount: TAccountMetas[9];
|
|
542
|
+
/** Protocol fee wallet (receives liquidation fees) */
|
|
543
|
+
feeWallet: TAccountMetas[10];
|
|
544
|
+
/** Liquidator/keeper (permissionless - anyone can call) */
|
|
545
|
+
liquidator: TAccountMetas[11];
|
|
546
|
+
tokenProgram: TAccountMetas[12];
|
|
547
|
+
systemProgram: TAccountMetas[13];
|
|
548
|
+
};
|
|
549
|
+
data: LiquidateWriterPositionInstructionData;
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
export function parseLiquidateWriterPositionInstruction<
|
|
553
|
+
TProgram extends string,
|
|
554
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
555
|
+
>(
|
|
556
|
+
instruction: Instruction<TProgram> &
|
|
557
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
558
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
559
|
+
): ParsedLiquidateWriterPositionInstruction<TProgram, TAccountMetas> {
|
|
560
|
+
if (instruction.accounts.length < 14) {
|
|
561
|
+
// TODO: Coded error.
|
|
562
|
+
throw new Error("Not enough accounts");
|
|
563
|
+
}
|
|
564
|
+
let accountIndex = 0;
|
|
565
|
+
const getNextAccount = () => {
|
|
566
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
567
|
+
accountIndex += 1;
|
|
568
|
+
return accountMeta;
|
|
569
|
+
};
|
|
570
|
+
return {
|
|
571
|
+
programAddress: instruction.programAddress,
|
|
572
|
+
accounts: {
|
|
573
|
+
optionPool: getNextAccount(),
|
|
574
|
+
optionAccount: getNextAccount(),
|
|
575
|
+
collateralPool: getNextAccount(),
|
|
576
|
+
writerPosition: getNextAccount(),
|
|
577
|
+
omlpVault: getNextAccount(),
|
|
578
|
+
underlyingMint: getNextAccount(),
|
|
579
|
+
marketData: getNextAccount(),
|
|
580
|
+
priceUpdate: getNextAccount(),
|
|
581
|
+
collateralVault: getNextAccount(),
|
|
582
|
+
omlpVaultTokenAccount: getNextAccount(),
|
|
583
|
+
feeWallet: getNextAccount(),
|
|
584
|
+
liquidator: getNextAccount(),
|
|
585
|
+
tokenProgram: getNextAccount(),
|
|
586
|
+
systemProgram: getNextAccount(),
|
|
587
|
+
},
|
|
588
|
+
data: getLiquidateWriterPositionInstructionDataDecoder().decode(
|
|
589
|
+
instruction.data,
|
|
590
|
+
),
|
|
591
|
+
};
|
|
592
|
+
}
|