Skip to content

Commit

Permalink
test: migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Grimal committed Oct 15, 2024
1 parent 4a5125b commit 2382b28
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/morpho-blue-bundlers"]
path = lib/morpho-blue-bundlers
url = https://github.com/morpho-org/morpho-blue-bundlers
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ out = "out"
libs = ["lib"]

[profile.default.fuzz]
runs = 16
runs = 32


[profile.default.rpc_endpoints]
Expand Down
1 change: 1 addition & 0 deletions lib/morpho-blue-bundlers
Submodule morpho-blue-bundlers added at 97ecc8
70 changes: 69 additions & 1 deletion test/MorphoTokenMigration.t.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {console} from "lib/forge-std/src/Test.sol";
import {BaseTest} from "./helpers/BaseTest.sol";
import {IMulticall} from "lib/morpho-blue-bundlers/src/interfaces/IMulticall.sol";
import {TransferBundler} from "lib/morpho-blue-bundlers/src/TransferBundler.sol";
import {ERC20WrapperBundler} from "lib/morpho-blue-bundlers/src/ERC20WrapperBundler.sol";
import {IERC20} from
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

// TODO: Test the following:
// - Test migration flow
// - Test bundler wrapping
contract MorphoTokenMigrationTest is BaseTest {
address internal constant BUNDLER_ADDRESS = 0x4095F064B8d3c3548A3bebfd0Bbfd04750E30077;
address internal constant LEGACY_MORPHO = 0x9994E35Db50125E0DF82e4c2dde62496CE330999;

IMulticall internal bundler;
IERC20 internal legacyMorpho;

uint256 internal forkId;

bytes[] internal bundle;

function setUp() public virtual override {
// DEPLOYMENTS
_fork();

vm.prank(MORPHO_DAO);
RolesAuthority(LEGACY_MORPHO).setPublicCapability(0x23b872dd, true);

bundler = IMulticall(BUNDLER_ADDRESS);
legacyMorpho = IERC20(LEGACY_MORPHO);

super.setUp();
}

Expand All @@ -22,4 +42,52 @@ contract MorphoTokenMigrationTest is BaseTest {
forkId = vm.createSelectFork(rpcUrl, forkBlockNumber);
vm.chainId(1);
}

function testDAOMigration() public {
uint256 DAOTokenAmount = legacyMorpho.balanceOf(MORPHO_DAO);

bundle.push(_erc20TransferFrom(LEGACY_MORPHO, DAOTokenAmount));
bundle.push(_erc20WrapperDepositFor(address(wrapper), DAOTokenAmount));

vm.startPrank(MORPHO_DAO);
legacyMorpho.approve(address(bundler), DAOTokenAmount);
bundler.multicall(bundle);
vm.stopPrank();

assertEq(legacyMorpho.balanceOf(MORPHO_DAO), 0, "legacyMorpho.balanceOf(MORPHO_DAO)");
assertEq(legacyMorpho.balanceOf(address(wrapper)), DAOTokenAmount, "legacyMorpho.balanceOf(wrapper)");
assertEq(newMorpho.balanceOf(MORPHO_DAO), DAOTokenAmount, "newMorpho.balanceOf(MORPHO_DAO)");
}

function testMigration(address migrater, uint256 amount) public {
vm.assume(migrater != address(0));
vm.assume(migrater != MORPHO_DAO);
amount = bound(amount, MIN_TEST_AMOUNT, 1_000_000_000e18);

deal(LEGACY_MORPHO, migrater, amount);

bundle.push(_erc20TransferFrom(LEGACY_MORPHO, amount));
bundle.push(_erc20WrapperDepositFor(address(wrapper), amount));

vm.startPrank(migrater);
legacyMorpho.approve(address(bundler), amount);
bundler.multicall(bundle);
vm.stopPrank();

assertEq(legacyMorpho.balanceOf(migrater), 0, "legacyMorpho.balanceOf(migrater)");
assertEq(legacyMorpho.balanceOf(address(wrapper)), amount, "legacyMorpho.balanceOf(wrapper)");
assertEq(newMorpho.balanceOf(migrater), amount, "newMorpho.balanceOf(migrater)");
}

function _erc20WrapperDepositFor(address asset, uint256 amount) internal pure returns (bytes memory) {
return abi.encodeCall(ERC20WrapperBundler.erc20WrapperDepositFor, (asset, amount));
}

function _erc20TransferFrom(address asset, uint256 amount) internal pure returns (bytes memory) {
return abi.encodeCall(TransferBundler.erc20TransferFrom, (asset, amount));
}
}

interface RolesAuthority {
function setPublicCapability(bytes4 functionSig, bool enabled) external;
}
2 changes: 1 addition & 1 deletion test/helpers/BaseTest.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "lib/forge-std/src/Test.sol";
import {Test} from "lib/forge-std/src/Test.sol";
import {MorphoToken} from "../../src/MorphoToken.sol";
import {Wrapper} from "../../src/Wrapper.sol";
import {ERC1967Proxy} from
Expand Down

0 comments on commit 2382b28

Please sign in to comment.