@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,253 @@
|
|
|
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
|
+
totalAvailable: bigint;
|
|
68
|
+
totalSold: bigint;
|
|
69
|
+
totalWithdrawn: bigint;
|
|
70
|
+
totalVolume: bigint;
|
|
71
|
+
volumeToday: bigint;
|
|
72
|
+
volumeResetDate: bigint;
|
|
73
|
+
tradeCount: bigint;
|
|
74
|
+
lastTradeTimestamp: bigint;
|
|
75
|
+
totalPremiumCollected: bigint;
|
|
76
|
+
totalPremiumClaimed: bigint;
|
|
77
|
+
totalPremiumUsedForCloses: bigint;
|
|
78
|
+
totalPremiumRoutedToCollateral: bigint;
|
|
79
|
+
totalOpenInterestQty: bigint;
|
|
80
|
+
accClosedPerOiFp: bigint;
|
|
81
|
+
accPayoutPerOiFp: bigint;
|
|
82
|
+
makerCount: number;
|
|
83
|
+
createdAt: bigint;
|
|
84
|
+
lastUpdated: bigint;
|
|
85
|
+
bump: number;
|
|
86
|
+
isActive: boolean;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type OptionPoolArgs = {
|
|
90
|
+
optionAccount: Address;
|
|
91
|
+
longMint: Address;
|
|
92
|
+
shortMint: Address;
|
|
93
|
+
underlyingMint: Address;
|
|
94
|
+
escrowLongAccount: Address;
|
|
95
|
+
premiumVault: Address;
|
|
96
|
+
totalDeposited: number | bigint;
|
|
97
|
+
totalAvailable: number | bigint;
|
|
98
|
+
totalSold: number | bigint;
|
|
99
|
+
totalWithdrawn: number | bigint;
|
|
100
|
+
totalVolume: number | bigint;
|
|
101
|
+
volumeToday: number | bigint;
|
|
102
|
+
volumeResetDate: number | bigint;
|
|
103
|
+
tradeCount: number | bigint;
|
|
104
|
+
lastTradeTimestamp: number | bigint;
|
|
105
|
+
totalPremiumCollected: number | bigint;
|
|
106
|
+
totalPremiumClaimed: number | bigint;
|
|
107
|
+
totalPremiumUsedForCloses: number | bigint;
|
|
108
|
+
totalPremiumRoutedToCollateral: number | bigint;
|
|
109
|
+
totalOpenInterestQty: number | bigint;
|
|
110
|
+
accClosedPerOiFp: number | bigint;
|
|
111
|
+
accPayoutPerOiFp: number | bigint;
|
|
112
|
+
makerCount: number;
|
|
113
|
+
createdAt: number | bigint;
|
|
114
|
+
lastUpdated: number | bigint;
|
|
115
|
+
bump: number;
|
|
116
|
+
isActive: boolean;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Gets the encoder for {@link OptionPoolArgs} account data. */
|
|
120
|
+
export function getOptionPoolEncoder(): FixedSizeEncoder<OptionPoolArgs> {
|
|
121
|
+
return transformEncoder(
|
|
122
|
+
getStructEncoder([
|
|
123
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
124
|
+
["optionAccount", getAddressEncoder()],
|
|
125
|
+
["longMint", getAddressEncoder()],
|
|
126
|
+
["shortMint", getAddressEncoder()],
|
|
127
|
+
["underlyingMint", getAddressEncoder()],
|
|
128
|
+
["escrowLongAccount", getAddressEncoder()],
|
|
129
|
+
["premiumVault", getAddressEncoder()],
|
|
130
|
+
["totalDeposited", getU64Encoder()],
|
|
131
|
+
["totalAvailable", getU64Encoder()],
|
|
132
|
+
["totalSold", getU64Encoder()],
|
|
133
|
+
["totalWithdrawn", getU64Encoder()],
|
|
134
|
+
["totalVolume", getU64Encoder()],
|
|
135
|
+
["volumeToday", getU64Encoder()],
|
|
136
|
+
["volumeResetDate", getI64Encoder()],
|
|
137
|
+
["tradeCount", getU64Encoder()],
|
|
138
|
+
["lastTradeTimestamp", getI64Encoder()],
|
|
139
|
+
["totalPremiumCollected", getU64Encoder()],
|
|
140
|
+
["totalPremiumClaimed", getU64Encoder()],
|
|
141
|
+
["totalPremiumUsedForCloses", getU64Encoder()],
|
|
142
|
+
["totalPremiumRoutedToCollateral", getU64Encoder()],
|
|
143
|
+
["totalOpenInterestQty", getU64Encoder()],
|
|
144
|
+
["accClosedPerOiFp", getU128Encoder()],
|
|
145
|
+
["accPayoutPerOiFp", getU128Encoder()],
|
|
146
|
+
["makerCount", getU32Encoder()],
|
|
147
|
+
["createdAt", getI64Encoder()],
|
|
148
|
+
["lastUpdated", getI64Encoder()],
|
|
149
|
+
["bump", getU8Encoder()],
|
|
150
|
+
["isActive", getBooleanEncoder()],
|
|
151
|
+
]),
|
|
152
|
+
(value) => ({ ...value, discriminator: OPTION_POOL_DISCRIMINATOR }),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Gets the decoder for {@link OptionPool} account data. */
|
|
157
|
+
export function getOptionPoolDecoder(): FixedSizeDecoder<OptionPool> {
|
|
158
|
+
return getStructDecoder([
|
|
159
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
160
|
+
["optionAccount", getAddressDecoder()],
|
|
161
|
+
["longMint", getAddressDecoder()],
|
|
162
|
+
["shortMint", getAddressDecoder()],
|
|
163
|
+
["underlyingMint", getAddressDecoder()],
|
|
164
|
+
["escrowLongAccount", getAddressDecoder()],
|
|
165
|
+
["premiumVault", getAddressDecoder()],
|
|
166
|
+
["totalDeposited", getU64Decoder()],
|
|
167
|
+
["totalAvailable", getU64Decoder()],
|
|
168
|
+
["totalSold", getU64Decoder()],
|
|
169
|
+
["totalWithdrawn", getU64Decoder()],
|
|
170
|
+
["totalVolume", getU64Decoder()],
|
|
171
|
+
["volumeToday", getU64Decoder()],
|
|
172
|
+
["volumeResetDate", getI64Decoder()],
|
|
173
|
+
["tradeCount", getU64Decoder()],
|
|
174
|
+
["lastTradeTimestamp", getI64Decoder()],
|
|
175
|
+
["totalPremiumCollected", getU64Decoder()],
|
|
176
|
+
["totalPremiumClaimed", getU64Decoder()],
|
|
177
|
+
["totalPremiumUsedForCloses", getU64Decoder()],
|
|
178
|
+
["totalPremiumRoutedToCollateral", getU64Decoder()],
|
|
179
|
+
["totalOpenInterestQty", getU64Decoder()],
|
|
180
|
+
["accClosedPerOiFp", getU128Decoder()],
|
|
181
|
+
["accPayoutPerOiFp", getU128Decoder()],
|
|
182
|
+
["makerCount", getU32Decoder()],
|
|
183
|
+
["createdAt", getI64Decoder()],
|
|
184
|
+
["lastUpdated", getI64Decoder()],
|
|
185
|
+
["bump", getU8Decoder()],
|
|
186
|
+
["isActive", getBooleanDecoder()],
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Gets the codec for {@link OptionPool} account data. */
|
|
191
|
+
export function getOptionPoolCodec(): FixedSizeCodec<
|
|
192
|
+
OptionPoolArgs,
|
|
193
|
+
OptionPool
|
|
194
|
+
> {
|
|
195
|
+
return combineCodec(getOptionPoolEncoder(), getOptionPoolDecoder());
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function decodeOptionPool<TAddress extends string = string>(
|
|
199
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
200
|
+
): Account<OptionPool, TAddress>;
|
|
201
|
+
export function decodeOptionPool<TAddress extends string = string>(
|
|
202
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
203
|
+
): MaybeAccount<OptionPool, TAddress>;
|
|
204
|
+
export function decodeOptionPool<TAddress extends string = string>(
|
|
205
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
206
|
+
): Account<OptionPool, TAddress> | MaybeAccount<OptionPool, TAddress> {
|
|
207
|
+
return decodeAccount(
|
|
208
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
209
|
+
getOptionPoolDecoder(),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export async function fetchOptionPool<TAddress extends string = string>(
|
|
214
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
215
|
+
address: Address<TAddress>,
|
|
216
|
+
config?: FetchAccountConfig,
|
|
217
|
+
): Promise<Account<OptionPool, TAddress>> {
|
|
218
|
+
const maybeAccount = await fetchMaybeOptionPool(rpc, address, config);
|
|
219
|
+
assertAccountExists(maybeAccount);
|
|
220
|
+
return maybeAccount;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export async function fetchMaybeOptionPool<TAddress extends string = string>(
|
|
224
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
225
|
+
address: Address<TAddress>,
|
|
226
|
+
config?: FetchAccountConfig,
|
|
227
|
+
): Promise<MaybeAccount<OptionPool, TAddress>> {
|
|
228
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
229
|
+
return decodeOptionPool(maybeAccount);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export async function fetchAllOptionPool(
|
|
233
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
234
|
+
addresses: Array<Address>,
|
|
235
|
+
config?: FetchAccountsConfig,
|
|
236
|
+
): Promise<Account<OptionPool>[]> {
|
|
237
|
+
const maybeAccounts = await fetchAllMaybeOptionPool(rpc, addresses, config);
|
|
238
|
+
assertAccountsExist(maybeAccounts);
|
|
239
|
+
return maybeAccounts;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export async function fetchAllMaybeOptionPool(
|
|
243
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
244
|
+
addresses: Array<Address>,
|
|
245
|
+
config?: FetchAccountsConfig,
|
|
246
|
+
): Promise<MaybeAccount<OptionPool>[]> {
|
|
247
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
248
|
+
return maybeAccounts.map((maybeAccount) => decodeOptionPool(maybeAccount));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function getOptionPoolSize(): number {
|
|
252
|
+
return 366;
|
|
253
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
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
|
+
getStructDecoder,
|
|
23
|
+
getStructEncoder,
|
|
24
|
+
getU16Decoder,
|
|
25
|
+
getU16Encoder,
|
|
26
|
+
getU64Decoder,
|
|
27
|
+
getU64Encoder,
|
|
28
|
+
getU8Decoder,
|
|
29
|
+
getU8Encoder,
|
|
30
|
+
transformEncoder,
|
|
31
|
+
type Account,
|
|
32
|
+
type Address,
|
|
33
|
+
type EncodedAccount,
|
|
34
|
+
type FetchAccountConfig,
|
|
35
|
+
type FetchAccountsConfig,
|
|
36
|
+
type FixedSizeCodec,
|
|
37
|
+
type FixedSizeDecoder,
|
|
38
|
+
type FixedSizeEncoder,
|
|
39
|
+
type MaybeAccount,
|
|
40
|
+
type MaybeEncodedAccount,
|
|
41
|
+
type ReadonlyUint8Array,
|
|
42
|
+
} from "@solana/kit";
|
|
43
|
+
|
|
44
|
+
export const POOL_LOAN_DISCRIMINATOR = new Uint8Array([
|
|
45
|
+
31, 179, 93, 157, 68, 113, 2, 128,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
export function getPoolLoanDiscriminatorBytes() {
|
|
49
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(POOL_LOAN_DISCRIMINATOR);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type PoolLoan = {
|
|
53
|
+
discriminator: ReadonlyUint8Array;
|
|
54
|
+
/** Maker (borrower) who took this loan */
|
|
55
|
+
maker: Address;
|
|
56
|
+
/** Vault this loan is from */
|
|
57
|
+
vault: Address;
|
|
58
|
+
/**
|
|
59
|
+
* Escrow state PDA that validates maker/mint binding
|
|
60
|
+
* The actual token account is derived from escrow_authority_v2
|
|
61
|
+
*/
|
|
62
|
+
escrowState: Address;
|
|
63
|
+
/** Principal borrowed */
|
|
64
|
+
principal: bigint;
|
|
65
|
+
/** Interest rate at time of borrow (from vault's dynamic rate) */
|
|
66
|
+
rateBps: number;
|
|
67
|
+
/** Accrued interest (computed from slots) */
|
|
68
|
+
accruedInterest: bigint;
|
|
69
|
+
/** Protocol fees accrued */
|
|
70
|
+
accruedProtocolFees: bigint;
|
|
71
|
+
/** Collateral amount provided */
|
|
72
|
+
collateral: bigint;
|
|
73
|
+
/** Slot when loan started */
|
|
74
|
+
startSlot: bigint;
|
|
75
|
+
/** Last slot when interest was updated */
|
|
76
|
+
lastUpdateSlot: bigint;
|
|
77
|
+
/** Loan status: 1=Active, 2=Repaid, 3=Liquidated */
|
|
78
|
+
status: number;
|
|
79
|
+
/** Loan nonce for uniqueness */
|
|
80
|
+
nonce: bigint;
|
|
81
|
+
/** PDA bump */
|
|
82
|
+
bump: number;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type PoolLoanArgs = {
|
|
86
|
+
/** Maker (borrower) who took this loan */
|
|
87
|
+
maker: Address;
|
|
88
|
+
/** Vault this loan is from */
|
|
89
|
+
vault: Address;
|
|
90
|
+
/**
|
|
91
|
+
* Escrow state PDA that validates maker/mint binding
|
|
92
|
+
* The actual token account is derived from escrow_authority_v2
|
|
93
|
+
*/
|
|
94
|
+
escrowState: Address;
|
|
95
|
+
/** Principal borrowed */
|
|
96
|
+
principal: number | bigint;
|
|
97
|
+
/** Interest rate at time of borrow (from vault's dynamic rate) */
|
|
98
|
+
rateBps: number;
|
|
99
|
+
/** Accrued interest (computed from slots) */
|
|
100
|
+
accruedInterest: number | bigint;
|
|
101
|
+
/** Protocol fees accrued */
|
|
102
|
+
accruedProtocolFees: number | bigint;
|
|
103
|
+
/** Collateral amount provided */
|
|
104
|
+
collateral: number | bigint;
|
|
105
|
+
/** Slot when loan started */
|
|
106
|
+
startSlot: number | bigint;
|
|
107
|
+
/** Last slot when interest was updated */
|
|
108
|
+
lastUpdateSlot: number | bigint;
|
|
109
|
+
/** Loan status: 1=Active, 2=Repaid, 3=Liquidated */
|
|
110
|
+
status: number;
|
|
111
|
+
/** Loan nonce for uniqueness */
|
|
112
|
+
nonce: number | bigint;
|
|
113
|
+
/** PDA bump */
|
|
114
|
+
bump: number;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** Gets the encoder for {@link PoolLoanArgs} account data. */
|
|
118
|
+
export function getPoolLoanEncoder(): FixedSizeEncoder<PoolLoanArgs> {
|
|
119
|
+
return transformEncoder(
|
|
120
|
+
getStructEncoder([
|
|
121
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
122
|
+
["maker", getAddressEncoder()],
|
|
123
|
+
["vault", getAddressEncoder()],
|
|
124
|
+
["escrowState", getAddressEncoder()],
|
|
125
|
+
["principal", getU64Encoder()],
|
|
126
|
+
["rateBps", getU16Encoder()],
|
|
127
|
+
["accruedInterest", getU64Encoder()],
|
|
128
|
+
["accruedProtocolFees", getU64Encoder()],
|
|
129
|
+
["collateral", getU64Encoder()],
|
|
130
|
+
["startSlot", getU64Encoder()],
|
|
131
|
+
["lastUpdateSlot", getU64Encoder()],
|
|
132
|
+
["status", getU8Encoder()],
|
|
133
|
+
["nonce", getU64Encoder()],
|
|
134
|
+
["bump", getU8Encoder()],
|
|
135
|
+
]),
|
|
136
|
+
(value) => ({ ...value, discriminator: POOL_LOAN_DISCRIMINATOR }),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Gets the decoder for {@link PoolLoan} account data. */
|
|
141
|
+
export function getPoolLoanDecoder(): FixedSizeDecoder<PoolLoan> {
|
|
142
|
+
return getStructDecoder([
|
|
143
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
144
|
+
["maker", getAddressDecoder()],
|
|
145
|
+
["vault", getAddressDecoder()],
|
|
146
|
+
["escrowState", getAddressDecoder()],
|
|
147
|
+
["principal", getU64Decoder()],
|
|
148
|
+
["rateBps", getU16Decoder()],
|
|
149
|
+
["accruedInterest", getU64Decoder()],
|
|
150
|
+
["accruedProtocolFees", getU64Decoder()],
|
|
151
|
+
["collateral", getU64Decoder()],
|
|
152
|
+
["startSlot", getU64Decoder()],
|
|
153
|
+
["lastUpdateSlot", getU64Decoder()],
|
|
154
|
+
["status", getU8Decoder()],
|
|
155
|
+
["nonce", getU64Decoder()],
|
|
156
|
+
["bump", getU8Decoder()],
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Gets the codec for {@link PoolLoan} account data. */
|
|
161
|
+
export function getPoolLoanCodec(): FixedSizeCodec<PoolLoanArgs, PoolLoan> {
|
|
162
|
+
return combineCodec(getPoolLoanEncoder(), getPoolLoanDecoder());
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function decodePoolLoan<TAddress extends string = string>(
|
|
166
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
167
|
+
): Account<PoolLoan, TAddress>;
|
|
168
|
+
export function decodePoolLoan<TAddress extends string = string>(
|
|
169
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
170
|
+
): MaybeAccount<PoolLoan, TAddress>;
|
|
171
|
+
export function decodePoolLoan<TAddress extends string = string>(
|
|
172
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
173
|
+
): Account<PoolLoan, TAddress> | MaybeAccount<PoolLoan, TAddress> {
|
|
174
|
+
return decodeAccount(
|
|
175
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
176
|
+
getPoolLoanDecoder(),
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export async function fetchPoolLoan<TAddress extends string = string>(
|
|
181
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
182
|
+
address: Address<TAddress>,
|
|
183
|
+
config?: FetchAccountConfig,
|
|
184
|
+
): Promise<Account<PoolLoan, TAddress>> {
|
|
185
|
+
const maybeAccount = await fetchMaybePoolLoan(rpc, address, config);
|
|
186
|
+
assertAccountExists(maybeAccount);
|
|
187
|
+
return maybeAccount;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export async function fetchMaybePoolLoan<TAddress extends string = string>(
|
|
191
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
192
|
+
address: Address<TAddress>,
|
|
193
|
+
config?: FetchAccountConfig,
|
|
194
|
+
): Promise<MaybeAccount<PoolLoan, TAddress>> {
|
|
195
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
196
|
+
return decodePoolLoan(maybeAccount);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function fetchAllPoolLoan(
|
|
200
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
201
|
+
addresses: Array<Address>,
|
|
202
|
+
config?: FetchAccountsConfig,
|
|
203
|
+
): Promise<Account<PoolLoan>[]> {
|
|
204
|
+
const maybeAccounts = await fetchAllMaybePoolLoan(rpc, addresses, config);
|
|
205
|
+
assertAccountsExist(maybeAccounts);
|
|
206
|
+
return maybeAccounts;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export async function fetchAllMaybePoolLoan(
|
|
210
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
211
|
+
addresses: Array<Address>,
|
|
212
|
+
config?: FetchAccountsConfig,
|
|
213
|
+
): Promise<MaybeAccount<PoolLoan>[]> {
|
|
214
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
215
|
+
return maybeAccounts.map((maybeAccount) => decodePoolLoan(maybeAccount));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function getPoolLoanSize(): number {
|
|
219
|
+
return 164;
|
|
220
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
getU64Decoder,
|
|
29
|
+
getU64Encoder,
|
|
30
|
+
transformEncoder,
|
|
31
|
+
type Account,
|
|
32
|
+
type Address,
|
|
33
|
+
type EncodedAccount,
|
|
34
|
+
type FetchAccountConfig,
|
|
35
|
+
type FetchAccountsConfig,
|
|
36
|
+
type FixedSizeCodec,
|
|
37
|
+
type FixedSizeDecoder,
|
|
38
|
+
type FixedSizeEncoder,
|
|
39
|
+
type MaybeAccount,
|
|
40
|
+
type MaybeEncodedAccount,
|
|
41
|
+
type ReadonlyUint8Array,
|
|
42
|
+
} from "@solana/kit";
|
|
43
|
+
|
|
44
|
+
export const POSITION_ACCOUNT_DISCRIMINATOR = new Uint8Array([
|
|
45
|
+
60, 125, 250, 193, 181, 109, 238, 86,
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
export function getPositionAccountDiscriminatorBytes() {
|
|
49
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
50
|
+
POSITION_ACCOUNT_DISCRIMINATOR,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type PositionAccount = {
|
|
55
|
+
discriminator: ReadonlyUint8Array;
|
|
56
|
+
buyer: Address;
|
|
57
|
+
optionAccount: Address;
|
|
58
|
+
quantity: bigint;
|
|
59
|
+
premiumPaid: bigint;
|
|
60
|
+
openedAt: bigint;
|
|
61
|
+
closedAt: bigint;
|
|
62
|
+
isClosed: boolean;
|
|
63
|
+
isExercised: boolean;
|
|
64
|
+
pnl: bigint;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type PositionAccountArgs = {
|
|
68
|
+
buyer: Address;
|
|
69
|
+
optionAccount: Address;
|
|
70
|
+
quantity: number | bigint;
|
|
71
|
+
premiumPaid: number | bigint;
|
|
72
|
+
openedAt: number | bigint;
|
|
73
|
+
closedAt: number | bigint;
|
|
74
|
+
isClosed: boolean;
|
|
75
|
+
isExercised: boolean;
|
|
76
|
+
pnl: number | bigint;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Gets the encoder for {@link PositionAccountArgs} account data. */
|
|
80
|
+
export function getPositionAccountEncoder(): FixedSizeEncoder<PositionAccountArgs> {
|
|
81
|
+
return transformEncoder(
|
|
82
|
+
getStructEncoder([
|
|
83
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
84
|
+
["buyer", getAddressEncoder()],
|
|
85
|
+
["optionAccount", getAddressEncoder()],
|
|
86
|
+
["quantity", getU64Encoder()],
|
|
87
|
+
["premiumPaid", getU64Encoder()],
|
|
88
|
+
["openedAt", getI64Encoder()],
|
|
89
|
+
["closedAt", getI64Encoder()],
|
|
90
|
+
["isClosed", getBooleanEncoder()],
|
|
91
|
+
["isExercised", getBooleanEncoder()],
|
|
92
|
+
["pnl", getI64Encoder()],
|
|
93
|
+
]),
|
|
94
|
+
(value) => ({ ...value, discriminator: POSITION_ACCOUNT_DISCRIMINATOR }),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Gets the decoder for {@link PositionAccount} account data. */
|
|
99
|
+
export function getPositionAccountDecoder(): FixedSizeDecoder<PositionAccount> {
|
|
100
|
+
return getStructDecoder([
|
|
101
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
102
|
+
["buyer", getAddressDecoder()],
|
|
103
|
+
["optionAccount", getAddressDecoder()],
|
|
104
|
+
["quantity", getU64Decoder()],
|
|
105
|
+
["premiumPaid", getU64Decoder()],
|
|
106
|
+
["openedAt", getI64Decoder()],
|
|
107
|
+
["closedAt", getI64Decoder()],
|
|
108
|
+
["isClosed", getBooleanDecoder()],
|
|
109
|
+
["isExercised", getBooleanDecoder()],
|
|
110
|
+
["pnl", getI64Decoder()],
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Gets the codec for {@link PositionAccount} account data. */
|
|
115
|
+
export function getPositionAccountCodec(): FixedSizeCodec<
|
|
116
|
+
PositionAccountArgs,
|
|
117
|
+
PositionAccount
|
|
118
|
+
> {
|
|
119
|
+
return combineCodec(getPositionAccountEncoder(), getPositionAccountDecoder());
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function decodePositionAccount<TAddress extends string = string>(
|
|
123
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
124
|
+
): Account<PositionAccount, TAddress>;
|
|
125
|
+
export function decodePositionAccount<TAddress extends string = string>(
|
|
126
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
127
|
+
): MaybeAccount<PositionAccount, TAddress>;
|
|
128
|
+
export function decodePositionAccount<TAddress extends string = string>(
|
|
129
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
130
|
+
):
|
|
131
|
+
| Account<PositionAccount, TAddress>
|
|
132
|
+
| MaybeAccount<PositionAccount, TAddress> {
|
|
133
|
+
return decodeAccount(
|
|
134
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
135
|
+
getPositionAccountDecoder(),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function fetchPositionAccount<TAddress extends string = string>(
|
|
140
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
141
|
+
address: Address<TAddress>,
|
|
142
|
+
config?: FetchAccountConfig,
|
|
143
|
+
): Promise<Account<PositionAccount, TAddress>> {
|
|
144
|
+
const maybeAccount = await fetchMaybePositionAccount(rpc, address, config);
|
|
145
|
+
assertAccountExists(maybeAccount);
|
|
146
|
+
return maybeAccount;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function fetchMaybePositionAccount<
|
|
150
|
+
TAddress extends string = string,
|
|
151
|
+
>(
|
|
152
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
153
|
+
address: Address<TAddress>,
|
|
154
|
+
config?: FetchAccountConfig,
|
|
155
|
+
): Promise<MaybeAccount<PositionAccount, TAddress>> {
|
|
156
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
157
|
+
return decodePositionAccount(maybeAccount);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export async function fetchAllPositionAccount(
|
|
161
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
162
|
+
addresses: Array<Address>,
|
|
163
|
+
config?: FetchAccountsConfig,
|
|
164
|
+
): Promise<Account<PositionAccount>[]> {
|
|
165
|
+
const maybeAccounts = await fetchAllMaybePositionAccount(
|
|
166
|
+
rpc,
|
|
167
|
+
addresses,
|
|
168
|
+
config,
|
|
169
|
+
);
|
|
170
|
+
assertAccountsExist(maybeAccounts);
|
|
171
|
+
return maybeAccounts;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function fetchAllMaybePositionAccount(
|
|
175
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
176
|
+
addresses: Array<Address>,
|
|
177
|
+
config?: FetchAccountsConfig,
|
|
178
|
+
): Promise<MaybeAccount<PositionAccount>[]> {
|
|
179
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
180
|
+
return maybeAccounts.map((maybeAccount) =>
|
|
181
|
+
decodePositionAccount(maybeAccount),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function getPositionAccountSize(): number {
|
|
186
|
+
return 114;
|
|
187
|
+
}
|