@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,668 @@
|
|
|
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
|
+
getU64Decoder,
|
|
20
|
+
getU64Encoder,
|
|
21
|
+
transformEncoder,
|
|
22
|
+
type AccountMeta,
|
|
23
|
+
type AccountSignerMeta,
|
|
24
|
+
type Address,
|
|
25
|
+
type FixedSizeCodec,
|
|
26
|
+
type FixedSizeDecoder,
|
|
27
|
+
type FixedSizeEncoder,
|
|
28
|
+
type Instruction,
|
|
29
|
+
type InstructionWithAccounts,
|
|
30
|
+
type InstructionWithData,
|
|
31
|
+
type ReadonlyAccount,
|
|
32
|
+
type ReadonlyUint8Array,
|
|
33
|
+
type TransactionSigner,
|
|
34
|
+
type WritableAccount,
|
|
35
|
+
type WritableSignerAccount,
|
|
36
|
+
} from "@solana/kit";
|
|
37
|
+
import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
|
|
38
|
+
import {
|
|
39
|
+
expectAddress,
|
|
40
|
+
getAccountMetaFactory,
|
|
41
|
+
type ResolvedAccount,
|
|
42
|
+
} from "../shared";
|
|
43
|
+
|
|
44
|
+
export const UNWIND_WRITER_UNSOLD_DISCRIMINATOR = new Uint8Array([
|
|
45
|
+
48, 116, 34, 53, 22, 225, 22, 79,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
export function getUnwindWriterUnsoldDiscriminatorBytes() {
|
|
49
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
50
|
+
UNWIND_WRITER_UNSOLD_DISCRIMINATOR,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type UnwindWriterUnsoldInstruction<
|
|
55
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
56
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountOptionAccount extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountCollateralPool extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountWriterPosition extends string | AccountMeta<string> = string,
|
|
60
|
+
TAccountLongMint extends string | AccountMeta<string> = string,
|
|
61
|
+
TAccountShortMint extends string | AccountMeta<string> = string,
|
|
62
|
+
TAccountEscrowLongAccount extends string | AccountMeta<string> = string,
|
|
63
|
+
TAccountWriterShortAccount extends string | AccountMeta<string> = string,
|
|
64
|
+
TAccountCollateralVault extends string | AccountMeta<string> = string,
|
|
65
|
+
TAccountWriterCollateralAccount extends string | AccountMeta<string> = string,
|
|
66
|
+
TAccountOmlpVault extends string | AccountMeta<string> = string,
|
|
67
|
+
TAccountFeeWallet extends string | AccountMeta<string> = string,
|
|
68
|
+
TAccountWriter extends string | AccountMeta<string> = string,
|
|
69
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
70
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
71
|
+
TAccountSystemProgram extends string | AccountMeta<string> =
|
|
72
|
+
"11111111111111111111111111111111",
|
|
73
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
74
|
+
> = Instruction<TProgram> &
|
|
75
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
76
|
+
InstructionWithAccounts<
|
|
77
|
+
[
|
|
78
|
+
TAccountOptionPool extends string
|
|
79
|
+
? WritableAccount<TAccountOptionPool>
|
|
80
|
+
: TAccountOptionPool,
|
|
81
|
+
TAccountOptionAccount extends string
|
|
82
|
+
? WritableAccount<TAccountOptionAccount>
|
|
83
|
+
: TAccountOptionAccount,
|
|
84
|
+
TAccountCollateralPool extends string
|
|
85
|
+
? WritableAccount<TAccountCollateralPool>
|
|
86
|
+
: TAccountCollateralPool,
|
|
87
|
+
TAccountWriterPosition extends string
|
|
88
|
+
? WritableAccount<TAccountWriterPosition>
|
|
89
|
+
: TAccountWriterPosition,
|
|
90
|
+
TAccountLongMint extends string
|
|
91
|
+
? WritableAccount<TAccountLongMint>
|
|
92
|
+
: TAccountLongMint,
|
|
93
|
+
TAccountShortMint extends string
|
|
94
|
+
? WritableAccount<TAccountShortMint>
|
|
95
|
+
: TAccountShortMint,
|
|
96
|
+
TAccountEscrowLongAccount extends string
|
|
97
|
+
? WritableAccount<TAccountEscrowLongAccount>
|
|
98
|
+
: TAccountEscrowLongAccount,
|
|
99
|
+
TAccountWriterShortAccount extends string
|
|
100
|
+
? WritableAccount<TAccountWriterShortAccount>
|
|
101
|
+
: TAccountWriterShortAccount,
|
|
102
|
+
TAccountCollateralVault extends string
|
|
103
|
+
? WritableAccount<TAccountCollateralVault>
|
|
104
|
+
: TAccountCollateralVault,
|
|
105
|
+
TAccountWriterCollateralAccount extends string
|
|
106
|
+
? WritableAccount<TAccountWriterCollateralAccount>
|
|
107
|
+
: TAccountWriterCollateralAccount,
|
|
108
|
+
TAccountOmlpVault extends string
|
|
109
|
+
? WritableAccount<TAccountOmlpVault>
|
|
110
|
+
: TAccountOmlpVault,
|
|
111
|
+
TAccountFeeWallet extends string
|
|
112
|
+
? WritableAccount<TAccountFeeWallet>
|
|
113
|
+
: TAccountFeeWallet,
|
|
114
|
+
TAccountWriter extends string
|
|
115
|
+
? WritableSignerAccount<TAccountWriter> &
|
|
116
|
+
AccountSignerMeta<TAccountWriter>
|
|
117
|
+
: TAccountWriter,
|
|
118
|
+
TAccountTokenProgram extends string
|
|
119
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
120
|
+
: TAccountTokenProgram,
|
|
121
|
+
TAccountSystemProgram extends string
|
|
122
|
+
? ReadonlyAccount<TAccountSystemProgram>
|
|
123
|
+
: TAccountSystemProgram,
|
|
124
|
+
...TRemainingAccounts,
|
|
125
|
+
]
|
|
126
|
+
>;
|
|
127
|
+
|
|
128
|
+
export type UnwindWriterUnsoldInstructionData = {
|
|
129
|
+
discriminator: ReadonlyUint8Array;
|
|
130
|
+
unwindQty: bigint;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export type UnwindWriterUnsoldInstructionDataArgs = {
|
|
134
|
+
unwindQty: number | bigint;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export function getUnwindWriterUnsoldInstructionDataEncoder(): FixedSizeEncoder<UnwindWriterUnsoldInstructionDataArgs> {
|
|
138
|
+
return transformEncoder(
|
|
139
|
+
getStructEncoder([
|
|
140
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
141
|
+
["unwindQty", getU64Encoder()],
|
|
142
|
+
]),
|
|
143
|
+
(value) => ({
|
|
144
|
+
...value,
|
|
145
|
+
discriminator: UNWIND_WRITER_UNSOLD_DISCRIMINATOR,
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function getUnwindWriterUnsoldInstructionDataDecoder(): FixedSizeDecoder<UnwindWriterUnsoldInstructionData> {
|
|
151
|
+
return getStructDecoder([
|
|
152
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
153
|
+
["unwindQty", getU64Decoder()],
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function getUnwindWriterUnsoldInstructionDataCodec(): FixedSizeCodec<
|
|
158
|
+
UnwindWriterUnsoldInstructionDataArgs,
|
|
159
|
+
UnwindWriterUnsoldInstructionData
|
|
160
|
+
> {
|
|
161
|
+
return combineCodec(
|
|
162
|
+
getUnwindWriterUnsoldInstructionDataEncoder(),
|
|
163
|
+
getUnwindWriterUnsoldInstructionDataDecoder(),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export type UnwindWriterUnsoldAsyncInput<
|
|
168
|
+
TAccountOptionPool extends string = string,
|
|
169
|
+
TAccountOptionAccount extends string = string,
|
|
170
|
+
TAccountCollateralPool extends string = string,
|
|
171
|
+
TAccountWriterPosition extends string = string,
|
|
172
|
+
TAccountLongMint extends string = string,
|
|
173
|
+
TAccountShortMint extends string = string,
|
|
174
|
+
TAccountEscrowLongAccount extends string = string,
|
|
175
|
+
TAccountWriterShortAccount extends string = string,
|
|
176
|
+
TAccountCollateralVault extends string = string,
|
|
177
|
+
TAccountWriterCollateralAccount extends string = string,
|
|
178
|
+
TAccountOmlpVault extends string = string,
|
|
179
|
+
TAccountFeeWallet extends string = string,
|
|
180
|
+
TAccountWriter extends string = string,
|
|
181
|
+
TAccountTokenProgram extends string = string,
|
|
182
|
+
TAccountSystemProgram extends string = string,
|
|
183
|
+
> = {
|
|
184
|
+
/** The option pool */
|
|
185
|
+
optionPool: Address<TAccountOptionPool>;
|
|
186
|
+
/** The option account */
|
|
187
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
188
|
+
/** Collateral pool */
|
|
189
|
+
collateralPool?: Address<TAccountCollateralPool>;
|
|
190
|
+
/** Writer's unified position account */
|
|
191
|
+
writerPosition?: Address<TAccountWriterPosition>;
|
|
192
|
+
/** LONG token mint (for burning from escrow) */
|
|
193
|
+
longMint: Address<TAccountLongMint>;
|
|
194
|
+
/** SHORT token mint (for burning from writer) */
|
|
195
|
+
shortMint: Address<TAccountShortMint>;
|
|
196
|
+
/** Pool's LONG escrow (source of LONG tokens to burn) */
|
|
197
|
+
escrowLongAccount: Address<TAccountEscrowLongAccount>;
|
|
198
|
+
/** Writer's SHORT token account (source of SHORT tokens to burn) */
|
|
199
|
+
writerShortAccount: Address<TAccountWriterShortAccount>;
|
|
200
|
+
/** Collateral vault (source of collateral return) */
|
|
201
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
202
|
+
/** Writer's underlying token account (receives returned collateral) */
|
|
203
|
+
writerCollateralAccount: Address<TAccountWriterCollateralAccount>;
|
|
204
|
+
/** OMLP vault token account (receives loan repayments) - optional */
|
|
205
|
+
omlpVault?: Address<TAccountOmlpVault>;
|
|
206
|
+
/** Protocol fee wallet (receives protocol fees) - optional */
|
|
207
|
+
feeWallet?: Address<TAccountFeeWallet>;
|
|
208
|
+
writer: TransactionSigner<TAccountWriter>;
|
|
209
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
210
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
211
|
+
unwindQty: UnwindWriterUnsoldInstructionDataArgs["unwindQty"];
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export async function getUnwindWriterUnsoldInstructionAsync<
|
|
215
|
+
TAccountOptionPool extends string,
|
|
216
|
+
TAccountOptionAccount extends string,
|
|
217
|
+
TAccountCollateralPool extends string,
|
|
218
|
+
TAccountWriterPosition extends string,
|
|
219
|
+
TAccountLongMint extends string,
|
|
220
|
+
TAccountShortMint extends string,
|
|
221
|
+
TAccountEscrowLongAccount extends string,
|
|
222
|
+
TAccountWriterShortAccount extends string,
|
|
223
|
+
TAccountCollateralVault extends string,
|
|
224
|
+
TAccountWriterCollateralAccount extends string,
|
|
225
|
+
TAccountOmlpVault extends string,
|
|
226
|
+
TAccountFeeWallet extends string,
|
|
227
|
+
TAccountWriter extends string,
|
|
228
|
+
TAccountTokenProgram extends string,
|
|
229
|
+
TAccountSystemProgram extends string,
|
|
230
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
231
|
+
>(
|
|
232
|
+
input: UnwindWriterUnsoldAsyncInput<
|
|
233
|
+
TAccountOptionPool,
|
|
234
|
+
TAccountOptionAccount,
|
|
235
|
+
TAccountCollateralPool,
|
|
236
|
+
TAccountWriterPosition,
|
|
237
|
+
TAccountLongMint,
|
|
238
|
+
TAccountShortMint,
|
|
239
|
+
TAccountEscrowLongAccount,
|
|
240
|
+
TAccountWriterShortAccount,
|
|
241
|
+
TAccountCollateralVault,
|
|
242
|
+
TAccountWriterCollateralAccount,
|
|
243
|
+
TAccountOmlpVault,
|
|
244
|
+
TAccountFeeWallet,
|
|
245
|
+
TAccountWriter,
|
|
246
|
+
TAccountTokenProgram,
|
|
247
|
+
TAccountSystemProgram
|
|
248
|
+
>,
|
|
249
|
+
config?: { programAddress?: TProgramAddress },
|
|
250
|
+
): Promise<
|
|
251
|
+
UnwindWriterUnsoldInstruction<
|
|
252
|
+
TProgramAddress,
|
|
253
|
+
TAccountOptionPool,
|
|
254
|
+
TAccountOptionAccount,
|
|
255
|
+
TAccountCollateralPool,
|
|
256
|
+
TAccountWriterPosition,
|
|
257
|
+
TAccountLongMint,
|
|
258
|
+
TAccountShortMint,
|
|
259
|
+
TAccountEscrowLongAccount,
|
|
260
|
+
TAccountWriterShortAccount,
|
|
261
|
+
TAccountCollateralVault,
|
|
262
|
+
TAccountWriterCollateralAccount,
|
|
263
|
+
TAccountOmlpVault,
|
|
264
|
+
TAccountFeeWallet,
|
|
265
|
+
TAccountWriter,
|
|
266
|
+
TAccountTokenProgram,
|
|
267
|
+
TAccountSystemProgram
|
|
268
|
+
>
|
|
269
|
+
> {
|
|
270
|
+
// Program address.
|
|
271
|
+
const programAddress =
|
|
272
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
273
|
+
|
|
274
|
+
// Original accounts.
|
|
275
|
+
const originalAccounts = {
|
|
276
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
277
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
278
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
279
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
280
|
+
longMint: { value: input.longMint ?? null, isWritable: true },
|
|
281
|
+
shortMint: { value: input.shortMint ?? null, isWritable: true },
|
|
282
|
+
escrowLongAccount: {
|
|
283
|
+
value: input.escrowLongAccount ?? null,
|
|
284
|
+
isWritable: true,
|
|
285
|
+
},
|
|
286
|
+
writerShortAccount: {
|
|
287
|
+
value: input.writerShortAccount ?? null,
|
|
288
|
+
isWritable: true,
|
|
289
|
+
},
|
|
290
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
291
|
+
writerCollateralAccount: {
|
|
292
|
+
value: input.writerCollateralAccount ?? null,
|
|
293
|
+
isWritable: true,
|
|
294
|
+
},
|
|
295
|
+
omlpVault: { value: input.omlpVault ?? null, isWritable: true },
|
|
296
|
+
feeWallet: { value: input.feeWallet ?? null, isWritable: true },
|
|
297
|
+
writer: { value: input.writer ?? null, isWritable: true },
|
|
298
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
299
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
300
|
+
};
|
|
301
|
+
const accounts = originalAccounts as Record<
|
|
302
|
+
keyof typeof originalAccounts,
|
|
303
|
+
ResolvedAccount
|
|
304
|
+
>;
|
|
305
|
+
|
|
306
|
+
// Original args.
|
|
307
|
+
const args = { ...input };
|
|
308
|
+
|
|
309
|
+
// Resolve default values.
|
|
310
|
+
if (!accounts.collateralPool.value) {
|
|
311
|
+
accounts.collateralPool.value = await getProgramDerivedAddress({
|
|
312
|
+
programAddress,
|
|
313
|
+
seeds: [
|
|
314
|
+
getBytesEncoder().encode(
|
|
315
|
+
new Uint8Array([
|
|
316
|
+
99, 111, 108, 108, 97, 116, 101, 114, 97, 108, 95, 112, 111, 111,
|
|
317
|
+
108,
|
|
318
|
+
]),
|
|
319
|
+
),
|
|
320
|
+
getAddressEncoder().encode(expectAddress(accounts.optionAccount.value)),
|
|
321
|
+
],
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
if (!accounts.writerPosition.value) {
|
|
325
|
+
accounts.writerPosition.value = await getProgramDerivedAddress({
|
|
326
|
+
programAddress,
|
|
327
|
+
seeds: [
|
|
328
|
+
getBytesEncoder().encode(
|
|
329
|
+
new Uint8Array([
|
|
330
|
+
119, 114, 105, 116, 101, 114, 95, 112, 111, 115, 105, 116, 105, 111,
|
|
331
|
+
110,
|
|
332
|
+
]),
|
|
333
|
+
),
|
|
334
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
335
|
+
getAddressEncoder().encode(expectAddress(accounts.writer.value)),
|
|
336
|
+
],
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (!accounts.tokenProgram.value) {
|
|
340
|
+
accounts.tokenProgram.value =
|
|
341
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
342
|
+
}
|
|
343
|
+
if (!accounts.systemProgram.value) {
|
|
344
|
+
accounts.systemProgram.value =
|
|
345
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
349
|
+
return Object.freeze({
|
|
350
|
+
accounts: [
|
|
351
|
+
getAccountMeta(accounts.optionPool),
|
|
352
|
+
getAccountMeta(accounts.optionAccount),
|
|
353
|
+
getAccountMeta(accounts.collateralPool),
|
|
354
|
+
getAccountMeta(accounts.writerPosition),
|
|
355
|
+
getAccountMeta(accounts.longMint),
|
|
356
|
+
getAccountMeta(accounts.shortMint),
|
|
357
|
+
getAccountMeta(accounts.escrowLongAccount),
|
|
358
|
+
getAccountMeta(accounts.writerShortAccount),
|
|
359
|
+
getAccountMeta(accounts.collateralVault),
|
|
360
|
+
getAccountMeta(accounts.writerCollateralAccount),
|
|
361
|
+
getAccountMeta(accounts.omlpVault),
|
|
362
|
+
getAccountMeta(accounts.feeWallet),
|
|
363
|
+
getAccountMeta(accounts.writer),
|
|
364
|
+
getAccountMeta(accounts.tokenProgram),
|
|
365
|
+
getAccountMeta(accounts.systemProgram),
|
|
366
|
+
],
|
|
367
|
+
data: getUnwindWriterUnsoldInstructionDataEncoder().encode(
|
|
368
|
+
args as UnwindWriterUnsoldInstructionDataArgs,
|
|
369
|
+
),
|
|
370
|
+
programAddress,
|
|
371
|
+
} as UnwindWriterUnsoldInstruction<
|
|
372
|
+
TProgramAddress,
|
|
373
|
+
TAccountOptionPool,
|
|
374
|
+
TAccountOptionAccount,
|
|
375
|
+
TAccountCollateralPool,
|
|
376
|
+
TAccountWriterPosition,
|
|
377
|
+
TAccountLongMint,
|
|
378
|
+
TAccountShortMint,
|
|
379
|
+
TAccountEscrowLongAccount,
|
|
380
|
+
TAccountWriterShortAccount,
|
|
381
|
+
TAccountCollateralVault,
|
|
382
|
+
TAccountWriterCollateralAccount,
|
|
383
|
+
TAccountOmlpVault,
|
|
384
|
+
TAccountFeeWallet,
|
|
385
|
+
TAccountWriter,
|
|
386
|
+
TAccountTokenProgram,
|
|
387
|
+
TAccountSystemProgram
|
|
388
|
+
>);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export type UnwindWriterUnsoldInput<
|
|
392
|
+
TAccountOptionPool extends string = string,
|
|
393
|
+
TAccountOptionAccount extends string = string,
|
|
394
|
+
TAccountCollateralPool extends string = string,
|
|
395
|
+
TAccountWriterPosition extends string = string,
|
|
396
|
+
TAccountLongMint extends string = string,
|
|
397
|
+
TAccountShortMint extends string = string,
|
|
398
|
+
TAccountEscrowLongAccount extends string = string,
|
|
399
|
+
TAccountWriterShortAccount extends string = string,
|
|
400
|
+
TAccountCollateralVault extends string = string,
|
|
401
|
+
TAccountWriterCollateralAccount extends string = string,
|
|
402
|
+
TAccountOmlpVault extends string = string,
|
|
403
|
+
TAccountFeeWallet extends string = string,
|
|
404
|
+
TAccountWriter extends string = string,
|
|
405
|
+
TAccountTokenProgram extends string = string,
|
|
406
|
+
TAccountSystemProgram extends string = string,
|
|
407
|
+
> = {
|
|
408
|
+
/** The option pool */
|
|
409
|
+
optionPool: Address<TAccountOptionPool>;
|
|
410
|
+
/** The option account */
|
|
411
|
+
optionAccount: Address<TAccountOptionAccount>;
|
|
412
|
+
/** Collateral pool */
|
|
413
|
+
collateralPool: Address<TAccountCollateralPool>;
|
|
414
|
+
/** Writer's unified position account */
|
|
415
|
+
writerPosition: Address<TAccountWriterPosition>;
|
|
416
|
+
/** LONG token mint (for burning from escrow) */
|
|
417
|
+
longMint: Address<TAccountLongMint>;
|
|
418
|
+
/** SHORT token mint (for burning from writer) */
|
|
419
|
+
shortMint: Address<TAccountShortMint>;
|
|
420
|
+
/** Pool's LONG escrow (source of LONG tokens to burn) */
|
|
421
|
+
escrowLongAccount: Address<TAccountEscrowLongAccount>;
|
|
422
|
+
/** Writer's SHORT token account (source of SHORT tokens to burn) */
|
|
423
|
+
writerShortAccount: Address<TAccountWriterShortAccount>;
|
|
424
|
+
/** Collateral vault (source of collateral return) */
|
|
425
|
+
collateralVault: Address<TAccountCollateralVault>;
|
|
426
|
+
/** Writer's underlying token account (receives returned collateral) */
|
|
427
|
+
writerCollateralAccount: Address<TAccountWriterCollateralAccount>;
|
|
428
|
+
/** OMLP vault token account (receives loan repayments) - optional */
|
|
429
|
+
omlpVault?: Address<TAccountOmlpVault>;
|
|
430
|
+
/** Protocol fee wallet (receives protocol fees) - optional */
|
|
431
|
+
feeWallet?: Address<TAccountFeeWallet>;
|
|
432
|
+
writer: TransactionSigner<TAccountWriter>;
|
|
433
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
434
|
+
systemProgram?: Address<TAccountSystemProgram>;
|
|
435
|
+
unwindQty: UnwindWriterUnsoldInstructionDataArgs["unwindQty"];
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
export function getUnwindWriterUnsoldInstruction<
|
|
439
|
+
TAccountOptionPool extends string,
|
|
440
|
+
TAccountOptionAccount extends string,
|
|
441
|
+
TAccountCollateralPool extends string,
|
|
442
|
+
TAccountWriterPosition extends string,
|
|
443
|
+
TAccountLongMint extends string,
|
|
444
|
+
TAccountShortMint extends string,
|
|
445
|
+
TAccountEscrowLongAccount extends string,
|
|
446
|
+
TAccountWriterShortAccount extends string,
|
|
447
|
+
TAccountCollateralVault extends string,
|
|
448
|
+
TAccountWriterCollateralAccount extends string,
|
|
449
|
+
TAccountOmlpVault extends string,
|
|
450
|
+
TAccountFeeWallet extends string,
|
|
451
|
+
TAccountWriter extends string,
|
|
452
|
+
TAccountTokenProgram extends string,
|
|
453
|
+
TAccountSystemProgram extends string,
|
|
454
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
455
|
+
>(
|
|
456
|
+
input: UnwindWriterUnsoldInput<
|
|
457
|
+
TAccountOptionPool,
|
|
458
|
+
TAccountOptionAccount,
|
|
459
|
+
TAccountCollateralPool,
|
|
460
|
+
TAccountWriterPosition,
|
|
461
|
+
TAccountLongMint,
|
|
462
|
+
TAccountShortMint,
|
|
463
|
+
TAccountEscrowLongAccount,
|
|
464
|
+
TAccountWriterShortAccount,
|
|
465
|
+
TAccountCollateralVault,
|
|
466
|
+
TAccountWriterCollateralAccount,
|
|
467
|
+
TAccountOmlpVault,
|
|
468
|
+
TAccountFeeWallet,
|
|
469
|
+
TAccountWriter,
|
|
470
|
+
TAccountTokenProgram,
|
|
471
|
+
TAccountSystemProgram
|
|
472
|
+
>,
|
|
473
|
+
config?: { programAddress?: TProgramAddress },
|
|
474
|
+
): UnwindWriterUnsoldInstruction<
|
|
475
|
+
TProgramAddress,
|
|
476
|
+
TAccountOptionPool,
|
|
477
|
+
TAccountOptionAccount,
|
|
478
|
+
TAccountCollateralPool,
|
|
479
|
+
TAccountWriterPosition,
|
|
480
|
+
TAccountLongMint,
|
|
481
|
+
TAccountShortMint,
|
|
482
|
+
TAccountEscrowLongAccount,
|
|
483
|
+
TAccountWriterShortAccount,
|
|
484
|
+
TAccountCollateralVault,
|
|
485
|
+
TAccountWriterCollateralAccount,
|
|
486
|
+
TAccountOmlpVault,
|
|
487
|
+
TAccountFeeWallet,
|
|
488
|
+
TAccountWriter,
|
|
489
|
+
TAccountTokenProgram,
|
|
490
|
+
TAccountSystemProgram
|
|
491
|
+
> {
|
|
492
|
+
// Program address.
|
|
493
|
+
const programAddress =
|
|
494
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
495
|
+
|
|
496
|
+
// Original accounts.
|
|
497
|
+
const originalAccounts = {
|
|
498
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
499
|
+
optionAccount: { value: input.optionAccount ?? null, isWritable: true },
|
|
500
|
+
collateralPool: { value: input.collateralPool ?? null, isWritable: true },
|
|
501
|
+
writerPosition: { value: input.writerPosition ?? null, isWritable: true },
|
|
502
|
+
longMint: { value: input.longMint ?? null, isWritable: true },
|
|
503
|
+
shortMint: { value: input.shortMint ?? null, isWritable: true },
|
|
504
|
+
escrowLongAccount: {
|
|
505
|
+
value: input.escrowLongAccount ?? null,
|
|
506
|
+
isWritable: true,
|
|
507
|
+
},
|
|
508
|
+
writerShortAccount: {
|
|
509
|
+
value: input.writerShortAccount ?? null,
|
|
510
|
+
isWritable: true,
|
|
511
|
+
},
|
|
512
|
+
collateralVault: { value: input.collateralVault ?? null, isWritable: true },
|
|
513
|
+
writerCollateralAccount: {
|
|
514
|
+
value: input.writerCollateralAccount ?? null,
|
|
515
|
+
isWritable: true,
|
|
516
|
+
},
|
|
517
|
+
omlpVault: { value: input.omlpVault ?? null, isWritable: true },
|
|
518
|
+
feeWallet: { value: input.feeWallet ?? null, isWritable: true },
|
|
519
|
+
writer: { value: input.writer ?? null, isWritable: true },
|
|
520
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
521
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
522
|
+
};
|
|
523
|
+
const accounts = originalAccounts as Record<
|
|
524
|
+
keyof typeof originalAccounts,
|
|
525
|
+
ResolvedAccount
|
|
526
|
+
>;
|
|
527
|
+
|
|
528
|
+
// Original args.
|
|
529
|
+
const args = { ...input };
|
|
530
|
+
|
|
531
|
+
// Resolve default values.
|
|
532
|
+
if (!accounts.tokenProgram.value) {
|
|
533
|
+
accounts.tokenProgram.value =
|
|
534
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
535
|
+
}
|
|
536
|
+
if (!accounts.systemProgram.value) {
|
|
537
|
+
accounts.systemProgram.value =
|
|
538
|
+
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
542
|
+
return Object.freeze({
|
|
543
|
+
accounts: [
|
|
544
|
+
getAccountMeta(accounts.optionPool),
|
|
545
|
+
getAccountMeta(accounts.optionAccount),
|
|
546
|
+
getAccountMeta(accounts.collateralPool),
|
|
547
|
+
getAccountMeta(accounts.writerPosition),
|
|
548
|
+
getAccountMeta(accounts.longMint),
|
|
549
|
+
getAccountMeta(accounts.shortMint),
|
|
550
|
+
getAccountMeta(accounts.escrowLongAccount),
|
|
551
|
+
getAccountMeta(accounts.writerShortAccount),
|
|
552
|
+
getAccountMeta(accounts.collateralVault),
|
|
553
|
+
getAccountMeta(accounts.writerCollateralAccount),
|
|
554
|
+
getAccountMeta(accounts.omlpVault),
|
|
555
|
+
getAccountMeta(accounts.feeWallet),
|
|
556
|
+
getAccountMeta(accounts.writer),
|
|
557
|
+
getAccountMeta(accounts.tokenProgram),
|
|
558
|
+
getAccountMeta(accounts.systemProgram),
|
|
559
|
+
],
|
|
560
|
+
data: getUnwindWriterUnsoldInstructionDataEncoder().encode(
|
|
561
|
+
args as UnwindWriterUnsoldInstructionDataArgs,
|
|
562
|
+
),
|
|
563
|
+
programAddress,
|
|
564
|
+
} as UnwindWriterUnsoldInstruction<
|
|
565
|
+
TProgramAddress,
|
|
566
|
+
TAccountOptionPool,
|
|
567
|
+
TAccountOptionAccount,
|
|
568
|
+
TAccountCollateralPool,
|
|
569
|
+
TAccountWriterPosition,
|
|
570
|
+
TAccountLongMint,
|
|
571
|
+
TAccountShortMint,
|
|
572
|
+
TAccountEscrowLongAccount,
|
|
573
|
+
TAccountWriterShortAccount,
|
|
574
|
+
TAccountCollateralVault,
|
|
575
|
+
TAccountWriterCollateralAccount,
|
|
576
|
+
TAccountOmlpVault,
|
|
577
|
+
TAccountFeeWallet,
|
|
578
|
+
TAccountWriter,
|
|
579
|
+
TAccountTokenProgram,
|
|
580
|
+
TAccountSystemProgram
|
|
581
|
+
>);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
export type ParsedUnwindWriterUnsoldInstruction<
|
|
585
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
586
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
587
|
+
> = {
|
|
588
|
+
programAddress: Address<TProgram>;
|
|
589
|
+
accounts: {
|
|
590
|
+
/** The option pool */
|
|
591
|
+
optionPool: TAccountMetas[0];
|
|
592
|
+
/** The option account */
|
|
593
|
+
optionAccount: TAccountMetas[1];
|
|
594
|
+
/** Collateral pool */
|
|
595
|
+
collateralPool: TAccountMetas[2];
|
|
596
|
+
/** Writer's unified position account */
|
|
597
|
+
writerPosition: TAccountMetas[3];
|
|
598
|
+
/** LONG token mint (for burning from escrow) */
|
|
599
|
+
longMint: TAccountMetas[4];
|
|
600
|
+
/** SHORT token mint (for burning from writer) */
|
|
601
|
+
shortMint: TAccountMetas[5];
|
|
602
|
+
/** Pool's LONG escrow (source of LONG tokens to burn) */
|
|
603
|
+
escrowLongAccount: TAccountMetas[6];
|
|
604
|
+
/** Writer's SHORT token account (source of SHORT tokens to burn) */
|
|
605
|
+
writerShortAccount: TAccountMetas[7];
|
|
606
|
+
/** Collateral vault (source of collateral return) */
|
|
607
|
+
collateralVault: TAccountMetas[8];
|
|
608
|
+
/** Writer's underlying token account (receives returned collateral) */
|
|
609
|
+
writerCollateralAccount: TAccountMetas[9];
|
|
610
|
+
/** OMLP vault token account (receives loan repayments) - optional */
|
|
611
|
+
omlpVault?: TAccountMetas[10] | undefined;
|
|
612
|
+
/** Protocol fee wallet (receives protocol fees) - optional */
|
|
613
|
+
feeWallet?: TAccountMetas[11] | undefined;
|
|
614
|
+
writer: TAccountMetas[12];
|
|
615
|
+
tokenProgram: TAccountMetas[13];
|
|
616
|
+
systemProgram: TAccountMetas[14];
|
|
617
|
+
};
|
|
618
|
+
data: UnwindWriterUnsoldInstructionData;
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
export function parseUnwindWriterUnsoldInstruction<
|
|
622
|
+
TProgram extends string,
|
|
623
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
624
|
+
>(
|
|
625
|
+
instruction: Instruction<TProgram> &
|
|
626
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
627
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
628
|
+
): ParsedUnwindWriterUnsoldInstruction<TProgram, TAccountMetas> {
|
|
629
|
+
if (instruction.accounts.length < 15) {
|
|
630
|
+
// TODO: Coded error.
|
|
631
|
+
throw new Error("Not enough accounts");
|
|
632
|
+
}
|
|
633
|
+
let accountIndex = 0;
|
|
634
|
+
const getNextAccount = () => {
|
|
635
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
636
|
+
accountIndex += 1;
|
|
637
|
+
return accountMeta;
|
|
638
|
+
};
|
|
639
|
+
const getNextOptionalAccount = () => {
|
|
640
|
+
const accountMeta = getNextAccount();
|
|
641
|
+
return accountMeta.address === OPTION_PROGRAM_PROGRAM_ADDRESS
|
|
642
|
+
? undefined
|
|
643
|
+
: accountMeta;
|
|
644
|
+
};
|
|
645
|
+
return {
|
|
646
|
+
programAddress: instruction.programAddress,
|
|
647
|
+
accounts: {
|
|
648
|
+
optionPool: getNextAccount(),
|
|
649
|
+
optionAccount: getNextAccount(),
|
|
650
|
+
collateralPool: getNextAccount(),
|
|
651
|
+
writerPosition: getNextAccount(),
|
|
652
|
+
longMint: getNextAccount(),
|
|
653
|
+
shortMint: getNextAccount(),
|
|
654
|
+
escrowLongAccount: getNextAccount(),
|
|
655
|
+
writerShortAccount: getNextAccount(),
|
|
656
|
+
collateralVault: getNextAccount(),
|
|
657
|
+
writerCollateralAccount: getNextAccount(),
|
|
658
|
+
omlpVault: getNextOptionalAccount(),
|
|
659
|
+
feeWallet: getNextOptionalAccount(),
|
|
660
|
+
writer: getNextAccount(),
|
|
661
|
+
tokenProgram: getNextAccount(),
|
|
662
|
+
systemProgram: getNextAccount(),
|
|
663
|
+
},
|
|
664
|
+
data: getUnwindWriterUnsoldInstructionDataDecoder().decode(
|
|
665
|
+
instruction.data,
|
|
666
|
+
),
|
|
667
|
+
};
|
|
668
|
+
}
|