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