@epicentral/sos-sdk 0.9.0-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.
Files changed (113) hide show
  1. package/.env.example +1 -0
  2. package/AGENTS.md +7 -0
  3. package/LICENSE +21 -0
  4. package/README.md +568 -0
  5. package/accounts/fetchers.ts +196 -0
  6. package/accounts/list.ts +184 -0
  7. package/accounts/pdas.ts +325 -0
  8. package/accounts/resolve-option.ts +104 -0
  9. package/client/lookup-table.ts +114 -0
  10. package/client/program.ts +13 -0
  11. package/client/types.ts +9 -0
  12. package/generated/accounts/collateralPool.ts +217 -0
  13. package/generated/accounts/config.ts +156 -0
  14. package/generated/accounts/escrowState.ts +183 -0
  15. package/generated/accounts/index.ts +20 -0
  16. package/generated/accounts/lenderPosition.ts +211 -0
  17. package/generated/accounts/makerCollateralShare.ts +229 -0
  18. package/generated/accounts/marketDataAccount.ts +176 -0
  19. package/generated/accounts/optionAccount.ts +247 -0
  20. package/generated/accounts/optionPool.ts +285 -0
  21. package/generated/accounts/poolLoan.ts +232 -0
  22. package/generated/accounts/positionAccount.ts +201 -0
  23. package/generated/accounts/vault.ts +366 -0
  24. package/generated/accounts/writerPosition.ts +327 -0
  25. package/generated/errors/index.ts +9 -0
  26. package/generated/errors/optionProgram.ts +476 -0
  27. package/generated/index.ts +13 -0
  28. package/generated/instructions/acceptAdmin.ts +230 -0
  29. package/generated/instructions/autoExerciseAllExpired.ts +685 -0
  30. package/generated/instructions/autoExerciseExpired.ts +754 -0
  31. package/generated/instructions/borrowFromPool.ts +619 -0
  32. package/generated/instructions/buyFromPool.ts +761 -0
  33. package/generated/instructions/closeLongToPool.ts +762 -0
  34. package/generated/instructions/closeOption.ts +235 -0
  35. package/generated/instructions/createEscrowV2.ts +518 -0
  36. package/generated/instructions/depositCollateral.ts +624 -0
  37. package/generated/instructions/depositToPosition.ts +429 -0
  38. package/generated/instructions/index.ts +47 -0
  39. package/generated/instructions/initCollateralPool.ts +513 -0
  40. package/generated/instructions/initConfig.ts +279 -0
  41. package/generated/instructions/initOptionPool.ts +587 -0
  42. package/generated/instructions/initializeMarketData.ts +359 -0
  43. package/generated/instructions/liquidateWriterPosition.ts +750 -0
  44. package/generated/instructions/liquidateWriterPositionRescue.ts +623 -0
  45. package/generated/instructions/omlpCreateVault.ts +553 -0
  46. package/generated/instructions/omlpUpdateFeeWallet.ts +473 -0
  47. package/generated/instructions/omlpUpdateInterestModel.ts +322 -0
  48. package/generated/instructions/omlpUpdateLiquidationThreshold.ts +304 -0
  49. package/generated/instructions/omlpUpdateMaintenanceBuffer.ts +304 -0
  50. package/generated/instructions/omlpUpdateMaxBorrowCap.ts +304 -0
  51. package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
  52. package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
  53. package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
  54. package/generated/instructions/optionExercise.ts +617 -0
  55. package/generated/instructions/optionMint.ts +1373 -0
  56. package/generated/instructions/optionValidate.ts +302 -0
  57. package/generated/instructions/repayPoolLoan.ts +558 -0
  58. package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
  59. package/generated/instructions/repayPoolLoanFromWallet.ts +542 -0
  60. package/generated/instructions/settleMakerCollateral.ts +509 -0
  61. package/generated/instructions/syncWriterPosition.ts +206 -0
  62. package/generated/instructions/transferAdmin.ts +245 -0
  63. package/generated/instructions/unwindWriterUnsold.ts +764 -0
  64. package/generated/instructions/updateImpliedVolatility.ts +226 -0
  65. package/generated/instructions/updateMarketData.ts +315 -0
  66. package/generated/instructions/withdrawFromPosition.ts +405 -0
  67. package/generated/instructions/writeToPool.ts +619 -0
  68. package/generated/programs/index.ts +9 -0
  69. package/generated/programs/optionProgram.ts +1144 -0
  70. package/generated/shared/index.ts +164 -0
  71. package/generated/types/impliedVolatilityUpdated.ts +73 -0
  72. package/generated/types/index.ts +28 -0
  73. package/generated/types/liquidationExecuted.ts +73 -0
  74. package/generated/types/liquidationRescueEvent.ts +82 -0
  75. package/generated/types/marketDataInitialized.ts +61 -0
  76. package/generated/types/marketDataUpdated.ts +69 -0
  77. package/generated/types/optionClosed.ts +56 -0
  78. package/generated/types/optionExercised.ts +62 -0
  79. package/generated/types/optionExpired.ts +49 -0
  80. package/generated/types/optionMinted.ts +78 -0
  81. package/generated/types/optionType.ts +38 -0
  82. package/generated/types/optionValidated.ts +82 -0
  83. package/generated/types/poolLoanCreated.ts +74 -0
  84. package/generated/types/poolLoanRepaid.ts +74 -0
  85. package/generated/types/positionDeposited.ts +73 -0
  86. package/generated/types/positionWithdrawn.ts +81 -0
  87. package/generated/types/protocolFeeUpdated.ts +69 -0
  88. package/generated/types/vaultCreated.ts +60 -0
  89. package/generated/types/vaultFeeWalletUpdated.ts +67 -0
  90. package/generated/types/vaultInterestModelUpdated.ts +77 -0
  91. package/generated/types/vaultLiquidationThresholdUpdated.ts +69 -0
  92. package/index.ts +68 -0
  93. package/long/builders.ts +690 -0
  94. package/long/exercise.ts +123 -0
  95. package/long/preflight.ts +214 -0
  96. package/long/quotes.ts +48 -0
  97. package/long/remaining-accounts.ts +111 -0
  98. package/omlp/builders.ts +94 -0
  99. package/omlp/service.ts +136 -0
  100. package/oracle/switchboard.ts +315 -0
  101. package/package.json +34 -0
  102. package/shared/amounts.ts +53 -0
  103. package/shared/balances.ts +57 -0
  104. package/shared/errors.ts +12 -0
  105. package/shared/remaining-accounts.ts +41 -0
  106. package/shared/trade-config.ts +27 -0
  107. package/shared/transactions.ts +121 -0
  108. package/short/builders.ts +874 -0
  109. package/short/close-option.ts +34 -0
  110. package/short/pool.ts +189 -0
  111. package/short/preflight.ts +619 -0
  112. package/tsconfig.json +13 -0
  113. package/wsol/instructions.ts +247 -0
@@ -0,0 +1,366 @@
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
+ getBytesDecoder,
21
+ getBytesEncoder,
22
+ getI64Decoder,
23
+ getI64Encoder,
24
+ getStructDecoder,
25
+ getStructEncoder,
26
+ getU128Decoder,
27
+ getU128Encoder,
28
+ getU16Decoder,
29
+ getU16Encoder,
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 VAULT_DISCRIMINATOR = new Uint8Array([
49
+ 211, 8, 232, 43, 2, 152, 117, 119,
50
+ ]);
51
+
52
+ export function getVaultDiscriminatorBytes() {
53
+ return fixEncoderSize(getBytesEncoder(), 8).encode(VAULT_DISCRIMINATOR);
54
+ }
55
+
56
+ export type Vault = {
57
+ discriminator: ReadonlyUint8Array;
58
+ /** The mint this vault holds (SOL wrapper or USDC) */
59
+ mint: Address;
60
+ /** PDA bump */
61
+ bump: number;
62
+ /** Total liquidity deposited by lenders */
63
+ totalLiquidity: bigint;
64
+ /** Total amount currently loaned out */
65
+ totalLoans: bigint;
66
+ /**
67
+ * Protocol fee charged on borrow interest (basis points)
68
+ * Example: 200-300 bps (2-3%) on top of lender APR
69
+ */
70
+ protocolFeeBps: number;
71
+ /** Liquidation threshold (basis points) */
72
+ liqThresholdBps: number;
73
+ /**
74
+ * Maximum leverage allowed for borrowing
75
+ * Example: 1000 = 10x leverage, 10000 = 100x leverage
76
+ * Configurable by admin (1x to 100x)
77
+ */
78
+ maxLeverageMultiplier: number;
79
+ /** Keeper/admin authority */
80
+ keeper: Address;
81
+ /** Epicentral fee wallet (receives protocol fees) */
82
+ feeWallet: Address;
83
+ /** Total protocol fees accumulated (in vault's asset) */
84
+ totalProtocolFees: bigint;
85
+ /** Vault creation timestamp */
86
+ createdAt: bigint;
87
+ /** Last update timestamp */
88
+ lastUpdated: bigint;
89
+ /**
90
+ * Base borrow rate when utilization = 0% (basis points)
91
+ * Example: 500 bps = 5% base rate
92
+ */
93
+ baseRateBps: number;
94
+ /**
95
+ * Optimal utilization rate target (basis points)
96
+ * Example: 8000 = 80% optimal utilization
97
+ */
98
+ optimalUtilizationBps: number;
99
+ /**
100
+ * Rate slope below optimal utilization (basis points)
101
+ * Example: 1000 = 10% slope
102
+ */
103
+ rateSlope1Bps: number;
104
+ /**
105
+ * Rate slope above optimal utilization (basis points)
106
+ * Example: 15000 = 150% steep slope when over-utilized
107
+ */
108
+ rateSlope2Bps: number;
109
+ /**
110
+ * Fixed supply limit for this vault (in lamports/base units)
111
+ * Set by admin, enforced on deposits. 0 = unlimited.
112
+ */
113
+ supplyLimit: bigint;
114
+ /**
115
+ * Maximum aggregate borrow cap as a share of total liquidity (basis points).
116
+ * Example: 9000 = at most 90% of liquidity may be loaned out.
117
+ */
118
+ maxBorrowCapBps: number;
119
+ /**
120
+ * Cumulative interest earned per deposited unit (fixed-point)
121
+ * Increases whenever loans are repaid/liquidated
122
+ */
123
+ accInterestPerShareFp: bigint;
124
+ /** Last slot when interest index was updated */
125
+ lastInterestUpdateSlot: bigint;
126
+ /**
127
+ * Extra cushion (basis points of principal) required ON TOP of
128
+ * interest+fees when evaluating writer health.
129
+ *
130
+ * Invariant:
131
+ * free_collateral + claimable_theta
132
+ * >= accrued_interest + accrued_fees + (principal × buffer_bps / 10_000)
133
+ *
134
+ * Typical values: 0 (off) — 500 (5%).
135
+ */
136
+ maintenanceBufferBps: number;
137
+ /**
138
+ * Cumulative **full** debt shortfall (principal + protocol fees)
139
+ * socialized across lenders via the permissioned
140
+ * `liquidate_writer_position_rescue` path. Incremented when the
141
+ * standard (permissionless) liquidation cannot cover the full debt
142
+ * from `collateral + theta`, letting the keeper perform a partial
143
+ * recovery instead of reverting indefinitely.
144
+ *
145
+ * Non-zero values represent real economic loss to OMLP depositors;
146
+ * operators should monitor this field as a solvency signal.
147
+ */
148
+ badDebtLamports: bigint;
149
+ };
150
+
151
+ export type VaultArgs = {
152
+ /** The mint this vault holds (SOL wrapper or USDC) */
153
+ mint: Address;
154
+ /** PDA bump */
155
+ bump: number;
156
+ /** Total liquidity deposited by lenders */
157
+ totalLiquidity: number | bigint;
158
+ /** Total amount currently loaned out */
159
+ totalLoans: number | bigint;
160
+ /**
161
+ * Protocol fee charged on borrow interest (basis points)
162
+ * Example: 200-300 bps (2-3%) on top of lender APR
163
+ */
164
+ protocolFeeBps: number;
165
+ /** Liquidation threshold (basis points) */
166
+ liqThresholdBps: number;
167
+ /**
168
+ * Maximum leverage allowed for borrowing
169
+ * Example: 1000 = 10x leverage, 10000 = 100x leverage
170
+ * Configurable by admin (1x to 100x)
171
+ */
172
+ maxLeverageMultiplier: number;
173
+ /** Keeper/admin authority */
174
+ keeper: Address;
175
+ /** Epicentral fee wallet (receives protocol fees) */
176
+ feeWallet: Address;
177
+ /** Total protocol fees accumulated (in vault's asset) */
178
+ totalProtocolFees: number | bigint;
179
+ /** Vault creation timestamp */
180
+ createdAt: number | bigint;
181
+ /** Last update timestamp */
182
+ lastUpdated: number | bigint;
183
+ /**
184
+ * Base borrow rate when utilization = 0% (basis points)
185
+ * Example: 500 bps = 5% base rate
186
+ */
187
+ baseRateBps: number;
188
+ /**
189
+ * Optimal utilization rate target (basis points)
190
+ * Example: 8000 = 80% optimal utilization
191
+ */
192
+ optimalUtilizationBps: number;
193
+ /**
194
+ * Rate slope below optimal utilization (basis points)
195
+ * Example: 1000 = 10% slope
196
+ */
197
+ rateSlope1Bps: number;
198
+ /**
199
+ * Rate slope above optimal utilization (basis points)
200
+ * Example: 15000 = 150% steep slope when over-utilized
201
+ */
202
+ rateSlope2Bps: number;
203
+ /**
204
+ * Fixed supply limit for this vault (in lamports/base units)
205
+ * Set by admin, enforced on deposits. 0 = unlimited.
206
+ */
207
+ supplyLimit: number | bigint;
208
+ /**
209
+ * Maximum aggregate borrow cap as a share of total liquidity (basis points).
210
+ * Example: 9000 = at most 90% of liquidity may be loaned out.
211
+ */
212
+ maxBorrowCapBps: number;
213
+ /**
214
+ * Cumulative interest earned per deposited unit (fixed-point)
215
+ * Increases whenever loans are repaid/liquidated
216
+ */
217
+ accInterestPerShareFp: number | bigint;
218
+ /** Last slot when interest index was updated */
219
+ lastInterestUpdateSlot: number | bigint;
220
+ /**
221
+ * Extra cushion (basis points of principal) required ON TOP of
222
+ * interest+fees when evaluating writer health.
223
+ *
224
+ * Invariant:
225
+ * free_collateral + claimable_theta
226
+ * >= accrued_interest + accrued_fees + (principal × buffer_bps / 10_000)
227
+ *
228
+ * Typical values: 0 (off) — 500 (5%).
229
+ */
230
+ maintenanceBufferBps: number;
231
+ /**
232
+ * Cumulative **full** debt shortfall (principal + protocol fees)
233
+ * socialized across lenders via the permissioned
234
+ * `liquidate_writer_position_rescue` path. Incremented when the
235
+ * standard (permissionless) liquidation cannot cover the full debt
236
+ * from `collateral + theta`, letting the keeper perform a partial
237
+ * recovery instead of reverting indefinitely.
238
+ *
239
+ * Non-zero values represent real economic loss to OMLP depositors;
240
+ * operators should monitor this field as a solvency signal.
241
+ */
242
+ badDebtLamports: number | bigint;
243
+ };
244
+
245
+ /** Gets the encoder for {@link VaultArgs} account data. */
246
+ export function getVaultEncoder(): FixedSizeEncoder<VaultArgs> {
247
+ return transformEncoder(
248
+ getStructEncoder([
249
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
250
+ ["mint", getAddressEncoder()],
251
+ ["bump", getU8Encoder()],
252
+ ["totalLiquidity", getU64Encoder()],
253
+ ["totalLoans", getU64Encoder()],
254
+ ["protocolFeeBps", getU16Encoder()],
255
+ ["liqThresholdBps", getU16Encoder()],
256
+ ["maxLeverageMultiplier", getU16Encoder()],
257
+ ["keeper", getAddressEncoder()],
258
+ ["feeWallet", getAddressEncoder()],
259
+ ["totalProtocolFees", getU64Encoder()],
260
+ ["createdAt", getI64Encoder()],
261
+ ["lastUpdated", getI64Encoder()],
262
+ ["baseRateBps", getU16Encoder()],
263
+ ["optimalUtilizationBps", getU16Encoder()],
264
+ ["rateSlope1Bps", getU16Encoder()],
265
+ ["rateSlope2Bps", getU16Encoder()],
266
+ ["supplyLimit", getU64Encoder()],
267
+ ["maxBorrowCapBps", getU16Encoder()],
268
+ ["accInterestPerShareFp", getU128Encoder()],
269
+ ["lastInterestUpdateSlot", getU64Encoder()],
270
+ ["maintenanceBufferBps", getU16Encoder()],
271
+ ["badDebtLamports", getU64Encoder()],
272
+ ]),
273
+ (value) => ({ ...value, discriminator: VAULT_DISCRIMINATOR }),
274
+ );
275
+ }
276
+
277
+ /** Gets the decoder for {@link Vault} account data. */
278
+ export function getVaultDecoder(): FixedSizeDecoder<Vault> {
279
+ return getStructDecoder([
280
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
281
+ ["mint", getAddressDecoder()],
282
+ ["bump", getU8Decoder()],
283
+ ["totalLiquidity", getU64Decoder()],
284
+ ["totalLoans", getU64Decoder()],
285
+ ["protocolFeeBps", getU16Decoder()],
286
+ ["liqThresholdBps", getU16Decoder()],
287
+ ["maxLeverageMultiplier", getU16Decoder()],
288
+ ["keeper", getAddressDecoder()],
289
+ ["feeWallet", getAddressDecoder()],
290
+ ["totalProtocolFees", getU64Decoder()],
291
+ ["createdAt", getI64Decoder()],
292
+ ["lastUpdated", getI64Decoder()],
293
+ ["baseRateBps", getU16Decoder()],
294
+ ["optimalUtilizationBps", getU16Decoder()],
295
+ ["rateSlope1Bps", getU16Decoder()],
296
+ ["rateSlope2Bps", getU16Decoder()],
297
+ ["supplyLimit", getU64Decoder()],
298
+ ["maxBorrowCapBps", getU16Decoder()],
299
+ ["accInterestPerShareFp", getU128Decoder()],
300
+ ["lastInterestUpdateSlot", getU64Decoder()],
301
+ ["maintenanceBufferBps", getU16Decoder()],
302
+ ["badDebtLamports", getU64Decoder()],
303
+ ]);
304
+ }
305
+
306
+ /** Gets the codec for {@link Vault} account data. */
307
+ export function getVaultCodec(): FixedSizeCodec<VaultArgs, Vault> {
308
+ return combineCodec(getVaultEncoder(), getVaultDecoder());
309
+ }
310
+
311
+ export function decodeVault<TAddress extends string = string>(
312
+ encodedAccount: EncodedAccount<TAddress>,
313
+ ): Account<Vault, TAddress>;
314
+ export function decodeVault<TAddress extends string = string>(
315
+ encodedAccount: MaybeEncodedAccount<TAddress>,
316
+ ): MaybeAccount<Vault, TAddress>;
317
+ export function decodeVault<TAddress extends string = string>(
318
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
319
+ ): Account<Vault, TAddress> | MaybeAccount<Vault, TAddress> {
320
+ return decodeAccount(
321
+ encodedAccount as MaybeEncodedAccount<TAddress>,
322
+ getVaultDecoder(),
323
+ );
324
+ }
325
+
326
+ export async function fetchVault<TAddress extends string = string>(
327
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
328
+ address: Address<TAddress>,
329
+ config?: FetchAccountConfig,
330
+ ): Promise<Account<Vault, TAddress>> {
331
+ const maybeAccount = await fetchMaybeVault(rpc, address, config);
332
+ assertAccountExists(maybeAccount);
333
+ return maybeAccount;
334
+ }
335
+
336
+ export async function fetchMaybeVault<TAddress extends string = string>(
337
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
338
+ address: Address<TAddress>,
339
+ config?: FetchAccountConfig,
340
+ ): Promise<MaybeAccount<Vault, TAddress>> {
341
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
342
+ return decodeVault(maybeAccount);
343
+ }
344
+
345
+ export async function fetchAllVault(
346
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
347
+ addresses: Array<Address>,
348
+ config?: FetchAccountsConfig,
349
+ ): Promise<Account<Vault>[]> {
350
+ const maybeAccounts = await fetchAllMaybeVault(rpc, addresses, config);
351
+ assertAccountsExist(maybeAccounts);
352
+ return maybeAccounts;
353
+ }
354
+
355
+ export async function fetchAllMaybeVault(
356
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
357
+ addresses: Array<Address>,
358
+ config?: FetchAccountsConfig,
359
+ ): Promise<MaybeAccount<Vault>[]> {
360
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
361
+ return maybeAccounts.map((maybeAccount) => decodeVault(maybeAccount));
362
+ }
363
+
364
+ export function getVaultSize(): number {
365
+ return 203;
366
+ }
@@ -0,0 +1,327 @@
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
+ /**
67
+ * Mint used for collateral backing this position (e.g., USDC, BTC, SOL)
68
+ * Can differ from the underlying asset - enables multi-collateral system
69
+ */
70
+ collateralMint: Address;
71
+ /**
72
+ * Mint used for settlement (same as collateral_mint)
73
+ * Buyers receive payout in this currency
74
+ */
75
+ settlementMint: Address;
76
+ /** Total contracts written (minted) by this writer */
77
+ writtenQty: bigint;
78
+ /** Total contracts sold to buyers (open interest from this writer) */
79
+ soldQty: bigint;
80
+ /** Contracts still available for sale (written_qty - sold_qty - withdrawn_qty) */
81
+ unsoldQty: bigint;
82
+ /** Total contracts withdrawn (unwound before selling) */
83
+ withdrawnQty: bigint;
84
+ /** Writer's own collateral deposited */
85
+ collateralDeposited: bigint;
86
+ /** Total borrowed from OMLP vault */
87
+ borrowedPrincipal: bigint;
88
+ /** Number of active PoolLoan accounts for this writer */
89
+ activeLoanCount: number;
90
+ /** Theta (time-decay) allocated to this writer (from pool accumulator) */
91
+ thetaEarned: bigint;
92
+ /** Theta already claimed/withdrawn */
93
+ thetaClaimed: bigint;
94
+ /** Snapshot of pool's acc_theta_per_oi_fp at last claim (reward-debt pattern) */
95
+ lastPoolAccThetaFp: bigint;
96
+ /** Snapshot of pool's acc_closed_per_oi_fp at last sync */
97
+ lastPoolAccClosedFp: bigint;
98
+ /** Snapshot of pool's acc_payout_per_oi_fp at last sync */
99
+ lastPoolAccPayoutFp: bigint;
100
+ /** Accumulated closed qty debt (for lazy settlement calc) */
101
+ closedQtyDebtFp: bigint;
102
+ /** Accumulated payout debt (for lazy settlement calc) */
103
+ payoutDebtFp: bigint;
104
+ /** Total payout to buyers from this writer's collateral */
105
+ totalBuyerPayout: bigint;
106
+ /** Total repaid to OMLP lenders (principal + interest + fees) */
107
+ totalLenderRepaid: bigint;
108
+ /** Total collateral returned to writer */
109
+ totalCollateralReturned: bigint;
110
+ /** Realized PnL (positive = profit, negative = loss) */
111
+ realizedPnl: bigint;
112
+ /** True if position is fully settled (all loans repaid, collateral returned) */
113
+ isSettled: boolean;
114
+ /** True if position was liquidated */
115
+ isLiquidated: boolean;
116
+ createdAt: bigint;
117
+ lastUpdated: bigint;
118
+ bump: number;
119
+ };
120
+
121
+ export type WriterPositionArgs = {
122
+ /** The writer's wallet address */
123
+ writerAuthority: Address;
124
+ /** Reference to the option pool */
125
+ optionPool: Address;
126
+ /** Reference to the option account */
127
+ optionAccount: Address;
128
+ /**
129
+ * Mint used for collateral backing this position (e.g., USDC, BTC, SOL)
130
+ * Can differ from the underlying asset - enables multi-collateral system
131
+ */
132
+ collateralMint: Address;
133
+ /**
134
+ * Mint used for settlement (same as collateral_mint)
135
+ * Buyers receive payout in this currency
136
+ */
137
+ settlementMint: Address;
138
+ /** Total contracts written (minted) by this writer */
139
+ writtenQty: number | bigint;
140
+ /** Total contracts sold to buyers (open interest from this writer) */
141
+ soldQty: number | bigint;
142
+ /** Contracts still available for sale (written_qty - sold_qty - withdrawn_qty) */
143
+ unsoldQty: number | bigint;
144
+ /** Total contracts withdrawn (unwound before selling) */
145
+ withdrawnQty: number | bigint;
146
+ /** Writer's own collateral deposited */
147
+ collateralDeposited: number | bigint;
148
+ /** Total borrowed from OMLP vault */
149
+ borrowedPrincipal: number | bigint;
150
+ /** Number of active PoolLoan accounts for this writer */
151
+ activeLoanCount: number;
152
+ /** Theta (time-decay) allocated to this writer (from pool accumulator) */
153
+ thetaEarned: number | bigint;
154
+ /** Theta already claimed/withdrawn */
155
+ thetaClaimed: number | bigint;
156
+ /** Snapshot of pool's acc_theta_per_oi_fp at last claim (reward-debt pattern) */
157
+ lastPoolAccThetaFp: number | bigint;
158
+ /** Snapshot of pool's acc_closed_per_oi_fp at last sync */
159
+ lastPoolAccClosedFp: number | bigint;
160
+ /** Snapshot of pool's acc_payout_per_oi_fp at last sync */
161
+ lastPoolAccPayoutFp: number | bigint;
162
+ /** Accumulated closed qty debt (for lazy settlement calc) */
163
+ closedQtyDebtFp: number | bigint;
164
+ /** Accumulated payout debt (for lazy settlement calc) */
165
+ payoutDebtFp: number | bigint;
166
+ /** Total payout to buyers from this writer's collateral */
167
+ totalBuyerPayout: number | bigint;
168
+ /** Total repaid to OMLP lenders (principal + interest + fees) */
169
+ totalLenderRepaid: number | bigint;
170
+ /** Total collateral returned to writer */
171
+ totalCollateralReturned: number | bigint;
172
+ /** Realized PnL (positive = profit, negative = loss) */
173
+ realizedPnl: number | bigint;
174
+ /** True if position is fully settled (all loans repaid, collateral returned) */
175
+ isSettled: boolean;
176
+ /** True if position was liquidated */
177
+ isLiquidated: boolean;
178
+ createdAt: number | bigint;
179
+ lastUpdated: number | bigint;
180
+ bump: number;
181
+ };
182
+
183
+ /** Gets the encoder for {@link WriterPositionArgs} account data. */
184
+ export function getWriterPositionEncoder(): FixedSizeEncoder<WriterPositionArgs> {
185
+ return transformEncoder(
186
+ getStructEncoder([
187
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
188
+ ["writerAuthority", getAddressEncoder()],
189
+ ["optionPool", getAddressEncoder()],
190
+ ["optionAccount", getAddressEncoder()],
191
+ ["collateralMint", getAddressEncoder()],
192
+ ["settlementMint", getAddressEncoder()],
193
+ ["writtenQty", getU64Encoder()],
194
+ ["soldQty", getU64Encoder()],
195
+ ["unsoldQty", getU64Encoder()],
196
+ ["withdrawnQty", getU64Encoder()],
197
+ ["collateralDeposited", getU64Encoder()],
198
+ ["borrowedPrincipal", getU64Encoder()],
199
+ ["activeLoanCount", getU8Encoder()],
200
+ ["thetaEarned", getU64Encoder()],
201
+ ["thetaClaimed", getU64Encoder()],
202
+ ["lastPoolAccThetaFp", getU128Encoder()],
203
+ ["lastPoolAccClosedFp", getU128Encoder()],
204
+ ["lastPoolAccPayoutFp", getU128Encoder()],
205
+ ["closedQtyDebtFp", getU128Encoder()],
206
+ ["payoutDebtFp", getU128Encoder()],
207
+ ["totalBuyerPayout", getU64Encoder()],
208
+ ["totalLenderRepaid", getU64Encoder()],
209
+ ["totalCollateralReturned", getU64Encoder()],
210
+ ["realizedPnl", getI64Encoder()],
211
+ ["isSettled", getBooleanEncoder()],
212
+ ["isLiquidated", getBooleanEncoder()],
213
+ ["createdAt", getI64Encoder()],
214
+ ["lastUpdated", getI64Encoder()],
215
+ ["bump", getU8Encoder()],
216
+ ]),
217
+ (value) => ({ ...value, discriminator: WRITER_POSITION_DISCRIMINATOR }),
218
+ );
219
+ }
220
+
221
+ /** Gets the decoder for {@link WriterPosition} account data. */
222
+ export function getWriterPositionDecoder(): FixedSizeDecoder<WriterPosition> {
223
+ return getStructDecoder([
224
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
225
+ ["writerAuthority", getAddressDecoder()],
226
+ ["optionPool", getAddressDecoder()],
227
+ ["optionAccount", getAddressDecoder()],
228
+ ["collateralMint", getAddressDecoder()],
229
+ ["settlementMint", getAddressDecoder()],
230
+ ["writtenQty", getU64Decoder()],
231
+ ["soldQty", getU64Decoder()],
232
+ ["unsoldQty", getU64Decoder()],
233
+ ["withdrawnQty", getU64Decoder()],
234
+ ["collateralDeposited", getU64Decoder()],
235
+ ["borrowedPrincipal", getU64Decoder()],
236
+ ["activeLoanCount", getU8Decoder()],
237
+ ["thetaEarned", getU64Decoder()],
238
+ ["thetaClaimed", getU64Decoder()],
239
+ ["lastPoolAccThetaFp", getU128Decoder()],
240
+ ["lastPoolAccClosedFp", getU128Decoder()],
241
+ ["lastPoolAccPayoutFp", getU128Decoder()],
242
+ ["closedQtyDebtFp", getU128Decoder()],
243
+ ["payoutDebtFp", getU128Decoder()],
244
+ ["totalBuyerPayout", getU64Decoder()],
245
+ ["totalLenderRepaid", getU64Decoder()],
246
+ ["totalCollateralReturned", getU64Decoder()],
247
+ ["realizedPnl", getI64Decoder()],
248
+ ["isSettled", getBooleanDecoder()],
249
+ ["isLiquidated", getBooleanDecoder()],
250
+ ["createdAt", getI64Decoder()],
251
+ ["lastUpdated", getI64Decoder()],
252
+ ["bump", getU8Decoder()],
253
+ ]);
254
+ }
255
+
256
+ /** Gets the codec for {@link WriterPosition} account data. */
257
+ export function getWriterPositionCodec(): FixedSizeCodec<
258
+ WriterPositionArgs,
259
+ WriterPosition
260
+ > {
261
+ return combineCodec(getWriterPositionEncoder(), getWriterPositionDecoder());
262
+ }
263
+
264
+ export function decodeWriterPosition<TAddress extends string = string>(
265
+ encodedAccount: EncodedAccount<TAddress>,
266
+ ): Account<WriterPosition, TAddress>;
267
+ export function decodeWriterPosition<TAddress extends string = string>(
268
+ encodedAccount: MaybeEncodedAccount<TAddress>,
269
+ ): MaybeAccount<WriterPosition, TAddress>;
270
+ export function decodeWriterPosition<TAddress extends string = string>(
271
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
272
+ ): Account<WriterPosition, TAddress> | MaybeAccount<WriterPosition, TAddress> {
273
+ return decodeAccount(
274
+ encodedAccount as MaybeEncodedAccount<TAddress>,
275
+ getWriterPositionDecoder(),
276
+ );
277
+ }
278
+
279
+ export async function fetchWriterPosition<TAddress extends string = string>(
280
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
281
+ address: Address<TAddress>,
282
+ config?: FetchAccountConfig,
283
+ ): Promise<Account<WriterPosition, TAddress>> {
284
+ const maybeAccount = await fetchMaybeWriterPosition(rpc, address, config);
285
+ assertAccountExists(maybeAccount);
286
+ return maybeAccount;
287
+ }
288
+
289
+ export async function fetchMaybeWriterPosition<
290
+ TAddress extends string = string,
291
+ >(
292
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
293
+ address: Address<TAddress>,
294
+ config?: FetchAccountConfig,
295
+ ): Promise<MaybeAccount<WriterPosition, TAddress>> {
296
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
297
+ return decodeWriterPosition(maybeAccount);
298
+ }
299
+
300
+ export async function fetchAllWriterPosition(
301
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
302
+ addresses: Array<Address>,
303
+ config?: FetchAccountsConfig,
304
+ ): Promise<Account<WriterPosition>[]> {
305
+ const maybeAccounts = await fetchAllMaybeWriterPosition(
306
+ rpc,
307
+ addresses,
308
+ config,
309
+ );
310
+ assertAccountsExist(maybeAccounts);
311
+ return maybeAccounts;
312
+ }
313
+
314
+ export async function fetchAllMaybeWriterPosition(
315
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
316
+ addresses: Array<Address>,
317
+ config?: FetchAccountsConfig,
318
+ ): Promise<MaybeAccount<WriterPosition>[]> {
319
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
320
+ return maybeAccounts.map((maybeAccount) =>
321
+ decodeWriterPosition(maybeAccount),
322
+ );
323
+ }
324
+
325
+ export function getWriterPositionSize(): number {
326
+ return 364;
327
+ }
@@ -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";