Skip to content

Commit

Permalink
feat: Add validation to migrator (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
JGcarv authored Oct 31, 2023
1 parent b0abce2 commit bff5c1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions contracts/MapleLoanV502Migrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ pragma solidity 0.8.7;

import { ProxiedInternals } from "../modules/maple-proxy-factory/modules/proxy-factory/contracts/ProxiedInternals.sol";

import { IGlobalsLike, IMapleProxyFactoryLike } from "./interfaces/Interfaces.sol";

import { MapleLoanStorage } from "./MapleLoanStorage.sol";

/// @title MapleLoanV502Migrator is to update the factory address for each deployed loan.
contract MapleLoanV502Migrator is ProxiedInternals, MapleLoanStorage {

fallback() external {
( address factory_ ) = abi.decode(msg.data, (address));
( address newFactory_ ) = abi.decode(msg.data, (address));

address globals = IMapleProxyFactoryLike(_factory()).mapleGlobals();

require(IGlobalsLike(globals).isInstanceOf("FT_LOAN_FACTORY", newFactory_), "MLV502M:INVALID_FACTORY");

_setFactory(factory_);
_setFactory(newFactory_);
}

}
12 changes: 12 additions & 0 deletions tests/MapleLoanV502Migrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ contract MapleLoanV502MigratorTests is TestUtils {
loan502 = MapleLoan(oldFactory.createInstance(arguments, "SALT2"));
}

function test_migration_invalidFactory() external {
newFactory = new MapleLoanFactory(address(globals), address(oldFactory));

bytes memory arguments = abi.encode(address(newFactory));

globals.__setIsInstanceOf(false);

vm.expectRevert("MPF:UI:FAILED");
vm.prank(securityAdmin);
loan501.upgrade(502, arguments);
}

function test_migration_factoryChange() external {
assertEq(loan501.factory(), address(oldFactory));
assertEq(loan501.implementation(), address(implementation501));
Expand Down

0 comments on commit bff5c1d

Please sign in to comment.