Skip to content

Commit

Permalink
shrunk immutable deployer contract size, fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDeadCe11 committed Sep 5, 2024
1 parent 19ad229 commit cf9d7c3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/factory/ImmutableMultiChainDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/Ra
import {IImmutableMultiChainDeployer} from "@interfaces/IImmutableMultiChainDeployer.sol";
import {L2YnOFTAdapterUpgradeable} from "@adapters/L2YnOFTAdapterUpgradeable.sol";
import {L2YnERC20Upgradeable} from "@adapters/L2YnERC20Upgradeable.sol";
import "forge-std/console.sol";

contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer {
event ContractCreated(address deployedAddress);
Expand Down Expand Up @@ -67,11 +68,11 @@ contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer {
address _lzEndpoint,
address _owner,
RateLimiter.RateLimitConfig[] calldata _rateLimitConfigs,
address _proxyController
address _proxyController,
bytes memory _l2YnOFTAdapterBytecode
) public returns (address _deployedContract) {
bytes memory bytecode = type(L2YnOFTAdapterUpgradeable).creationCode;
bytes memory constructorParams = abi.encode(_token, _lzEndpoint);
bytes memory contractCode = abi.encodePacked(bytecode, constructorParams);
bytes memory contractCode = abi.encodePacked(_l2YnOFTAdapterBytecode, constructorParams);

address adapterImpl = deploy(_implSalt, contractCode);
_deployedContract = deployProxy(_proxySalt, adapterImpl, _proxyController);
Expand All @@ -85,9 +86,10 @@ contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer {
string memory _name,
string memory _symbol,
address _owner,
address _proxyController
address _proxyController,
bytes memory _l2YnERC20UpgradeableByteCode
) public returns (address _deployedContract) {
address adapterImpl = deploy(_implSalt, type(L2YnERC20Upgradeable).creationCode);
address adapterImpl = deploy(_implSalt, _l2YnERC20UpgradeableByteCode);
_deployedContract = deployProxy(_proxySalt, adapterImpl, _proxyController);
L2YnERC20Upgradeable(_deployedContract).initialize(_name, _symbol, _owner);
}
Expand Down
6 changes: 4 additions & 2 deletions src/interfaces/IImmutableMultiChainDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ interface IImmutableMultiChainDeployer {
address _lzEndpoint,
address _owner,
RateLimiter.RateLimitConfig[] calldata _rateLimitConfigs,
address _proxyController
address _proxyController,
bytes memory _l2YnOFTAdapterBytecode
) external returns (address deployed);

/// @notice Deploys a deployYnERC20 contract using CREATE3 and initializes in the same call
Expand All @@ -49,7 +50,8 @@ interface IImmutableMultiChainDeployer {
string memory _name,
string memory _symbol,
address _owner,
address _proxyController
address _proxyController,
bytes memory _l2YnOFTAdapterBytecode
) external returns (address deployed);

/// @notice Predicts the address of a deployed contract
Expand Down
26 changes: 22 additions & 4 deletions test/CrossChainBaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ contract CrossChainBaseTest is TestHelper {
L2YnERC20Upgradeable public optimismERC20;
L2YnERC20Upgradeable public arbitrumERC20;

bytes public l2YnOFTAdapterByteCode = type(L2YnOFTAdapterUpgradeable).creationCode;
bytes public l1YnOFTAdapterByteCode = type(L1YnOFTAdapterUpgradeable).creationCode;
bytes public l2YnERC20ByteCode = type(L2YnERC20Upgradeable).creationCode;

address mainnetOFTAdapterImpl;

uint256 optimismFork;
Expand Down Expand Up @@ -86,7 +90,13 @@ contract CrossChainBaseTest is TestHelper {
bytes32 optimismERC20ProxySalt = createSalt(_deployer, "ERC20Proxy");
optimismERC20 = L2YnERC20Upgradeable(
optimismDeployer.deployL2YnERC20(
optimismERC20Salt, optimismERC20ProxySalt, "Test Token", "TEST", _owner, _controller
optimismERC20Salt,
optimismERC20ProxySalt,
"Test Token",
"TEST",
_owner,
_controller,
l2YnERC20ByteCode
)
);
bytes32 optimismOFTAdapterSalt = createSalt(_deployer, "OFTAdapter");
Expand All @@ -99,7 +109,8 @@ contract CrossChainBaseTest is TestHelper {
address(optimismLzEndpoint),
_owner,
_rateLimitConfigs,
_controller
_controller,
l2YnOFTAdapterByteCode
)
);
}
Expand All @@ -111,7 +122,13 @@ contract CrossChainBaseTest is TestHelper {
bytes32 arbitrumERC20ProxySalt = createSalt(_deployer, "ERC20Proxy");
arbitrumERC20 = L2YnERC20Upgradeable(
arbitrumDeployer.deployL2YnERC20(
arbitrumERC20Salt, arbitrumERC20ProxySalt, "Test Token", "TEST", _owner, _controller
arbitrumERC20Salt,
arbitrumERC20ProxySalt,
"Test Token",
"TEST",
_owner,
_controller,
l2YnERC20ByteCode
)
);
bytes32 arbitrumOFTAdapterSalt = createSalt(_deployer, "OFTAdapter");
Expand All @@ -124,7 +141,8 @@ contract CrossChainBaseTest is TestHelper {
address(arbitrumLzEndpoint),
_owner,
_rateLimitConfigs,
_controller
_controller,
l2YnOFTAdapterByteCode
)
);
}
Expand Down
3 changes: 2 additions & 1 deletion test/MultiChainDeployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ contract Test_ImmutableMultiChainDeployer is CrossChainBaseTest {
address(arbitrumLzEndpoint),
_owner,
_rateLimitConfigs,
_controller
_controller,
l2YnOFTAdapterByteCode
)
);
}
Expand Down

0 comments on commit cf9d7c3

Please sign in to comment.