-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from catalystdao/layer-zero
Layer Zero integration
- Loading branch information
Showing
36 changed files
with
1,203 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -5,4 +5,5 @@ mumbai= | |
sepolia= | ||
basesepolia= | ||
arbitrumsepolia= | ||
optimismsepolia= | ||
optimismsepolia= | ||
basttestnet= |
This file contains 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 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
Binary file modified
BIN
+151 KB
(110%)
audit/ackee-blockchain-catalyst-generalised-incentives-report.pdf
Binary file not shown.
Submodule LayerZero-v2
added at
3fd23f
Submodule solidity-bytes-utils
added at
e0115c
This file contains 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
forge-std/=lib/forge-std/src/ | ||
openzeppelin/=lib/openzeppelin-contracts/contracts/ | ||
vibc-core-smart-contracts/=lib/vibc-core-smart-contracts/contracts/ | ||
vibc-core-smart-contracts/=lib/vibc-core-smart-contracts/contracts/ | ||
@openzeppelin/=lib/openzeppelin-contracts/ | ||
@layerzerolabs/lz-evm-protocol-v2/=lib/LayerZero-v2/protocol/ | ||
|
||
solidity-bytes-utils/=lib/solidity-bytes-utils/ |
This file contains 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 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,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.22; | ||
|
||
import { ICrossChainReceiver } from "../src/interfaces/ICrossChainReceiver.sol"; | ||
import { IIncentivizedMessageEscrow } from "../src/interfaces/IIncentivizedMessageEscrow.sol"; | ||
|
||
/** | ||
* @title Example application contract | ||
*/ | ||
contract SimpleApplication is ICrossChainReceiver { | ||
|
||
event Event(bytes message); | ||
|
||
IIncentivizedMessageEscrow immutable MESSAGE_ESCROW; | ||
|
||
constructor(address messageEscrow_) { | ||
MESSAGE_ESCROW = IIncentivizedMessageEscrow(messageEscrow_); | ||
} | ||
|
||
function submitMessage( | ||
bytes32 destinationIdentifier, | ||
bytes calldata destinationAddress, | ||
bytes calldata message, | ||
IIncentivizedMessageEscrow.IncentiveDescription calldata incentive, | ||
uint64 deadline | ||
) external payable returns(uint256 gasRefund, bytes32 messageIdentifier) { | ||
(gasRefund, messageIdentifier) = MESSAGE_ESCROW.submitMessage{value: msg.value}( | ||
destinationIdentifier, | ||
destinationAddress, | ||
message, | ||
incentive, | ||
deadline | ||
); | ||
} | ||
|
||
function setRemoteImplementation(bytes32 destinationIdentifier, bytes calldata implementation) external { | ||
MESSAGE_ESCROW.setRemoteImplementation(destinationIdentifier, implementation); | ||
} | ||
|
||
function receiveAck(bytes32 /* destinationIdentifier */, bytes32 /* messageIdentifier */, bytes calldata acknowledgement) external { | ||
emit Event(acknowledgement); | ||
} | ||
|
||
function receiveMessage(bytes32 /* sourceIdentifierbytes */, bytes32 /* messageIdentifier */, bytes calldata /* fromApplication */, bytes calldata message) external returns(bytes calldata acknowledgement) { | ||
emit Event(message); | ||
return message; | ||
} | ||
|
||
receive() external payable {} | ||
} |
This file contains 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,45 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.22; | ||
|
||
import "forge-std/Script.sol"; | ||
import {stdJson} from "forge-std/StdJson.sol"; | ||
|
||
import { BaseMultiChainDeployer} from "./BaseMultiChainDeployer.s.sol"; | ||
|
||
// Import all the Apps for deployment here. | ||
import { IMessageEscrowStructs } from "../src/interfaces/IMessageEscrowStructs.sol"; | ||
import { IIncentivizedMessageEscrow } from "../src/interfaces/IIncentivizedMessageEscrow.sol"; | ||
|
||
import { SimpleApplication } from "./SimpleApplication.sol"; | ||
|
||
contract SubmitMessage is BaseMultiChainDeployer { | ||
function submitMessage(address app, bytes32 destinationIdentifier, bytes memory destinationAddress, string memory message, address refundGasTo) external broadcast { | ||
IMessageEscrowStructs.IncentiveDescription memory incentive = IMessageEscrowStructs.IncentiveDescription({ | ||
maxGasDelivery: 200000, | ||
maxGasAck: 200000, | ||
refundGasTo: refundGasTo, | ||
priceOfDeliveryGas: 1 gwei, | ||
priceOfAckGas: 1 gwei, | ||
targetDelta: 0 | ||
}); | ||
|
||
uint256 incentiveValue = 200000 * 1 gwei * 2; | ||
|
||
SimpleApplication(payable(app)).submitMessage{value: 2807712706467 + incentiveValue}( | ||
destinationIdentifier, | ||
destinationAddress, | ||
abi.encodePacked(message), | ||
incentive, | ||
0 | ||
); | ||
} | ||
|
||
function setRemoteImplementation(address app, bytes32 destinationIdentifier, bytes calldata implementation) broadcast external { | ||
SimpleApplication(payable(app)).setRemoteImplementation(destinationIdentifier, implementation); | ||
} | ||
|
||
function deploySimpleApplication(string[] memory chains, address escrow) iter_chains_string(chains) broadcast external returns(address app) { | ||
app = address(new SimpleApplication{salt: bytes32(0)}(escrow)); | ||
} | ||
} | ||
|
This file contains 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 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,126 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.22; | ||
|
||
import "forge-std/Script.sol"; | ||
import {stdJson} from "forge-std/StdJson.sol"; | ||
|
||
import { BaseMultiChainDeployer} from "../BaseMultiChainDeployer.s.sol"; | ||
|
||
import { IncentivizedLayerZeroEscrow } from "../../src/apps/layerzero/IncentivizedLayerZeroEscrow.sol"; | ||
|
||
import { ILayerZeroEndpointV2 } from "LayerZero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; | ||
|
||
contract InitConfigLayerZero is BaseMultiChainDeployer { | ||
using stdJson for string; | ||
|
||
error IncentivesNotFound(); | ||
|
||
string bridge_config; | ||
|
||
bytes32 constant KECCACK_OF_NOTHING = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; | ||
|
||
// define a list of AMB mappings so we can get their addresses. | ||
mapping(string => address) escrow; | ||
mapping(string => uint32 eid) chainEid; | ||
|
||
function _setInitConfig(string[] memory counterPartyChains) internal { | ||
IncentivizedLayerZeroEscrow lzescrow = IncentivizedLayerZeroEscrow(payable(escrow[currentChainKey])); | ||
ILayerZeroEndpointV2 endpoint = ILayerZeroEndpointV2(lzescrow.ENDPOINT()); | ||
endpoint.eid(); | ||
|
||
// Get all eids. | ||
uint32[] memory remoteEids = getEids(counterPartyChains); | ||
|
||
// Get 1 example of the send library. | ||
address sendLibrary = endpoint.getSendLibrary(address(lzescrow), remoteEids[0]); | ||
|
||
lzescrow.initConfig(sendLibrary, remoteEids); | ||
} | ||
|
||
function _initConfig(string[] memory chains, string[] memory counterPartyChains) iter_chains_string(chains) broadcast internal { | ||
_setInitConfig(counterPartyChains); | ||
} | ||
|
||
function _loadEids(string[] memory chains) iter_chains_string(chains) internal { | ||
IncentivizedLayerZeroEscrow lzescrow = IncentivizedLayerZeroEscrow(payable(escrow[currentChainKey])); | ||
ILayerZeroEndpointV2 endpoint = ILayerZeroEndpointV2(lzescrow.ENDPOINT()); | ||
chainEid[currentChainKey] = endpoint.eid(); | ||
} | ||
|
||
function _loadAllEids(string[] memory chains, string[] memory counterPartyChains) internal { | ||
_loadEids(combineString(chains, counterPartyChains)); | ||
} | ||
|
||
function initConfig(string[] memory chains, string[] memory counterPartyChains) load_config external { | ||
_loadAllEids(chains, counterPartyChains); | ||
_initConfig(chains, counterPartyChains); | ||
} | ||
|
||
//-- Helpers --// | ||
function getEids(string[] memory chains) public view returns(uint32[] memory eids) { | ||
eids = new uint32[](chains.length); | ||
for (uint256 i = 0; i < chains.length; ++i) { | ||
eids[i] = chainEid[chains[i]]; | ||
} | ||
} | ||
|
||
function combineString(string[] memory a, string[] memory b) public pure returns (string[] memory all_chains) { | ||
all_chains = new string[](a.length + b.length); | ||
uint256 i = 0; | ||
for (i = 0; i < a.length; ++i) { | ||
all_chains[i] = a[i]; | ||
} | ||
uint256 j = 0; | ||
for (uint256 p = 0; p < b.length; ++p) { | ||
string memory selected = b[p]; | ||
bool found = false; | ||
for (uint256 q = 0; q < a.length; ++q) { | ||
if (keccak256(abi.encode(a[q])) == keccak256(abi.encode(selected))) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) { | ||
all_chains[i+j] = selected; | ||
++j; | ||
} | ||
} | ||
string[] memory all_chains_copy = all_chains; | ||
all_chains = new string[](i+j); | ||
for (i = 0; i < all_chains.length; ++i) { | ||
all_chains[i] = all_chains_copy[i]; | ||
} | ||
} | ||
|
||
function filter(string[] memory a, string memory val) public pure returns(string[] memory filtered) { | ||
filtered = new string[](a.length - 1); | ||
uint256 j = 0; | ||
for (uint256 i = 0; i < a.length; ++i) { | ||
string memory currentElement = a[i]; | ||
if (keccak256(abi.encodePacked(val)) == keccak256(abi.encodePacked(currentElement))) continue; | ||
filtered[j] = currentElement; | ||
++j; | ||
} | ||
require(j == a.length - 1, "Invalid Index"); // May be because val is replicated in a. | ||
} | ||
|
||
modifier load_config() { | ||
string memory pathRoot = vm.projectRoot(); | ||
string memory pathToAmbConfig = string.concat(pathRoot, "/script/bridge_contracts.json"); | ||
|
||
bridge_config = vm.readFile(pathToAmbConfig); | ||
|
||
string memory bridge = "LayerZero"; | ||
// Get the chains this bridge supports. | ||
string[] memory availableBridgesChains = vm.parseJsonKeys(bridge_config, string.concat(".", bridge)); | ||
for (uint256 j = 0; j < availableBridgesChains.length; ++j) { | ||
string memory chain = availableBridgesChains[j]; | ||
// Decode the address | ||
address escrowContract = vm.parseJsonAddress(bridge_config, string.concat(".", bridge, ".", chain, ".escrow")); | ||
escrow[chain] = escrowContract; | ||
} | ||
|
||
_; | ||
} | ||
} | ||
|
This file contains 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,20 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.22; | ||
|
||
import "forge-std/Script.sol"; | ||
import {stdJson} from "forge-std/StdJson.sol"; | ||
|
||
import { BaseMultiChainDeployer} from "../BaseMultiChainDeployer.s.sol"; | ||
|
||
import { IncentivizedLayerZeroEscrow } from "../../src/apps/layerzero/IncentivizedLayerZeroEscrow.sol"; | ||
|
||
contract LZProcessMessage is BaseMultiChainDeployer { | ||
function processMessage( | ||
address escrow, | ||
bytes calldata rawMessage, | ||
bytes32 feeRecipient | ||
) external broadcast { | ||
IncentivizedLayerZeroEscrow(payable(escrow)).processPacket{value: 2806592784579}(hex"", rawMessage, feeRecipient); | ||
} | ||
} | ||
|
Oops, something went wrong.