Skip to content

Commit

Permalink
feat: add mapleGlobals setter (c4 #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
deluca-mike committed Dec 12, 2021
1 parent a1f43ec commit 5562c7c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions contracts/MapleProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ contract MapleProxyFactory is IMapleProxyFactory, ProxyFactory {
emit DefaultVersionSet(defaultVersion = version_);
}

function setGlobals(address mapleGlobals_) public override virtual onlyGovernor {
require(IMapleGlobalsLike(mapleGlobals_).governor() != address(0), "MPF:SG:INVALID_GLOBALS");

emit MapleGlobalsSet(mapleGlobals = mapleGlobals_);
}

/****************+++++******/
/*** Instance Functions ***/
/***************++++*******/
Expand Down
13 changes: 13 additions & 0 deletions contracts/interfaces/IMapleProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ interface IMapleProxyFactory is IDefaultImplementationBeacon {
*/
event InstanceUpgraded(address indexed instance, uint256 indexed fromVersion, uint256 indexed toVersion, bytes migrationArguments);

/**
* @dev The MapleGlobals was set.
* @param mapleGlobals The address of a Maple Globals contract.
*/
event MapleGlobalsSet(address indexed mapleGlobals);

/**
* @dev An upgrade path was disabled, with an optional migrator contract.
* @param fromVersion The starting version of the upgrade path.
Expand Down Expand Up @@ -124,6 +130,13 @@ interface IMapleProxyFactory is IDefaultImplementationBeacon {
*/
function setDefaultVersion(uint256 version_) external;

/**
* @dev Sets the Maple Globals contract.
* @dev Only the Governor can call this function.
* @param mapleGlobals_ The address of a Maple Globals contract.
*/
function setGlobals(address mapleGlobals_) external;

/**
* @dev Upgrades the calling proxy contract's implementation, with some migration arguments.
* @param toVersion_ The implementation version to upgrade the proxy contract to.
Expand Down
12 changes: 11 additions & 1 deletion contracts/test/MapleProxyFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ contract MapleProxyFactoryTests is TestUtils {
notGovernor = new Governor();
user = new User();


globals = new MapleGlobalsMock(address(governor));
factory = new MapleProxyFactory(address(globals));
}
Expand Down Expand Up @@ -183,4 +182,15 @@ contract MapleProxyFactoryTests is TestUtils {
assertEq(factory.versionOf(instance.implementation()), 2);
}

function test_setGlobals() external {
MapleGlobalsMock newGlobals = new MapleGlobalsMock(address(governor));

assertEq(factory.mapleGlobals(), address(globals));

assertTrue(!notGovernor.try_mapleProxyFactory_setGlobals(address(factory), address(newGlobals)));
assertTrue( governor.try_mapleProxyFactory_setGlobals(address(factory), address(newGlobals)));

assertEq(factory.mapleGlobals(), address(newGlobals));
}

}
8 changes: 8 additions & 0 deletions contracts/test/accounts/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ contract Governor {
IMapleProxyFactory(factory_).setDefaultVersion(version_);
}

function mapleProxyFactory_setGlobals(address factory_, address mapleGlobals_) external {
IMapleProxyFactory(factory_).setGlobals(mapleGlobals_);
}

/*********************/
/*** Try Functions ***/
/*********************/
Expand Down Expand Up @@ -62,4 +66,8 @@ contract Governor {
( ok_, ) = factory_.call(abi.encodeWithSelector(IMapleProxyFactory.setDefaultVersion.selector, version_));
}

function try_mapleProxyFactory_setGlobals(address factory_, address mapleGlobals_) external returns (bool ok_) {
( ok_, ) = factory_.call(abi.encodeWithSelector(IMapleProxyFactory.setGlobals.selector, mapleGlobals_));
}

}

0 comments on commit 5562c7c

Please sign in to comment.