@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.
- package/LICENSE +21 -0
- package/README.md +239 -0
- package/accounts/fetchers.ts +140 -0
- package/accounts/list.ts +152 -0
- package/accounts/pdas.ts +308 -0
- package/client/lookup-table.ts +32 -0
- package/client/program.ts +13 -0
- package/client/types.ts +8 -0
- package/generated/accounts/collateralPool.ts +217 -0
- package/generated/accounts/config.ts +156 -0
- package/generated/accounts/dualSourceContract.ts +235 -0
- package/generated/accounts/escrowState.ts +183 -0
- package/generated/accounts/index.ts +24 -0
- package/generated/accounts/lenderPosition.ts +211 -0
- package/generated/accounts/liquidityRouter.ts +223 -0
- package/generated/accounts/makerCollateralShare.ts +229 -0
- package/generated/accounts/makerPoolShare.ts +203 -0
- package/generated/accounts/marketDataAccount.ts +176 -0
- package/generated/accounts/optionAccount.ts +247 -0
- package/generated/accounts/optionPool.ts +253 -0
- package/generated/accounts/poolLoan.ts +220 -0
- package/generated/accounts/positionAccount.ts +187 -0
- package/generated/accounts/priceUpdateV2.ts +163 -0
- package/generated/accounts/vault.ts +304 -0
- package/generated/accounts/writerPosition.ts +297 -0
- package/generated/errors/index.ts +9 -0
- package/generated/errors/optionProgram.ts +392 -0
- package/generated/index.ts +13 -0
- package/generated/instructions/acceptAdmin.ts +230 -0
- package/generated/instructions/autoExerciseAllExpired.ts +523 -0
- package/generated/instructions/autoExerciseExpired.ts +623 -0
- package/generated/instructions/borrowFromPool.ts +554 -0
- package/generated/instructions/buyFromPool.ts +684 -0
- package/generated/instructions/claimPremium.ts +377 -0
- package/generated/instructions/closeLongToPool.ts +716 -0
- package/generated/instructions/closeOption.ts +235 -0
- package/generated/instructions/createEscrowV2.ts +518 -0
- package/generated/instructions/createLiquidityRouter.ts +361 -0
- package/generated/instructions/depositCollateral.ts +624 -0
- package/generated/instructions/depositToPool.ts +497 -0
- package/generated/instructions/depositToPosition.ts +429 -0
- package/generated/instructions/index.ts +45 -0
- package/generated/instructions/initCollateralPool.ts +513 -0
- package/generated/instructions/initConfig.ts +279 -0
- package/generated/instructions/initOptionPool.ts +587 -0
- package/generated/instructions/initializeMarketData.ts +359 -0
- package/generated/instructions/liquidateWriterPosition.ts +592 -0
- package/generated/instructions/omlpCreateVault.ts +547 -0
- package/generated/instructions/omlpTakeOfferWithFailover.ts +606 -0
- package/generated/instructions/omlpUpdateMaxLeverage.ts +304 -0
- package/generated/instructions/omlpUpdateProtocolFee.ts +304 -0
- package/generated/instructions/omlpUpdateSupplyLimit.ts +304 -0
- package/generated/instructions/optionExercise.ts +540 -0
- package/generated/instructions/optionMint.ts +1349 -0
- package/generated/instructions/optionValidate.ts +255 -0
- package/generated/instructions/repayPoolLoan.ts +499 -0
- package/generated/instructions/repayPoolLoanFromCollateral.ts +514 -0
- package/generated/instructions/settleMakerCollateral.ts +472 -0
- package/generated/instructions/syncWriterPosition.ts +206 -0
- package/generated/instructions/transferAdmin.ts +245 -0
- package/generated/instructions/unwindWriterUnsold.ts +668 -0
- package/generated/instructions/updateImpliedVolatility.ts +226 -0
- package/generated/instructions/updateMarketData.ts +315 -0
- package/generated/instructions/withdrawFromPool.ts +429 -0
- package/generated/instructions/withdrawFromPosition.ts +405 -0
- package/generated/instructions/writeToPool.ts +594 -0
- package/generated/programs/index.ts +9 -0
- package/generated/programs/optionProgram.ts +832 -0
- package/generated/shared/index.ts +164 -0
- package/generated/types/borrowedFromSAP1.ts +75 -0
- package/generated/types/borrowedFromSAP2.ts +83 -0
- package/generated/types/failoverTriggered.ts +85 -0
- package/generated/types/impliedVolatilityUpdated.ts +73 -0
- package/generated/types/index.ts +32 -0
- package/generated/types/liquidationExecuted.ts +73 -0
- package/generated/types/liquidityMetrics.ts +69 -0
- package/generated/types/liquidityRouterCreated.ts +79 -0
- package/generated/types/marketDataInitialized.ts +61 -0
- package/generated/types/marketDataUpdated.ts +69 -0
- package/generated/types/optionClosed.ts +56 -0
- package/generated/types/optionExercised.ts +62 -0
- package/generated/types/optionExpired.ts +49 -0
- package/generated/types/optionMinted.ts +78 -0
- package/generated/types/optionType.ts +38 -0
- package/generated/types/optionValidated.ts +82 -0
- package/generated/types/poolLoanCreated.ts +74 -0
- package/generated/types/poolLoanRepaid.ts +74 -0
- package/generated/types/positionDeposited.ts +73 -0
- package/generated/types/positionWithdrawn.ts +81 -0
- package/generated/types/priceFeedMessage.ts +117 -0
- package/generated/types/protocolFeeUpdated.ts +69 -0
- package/generated/types/sap2Provider.ts +38 -0
- package/generated/types/vaultCreated.ts +60 -0
- package/generated/types/verificationLevel.ts +95 -0
- package/index.ts +25 -0
- package/long/builders.ts +126 -0
- package/long/exercise.ts +49 -0
- package/long/quotes.ts +48 -0
- package/omlp/builders.ts +74 -0
- package/omlp/service.ts +94 -0
- package/package.json +22 -0
- package/shared/amounts.ts +32 -0
- package/shared/errors.ts +12 -0
- package/shared/remaining-accounts.ts +41 -0
- package/shared/transactions.ts +49 -0
- package/short/builders.ts +268 -0
- package/short/claim-premium.ts +37 -0
- package/short/close-option.ts +34 -0
- package/short/pool.ts +224 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,203 @@
|
|
|
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
|
+
getU32Decoder,
|
|
27
|
+
getU32Encoder,
|
|
28
|
+
getU64Decoder,
|
|
29
|
+
getU64Encoder,
|
|
30
|
+
getU8Decoder,
|
|
31
|
+
getU8Encoder,
|
|
32
|
+
transformEncoder,
|
|
33
|
+
type Account,
|
|
34
|
+
type Address,
|
|
35
|
+
type EncodedAccount,
|
|
36
|
+
type FetchAccountConfig,
|
|
37
|
+
type FetchAccountsConfig,
|
|
38
|
+
type FixedSizeCodec,
|
|
39
|
+
type FixedSizeDecoder,
|
|
40
|
+
type FixedSizeEncoder,
|
|
41
|
+
type MaybeAccount,
|
|
42
|
+
type MaybeEncodedAccount,
|
|
43
|
+
type ReadonlyUint8Array,
|
|
44
|
+
} from "@solana/kit";
|
|
45
|
+
|
|
46
|
+
export const MAKER_POOL_SHARE_DISCRIMINATOR = new Uint8Array([
|
|
47
|
+
171, 211, 240, 11, 182, 141, 59, 217,
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
export function getMakerPoolShareDiscriminatorBytes() {
|
|
51
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
52
|
+
MAKER_POOL_SHARE_DISCRIMINATOR,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type MakerPoolShare = {
|
|
57
|
+
discriminator: ReadonlyUint8Array;
|
|
58
|
+
maker: Address;
|
|
59
|
+
optionPool: Address;
|
|
60
|
+
optionAccount: Address;
|
|
61
|
+
deposited: bigint;
|
|
62
|
+
remaining: bigint;
|
|
63
|
+
sold: bigint;
|
|
64
|
+
withdrawn: bigint;
|
|
65
|
+
premiumEarned: bigint;
|
|
66
|
+
premiumClaimed: bigint;
|
|
67
|
+
depositCount: number;
|
|
68
|
+
createdAt: bigint;
|
|
69
|
+
lastUpdated: bigint;
|
|
70
|
+
bump: number;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type MakerPoolShareArgs = {
|
|
74
|
+
maker: Address;
|
|
75
|
+
optionPool: Address;
|
|
76
|
+
optionAccount: Address;
|
|
77
|
+
deposited: number | bigint;
|
|
78
|
+
remaining: number | bigint;
|
|
79
|
+
sold: number | bigint;
|
|
80
|
+
withdrawn: number | bigint;
|
|
81
|
+
premiumEarned: number | bigint;
|
|
82
|
+
premiumClaimed: number | bigint;
|
|
83
|
+
depositCount: number;
|
|
84
|
+
createdAt: number | bigint;
|
|
85
|
+
lastUpdated: number | bigint;
|
|
86
|
+
bump: number;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** Gets the encoder for {@link MakerPoolShareArgs} account data. */
|
|
90
|
+
export function getMakerPoolShareEncoder(): FixedSizeEncoder<MakerPoolShareArgs> {
|
|
91
|
+
return transformEncoder(
|
|
92
|
+
getStructEncoder([
|
|
93
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
94
|
+
["maker", getAddressEncoder()],
|
|
95
|
+
["optionPool", getAddressEncoder()],
|
|
96
|
+
["optionAccount", getAddressEncoder()],
|
|
97
|
+
["deposited", getU64Encoder()],
|
|
98
|
+
["remaining", getU64Encoder()],
|
|
99
|
+
["sold", getU64Encoder()],
|
|
100
|
+
["withdrawn", getU64Encoder()],
|
|
101
|
+
["premiumEarned", getU64Encoder()],
|
|
102
|
+
["premiumClaimed", getU64Encoder()],
|
|
103
|
+
["depositCount", getU32Encoder()],
|
|
104
|
+
["createdAt", getI64Encoder()],
|
|
105
|
+
["lastUpdated", getI64Encoder()],
|
|
106
|
+
["bump", getU8Encoder()],
|
|
107
|
+
]),
|
|
108
|
+
(value) => ({ ...value, discriminator: MAKER_POOL_SHARE_DISCRIMINATOR }),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Gets the decoder for {@link MakerPoolShare} account data. */
|
|
113
|
+
export function getMakerPoolShareDecoder(): FixedSizeDecoder<MakerPoolShare> {
|
|
114
|
+
return getStructDecoder([
|
|
115
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
116
|
+
["maker", getAddressDecoder()],
|
|
117
|
+
["optionPool", getAddressDecoder()],
|
|
118
|
+
["optionAccount", getAddressDecoder()],
|
|
119
|
+
["deposited", getU64Decoder()],
|
|
120
|
+
["remaining", getU64Decoder()],
|
|
121
|
+
["sold", getU64Decoder()],
|
|
122
|
+
["withdrawn", getU64Decoder()],
|
|
123
|
+
["premiumEarned", getU64Decoder()],
|
|
124
|
+
["premiumClaimed", getU64Decoder()],
|
|
125
|
+
["depositCount", getU32Decoder()],
|
|
126
|
+
["createdAt", getI64Decoder()],
|
|
127
|
+
["lastUpdated", getI64Decoder()],
|
|
128
|
+
["bump", getU8Decoder()],
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Gets the codec for {@link MakerPoolShare} account data. */
|
|
133
|
+
export function getMakerPoolShareCodec(): FixedSizeCodec<
|
|
134
|
+
MakerPoolShareArgs,
|
|
135
|
+
MakerPoolShare
|
|
136
|
+
> {
|
|
137
|
+
return combineCodec(getMakerPoolShareEncoder(), getMakerPoolShareDecoder());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function decodeMakerPoolShare<TAddress extends string = string>(
|
|
141
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
142
|
+
): Account<MakerPoolShare, TAddress>;
|
|
143
|
+
export function decodeMakerPoolShare<TAddress extends string = string>(
|
|
144
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
145
|
+
): MaybeAccount<MakerPoolShare, TAddress>;
|
|
146
|
+
export function decodeMakerPoolShare<TAddress extends string = string>(
|
|
147
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
148
|
+
): Account<MakerPoolShare, TAddress> | MaybeAccount<MakerPoolShare, TAddress> {
|
|
149
|
+
return decodeAccount(
|
|
150
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
151
|
+
getMakerPoolShareDecoder(),
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function fetchMakerPoolShare<TAddress extends string = string>(
|
|
156
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
157
|
+
address: Address<TAddress>,
|
|
158
|
+
config?: FetchAccountConfig,
|
|
159
|
+
): Promise<Account<MakerPoolShare, TAddress>> {
|
|
160
|
+
const maybeAccount = await fetchMaybeMakerPoolShare(rpc, address, config);
|
|
161
|
+
assertAccountExists(maybeAccount);
|
|
162
|
+
return maybeAccount;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function fetchMaybeMakerPoolShare<
|
|
166
|
+
TAddress extends string = string,
|
|
167
|
+
>(
|
|
168
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
169
|
+
address: Address<TAddress>,
|
|
170
|
+
config?: FetchAccountConfig,
|
|
171
|
+
): Promise<MaybeAccount<MakerPoolShare, TAddress>> {
|
|
172
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
173
|
+
return decodeMakerPoolShare(maybeAccount);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export async function fetchAllMakerPoolShare(
|
|
177
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
178
|
+
addresses: Array<Address>,
|
|
179
|
+
config?: FetchAccountsConfig,
|
|
180
|
+
): Promise<Account<MakerPoolShare>[]> {
|
|
181
|
+
const maybeAccounts = await fetchAllMaybeMakerPoolShare(
|
|
182
|
+
rpc,
|
|
183
|
+
addresses,
|
|
184
|
+
config,
|
|
185
|
+
);
|
|
186
|
+
assertAccountsExist(maybeAccounts);
|
|
187
|
+
return maybeAccounts;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export async function fetchAllMaybeMakerPoolShare(
|
|
191
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
192
|
+
addresses: Array<Address>,
|
|
193
|
+
config?: FetchAccountsConfig,
|
|
194
|
+
): Promise<MaybeAccount<MakerPoolShare>[]> {
|
|
195
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
196
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
197
|
+
decodeMakerPoolShare(maybeAccount),
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function getMakerPoolShareSize(): number {
|
|
202
|
+
return 173;
|
|
203
|
+
}
|
|
@@ -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
|
+
pythFeedId: ReadonlyUint8Array;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type MarketDataAccountArgs = {
|
|
63
|
+
underlyingAsset: Address;
|
|
64
|
+
riskFreeRate: number;
|
|
65
|
+
historicalVolatility: number;
|
|
66
|
+
lastUpdated: number | bigint;
|
|
67
|
+
authority: Address;
|
|
68
|
+
pythFeedId: 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
|
+
["pythFeedId", 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
|
+
["pythFeedId", 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
|
+
}
|