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