Skip to content

Commit

Permalink
state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xripleys committed Jul 12, 2023
1 parent cc8e20c commit 1aa823d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion solend-sdk/src/instructions/instruction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum LendingInstruction {
InitLendingMarket = 0,
SetLendingMarketOwner = 1,
SetLendingMarketOwnerAndConfig = 1,
InitReserve = 2,
RefreshReserve = 3,
DepositReserveLiquidity = 4,
Expand Down
6 changes: 5 additions & 1 deletion solend-sdk/src/state/lendingMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface LendingMarket {
oracleProgramId: PublicKey;
switchboardOracleProgramId: PublicKey;
rateLimiter: RateLimiter;
whitelistedLiquidator: PublicKey | null;
riskAuthority: PublicKey;
}

export const LendingMarketLayout: typeof BufferLayout.Structure =
Expand All @@ -30,7 +32,9 @@ export const LendingMarketLayout: typeof BufferLayout.Structure =
Layout.publicKey("oracleProgramId"),
Layout.publicKey("switchboardOracleProgramId"),
RateLimiterLayout,
BufferLayout.blob(128 - RATE_LIMITER_LEN, "padding"),
Layout.publicKey("whitelistedLiquidator"),
Layout.publicKey("riskAuthority"),
BufferLayout.blob(8, "padding"),
]);

export const LENDING_MARKET_SIZE = LendingMarketLayout.span;
Expand Down
8 changes: 6 additions & 2 deletions solend-sdk/src/state/obligation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export interface Obligation {
borrows: ObligationLiquidity[];
depositedValue: BN; // decimals
borrowedValue: BN; // decimals
borrowedValueUpperBound: BN; // decimals
allowedBorrowValue: BN; // decimals
unhealthyBorrowValue: BN; // decimals
borrowedValueUpperBound: BN; // decimals
superUnhealthyBorrowValue: BN; // decimals
borrowingIsolatedAsset: boolean;
}

// BN defines toJSON property, which messes up serialization
Expand Down Expand Up @@ -73,7 +75,9 @@ export const ObligationLayout: typeof BufferLayout.Structure =
Layout.uint128("allowedBorrowValue"),
Layout.uint128("unhealthyBorrowValue"),
Layout.uint128("borrowedValueUpperBound"),
BufferLayout.blob(48, "_padding"),
BufferLayout.u8("borrowingIsolatedAsset"),
Layout.uint128("superUnhealthyBorrowValue"),
BufferLayout.blob(31, "_padding"),

BufferLayout.u8("depositsLen"),
BufferLayout.u8("borrowsLen"),
Expand Down
27 changes: 26 additions & 1 deletion solend-sdk/src/state/reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ export interface ReserveCollateral {

export interface ReserveConfig {
optimalUtilizationRate: number;
maxUtilizationRate: number;
loanToValueRatio: number;
liquidationBonus: number;
maxLiquidationBonus: number;
liquidationThreshold: number;
maxLiquidationThreshold: number;
minBorrowRate: number;
optimalBorrowRate: number;
maxBorrowRate: number;
superMaxBorrowRate: BN;
fees: {
borrowFeeWad: BN;
flashLoanFeeWad: BN;
Expand All @@ -61,17 +65,27 @@ export interface ReserveConfig {
protocolTakeRate: number;
addedBorrowWeightBPS: BN;
borrowWeight: BigNumber;
reserveType: ReserveType;
}

export enum ReserveType {
Regular = 0,
Isolated = 1
}

export const ReserveConfigLayout = BufferLayout.struct(
[
BufferLayout.u8("optimalUtilizationRate"),
BufferLayout.u8("maxUtilizationRate"),
BufferLayout.u8("loanToValueRatio"),
BufferLayout.u8("liquidationBonus"),
BufferLayout.u8("maxLiquidationBonus"),
BufferLayout.u8("liquidationThreshold"),
BufferLayout.u8("maxLiquidationThreshold"),
BufferLayout.u8("minBorrowRate"),
BufferLayout.u8("optimalBorrowRate"),
BufferLayout.u8("maxBorrowRate"),
BufferLayout.u8("superMaxBorrowRate"),
BufferLayout.struct(
[
Layout.uint64("borrowFeeWad"),
Expand All @@ -86,6 +100,7 @@ export const ReserveConfigLayout = BufferLayout.struct(
BufferLayout.u8("protocolLiquidationFee"),
BufferLayout.u8("protocolTakeRate"),
Layout.uint64("addedBorrowWeightBPS"),
BufferLayout.u8("reserveType"),
],
"config"
);
Expand Down Expand Up @@ -131,7 +146,12 @@ export const ReserveLayout: typeof BufferLayout.Structure = BufferLayout.struct(
RateLimiterLayout,
Layout.uint64("addedBorrowWeightBPS"),
Layout.uint128("liquiditySmoothedMarketPrice"),
BufferLayout.blob(150, "padding"),
BufferLayout.u8("reserveType"),
BufferLayout.u8("maxUtilizationRate"),
BufferLayout.u8("superMaxBorrowRate"),
BufferLayout.u8("maxLiquidationBonus"),
BufferLayout.u8("maxLiquidationThreshold"),
BufferLayout.blob(138, "padding"),
]
);

Expand Down Expand Up @@ -163,12 +183,16 @@ function decodeReserve(buffer: Buffer): Reserve {
},
config: {
optimalUtilizationRate: reserve.optimalUtilizationRate,
maxUtilizationRate: reserve.maxUtilizationRate,
loanToValueRatio: reserve.loanToValueRatio,
liquidationBonus: reserve.liquidationBonus,
maxLiquidationBonus: reserve.maxLiquidationBonus,
liquidationThreshold: reserve.liquidationThreshold,
maxLiquidationThreshold: reserve.maxLiquidationThreshold,
minBorrowRate: reserve.minBorrowRate,
optimalBorrowRate: reserve.optimalBorrowRate,
maxBorrowRate: reserve.maxBorrowRate,
superMaxBorrowRate: reserve.superMaxBorrowRate,
fees: {
borrowFeeWad: reserve.borrowFeeWad,
flashLoanFeeWad: reserve.flashLoanFeeWad,
Expand All @@ -183,6 +207,7 @@ function decodeReserve(buffer: Buffer): Reserve {
borrowWeight: new BigNumber(reserve.addedBorrowWeightBPS.toString())
.dividedBy(new BigNumber(10000))
.plus(new BigNumber(1)),
reserveType: reserve.reserveType == 0 ? ReserveType.Regular : ReserveType.Isolated,
},
rateLimiter: reserve.rateLimiter,
};
Expand Down

0 comments on commit 1aa823d

Please sign in to comment.