-
Notifications
You must be signed in to change notification settings - Fork 12
fix: Pay in LZToken (SC-1152) #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+168
−8
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| pragma solidity >=0.8.0; | ||
|
|
||
| import { IERC20 } from "forge-std/interfaces/IERC20.sol"; | ||
|
|
||
| import { OptionsBuilder } from "layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol"; | ||
|
|
||
| import { LZBridgeTesting } from "src/testing/bridges/LZBridgeTesting.sol"; | ||
| import { LZForwarder, ILayerZeroEndpointV2 } from "src/forwarders/LZForwarder.sol"; | ||
| import { LZReceiver, Origin } from "src/receivers/LZReceiver.sol"; | ||
| import { RecordedLogs } from "src/testing/utils/RecordedLogs.sol"; | ||
|
|
||
| import "./IntegrationBase.t.sol"; | ||
|
|
||
| interface ITreasury { | ||
| function setLzTokenEnabled(bool _lzTokenEnabled) external; | ||
| function setLzTokenFee(uint256 _lzTokenFee) external; | ||
| } | ||
|
|
||
| contract LZIntegrationTestWithLZToken is IntegrationBaseTest { | ||
|
|
||
| using DomainHelpers for *; | ||
| using LZBridgeTesting for *; | ||
| using OptionsBuilder for bytes; | ||
|
|
||
| uint32 sourceEndpointId = LZForwarder.ENDPOINT_ID_ETHEREUM; | ||
| uint32 destinationEndpointId; | ||
|
|
||
| address sourceEndpoint = LZForwarder.ENDPOINT_ETHEREUM; | ||
| address destinationEndpoint; | ||
|
|
||
| address lzToken = 0x6985884C4392D348587B19cb9eAAf157F13271cd; | ||
| address lzOwner = 0xBe010A7e3686FdF65E93344ab664D065A0B02478; | ||
| address treasury = 0x5ebB3f2feaA15271101a927869B3A56837e73056; | ||
|
|
||
| Domain destination2; | ||
| Bridge bridge2; | ||
|
|
||
| function setUp() public override { | ||
| super.setUp(); | ||
|
|
||
| source.selectFork(); | ||
|
|
||
| vm.startPrank(lzOwner); | ||
| ILayerZeroEndpointV2(sourceEndpoint).setLzToken(lzToken); | ||
| ITreasury(treasury).setLzTokenEnabled(true); | ||
| ITreasury(treasury).setLzTokenFee(1e18); | ||
| vm.stopPrank(); | ||
| } | ||
|
|
||
| function test_base() public { | ||
| destinationEndpointId = LZForwarder.ENDPOINT_ID_BASE; | ||
| destinationEndpoint = LZForwarder.ENDPOINT_BASE; | ||
|
|
||
| runCrossChainTests(getChain("base").createFork()); | ||
| } | ||
|
|
||
| function test_binance() public { | ||
| destinationEndpointId = LZForwarder.ENDPOINT_ID_BNB; | ||
| destinationEndpoint = LZForwarder.ENDPOINT_BNB; | ||
|
|
||
| runCrossChainTests(getChain("bnb_smart_chain").createFork()); | ||
| } | ||
|
|
||
| function initSourceReceiver() internal override returns (address) { | ||
| return address(new LZReceiver( | ||
| sourceEndpoint, | ||
| destinationEndpointId, | ||
| bytes32(uint256(uint160(destinationAuthority))), | ||
| address(moSource), | ||
| makeAddr("delegate"), | ||
| makeAddr("owner") | ||
| )); | ||
| } | ||
|
|
||
| function initDestinationReceiver() internal override returns (address) { | ||
| return address(new LZReceiver( | ||
| destinationEndpoint, | ||
| sourceEndpointId, | ||
| bytes32(uint256(uint160(sourceAuthority))), | ||
| address(moDestination), | ||
| makeAddr("delegate"), | ||
| makeAddr("owner") | ||
| )); | ||
| } | ||
|
|
||
| function initBridgeTesting() internal override returns (Bridge memory) { | ||
| return LZBridgeTesting.createLZBridge(source, destination); | ||
| } | ||
|
|
||
| function queueSourceToDestination(bytes memory message) internal override { | ||
| // Gas to queue message | ||
| vm.deal(sourceAuthority, 1 ether); | ||
| deal(lzToken, sourceAuthority, 1 ether); | ||
|
|
||
| bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200_000, 0); | ||
|
|
||
| assertEq(IERC20(lzToken).balanceOf(address(sourceAuthority)), 1 ether); | ||
| assertEq(address(sourceAuthority).balance, 1 ether); | ||
|
|
||
| LZForwarder.sendMessage( | ||
| destinationEndpointId, | ||
| bytes32(uint256(uint160(destinationReceiver))), | ||
| ILayerZeroEndpointV2(bridge.sourceCrossChainMessenger), | ||
| message, | ||
| options, | ||
| sourceAuthority, | ||
| true | ||
| ); | ||
|
|
||
| // LZ token and ETH spent | ||
| assertLt(IERC20(lzToken).balanceOf(address(sourceAuthority)), 1 ether); | ||
| assertLt(address(sourceAuthority).balance, 1 ether); | ||
| } | ||
|
Comment on lines
+91
to
+114
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add assertions function queueSourceToDestination(bytes memory message) internal override {
// Gas to queue message
vm.deal(sourceAuthority, 1 ether);
deal(lzToken, sourceAuthority, 1 ether);
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200_000, 0);
assertEq(IERC20(lzToken).balanceOf(address(sourceAuthority)), 1 ether);
assertEq(address(sourceAuthority).balance, 1 ether);
LZForwarder.sendMessage(
destinationEndpointId,
bytes32(uint256(uint160(destinationReceiver))),
ILayerZeroEndpointV2(bridge.sourceCrossChainMessenger),
message,
options,
sourceAuthority,
true
);
// LZ token and ETH spent
assertLt(IERC20(lzToken).balanceOf(address(sourceAuthority)), 1 ether);
assertLt(address(sourceAuthority).balance, 1 ether);
}
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
|
|
||
| function queueDestinationToSource(bytes memory message) internal override { | ||
| vm.deal(destinationAuthority, 1 ether); // Gas to queue message | ||
|
|
||
| bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200_000, 0); | ||
|
|
||
| LZForwarder.sendMessage( | ||
| sourceEndpointId, | ||
| bytes32(uint256(uint160(sourceReceiver))), | ||
| ILayerZeroEndpointV2(bridge.destinationCrossChainMessenger), | ||
| message, | ||
| options, | ||
| destinationAuthority, | ||
| false | ||
| ); | ||
| } | ||
|
|
||
| function relaySourceToDestination() internal override { | ||
| bridge.relayMessagesToDestination(true, sourceAuthority, destinationReceiver); | ||
| } | ||
|
|
||
| function relayDestinationToSource() internal override { | ||
| bridge.relayMessagesToSource(true, destinationAuthority, sourceReceiver); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.