Skip to content

Commit

Permalink
fix: update to standard structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-manuel committed Nov 9, 2023
1 parent 9086ad4 commit faec6fe
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 128 deletions.
59 changes: 33 additions & 26 deletions src/SparkLendFreezer.sol → src/SparkLendFreezerMom.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.13;

import { ISparkLendFreezer } from "src/interfaces/ISparkLendFreezer.sol";
import { ISparkLendFreezerMom } from "src/interfaces/ISparkLendFreezerMom.sol";

interface AuthorityLike {
function canCall(address src, address dst, bytes4 sig) external view returns (bool);
Expand All @@ -15,7 +15,7 @@ interface PoolLike {
function getReservesList() external view returns (address[] memory);
}

contract SparkLendFreezer is ISparkLendFreezer {
contract SparkLendFreezerMom is ISparkLendFreezerMom {

/**********************************************************************************************/
/*** Declarations and Constructor ***/
Expand All @@ -25,60 +25,51 @@ contract SparkLendFreezer is ISparkLendFreezer {
address public immutable pool;

address public authority;

mapping (address => uint256) public override wards;
address public owner;

constructor(address poolConfigurator_, address pool_, address authority_) {
poolConfigurator = poolConfigurator_;
pool = pool_;
authority = authority_;
owner = msg.sender;

wards[msg.sender] = 1;
emit Rely(msg.sender);
emit SetOwner(address(0), msg.sender);
}

/**********************************************************************************************/
/*** Modifiers ***/
/**********************************************************************************************/

modifier auth {
require(wards[msg.sender] == 1, "SparkLendFreezer/not-authorized");
modifier onlyOwner {
require(msg.sender == owner, "SparkLendFreezerMom/only-owner");
_;
}

modifier canCall {
require(
AuthorityLike(authority).canCall(msg.sender, address(this), msg.sig),
"SparkLendFreezer/cannot-call"
);
modifier auth {
require(isAuthorized(msg.sender, msg.sig), "SparkLendFreezerMom/not-authorized");
_;
}

/**********************************************************************************************/
/*** Wards Functions ***/
/**********************************************************************************************/

function deny(address usr) external override auth {
wards[usr] = 0;
emit Deny(usr);
function setAuthority(address authority_) external onlyOwner {
emit SetAuthority(authority, authority_);
authority = authority_;
}

function rely(address usr) external override auth {
wards[usr] = 1;
emit Rely(usr);
}

function setAuthority(address authority_) external auth {
address oldAuthority = authority;
authority = authority_;
emit SetAuthority(oldAuthority, authority_);
function setOwner(address owner_) external onlyOwner {
emit SetOwner(owner, owner_);
owner = owner_;
}

/**********************************************************************************************/
/*** Auth Functions ***/
/**********************************************************************************************/

function freezeAllMarkets() external canCall {
function freezeAllMarkets() external auth {
address[] memory reserves = PoolLike(pool).getReservesList();

for (uint256 i = 0; i < reserves.length; i++) {
Expand All @@ -87,9 +78,25 @@ contract SparkLendFreezer is ISparkLendFreezer {
}
}

function freezeMarket(address reserve) external canCall {
function freezeMarket(address reserve) external auth {
PoolConfiguratorLike(poolConfigurator).setReserveFreeze(reserve, true);
}

/**********************************************************************************************/
/*** Internal Functions ***/
/**********************************************************************************************/

function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
if (src == address(this)) {
return true;
} else if (src == owner) {
return true;
} else if (authority == address(0)) {
return false;
} else {
return AuthorityLike(authority).canCall(src, address(this), sig);
}
}

}

51 changes: 0 additions & 51 deletions src/interfaces/ISparkLendFreezer.sol

This file was deleted.

13 changes: 13 additions & 0 deletions src/interfaces/ISparkLendFreezerMom.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.0;

interface ISparkLendFreezerMom {

/**********************************************************************************************/
/*** Events ***/
/**********************************************************************************************/

event SetOwner(address indexed oldOwner, address indexed newOwner);
event SetAuthority(address indexed oldAuthority, address indexed newAuthority);

}
83 changes: 32 additions & 51 deletions test/SparkLendFreezer.t.sol → test/SparkLendFreezerMom.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,88 @@ pragma solidity ^0.8.13;

import "forge-std/Test.sol";

import { SparkLendFreezer } from "../src/SparkLendFreezer.sol";
import { SparkLendFreezerMom } from "../src/SparkLendFreezerMom.sol";

import { AuthorityMock, ConfiguratorMock, PoolMock } from "./Mocks.sol";

contract SparkLendFreezerUnitTestBase is Test {
contract SparkLendFreezerMomUnitTestBase is Test {

address public configurator;
address public pool;
address public ward;
address public owner;

AuthorityMock public authority;

SparkLendFreezer public freezer;
SparkLendFreezerMom public freezer;

function setUp() public {
ward = makeAddr("ward");
owner = makeAddr("owner");

authority = new AuthorityMock();
configurator = address(new ConfiguratorMock());
pool = address(new PoolMock());
freezer = new SparkLendFreezer(configurator, pool, address(authority));
freezer = new SparkLendFreezerMom(configurator, pool, address(authority));

freezer.rely(ward);
freezer.deny(address(this));
freezer.setOwner(owner);
}

}

contract ConstructorTests is SparkLendFreezerUnitTestBase {
contract ConstructorTests is SparkLendFreezerMomUnitTestBase {

function test_constructor() public {
freezer = new SparkLendFreezer(configurator, pool, address(authority));
freezer = new SparkLendFreezerMom(configurator, pool, address(authority));

assertEq(freezer.poolConfigurator(), configurator);
assertEq(freezer.pool(), pool);
assertEq(freezer.authority(), address(authority));
assertEq(freezer.wards(address(this)), 1);
assertEq(freezer.poolConfigurator(), configurator);
assertEq(freezer.pool(), pool);
assertEq(freezer.authority(), address(authority));
assertEq(freezer.owner(), address(this));
}

}

contract DenyTests is SparkLendFreezerUnitTestBase {
contract SetOwnerTests is SparkLendFreezerMomUnitTestBase {

function test_deny_no_auth() public {
vm.expectRevert("SparkLendFreezer/not-authorized");
freezer.deny(ward);
function test_setOwner_no_auth() public {
vm.expectRevert("SparkLendFreezerMom/only-owner");
freezer.setOwner(address(1));
}

function test_deny() public {
assertEq(freezer.wards(ward), 1);
function test_setOwner() public {
address newOwner = makeAddr("newOwner");
assertEq(freezer.owner(), owner);

vm.prank(ward);
freezer.deny(ward);
vm.prank(owner);
freezer.setOwner(newOwner);

assertEq(freezer.wards(ward), 0);
assertEq(freezer.owner(), newOwner);
}

}

contract RelyTests is SparkLendFreezerUnitTestBase {

function test_rely_no_auth() public {
vm.expectRevert("SparkLendFreezer/not-authorized");
freezer.rely(makeAddr("new ward"));
}

function test_rely() public {
address newWard = makeAddr("new ward");
assertEq(freezer.wards(newWard), 0);

vm.prank(ward);
freezer.rely(newWard);

assertEq(freezer.wards(ward), 1);
}

}

contract SetAuthorityTests is SparkLendFreezerUnitTestBase {
contract SetAuthorityTests is SparkLendFreezerMomUnitTestBase {

function test_setAuthority_no_auth() public {
vm.expectRevert("SparkLendFreezer/not-authorized");
freezer.setAuthority(makeAddr("new authority"));
vm.expectRevert("SparkLendFreezerMom/only-owner");
freezer.setAuthority(makeAddr("newAuthority"));
}

function test_setAuthority() public {
address newAuthority = makeAddr("new authority");
address newAuthority = makeAddr("newAuthority");
assertEq(freezer.authority(), address(authority));

vm.prank(ward);
vm.prank(owner);
freezer.setAuthority(newAuthority);

assertEq(freezer.authority(), newAuthority);
}

}

contract FreezeAllMarketsTests is SparkLendFreezerUnitTestBase {
contract FreezeAllMarketsTests is SparkLendFreezerMomUnitTestBase {

function test_freezeAllMarkets_noAuth() public {
vm.expectRevert("SparkLendFreezer/cannot-call");
vm.expectRevert("SparkLendFreezerMom/not-authorized");
freezer.freezeAllMarkets();
}

Expand Down Expand Up @@ -132,12 +113,12 @@ contract FreezeAllMarketsTests is SparkLendFreezerUnitTestBase {

}

contract FreezeMarketTests is SparkLendFreezerUnitTestBase {
contract FreezeMarketTests is SparkLendFreezerMomUnitTestBase {

address reserve = makeAddr("reserve");

function test_freezeMarket_noAuth() public {
vm.expectRevert("SparkLendFreezer/cannot-call");
vm.expectRevert("SparkLendFreezerMom/not-authorized");
freezer.freezeMarket(reserve);
}

Expand Down

0 comments on commit faec6fe

Please sign in to comment.