@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,235 @@
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
+ getStructDecoder,
16
+ getStructEncoder,
17
+ transformEncoder,
18
+ type AccountMeta,
19
+ type AccountSignerMeta,
20
+ type Address,
21
+ type FixedSizeCodec,
22
+ type FixedSizeDecoder,
23
+ type FixedSizeEncoder,
24
+ type Instruction,
25
+ type InstructionWithAccounts,
26
+ type InstructionWithData,
27
+ type ReadonlyAccount,
28
+ type ReadonlyUint8Array,
29
+ type TransactionSigner,
30
+ type WritableAccount,
31
+ type WritableSignerAccount,
32
+ } from "@solana/kit";
33
+ import { OPTION_PROGRAM_PROGRAM_ADDRESS } from "../programs";
34
+ import { getAccountMetaFactory, type ResolvedAccount } from "../shared";
35
+
36
+ export const CLOSE_OPTION_DISCRIMINATOR = new Uint8Array([
37
+ 138, 79, 53, 54, 221, 16, 109, 141,
38
+ ]);
39
+
40
+ export function getCloseOptionDiscriminatorBytes() {
41
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
42
+ CLOSE_OPTION_DISCRIMINATOR,
43
+ );
44
+ }
45
+
46
+ export type CloseOptionInstruction<
47
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
48
+ TAccountOptionAccount extends string | AccountMeta<string> = string,
49
+ TAccountOptionMint extends string | AccountMeta<string> = string,
50
+ TAccountMakerOptionAccount extends string | AccountMeta<string> = string,
51
+ TAccountMaker extends string | AccountMeta<string> = string,
52
+ TAccountTokenProgram extends string | AccountMeta<string> =
53
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
54
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
55
+ > = Instruction<TProgram> &
56
+ InstructionWithData<ReadonlyUint8Array> &
57
+ InstructionWithAccounts<
58
+ [
59
+ TAccountOptionAccount extends string
60
+ ? WritableAccount<TAccountOptionAccount>
61
+ : TAccountOptionAccount,
62
+ TAccountOptionMint extends string
63
+ ? WritableAccount<TAccountOptionMint>
64
+ : TAccountOptionMint,
65
+ TAccountMakerOptionAccount extends string
66
+ ? WritableAccount<TAccountMakerOptionAccount>
67
+ : TAccountMakerOptionAccount,
68
+ TAccountMaker extends string
69
+ ? WritableSignerAccount<TAccountMaker> &
70
+ AccountSignerMeta<TAccountMaker>
71
+ : TAccountMaker,
72
+ TAccountTokenProgram extends string
73
+ ? ReadonlyAccount<TAccountTokenProgram>
74
+ : TAccountTokenProgram,
75
+ ...TRemainingAccounts,
76
+ ]
77
+ >;
78
+
79
+ export type CloseOptionInstructionData = { discriminator: ReadonlyUint8Array };
80
+
81
+ export type CloseOptionInstructionDataArgs = {};
82
+
83
+ export function getCloseOptionInstructionDataEncoder(): FixedSizeEncoder<CloseOptionInstructionDataArgs> {
84
+ return transformEncoder(
85
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
86
+ (value) => ({ ...value, discriminator: CLOSE_OPTION_DISCRIMINATOR }),
87
+ );
88
+ }
89
+
90
+ export function getCloseOptionInstructionDataDecoder(): FixedSizeDecoder<CloseOptionInstructionData> {
91
+ return getStructDecoder([
92
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
93
+ ]);
94
+ }
95
+
96
+ export function getCloseOptionInstructionDataCodec(): FixedSizeCodec<
97
+ CloseOptionInstructionDataArgs,
98
+ CloseOptionInstructionData
99
+ > {
100
+ return combineCodec(
101
+ getCloseOptionInstructionDataEncoder(),
102
+ getCloseOptionInstructionDataDecoder(),
103
+ );
104
+ }
105
+
106
+ export type CloseOptionInput<
107
+ TAccountOptionAccount extends string = string,
108
+ TAccountOptionMint extends string = string,
109
+ TAccountMakerOptionAccount extends string = string,
110
+ TAccountMaker extends string = string,
111
+ TAccountTokenProgram extends string = string,
112
+ > = {
113
+ optionAccount: Address<TAccountOptionAccount>;
114
+ optionMint: Address<TAccountOptionMint>;
115
+ makerOptionAccount: Address<TAccountMakerOptionAccount>;
116
+ maker: TransactionSigner<TAccountMaker>;
117
+ tokenProgram?: Address<TAccountTokenProgram>;
118
+ };
119
+
120
+ export function getCloseOptionInstruction<
121
+ TAccountOptionAccount extends string,
122
+ TAccountOptionMint extends string,
123
+ TAccountMakerOptionAccount extends string,
124
+ TAccountMaker extends string,
125
+ TAccountTokenProgram extends string,
126
+ TProgramAddress extends Address = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
127
+ >(
128
+ input: CloseOptionInput<
129
+ TAccountOptionAccount,
130
+ TAccountOptionMint,
131
+ TAccountMakerOptionAccount,
132
+ TAccountMaker,
133
+ TAccountTokenProgram
134
+ >,
135
+ config?: { programAddress?: TProgramAddress },
136
+ ): CloseOptionInstruction<
137
+ TProgramAddress,
138
+ TAccountOptionAccount,
139
+ TAccountOptionMint,
140
+ TAccountMakerOptionAccount,
141
+ TAccountMaker,
142
+ TAccountTokenProgram
143
+ > {
144
+ // Program address.
145
+ const programAddress =
146
+ config?.programAddress ?? OPTION_PROGRAM_PROGRAM_ADDRESS;
147
+
148
+ // Original accounts.
149
+ const originalAccounts = {
150
+ optionAccount: { value: input.optionAccount ?? null, isWritable: true },
151
+ optionMint: { value: input.optionMint ?? null, isWritable: true },
152
+ makerOptionAccount: {
153
+ value: input.makerOptionAccount ?? null,
154
+ isWritable: true,
155
+ },
156
+ maker: { value: input.maker ?? null, isWritable: true },
157
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
158
+ };
159
+ const accounts = originalAccounts as Record<
160
+ keyof typeof originalAccounts,
161
+ ResolvedAccount
162
+ >;
163
+
164
+ // Resolve default values.
165
+ if (!accounts.tokenProgram.value) {
166
+ accounts.tokenProgram.value =
167
+ "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">;
168
+ }
169
+
170
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
171
+ return Object.freeze({
172
+ accounts: [
173
+ getAccountMeta(accounts.optionAccount),
174
+ getAccountMeta(accounts.optionMint),
175
+ getAccountMeta(accounts.makerOptionAccount),
176
+ getAccountMeta(accounts.maker),
177
+ getAccountMeta(accounts.tokenProgram),
178
+ ],
179
+ data: getCloseOptionInstructionDataEncoder().encode({}),
180
+ programAddress,
181
+ } as CloseOptionInstruction<
182
+ TProgramAddress,
183
+ TAccountOptionAccount,
184
+ TAccountOptionMint,
185
+ TAccountMakerOptionAccount,
186
+ TAccountMaker,
187
+ TAccountTokenProgram
188
+ >);
189
+ }
190
+
191
+ export type ParsedCloseOptionInstruction<
192
+ TProgram extends string = typeof OPTION_PROGRAM_PROGRAM_ADDRESS,
193
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
194
+ > = {
195
+ programAddress: Address<TProgram>;
196
+ accounts: {
197
+ optionAccount: TAccountMetas[0];
198
+ optionMint: TAccountMetas[1];
199
+ makerOptionAccount: TAccountMetas[2];
200
+ maker: TAccountMetas[3];
201
+ tokenProgram: TAccountMetas[4];
202
+ };
203
+ data: CloseOptionInstructionData;
204
+ };
205
+
206
+ export function parseCloseOptionInstruction<
207
+ TProgram extends string,
208
+ TAccountMetas extends readonly AccountMeta[],
209
+ >(
210
+ instruction: Instruction<TProgram> &
211
+ InstructionWithAccounts<TAccountMetas> &
212
+ InstructionWithData<ReadonlyUint8Array>,
213
+ ): ParsedCloseOptionInstruction<TProgram, TAccountMetas> {
214
+ if (instruction.accounts.length < 5) {
215
+ // TODO: Coded error.
216
+ throw new Error("Not enough accounts");
217
+ }
218
+ let accountIndex = 0;
219
+ const getNextAccount = () => {
220
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
221
+ accountIndex += 1;
222
+ return accountMeta;
223
+ };
224
+ return {
225
+ programAddress: instruction.programAddress,
226
+ accounts: {
227
+ optionAccount: getNextAccount(),
228
+ optionMint: getNextAccount(),
229
+ makerOptionAccount: getNextAccount(),
230
+ maker: getNextAccount(),
231
+ tokenProgram: getNextAccount(),
232
+ },
233
+ data: getCloseOptionInstructionDataDecoder().decode(instruction.data),
234
+ };
235
+ }