Skip to content

Commit

Permalink
setting peers
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Sep 4, 2024
1 parent 0e3dccb commit 83d8a51
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 24 deletions.
10 changes: 6 additions & 4 deletions src/factory/ImmutableMultiChainDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer {
address _token,
address _lzEndpoint,
address _owner,
RateLimiter.RateLimitConfig[] calldata _rateLimitConfigs
RateLimiter.RateLimitConfig[] calldata _rateLimitConfigs,
address _proxyController
) public returns (address _deployedContract) {
bytes memory bytecode = type(L2YnOFTAdapterUpgradeable).creationCode;
bytes memory constructorParams = abi.encode(_token, _lzEndpoint);
bytes memory contractCode = abi.encodePacked(bytecode, constructorParams);

address adapterImpl = deploy(_implSalt, contractCode);
_deployedContract = deployProxy(_proxySalt, adapterImpl, _owner);
_deployedContract = deployProxy(_proxySalt, adapterImpl, _proxyController);
L2YnOFTAdapterUpgradeable(_deployedContract).initialize(_owner, _rateLimitConfigs);
}

Expand All @@ -83,10 +84,11 @@ contract ImmutableMultiChainDeployer is IImmutableMultiChainDeployer {
bytes32 _proxySalt,
string memory _name,
string memory _symbol,
address _owner
address _owner,
address _proxyController
) public returns (address _deployedContract) {
address adapterImpl = deploy(_implSalt, type(L2YnERC20Upgradeable).creationCode);
_deployedContract = deployProxy(_proxySalt, adapterImpl, _owner);
_deployedContract = deployProxy(_proxySalt, adapterImpl, _proxyController);
L2YnERC20Upgradeable(_deployedContract).initialize(_name, _symbol, _owner);
}

Expand Down
8 changes: 6 additions & 2 deletions src/interfaces/IImmutableMultiChainDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ interface IImmutableMultiChainDeployer {
/// @param _token the token address for the oft adapter to be passed to the initializer
/// @param _lzEndpoint the lz endpoint for the oft adapter to be passed to the initializer
/// @param _rateLimitConfigs the desired rate limit configs for the oft adapter to be passed to the initializer
/// @param _proxyController the proxy controller of the erc20 to be passed to the initializer
/// @return deployed The address of the deployed contract
function deployL2YnOFTAdapter(
bytes32 _implSalt,
bytes32 _proxySalt,
address _token,
address _lzEndpoint,
address _owner,
RateLimiter.RateLimitConfig[] calldata _rateLimitConfigs
RateLimiter.RateLimitConfig[] calldata _rateLimitConfigs,
address _proxyController
) external returns (address deployed);

/// @notice Deploys a deployYnERC20 contract using CREATE3 and initializes in the same call
Expand All @@ -39,13 +41,15 @@ interface IImmutableMultiChainDeployer {
/// @param _name the name of the erc20 to be passed to the initializer
/// @param _symbol the symbol of the erc20 to be passed to the initializer
/// @param _owner the owner of the erc20 to be passed to the initializer
/// @param _proxyController the proxy controller of the erc20 to be passed to the initializer
/// @return deployed The address of the deployed contract
function deployL2YnERC20(
bytes32 _implSalt,
bytes32 _proxySalt,
string memory _name,
string memory _symbol,
address _owner
address _owner,
address _proxyController
) external returns (address deployed);

/// @notice Predicts the address of a deployed contract
Expand Down
43 changes: 28 additions & 15 deletions test/CrossChainBaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {L2YnERC20Upgradeable} from "@adapters/L2YnERC20Upgradeable.sol";
import {L2YnOFTAdapterUpgradeable} from "@adapters/L2YnOFTAdapterUpgradeable.sol";
import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";
import {ERC20Mock} from "@layerzerolabs/lz-evm-oapp-v2/test/mocks/ERC20Mock.sol";
import {EndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/EndpointV2.sol";
import {TestHelper} from "@layerzerolabs/lz-evm-oapp-v2/test/TestHelper.sol";
import "forge-std/console.sol";

Expand All @@ -27,10 +28,12 @@ contract CrossChainBaseTest is TestHelper {
L2YnOFTAdapterUpgradeable public arbitrumOFTAdapter;

address public _deployer = makeAddr("deployer");
address public _owner = makeAddr("owner");
address public _controller = makeAddr("controller");

address public arbitrumLzEndpoint = address(0x1a44076050125825900e736c501f859c50fE728c);
address public optimismLzEndpoint = address(0x1a44076050125825900e736c501f859c50fE728c);
address public mainnetLzEndpoint = address(0x1a44076050125825900e736c501f859c50fE728c);
EndpointV2 public arbitrumLzEndpoint = EndpointV2(0x1a44076050125825900e736c501f859c50fE728c);
EndpointV2 public optimismLzEndpoint = EndpointV2(0x1a44076050125825900e736c501f859c50fE728c);
EndpointV2 public mainnetLzEndpoint = EndpointV2(0x1a44076050125825900e736c501f859c50fE728c);

ERC20Mock public mainnetERC20;
// LZEndpointMock public mainnetLZEndpoint;
Expand All @@ -45,11 +48,15 @@ contract CrossChainBaseTest is TestHelper {
uint256 arbitrumFork;
uint256 mainnetFork;

uint32 mainnetEid;
uint32 optimismEid;
uint32 arbitrumEid;

// uint256 holeskyFork;
// uint256 fraxFork;
// uint256 baseFork;

function setUp() public override {
function setUp() public virtual override {
// create forks
optimismFork = vm.createFork(vm.envString("OPTIMISM_RPC_URL"), 124909408);
arbitrumFork = vm.createFork(vm.envString("ARBITRUM_RPC_URL"), 249855816);
Expand All @@ -71,11 +78,13 @@ contract CrossChainBaseTest is TestHelper {
vm.selectFork(mainnetFork);
mainnetDeployer = new ImmutableMultiChainDeployer{salt: "SALT"}();
mainnetERC20 = new ERC20Mock("Test Token", "TEST");
mainnetOFTAdapterImpl = address(new L1YnOFTAdapterUpgradeable(address(mainnetERC20), mainnetLzEndpoint));
mainnetOFTAdapterImpl =
address(new L1YnOFTAdapterUpgradeable(address(mainnetERC20), address(mainnetLzEndpoint)));
mainnetOFTAdapter = L1YnOFTAdapterUpgradeable(
address(new TransparentUpgradeableProxy(mainnetOFTAdapterImpl, _deployer, ""))
address(new TransparentUpgradeableProxy(mainnetOFTAdapterImpl, _controller, ""))
);
mainnetOFTAdapter.initialize(_deployer, _rateLimitConfigs);
mainnetOFTAdapter.initialize(_owner, _rateLimitConfigs);
mainnetEid = mainnetLzEndpoint.eid();
}

{
Expand All @@ -85,7 +94,7 @@ contract CrossChainBaseTest is TestHelper {
bytes32 optimismERC20ProxySalt = createSalt(_deployer, "ERC20Proxy");
optimismERC20 = L2YnERC20Upgradeable(
optimismDeployer.deployL2YnERC20(
optimismERC20Salt, optimismERC20ProxySalt, "Test Token", "TEST", _deployer
optimismERC20Salt, optimismERC20ProxySalt, "Test Token", "TEST", _owner, _controller
)
);
bytes32 optimismOFTAdapterSalt = createSalt(_deployer, "OFTAdapter");
Expand All @@ -95,11 +104,13 @@ contract CrossChainBaseTest is TestHelper {
optimismOFTAdapterSalt,
optimismOFTAdapterProxySalt,
address(optimismERC20),
optimismLzEndpoint,
_deployer,
_rateLimitConfigs
address(optimismLzEndpoint),
_owner,
_rateLimitConfigs,
_controller
)
);
optimismEid = optimismLzEndpoint.eid();
}

{
Expand All @@ -109,7 +120,7 @@ contract CrossChainBaseTest is TestHelper {
bytes32 arbitrumERC20ProxySalt = createSalt(_deployer, "ERC20Proxy");
arbitrumERC20 = L2YnERC20Upgradeable(
arbitrumDeployer.deployL2YnERC20(
arbitrumERC20Salt, arbitrumERC20ProxySalt, "Test Token", "TEST", _deployer
arbitrumERC20Salt, arbitrumERC20ProxySalt, "Test Token", "TEST", _owner, _controller
)
);
bytes32 arbitrumOFTAdapterSalt = createSalt(_deployer, "OFTAdapter");
Expand All @@ -119,11 +130,13 @@ contract CrossChainBaseTest is TestHelper {
arbitrumOFTAdapterSalt,
arbitrumOFTAdapterProxySalt,
address(arbitrumERC20),
arbitrumLzEndpoint,
_deployer,
_rateLimitConfigs
address(arbitrumLzEndpoint),
_owner,
_rateLimitConfigs,
_controller
)
);
arbitrumEid = arbitrumLzEndpoint.eid();
}

// vm.selectFork(baseFork);
Expand Down
32 changes: 32 additions & 0 deletions test/L1YnOFTAdapterUpgradeable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,42 @@ import {L1YnOFTAdapterUpgradeable} from "@adapters/L1YnOFTAdapterUpgradeable.sol
import {L2YnERC20Upgradeable} from "@adapters/L2YnERC20Upgradeable.sol";
import {L2YnOFTAdapterUpgradeable} from "@adapters/L2YnOFTAdapterUpgradeable.sol";
import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";
import {OApp} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OApp.sol";

import {IOFT, SendParam, OFTReceipt} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol";

contract Test_L1YnOFTAdapterUpgradeable is CrossChainBaseTest {
address public userA = address(0x1);
address public userB = address(0x2);
address public userC = address(0x3);

function setUp() public override {
super.setUp();

vm.deal(userA, 1000 ether);
vm.deal(userB, 1000 ether);
vm.deal(userC, 1000 ether);

// config and wire the ofts
wireMultichainOApps();
}

function wireMultichainOApps() public {
vm.startPrank(_owner);
vm.selectFork(mainnetFork);
mainnetOFTAdapter.setPeer(arbitrumEid, addressToBytes32(address(arbitrumOFTAdapter)));
mainnetOFTAdapter.setPeer(optimismEid, addressToBytes32(address(optimismOFTAdapter)));

vm.selectFork(arbitrumFork);
arbitrumOFTAdapter.setPeer(mainnetEid, addressToBytes32(address(mainnetOFTAdapter)));
arbitrumOFTAdapter.setPeer(optimismEid, addressToBytes32(address(optimismOFTAdapter)));

vm.selectFork(optimismFork);
optimismOFTAdapter.setPeer(mainnetEid, addressToBytes32(address(mainnetOFTAdapter)));
optimismOFTAdapter.setPeer(arbitrumEid, addressToBytes32(address(arbitrumOFTAdapter)));
vm.stopPrank();
}

// function test_contructor() public {
// vm.selectFork(mainnetFork);
// assertEq(aOFT.owner(), address(this));
Expand Down
7 changes: 4 additions & 3 deletions test/MultiChainDeployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ contract Test_ImmutableMultiChainDeployer is CrossChainBaseTest {
keccak256(abi.encode("test")),
keccak256(abi.encode("proxySalt")),
address(arbitrumERC20),
arbitrumLzEndpoint,
_deployer,
_rateLimitConfigs
address(arbitrumLzEndpoint),
_owner,
_rateLimitConfigs,
_controller
)
);
}
Expand Down

0 comments on commit 83d8a51

Please sign in to comment.