@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,377 @@
|
|
|
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 CLAIM_PREMIUM_DISCRIMINATOR = new Uint8Array([
|
|
43
|
+
225, 124, 12, 107, 24, 154, 37, 100,
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
export function getClaimPremiumDiscriminatorBytes() {
|
|
47
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
48
|
+
CLAIM_PREMIUM_DISCRIMINATOR,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type ClaimPremiumInstruction<
|
|
53
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
54
|
+
TAccountOptionPool extends string | AccountMeta<string> = string,
|
|
55
|
+
TAccountMakerPoolShare extends string | AccountMeta<string> = string,
|
|
56
|
+
TAccountMakerPaymentAccount extends string | AccountMeta<string> = string,
|
|
57
|
+
TAccountPremiumVault extends string | AccountMeta<string> = string,
|
|
58
|
+
TAccountMaker extends string | AccountMeta<string> = string,
|
|
59
|
+
TAccountTokenProgram extends string | AccountMeta<string> =
|
|
60
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
|
|
61
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
62
|
+
> = Instruction<TProgram> &
|
|
63
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
64
|
+
InstructionWithAccounts<
|
|
65
|
+
[
|
|
66
|
+
TAccountOptionPool extends string
|
|
67
|
+
? WritableAccount<TAccountOptionPool>
|
|
68
|
+
: TAccountOptionPool,
|
|
69
|
+
TAccountMakerPoolShare extends string
|
|
70
|
+
? WritableAccount<TAccountMakerPoolShare>
|
|
71
|
+
: TAccountMakerPoolShare,
|
|
72
|
+
TAccountMakerPaymentAccount extends string
|
|
73
|
+
? WritableAccount<TAccountMakerPaymentAccount>
|
|
74
|
+
: TAccountMakerPaymentAccount,
|
|
75
|
+
TAccountPremiumVault extends string
|
|
76
|
+
? WritableAccount<TAccountPremiumVault>
|
|
77
|
+
: TAccountPremiumVault,
|
|
78
|
+
TAccountMaker extends string
|
|
79
|
+
? WritableSignerAccount<TAccountMaker> &
|
|
80
|
+
AccountSignerMeta<TAccountMaker>
|
|
81
|
+
: TAccountMaker,
|
|
82
|
+
TAccountTokenProgram extends string
|
|
83
|
+
? ReadonlyAccount<TAccountTokenProgram>
|
|
84
|
+
: TAccountTokenProgram,
|
|
85
|
+
...TRemainingAccounts,
|
|
86
|
+
]
|
|
87
|
+
>;
|
|
88
|
+
|
|
89
|
+
export type ClaimPremiumInstructionData = { discriminator: ReadonlyUint8Array };
|
|
90
|
+
|
|
91
|
+
export type ClaimPremiumInstructionDataArgs = {};
|
|
92
|
+
|
|
93
|
+
export function getClaimPremiumInstructionDataEncoder(): FixedSizeEncoder<ClaimPremiumInstructionDataArgs> {
|
|
94
|
+
return transformEncoder(
|
|
95
|
+
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
|
96
|
+
(value) => ({ ...value, discriminator: CLAIM_PREMIUM_DISCRIMINATOR }),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getClaimPremiumInstructionDataDecoder(): FixedSizeDecoder<ClaimPremiumInstructionData> {
|
|
101
|
+
return getStructDecoder([
|
|
102
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function getClaimPremiumInstructionDataCodec(): FixedSizeCodec<
|
|
107
|
+
ClaimPremiumInstructionDataArgs,
|
|
108
|
+
ClaimPremiumInstructionData
|
|
109
|
+
> {
|
|
110
|
+
return combineCodec(
|
|
111
|
+
getClaimPremiumInstructionDataEncoder(),
|
|
112
|
+
getClaimPremiumInstructionDataDecoder(),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type ClaimPremiumAsyncInput<
|
|
117
|
+
TAccountOptionPool extends string = string,
|
|
118
|
+
TAccountMakerPoolShare extends string = string,
|
|
119
|
+
TAccountMakerPaymentAccount extends string = string,
|
|
120
|
+
TAccountPremiumVault extends string = string,
|
|
121
|
+
TAccountMaker extends string = string,
|
|
122
|
+
TAccountTokenProgram extends string = string,
|
|
123
|
+
> = {
|
|
124
|
+
/** The pool */
|
|
125
|
+
optionPool: Address<TAccountOptionPool>;
|
|
126
|
+
/** Maker's share account */
|
|
127
|
+
makerPoolShare?: Address<TAccountMakerPoolShare>;
|
|
128
|
+
/** Maker's account to receive premium (in underlying asset) */
|
|
129
|
+
makerPaymentAccount: Address<TAccountMakerPaymentAccount>;
|
|
130
|
+
/** Pool's premium vault (source of premium) */
|
|
131
|
+
premiumVault: Address<TAccountPremiumVault>;
|
|
132
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
133
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export async function getClaimPremiumInstructionAsync<
|
|
137
|
+
TAccountOptionPool extends string,
|
|
138
|
+
TAccountMakerPoolShare extends string,
|
|
139
|
+
TAccountMakerPaymentAccount extends string,
|
|
140
|
+
TAccountPremiumVault extends string,
|
|
141
|
+
TAccountMaker extends string,
|
|
142
|
+
TAccountTokenProgram extends string,
|
|
143
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
144
|
+
>(
|
|
145
|
+
input: ClaimPremiumAsyncInput<
|
|
146
|
+
TAccountOptionPool,
|
|
147
|
+
TAccountMakerPoolShare,
|
|
148
|
+
TAccountMakerPaymentAccount,
|
|
149
|
+
TAccountPremiumVault,
|
|
150
|
+
TAccountMaker,
|
|
151
|
+
TAccountTokenProgram
|
|
152
|
+
>,
|
|
153
|
+
config?: { programAddress?: TProgramAddress },
|
|
154
|
+
): Promise<
|
|
155
|
+
ClaimPremiumInstruction<
|
|
156
|
+
TProgramAddress,
|
|
157
|
+
TAccountOptionPool,
|
|
158
|
+
TAccountMakerPoolShare,
|
|
159
|
+
TAccountMakerPaymentAccount,
|
|
160
|
+
TAccountPremiumVault,
|
|
161
|
+
TAccountMaker,
|
|
162
|
+
TAccountTokenProgram
|
|
163
|
+
>
|
|
164
|
+
> {
|
|
165
|
+
// Program address.
|
|
166
|
+
const programAddress =
|
|
167
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
168
|
+
|
|
169
|
+
// Original accounts.
|
|
170
|
+
const originalAccounts = {
|
|
171
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
172
|
+
makerPoolShare: { value: input.makerPoolShare ?? null, isWritable: true },
|
|
173
|
+
makerPaymentAccount: {
|
|
174
|
+
value: input.makerPaymentAccount ?? null,
|
|
175
|
+
isWritable: true,
|
|
176
|
+
},
|
|
177
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
178
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
179
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
180
|
+
};
|
|
181
|
+
const accounts = originalAccounts as Record<
|
|
182
|
+
keyof typeof originalAccounts,
|
|
183
|
+
ResolvedAccount
|
|
184
|
+
>;
|
|
185
|
+
|
|
186
|
+
// Resolve default values.
|
|
187
|
+
if (!accounts.makerPoolShare.value) {
|
|
188
|
+
accounts.makerPoolShare.value = await getProgramDerivedAddress({
|
|
189
|
+
programAddress,
|
|
190
|
+
seeds: [
|
|
191
|
+
getBytesEncoder().encode(
|
|
192
|
+
new Uint8Array([
|
|
193
|
+
109, 97, 107, 101, 114, 95, 112, 111, 111, 108, 95, 115, 104, 97,
|
|
194
|
+
114, 101,
|
|
195
|
+
]),
|
|
196
|
+
),
|
|
197
|
+
getAddressEncoder().encode(expectAddress(accounts.optionPool.value)),
|
|
198
|
+
getAddressEncoder().encode(expectAddress(accounts.maker.value)),
|
|
199
|
+
],
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (!accounts.tokenProgram.value) {
|
|
203
|
+
accounts.tokenProgram.value =
|
|
204
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
208
|
+
return Object.freeze({
|
|
209
|
+
accounts: [
|
|
210
|
+
getAccountMeta(accounts.optionPool),
|
|
211
|
+
getAccountMeta(accounts.makerPoolShare),
|
|
212
|
+
getAccountMeta(accounts.makerPaymentAccount),
|
|
213
|
+
getAccountMeta(accounts.premiumVault),
|
|
214
|
+
getAccountMeta(accounts.maker),
|
|
215
|
+
getAccountMeta(accounts.tokenProgram),
|
|
216
|
+
],
|
|
217
|
+
data: getClaimPremiumInstructionDataEncoder().encode({}),
|
|
218
|
+
programAddress,
|
|
219
|
+
} as ClaimPremiumInstruction<
|
|
220
|
+
TProgramAddress,
|
|
221
|
+
TAccountOptionPool,
|
|
222
|
+
TAccountMakerPoolShare,
|
|
223
|
+
TAccountMakerPaymentAccount,
|
|
224
|
+
TAccountPremiumVault,
|
|
225
|
+
TAccountMaker,
|
|
226
|
+
TAccountTokenProgram
|
|
227
|
+
>);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export type ClaimPremiumInput<
|
|
231
|
+
TAccountOptionPool extends string = string,
|
|
232
|
+
TAccountMakerPoolShare extends string = string,
|
|
233
|
+
TAccountMakerPaymentAccount extends string = string,
|
|
234
|
+
TAccountPremiumVault extends string = string,
|
|
235
|
+
TAccountMaker extends string = string,
|
|
236
|
+
TAccountTokenProgram extends string = string,
|
|
237
|
+
> = {
|
|
238
|
+
/** The pool */
|
|
239
|
+
optionPool: Address<TAccountOptionPool>;
|
|
240
|
+
/** Maker's share account */
|
|
241
|
+
makerPoolShare: Address<TAccountMakerPoolShare>;
|
|
242
|
+
/** Maker's account to receive premium (in underlying asset) */
|
|
243
|
+
makerPaymentAccount: Address<TAccountMakerPaymentAccount>;
|
|
244
|
+
/** Pool's premium vault (source of premium) */
|
|
245
|
+
premiumVault: Address<TAccountPremiumVault>;
|
|
246
|
+
maker: TransactionSigner<TAccountMaker>;
|
|
247
|
+
tokenProgram?: Address<TAccountTokenProgram>;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export function getClaimPremiumInstruction<
|
|
251
|
+
TAccountOptionPool extends string,
|
|
252
|
+
TAccountMakerPoolShare extends string,
|
|
253
|
+
TAccountMakerPaymentAccount extends string,
|
|
254
|
+
TAccountPremiumVault extends string,
|
|
255
|
+
TAccountMaker extends string,
|
|
256
|
+
TAccountTokenProgram extends string,
|
|
257
|
+
TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
258
|
+
>(
|
|
259
|
+
input: ClaimPremiumInput<
|
|
260
|
+
TAccountOptionPool,
|
|
261
|
+
TAccountMakerPoolShare,
|
|
262
|
+
TAccountMakerPaymentAccount,
|
|
263
|
+
TAccountPremiumVault,
|
|
264
|
+
TAccountMaker,
|
|
265
|
+
TAccountTokenProgram
|
|
266
|
+
>,
|
|
267
|
+
config?: { programAddress?: TProgramAddress },
|
|
268
|
+
): ClaimPremiumInstruction<
|
|
269
|
+
TProgramAddress,
|
|
270
|
+
TAccountOptionPool,
|
|
271
|
+
TAccountMakerPoolShare,
|
|
272
|
+
TAccountMakerPaymentAccount,
|
|
273
|
+
TAccountPremiumVault,
|
|
274
|
+
TAccountMaker,
|
|
275
|
+
TAccountTokenProgram
|
|
276
|
+
> {
|
|
277
|
+
// Program address.
|
|
278
|
+
const programAddress =
|
|
279
|
+
config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
|
|
280
|
+
|
|
281
|
+
// Original accounts.
|
|
282
|
+
const originalAccounts = {
|
|
283
|
+
optionPool: { value: input.optionPool ?? null, isWritable: true },
|
|
284
|
+
makerPoolShare: { value: input.makerPoolShare ?? null, isWritable: true },
|
|
285
|
+
makerPaymentAccount: {
|
|
286
|
+
value: input.makerPaymentAccount ?? null,
|
|
287
|
+
isWritable: true,
|
|
288
|
+
},
|
|
289
|
+
premiumVault: { value: input.premiumVault ?? null, isWritable: true },
|
|
290
|
+
maker: { value: input.maker ?? null, isWritable: true },
|
|
291
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
292
|
+
};
|
|
293
|
+
const accounts = originalAccounts as Record<
|
|
294
|
+
keyof typeof originalAccounts,
|
|
295
|
+
ResolvedAccount
|
|
296
|
+
>;
|
|
297
|
+
|
|
298
|
+
// Resolve default values.
|
|
299
|
+
if (!accounts.tokenProgram.value) {
|
|
300
|
+
accounts.tokenProgram.value =
|
|
301
|
+
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
|
305
|
+
return Object.freeze({
|
|
306
|
+
accounts: [
|
|
307
|
+
getAccountMeta(accounts.optionPool),
|
|
308
|
+
getAccountMeta(accounts.makerPoolShare),
|
|
309
|
+
getAccountMeta(accounts.makerPaymentAccount),
|
|
310
|
+
getAccountMeta(accounts.premiumVault),
|
|
311
|
+
getAccountMeta(accounts.maker),
|
|
312
|
+
getAccountMeta(accounts.tokenProgram),
|
|
313
|
+
],
|
|
314
|
+
data: getClaimPremiumInstructionDataEncoder().encode({}),
|
|
315
|
+
programAddress,
|
|
316
|
+
} as ClaimPremiumInstruction<
|
|
317
|
+
TProgramAddress,
|
|
318
|
+
TAccountOptionPool,
|
|
319
|
+
TAccountMakerPoolShare,
|
|
320
|
+
TAccountMakerPaymentAccount,
|
|
321
|
+
TAccountPremiumVault,
|
|
322
|
+
TAccountMaker,
|
|
323
|
+
TAccountTokenProgram
|
|
324
|
+
>);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export type ParsedClaimPremiumInstruction<
|
|
328
|
+
TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
|
|
329
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
330
|
+
> = {
|
|
331
|
+
programAddress: Address<TProgram>;
|
|
332
|
+
accounts: {
|
|
333
|
+
/** The pool */
|
|
334
|
+
optionPool: TAccountMetas[0];
|
|
335
|
+
/** Maker's share account */
|
|
336
|
+
makerPoolShare: TAccountMetas[1];
|
|
337
|
+
/** Maker's account to receive premium (in underlying asset) */
|
|
338
|
+
makerPaymentAccount: TAccountMetas[2];
|
|
339
|
+
/** Pool's premium vault (source of premium) */
|
|
340
|
+
premiumVault: TAccountMetas[3];
|
|
341
|
+
maker: TAccountMetas[4];
|
|
342
|
+
tokenProgram: TAccountMetas[5];
|
|
343
|
+
};
|
|
344
|
+
data: ClaimPremiumInstructionData;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
export function parseClaimPremiumInstruction<
|
|
348
|
+
TProgram extends string,
|
|
349
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
350
|
+
>(
|
|
351
|
+
instruction: Instruction<TProgram> &
|
|
352
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
353
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
354
|
+
): ParsedClaimPremiumInstruction<TProgram, TAccountMetas> {
|
|
355
|
+
if (instruction.accounts.length < 6) {
|
|
356
|
+
// TODO: Coded error.
|
|
357
|
+
throw new Error("Not enough accounts");
|
|
358
|
+
}
|
|
359
|
+
let accountIndex = 0;
|
|
360
|
+
const getNextAccount = () => {
|
|
361
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
362
|
+
accountIndex += 1;
|
|
363
|
+
return accountMeta;
|
|
364
|
+
};
|
|
365
|
+
return {
|
|
366
|
+
programAddress: instruction.programAddress,
|
|
367
|
+
accounts: {
|
|
368
|
+
optionPool: getNextAccount(),
|
|
369
|
+
makerPoolShare: getNextAccount(),
|
|
370
|
+
makerPaymentAccount: getNextAccount(),
|
|
371
|
+
premiumVault: getNextAccount(),
|
|
372
|
+
maker: getNextAccount(),
|
|
373
|
+
tokenProgram: getNextAccount(),
|
|
374
|
+
},
|
|
375
|
+
data: getClaimPremiumInstructionDataDecoder().decode(instruction.data),
|
|
376
|
+
};
|
|
377
|
+
}
|