Skip to content

Commit 1481453

Browse files
committed
Add parser for v2 reserves
1 parent 859cc0d commit 1481453

3 files changed

Lines changed: 39 additions & 9 deletions

File tree

solend-sdk/src/core/utils/pools.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ export async function fetchPools(
1313
programId: string,
1414
debug?: boolean
1515
) {
16-
const reserves = (await getReservesFromChain(
17-
connection,
18-
switchboardProgram,
19-
programId,
20-
debug
21-
)).sort((a, b) => a.totalSupply.isGreaterThan(b.totalSupply) ? -1 : 1);
16+
const reserves = (
17+
await getReservesFromChain(connection, switchboardProgram, programId, debug)
18+
).sort((a, b) => (a.totalSupply.isGreaterThan(b.totalSupply) ? -1 : 1));
2219

2320
const pools = Object.fromEntries(
2421
oldPools.map((c) => [

solend-sdk/src/state/reserve.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface Reserve {
1313
liquidity: ReserveLiquidity;
1414
collateral: ReserveCollateral;
1515
config: ReserveConfig;
16+
rateLimiter: RateLimiter;
1617
}
1718

1819
export interface ReserveLiquidity {
@@ -26,8 +27,9 @@ export interface ReserveLiquidity {
2627
availableAmount: BN;
2728
borrowedAmountWads: BN;
2829
cumulativeBorrowRateWads: BN;
29-
marketPrice: BN;
3030
accumulatedProtocolFeesWads: BN;
31+
marketPrice: BN;
32+
smoothedMarketPrice: BN;
3133
}
3234

3335
export interface ReserveCollateral {
@@ -54,6 +56,20 @@ export interface ReserveConfig {
5456
feeReceiver: PublicKey;
5557
protocolLiquidationFee: number;
5658
protocolTakeRate: number;
59+
addedBorrowWeightBPS: number;
60+
borrowWeight: number;
61+
}
62+
63+
export interface RateLimiter {
64+
config: RateLimiterConfig;
65+
previousQuantity: BN;
66+
windowStart: number;
67+
currentQuantity: BN;
68+
}
69+
70+
export interface RateLimiterConfig {
71+
windowDuration: BN;
72+
maxOutflow: BN;
5773
}
5874

5975
export const ReserveConfigLayout = BufferLayout.struct(
@@ -78,6 +94,7 @@ export const ReserveConfigLayout = BufferLayout.struct(
7894
Layout.publicKey("feeReceiver"),
7995
BufferLayout.u8("protocolLiquidationFee"),
8096
BufferLayout.u8("protocolTakeRate"),
97+
Layout.uint64("addedBorrowWeightBPS"),
8198
],
8299
"config"
83100
);
@@ -87,7 +104,6 @@ export const ReserveLayout: typeof BufferLayout.Structure = BufferLayout.struct(
87104
BufferLayout.u8("version"),
88105
LastUpdateLayout,
89106
Layout.publicKey("lendingMarket"),
90-
91107
Layout.publicKey("liquidityMintPubkey"),
92108
BufferLayout.u8("liquidityMintDecimals"),
93109
Layout.publicKey("liquiditySupplyPubkey"),
@@ -121,7 +137,20 @@ export const ReserveLayout: typeof BufferLayout.Structure = BufferLayout.struct(
121137
BufferLayout.u8("protocolLiquidationFee"),
122138
BufferLayout.u8("protocolTakeRate"),
123139
Layout.uint128("accumulatedProtocolFeesWads"),
124-
BufferLayout.blob(230, "padding"),
140+
141+
BufferLayout.struct(
142+
[
143+
Layout.uint64("maxOutflow"),
144+
Layout.uint64("windowDuration"),
145+
Layout.uint128("previousQuantity"),
146+
Layout.uint64("windowStart"),
147+
Layout.uint128("currentQuantity"),
148+
],
149+
"rateLimiter"
150+
),
151+
BufferLayout.u64("addedBorrowWeightBPS"),
152+
Layout.uint128("liquiditySmoothedMarketPrice"),
153+
BufferLayout.blob(150, "padding"),
125154
]
126155
);
127156

@@ -144,6 +173,7 @@ function decodeReserve(buffer: Buffer): Reserve {
144173
cumulativeBorrowRateWads: reserve.liquidityCumulativeBorrowRateWads,
145174
marketPrice: reserve.liquidityMarketPrice,
146175
accumulatedProtocolFeesWads: reserve.accumulatedProtocolFeesWads,
176+
smoothedMarketPrice: reserve.smoothedMarketPrice,
147177
},
148178
collateral: {
149179
mintPubkey: reserve.collateralMintPubkey,
@@ -168,7 +198,10 @@ function decodeReserve(buffer: Buffer): Reserve {
168198
feeReceiver: reserve.feeReceiver,
169199
protocolLiquidationFee: reserve.protocolLiquidationFee,
170200
protocolTakeRate: reserve.protocolTakeRate,
201+
addedBorrowWeightBPS: reserve.addedBorrowWeightBPS,
202+
borrowWeight: 1 - (1.0 * reserve.borrowWeightBPS) / 10000,
171203
},
204+
rateLimiter: reserve.rateLimiter,
172205
};
173206
}
174207

solend-sdk/src/state/reserveV2.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)