@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,279 @@
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
+ transformEncoder,
19
+ type AccountMeta,
20
+ type AccountSignerMeta,
21
+ type Address,
22
+ type FixedSizeCodec,
23
+ type FixedSizeDecoder,
24
+ type FixedSizeEncoder,
25
+ type Instruction,
26
+ type InstructionWithAccounts,
27
+ type InstructionWithData,
28
+ type ReadonlyAccount,
29
+ type ReadonlyUint8Array,
30
+ type TransactionSigner,
31
+ type WritableAccount,
32
+ type WritableSignerAccount,
33
+ } from "@solana/kit";
34
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
35
+ import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
36
+
37
+ export const INIT_CONFIG_DISCRIMINATOR = new Uint8Array([
38
+ 23, 235, 115, 232, 168, 96, 1, 231,
39
+ ]);
40
+
41
+ export function getInitConfigDiscriminatorBytes() {
42
+ return fixEncoderSize(getBytesEncoder(), 8).encode(INIT_CONFIG_DISCRIMINATOR);
43
+ }
44
+
45
+ export type InitConfigInstruction<
46
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
47
+ TAccountConfig extends string | AccountMeta<string> = string,
48
+ TAccountInitializer extends string | AccountMeta<string> = string,
49
+ TAccountSystemProgram extends string | AccountMeta<string> =
50
+ "11111111111111111111111111111111",
51
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
52
+ > = Instruction<TProgram> &
53
+ InstructionWithData<ReadonlyUint8Array> &
54
+ InstructionWithAccounts<
55
+ [
56
+ TAccountConfig extends string
57
+ ? WritableAccount<TAccountConfig>
58
+ : TAccountConfig,
59
+ TAccountInitializer extends string
60
+ ? WritableSignerAccount<TAccountInitializer> &
61
+ AccountSignerMeta<TAccountInitializer>
62
+ : TAccountInitializer,
63
+ TAccountSystemProgram extends string
64
+ ? ReadonlyAccount<TAccountSystemProgram>
65
+ : TAccountSystemProgram,
66
+ ...TRemainingAccounts,
67
+ ]
68
+ >;
69
+
70
+ export type InitConfigInstructionData = { discriminator: ReadonlyUint8Array };
71
+
72
+ export type InitConfigInstructionDataArgs = {};
73
+
74
+ export function getInitConfigInstructionDataEncoder(): FixedSizeEncoder<InitConfigInstructionDataArgs> {
75
+ return transformEncoder(
76
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
77
+ (value) => ({ ...value, discriminator: INIT_CONFIG_DISCRIMINATOR }),
78
+ );
79
+ }
80
+
81
+ export function getInitConfigInstructionDataDecoder(): FixedSizeDecoder<InitConfigInstructionData> {
82
+ return getStructDecoder([
83
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
84
+ ]);
85
+ }
86
+
87
+ export function getInitConfigInstructionDataCodec(): FixedSizeCodec<
88
+ InitConfigInstructionDataArgs,
89
+ InitConfigInstructionData
90
+ > {
91
+ return combineCodec(
92
+ getInitConfigInstructionDataEncoder(),
93
+ getInitConfigInstructionDataDecoder(),
94
+ );
95
+ }
96
+
97
+ export type InitConfigAsyncInput<
98
+ TAccountConfig extends string = string,
99
+ TAccountInitializer extends string = string,
100
+ TAccountSystemProgram extends string = string,
101
+ > = {
102
+ config?: Address<TAccountConfig>;
103
+ initializer: TransactionSigner<TAccountInitializer>;
104
+ systemProgram?: Address<TAccountSystemProgram>;
105
+ };
106
+
107
+ export async function getInitConfigInstructionAsync<
108
+ TAccountConfig extends string,
109
+ TAccountInitializer extends string,
110
+ TAccountSystemProgram extends string,
111
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
112
+ >(
113
+ input: InitConfigAsyncInput<
114
+ TAccountConfig,
115
+ TAccountInitializer,
116
+ TAccountSystemProgram
117
+ >,
118
+ config?: { programAddress?: TProgramAddress },
119
+ ): Promise<
120
+ InitConfigInstruction<
121
+ TProgramAddress,
122
+ TAccountConfig,
123
+ TAccountInitializer,
124
+ TAccountSystemProgram
125
+ >
126
+ > {
127
+ // Program address.
128
+ const programAddress =
129
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
130
+
131
+ // Original accounts.
132
+ const originalAccounts = {
133
+ config: { value: input.config ?? null, isWritable: true },
134
+ initializer: { value: input.initializer ?? null, isWritable: true },
135
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
136
+ };
137
+ const accounts = originalAccounts as Record<
138
+ keyof typeof originalAccounts,
139
+ ResolvedAccount
140
+ >;
141
+
142
+ // Resolve default values.
143
+ if (!accounts.config.value) {
144
+ accounts.config.value = await getProgramDerivedAddress({
145
+ programAddress,
146
+ seeds: [
147
+ getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103])),
148
+ ],
149
+ });
150
+ }
151
+ if (!accounts.systemProgram.value) {
152
+ accounts.systemProgram.value =
153
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
154
+ }
155
+
156
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
157
+ return Object.freeze({
158
+ accounts: [
159
+ getAccountMeta(accounts.config),
160
+ getAccountMeta(accounts.initializer),
161
+ getAccountMeta(accounts.systemProgram),
162
+ ],
163
+ data: getInitConfigInstructionDataEncoder().encode({}),
164
+ programAddress,
165
+ } as InitConfigInstruction<
166
+ TProgramAddress,
167
+ TAccountConfig,
168
+ TAccountInitializer,
169
+ TAccountSystemProgram
170
+ >);
171
+ }
172
+
173
+ export type InitConfigInput<
174
+ TAccountConfig extends string = string,
175
+ TAccountInitializer extends string = string,
176
+ TAccountSystemProgram extends string = string,
177
+ > = {
178
+ config: Address<TAccountConfig>;
179
+ initializer: TransactionSigner<TAccountInitializer>;
180
+ systemProgram?: Address<TAccountSystemProgram>;
181
+ };
182
+
183
+ export function getInitConfigInstruction<
184
+ TAccountConfig extends string,
185
+ TAccountInitializer extends string,
186
+ TAccountSystemProgram extends string,
187
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
188
+ >(
189
+ input: InitConfigInput<
190
+ TAccountConfig,
191
+ TAccountInitializer,
192
+ TAccountSystemProgram
193
+ >,
194
+ config?: { programAddress?: TProgramAddress },
195
+ ): InitConfigInstruction<
196
+ TProgramAddress,
197
+ TAccountConfig,
198
+ TAccountInitializer,
199
+ TAccountSystemProgram
200
+ > {
201
+ // Program address.
202
+ const programAddress =
203
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
204
+
205
+ // Original accounts.
206
+ const originalAccounts = {
207
+ config: { value: input.config ?? null, isWritable: true },
208
+ initializer: { value: input.initializer ?? null, isWritable: true },
209
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
210
+ };
211
+ const accounts = originalAccounts as Record<
212
+ keyof typeof originalAccounts,
213
+ ResolvedAccount
214
+ >;
215
+
216
+ // Resolve default values.
217
+ if (!accounts.systemProgram.value) {
218
+ accounts.systemProgram.value =
219
+ "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
220
+ }
221
+
222
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
223
+ return Object.freeze({
224
+ accounts: [
225
+ getAccountMeta(accounts.config),
226
+ getAccountMeta(accounts.initializer),
227
+ getAccountMeta(accounts.systemProgram),
228
+ ],
229
+ data: getInitConfigInstructionDataEncoder().encode({}),
230
+ programAddress,
231
+ } as InitConfigInstruction<
232
+ TProgramAddress,
233
+ TAccountConfig,
234
+ TAccountInitializer,
235
+ TAccountSystemProgram
236
+ >);
237
+ }
238
+
239
+ export type ParsedInitConfigInstruction<
240
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
241
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
242
+ > = {
243
+ programAddress: Address<TProgram>;
244
+ accounts: {
245
+ config: TAccountMetas[0];
246
+ initializer: TAccountMetas[1];
247
+ systemProgram: TAccountMetas[2];
248
+ };
249
+ data: InitConfigInstructionData;
250
+ };
251
+
252
+ export function parseInitConfigInstruction<
253
+ TProgram extends string,
254
+ TAccountMetas extends readonly AccountMeta[],
255
+ >(
256
+ instruction: Instruction<TProgram> &
257
+ InstructionWithAccounts<TAccountMetas> &
258
+ InstructionWithData<ReadonlyUint8Array>,
259
+ ): ParsedInitConfigInstruction<TProgram, TAccountMetas> {
260
+ if (instruction.accounts.length < 3) {
261
+ // TODO: Coded error.
262
+ throw new Error("Not enough accounts");
263
+ }
264
+ let accountIndex = 0;
265
+ const getNextAccount = () => {
266
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
267
+ accountIndex += 1;
268
+ return accountMeta;
269
+ };
270
+ return {
271
+ programAddress: instruction.programAddress,
272
+ accounts: {
273
+ config: getNextAccount(),
274
+ initializer: getNextAccount(),
275
+ systemProgram: getNextAccount(),
276
+ },
277
+ data: getInitConfigInstructionDataDecoder().decode(instruction.data),
278
+ };
279
+ }