@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,163 @@
|
|
|
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
|
+
getU64Decoder,
|
|
25
|
+
getU64Encoder,
|
|
26
|
+
transformEncoder,
|
|
27
|
+
type Account,
|
|
28
|
+
type Address,
|
|
29
|
+
type Codec,
|
|
30
|
+
type Decoder,
|
|
31
|
+
type EncodedAccount,
|
|
32
|
+
type Encoder,
|
|
33
|
+
type FetchAccountConfig,
|
|
34
|
+
type FetchAccountsConfig,
|
|
35
|
+
type MaybeAccount,
|
|
36
|
+
type MaybeEncodedAccount,
|
|
37
|
+
type ReadonlyUint8Array,
|
|
38
|
+
} from "@solana/kit";
|
|
39
|
+
import {
|
|
40
|
+
getPriceFeedMessageDecoder,
|
|
41
|
+
getPriceFeedMessageEncoder,
|
|
42
|
+
getVerificationLevelDecoder,
|
|
43
|
+
getVerificationLevelEncoder,
|
|
44
|
+
type PriceFeedMessage,
|
|
45
|
+
type PriceFeedMessageArgs,
|
|
46
|
+
type VerificationLevel,
|
|
47
|
+
type VerificationLevelArgs,
|
|
48
|
+
} from "../types";
|
|
49
|
+
|
|
50
|
+
export const PRICE_UPDATE_V2_DISCRIMINATOR = new Uint8Array([
|
|
51
|
+
34, 241, 35, 99, 157, 126, 244, 205,
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
export function getPriceUpdateV2DiscriminatorBytes() {
|
|
55
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
56
|
+
PRICE_UPDATE_V2_DISCRIMINATOR,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type PriceUpdateV2 = {
|
|
61
|
+
discriminator: ReadonlyUint8Array;
|
|
62
|
+
writeAuthority: Address;
|
|
63
|
+
verificationLevel: VerificationLevel;
|
|
64
|
+
priceMessage: PriceFeedMessage;
|
|
65
|
+
postedSlot: bigint;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type PriceUpdateV2Args = {
|
|
69
|
+
writeAuthority: Address;
|
|
70
|
+
verificationLevel: VerificationLevelArgs;
|
|
71
|
+
priceMessage: PriceFeedMessageArgs;
|
|
72
|
+
postedSlot: number | bigint;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** Gets the encoder for {@link PriceUpdateV2Args} account data. */
|
|
76
|
+
export function getPriceUpdateV2Encoder(): Encoder<PriceUpdateV2Args> {
|
|
77
|
+
return transformEncoder(
|
|
78
|
+
getStructEncoder([
|
|
79
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
80
|
+
["writeAuthority", getAddressEncoder()],
|
|
81
|
+
["verificationLevel", getVerificationLevelEncoder()],
|
|
82
|
+
["priceMessage", getPriceFeedMessageEncoder()],
|
|
83
|
+
["postedSlot", getU64Encoder()],
|
|
84
|
+
]),
|
|
85
|
+
(value) => ({ ...value, discriminator: PRICE_UPDATE_V2_DISCRIMINATOR }),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Gets the decoder for {@link PriceUpdateV2} account data. */
|
|
90
|
+
export function getPriceUpdateV2Decoder(): Decoder<PriceUpdateV2> {
|
|
91
|
+
return getStructDecoder([
|
|
92
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
93
|
+
["writeAuthority", getAddressDecoder()],
|
|
94
|
+
["verificationLevel", getVerificationLevelDecoder()],
|
|
95
|
+
["priceMessage", getPriceFeedMessageDecoder()],
|
|
96
|
+
["postedSlot", getU64Decoder()],
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Gets the codec for {@link PriceUpdateV2} account data. */
|
|
101
|
+
export function getPriceUpdateV2Codec(): Codec<
|
|
102
|
+
PriceUpdateV2Args,
|
|
103
|
+
PriceUpdateV2
|
|
104
|
+
> {
|
|
105
|
+
return combineCodec(getPriceUpdateV2Encoder(), getPriceUpdateV2Decoder());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function decodePriceUpdateV2<TAddress extends string = string>(
|
|
109
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
110
|
+
): Account<PriceUpdateV2, TAddress>;
|
|
111
|
+
export function decodePriceUpdateV2<TAddress extends string = string>(
|
|
112
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
113
|
+
): MaybeAccount<PriceUpdateV2, TAddress>;
|
|
114
|
+
export function decodePriceUpdateV2<TAddress extends string = string>(
|
|
115
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
116
|
+
): Account<PriceUpdateV2, TAddress> | MaybeAccount<PriceUpdateV2, TAddress> {
|
|
117
|
+
return decodeAccount(
|
|
118
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
119
|
+
getPriceUpdateV2Decoder(),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function fetchPriceUpdateV2<TAddress extends string = string>(
|
|
124
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
125
|
+
address: Address<TAddress>,
|
|
126
|
+
config?: FetchAccountConfig,
|
|
127
|
+
): Promise<Account<PriceUpdateV2, TAddress>> {
|
|
128
|
+
const maybeAccount = await fetchMaybePriceUpdateV2(rpc, address, config);
|
|
129
|
+
assertAccountExists(maybeAccount);
|
|
130
|
+
return maybeAccount;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function fetchMaybePriceUpdateV2<TAddress extends string = string>(
|
|
134
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
135
|
+
address: Address<TAddress>,
|
|
136
|
+
config?: FetchAccountConfig,
|
|
137
|
+
): Promise<MaybeAccount<PriceUpdateV2, TAddress>> {
|
|
138
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
139
|
+
return decodePriceUpdateV2(maybeAccount);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function fetchAllPriceUpdateV2(
|
|
143
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
144
|
+
addresses: Array<Address>,
|
|
145
|
+
config?: FetchAccountsConfig,
|
|
146
|
+
): Promise<Account<PriceUpdateV2>[]> {
|
|
147
|
+
const maybeAccounts = await fetchAllMaybePriceUpdateV2(
|
|
148
|
+
rpc,
|
|
149
|
+
addresses,
|
|
150
|
+
config,
|
|
151
|
+
);
|
|
152
|
+
assertAccountsExist(maybeAccounts);
|
|
153
|
+
return maybeAccounts;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export async function fetchAllMaybePriceUpdateV2(
|
|
157
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
158
|
+
addresses: Array<Address>,
|
|
159
|
+
config?: FetchAccountsConfig,
|
|
160
|
+
): Promise<MaybeAccount<PriceUpdateV2>[]> {
|
|
161
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
162
|
+
return maybeAccounts.map((maybeAccount) => decodePriceUpdateV2(maybeAccount));
|
|
163
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was AUTOGENERATED using the Codama library.
|
|
3
|
+
* Please DO NOT EDIT THIS FILE, instead use visitors
|
|
4
|
+
* to add features, then rerun Codama to update it.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/codama-idl/codama
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
assertAccountExists,
|
|
11
|
+
assertAccountsExist,
|
|
12
|
+
combineCodec,
|
|
13
|
+
decodeAccount,
|
|
14
|
+
fetchEncodedAccount,
|
|
15
|
+
fetchEncodedAccounts,
|
|
16
|
+
fixDecoderSize,
|
|
17
|
+
fixEncoderSize,
|
|
18
|
+
getAddressDecoder,
|
|
19
|
+
getAddressEncoder,
|
|
20
|
+
getBytesDecoder,
|
|
21
|
+
getBytesEncoder,
|
|
22
|
+
getI64Decoder,
|
|
23
|
+
getI64Encoder,
|
|
24
|
+
getStructDecoder,
|
|
25
|
+
getStructEncoder,
|
|
26
|
+
getU128Decoder,
|
|
27
|
+
getU128Encoder,
|
|
28
|
+
getU16Decoder,
|
|
29
|
+
getU16Encoder,
|
|
30
|
+
getU64Decoder,
|
|
31
|
+
getU64Encoder,
|
|
32
|
+
getU8Decoder,
|
|
33
|
+
getU8Encoder,
|
|
34
|
+
transformEncoder,
|
|
35
|
+
type Account,
|
|
36
|
+
type Address,
|
|
37
|
+
type EncodedAccount,
|
|
38
|
+
type FetchAccountConfig,
|
|
39
|
+
type FetchAccountsConfig,
|
|
40
|
+
type FixedSizeCodec,
|
|
41
|
+
type FixedSizeDecoder,
|
|
42
|
+
type FixedSizeEncoder,
|
|
43
|
+
type MaybeAccount,
|
|
44
|
+
type MaybeEncodedAccount,
|
|
45
|
+
type ReadonlyUint8Array,
|
|
46
|
+
} from "@solana/kit";
|
|
47
|
+
|
|
48
|
+
export const VAULT_DISCRIMINATOR = new Uint8Array([
|
|
49
|
+
211, 8, 232, 43, 2, 152, 117, 119,
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export function getVaultDiscriminatorBytes() {
|
|
53
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(VAULT_DISCRIMINATOR);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type Vault = {
|
|
57
|
+
discriminator: ReadonlyUint8Array;
|
|
58
|
+
/** The mint this vault holds (SOL wrapper or USDC) */
|
|
59
|
+
mint: Address;
|
|
60
|
+
/** PDA bump */
|
|
61
|
+
bump: number;
|
|
62
|
+
/** Total liquidity deposited by lenders */
|
|
63
|
+
totalLiquidity: bigint;
|
|
64
|
+
/** Total amount currently loaned out */
|
|
65
|
+
totalLoans: bigint;
|
|
66
|
+
/**
|
|
67
|
+
* Protocol fee charged on borrow interest (basis points)
|
|
68
|
+
* Example: 200-300 bps (2-3%) on top of lender APR
|
|
69
|
+
*/
|
|
70
|
+
protocolFeeBps: number;
|
|
71
|
+
/** Liquidation threshold (basis points) */
|
|
72
|
+
liqThresholdBps: number;
|
|
73
|
+
/**
|
|
74
|
+
* Maximum leverage allowed for borrowing
|
|
75
|
+
* Example: 1000 = 10x leverage, 10000 = 100x leverage
|
|
76
|
+
* Configurable by admin (1x to 100x)
|
|
77
|
+
*/
|
|
78
|
+
maxLeverageMultiplier: number;
|
|
79
|
+
/** Keeper/admin authority */
|
|
80
|
+
keeper: Address;
|
|
81
|
+
/** Epicentral fee wallet (receives protocol fees) */
|
|
82
|
+
feeWallet: Address;
|
|
83
|
+
/** Total protocol fees accumulated (in vault's asset) */
|
|
84
|
+
totalProtocolFees: bigint;
|
|
85
|
+
/** Vault creation timestamp */
|
|
86
|
+
createdAt: bigint;
|
|
87
|
+
/** Last update timestamp */
|
|
88
|
+
lastUpdated: bigint;
|
|
89
|
+
/**
|
|
90
|
+
* Base borrow rate when utilization = 0% (basis points)
|
|
91
|
+
* Example: 500 bps = 5% base rate
|
|
92
|
+
*/
|
|
93
|
+
baseRateBps: number;
|
|
94
|
+
/**
|
|
95
|
+
* Optimal utilization rate target (basis points)
|
|
96
|
+
* Example: 8000 = 80% optimal utilization
|
|
97
|
+
*/
|
|
98
|
+
optimalUtilizationBps: number;
|
|
99
|
+
/**
|
|
100
|
+
* Rate slope below optimal utilization (basis points)
|
|
101
|
+
* Example: 1000 = 10% slope
|
|
102
|
+
*/
|
|
103
|
+
rateSlope1Bps: number;
|
|
104
|
+
/**
|
|
105
|
+
* Rate slope above optimal utilization (basis points)
|
|
106
|
+
* Example: 15000 = 150% steep slope when over-utilized
|
|
107
|
+
*/
|
|
108
|
+
rateSlope2Bps: number;
|
|
109
|
+
/**
|
|
110
|
+
* Fixed supply limit for this vault (in lamports/base units)
|
|
111
|
+
* Set by admin, enforced on deposits. 0 = unlimited.
|
|
112
|
+
*/
|
|
113
|
+
supplyLimit: bigint;
|
|
114
|
+
/**
|
|
115
|
+
* Cumulative interest earned per deposited unit (fixed-point)
|
|
116
|
+
* Increases whenever loans are repaid/liquidated
|
|
117
|
+
*/
|
|
118
|
+
accInterestPerShareFp: bigint;
|
|
119
|
+
/** Last slot when interest index was updated */
|
|
120
|
+
lastInterestUpdateSlot: bigint;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export type VaultArgs = {
|
|
124
|
+
/** The mint this vault holds (SOL wrapper or USDC) */
|
|
125
|
+
mint: Address;
|
|
126
|
+
/** PDA bump */
|
|
127
|
+
bump: number;
|
|
128
|
+
/** Total liquidity deposited by lenders */
|
|
129
|
+
totalLiquidity: number | bigint;
|
|
130
|
+
/** Total amount currently loaned out */
|
|
131
|
+
totalLoans: number | bigint;
|
|
132
|
+
/**
|
|
133
|
+
* Protocol fee charged on borrow interest (basis points)
|
|
134
|
+
* Example: 200-300 bps (2-3%) on top of lender APR
|
|
135
|
+
*/
|
|
136
|
+
protocolFeeBps: number;
|
|
137
|
+
/** Liquidation threshold (basis points) */
|
|
138
|
+
liqThresholdBps: number;
|
|
139
|
+
/**
|
|
140
|
+
* Maximum leverage allowed for borrowing
|
|
141
|
+
* Example: 1000 = 10x leverage, 10000 = 100x leverage
|
|
142
|
+
* Configurable by admin (1x to 100x)
|
|
143
|
+
*/
|
|
144
|
+
maxLeverageMultiplier: number;
|
|
145
|
+
/** Keeper/admin authority */
|
|
146
|
+
keeper: Address;
|
|
147
|
+
/** Epicentral fee wallet (receives protocol fees) */
|
|
148
|
+
feeWallet: Address;
|
|
149
|
+
/** Total protocol fees accumulated (in vault's asset) */
|
|
150
|
+
totalProtocolFees: number | bigint;
|
|
151
|
+
/** Vault creation timestamp */
|
|
152
|
+
createdAt: number | bigint;
|
|
153
|
+
/** Last update timestamp */
|
|
154
|
+
lastUpdated: number | bigint;
|
|
155
|
+
/**
|
|
156
|
+
* Base borrow rate when utilization = 0% (basis points)
|
|
157
|
+
* Example: 500 bps = 5% base rate
|
|
158
|
+
*/
|
|
159
|
+
baseRateBps: number;
|
|
160
|
+
/**
|
|
161
|
+
* Optimal utilization rate target (basis points)
|
|
162
|
+
* Example: 8000 = 80% optimal utilization
|
|
163
|
+
*/
|
|
164
|
+
optimalUtilizationBps: number;
|
|
165
|
+
/**
|
|
166
|
+
* Rate slope below optimal utilization (basis points)
|
|
167
|
+
* Example: 1000 = 10% slope
|
|
168
|
+
*/
|
|
169
|
+
rateSlope1Bps: number;
|
|
170
|
+
/**
|
|
171
|
+
* Rate slope above optimal utilization (basis points)
|
|
172
|
+
* Example: 15000 = 150% steep slope when over-utilized
|
|
173
|
+
*/
|
|
174
|
+
rateSlope2Bps: number;
|
|
175
|
+
/**
|
|
176
|
+
* Fixed supply limit for this vault (in lamports/base units)
|
|
177
|
+
* Set by admin, enforced on deposits. 0 = unlimited.
|
|
178
|
+
*/
|
|
179
|
+
supplyLimit: number | bigint;
|
|
180
|
+
/**
|
|
181
|
+
* Cumulative interest earned per deposited unit (fixed-point)
|
|
182
|
+
* Increases whenever loans are repaid/liquidated
|
|
183
|
+
*/
|
|
184
|
+
accInterestPerShareFp: number | bigint;
|
|
185
|
+
/** Last slot when interest index was updated */
|
|
186
|
+
lastInterestUpdateSlot: number | bigint;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** Gets the encoder for {@link VaultArgs} account data. */
|
|
190
|
+
export function getVaultEncoder(): FixedSizeEncoder<VaultArgs> {
|
|
191
|
+
return transformEncoder(
|
|
192
|
+
getStructEncoder([
|
|
193
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
194
|
+
["mint", getAddressEncoder()],
|
|
195
|
+
["bump", getU8Encoder()],
|
|
196
|
+
["totalLiquidity", getU64Encoder()],
|
|
197
|
+
["totalLoans", getU64Encoder()],
|
|
198
|
+
["protocolFeeBps", getU16Encoder()],
|
|
199
|
+
["liqThresholdBps", getU16Encoder()],
|
|
200
|
+
["maxLeverageMultiplier", getU16Encoder()],
|
|
201
|
+
["keeper", getAddressEncoder()],
|
|
202
|
+
["feeWallet", getAddressEncoder()],
|
|
203
|
+
["totalProtocolFees", getU64Encoder()],
|
|
204
|
+
["createdAt", getI64Encoder()],
|
|
205
|
+
["lastUpdated", getI64Encoder()],
|
|
206
|
+
["baseRateBps", getU16Encoder()],
|
|
207
|
+
["optimalUtilizationBps", getU16Encoder()],
|
|
208
|
+
["rateSlope1Bps", getU16Encoder()],
|
|
209
|
+
["rateSlope2Bps", getU16Encoder()],
|
|
210
|
+
["supplyLimit", getU64Encoder()],
|
|
211
|
+
["accInterestPerShareFp", getU128Encoder()],
|
|
212
|
+
["lastInterestUpdateSlot", getU64Encoder()],
|
|
213
|
+
]),
|
|
214
|
+
(value) => ({ ...value, discriminator: VAULT_DISCRIMINATOR }),
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Gets the decoder for {@link Vault} account data. */
|
|
219
|
+
export function getVaultDecoder(): FixedSizeDecoder<Vault> {
|
|
220
|
+
return getStructDecoder([
|
|
221
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
222
|
+
["mint", getAddressDecoder()],
|
|
223
|
+
["bump", getU8Decoder()],
|
|
224
|
+
["totalLiquidity", getU64Decoder()],
|
|
225
|
+
["totalLoans", getU64Decoder()],
|
|
226
|
+
["protocolFeeBps", getU16Decoder()],
|
|
227
|
+
["liqThresholdBps", getU16Decoder()],
|
|
228
|
+
["maxLeverageMultiplier", getU16Decoder()],
|
|
229
|
+
["keeper", getAddressDecoder()],
|
|
230
|
+
["feeWallet", getAddressDecoder()],
|
|
231
|
+
["totalProtocolFees", getU64Decoder()],
|
|
232
|
+
["createdAt", getI64Decoder()],
|
|
233
|
+
["lastUpdated", getI64Decoder()],
|
|
234
|
+
["baseRateBps", getU16Decoder()],
|
|
235
|
+
["optimalUtilizationBps", getU16Decoder()],
|
|
236
|
+
["rateSlope1Bps", getU16Decoder()],
|
|
237
|
+
["rateSlope2Bps", getU16Decoder()],
|
|
238
|
+
["supplyLimit", getU64Decoder()],
|
|
239
|
+
["accInterestPerShareFp", getU128Decoder()],
|
|
240
|
+
["lastInterestUpdateSlot", getU64Decoder()],
|
|
241
|
+
]);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Gets the codec for {@link Vault} account data. */
|
|
245
|
+
export function getVaultCodec(): FixedSizeCodec<VaultArgs, Vault> {
|
|
246
|
+
return combineCodec(getVaultEncoder(), getVaultDecoder());
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function decodeVault<TAddress extends string = string>(
|
|
250
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
251
|
+
): Account<Vault, TAddress>;
|
|
252
|
+
export function decodeVault<TAddress extends string = string>(
|
|
253
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
254
|
+
): MaybeAccount<Vault, TAddress>;
|
|
255
|
+
export function decodeVault<TAddress extends string = string>(
|
|
256
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
257
|
+
): Account<Vault, TAddress> | MaybeAccount<Vault, TAddress> {
|
|
258
|
+
return decodeAccount(
|
|
259
|
+
encodedAccount as MaybeEncodedAccount<TAddress>,
|
|
260
|
+
getVaultDecoder(),
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export async function fetchVault<TAddress extends string = string>(
|
|
265
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
266
|
+
address: Address<TAddress>,
|
|
267
|
+
config?: FetchAccountConfig,
|
|
268
|
+
): Promise<Account<Vault, TAddress>> {
|
|
269
|
+
const maybeAccount = await fetchMaybeVault(rpc, address, config);
|
|
270
|
+
assertAccountExists(maybeAccount);
|
|
271
|
+
return maybeAccount;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export async function fetchMaybeVault<TAddress extends string = string>(
|
|
275
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
276
|
+
address: Address<TAddress>,
|
|
277
|
+
config?: FetchAccountConfig,
|
|
278
|
+
): Promise<MaybeAccount<Vault, TAddress>> {
|
|
279
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
280
|
+
return decodeVault(maybeAccount);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export async function fetchAllVault(
|
|
284
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
285
|
+
addresses: Array<Address>,
|
|
286
|
+
config?: FetchAccountsConfig,
|
|
287
|
+
): Promise<Account<Vault>[]> {
|
|
288
|
+
const maybeAccounts = await fetchAllMaybeVault(rpc, addresses, config);
|
|
289
|
+
assertAccountsExist(maybeAccounts);
|
|
290
|
+
return maybeAccounts;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export async function fetchAllMaybeVault(
|
|
294
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
295
|
+
addresses: Array<Address>,
|
|
296
|
+
config?: FetchAccountsConfig,
|
|
297
|
+
): Promise<MaybeAccount<Vault>[]> {
|
|
298
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
299
|
+
return maybeAccounts.map((maybeAccount) => decodeVault(maybeAccount));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export function getVaultSize(): number {
|
|
303
|
+
return 191;
|
|
304
|
+
}
|