Skip to content

Commit

Permalink
sending working
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Sep 4, 2024
1 parent 83d8a51 commit a5624e9
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 48 deletions.
28 changes: 23 additions & 5 deletions test/CrossChainBaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,18 @@ contract CrossChainBaseTest is TestHelper {
// mainnetLZEndpoint = new LZEndpointMock(1);
// optimismLZEndpoint = new LZEndpointMock(10);
// arbitrumLzEndpoint = new LZEndpointMock(42161);
vm.selectFork(mainnetFork);
mainnetEid = mainnetLzEndpoint.eid();

RateLimiter.RateLimitConfig[] memory _rateLimitConfigs = new RateLimiter.RateLimitConfig[](1);
_rateLimitConfigs[0] = RateLimiter.RateLimitConfig({dstEid: uint32(1), limit: 1 ether, window: 1 days});
vm.selectFork(optimismFork);
optimismEid = optimismLzEndpoint.eid();

vm.selectFork(arbitrumFork);
arbitrumEid = arbitrumLzEndpoint.eid();

RateLimiter.RateLimitConfig[] memory _rateLimitConfigs = new RateLimiter.RateLimitConfig[](2);
_rateLimitConfigs[0] = RateLimiter.RateLimitConfig({dstEid: optimismEid, limit: 1000000 ether, window: 1 days});
_rateLimitConfigs[1] = RateLimiter.RateLimitConfig({dstEid: arbitrumEid, limit: 1000000 ether, window: 1 days});

vm.startPrank(_deployer);

Expand All @@ -84,7 +93,6 @@ contract CrossChainBaseTest is TestHelper {
address(new TransparentUpgradeableProxy(mainnetOFTAdapterImpl, _controller, ""))
);
mainnetOFTAdapter.initialize(_owner, _rateLimitConfigs);
mainnetEid = mainnetLzEndpoint.eid();
}

{
Expand All @@ -99,6 +107,10 @@ contract CrossChainBaseTest is TestHelper {
);
bytes32 optimismOFTAdapterSalt = createSalt(_deployer, "OFTAdapter");
bytes32 optimismOFTAdapterProxySalt = createSalt(_deployer, "OFTAdapterProxy");
_rateLimitConfigs[0] =
RateLimiter.RateLimitConfig({dstEid: mainnetEid, limit: 1000000 ether, window: 1 days});
_rateLimitConfigs[1] =
RateLimiter.RateLimitConfig({dstEid: arbitrumEid, limit: 1000000 ether, window: 1 days});
optimismOFTAdapter = L2YnOFTAdapterUpgradeable(
optimismDeployer.deployL2YnOFTAdapter(
optimismOFTAdapterSalt,
Expand All @@ -110,7 +122,6 @@ contract CrossChainBaseTest is TestHelper {
_controller
)
);
optimismEid = optimismLzEndpoint.eid();
}

{
Expand All @@ -125,6 +136,10 @@ contract CrossChainBaseTest is TestHelper {
);
bytes32 arbitrumOFTAdapterSalt = createSalt(_deployer, "OFTAdapter");
bytes32 arbitrumOFTAdapterProxySalt = createSalt(_deployer, "OFTAdapterProxy");
_rateLimitConfigs[0] =
RateLimiter.RateLimitConfig({dstEid: mainnetEid, limit: 1000000 ether, window: 1 days});
_rateLimitConfigs[1] =
RateLimiter.RateLimitConfig({dstEid: optimismEid, limit: 1000000 ether, window: 1 days});
arbitrumOFTAdapter = L2YnOFTAdapterUpgradeable(
arbitrumDeployer.deployL2YnOFTAdapter(
arbitrumOFTAdapterSalt,
Expand All @@ -136,9 +151,12 @@ contract CrossChainBaseTest is TestHelper {
_controller
)
);
arbitrumEid = arbitrumLzEndpoint.eid();
}

endpoints[mainnetEid] = address(mainnetLzEndpoint);
endpoints[optimismEid] = address(optimismLzEndpoint);
endpoints[arbitrumEid] = address(arbitrumLzEndpoint);

// vm.selectFork(baseFork);
// baseDeployer = new ImmutableMultiChainDeployer();

Expand Down
126 changes: 83 additions & 43 deletions test/L1YnOFTAdapterUpgradeable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ 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 {OptionsBuilder} from "@layerzerolabs/lz-evm-oapp-v2/contracts-upgradeable/oapp/libs/OptionsBuilder.sol";
import {
MessagingFee,
MessagingReceipt
} from "@layerzerolabs/lz-evm-oapp-v2/contracts-upgradeable/oft/OFTCoreUpgradeable.sol";

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

contract Test_L1YnOFTAdapterUpgradeable is CrossChainBaseTest {
using OptionsBuilder for bytes;

address public userA = address(0x1);
address public userB = address(0x2);
address public userC = address(0x3);

uint256 public initialBalance = 100 ether;

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

Expand All @@ -26,6 +36,14 @@ contract Test_L1YnOFTAdapterUpgradeable is CrossChainBaseTest {

// config and wire the ofts
wireMultichainOApps();

// mint tokens on mainnet
vm.selectFork(mainnetFork);
vm.startPrank(_owner);
mainnetERC20.mint(userA, initialBalance);
mainnetERC20.mint(userB, initialBalance);
mainnetERC20.mint(userC, initialBalance);
vm.stopPrank();
}

function wireMultichainOApps() public {
Expand All @@ -44,45 +62,67 @@ contract Test_L1YnOFTAdapterUpgradeable is CrossChainBaseTest {
vm.stopPrank();
}

// function test_contructor() public {
// vm.selectFork(mainnetFork);
// assertEq(aOFT.owner(), address(this));
// assertEq(bOFT.owner(), address(this));
// assertEq(cOFTAdapter.owner(), address(this));
//
// assertEq(aOFT.balanceOf(userA), initialBalance);
// assertEq(bOFT.balanceOf(userB), initialBalance);
// assertEq(IERC20(cOFTAdapter.token()).balanceOf(userC), initialBalance);
//
// assertEq(aOFT.token(), address(aOFT));
// assertEq(bOFT.token(), address(bOFT));
// assertEq(cOFTAdapter.token(), address(cERC20Mock));
// }

function test_L1OFTAdapterDeployment() public {}

// function test_send_oft() public {
// uint256 tokensToSend = 1 ether;
// bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200000, 0);
// SendParam memory sendParam = SendParam(
// bEid,
// addressToBytes32(userB),
// tokensToSend,
// tokensToSend,
// options,
// "",
// ""
// );
// MessagingFee memory fee = aOFT.quoteSend(sendParam, false);
//
// assertEq(aOFT.balanceOf(userA), initialBalance);
// assertEq(bOFT.balanceOf(userB), initialBalance);
//
// vm.prank(userA);
// aOFT.send{ value: fee.nativeFee }(sendParam, fee, payable(address(this)));
// verifyPackets(bEid, addressToBytes32(address(bOFT)));
//
// assertEq(aOFT.balanceOf(userA), initialBalance - tokensToSend);
// assertEq(bOFT.balanceOf(userB), initialBalance + tokensToSend);
// }
function test_constructor() public {
vm.selectFork(mainnetFork);
assertEq(mainnetOFTAdapter.owner(), _owner);
assertEq(mainnetOFTAdapter.token(), address(mainnetERC20));
assertEq(mainnetOFTAdapter.peers(arbitrumEid), addressToBytes32(address(arbitrumOFTAdapter)));
assertEq(mainnetOFTAdapter.peers(optimismEid), addressToBytes32(address(optimismOFTAdapter)));
assertEq(mainnetERC20.balanceOf(address(mainnetOFTAdapter)), 0);
assertEq(mainnetERC20.balanceOf(userA), initialBalance);
assertEq(mainnetERC20.balanceOf(userB), initialBalance);
assertEq(mainnetERC20.balanceOf(userC), initialBalance);

vm.selectFork(arbitrumFork);
assertEq(arbitrumOFTAdapter.owner(), _owner);
assertEq(arbitrumOFTAdapter.token(), address(arbitrumERC20));
assertEq(arbitrumOFTAdapter.peers(mainnetEid), addressToBytes32(address(mainnetOFTAdapter)));
assertEq(arbitrumOFTAdapter.peers(optimismEid), addressToBytes32(address(optimismOFTAdapter)));

vm.selectFork(optimismFork);
assertEq(optimismOFTAdapter.owner(), _owner);
assertEq(optimismOFTAdapter.token(), address(optimismERC20));
assertEq(optimismOFTAdapter.peers(mainnetEid), addressToBytes32(address(mainnetOFTAdapter)));
assertEq(optimismOFTAdapter.peers(arbitrumEid), addressToBytes32(address(arbitrumOFTAdapter)));
}

function test_oftVersion() public {
vm.selectFork(mainnetFork);
(bytes4 interfaceId,) = mainnetOFTAdapter.oftVersion();
bytes4 expectedId = 0x02e49c2c;
assertEq(interfaceId, expectedId);

vm.selectFork(arbitrumFork);
(interfaceId,) = arbitrumOFTAdapter.oftVersion();
assertEq(interfaceId, expectedId);

vm.selectFork(optimismFork);
(interfaceId,) = optimismOFTAdapter.oftVersion();
assertEq(interfaceId, expectedId);
}

function test_send_oft() public {
uint256 tokensToSend = 1 ether;
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200000, 0);
SendParam memory sendParam =
SendParam(arbitrumEid, addressToBytes32(userB), tokensToSend, tokensToSend, options, "", "");

vm.selectFork(mainnetFork);
MessagingFee memory fee = mainnetOFTAdapter.quoteSend(sendParam, false);
assertEq(mainnetERC20.balanceOf(userA), initialBalance);

vm.selectFork(arbitrumFork);
assertEq(arbitrumERC20.balanceOf(userB), 0);

vm.selectFork(mainnetFork);
vm.startPrank(userA);
mainnetERC20.approve(address(mainnetOFTAdapter), tokensToSend);
mainnetOFTAdapter.send{value: fee.nativeFee}(sendParam, fee, payable(address(_owner)));
vm.stopPrank();

// verifyPackets(bEid, addressToBytes32(address(bOFT)));
//
// assertEq(aOFT.balanceOf(userA), initialBalance - tokensToSend);
// assertEq(bOFT.balanceOf(userB), initialBalance + tokensToSend);
}
}

0 comments on commit a5624e9

Please sign in to comment.