@epicentral/sos-sdk 0.11.0-beta → 0.11.1-beta
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/index.ts +3 -1
- package/package.json +1 -1
- package/shared/option-program-parser.ts +317 -0
package/index.ts
CHANGED
|
@@ -5,9 +5,11 @@ export { OptionType } from "./generated/types";
|
|
|
5
5
|
|
|
6
6
|
export type { OptionAccount } from "./generated/accounts/optionAccount";
|
|
7
7
|
export {
|
|
8
|
+
identifyOptionProgramInstruction,
|
|
8
9
|
OptionProgramInstruction,
|
|
9
|
-
|
|
10
|
+
type ParsedOptionProgramInstruction,
|
|
10
11
|
} from "./generated/programs/optionProgram";
|
|
12
|
+
export { parseOptionProgramInstruction } from "./shared/option-program-parser";
|
|
11
13
|
|
|
12
14
|
export * from "./accounts/pdas";
|
|
13
15
|
export * from "./accounts/fetchers";
|
package/package.json
CHANGED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AccountMeta,
|
|
3
|
+
Instruction,
|
|
4
|
+
InstructionWithAccounts,
|
|
5
|
+
InstructionWithData,
|
|
6
|
+
ReadonlyUint8Array,
|
|
7
|
+
} from "@solana/kit";
|
|
8
|
+
import {
|
|
9
|
+
parseAcceptAdminInstruction,
|
|
10
|
+
parseAutoExerciseAllExpiredInstruction,
|
|
11
|
+
parseAutoExerciseExpiredInstruction,
|
|
12
|
+
parseBorrowFromPoolInstruction,
|
|
13
|
+
parseBuyFromPoolInstruction,
|
|
14
|
+
parseClaimBuyerSettlementInstruction,
|
|
15
|
+
parseClaimMakerRemainingInstruction,
|
|
16
|
+
parseClaimMakerSettlementInstruction,
|
|
17
|
+
parseCloseLongToPoolInstruction,
|
|
18
|
+
parseCloseOptionInstruction,
|
|
19
|
+
parseCreateEscrowV2Instruction,
|
|
20
|
+
parseDepositCollateralInstruction,
|
|
21
|
+
parseDepositToPositionInstruction,
|
|
22
|
+
parseInitCollateralPoolInstruction,
|
|
23
|
+
parseInitConfigInstruction,
|
|
24
|
+
parseInitializeMarketDataInstruction,
|
|
25
|
+
parseInitOptionPoolInstruction,
|
|
26
|
+
parseLiquidateWriterPositionInstruction,
|
|
27
|
+
parseLiquidateWriterPositionRescueInstruction,
|
|
28
|
+
parseMigrateCollateralPoolV1ToV2Instruction,
|
|
29
|
+
parseOmlpCreateVaultInstruction,
|
|
30
|
+
parseOmlpUpdateFeeWalletInstruction,
|
|
31
|
+
parseOmlpUpdateInterestModelInstruction,
|
|
32
|
+
parseOmlpUpdateLiquidationThresholdInstruction,
|
|
33
|
+
parseOmlpUpdateMaintenanceBufferInstruction,
|
|
34
|
+
parseOmlpUpdateMaxBorrowCapInstruction,
|
|
35
|
+
parseOmlpUpdateMaxLeverageInstruction,
|
|
36
|
+
parseOmlpUpdateProtocolFeeInstruction,
|
|
37
|
+
parseOmlpUpdateSupplyLimitInstruction,
|
|
38
|
+
parseOptionExerciseInstruction,
|
|
39
|
+
parseOptionMintInstruction,
|
|
40
|
+
parseOptionValidateInstruction,
|
|
41
|
+
parsePrepareBuyerSettlementInstruction,
|
|
42
|
+
parsePrepareMakerSettlementInstruction,
|
|
43
|
+
parseRepayPoolLoanFromCollateralInstruction,
|
|
44
|
+
parseRepayPoolLoanFromWalletInstruction,
|
|
45
|
+
parseRepayPoolLoanInstruction,
|
|
46
|
+
parseSettleMakerCollateralInstruction,
|
|
47
|
+
parseSyncWriterPositionInstruction,
|
|
48
|
+
parseTransferAdminInstruction,
|
|
49
|
+
parseUnwindWriterUnsoldInstruction,
|
|
50
|
+
parseUpdateImpliedVolatilityInstruction,
|
|
51
|
+
parseUpdateMarketDataInstruction,
|
|
52
|
+
parseWithdrawFromPositionInstruction,
|
|
53
|
+
parseWriteToPoolInstruction,
|
|
54
|
+
} from "../generated/instructions";
|
|
55
|
+
import {
|
|
56
|
+
identifyOptionProgramInstruction,
|
|
57
|
+
OptionProgramInstruction,
|
|
58
|
+
type ParsedOptionProgramInstruction,
|
|
59
|
+
} from "../generated/programs/optionProgram";
|
|
60
|
+
|
|
61
|
+
type OptionProgramInstructionInput<
|
|
62
|
+
TProgram extends string,
|
|
63
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
64
|
+
> = Instruction<TProgram> &
|
|
65
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
66
|
+
InstructionWithData<ReadonlyUint8Array>;
|
|
67
|
+
|
|
68
|
+
function withInstructionType<TProgram extends string>(
|
|
69
|
+
parsed: Omit<ParsedOptionProgramInstruction<TProgram>, "instructionType">,
|
|
70
|
+
instructionType: ParsedOptionProgramInstruction<TProgram>["instructionType"],
|
|
71
|
+
): ParsedOptionProgramInstruction<TProgram> {
|
|
72
|
+
return {
|
|
73
|
+
instructionType,
|
|
74
|
+
...parsed,
|
|
75
|
+
} as ParsedOptionProgramInstruction<TProgram>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function parseOptionProgramInstruction<
|
|
79
|
+
TProgram extends string,
|
|
80
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
81
|
+
>(
|
|
82
|
+
instruction: OptionProgramInstructionInput<TProgram, TAccountMetas>,
|
|
83
|
+
): ParsedOptionProgramInstruction<TProgram> {
|
|
84
|
+
const instructionType = identifyOptionProgramInstruction(instruction);
|
|
85
|
+
|
|
86
|
+
switch (instructionType) {
|
|
87
|
+
case OptionProgramInstruction.AcceptAdmin:
|
|
88
|
+
return withInstructionType(
|
|
89
|
+
parseAcceptAdminInstruction(instruction),
|
|
90
|
+
instructionType,
|
|
91
|
+
);
|
|
92
|
+
case OptionProgramInstruction.AutoExerciseAllExpired:
|
|
93
|
+
return withInstructionType(
|
|
94
|
+
parseAutoExerciseAllExpiredInstruction(instruction),
|
|
95
|
+
instructionType,
|
|
96
|
+
);
|
|
97
|
+
case OptionProgramInstruction.AutoExerciseExpired:
|
|
98
|
+
return withInstructionType(
|
|
99
|
+
parseAutoExerciseExpiredInstruction(instruction),
|
|
100
|
+
instructionType,
|
|
101
|
+
);
|
|
102
|
+
case OptionProgramInstruction.BorrowFromPool:
|
|
103
|
+
return withInstructionType(
|
|
104
|
+
parseBorrowFromPoolInstruction(instruction),
|
|
105
|
+
instructionType,
|
|
106
|
+
);
|
|
107
|
+
case OptionProgramInstruction.BuyFromPool:
|
|
108
|
+
return withInstructionType(
|
|
109
|
+
parseBuyFromPoolInstruction(instruction),
|
|
110
|
+
instructionType,
|
|
111
|
+
);
|
|
112
|
+
case OptionProgramInstruction.ClaimBuyerSettlement:
|
|
113
|
+
return withInstructionType(
|
|
114
|
+
parseClaimBuyerSettlementInstruction(instruction),
|
|
115
|
+
instructionType,
|
|
116
|
+
);
|
|
117
|
+
case OptionProgramInstruction.ClaimMakerRemaining:
|
|
118
|
+
return withInstructionType(
|
|
119
|
+
parseClaimMakerRemainingInstruction(instruction),
|
|
120
|
+
instructionType,
|
|
121
|
+
);
|
|
122
|
+
case OptionProgramInstruction.ClaimMakerSettlement:
|
|
123
|
+
return withInstructionType(
|
|
124
|
+
parseClaimMakerSettlementInstruction(instruction),
|
|
125
|
+
instructionType,
|
|
126
|
+
);
|
|
127
|
+
case OptionProgramInstruction.CloseLongToPool:
|
|
128
|
+
return withInstructionType(
|
|
129
|
+
parseCloseLongToPoolInstruction(instruction),
|
|
130
|
+
instructionType,
|
|
131
|
+
);
|
|
132
|
+
case OptionProgramInstruction.CloseOption:
|
|
133
|
+
return withInstructionType(
|
|
134
|
+
parseCloseOptionInstruction(instruction),
|
|
135
|
+
instructionType,
|
|
136
|
+
);
|
|
137
|
+
case OptionProgramInstruction.CreateEscrowV2:
|
|
138
|
+
return withInstructionType(
|
|
139
|
+
parseCreateEscrowV2Instruction(instruction),
|
|
140
|
+
instructionType,
|
|
141
|
+
);
|
|
142
|
+
case OptionProgramInstruction.DepositCollateral:
|
|
143
|
+
return withInstructionType(
|
|
144
|
+
parseDepositCollateralInstruction(instruction),
|
|
145
|
+
instructionType,
|
|
146
|
+
);
|
|
147
|
+
case OptionProgramInstruction.DepositToPosition:
|
|
148
|
+
return withInstructionType(
|
|
149
|
+
parseDepositToPositionInstruction(instruction),
|
|
150
|
+
instructionType,
|
|
151
|
+
);
|
|
152
|
+
case OptionProgramInstruction.InitCollateralPool:
|
|
153
|
+
return withInstructionType(
|
|
154
|
+
parseInitCollateralPoolInstruction(instruction),
|
|
155
|
+
instructionType,
|
|
156
|
+
);
|
|
157
|
+
case OptionProgramInstruction.InitConfig:
|
|
158
|
+
return withInstructionType(
|
|
159
|
+
parseInitConfigInstruction(instruction),
|
|
160
|
+
instructionType,
|
|
161
|
+
);
|
|
162
|
+
case OptionProgramInstruction.InitOptionPool:
|
|
163
|
+
return withInstructionType(
|
|
164
|
+
parseInitOptionPoolInstruction(instruction),
|
|
165
|
+
instructionType,
|
|
166
|
+
);
|
|
167
|
+
case OptionProgramInstruction.InitializeMarketData:
|
|
168
|
+
return withInstructionType(
|
|
169
|
+
parseInitializeMarketDataInstruction(instruction),
|
|
170
|
+
instructionType,
|
|
171
|
+
);
|
|
172
|
+
case OptionProgramInstruction.LiquidateWriterPosition:
|
|
173
|
+
return withInstructionType(
|
|
174
|
+
parseLiquidateWriterPositionInstruction(instruction),
|
|
175
|
+
instructionType,
|
|
176
|
+
);
|
|
177
|
+
case OptionProgramInstruction.LiquidateWriterPositionRescue:
|
|
178
|
+
return withInstructionType(
|
|
179
|
+
parseLiquidateWriterPositionRescueInstruction(instruction),
|
|
180
|
+
instructionType,
|
|
181
|
+
);
|
|
182
|
+
case OptionProgramInstruction.MigrateCollateralPoolV1ToV2:
|
|
183
|
+
return withInstructionType(
|
|
184
|
+
parseMigrateCollateralPoolV1ToV2Instruction(instruction),
|
|
185
|
+
instructionType,
|
|
186
|
+
);
|
|
187
|
+
case OptionProgramInstruction.OmlpCreateVault:
|
|
188
|
+
return withInstructionType(
|
|
189
|
+
parseOmlpCreateVaultInstruction(instruction),
|
|
190
|
+
instructionType,
|
|
191
|
+
);
|
|
192
|
+
case OptionProgramInstruction.OmlpUpdateFeeWallet:
|
|
193
|
+
return withInstructionType(
|
|
194
|
+
parseOmlpUpdateFeeWalletInstruction(instruction),
|
|
195
|
+
instructionType,
|
|
196
|
+
);
|
|
197
|
+
case OptionProgramInstruction.OmlpUpdateInterestModel:
|
|
198
|
+
return withInstructionType(
|
|
199
|
+
parseOmlpUpdateInterestModelInstruction(instruction),
|
|
200
|
+
instructionType,
|
|
201
|
+
);
|
|
202
|
+
case OptionProgramInstruction.OmlpUpdateLiquidationThreshold:
|
|
203
|
+
return withInstructionType(
|
|
204
|
+
parseOmlpUpdateLiquidationThresholdInstruction(instruction),
|
|
205
|
+
instructionType,
|
|
206
|
+
);
|
|
207
|
+
case OptionProgramInstruction.OmlpUpdateMaintenanceBuffer:
|
|
208
|
+
return withInstructionType(
|
|
209
|
+
parseOmlpUpdateMaintenanceBufferInstruction(instruction),
|
|
210
|
+
instructionType,
|
|
211
|
+
);
|
|
212
|
+
case OptionProgramInstruction.OmlpUpdateMaxBorrowCap:
|
|
213
|
+
return withInstructionType(
|
|
214
|
+
parseOmlpUpdateMaxBorrowCapInstruction(instruction),
|
|
215
|
+
instructionType,
|
|
216
|
+
);
|
|
217
|
+
case OptionProgramInstruction.OmlpUpdateMaxLeverage:
|
|
218
|
+
return withInstructionType(
|
|
219
|
+
parseOmlpUpdateMaxLeverageInstruction(instruction),
|
|
220
|
+
instructionType,
|
|
221
|
+
);
|
|
222
|
+
case OptionProgramInstruction.OmlpUpdateProtocolFee:
|
|
223
|
+
return withInstructionType(
|
|
224
|
+
parseOmlpUpdateProtocolFeeInstruction(instruction),
|
|
225
|
+
instructionType,
|
|
226
|
+
);
|
|
227
|
+
case OptionProgramInstruction.OmlpUpdateSupplyLimit:
|
|
228
|
+
return withInstructionType(
|
|
229
|
+
parseOmlpUpdateSupplyLimitInstruction(instruction),
|
|
230
|
+
instructionType,
|
|
231
|
+
);
|
|
232
|
+
case OptionProgramInstruction.OptionExercise:
|
|
233
|
+
return withInstructionType(
|
|
234
|
+
parseOptionExerciseInstruction(instruction),
|
|
235
|
+
instructionType,
|
|
236
|
+
);
|
|
237
|
+
case OptionProgramInstruction.OptionMint:
|
|
238
|
+
return withInstructionType(
|
|
239
|
+
parseOptionMintInstruction(instruction),
|
|
240
|
+
instructionType,
|
|
241
|
+
);
|
|
242
|
+
case OptionProgramInstruction.OptionValidate:
|
|
243
|
+
return withInstructionType(
|
|
244
|
+
parseOptionValidateInstruction(instruction),
|
|
245
|
+
instructionType,
|
|
246
|
+
);
|
|
247
|
+
case OptionProgramInstruction.PrepareBuyerSettlement:
|
|
248
|
+
return withInstructionType(
|
|
249
|
+
parsePrepareBuyerSettlementInstruction(instruction),
|
|
250
|
+
instructionType,
|
|
251
|
+
);
|
|
252
|
+
case OptionProgramInstruction.PrepareMakerSettlement:
|
|
253
|
+
return withInstructionType(
|
|
254
|
+
parsePrepareMakerSettlementInstruction(instruction),
|
|
255
|
+
instructionType,
|
|
256
|
+
);
|
|
257
|
+
case OptionProgramInstruction.RepayPoolLoan:
|
|
258
|
+
return withInstructionType(
|
|
259
|
+
parseRepayPoolLoanInstruction(instruction),
|
|
260
|
+
instructionType,
|
|
261
|
+
);
|
|
262
|
+
case OptionProgramInstruction.RepayPoolLoanFromCollateral:
|
|
263
|
+
return withInstructionType(
|
|
264
|
+
parseRepayPoolLoanFromCollateralInstruction(instruction),
|
|
265
|
+
instructionType,
|
|
266
|
+
);
|
|
267
|
+
case OptionProgramInstruction.RepayPoolLoanFromWallet:
|
|
268
|
+
return withInstructionType(
|
|
269
|
+
parseRepayPoolLoanFromWalletInstruction(instruction),
|
|
270
|
+
instructionType,
|
|
271
|
+
);
|
|
272
|
+
case OptionProgramInstruction.SettleMakerCollateral:
|
|
273
|
+
return withInstructionType(
|
|
274
|
+
parseSettleMakerCollateralInstruction(instruction),
|
|
275
|
+
instructionType,
|
|
276
|
+
);
|
|
277
|
+
case OptionProgramInstruction.SyncWriterPosition:
|
|
278
|
+
return withInstructionType(
|
|
279
|
+
parseSyncWriterPositionInstruction(instruction),
|
|
280
|
+
instructionType,
|
|
281
|
+
);
|
|
282
|
+
case OptionProgramInstruction.TransferAdmin:
|
|
283
|
+
return withInstructionType(
|
|
284
|
+
parseTransferAdminInstruction(instruction),
|
|
285
|
+
instructionType,
|
|
286
|
+
);
|
|
287
|
+
case OptionProgramInstruction.UnwindWriterUnsold:
|
|
288
|
+
return withInstructionType(
|
|
289
|
+
parseUnwindWriterUnsoldInstruction(instruction),
|
|
290
|
+
instructionType,
|
|
291
|
+
);
|
|
292
|
+
case OptionProgramInstruction.UpdateImpliedVolatility:
|
|
293
|
+
return withInstructionType(
|
|
294
|
+
parseUpdateImpliedVolatilityInstruction(instruction),
|
|
295
|
+
instructionType,
|
|
296
|
+
);
|
|
297
|
+
case OptionProgramInstruction.UpdateMarketData:
|
|
298
|
+
return withInstructionType(
|
|
299
|
+
parseUpdateMarketDataInstruction(instruction),
|
|
300
|
+
instructionType,
|
|
301
|
+
);
|
|
302
|
+
case OptionProgramInstruction.WithdrawFromPosition:
|
|
303
|
+
return withInstructionType(
|
|
304
|
+
parseWithdrawFromPositionInstruction(instruction),
|
|
305
|
+
instructionType,
|
|
306
|
+
);
|
|
307
|
+
case OptionProgramInstruction.WriteToPool:
|
|
308
|
+
return withInstructionType(
|
|
309
|
+
parseWriteToPoolInstruction(instruction),
|
|
310
|
+
instructionType,
|
|
311
|
+
);
|
|
312
|
+
default: {
|
|
313
|
+
const exhaustiveCheck: never = instructionType;
|
|
314
|
+
throw new Error(`Unsupported option program instruction: ${exhaustiveCheck}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|