Skip to content

Commit

Permalink
feat: [VEN-953] add ACM check to setCloseFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kkirka committed Mar 15, 2023
1 parent c75580a commit d8494f7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion contracts/Comptroller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,8 @@ contract Comptroller is
* @custom:event Emits NewCloseFactor on success
* @custom:access Only Governance
*/
function setCloseFactor(uint256 newCloseFactorMantissa) external onlyOwner {
function setCloseFactor(uint256 newCloseFactorMantissa) external {
_checkAccessAllowed("setCloseFactor(uint256)");
require(closeFactorMaxMantissa >= newCloseFactorMantissa, "Close factor greater than maximum close factor");
require(closeFactorMinMantissa <= newCloseFactorMantissa, "Close factor smaller than minimum close factor");

Expand Down
8 changes: 8 additions & 0 deletions deploy/008-access-control-configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await tx.wait();
console.log("DEFAULT_ADMIN | PoolRegistry | setLiquidationIncentive(uint256)");

tx = await accessControlManager.giveCallPermission(
ethers.constants.AddressZero,
"setCloseFactor(uint256)",
poolRegistry.address,
);
await tx.wait();
console.log("DEFAULT_ADMIN | PoolRegistry | setCloseFactor(uint256)");

tx = await accessControlManager.giveCallPermission(
ethers.constants.AddressZero,
"setMinLiquidatableCollateral(uint256)",
Expand Down
16 changes: 6 additions & 10 deletions tests/hardhat/Comptroller/setters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,12 @@ describe("setters", async () => {
});

describe("setCloseFactor", async () => {
let newPriceOracle: FakeContract<PriceOracle>;

before(async () => {
newPriceOracle = await smock.fake<PriceOracle>("PriceOracle");
});

it("reverts if called by a non-owner", async () => {
await expect(comptroller.connect(user).setPriceOracle(newPriceOracle.address)).to.be.revertedWith(
"Ownable: caller is not the owner",
);
const newCloseFactor = convertToUnit("0.8", 18);
it("reverts if access control manager does not allow the call", async () => {
accessControl.isAllowedToCall.whenCalledWith(owner.address, "setCloseFactor(uint256)").returns(false);
await expect(comptroller.setCloseFactor(newCloseFactor))
.to.be.revertedWithCustomError(comptroller, "Unauthorized")
.withArgs(owner.address, comptroller.address, "setCloseFactor(uint256)");
});
});

Expand Down
6 changes: 6 additions & 0 deletions tests/hardhat/Fork/RiskFund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ const riskFundFixture = async (): Promise<void> => {
poolRegistry.address,
);

await accessControlManager.giveCallPermission(
ethers.constants.AddressZero,
"setCloseFactor(uint256)",
poolRegistry.address,
);

await accessControlManager.giveCallPermission(
poolRegistry.address,
"createRegistryPool(string,address,uint256,uint256,uint256,address,uint256,address)",
Expand Down

0 comments on commit d8494f7

Please sign in to comment.