diff --git a/src/Blue.sol b/src/Blue.sol index 7f84e570f..45ca704db 100644 --- a/src/Blue.sol +++ b/src/Blue.sol @@ -39,6 +39,8 @@ contract Blue { // Storage. + // Owner. + address public owner; // User' supply balances. mapping(Id => mapping(address => uint)) public supplyShare; // User' borrow balances. @@ -56,6 +58,19 @@ contract Blue { // Interests last update (used to check if a market has been created). mapping(Id => uint) public lastUpdate; + // Constructor. + + constructor(address newOwner) { + owner = newOwner; + } + + // Only owner functions. + + function transferOwnership(address newOwner) external { + require(msg.sender == owner, "not owner"); + owner = newOwner; + } + // Markets management. function createMarket(Market calldata market) external { diff --git a/test/forge/Blue.t.sol b/test/forge/Blue.t.sol index 753372473..6730a31a1 100644 --- a/test/forge/Blue.t.sol +++ b/test/forge/Blue.t.sol @@ -14,6 +14,7 @@ import {OracleMock as Oracle} from "src/mocks/OracleMock.sol"; contract BlueTest is Test { using MathLib for uint; + address private constant owner = address(0xdeed); address private constant borrower = address(1234); address private constant liquidator = address(5678); uint private constant lLTV = 0.8 ether; @@ -28,7 +29,7 @@ contract BlueTest is Test { function setUp() public { // Create Blue. - blue = new Blue(); + blue = new Blue(owner); // List a market. borrowableAsset = new ERC20("borrowable", "B", 18); @@ -91,6 +92,30 @@ contract BlueTest is Test { // Tests + function testOwner(address newOwner) public { + Blue blue2 = new Blue(newOwner); + + assertEq(blue2.owner(), newOwner, "owner"); + } + + function testTransferOwnership(address oldOwner, address newOwner) public { + Blue blue2 = new Blue(oldOwner); + + vm.prank(oldOwner); + blue2.transferOwnership(newOwner); + assertEq(blue2.owner(), newOwner, "owner"); + } + + function testTransferOwnershipWhenNotOwner(address attacker, address newOwner) public { + vm.assume(attacker != address(0xdead)); + + Blue blue2 = new Blue(address(0xdead)); + + vm.prank(attacker); + vm.expectRevert("not owner"); + blue2.transferOwnership(newOwner); + } + function testSupply(uint amount) public { amount = bound(amount, 1, 2 ** 64);