Skip to content

Commit

Permalink
Merge pull request #56 from solendprotocol/fix-rate-limiter-calc
Browse files Browse the repository at this point in the history
Fix rate limiter calc
  • Loading branch information
0xodia authored Aug 2, 2023
2 parents 405daa6 + fa0fbe0 commit df622fe
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
1 change: 0 additions & 1 deletion solend-lite/src/components/InterestGraph/InterestGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ function InterestGraph({ reserve }: { reserve: ReserveType }): ReactElement {
</XAxis>
<YAxis
type='number'
domain={[0, 100]}
style={{
fontSize: 12,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function ReserveStats({
}}
>
{showGraph && (
<Box h={168} cursor='pointer' onClick={() => setShowGraph(false)}>
<Box h={192} cursor='pointer' onClick={() => setShowGraph(false)}>
<Flex justify='center'>
<Text variant='caption' color='secondary'>
Interest rate curve
Expand Down Expand Up @@ -211,14 +211,13 @@ function ReserveStats({
/>
<Metric
row
label='Target borrow APR'
value={formatPercent(reserve.targetBorrowApr)}
tooltip='When utilization is equal to the target utilization, borrow APR will be this value.'
label='Current borrow APR'
value={formatPercent(reserve.borrowInterest)}
/>
<Metric
row
label='Current borrow APR'
value={formatPercent(reserve.borrowInterest)}
label='Min borrow APR'
value={formatPercent(reserve.minBorrowApr)}
/>
<Metric
row
Expand All @@ -228,18 +227,24 @@ function ReserveStats({
/>
<Metric
row
label='Max borrow APR'
value={formatPercent(
reserve.maxBorrowApr,
)}
tooltip='Maximum possible borrow APR.'
label='Target borrow APR'
value={formatPercent(reserve.targetBorrowApr)}
tooltip='When utilization is equal to the target utilization, borrow APR will be this value.'
/>
<Metric
row
label='Max utilization'
value={formatPercent(reserve.maxUtilizationRate)}
tooltip='When utilization goes above this value, borrows and withdraws will not be possible.'
/>
<Metric
row
label='Max borrow APR'
value={formatPercent(
reserve.maxBorrowApr,
)}
tooltip='Maximum possible borrow APR.'
/>
<Metric
row
label='Supermax borrow APR'
Expand Down Expand Up @@ -296,7 +301,7 @@ function ReserveStats({
<Metric
row
label='Max close LTV'
value={formatPercent(reserve.liquidationThreshold)}
value={formatPercent(reserve.maxLiquidationThreshold)}
tooltip='Max close Loan-to-value (LTV) is the ratio at which the max liquidation penalty occurs.'
/>
<Metric
Expand All @@ -307,7 +312,7 @@ function ReserveStats({
<Metric
row
label='Max liquidation penalty'
value={<>{formatPercent(reserve.protocolLiquidationFee)}</>}
value={<>{formatPercent(reserve.maxLiquidationPenalty)}</>}
tooltip='Liquidation penalty increases past close LTV until max close LTV, where max liquidation penalty occurs.'
/>
<Metric
Expand Down
3 changes: 2 additions & 1 deletion solend-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solendprotocol/solend-sdk",
"version": "0.6.25",
"version": "0.6.32",
"private": true,
"main": "src/index.ts",
"module": "src/index.ts",
Expand All @@ -27,6 +27,7 @@
"@solana/buffer-layout": "^4.0.0",
"@solana/spl-token": "^0.3.6",
"@solana/web3.js": "=1.76.0",
"@solendprotocol/solend-sdk": "^0.6.31",
"@solflare-wallet/utl-sdk": "^1.4.0",
"@types/bn.js": "^5.1.1",
"axios": "^0.24.0",
Expand Down
2 changes: 1 addition & 1 deletion solend-sdk/src/core/utils/obligations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function formatObligation(
reserveAddress,
amount,
amountUsd,
weightedAmountUsd: reserve.borrowWeight.multipliedBy(amountUsd)
weightedAmountUsd: new BigNumber(reserve.borrowWeight).multipliedBy(amountUsd)
};
});

Expand Down
2 changes: 1 addition & 1 deletion solend-sdk/src/core/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const remainingOutflow = (
const curOutflow = prevWeight.times(
previousQuantity.plus(currentQuantity),
);
outflow = maxOutflow.plus(curOutflow);
outflow = maxOutflow.minus(curOutflow);
} else if (windowStart.plus(windowDuration).isEqualTo(curSlotStart)) {
const curOutflow = prevWeight.times(currentQuantity);
outflow = maxOutflow.minus(curOutflow);
Expand Down
3 changes: 3 additions & 0 deletions solend-sdk/src/instructions/updateReserveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const updateReserveConfig = (
BufferLayout.u8("minBorrowRate"),
BufferLayout.u8("optimalBorrowRate"),
BufferLayout.u8("maxBorrowRate"),
Layout.uint64("superMaxBorrowRate"),
Layout.uint64("borrowFeeWad"),
Layout.uint64("flashLoanFeeWad"),
BufferLayout.u8("hostFeePercentage"),
Expand All @@ -56,6 +57,7 @@ export const updateReserveConfig = (
]);

const data = Buffer.alloc(dataLayout.span);

dataLayout.encode(
{
instruction: LendingInstruction.UpdateReserveConfig,
Expand All @@ -73,6 +75,7 @@ export const updateReserveConfig = (
depositLimit: reserveConfig.depositLimit,
borrowLimit: reserveConfig.borrowLimit,
feeReceiver: reserveConfig.feeReceiver,
superMaxBorrowRate: reserveConfig.superMaxBorrowRate,
protocolLiquidationFee: reserveConfig.protocolLiquidationFee,
protocolTakeRate: reserveConfig.protocolTakeRate,
addedBorrowWeightBPS: reserveConfig.addedBorrowWeightBPS,
Expand Down
1 change: 1 addition & 0 deletions solend-sdk/src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./lastUpdate";
export * from "./lendingMarket";
export * from "./reserve";
export * from "./obligation";
export * from './rateLimiter';
8 changes: 4 additions & 4 deletions solend-sdk/src/state/reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface ReserveConfig {
protocolLiquidationFee: number;
protocolTakeRate: number;
addedBorrowWeightBPS: BN;
borrowWeight: BigNumber;
borrowWeight: number;
reserveType: AssetType;
}

Expand Down Expand Up @@ -148,7 +148,7 @@ export const ReserveLayout: typeof BufferLayout.Structure = BufferLayout.struct(
Layout.uint128("liquiditySmoothedMarketPrice"),
BufferLayout.u8("reserveType"),
BufferLayout.u8("maxUtilizationRate"),
BufferLayout.u8("superMaxBorrowRate"),
Layout.uint64("superMaxBorrowRate"),
BufferLayout.u8("maxLiquidationBonus"),
BufferLayout.u8("maxLiquidationThreshold"),
BufferLayout.blob(138, "padding"),
Expand Down Expand Up @@ -192,7 +192,7 @@ function decodeReserve(buffer: Buffer): Reserve {
minBorrowRate: reserve.minBorrowRate,
optimalBorrowRate: reserve.optimalBorrowRate,
maxBorrowRate: reserve.maxBorrowRate,
superMaxBorrowRate: Math.max(reserve.superMaxBorrowRate, reserve.maxBorrowRate),
superMaxBorrowRate: Math.max(reserve.superMaxBorrowRate.toNumber(), reserve.maxBorrowRate),
fees: {
borrowFeeWad: reserve.borrowFeeWad,
flashLoanFeeWad: reserve.flashLoanFeeWad,
Expand All @@ -207,7 +207,7 @@ function decodeReserve(buffer: Buffer): Reserve {
addedBorrowWeightBPS: reserve.addedBorrowWeightBPS,
borrowWeight: new BigNumber(reserve.addedBorrowWeightBPS.toString())
.dividedBy(new BigNumber(10000))
.plus(new BigNumber(1)),
.plus(new BigNumber(1)).toNumber(),
reserveType:
reserve.reserveType == 0 ? AssetType.Regular : AssetType.Isolated,
},
Expand Down

0 comments on commit df622fe

Please sign in to comment.