@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.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +239 -0
  3. package/accounts/fetchers.ts +140 -0
  4. package/accounts/list.ts +152 -0
  5. package/accounts/pdas.ts +308 -0
  6. package/client/lookup-table.ts +32 -0
  7. package/client/program.ts +13 -0
  8. package/client/types.ts +8 -0
  9. package/generated/accounts/collateralPool.ts +217 -0
  10. package/generated/accounts/config.ts +156 -0
  11. package/generated/accounts/dualSourceContract.ts +235 -0
  12. package/generated/accounts/escrowState.ts +183 -0
  13. package/generated/accounts/index.ts +24 -0
  14. package/generated/accounts/lenderPosition.ts +211 -0
  15. package/generated/accounts/liquidityRouter.ts +223 -0
  16. package/generated/accounts/makerCollateralShare.ts +229 -0
  17. package/generated/accounts/makerPoolShare.ts +203 -0
  18. package/generated/accounts/marketDataAccount.ts +176 -0
  19. package/generated/accounts/optionAccount.ts +247 -0
  20. package/generated/accounts/optionPool.ts +253 -0
  21. package/generated/accounts/poolLoan.ts +220 -0
  22. package/generated/accounts/positionAccount.ts +187 -0
  23. package/generated/accounts/priceUpdateV2.ts +163 -0
  24. package/generated/accounts/vault.ts +304 -0
  25. package/generated/accounts/writerPosition.ts +297 -0
  26. package/generated/errors/index.ts +9 -0
  27. package/generated/errors/optionProgram.ts +392 -0
  28. package/generated/index.ts +13 -0
  29. package/generated/instructions/acceptAdmin.ts +230 -0
  30. package/generated/instructions/autoExerciseAllExpired.ts +523 -0
  31. package/generated/instructions/autoExerciseExpired.ts +623 -0
  32. package/generated/instructions/borrowFromPool.ts +554 -0
  33. package/generated/instructions/buyFromPool.ts +684 -0
  34. package/generated/instructions/claimPremium.ts +377 -0
  35. package/generated/instructions/closeLongToPool.ts +716 -0
  36. package/generated/instructions/closeOption.ts +235 -0
  37. package/generated/instructions/createEscrowV2.ts +518 -0
  38. package/generated/instructions/createLiquidityRouter.ts +361 -0
  39. package/generated/instructions/depositCollateral.ts +624 -0
  40. package/generated/instructions/depositToPool.ts +497 -0
  41. package/generated/instructions/depositToPosition.ts +429 -0
  42. package/generated/instructions/index.ts +45 -0
  43. package/generated/instructions/initCollateralPool.ts +513 -0
  44. package/generated/instructions/initConfig.ts +279 -0
  45. package/generated/instructions/initOptionPool.ts +587 -0
  46. package/generated/instructions/initializeMarketData.ts +359 -0
  47. package/generated/instructions/liquidateWriterPosition.ts +592 -0
  48. package/generated/instructions/omlpCreateVault.ts +547 -0
  49. package/generated/instructions/omlpTakeOfferWithFailover.ts +606 -0
  50. package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
  51. package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
  52. package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
  53. package/generated/instructions/optionExercise.ts +540 -0
  54. package/generated/instructions/optionMint.ts +1349 -0
  55. package/generated/instructions/optionValidate.ts +255 -0
  56. package/generated/instructions/repayPoolLoan.ts +499 -0
  57. package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
  58. package/generated/instructions/settleMakerCollateral.ts +472 -0
  59. package/generated/instructions/syncWriterPosition.ts +206 -0
  60. package/generated/instructions/transferAdmin.ts +245 -0
  61. package/generated/instructions/unwindWriterUnsold.ts +668 -0
  62. package/generated/instructions/updateImpliedVolatility.ts +226 -0
  63. package/generated/instructions/updateMarketData.ts +315 -0
  64. package/generated/instructions/withdrawFromPool.ts +429 -0
  65. package/generated/instructions/withdrawFromPosition.ts +405 -0
  66. package/generated/instructions/writeToPool.ts +594 -0
  67. package/generated/programs/index.ts +9 -0
  68. package/generated/programs/optionProgram.ts +832 -0
  69. package/generated/shared/index.ts +164 -0
  70. package/generated/types/borrowedFromSAP1.ts +75 -0
  71. package/generated/types/borrowedFromSAP2.ts +83 -0
  72. package/generated/types/failoverTriggered.ts +85 -0
  73. package/generated/types/impliedVolatilityUpdated.ts +73 -0
  74. package/generated/types/index.ts +32 -0
  75. package/generated/types/liquidationExecuted.ts +73 -0
  76. package/generated/types/liquidityMetrics.ts +69 -0
  77. package/generated/types/liquidityRouterCreated.ts +79 -0
  78. package/generated/types/marketDataInitialized.ts +61 -0
  79. package/generated/types/marketDataUpdated.ts +69 -0
  80. package/generated/types/optionClosed.ts +56 -0
  81. package/generated/types/optionExercised.ts +62 -0
  82. package/generated/types/optionExpired.ts +49 -0
  83. package/generated/types/optionMinted.ts +78 -0
  84. package/generated/types/optionType.ts +38 -0
  85. package/generated/types/optionValidated.ts +82 -0
  86. package/generated/types/poolLoanCreated.ts +74 -0
  87. package/generated/types/poolLoanRepaid.ts +74 -0
  88. package/generated/types/positionDeposited.ts +73 -0
  89. package/generated/types/positionWithdrawn.ts +81 -0
  90. package/generated/types/priceFeedMessage.ts +117 -0
  91. package/generated/types/protocolFeeUpdated.ts +69 -0
  92. package/generated/types/sap2Provider.ts +38 -0
  93. package/generated/types/vaultCreated.ts +60 -0
  94. package/generated/types/verificationLevel.ts +95 -0
  95. package/index.ts +25 -0
  96. package/long/builders.ts +126 -0
  97. package/long/exercise.ts +49 -0
  98. package/long/quotes.ts +48 -0
  99. package/omlp/builders.ts +74 -0
  100. package/omlp/service.ts +94 -0
  101. package/package.json +22 -0
  102. package/shared/amounts.ts +32 -0
  103. package/shared/errors.ts +12 -0
  104. package/shared/remaining-accounts.ts +41 -0
  105. package/shared/transactions.ts +49 -0
  106. package/short/builders.ts +268 -0
  107. package/short/claim-premium.ts +37 -0
  108. package/short/close-option.ts +34 -0
  109. package/short/pool.ts +224 -0
  110. package/tsconfig.json +12 -0
@@ -0,0 +1,304 @@
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
+ getBytesDecoder,
14
+ getBytesEncoder,
15
+ getProgramDerivedAddress,
16
+ getStructDecoder,
17
+ getStructEncoder,
18
+ getU64Decoder,
19
+ getU64Encoder,
20
+ transformEncoder,
21
+ type AccountMeta,
22
+ type AccountSignerMeta,
23
+ type Address,
24
+ type FixedSizeCodec,
25
+ type FixedSizeDecoder,
26
+ type FixedSizeEncoder,
27
+ type Instruction,
28
+ type InstructionWithAccounts,
29
+ type InstructionWithData,
30
+ type ReadonlyAccount,
31
+ type ReadonlySignerAccount,
32
+ type ReadonlyUint8Array,
33
+ type TransactionSigner,
34
+ type WritableAccount,
35
+ } from "@solana/kit";
36
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
37
+ import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
38
+
39
+ export const OMLP_UPDATE_SUPPLY_LIMIT_DISCRIMINATOR = new Uint8Array([
40
+ 38, 178, 193, 188, 127, 170, 122, 42,
41
+ ]);
42
+
43
+ export function getOmlpUpdateSupplyLimitDiscriminatorBytes() {
44
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
45
+ OMLP_UPDATE_SUPPLY_LIMIT_DISCRIMINATOR,
46
+ );
47
+ }
48
+
49
+ export type OmlpUpdateSupplyLimitInstruction<
50
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
51
+ TAccountConfig extends string | AccountMeta<string> = string,
52
+ TAccountVault extends string | AccountMeta<string> = string,
53
+ TAccountAdmin extends string | AccountMeta<string> = string,
54
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
55
+ > = Instruction<TProgram> &
56
+ InstructionWithData<ReadonlyUint8Array> &
57
+ InstructionWithAccounts<
58
+ [
59
+ TAccountConfig extends string
60
+ ? ReadonlyAccount<TAccountConfig>
61
+ : TAccountConfig,
62
+ TAccountVault extends string
63
+ ? WritableAccount<TAccountVault>
64
+ : TAccountVault,
65
+ TAccountAdmin extends string
66
+ ? ReadonlySignerAccount<TAccountAdmin> &
67
+ AccountSignerMeta<TAccountAdmin>
68
+ : TAccountAdmin,
69
+ ...TRemainingAccounts,
70
+ ]
71
+ >;
72
+
73
+ export type OmlpUpdateSupplyLimitInstructionData = {
74
+ discriminator: ReadonlyUint8Array;
75
+ newSupplyLimit: bigint;
76
+ };
77
+
78
+ export type OmlpUpdateSupplyLimitInstructionDataArgs = {
79
+ newSupplyLimit: number | bigint;
80
+ };
81
+
82
+ export function getOmlpUpdateSupplyLimitInstructionDataEncoder(): FixedSizeEncoder<OmlpUpdateSupplyLimitInstructionDataArgs> {
83
+ return transformEncoder(
84
+ getStructEncoder([
85
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
86
+ ["newSupplyLimit", getU64Encoder()],
87
+ ]),
88
+ (value) => ({
89
+ ...value,
90
+ discriminator: OMLP_UPDATE_SUPPLY_LIMIT_DISCRIMINATOR,
91
+ }),
92
+ );
93
+ }
94
+
95
+ export function getOmlpUpdateSupplyLimitInstructionDataDecoder(): FixedSizeDecoder<OmlpUpdateSupplyLimitInstructionData> {
96
+ return getStructDecoder([
97
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
98
+ ["newSupplyLimit", getU64Decoder()],
99
+ ]);
100
+ }
101
+
102
+ export function getOmlpUpdateSupplyLimitInstructionDataCodec(): FixedSizeCodec<
103
+ OmlpUpdateSupplyLimitInstructionDataArgs,
104
+ OmlpUpdateSupplyLimitInstructionData
105
+ > {
106
+ return combineCodec(
107
+ getOmlpUpdateSupplyLimitInstructionDataEncoder(),
108
+ getOmlpUpdateSupplyLimitInstructionDataDecoder(),
109
+ );
110
+ }
111
+
112
+ export type OmlpUpdateSupplyLimitAsyncInput<
113
+ TAccountConfig extends string = string,
114
+ TAccountVault extends string = string,
115
+ TAccountAdmin extends string = string,
116
+ > = {
117
+ /** Protocol config - stores admin authority */
118
+ config?: Address<TAccountConfig>;
119
+ vault: Address<TAccountVault>;
120
+ /** Admin signer - must match config.admin */
121
+ admin: TransactionSigner<TAccountAdmin>;
122
+ newSupplyLimit: OmlpUpdateSupplyLimitInstructionDataArgs["newSupplyLimit"];
123
+ };
124
+
125
+ export async function getOmlpUpdateSupplyLimitInstructionAsync<
126
+ TAccountConfig extends string,
127
+ TAccountVault extends string,
128
+ TAccountAdmin extends string,
129
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
130
+ >(
131
+ input: OmlpUpdateSupplyLimitAsyncInput<
132
+ TAccountConfig,
133
+ TAccountVault,
134
+ TAccountAdmin
135
+ >,
136
+ config?: { programAddress?: TProgramAddress },
137
+ ): Promise<
138
+ OmlpUpdateSupplyLimitInstruction<
139
+ TProgramAddress,
140
+ TAccountConfig,
141
+ TAccountVault,
142
+ TAccountAdmin
143
+ >
144
+ > {
145
+ // Program address.
146
+ const programAddress =
147
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
148
+
149
+ // Original accounts.
150
+ const originalAccounts = {
151
+ config: { value: input.config ?? null, isWritable: false },
152
+ vault: { value: input.vault ?? null, isWritable: true },
153
+ admin: { value: input.admin ?? null, isWritable: false },
154
+ };
155
+ const accounts = originalAccounts as Record<
156
+ keyof typeof originalAccounts,
157
+ ResolvedAccount
158
+ >;
159
+
160
+ // Original args.
161
+ const args = { ...input };
162
+
163
+ // Resolve default values.
164
+ if (!accounts.config.value) {
165
+ accounts.config.value = await getProgramDerivedAddress({
166
+ programAddress,
167
+ seeds: [
168
+ getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103])),
169
+ ],
170
+ });
171
+ }
172
+
173
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
174
+ return Object.freeze({
175
+ accounts: [
176
+ getAccountMeta(accounts.config),
177
+ getAccountMeta(accounts.vault),
178
+ getAccountMeta(accounts.admin),
179
+ ],
180
+ data: getOmlpUpdateSupplyLimitInstructionDataEncoder().encode(
181
+ args as OmlpUpdateSupplyLimitInstructionDataArgs,
182
+ ),
183
+ programAddress,
184
+ } as OmlpUpdateSupplyLimitInstruction<
185
+ TProgramAddress,
186
+ TAccountConfig,
187
+ TAccountVault,
188
+ TAccountAdmin
189
+ >);
190
+ }
191
+
192
+ export type OmlpUpdateSupplyLimitInput<
193
+ TAccountConfig extends string = string,
194
+ TAccountVault extends string = string,
195
+ TAccountAdmin extends string = string,
196
+ > = {
197
+ /** Protocol config - stores admin authority */
198
+ config: Address<TAccountConfig>;
199
+ vault: Address<TAccountVault>;
200
+ /** Admin signer - must match config.admin */
201
+ admin: TransactionSigner<TAccountAdmin>;
202
+ newSupplyLimit: OmlpUpdateSupplyLimitInstructionDataArgs["newSupplyLimit"];
203
+ };
204
+
205
+ export function getOmlpUpdateSupplyLimitInstruction<
206
+ TAccountConfig extends string,
207
+ TAccountVault extends string,
208
+ TAccountAdmin extends string,
209
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
210
+ >(
211
+ input: OmlpUpdateSupplyLimitInput<
212
+ TAccountConfig,
213
+ TAccountVault,
214
+ TAccountAdmin
215
+ >,
216
+ config?: { programAddress?: TProgramAddress },
217
+ ): OmlpUpdateSupplyLimitInstruction<
218
+ TProgramAddress,
219
+ TAccountConfig,
220
+ TAccountVault,
221
+ TAccountAdmin
222
+ > {
223
+ // Program address.
224
+ const programAddress =
225
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
226
+
227
+ // Original accounts.
228
+ const originalAccounts = {
229
+ config: { value: input.config ?? null, isWritable: false },
230
+ vault: { value: input.vault ?? null, isWritable: true },
231
+ admin: { value: input.admin ?? null, isWritable: false },
232
+ };
233
+ const accounts = originalAccounts as Record<
234
+ keyof typeof originalAccounts,
235
+ ResolvedAccount
236
+ >;
237
+
238
+ // Original args.
239
+ const args = { ...input };
240
+
241
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
242
+ return Object.freeze({
243
+ accounts: [
244
+ getAccountMeta(accounts.config),
245
+ getAccountMeta(accounts.vault),
246
+ getAccountMeta(accounts.admin),
247
+ ],
248
+ data: getOmlpUpdateSupplyLimitInstructionDataEncoder().encode(
249
+ args as OmlpUpdateSupplyLimitInstructionDataArgs,
250
+ ),
251
+ programAddress,
252
+ } as OmlpUpdateSupplyLimitInstruction<
253
+ TProgramAddress,
254
+ TAccountConfig,
255
+ TAccountVault,
256
+ TAccountAdmin
257
+ >);
258
+ }
259
+
260
+ export type ParsedOmlpUpdateSupplyLimitInstruction<
261
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
262
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
263
+ > = {
264
+ programAddress: Address<TProgram>;
265
+ accounts: {
266
+ /** Protocol config - stores admin authority */
267
+ config: TAccountMetas[0];
268
+ vault: TAccountMetas[1];
269
+ /** Admin signer - must match config.admin */
270
+ admin: TAccountMetas[2];
271
+ };
272
+ data: OmlpUpdateSupplyLimitInstructionData;
273
+ };
274
+
275
+ export function parseOmlpUpdateSupplyLimitInstruction<
276
+ TProgram extends string,
277
+ TAccountMetas extends readonly AccountMeta[],
278
+ >(
279
+ instruction: Instruction<TProgram> &
280
+ InstructionWithAccounts<TAccountMetas> &
281
+ InstructionWithData<ReadonlyUint8Array>,
282
+ ): ParsedOmlpUpdateSupplyLimitInstruction<TProgram, TAccountMetas> {
283
+ if (instruction.accounts.length < 3) {
284
+ // TODO: Coded error.
285
+ throw new Error("Not enough accounts");
286
+ }
287
+ let accountIndex = 0;
288
+ const getNextAccount = () => {
289
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
290
+ accountIndex += 1;
291
+ return accountMeta;
292
+ };
293
+ return {
294
+ programAddress: instruction.programAddress,
295
+ accounts: {
296
+ config: getNextAccount(),
297
+ vault: getNextAccount(),
298
+ admin: getNextAccount(),
299
+ },
300
+ data: getOmlpUpdateSupplyLimitInstructionDataDecoder().decode(
301
+ instruction.data,
302
+ ),
303
+ };
304
+ }