Skip to content

Commit fa48839

Browse files
authored
feat: add owner to interest rate contract (#131)
* add owner to InterestRate contract * deploy WETH IRM
1 parent 98558b1 commit fa48839

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

contracts/protocol/InterestRate.sol

+22-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {WadRayMath} from "../libraries/math/WadRayMath.sol";
77
import {PercentageMath} from "../libraries/math/PercentageMath.sol";
88

99
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
10+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
1011

1112
/**
1213
* @title InterestRate contract
@@ -15,42 +16,42 @@ import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20
1516
* point of utilization and another from that one to 100%
1617
* @author Bend
1718
**/
18-
contract InterestRate is IInterestRate {
19+
contract InterestRate is IInterestRate, Ownable {
1920
using WadRayMath for uint256;
2021
using PercentageMath for uint256;
2122

22-
ILendPoolAddressesProvider public immutable addressesProvider;
23+
ILendPoolAddressesProvider public addressesProvider;
2324

2425
/**
2526
* @dev this constant represents the utilization rate at which the pool aims to obtain most competitive borrow rates.
2627
* Expressed in ray
2728
**/
28-
uint256 public immutable OPTIMAL_UTILIZATION_RATE;
29+
uint256 public OPTIMAL_UTILIZATION_RATE;
2930

3031
/**
3132
* @dev This constant represents the excess utilization rate above the optimal. It's always equal to
3233
* 1-optimal utilization rate. Added as a constant here for gas optimizations.
3334
* Expressed in ray
3435
**/
3536

36-
uint256 public immutable EXCESS_UTILIZATION_RATE;
37+
uint256 public EXCESS_UTILIZATION_RATE;
3738

3839
// Base variable borrow rate when Utilization rate = 0. Expressed in ray
39-
uint256 internal immutable _baseVariableBorrowRate;
40+
uint256 internal _baseVariableBorrowRate;
4041

4142
// Slope of the variable interest curve when utilization rate > 0 and <= OPTIMAL_UTILIZATION_RATE. Expressed in ray
42-
uint256 internal immutable _variableRateSlope1;
43+
uint256 internal _variableRateSlope1;
4344

4445
// Slope of the variable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray
45-
uint256 internal immutable _variableRateSlope2;
46+
uint256 internal _variableRateSlope2;
4647

4748
constructor(
4849
ILendPoolAddressesProvider provider,
4950
uint256 optimalUtilizationRate_,
5051
uint256 baseVariableBorrowRate_,
5152
uint256 variableRateSlope1_,
5253
uint256 variableRateSlope2_
53-
) {
54+
) Ownable() {
5455
addressesProvider = provider;
5556
OPTIMAL_UTILIZATION_RATE = optimalUtilizationRate_;
5657
EXCESS_UTILIZATION_RATE = WadRayMath.ray() - (optimalUtilizationRate_);
@@ -59,6 +60,19 @@ contract InterestRate is IInterestRate {
5960
_variableRateSlope2 = variableRateSlope2_;
6061
}
6162

63+
function setInterestRateParams(
64+
uint256 optimalUtilizationRate_,
65+
uint256 baseVariableBorrowRate_,
66+
uint256 variableRateSlope1_,
67+
uint256 variableRateSlope2_
68+
) public onlyOwner {
69+
OPTIMAL_UTILIZATION_RATE = optimalUtilizationRate_;
70+
EXCESS_UTILIZATION_RATE = WadRayMath.ray() - (optimalUtilizationRate_);
71+
_baseVariableBorrowRate = baseVariableBorrowRate_;
72+
_variableRateSlope1 = variableRateSlope1_;
73+
_variableRateSlope2 = variableRateSlope2_;
74+
}
75+
6276
function variableRateSlope1() external view returns (uint256) {
6377
return _variableRateSlope1;
6478
}

deployments/deployed-contracts-main.json

+4
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,9 @@
268268
"TokenOracle": {
269269
"address": "0x09AbE7f7297B27e4343E1f3906267b0BE6dBe4eb",
270270
"deployer": "0x868964fa49a6fd6e116FE82c8f4165904406f479"
271+
},
272+
"rateStrategyWETH250205": {
273+
"address": "0xeDc614E4e9A173Fb72e21b1814AC068A458C64e7",
274+
"deployer": "0x868964fa49a6fd6e116FE82c8f4165904406f479"
271275
}
272276
}

deployments/deployed-contracts-sepolia.json

+4
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,9 @@
175175
"TokenOracle": {
176176
"address": "0xA840dC2B97F565BF5179CccC8e4f6E72d5eD1eab",
177177
"deployer": "0xafF5C36642385b6c7Aaf7585eC785aB2316b5db6"
178+
},
179+
"rateStrategyWETH250205": {
180+
"address": "0xF1F89AE4a28318e36026ADcFe1B7188e2122db6B",
181+
"deployer": "0xafF5C36642385b6c7Aaf7585eC785aB2316b5db6"
178182
}
179183
}

test/interest-rate.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ makeSuite("Interest rate tests", (testEnv: TestEnv) => {
3535
);
3636
});
3737

38+
it("Test the ownership check", async () => {
39+
const { users } = testEnv;
40+
41+
const owner = await rateInstance.owner();
42+
43+
await rateInstance.transferOwnership(users[1].address);
44+
45+
await expect(rateInstance.setInterestRateParams(100, 100, 100, 100)).to.be.revertedWith(
46+
"Ownable: caller is not the owner"
47+
);
48+
49+
await rateInstance.connect(users[1].signer).transferOwnership(owner);
50+
});
51+
52+
it("Test the set params", async () => {
53+
await rateInstance.setInterestRateParams(100, 200, 300, 400);
54+
55+
await expect(await rateInstance.baseVariableBorrowRate()).to.be.equal(200, "baseRate not eq");
56+
await expect(await rateInstance.variableRateSlope1()).to.be.equal(300, "slope1 not eq");
57+
await expect(await rateInstance.variableRateSlope2()).to.be.equal(400, "slope2 not eq");
58+
59+
await rateInstance.setInterestRateParams(
60+
rateStrategyStableOne.optimalUtilizationRate,
61+
rateStrategyStableOne.baseVariableBorrowRate,
62+
rateStrategyStableOne.variableRateSlope1,
63+
rateStrategyStableOne.variableRateSlope2
64+
);
65+
});
66+
3867
it("Checks rates at 0% utilization rate, empty reserve", async () => {
3968
const { 0: currentLiquidityRate, 1: currentVariableBorrowRate } = await rateInstance[
4069
"calculateInterestRates(address,address,uint256,uint256,uint256,uint256)"

0 commit comments

Comments
 (0)