diff --git a/contracts/MapleProxyFactory.sol b/contracts/MapleProxyFactory.sol index aca21d0..d3a2fed 100644 --- a/contracts/MapleProxyFactory.sol +++ b/contracts/MapleProxyFactory.sol @@ -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 ***/ /***************++++*******/ diff --git a/contracts/interfaces/IMapleProxyFactory.sol b/contracts/interfaces/IMapleProxyFactory.sol index 9344ffc..936e33c 100644 --- a/contracts/interfaces/IMapleProxyFactory.sol +++ b/contracts/interfaces/IMapleProxyFactory.sol @@ -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. @@ -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. diff --git a/contracts/test/MapleProxyFactory.t.sol b/contracts/test/MapleProxyFactory.t.sol index f93c055..ac4f988 100644 --- a/contracts/test/MapleProxyFactory.t.sol +++ b/contracts/test/MapleProxyFactory.t.sol @@ -50,7 +50,6 @@ contract MapleProxyFactoryTests is TestUtils { notGovernor = new Governor(); user = new User(); - globals = new MapleGlobalsMock(address(governor)); factory = new MapleProxyFactory(address(globals)); } @@ -183,4 +182,17 @@ 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(1))); + assertTrue( !governor.try_mapleProxyFactory_setGlobals(address(factory), address(new EmptyContract()))); + assertTrue( governor.try_mapleProxyFactory_setGlobals(address(factory), address(newGlobals))); + + assertEq(factory.mapleGlobals(), address(newGlobals)); + } + } diff --git a/contracts/test/accounts/Governor.sol b/contracts/test/accounts/Governor.sol index bbf2068..da60af6 100644 --- a/contracts/test/accounts/Governor.sol +++ b/contracts/test/accounts/Governor.sol @@ -30,6 +30,10 @@ contract Governor { IMapleProxyFactory(factory_).setDefaultVersion(version_); } + function mapleProxyFactory_setGlobals(address factory_, address mapleGlobals_) external { + IMapleProxyFactory(factory_).setGlobals(mapleGlobals_); + } + /*********************/ /*** Try Functions ***/ /*********************/ @@ -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_)); + } + } diff --git a/modules/proxy-factory b/modules/proxy-factory index ba289ac..54eec1d 160000 --- a/modules/proxy-factory +++ b/modules/proxy-factory @@ -1 +1 @@ -Subproject commit ba289acdd8ece6d15391cd769c94eb66497f6f1b +Subproject commit 54eec1df1bb66d97bfa748c774147a93264da441