Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Build initial implementation with unit testing (SC-204) #1

Merged
merged 21 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions script/Counter.s.sol

This file was deleted.

14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

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

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

interface AuthorityLike {
function canCall(address src, address dst, bytes4 sig) external view returns (bool);
}

interface PoolConfiguratorLike {
function setReserveFreeze(address asset, bool freeze) external;
}

interface PoolLike {
function getReservesList() external view returns (address[] memory);
}

contract SparkLendFreezer is ISparkLendFreezer {

/**********************************************************************************************/
/*** Declarations and Constructor ***/
/**********************************************************************************************/

address public immutable poolConfigurator;
address public immutable pool;

address public authority;

mapping (address => uint256) public override wards;

constructor(address poolConfigurator_, address pool_, address authority_) {
poolConfigurator = poolConfigurator_;
pool = pool_;
authority = authority_;

wards[msg.sender] = 1;
emit Rely(msg.sender);
}

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

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

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

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

function deny(address usr) external override auth {
wards[usr] = 0;
emit Deny(usr);
}

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_);
}

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

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

for (uint256 i = 0; i < reserves.length; i++) {
if (reserves[i] == address(0)) continue;
PoolConfiguratorLike(poolConfigurator).setReserveFreeze(reserves[i], true);
}
}

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

}

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

interface ISparkLendFreezer {

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

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

/**
* @dev Event emitted when a new admin is removed from the Conduit.
* @param usr The address of the user to remove.
*/
event Deny(address indexed usr);

/**
* @dev Event emitted when a new admin is added to the Conduit.
* @param usr The address of the user to add.
*/
event Rely(address indexed usr);

/**********************************************************************************************/
/*** Storage Variables ***/
/**********************************************************************************************/

/**
* @dev Returns a 0 or 1 depending on if the user has been added as an admin.
* @return relied The value of the user's admin status.
*/
function wards(address user) external view returns (uint256 relied);

/**********************************************************************************************/
/*** Administrative Functions ***/
/**********************************************************************************************/

/**
* @dev Function to remove an addresses admin permissions.
* @param usr The address of the admin.
*/
function deny(address usr) external;

/**
* @dev Function to give an address admin permissions.
* @param usr The address of the new admin.
*/
function rely(address usr) external;

}
25 changes: 0 additions & 25 deletions test/Counter.t.sol

This file was deleted.

48 changes: 48 additions & 0 deletions test/Mocks.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.13;

contract AuthorityMock {

bool internal _allCanCall;

mapping (address => mapping (address => mapping (bytes4 => bool))) internal callAllowed;

function __setCanCall(address src, address dst, bytes4 sig, bool allowed) public {
callAllowed[src][dst][sig] = allowed;
}

function __setAllCanCall(bool allCanCall_) public {
_allCanCall = allCanCall_;
}

function canCall(address src, address dst, bytes4 sig) external view returns (bool) {
return callAllowed[src][dst][sig] || _allCanCall;
}

}

contract ConfiguratorMock {

function setReserveFreeze(address asset, bool freeze) external {}

}

contract PoolMock {

address[] internal assets;

function getReservesList() external view returns (address[] memory list) {
list = new address[](assets.length);

for (uint256 i; i < assets.length; ++i) {
list[i] = assets[i];
}
}

function __addAsset(address asset) public {
assets.push(asset);
}

}


Loading
Loading