diff --git a/src/DeployerBase.sol b/src/DeployerBase.sol index d71c255..f5409c0 100644 --- a/src/DeployerBase.sol +++ b/src/DeployerBase.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.20; import {Positions} from "./Positions.sol"; import {Proxy} from "@zkevm-stb/Proxy.sol"; -import {ICREATE3Factory} from "./interfaces/ICREATE3Factory.sol"; +import {CREATE3} from "./libraries/CREATE3.sol"; import {IPolygonZkEVMBridge} from "./interfaces/Polygon/IPolygonZkEVMBridge.sol"; /** @@ -13,10 +13,6 @@ import {IPolygonZkEVMBridge} from "./interfaces/Polygon/IPolygonZkEVMBridge.sol" contract DeployerBase is Positions { uint32 internal constant ORIGIN_NETWORK_ID = 0; - /// @notice Address of the ICREATE3Factory contract used for deployment - ICREATE3Factory internal constant create3Factory = - ICREATE3Factory(0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1); - /*////////////////////////////////////////////////////////////// POSITION ID'S //////////////////////////////////////////////////////////////*/ @@ -50,7 +46,7 @@ contract DeployerBase is Positions { address _l1TokenAddress ) public view virtual returns (address) { return - create3Factory.getDeployed( + _getDeployed( getPositionHolder(L2_DEPLOYER), keccak256(abi.encodePacked(bytes("L2Token:"), _l1TokenAddress)) ); @@ -65,7 +61,7 @@ contract DeployerBase is Positions { address _l1TokenAddress ) public view virtual returns (address) { return - create3Factory.getDeployed( + _getDeployed( getPositionHolder(L1_DEPLOYER), keccak256(abi.encodePacked(bytes("L1Escrow:"), _l1TokenAddress)) ); @@ -80,7 +76,7 @@ contract DeployerBase is Positions { address _l1TokenAddress ) public view virtual returns (address) { return - create3Factory.getDeployed( + _getDeployed( getPositionHolder(L2_DEPLOYER), keccak256(abi.encodePacked(bytes("L2Escrow:"), _l1TokenAddress)) ); @@ -95,7 +91,7 @@ contract DeployerBase is Positions { address _l1TokenAddress ) public view virtual returns (address) { return - create3Factory.getDeployed( + _getDeployed( getPositionHolder(L2_DEPLOYER), keccak256( abi.encodePacked( @@ -106,6 +102,16 @@ contract DeployerBase is Positions { ); } + /** + * @dev Get the expected address based on the deployer and salt. + */ + function _getDeployed( + address deployer, + bytes32 salt + ) internal view virtual returns (address) { + return CREATE3.getDeployed(deployer, salt); + } + /** * @notice Deploy a contract using CREATE3 * @param _salt Salt value for contract deployment @@ -123,6 +129,6 @@ contract DeployerBase is Positions { abi.encode(_implementation, _initData) ); - return create3Factory.deploy(_salt, _creationCode); + return CREATE3.deploy(_salt, _creationCode, 0); } } diff --git a/src/L1Deployer.sol b/src/L1Deployer.sol index 404e5f1..cb4b5e4 100644 --- a/src/L1Deployer.sol +++ b/src/L1Deployer.sol @@ -25,7 +25,7 @@ contract L1Deployer is RoleManager { struct ChainConfig { IPolygonRollupContract rollupContract; address escrowManager; - mapping(address => address) escrows; + mapping(address => address) escrows; // asset => escrow contract } /// @notice Only allow either governance or the position holder to call. @@ -113,7 +113,7 @@ contract L1Deployer is RoleManager { _registerRollup(_rollupID, address(0)); } - // Verify that the vault is not already set for that chain. + // Verify that an escrow is not already deployed for that chain. _l1Escrow = getEscrow(_rollupID, _asset); if (_l1Escrow != address(0)) revert AlreadyDeployed(_l1Escrow); @@ -155,8 +155,6 @@ contract L1Deployer is RoleManager { uint32 _rollupID, address _escrowManager ) internal virtual { - ChainConfig storage chainConfig_ = _chainConfig[_rollupID]; - IPolygonRollupContract _rollupContract = rollupManager .rollupIDToRollupData(_rollupID) .rollupContract; @@ -164,13 +162,16 @@ contract L1Deployer is RoleManager { // Checks the rollup ID is valid address admin = _rollupContract.admin(); // If the caller is not the rollup Admin. - if (msg.sender != _rollupContract.admin()) { + if ( + msg.sender != _rollupContract.admin() || + _escrowManager == address(0) + ) { // Default the manager to be the admin _escrowManager = admin; } - chainConfig_.rollupContract = _rollupContract; - chainConfig_.escrowManager = _escrowManager; + _chainConfig[_rollupID].rollupContract = _rollupContract; + _chainConfig[_rollupID].escrowManager = _escrowManager; emit RegisteredNewRollup( _rollupID, @@ -202,7 +203,7 @@ contract L1Deployer is RoleManager { * @notice Creates a new custom vault and escrow for a specific asset on the specified rollup. * @param _rollupID The ID of the rollup. * @param _asset The address of the asset for which the vault and escrow are created. - * @return _l1Escrow The address of the newly created L1 escrow. + * @return _l1Escrow The address of the L1 escrow. * @return _vault The address of the newly created vault. */ function newCustomVault( @@ -219,17 +220,18 @@ contract L1Deployer is RoleManager { } /** - * @notice Creates a new custom vault for a specific asset on the specified rollup. + * @notice Adds a new custom vault for a specific asset on the specified rollup. * @param _rollupID The ID of the rollup. * @param _asset The address of the asset for which the vault is created. * @param _vault The address of the vault. - * @return _l1Escrow The address of the newly created L1 escrow. + * @return _l1Escrow The address of the L1 escrow. */ function newCustomVault( uint32 _rollupID, address _asset, address _vault ) external virtual onlyRollupAdmin(_rollupID) returns (address _l1Escrow) { + // If the vault has not been registered yet. if (!isVaultsRoleManager(_vault)) { _addNewVault(_rollupID, _vault); } @@ -250,8 +252,6 @@ contract L1Deployer is RoleManager { if (_l1Escrow == address(0)) { _l1Escrow = _deployL1Escrow(_rollupID, _asset, _vault); } - - _assetToVault[_asset][_rollupID] = _vault; } /*////////////////////////////////////////////////////////////// diff --git a/src/L1YearnEscrow.sol b/src/L1YearnEscrow.sol index 285b997..7e41ab2 100644 --- a/src/L1YearnEscrow.sol +++ b/src/L1YearnEscrow.sol @@ -171,7 +171,7 @@ contract L1YearnEscrow is L1Escrow { } } - // Check again to account for if there was underlying + // Check again to account for if there was loose underlying if (amount > maxWithdraw) { // Send an equivalent amount of shares for the difference. uint256 shares = _vault.convertToShares(amount - maxWithdraw); @@ -239,15 +239,18 @@ contract L1YearnEscrow is L1Escrow { // Max approve the new vault originToken.forceApprove(_vaultAddress, 2 ** 256 - 1); - // Deposit any loose funds + // Deposit any loose funds over minimum buffer uint256 balance = originToken.balanceOf(address(this)); - if (balance != 0) - IVault(_vaultAddress).deposit(balance, address(this)); + uint256 minimumBuffer = $.minimumBuffer; + if (balance > minimumBuffer) + IVault(_vaultAddress).deposit( + balance - minimumBuffer, + address(this) + ); } // Update Storage $.vaultAddress = IVault(_vaultAddress); - emit UpdateVaultAddress(_vaultAddress); } diff --git a/src/RoleManager.sol b/src/RoleManager.sol index b4e5606..8667b56 100644 --- a/src/RoleManager.sol +++ b/src/RoleManager.sol @@ -337,6 +337,28 @@ contract RoleManager is DeployerBase { VAULT MANAGEMENT //////////////////////////////////////////////////////////////*/ + /** + * @notice Deploys a new vault to the RoleManager for the default version. + * @dev This will override any existing default vault. + * @param _asset Address of the asset to be used. + */ + function newVault( + address _asset + ) external virtual onlyPositionHolder(GOVERNATOR) { + _newVault(ORIGIN_NETWORK_ID, _asset); + } + + /** + * @notice Adds a new vault to the RoleManager for the default version. + * @dev This will override any existing default vault. + * @param _vault Address of the vault to be added. + */ + function addNewVault( + address _vault + ) external virtual onlyPositionHolder(GOVERNATOR) { + _addNewVault(ORIGIN_NETWORK_ID, _vault); + } + /** * @notice Adds a new vault to the RoleManager with the specified category and debt allocator. * @dev If not already endorsed this function will endorse the vault. diff --git a/src/interfaces/ICREATE3Factory.sol b/src/interfaces/ICREATE3Factory.sol deleted file mode 100644 index 461fc5a..0000000 --- a/src/interfaces/ICREATE3Factory.sol +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.23; - -interface ICREATE3Factory { - function getDeployed( - address deployer, - bytes32 salt - ) external view returns (address); - function deploy( - bytes32 salt, - bytes memory creationCode - ) external payable returns (address deployed); -} diff --git a/src/libraries/Bytes32AddressLib.sol b/src/libraries/Bytes32AddressLib.sol new file mode 100644 index 0000000..75c4cf6 --- /dev/null +++ b/src/libraries/Bytes32AddressLib.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity >=0.8.0; + +/// @notice Library for converting between addresses and bytes32 values. +/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/Bytes32AddressLib.sol) +library Bytes32AddressLib { + function fromLast20Bytes( + bytes32 bytesValue + ) internal pure returns (address) { + return address(uint160(uint256(bytesValue))); + } + + function fillLast12Bytes( + address addressValue + ) internal pure returns (bytes32) { + return bytes32(bytes20(addressValue)); + } +} diff --git a/src/libraries/CREATE3.sol b/src/libraries/CREATE3.sol new file mode 100644 index 0000000..62ebda5 --- /dev/null +++ b/src/libraries/CREATE3.sol @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: AGPL-3.0-only +pragma solidity >=0.8.0; + +import {Bytes32AddressLib} from "./Bytes32AddressLib.sol"; + +/// @notice Deploy to deterministic addresses without an initcode factor. +/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/CREATE3.sol) +/// @author Modified from 0xSequence (https://github.com/0xSequence/create3/blob/master/contracts/Create3.sol) +library CREATE3 { + using Bytes32AddressLib for bytes32; + + //--------------------------------------------------------------------------------// + // Opcode | Opcode + Arguments | Description | Stack View // + //--------------------------------------------------------------------------------// + // 0x36 | 0x36 | CALLDATASIZE | size // + // 0x3d | 0x3d | RETURNDATASIZE | 0 size // + // 0x3d | 0x3d | RETURNDATASIZE | 0 0 size // + // 0x37 | 0x37 | CALLDATACOPY | // + // 0x36 | 0x36 | CALLDATASIZE | size // + // 0x3d | 0x3d | RETURNDATASIZE | 0 size // + // 0x34 | 0x34 | CALLVALUE | value 0 size // + // 0xf0 | 0xf0 | CREATE | newContract // + //--------------------------------------------------------------------------------// + // Opcode | Opcode + Arguments | Description | Stack View // + //--------------------------------------------------------------------------------// + // 0x67 | 0x67XXXXXXXXXXXXXXXX | PUSH8 bytecode | bytecode // + // 0x3d | 0x3d | RETURNDATASIZE | 0 bytecode // + // 0x52 | 0x52 | MSTORE | // + // 0x60 | 0x6008 | PUSH1 08 | 8 // + // 0x60 | 0x6018 | PUSH1 18 | 24 8 // + // 0xf3 | 0xf3 | RETURN | // + //--------------------------------------------------------------------------------// + bytes internal constant PROXY_BYTECODE = + hex"67_36_3d_3d_37_36_3d_34_f0_3d_52_60_08_60_18_f3"; + + bytes32 internal constant PROXY_BYTECODE_HASH = keccak256(PROXY_BYTECODE); + + function deploy( + bytes32 salt, + bytes memory creationCode, + uint256 value + ) internal returns (address deployed) { + bytes memory proxyChildBytecode = PROXY_BYTECODE; + + address proxy; + assembly { + // Deploy a new contract with our pre-made bytecode via CREATE2. + // We start 32 bytes into the code to avoid copying the byte length. + proxy := create2( + 0, + add(proxyChildBytecode, 32), + mload(proxyChildBytecode), + salt + ) + } + require(proxy != address(0), "DEPLOYMENT_FAILED"); + + deployed = getDeployed(address(this), salt); + (bool success, ) = proxy.call{value: value}(creationCode); + require(success && deployed.code.length != 0, "INITIALIZATION_FAILED"); + } + + function getDeployed( + address deployer, + bytes32 salt + ) internal pure returns (address) { + address proxy = keccak256( + abi.encodePacked( + // Prefix: + bytes1(0xFF), + // Creator: + deployer, + // Salt: + salt, + // Bytecode hash: + PROXY_BYTECODE_HASH + ) + ).fromLast20Bytes(); + + return + keccak256( + abi.encodePacked( + // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01) + // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex) + hex"d6_94", + proxy, + hex"01" // Nonce of the proxy contract (1) + ) + ).fromLast20Bytes(); + } +} diff --git a/test/L1Deployer.t.sol b/test/L1Deployer.t.sol index 912db89..4509064 100644 --- a/test/L1Deployer.t.sol +++ b/test/L1Deployer.t.sol @@ -122,7 +122,7 @@ contract L1DeployerTest is Setup { assertEq(l1Deployer.getEscrow(rollupID, address(asset)), address(0)); } - function test_registerRollup_badIdea() public { + function test_registerRollup_badId() public { uint32 rollupID = 69; assertEq(l1Deployer.getRollupContract(rollupID), address(0)); assertEq(l1Deployer.getEscrowManager(rollupID), address(0)); @@ -151,7 +151,7 @@ contract L1DeployerTest is Setup { .admin() ); - address _l1Escrow = getL1EscrowAddress(address(asset)); + address _l1Escrow = l1Deployer.getL1EscrowAddress(address(asset)); vm.expectEmit(true, true, true, true, address(l1Deployer)); emit NewL1Escrow(rollupID, _l1Escrow); @@ -186,13 +186,13 @@ contract L1DeployerTest is Setup { assertEq(escrow.polygonZkEVMBridge(), address(polygonZkEVMBridge)); assertEq( escrow.counterpartContract(), - getL2EscrowAddress(address(asset)) + l1Deployer.getL2EscrowAddress(address(asset)) ); assertEq(escrow.counterpartNetwork(), rollupID); assertEq(address(escrow.originTokenAddress()), address(asset)); assertEq( address(escrow.wrappedTokenAddress()), - getL2TokenAddress(address(asset)) + l1Deployer.getL2TokenAddress(address(asset)) ); assertEq(address(escrow.vaultAddress()), address(vault)); assertEq(escrow.minimumBuffer(), 0); @@ -234,7 +234,7 @@ contract L1DeployerTest is Setup { vm.prank(rollupAdmin); IVault(_vault).transfer_role_manager(address(l1Deployer)); - address _l1Escrow = getL1EscrowAddress(address(asset)); + address _l1Escrow = l1Deployer.getL1EscrowAddress(address(asset)); vm.expectRevert("!admin"); l1Deployer.newCustomVault(rollupID, address(asset), _vault); @@ -273,13 +273,13 @@ contract L1DeployerTest is Setup { assertEq(escrow.polygonZkEVMBridge(), address(polygonZkEVMBridge)); assertEq( escrow.counterpartContract(), - getL2EscrowAddress(address(asset)) + l1Deployer.getL2EscrowAddress(address(asset)) ); assertEq(escrow.counterpartNetwork(), rollupID); assertEq(address(escrow.originTokenAddress()), address(asset)); assertEq( address(escrow.wrappedTokenAddress()), - getL2TokenAddress(address(asset)) + l1Deployer.getL2TokenAddress(address(asset)) ); assertEq(address(escrow.vaultAddress()), address(vault)); assertEq(escrow.minimumBuffer(), 0); diff --git a/test/L1Escrow.t.sol b/test/L1Escrow.t.sol index f07e3bf..7d608db 100644 --- a/test/L1Escrow.t.sol +++ b/test/L1Escrow.t.sol @@ -10,7 +10,7 @@ contract EscrowTest is Setup { function setUp() public virtual override { super.setUp(); - l2TokenAddress = getL2TokenAddress(address(asset)); + l2TokenAddress = l1Deployer.getL2TokenAddress(address(asset)); vault = deployMockVault(); } @@ -55,13 +55,7 @@ contract EscrowTest is Setup { ) ); - mockEscrow = L1YearnEscrow( - _create3Deploy( - keccak256(abi.encodePacked(bytes("L1Escrow:"), address(asset))), - address(l1EscrowImpl), - data - ) - ); + mockEscrow = L1YearnEscrow(_deployProxy(address(l1EscrowImpl), data)); assertEq(mockEscrow.owner(), governator); assertTrue(mockEscrow.hasRole(mockEscrow.ESCROW_MANAGER_ROLE(), czar)); @@ -80,7 +74,7 @@ contract EscrowTest is Setup { function test_bridgeAsset(uint256 _amount) public { _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); - address counterPart = getL2EscrowAddress(address(asset)); + address counterPart = l1Deployer.getL2EscrowAddress(address(asset)); mockEscrow = deployMockL1Escrow(); // Simulate a bridge txn @@ -157,7 +151,7 @@ contract EscrowTest is Setup { ) public { _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); _minimumBuffer = bound(_minimumBuffer, 10, maxFuzzAmount); - address counterPart = getL2EscrowAddress(address(asset)); + address counterPart = l1Deployer.getL2EscrowAddress(address(asset)); mockEscrow = deployMockL1Escrow(); @@ -193,7 +187,7 @@ contract EscrowTest is Setup { function test_bridgeAsset_updateVault(uint256 _amount) public { _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); - address counterPart = getL2EscrowAddress(address(asset)); + address counterPart = l1Deployer.getL2EscrowAddress(address(asset)); mockEscrow = deployMockL1Escrow(); @@ -248,7 +242,7 @@ contract EscrowTest is Setup { function test_managerWithdraw(uint256 _amount) public { _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); - address counterPart = getL2EscrowAddress(address(asset)); + address counterPart = l1Deployer.getL2EscrowAddress(address(asset)); mockEscrow = deployMockL1Escrow(); @@ -293,7 +287,7 @@ contract EscrowTest is Setup { function test_illiquidWithdraw(uint256 _amount) public { _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); - address counterPart = getL2EscrowAddress(address(asset)); + address counterPart = l1Deployer.getL2EscrowAddress(address(asset)); mockEscrow = deployMockL1Escrow(); @@ -334,7 +328,7 @@ contract EscrowTest is Setup { ) public { _amount = bound(_amount, minFuzzAmount, maxFuzzAmount); _minimumBuffer = bound(_minimumBuffer, 10, _amount / 2); - address counterPart = getL2EscrowAddress(address(asset)); + address counterPart = l1Deployer.getL2EscrowAddress(address(asset)); mockEscrow = deployMockL1Escrow(); diff --git a/test/L2Deployer.t.sol b/test/L2Deployer.t.sol index 7bfebac..b5d4a02 100644 --- a/test/L2Deployer.t.sol +++ b/test/L2Deployer.t.sol @@ -68,9 +68,11 @@ contract L2DeployerTest is Setup { "ptTKN" ); - address expectedTokenAddress = getL2TokenAddress(_asset); - address expectedEscrowAddress = getL2EscrowAddress(_asset); - address expectedConverterAddress = getL2ConverterAddress(_asset); + address expectedTokenAddress = l1Deployer.getL2TokenAddress(_asset); + address expectedEscrowAddress = l1Deployer.getL2EscrowAddress(_asset); + address expectedConverterAddress = l1Deployer.getL2ConverterAddress( + _asset + ); vm.expectRevert("L2Deployer: Not PolygonZkEVMBridge"); l2Deployer.onMessageReceived(address(l1Deployer), l1RollupID, data); @@ -118,7 +120,9 @@ contract L2DeployerTest is Setup { "ptTKN" ); - address expectedTokenAddress = getL2TokenAddress(address(asset)); + address expectedTokenAddress = l1Deployer.getL2TokenAddress( + address(asset) + ); vm.prank(address(polygonZkEVMBridge)); l2Deployer.onMessageReceived(address(l1Deployer), l1RollupID, data); @@ -188,7 +192,9 @@ contract L2DeployerTest is Setup { "ptTKN" ); - address expectedEscrowAddress = getL2EscrowAddress(address(asset)); + address expectedEscrowAddress = l1Deployer.getL2EscrowAddress( + address(asset) + ); vm.prank(address(polygonZkEVMBridge)); l2Deployer.onMessageReceived(address(l1Deployer), l1RollupID, data); @@ -255,7 +261,7 @@ contract L2DeployerTest is Setup { "ptTKN" ); - address expectedConverterAddress = getL2ConverterAddress( + address expectedConverterAddress = l1Deployer.getL2ConverterAddress( address(asset) ); diff --git a/test/utils/Setup.sol b/test/utils/Setup.sol index 052431a..cf74511 100644 --- a/test/utils/Setup.sol +++ b/test/utils/Setup.sol @@ -20,16 +20,14 @@ import {IVaultFactory} from "@yearn-vaults/interfaces/IVaultFactory.sol"; import {MockTokenizedStrategy} from "../mocks/MockTokenizedStrategy.sol"; -import {ICREATE3Factory} from "../../src/interfaces/ICREATE3Factory.sol"; - +import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import {IAccountant} from "../../src/interfaces/Yearn/IAccountant.sol"; -import {IAccountantFactory} from "../../src/interfaces/Yearn/IAccountantFactory.sol"; - import {IPolygonZkEVMBridge} from "../../src/interfaces/Polygon/IPolygonZkEVMBridge.sol"; +import {IAccountant} from "../../src/interfaces/Yearn/IAccountant.sol"; +import {IAccountantFactory} from "../../src/interfaces/Yearn/IAccountantFactory.sol"; import {Registry, RegistryFactory} from "@vault-periphery/registry/RegistryFactory.sol"; import {DebtAllocator, DebtAllocatorFactory} from "@vault-periphery/debtAllocators/DebtAllocatorFactory.sol"; @@ -39,9 +37,6 @@ contract Setup is ExtendedTest { // Contract instances that we will use repeatedly. ERC20 public asset; - ICREATE3Factory internal constant create3Factory = - ICREATE3Factory(0x93FEC2C00BfE902F733B57c5a6CeeD7CD1384AE1); - IPolygonZkEVMBridge public polygonZkEVMBridge = IPolygonZkEVMBridge(0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe); @@ -204,7 +199,6 @@ contract Setup is ExtendedTest { vm.label(address(l2EscrowImpl), "L2 Escrow IMPL"); vm.label(address(l1EscrowImpl), "L1 escrow IMPL"); vm.label(address(vaultFactory), " vault factory"); - vm.label(address(create3Factory), "Create 3 Factory"); vm.label(address(polygonZkEVMBridge), "Polygon Bridge"); vm.label(address(allocatorFactory), "Allocator Factory"); vm.label(address(l2TokenConverterImpl), "L2 Converter IMPL"); @@ -258,21 +252,22 @@ contract Setup is ExtendedTest { governator, czar, address(polygonZkEVMBridge), - getL2EscrowAddress(address(asset)), + l1Deployer.getL2EscrowAddress(address(asset)), l2RollupID, address(asset), - getL2TokenAddress(address(asset)), + l1Deployer.getL2TokenAddress(address(asset)), address(vault) ) ); - newEscrow = L1YearnEscrow( - _create3Deploy( - keccak256(abi.encodePacked(bytes("L1Escrow:"), address(asset))), - address(l1EscrowImpl), - data - ) - ); + return L1YearnEscrow(_deployProxy(address(l1EscrowImpl), data)); + } + + function _deployProxy( + address implementation, + bytes memory data + ) internal returns (address) { + return address(new Proxy(implementation, data)); } function bridgeAsset( @@ -330,71 +325,7 @@ contract Setup is ExtendedTest { deal(address(_asset), _to, balanceBefore + _amount); } - function getL2TokenAddress( - address _l1TokenAddress - ) public view virtual returns (address) { - return - create3Factory.getDeployed( - address(l2Deployer), - keccak256(abi.encodePacked(bytes("L2Token:"), _l1TokenAddress)) - ); - } - - function getL1EscrowAddress( - address _l1TokenAddress - ) public view virtual returns (address) { - return - create3Factory.getDeployed( - address(l1Deployer), - keccak256(abi.encodePacked(bytes("L1Escrow:"), _l1TokenAddress)) - ); - } - - function getL2EscrowAddress( - address _l1TokenAddress - ) public view virtual returns (address) { - return - create3Factory.getDeployed( - address(l2Deployer), - keccak256(abi.encodePacked(bytes("L2Escrow:"), _l1TokenAddress)) - ); - } - - function getL2ConverterAddress( - address _l1TokenAddress - ) public view virtual returns (address) { - return - create3Factory.getDeployed( - address(l2Deployer), - keccak256( - abi.encodePacked( - bytes("L2TokenConverter:"), - _l1TokenAddress - ) - ) - ); - } - - function _create3Deploy( - bytes32 _salt, - address _implementation, - bytes memory _initData - ) internal returns (address) { - bytes memory _creationCode = abi.encodePacked( - type(Proxy).creationCode, - abi.encode(_implementation, _initData) - ); - - return create3Factory.deploy(_salt, _creationCode); - } - function _setTokenAddrs() internal { - tokenAddrs["WBTC"] = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599; - tokenAddrs["YFI"] = 0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e; - tokenAddrs["WETH"] = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; - tokenAddrs["LINK"] = 0x514910771AF9Ca656af840dff83E8264EcF986CA; - tokenAddrs["USDT"] = 0xdAC17F958D2ee523a2206206994597C13D831ec7; tokenAddrs["DAI"] = 0x6B175474E89094C44Da98b954EedeAC495271d0F; - tokenAddrs["USDC"] = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; } }