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: Add mapleGlobals setter (C4 #7) #24

Merged
merged 7 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
14 changes: 13 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,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)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add an assertTrue(!) of an emptyContract globals

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

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

}
2 changes: 1 addition & 1 deletion modules/proxy-factory