Code
function test_fundsDoesntMoveAfterMigration() public {
uint256 startingBalance = 100e6;
uint256 depositBalance = 50e6;
vm.startPrank(godFather);
usdc.transfer(testAccount, startingBalance);
vm.stopPrank();
vm.startPrank(testAccount);
usdc.approve(address(moneyShelf), startingBalance);
laundrette.depositTheCrimeMoneyInATM(testAccount, testAccount, depositBalance);
vm.stopPrank();
assertEq(usdc.balanceOf(address(moneyShelf)), depositBalance);
assertEq(usdc.balanceOf(testAccount), startingBalance - depositBalance);
EmergencyMigration migration = new EmergencyMigration();
MoneyVault moneyVault = migration.migrate(kernel, usdc, crimeMoney);
assertNotEq(address(moneyShelf), address(moneyVault));
assertEq(address(kernel.getModuleForKeycode(Keycode.wrap("MONEY"))), address(moneyVault));
assertEq(usdc.balanceOf(address(moneyVault)), 0);
assertEq(usdc.balanceOf(address(moneyShelf)), depositBalance);
}
function migrateFundsToVault(address to) external {
require(kernel.executor() == msg.sender, "MoneyShelf: you are not the godfather");
uint256 totalUsdcBalance = usdc.balanceOf(address(this));
usdc.transfer(to, totalUsdcBalance);
}
+ import { MoneyShelf } from "src/modules/MoneyShelf.sol";
contract EmergencyMigration is Script {
address public godFather;
function run() public {
// To set at the deployment, no leak of addresses before.
Kernel kernel = Kernel(address(0));
IERC20 usdc = IERC20(address(0));
CrimeMoney crimeMoney = CrimeMoney(address(0));
+ MoneyShelf moneyShelf = MoneyShelf(address(0));
- migrate(kernel, usdc, crimeMoney);
+ migrate(kernel, usdc, crimeMoney, moneyShelf);
}
// In case of any issue, the GodFather call this function to migrate the money shelf to a contract that only him
// can manage the money.
// This function has to success in any case to protect the money.
- function migrate(Kernel kernel, IERC20 usdc, CrimeMoney crimeMoney) public returns (MoneyVault) {
+ function migrate(Kernel kernel, IERC20 usdc, CrimeMoney crimeMoney, MoneyShelf moneyShelf) public returns (MoneyVault) {
vm.startBroadcast(kernel.executor());
MoneyVault moneyVault = new MoneyVault(kernel, usdc, crimeMoney);
kernel.executeAction(Actions.UpgradeModule, address(moneyVault));
+ moneyShelf.migrateFundsToVault(address(moneyVault));
vm.stopBroadcast();
// Once the problem is solved, GodFather migrate to a new contract and redistribute manually
// all the money to gang members thanks to event monitoring and his accountant.
return moneyVault;
}
}