From 8fce35d32da1f2cd399f5fa052c8a198a36716a7 Mon Sep 17 00:00:00 2001 From: zhoujia6139 Date: Wed, 28 Feb 2024 11:37:16 +0800 Subject: [PATCH] add update reserve factor script --- Makefile | 4 +++ .../DefaultReserveInterestRateStrategy.sol | 13 ++++----- tasks/dev/reserveConfigurator.ts | 27 +++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index b498f34b7..a5b7bb774 100644 --- a/Makefile +++ b/Makefile @@ -568,6 +568,10 @@ set-liquidation-threshold: set-reserve-factor: make TASK_NAME=set-reserve-factor run-task +.PHONY: reset-all-asset-reserve-factor +reset-all-asset-reserve-factor: + make TASK_NAME=reset-all-asset-reserve-factor run-task + .PHONY: set-interest-rate-strategy set-interest-rate-strategy: make TASK_NAME=set-interest-rate-strategy run-task diff --git a/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol b/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol index 499135476..c4a9a8090 100644 --- a/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol +++ b/contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol @@ -9,6 +9,7 @@ import {IReserveInterestRateStrategy} from "../../interfaces/IReserveInterestRat import {IPoolAddressesProvider} from "../../interfaces/IPoolAddressesProvider.sol"; import {IToken} from "../../interfaces/IToken.sol"; import {Errors} from "../libraries/helpers/Errors.sol"; +import {MathUtils} from "../libraries/math/MathUtils.sol"; /** * @title DefaultReserveInterestRateStrategy contract @@ -103,12 +104,7 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy { } /// @inheritdoc IReserveInterestRateStrategy - function getMaxVariableBorrowRate() - external - view - override - returns (uint256) - { + function getMaxVariableBorrowRate() public view override returns (uint256) { return _baseVariableBorrowRate + _variableRateSlope1 + _variableRateSlope2; } @@ -173,4 +169,9 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy { return (vars.currentLiquidityRate, vars.currentVariableBorrowRate); } + + function calculateMaxYearAPY() external view returns (uint256) { + uint256 maxRate = getMaxVariableBorrowRate(); + return MathUtils.calculateCompoundedInterest(maxRate, 0, 31536000); + } } diff --git a/tasks/dev/reserveConfigurator.ts b/tasks/dev/reserveConfigurator.ts index 6aaebcc3a..fc9218c6d 100644 --- a/tasks/dev/reserveConfigurator.ts +++ b/tasks/dev/reserveConfigurator.ts @@ -140,6 +140,33 @@ task("set-reserve-factor", "Set reserve factor") } }); +task("reset-all-asset-reserve-factor", "Reset all asset reserve factor") + .addPositionalParam("reserveFactor", "reserve factor") + .setAction(async ({reserveFactor}, DRE) => { + await DRE.run("set-DRE"); + const {dryRunEncodedData} = await import("../../helpers/contracts-helpers"); + const {getPoolProxy, getPoolConfiguratorProxy} = await import( + "../../helpers/contracts-getters" + ); + const configurator = await getPoolConfiguratorProxy(); + const poolProxy = await getPoolProxy(); + const assets = await poolProxy.getReservesList(); + + for (const asset of assets) { + const encodedData = configurator.interface.encodeFunctionData( + "setReserveFactor", + [asset, reserveFactor] + ); + if (DRY_RUN) { + await dryRunEncodedData(configurator.address, encodedData); + } else { + await waitForTx( + await configurator.setReserveFactor(asset, reserveFactor) + ); + } + } + }); + task("set-interest-rate-strategy", "Set interest rate strategy") .addPositionalParam("assets", "assets") .addPositionalParam(