@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,297 @@
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
+ assertAccountExists,
11
+ assertAccountsExist,
12
+ combineCodec,
13
+ decodeAccount,
14
+ fetchEncodedAccount,
15
+ fetchEncodedAccounts,
16
+ fixDecoderSize,
17
+ fixEncoderSize,
18
+ getAddressDecoder,
19
+ getAddressEncoder,
20
+ getBooleanDecoder,
21
+ getBooleanEncoder,
22
+ getBytesDecoder,
23
+ getBytesEncoder,
24
+ getI64Decoder,
25
+ getI64Encoder,
26
+ getStructDecoder,
27
+ getStructEncoder,
28
+ getU128Decoder,
29
+ getU128Encoder,
30
+ getU64Decoder,
31
+ getU64Encoder,
32
+ getU8Decoder,
33
+ getU8Encoder,
34
+ transformEncoder,
35
+ type Account,
36
+ type Address,
37
+ type EncodedAccount,
38
+ type FetchAccountConfig,
39
+ type FetchAccountsConfig,
40
+ type FixedSizeCodec,
41
+ type FixedSizeDecoder,
42
+ type FixedSizeEncoder,
43
+ type MaybeAccount,
44
+ type MaybeEncodedAccount,
45
+ type ReadonlyUint8Array,
46
+ } from "@solana/kit";
47
+
48
+ export const WRITER_POSITION_DISCRIMINATOR = new Uint8Array([
49
+ 195, 252, 56, 77, 221, 13, 8, 69,
50
+ ]);
51
+
52
+ export function getWriterPositionDiscriminatorBytes() {
53
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
54
+ WRITER_POSITION_DISCRIMINATOR,
55
+ );
56
+ }
57
+
58
+ export type WriterPosition = {
59
+ discriminator: ReadonlyUint8Array;
60
+ /** The writer's wallet address */
61
+ writerAuthority: Address;
62
+ /** Reference to the option pool */
63
+ optionPool: Address;
64
+ /** Reference to the option account */
65
+ optionAccount: Address;
66
+ /** Total contracts written (minted) by this writer */
67
+ writtenQty: bigint;
68
+ /** Total contracts sold to buyers (open interest from this writer) */
69
+ soldQty: bigint;
70
+ /** Contracts still available for sale (written_qty - sold_qty - withdrawn_qty) */
71
+ unsoldQty: bigint;
72
+ /** Total contracts withdrawn (unwound before selling) */
73
+ withdrawnQty: bigint;
74
+ /** Writer's own collateral deposited */
75
+ collateralDeposited: bigint;
76
+ /** Total borrowed from OMLP vault */
77
+ borrowedPrincipal: bigint;
78
+ /** Number of active PoolLoan accounts for this writer */
79
+ activeLoanCount: number;
80
+ /** Total premium earned from sales */
81
+ premiumEarned: bigint;
82
+ /** Premium already claimed/withdrawn */
83
+ premiumClaimed: bigint;
84
+ /** Snapshot of pool's acc_closed_per_oi_fp at last sync */
85
+ lastPoolAccClosedFp: bigint;
86
+ /** Snapshot of pool's acc_payout_per_oi_fp at last sync */
87
+ lastPoolAccPayoutFp: bigint;
88
+ /** Accumulated closed qty debt (for lazy settlement calc) */
89
+ closedQtyDebtFp: bigint;
90
+ /** Accumulated payout debt (for lazy settlement calc) */
91
+ payoutDebtFp: bigint;
92
+ /** Total payout to buyers from this writer's collateral */
93
+ totalBuyerPayout: bigint;
94
+ /** Total repaid to OMLP lenders (principal + interest + fees) */
95
+ totalLenderRepaid: bigint;
96
+ /** Total collateral returned to writer */
97
+ totalCollateralReturned: bigint;
98
+ /** Realized PnL (positive = profit, negative = loss) */
99
+ realizedPnl: bigint;
100
+ /** True if position is fully settled (all loans repaid, collateral returned) */
101
+ isSettled: boolean;
102
+ /** True if position was liquidated */
103
+ isLiquidated: boolean;
104
+ createdAt: bigint;
105
+ lastUpdated: bigint;
106
+ bump: number;
107
+ };
108
+
109
+ export type WriterPositionArgs = {
110
+ /** The writer's wallet address */
111
+ writerAuthority: Address;
112
+ /** Reference to the option pool */
113
+ optionPool: Address;
114
+ /** Reference to the option account */
115
+ optionAccount: Address;
116
+ /** Total contracts written (minted) by this writer */
117
+ writtenQty: number | bigint;
118
+ /** Total contracts sold to buyers (open interest from this writer) */
119
+ soldQty: number | bigint;
120
+ /** Contracts still available for sale (written_qty - sold_qty - withdrawn_qty) */
121
+ unsoldQty: number | bigint;
122
+ /** Total contracts withdrawn (unwound before selling) */
123
+ withdrawnQty: number | bigint;
124
+ /** Writer's own collateral deposited */
125
+ collateralDeposited: number | bigint;
126
+ /** Total borrowed from OMLP vault */
127
+ borrowedPrincipal: number | bigint;
128
+ /** Number of active PoolLoan accounts for this writer */
129
+ activeLoanCount: number;
130
+ /** Total premium earned from sales */
131
+ premiumEarned: number | bigint;
132
+ /** Premium already claimed/withdrawn */
133
+ premiumClaimed: number | bigint;
134
+ /** Snapshot of pool's acc_closed_per_oi_fp at last sync */
135
+ lastPoolAccClosedFp: number | bigint;
136
+ /** Snapshot of pool's acc_payout_per_oi_fp at last sync */
137
+ lastPoolAccPayoutFp: number | bigint;
138
+ /** Accumulated closed qty debt (for lazy settlement calc) */
139
+ closedQtyDebtFp: number | bigint;
140
+ /** Accumulated payout debt (for lazy settlement calc) */
141
+ payoutDebtFp: number | bigint;
142
+ /** Total payout to buyers from this writer's collateral */
143
+ totalBuyerPayout: number | bigint;
144
+ /** Total repaid to OMLP lenders (principal + interest + fees) */
145
+ totalLenderRepaid: number | bigint;
146
+ /** Total collateral returned to writer */
147
+ totalCollateralReturned: number | bigint;
148
+ /** Realized PnL (positive = profit, negative = loss) */
149
+ realizedPnl: number | bigint;
150
+ /** True if position is fully settled (all loans repaid, collateral returned) */
151
+ isSettled: boolean;
152
+ /** True if position was liquidated */
153
+ isLiquidated: boolean;
154
+ createdAt: number | bigint;
155
+ lastUpdated: number | bigint;
156
+ bump: number;
157
+ };
158
+
159
+ /** Gets the encoder for {@link WriterPositionArgs} account data. */
160
+ export function getWriterPositionEncoder(): FixedSizeEncoder<WriterPositionArgs> {
161
+ return transformEncoder(
162
+ getStructEncoder([
163
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
164
+ ["writerAuthority", getAddressEncoder()],
165
+ ["optionPool", getAddressEncoder()],
166
+ ["optionAccount", getAddressEncoder()],
167
+ ["writtenQty", getU64Encoder()],
168
+ ["soldQty", getU64Encoder()],
169
+ ["unsoldQty", getU64Encoder()],
170
+ ["withdrawnQty", getU64Encoder()],
171
+ ["collateralDeposited", getU64Encoder()],
172
+ ["borrowedPrincipal", getU64Encoder()],
173
+ ["activeLoanCount", getU8Encoder()],
174
+ ["premiumEarned", getU64Encoder()],
175
+ ["premiumClaimed", getU64Encoder()],
176
+ ["lastPoolAccClosedFp", getU128Encoder()],
177
+ ["lastPoolAccPayoutFp", getU128Encoder()],
178
+ ["closedQtyDebtFp", getU128Encoder()],
179
+ ["payoutDebtFp", getU128Encoder()],
180
+ ["totalBuyerPayout", getU64Encoder()],
181
+ ["totalLenderRepaid", getU64Encoder()],
182
+ ["totalCollateralReturned", getU64Encoder()],
183
+ ["realizedPnl", getI64Encoder()],
184
+ ["isSettled", getBooleanEncoder()],
185
+ ["isLiquidated", getBooleanEncoder()],
186
+ ["createdAt", getI64Encoder()],
187
+ ["lastUpdated", getI64Encoder()],
188
+ ["bump", getU8Encoder()],
189
+ ]),
190
+ (value) => ({ ...value, discriminator: WRITER_POSITION_DISCRIMINATOR }),
191
+ );
192
+ }
193
+
194
+ /** Gets the decoder for {@link WriterPosition} account data. */
195
+ export function getWriterPositionDecoder(): FixedSizeDecoder<WriterPosition> {
196
+ return getStructDecoder([
197
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
198
+ ["writerAuthority", getAddressDecoder()],
199
+ ["optionPool", getAddressDecoder()],
200
+ ["optionAccount", getAddressDecoder()],
201
+ ["writtenQty", getU64Decoder()],
202
+ ["soldQty", getU64Decoder()],
203
+ ["unsoldQty", getU64Decoder()],
204
+ ["withdrawnQty", getU64Decoder()],
205
+ ["collateralDeposited", getU64Decoder()],
206
+ ["borrowedPrincipal", getU64Decoder()],
207
+ ["activeLoanCount", getU8Decoder()],
208
+ ["premiumEarned", getU64Decoder()],
209
+ ["premiumClaimed", getU64Decoder()],
210
+ ["lastPoolAccClosedFp", getU128Decoder()],
211
+ ["lastPoolAccPayoutFp", getU128Decoder()],
212
+ ["closedQtyDebtFp", getU128Decoder()],
213
+ ["payoutDebtFp", getU128Decoder()],
214
+ ["totalBuyerPayout", getU64Decoder()],
215
+ ["totalLenderRepaid", getU64Decoder()],
216
+ ["totalCollateralReturned", getU64Decoder()],
217
+ ["realizedPnl", getI64Decoder()],
218
+ ["isSettled", getBooleanDecoder()],
219
+ ["isLiquidated", getBooleanDecoder()],
220
+ ["createdAt", getI64Decoder()],
221
+ ["lastUpdated", getI64Decoder()],
222
+ ["bump", getU8Decoder()],
223
+ ]);
224
+ }
225
+
226
+ /** Gets the codec for {@link WriterPosition} account data. */
227
+ export function getWriterPositionCodec(): FixedSizeCodec<
228
+ WriterPositionArgs,
229
+ WriterPosition
230
+ > {
231
+ return combineCodec(getWriterPositionEncoder(), getWriterPositionDecoder());
232
+ }
233
+
234
+ export function decodeWriterPosition<TAddress extends string = string>(
235
+ encodedAccount: EncodedAccount<TAddress>,
236
+ ): Account<WriterPosition, TAddress>;
237
+ export function decodeWriterPosition<TAddress extends string = string>(
238
+ encodedAccount: MaybeEncodedAccount<TAddress>,
239
+ ): MaybeAccount<WriterPosition, TAddress>;
240
+ export function decodeWriterPosition<TAddress extends string = string>(
241
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
242
+ ): Account<WriterPosition, TAddress> | MaybeAccount<WriterPosition, TAddress> {
243
+ return decodeAccount(
244
+ encodedAccount as MaybeEncodedAccount<TAddress>,
245
+ getWriterPositionDecoder(),
246
+ );
247
+ }
248
+
249
+ export async function fetchWriterPosition<TAddress extends string = string>(
250
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
251
+ address: Address<TAddress>,
252
+ config?: FetchAccountConfig,
253
+ ): Promise<Account<WriterPosition, TAddress>> {
254
+ const maybeAccount = await fetchMaybeWriterPosition(rpc, address, config);
255
+ assertAccountExists(maybeAccount);
256
+ return maybeAccount;
257
+ }
258
+
259
+ export async function fetchMaybeWriterPosition<
260
+ TAddress extends string = string,
261
+ >(
262
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
263
+ address: Address<TAddress>,
264
+ config?: FetchAccountConfig,
265
+ ): Promise<MaybeAccount<WriterPosition, TAddress>> {
266
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
267
+ return decodeWriterPosition(maybeAccount);
268
+ }
269
+
270
+ export async function fetchAllWriterPosition(
271
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
272
+ addresses: Array<Address>,
273
+ config?: FetchAccountsConfig,
274
+ ): Promise<Account<WriterPosition>[]> {
275
+ const maybeAccounts = await fetchAllMaybeWriterPosition(
276
+ rpc,
277
+ addresses,
278
+ config,
279
+ );
280
+ assertAccountsExist(maybeAccounts);
281
+ return maybeAccounts;
282
+ }
283
+
284
+ export async function fetchAllMaybeWriterPosition(
285
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
286
+ addresses: Array<Address>,
287
+ config?: FetchAccountsConfig,
288
+ ): Promise<MaybeAccount<WriterPosition>[]> {
289
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
290
+ return maybeAccounts.map((maybeAccount) =>
291
+ decodeWriterPosition(maybeAccount),
292
+ );
293
+ }
294
+
295
+ export function getWriterPositionSize(): number {
296
+ return 284;
297
+ }
@@ -0,0 +1,9 @@
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
+ export * from "./optionProgram";