@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,176 @@
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
+ getF64Decoder,
23
+ getF64Encoder,
24
+ getI64Decoder,
25
+ getI64Encoder,
26
+ getStructDecoder,
27
+ getStructEncoder,
28
+ transformEncoder,
29
+ type Account,
30
+ type Address,
31
+ type EncodedAccount,
32
+ type FetchAccountConfig,
33
+ type FetchAccountsConfig,
34
+ type FixedSizeCodec,
35
+ type FixedSizeDecoder,
36
+ type FixedSizeEncoder,
37
+ type MaybeAccount,
38
+ type MaybeEncodedAccount,
39
+ type ReadonlyUint8Array,
40
+ } from "@solana/kit";
41
+
42
+ export const MARKET_DATA_ACCOUNT_DISCRIMINATOR = new Uint8Array([
43
+ 181, 15, 209, 146, 116, 22, 98, 208,
44
+ ]);
45
+
46
+ export function getMarketDataAccountDiscriminatorBytes() {
47
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
48
+ MARKET_DATA_ACCOUNT_DISCRIMINATOR,
49
+ );
50
+ }
51
+
52
+ export type MarketDataAccount = {
53
+ discriminator: ReadonlyUint8Array;
54
+ underlyingAsset: Address;
55
+ riskFreeRate: number;
56
+ historicalVolatility: number;
57
+ lastUpdated: bigint;
58
+ authority: Address;
59
+ switchboardFeedId: ReadonlyUint8Array;
60
+ };
61
+
62
+ export type MarketDataAccountArgs = {
63
+ underlyingAsset: Address;
64
+ riskFreeRate: number;
65
+ historicalVolatility: number;
66
+ lastUpdated: number | bigint;
67
+ authority: Address;
68
+ switchboardFeedId: ReadonlyUint8Array;
69
+ };
70
+
71
+ /** Gets the encoder for {@link MarketDataAccountArgs} account data. */
72
+ export function getMarketDataAccountEncoder(): FixedSizeEncoder<MarketDataAccountArgs> {
73
+ return transformEncoder(
74
+ getStructEncoder([
75
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
76
+ ["underlyingAsset", getAddressEncoder()],
77
+ ["riskFreeRate", getF64Encoder()],
78
+ ["historicalVolatility", getF64Encoder()],
79
+ ["lastUpdated", getI64Encoder()],
80
+ ["authority", getAddressEncoder()],
81
+ ["switchboardFeedId", fixEncoderSize(getBytesEncoder(), 32)],
82
+ ]),
83
+ (value) => ({ ...value, discriminator: MARKET_DATA_ACCOUNT_DISCRIMINATOR }),
84
+ );
85
+ }
86
+
87
+ /** Gets the decoder for {@link MarketDataAccount} account data. */
88
+ export function getMarketDataAccountDecoder(): FixedSizeDecoder<MarketDataAccount> {
89
+ return getStructDecoder([
90
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
91
+ ["underlyingAsset", getAddressDecoder()],
92
+ ["riskFreeRate", getF64Decoder()],
93
+ ["historicalVolatility", getF64Decoder()],
94
+ ["lastUpdated", getI64Decoder()],
95
+ ["authority", getAddressDecoder()],
96
+ ["switchboardFeedId", fixDecoderSize(getBytesDecoder(), 32)],
97
+ ]);
98
+ }
99
+
100
+ /** Gets the codec for {@link MarketDataAccount} account data. */
101
+ export function getMarketDataAccountCodec(): FixedSizeCodec<
102
+ MarketDataAccountArgs,
103
+ MarketDataAccount
104
+ > {
105
+ return combineCodec(
106
+ getMarketDataAccountEncoder(),
107
+ getMarketDataAccountDecoder(),
108
+ );
109
+ }
110
+
111
+ export function decodeMarketDataAccount<TAddress extends string = string>(
112
+ encodedAccount: EncodedAccount<TAddress>,
113
+ ): Account<MarketDataAccount, TAddress>;
114
+ export function decodeMarketDataAccount<TAddress extends string = string>(
115
+ encodedAccount: MaybeEncodedAccount<TAddress>,
116
+ ): MaybeAccount<MarketDataAccount, TAddress>;
117
+ export function decodeMarketDataAccount<TAddress extends string = string>(
118
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
119
+ ):
120
+ | Account<MarketDataAccount, TAddress>
121
+ | MaybeAccount<MarketDataAccount, TAddress> {
122
+ return decodeAccount(
123
+ encodedAccount as MaybeEncodedAccount<TAddress>,
124
+ getMarketDataAccountDecoder(),
125
+ );
126
+ }
127
+
128
+ export async function fetchMarketDataAccount<TAddress extends string = string>(
129
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
130
+ address: Address<TAddress>,
131
+ config?: FetchAccountConfig,
132
+ ): Promise<Account<MarketDataAccount, TAddress>> {
133
+ const maybeAccount = await fetchMaybeMarketDataAccount(rpc, address, config);
134
+ assertAccountExists(maybeAccount);
135
+ return maybeAccount;
136
+ }
137
+
138
+ export async function fetchMaybeMarketDataAccount<
139
+ TAddress extends string = string,
140
+ >(
141
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
142
+ address: Address<TAddress>,
143
+ config?: FetchAccountConfig,
144
+ ): Promise<MaybeAccount<MarketDataAccount, TAddress>> {
145
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
146
+ return decodeMarketDataAccount(maybeAccount);
147
+ }
148
+
149
+ export async function fetchAllMarketDataAccount(
150
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
151
+ addresses: Array<Address>,
152
+ config?: FetchAccountsConfig,
153
+ ): Promise<Account<MarketDataAccount>[]> {
154
+ const maybeAccounts = await fetchAllMaybeMarketDataAccount(
155
+ rpc,
156
+ addresses,
157
+ config,
158
+ );
159
+ assertAccountsExist(maybeAccounts);
160
+ return maybeAccounts;
161
+ }
162
+
163
+ export async function fetchAllMaybeMarketDataAccount(
164
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
165
+ addresses: Array<Address>,
166
+ config?: FetchAccountsConfig,
167
+ ): Promise<MaybeAccount<MarketDataAccount>[]> {
168
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
169
+ return maybeAccounts.map((maybeAccount) =>
170
+ decodeMarketDataAccount(maybeAccount),
171
+ );
172
+ }
173
+
174
+ export function getMarketDataAccountSize(): number {
175
+ return 128;
176
+ }
@@ -0,0 +1,247 @@
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
+ getF64Decoder,
25
+ getF64Encoder,
26
+ getI64Decoder,
27
+ getI64Encoder,
28
+ getStructDecoder,
29
+ getStructEncoder,
30
+ getU32Decoder,
31
+ getU32Encoder,
32
+ getU64Decoder,
33
+ getU64Encoder,
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
+ import {
48
+ getOptionTypeDecoder,
49
+ getOptionTypeEncoder,
50
+ type OptionType,
51
+ type OptionTypeArgs,
52
+ } from "../types";
53
+
54
+ export const OPTION_ACCOUNT_DISCRIMINATOR = new Uint8Array([
55
+ 82, 44, 195, 42, 219, 57, 18, 92,
56
+ ]);
57
+
58
+ export function getOptionAccountDiscriminatorBytes() {
59
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
60
+ OPTION_ACCOUNT_DISCRIMINATOR,
61
+ );
62
+ }
63
+
64
+ export type OptionAccount = {
65
+ discriminator: ReadonlyUint8Array;
66
+ authority: Address;
67
+ underlyingAsset: Address;
68
+ optionType: OptionType;
69
+ strikePrice: number;
70
+ expirationDate: bigint;
71
+ quantity: bigint;
72
+ premium: number;
73
+ delta: number;
74
+ gamma: number;
75
+ theta: number;
76
+ vega: number;
77
+ rho: number;
78
+ impliedVolatility: number;
79
+ isExercised: boolean;
80
+ createdAt: bigint;
81
+ lastUpdated: bigint;
82
+ longMint: Address;
83
+ shortMint: Address;
84
+ totalBuyerPositions: number;
85
+ settledBuyerPositions: number;
86
+ totalAskPositions: number;
87
+ settledAskPositions: number;
88
+ isFullySettled: boolean;
89
+ };
90
+
91
+ export type OptionAccountArgs = {
92
+ authority: Address;
93
+ underlyingAsset: Address;
94
+ optionType: OptionTypeArgs;
95
+ strikePrice: number;
96
+ expirationDate: number | bigint;
97
+ quantity: number | bigint;
98
+ premium: number;
99
+ delta: number;
100
+ gamma: number;
101
+ theta: number;
102
+ vega: number;
103
+ rho: number;
104
+ impliedVolatility: number;
105
+ isExercised: boolean;
106
+ createdAt: number | bigint;
107
+ lastUpdated: number | bigint;
108
+ longMint: Address;
109
+ shortMint: Address;
110
+ totalBuyerPositions: number;
111
+ settledBuyerPositions: number;
112
+ totalAskPositions: number;
113
+ settledAskPositions: number;
114
+ isFullySettled: boolean;
115
+ };
116
+
117
+ /** Gets the encoder for {@link OptionAccountArgs} account data. */
118
+ export function getOptionAccountEncoder(): FixedSizeEncoder<OptionAccountArgs> {
119
+ return transformEncoder(
120
+ getStructEncoder([
121
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
122
+ ["authority", getAddressEncoder()],
123
+ ["underlyingAsset", getAddressEncoder()],
124
+ ["optionType", getOptionTypeEncoder()],
125
+ ["strikePrice", getF64Encoder()],
126
+ ["expirationDate", getI64Encoder()],
127
+ ["quantity", getU64Encoder()],
128
+ ["premium", getF64Encoder()],
129
+ ["delta", getF64Encoder()],
130
+ ["gamma", getF64Encoder()],
131
+ ["theta", getF64Encoder()],
132
+ ["vega", getF64Encoder()],
133
+ ["rho", getF64Encoder()],
134
+ ["impliedVolatility", getF64Encoder()],
135
+ ["isExercised", getBooleanEncoder()],
136
+ ["createdAt", getI64Encoder()],
137
+ ["lastUpdated", getI64Encoder()],
138
+ ["longMint", getAddressEncoder()],
139
+ ["shortMint", getAddressEncoder()],
140
+ ["totalBuyerPositions", getU32Encoder()],
141
+ ["settledBuyerPositions", getU32Encoder()],
142
+ ["totalAskPositions", getU32Encoder()],
143
+ ["settledAskPositions", getU32Encoder()],
144
+ ["isFullySettled", getBooleanEncoder()],
145
+ ]),
146
+ (value) => ({ ...value, discriminator: OPTION_ACCOUNT_DISCRIMINATOR }),
147
+ );
148
+ }
149
+
150
+ /** Gets the decoder for {@link OptionAccount} account data. */
151
+ export function getOptionAccountDecoder(): FixedSizeDecoder<OptionAccount> {
152
+ return getStructDecoder([
153
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
154
+ ["authority", getAddressDecoder()],
155
+ ["underlyingAsset", getAddressDecoder()],
156
+ ["optionType", getOptionTypeDecoder()],
157
+ ["strikePrice", getF64Decoder()],
158
+ ["expirationDate", getI64Decoder()],
159
+ ["quantity", getU64Decoder()],
160
+ ["premium", getF64Decoder()],
161
+ ["delta", getF64Decoder()],
162
+ ["gamma", getF64Decoder()],
163
+ ["theta", getF64Decoder()],
164
+ ["vega", getF64Decoder()],
165
+ ["rho", getF64Decoder()],
166
+ ["impliedVolatility", getF64Decoder()],
167
+ ["isExercised", getBooleanDecoder()],
168
+ ["createdAt", getI64Decoder()],
169
+ ["lastUpdated", getI64Decoder()],
170
+ ["longMint", getAddressDecoder()],
171
+ ["shortMint", getAddressDecoder()],
172
+ ["totalBuyerPositions", getU32Decoder()],
173
+ ["settledBuyerPositions", getU32Decoder()],
174
+ ["totalAskPositions", getU32Decoder()],
175
+ ["settledAskPositions", getU32Decoder()],
176
+ ["isFullySettled", getBooleanDecoder()],
177
+ ]);
178
+ }
179
+
180
+ /** Gets the codec for {@link OptionAccount} account data. */
181
+ export function getOptionAccountCodec(): FixedSizeCodec<
182
+ OptionAccountArgs,
183
+ OptionAccount
184
+ > {
185
+ return combineCodec(getOptionAccountEncoder(), getOptionAccountDecoder());
186
+ }
187
+
188
+ export function decodeOptionAccount<TAddress extends string = string>(
189
+ encodedAccount: EncodedAccount<TAddress>,
190
+ ): Account<OptionAccount, TAddress>;
191
+ export function decodeOptionAccount<TAddress extends string = string>(
192
+ encodedAccount: MaybeEncodedAccount<TAddress>,
193
+ ): MaybeAccount<OptionAccount, TAddress>;
194
+ export function decodeOptionAccount<TAddress extends string = string>(
195
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
196
+ ): Account<OptionAccount, TAddress> | MaybeAccount<OptionAccount, TAddress> {
197
+ return decodeAccount(
198
+ encodedAccount as MaybeEncodedAccount<TAddress>,
199
+ getOptionAccountDecoder(),
200
+ );
201
+ }
202
+
203
+ export async function fetchOptionAccount<TAddress extends string = string>(
204
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
205
+ address: Address<TAddress>,
206
+ config?: FetchAccountConfig,
207
+ ): Promise<Account<OptionAccount, TAddress>> {
208
+ const maybeAccount = await fetchMaybeOptionAccount(rpc, address, config);
209
+ assertAccountExists(maybeAccount);
210
+ return maybeAccount;
211
+ }
212
+
213
+ export async function fetchMaybeOptionAccount<TAddress extends string = string>(
214
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
215
+ address: Address<TAddress>,
216
+ config?: FetchAccountConfig,
217
+ ): Promise<MaybeAccount<OptionAccount, TAddress>> {
218
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
219
+ return decodeOptionAccount(maybeAccount);
220
+ }
221
+
222
+ export async function fetchAllOptionAccount(
223
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
224
+ addresses: Array<Address>,
225
+ config?: FetchAccountsConfig,
226
+ ): Promise<Account<OptionAccount>[]> {
227
+ const maybeAccounts = await fetchAllMaybeOptionAccount(
228
+ rpc,
229
+ addresses,
230
+ config,
231
+ );
232
+ assertAccountsExist(maybeAccounts);
233
+ return maybeAccounts;
234
+ }
235
+
236
+ export async function fetchAllMaybeOptionAccount(
237
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
238
+ addresses: Array<Address>,
239
+ config?: FetchAccountsConfig,
240
+ ): Promise<MaybeAccount<OptionAccount>[]> {
241
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
242
+ return maybeAccounts.map((maybeAccount) => decodeOptionAccount(maybeAccount));
243
+ }
244
+
245
+ export function getOptionAccountSize(): number {
246
+ return 251;
247
+ }
@@ -0,0 +1,285 @@
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
+ getU32Decoder,
31
+ getU32Encoder,
32
+ getU64Decoder,
33
+ getU64Encoder,
34
+ getU8Decoder,
35
+ getU8Encoder,
36
+ transformEncoder,
37
+ type Account,
38
+ type Address,
39
+ type EncodedAccount,
40
+ type FetchAccountConfig,
41
+ type FetchAccountsConfig,
42
+ type FixedSizeCodec,
43
+ type FixedSizeDecoder,
44
+ type FixedSizeEncoder,
45
+ type MaybeAccount,
46
+ type MaybeEncodedAccount,
47
+ type ReadonlyUint8Array,
48
+ } from "@solana/kit";
49
+
50
+ export const OPTION_POOL_DISCRIMINATOR = new Uint8Array([
51
+ 100, 175, 136, 125, 88, 244, 169, 209,
52
+ ]);
53
+
54
+ export function getOptionPoolDiscriminatorBytes() {
55
+ return fixEncoderSize(getBytesEncoder(), 8).encode(OPTION_POOL_DISCRIMINATOR);
56
+ }
57
+
58
+ export type OptionPool = {
59
+ discriminator: ReadonlyUint8Array;
60
+ optionAccount: Address;
61
+ longMint: Address;
62
+ shortMint: Address;
63
+ underlyingMint: Address;
64
+ escrowLongAccount: Address;
65
+ premiumVault: Address;
66
+ totalDeposited: bigint;
67
+ /**
68
+ * LONG units in pool escrow that `buy_from_pool` may sell: increased on
69
+ * `write_to_pool` and `close_long_to_pool` (recycle), decreased on `buy_from_pool`
70
+ * and writer unwind / liquidation burns — must stay consistent with escrow movements.
71
+ */
72
+ totalAvailable: bigint;
73
+ totalSold: bigint;
74
+ totalWithdrawn: bigint;
75
+ /**
76
+ * Live outstanding sold inventory across all writer positions in this pool.
77
+ * Invariant: `sum(WriterPosition.sold_qty for active writers) == total_sold_qty`.
78
+ * Incremented on every `buy_from_pool` and decremented on every `close_long_to_pool`.
79
+ * Used by `close_long_to_pool` to require a full-writer-set pass for Hamilton pro-rata
80
+ * redistribution (strict completeness check).
81
+ */
82
+ totalSoldQty: bigint;
83
+ totalVolume: bigint;
84
+ volumeToday: bigint;
85
+ volumeResetDate: bigint;
86
+ tradeCount: bigint;
87
+ lastTradeTimestamp: bigint;
88
+ totalPremiumCollected: bigint;
89
+ totalPremiumClaimed: bigint;
90
+ totalPremiumUsedForCloses: bigint;
91
+ totalPremiumRoutedToCollateral: bigint;
92
+ totalOpenInterestQty: bigint;
93
+ accClosedPerOiFp: bigint;
94
+ accPayoutPerOiFp: bigint;
95
+ accThetaPerOiFp: bigint;
96
+ makerCount: number;
97
+ createdAt: bigint;
98
+ lastUpdated: bigint;
99
+ bump: number;
100
+ isActive: boolean;
101
+ };
102
+
103
+ export type OptionPoolArgs = {
104
+ optionAccount: Address;
105
+ longMint: Address;
106
+ shortMint: Address;
107
+ underlyingMint: Address;
108
+ escrowLongAccount: Address;
109
+ premiumVault: Address;
110
+ totalDeposited: number | bigint;
111
+ /**
112
+ * LONG units in pool escrow that `buy_from_pool` may sell: increased on
113
+ * `write_to_pool` and `close_long_to_pool` (recycle), decreased on `buy_from_pool`
114
+ * and writer unwind / liquidation burns — must stay consistent with escrow movements.
115
+ */
116
+ totalAvailable: number | bigint;
117
+ totalSold: number | bigint;
118
+ totalWithdrawn: number | bigint;
119
+ /**
120
+ * Live outstanding sold inventory across all writer positions in this pool.
121
+ * Invariant: `sum(WriterPosition.sold_qty for active writers) == total_sold_qty`.
122
+ * Incremented on every `buy_from_pool` and decremented on every `close_long_to_pool`.
123
+ * Used by `close_long_to_pool` to require a full-writer-set pass for Hamilton pro-rata
124
+ * redistribution (strict completeness check).
125
+ */
126
+ totalSoldQty: number | bigint;
127
+ totalVolume: number | bigint;
128
+ volumeToday: number | bigint;
129
+ volumeResetDate: number | bigint;
130
+ tradeCount: number | bigint;
131
+ lastTradeTimestamp: number | bigint;
132
+ totalPremiumCollected: number | bigint;
133
+ totalPremiumClaimed: number | bigint;
134
+ totalPremiumUsedForCloses: number | bigint;
135
+ totalPremiumRoutedToCollateral: number | bigint;
136
+ totalOpenInterestQty: number | bigint;
137
+ accClosedPerOiFp: number | bigint;
138
+ accPayoutPerOiFp: number | bigint;
139
+ accThetaPerOiFp: number | bigint;
140
+ makerCount: number;
141
+ createdAt: number | bigint;
142
+ lastUpdated: number | bigint;
143
+ bump: number;
144
+ isActive: boolean;
145
+ };
146
+
147
+ /** Gets the encoder for {@link OptionPoolArgs} account data. */
148
+ export function getOptionPoolEncoder(): FixedSizeEncoder<OptionPoolArgs> {
149
+ return transformEncoder(
150
+ getStructEncoder([
151
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
152
+ ["optionAccount", getAddressEncoder()],
153
+ ["longMint", getAddressEncoder()],
154
+ ["shortMint", getAddressEncoder()],
155
+ ["underlyingMint", getAddressEncoder()],
156
+ ["escrowLongAccount", getAddressEncoder()],
157
+ ["premiumVault", getAddressEncoder()],
158
+ ["totalDeposited", getU64Encoder()],
159
+ ["totalAvailable", getU64Encoder()],
160
+ ["totalSold", getU64Encoder()],
161
+ ["totalWithdrawn", getU64Encoder()],
162
+ ["totalSoldQty", getU64Encoder()],
163
+ ["totalVolume", getU64Encoder()],
164
+ ["volumeToday", getU64Encoder()],
165
+ ["volumeResetDate", getI64Encoder()],
166
+ ["tradeCount", getU64Encoder()],
167
+ ["lastTradeTimestamp", getI64Encoder()],
168
+ ["totalPremiumCollected", getU64Encoder()],
169
+ ["totalPremiumClaimed", getU64Encoder()],
170
+ ["totalPremiumUsedForCloses", getU64Encoder()],
171
+ ["totalPremiumRoutedToCollateral", getU64Encoder()],
172
+ ["totalOpenInterestQty", getU64Encoder()],
173
+ ["accClosedPerOiFp", getU128Encoder()],
174
+ ["accPayoutPerOiFp", getU128Encoder()],
175
+ ["accThetaPerOiFp", getU128Encoder()],
176
+ ["makerCount", getU32Encoder()],
177
+ ["createdAt", getI64Encoder()],
178
+ ["lastUpdated", getI64Encoder()],
179
+ ["bump", getU8Encoder()],
180
+ ["isActive", getBooleanEncoder()],
181
+ ]),
182
+ (value) => ({ ...value, discriminator: OPTION_POOL_DISCRIMINATOR }),
183
+ );
184
+ }
185
+
186
+ /** Gets the decoder for {@link OptionPool} account data. */
187
+ export function getOptionPoolDecoder(): FixedSizeDecoder<OptionPool> {
188
+ return getStructDecoder([
189
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
190
+ ["optionAccount", getAddressDecoder()],
191
+ ["longMint", getAddressDecoder()],
192
+ ["shortMint", getAddressDecoder()],
193
+ ["underlyingMint", getAddressDecoder()],
194
+ ["escrowLongAccount", getAddressDecoder()],
195
+ ["premiumVault", getAddressDecoder()],
196
+ ["totalDeposited", getU64Decoder()],
197
+ ["totalAvailable", getU64Decoder()],
198
+ ["totalSold", getU64Decoder()],
199
+ ["totalWithdrawn", getU64Decoder()],
200
+ ["totalSoldQty", getU64Decoder()],
201
+ ["totalVolume", getU64Decoder()],
202
+ ["volumeToday", getU64Decoder()],
203
+ ["volumeResetDate", getI64Decoder()],
204
+ ["tradeCount", getU64Decoder()],
205
+ ["lastTradeTimestamp", getI64Decoder()],
206
+ ["totalPremiumCollected", getU64Decoder()],
207
+ ["totalPremiumClaimed", getU64Decoder()],
208
+ ["totalPremiumUsedForCloses", getU64Decoder()],
209
+ ["totalPremiumRoutedToCollateral", getU64Decoder()],
210
+ ["totalOpenInterestQty", getU64Decoder()],
211
+ ["accClosedPerOiFp", getU128Decoder()],
212
+ ["accPayoutPerOiFp", getU128Decoder()],
213
+ ["accThetaPerOiFp", getU128Decoder()],
214
+ ["makerCount", getU32Decoder()],
215
+ ["createdAt", getI64Decoder()],
216
+ ["lastUpdated", getI64Decoder()],
217
+ ["bump", getU8Decoder()],
218
+ ["isActive", getBooleanDecoder()],
219
+ ]);
220
+ }
221
+
222
+ /** Gets the codec for {@link OptionPool} account data. */
223
+ export function getOptionPoolCodec(): FixedSizeCodec<
224
+ OptionPoolArgs,
225
+ OptionPool
226
+ > {
227
+ return combineCodec(getOptionPoolEncoder(), getOptionPoolDecoder());
228
+ }
229
+
230
+ export function decodeOptionPool<TAddress extends string = string>(
231
+ encodedAccount: EncodedAccount<TAddress>,
232
+ ): Account<OptionPool, TAddress>;
233
+ export function decodeOptionPool<TAddress extends string = string>(
234
+ encodedAccount: MaybeEncodedAccount<TAddress>,
235
+ ): MaybeAccount<OptionPool, TAddress>;
236
+ export function decodeOptionPool<TAddress extends string = string>(
237
+ encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
238
+ ): Account<OptionPool, TAddress> | MaybeAccount<OptionPool, TAddress> {
239
+ return decodeAccount(
240
+ encodedAccount as MaybeEncodedAccount<TAddress>,
241
+ getOptionPoolDecoder(),
242
+ );
243
+ }
244
+
245
+ export async function fetchOptionPool<TAddress extends string = string>(
246
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
247
+ address: Address<TAddress>,
248
+ config?: FetchAccountConfig,
249
+ ): Promise<Account<OptionPool, TAddress>> {
250
+ const maybeAccount = await fetchMaybeOptionPool(rpc, address, config);
251
+ assertAccountExists(maybeAccount);
252
+ return maybeAccount;
253
+ }
254
+
255
+ export async function fetchMaybeOptionPool<TAddress extends string = string>(
256
+ rpc: Parameters<typeof fetchEncodedAccount>[0],
257
+ address: Address<TAddress>,
258
+ config?: FetchAccountConfig,
259
+ ): Promise<MaybeAccount<OptionPool, TAddress>> {
260
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
261
+ return decodeOptionPool(maybeAccount);
262
+ }
263
+
264
+ export async function fetchAllOptionPool(
265
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
266
+ addresses: Array<Address>,
267
+ config?: FetchAccountsConfig,
268
+ ): Promise<Account<OptionPool>[]> {
269
+ const maybeAccounts = await fetchAllMaybeOptionPool(rpc, addresses, config);
270
+ assertAccountsExist(maybeAccounts);
271
+ return maybeAccounts;
272
+ }
273
+
274
+ export async function fetchAllMaybeOptionPool(
275
+ rpc: Parameters<typeof fetchEncodedAccounts>[0],
276
+ addresses: Array<Address>,
277
+ config?: FetchAccountsConfig,
278
+ ): Promise<MaybeAccount<OptionPool>[]> {
279
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
280
+ return maybeAccounts.map((maybeAccount) => decodeOptionPool(maybeAccount));
281
+ }
282
+
283
+ export function getOptionPoolSize(): number {
284
+ return 390;
285
+ }