Skip to content
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

feat: reporter, relayer, executor for Hashi v0.2 #66

Merged
merged 89 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
169d011
feat(reporter): <- adds skeleton for this
allemanfredi Oct 13, 2023
e7b600a
create ABI and AMBHeaderReporterCall script
zengzengzenghuy Oct 15, 2023
aa96a8b
WIP: first draft of reporter scripts
zengzengzenghuy Oct 18, 2023
c310d20
WIP: controller with batching blocks functionality
zengzengzenghuy Oct 20, 2023
55d965e
WIP: add Multiclient class
zengzengzenghuy Oct 21, 2023
8e3656e
feat: controller logic
zengzengzenghuy Oct 22, 2023
6f2f1e8
doc: update README.md
zengzengzenghuy Oct 22, 2023
f802b1c
fix: first review
zengzengzenghuy Oct 23, 2023
bf7dd35
fix: second review
zengzengzenghuy Oct 24, 2023
79883e0
remove unused code
zengzengzenghuy Oct 24, 2023
a7fe83e
remove process.env in class and add data field as constructor parameter
zengzengzenghuy Oct 24, 2023
afb0e58
fix: naming of variables
zengzengzenghuy Oct 24, 2023
1fb6f56
fix: change BlockListener constructur to config
zengzengzenghuy Oct 24, 2023
4422cda
refactor: putting all configurable variables under settings/index.ts
zengzengzenghuy Oct 25, 2023
91981fe
fix: remove lastProcessedBlock and move queryBlockLength logic to ind…
zengzengzenghuy Oct 25, 2023
c902049
fix: remove unused code
zengzengzenghuy Oct 25, 2023
32dffd9
chore(evm): adds gitignore
allemanfredi Oct 25, 2023
96a5ff4
feat: allow each controllers to set interval individually
zengzengzenghuy Oct 26, 2023
5cb88f7
Merge branch 'feat/reporter' of https://github.com/gnosis/hashi into …
zengzengzenghuy Oct 26, 2023
466ef45
feat: added isLightClient check and separate intervals for LC based r…
zengzengzenghuy Oct 26, 2023
fc6c679
feat(reporter): improves classes design, rm not used code and improve…
allemanfredi Oct 26, 2023
5d1cac5
refactor(reporter): rn some vars
allemanfredi Oct 26, 2023
c2e7dff
chore(reporter): fixes compile erros
allemanfredi Oct 27, 2023
40dca77
chore(reporter): rm package-lock.json
allemanfredi Oct 27, 2023
bc7b6f6
feat(reporter): <- dockerizes it
allemanfredi Oct 27, 2023
06b07b1
fix: update .env.example
zengzengzenghuy Oct 27, 2023
719ad57
Merge branch 'feat/reporter' of https://github.com/gnosis/hashi into …
zengzengzenghuy Oct 27, 2023
d0a0972
feat(reporter): handles concurrency for sending a transaction and rn …
allemanfredi Oct 27, 2023
89f4815
Merge branch 'feat/reporter' of https://github.com/gnosis/hashi into …
allemanfredi Oct 27, 2023
baecfdc
fix: update .env.example
zengzengzenghuy Oct 30, 2023
2ba2c56
fix: TelepathyReporterCntroller logic
zengzengzenghuy Oct 30, 2023
b19e6de
Merge branch 'main' into feat/reporter
zengzengzenghuy Nov 3, 2023
742c4c8
feat(reporter): adds more settings and limit AMBReporterController to…
allemanfredi Nov 10, 2023
86d0ac9
fix: wrong transaction nonce error for Telepathy
zengzengzenghuy Nov 14, 2023
12ef0c1
Merge branch 'main' into feat/reporter
allemanfredi Nov 23, 2023
acfb232
feat(reporter): adds WormholeReporterController
allemanfredi Nov 24, 2023
d08d9c1
feat(reporter): adds OptimismReporterController
allemanfredi Nov 24, 2023
ae7a3f6
feat(reporter): adds AxelarReporterController
allemanfredi Nov 24, 2023
3e27cfd
refactor(reporter): adds reporterAddresses within BaseController
allemanfredi Nov 27, 2023
e4a95a3
feat(reporter): adds ConnextReporterController
allemanfredi Nov 27, 2023
94cd1c4
feat(reporter): adds StandardReporterController and adds support to c…
allemanfredi Nov 27, 2023
ec2db70
fix(reporter): fixes wrong param
allemanfredi Nov 27, 2023
7fc61c0
feat(reporter): adds support for ccip, hyperlane and l0
allemanfredi Nov 28, 2023
25f3abf
fix(reporter): fixes lastProcessedBlock within TelepathyReporterContr…
allemanfredi Nov 29, 2023
c2812c7
feat(reporter): adds new l0 and ccip adapters and adds support for ze…
allemanfredi Nov 29, 2023
578ac99
Merge branch 'main' into feat/reporter
allemanfredi Nov 29, 2023
6eb8586
feat(reporter): enabled SygmaReporterController
allemanfredi Dec 1, 2023
e49c49f
feat(reporter): adds ElectronReporterController and changes tsconfig.…
allemanfredi Dec 7, 2023
11e7a86
refactor(reporter): rm fs
allemanfredi Dec 7, 2023
5993963
refactor(reporter): refactors getHeader
allemanfredi Dec 7, 2023
ba754ea
chore: merge from feat/v0.2.0
zengzengzenghuy Jul 10, 2024
b1a3639
WIP: fix controllers to comply with hashi v0.2.0
zengzengzenghuy Jul 10, 2024
782cf3e
WIP: update StandardReporterController
zengzengzenghuy Jul 10, 2024
22e1961
WIP: fix ElectronController type and add AMB for Sepolia and Chiado
zengzengzenghuy Jul 11, 2024
a0a9abd
feat: CCIP Reporter controller
zengzengzenghuy Jul 11, 2024
adbf1ee
chore: change AMB controller into Standard controller
zengzengzenghuy Jul 11, 2024
f5d5e83
WIP: update LayerZero adapter to LZ v2 & fix controller config
zengzengzenghuy Jul 12, 2024
f215268
fix: LayerZeroV2 Reporter & Adapter
zengzengzenghuy Jul 15, 2024
cb557de
feat: add Base config to LayerZero controller
zengzengzenghuy Jul 15, 2024
da427a4
chore: update tsconfig.json and Dockerfile
zengzengzenghuy Jul 15, 2024
b7177be
chore: add configuration logs in Controller class
zengzengzenghuy Jul 15, 2024
aac37d5
update .env.example
zengzengzenghuy Jul 15, 2024
1aeff54
fix: typo and .env.example
zengzengzenghuy Jul 18, 2024
fc6f62d
feat(reporter): update Wormhole Reporter syntax and address
zengzengzenghuy Jul 26, 2024
10a88b5
chore(evm): update Wormhole deploy task
zengzengzenghuy Jul 26, 2024
ea3bd02
misc(relayer): update .env.example
zengzengzenghuy Jul 26, 2024
77e0275
chore(reporter): update AMB reporter variable name
zengzengzenghuy Jul 26, 2024
99a6a2a
feat(reporter): add Base related addresses
zengzengzenghuy Jul 29, 2024
c6558b2
feat: dockerfile and docker compose for executor and relayer
zengzengzenghuy Aug 25, 2024
926ef27
fix: docker-compose format error
zengzengzenghuy Aug 25, 2024
b1517a2
fix: Executor messageIds type & relayer start script
zengzengzenghuy Aug 30, 2024
10f1856
chore(reporter): update reporters and adapters configs
zengzengzenghuy Sep 13, 2024
943ae5f
chore: remove unused ABI files
zengzengzenghuy Sep 16, 2024
0e86e03
chore(reporter): remove redundant addresses in .env.example
zengzengzenghuy Sep 18, 2024
19b0666
chore(evm): rename LayerZeroAdapter.sol enabledReporters mapping
zengzengzenghuy Sep 18, 2024
5e9b58a
chore(reporter): remove SygmaReporterController class
zengzengzenghuy Sep 18, 2024
00e2b98
Merge branch 'feat/v0.2.0' into feat/reporter
allemanfredi Sep 18, 2024
7d03cc0
chore(reporter): delete files unrelated to Hashi v0.2.0
zengzengzenghuy Sep 19, 2024
56bb792
fix(reporter): wormhole reporter ABI file name
zengzengzenghuy Sep 19, 2024
a90cde0
chore(reporter): remove yarn.lock
zengzengzenghuy Sep 19, 2024
681a16f
refactor(reporter,relayer,executor): dockerfile and docker-compose.ym…
zengzengzenghuy Sep 20, 2024
77ff55c
chore(reporter): <- makes it to be part of the workspaces
allemanfredi Sep 20, 2024
c57a4ee
fix(reporter): adds nonce within simulateContract to avoid to generat…
allemanfredi Sep 20, 2024
e43d664
refactor(reporter): update dockerfile and tsconfig.json
zengzengzenghuy Sep 20, 2024
93f96f5
chore: rename image names in docker-compose.yml
zengzengzenghuy Sep 20, 2024
3c0f4f3
docs: update README
zengzengzenghuy Sep 23, 2024
d21c428
chore: delete docker-compose-reporter.yml and merge the code into doc…
zengzengzenghuy Sep 23, 2024
d464ceb
docs: update README
zengzengzenghuy Sep 23, 2024
550f4ba
docs: remove unrelated code in README
zengzengzenghuy Sep 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
**/.coverage_contracts
**/dist
**/node_modules
**/types
**/.yarn

# files
Expand Down
30 changes: 30 additions & 0 deletions Dockerfile.executor
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:18-alpine

WORKDIR /usr/src/app
COPY package.json yarn.lock ./

COPY packages/common/package.json ./packages/common/
COPY packages/executor/package.json ./packages/executor/

RUN yarn install --ignore-scripts

WORKDIR /usr/src/app/packages/common
RUN yarn install --ignore-scripts

WORKDIR /usr/src/app/packages/executor
RUN yarn install --ignore-scripts

WORKDIR /usr/src/app

COPY packages/common/ ./packages/common/
COPY packages/executor/ ./packages/executor/

WORKDIR /usr/src/app/packages/common
RUN yarn compile



WORKDIR /usr/src/app/packages/executor
RUN yarn compile

CMD ["yarn", "start"]
30 changes: 30 additions & 0 deletions Dockerfile.relayer
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:18-alpine

WORKDIR /usr/src/app
COPY package.json yarn.lock ./

COPY packages/common/package.json ./packages/common/
COPY packages/relayer/package.json ./packages/relayer/

RUN yarn install --ignore-scripts

WORKDIR /usr/src/app/packages/common
RUN yarn install --ignore-scripts

WORKDIR /usr/src/app/packages/relayer
RUN yarn install --ignore-scripts

WORKDIR /usr/src/app

COPY packages/common/ ./packages/common/
COPY packages/relayer/ ./packages/relayer/

WORKDIR /usr/src/app/packages/common
RUN yarn compile



WORKDIR /usr/src/app/packages/relayer
RUN yarn compile

CMD ["yarn", "start"]
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "3.8"

services:
mongodb:
image: mongo:latest
container_name: mongodb
ports:
- "27017:27017"
networks:
- mongo-network
volumes:
- mongo-data:/data/db

executor:
build:
context: .
dockerfile: Dockerfile.executor
container_name: executor
networks:
- mongo-network
depends_on:
- mongodb

relayer:
build:
context: .
dockerfile: Dockerfile.relayer
container_name: hashi-relayer
networks:
- mongo-network
depends_on:
- mongodb
networks:
mongo-network:
driver: bridge

volumes:
mongo-data:
driver: local
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\""
},
"dependencies": {
"winston": "^3.11.0",
"viem": "^2.9.28"
"viem": "^2.9.28",
"winston": "^3.11.0"
},
"devDependencies": {
"@types/node": "^20.8.9",
Expand Down
1 change: 1 addition & 0 deletions packages/evm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
types/
45 changes: 33 additions & 12 deletions packages/evm/contracts/adapters/LayerZero/LayerZeroAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,54 @@ pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ILayerZeroReceiver } from "./interfaces/ILayerZeroReceiver.sol";
import { Origin } from "./interfaces/ILayerZeroEndpointV2.sol";
import { OAppCore } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppCore.sol";
import { BlockHashAdapter } from "../BlockHashAdapter.sol";

contract LayerZeroAdapter is BlockHashAdapter, Ownable, ILayerZeroReceiver {
contract LayerZeroAdapter is BlockHashAdapter, Ownable, ILayerZeroReceiver, OAppCore {
string public constant PROVIDER = "layer-zero";
address public immutable LAYER_ZERO_ENDPOINT;

mapping(uint32 => bytes32) public enabledReportersPaths;
mapping(uint32 => address) public enabledReporter;
zengzengzenghuy marked this conversation as resolved.
Show resolved Hide resolved
mapping(uint32 => uint256) public chainIds;

error UnauthorizedLayerZeroReceive();

event ReporterSet(uint256 indexed chainId, uint16 indexed endpointId, address indexed reporter);
event ReporterSet(uint256 indexed chainId, uint32 indexed endpointId, address indexed reporter);

constructor(address lzEndpoint) {
constructor(address lzEndpoint, address delegate) OAppCore(lzEndpoint, delegate) {
LAYER_ZERO_ENDPOINT = lzEndpoint;
}

function lzReceive(uint16 srcEndpointId, bytes memory srcPath, uint64 /* nonce */, bytes memory payload) external {
if (msg.sender != LAYER_ZERO_ENDPOINT || enabledReportersPaths[srcEndpointId] != keccak256(srcPath))
revert UnauthorizedLayerZeroReceive();
uint256 sourceChainId = chainIds[srcEndpointId];
(uint256[] memory ids, bytes32[] memory hashes) = abi.decode(payload, (uint256[], bytes32[]));
_storeHashes(sourceChainId, ids, hashes);
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) external payable {
if (
msg.sender != LAYER_ZERO_ENDPOINT ||
enabledReporter[_origin.srcEid] != address(uint160(uint256(_origin.sender)))
) revert UnauthorizedLayerZeroReceive();
(uint256[] memory ids, bytes32[] memory hashes) = abi.decode(_message, (uint256[], bytes32[]));
_storeHashes(chainIds[_origin.srcEid], ids, hashes);
}

function setReporterByChain(uint256 chainId, uint16 endpointId, address reporter) external onlyOwner {
enabledReportersPaths[endpointId] = keccak256(abi.encodePacked(reporter, address(this)));
function nextNonce(uint32 /*_srcEid*/, bytes32 /*_sender*/) public pure override returns (uint64 nonce) {
return 0;
}

function allowInitializePath(Origin calldata origin) public view override returns (bool) {
return peers[origin.srcEid] == origin.sender;
}

function oAppVersion() public pure virtual override returns (uint64 senderVersion, uint64 receiverVersion) {
return (1, 1);
}

function setReporterByChain(uint256 chainId, uint32 endpointId, address reporter) external onlyOwner {
enabledReporter[endpointId] = reporter;
chainIds[endpointId] = chainId;
emit ReporterSet(chainId, endpointId, reporter);
}
Expand Down
66 changes: 45 additions & 21 deletions packages/evm/contracts/adapters/LayerZero/LayerZeroReporter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,78 @@
pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ILayerZeroEndpoint } from "./interfaces/ILayerZeroEndpoint.sol";
import { ILayerZeroEndpointV2, MessagingParams, MessagingFee, MessagingReceipt } from "./interfaces/ILayerZeroEndpointV2.sol";
import { Reporter } from "../Reporter.sol";
import { OptionsBuilder } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol";
import { OAppCore } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppCore.sol";

contract LayerZeroReporter is Reporter, Ownable, OAppCore {
using OptionsBuilder for bytes;

contract LayerZeroReporter is Reporter, Ownable {
string public constant PROVIDER = "layer-zero";
ILayerZeroEndpoint public immutable LAYER_ZERO_ENDPOINT;
ILayerZeroEndpointV2 public immutable LAYER_ZERO_ENDPOINT;

mapping(uint256 => uint16) public endpointIds;
uint256 public fee;
mapping(uint256 => uint32) public endpointIds;
uint128 public fee;
address refundAddress;

error EndpointIdNotAvailable();

event EndpointIdSet(uint256 indexed chainId, uint16 indexed endpointId);
event EndpointIdSet(uint256 indexed chainId, uint32 indexed endpointId);
event FeeSet(uint256 fee);

constructor(address headerStorage, address yaho, address lzEndpoint) Reporter(headerStorage, yaho) {
LAYER_ZERO_ENDPOINT = ILayerZeroEndpoint(lzEndpoint);
constructor(
address headerStorage,
address yaho,
address lzEndpoint,
address delegate,
address refundAddress_,
uint128 defaultFee_
) Reporter(headerStorage, yaho) OAppCore(lzEndpoint, delegate) {
refundAddress = refundAddress_;
fee = defaultFee_;
LAYER_ZERO_ENDPOINT = ILayerZeroEndpointV2(lzEndpoint);
}

function setEndpointIdByChainId(uint256 chainId, uint16 endpointId) external onlyOwner {
function setEndpointIdByChainId(uint256 chainId, uint32 endpointId) external onlyOwner {
endpointIds[chainId] = endpointId;
emit EndpointIdSet(chainId, endpointId);
}

function setFee(uint256 fee_) external onlyOwner {
function setFee(uint128 fee_) external onlyOwner {
fee = fee_;
emit FeeSet(fee);
}

function setDefaultRefundAddress(address refundAddress_) external onlyOwner {
refundAddress = refundAddress_;
}

function oAppVersion() public pure virtual override returns (uint64 senderVersion, uint64 receiverVersion) {
return (1, 1);
}
function _dispatch(
uint256 targetChainId,
address adapter,
uint256[] memory ids,
bytes32[] memory hashes
) internal override returns (bytes32) {
uint16 targetEndpointId = endpointIds[targetChainId];
uint32 targetEndpointId = endpointIds[targetChainId];
if (targetEndpointId == 0) revert EndpointIdNotAvailable();
bytes memory payload = abi.encode(ids, hashes);
bytes memory path = abi.encodePacked(adapter, address(this));
// solhint-disable-next-line check-send-result
LAYER_ZERO_ENDPOINT.send{ value: fee }(
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(fee, 0);
bytes memory message = abi.encode(ids, hashes);
MessagingParams memory params = MessagingParams(
targetEndpointId,
path,
payload,
payable(msg.sender), // _refundAddress: refund address
address(0), // _zroPaymentAddress: future parameter
bytes("") // _adapterParams: adapterParams (see "Advanced Features")
bytes32(abi.encode(adapter)),
message,
options,
false // receiver in lz Token
);
return bytes32(0);
// solhint-disable-next-line check-send-result
MessagingFee memory msgFee = LAYER_ZERO_ENDPOINT.quote(params, address(this));
MessagingReceipt memory receipt = LAYER_ZERO_ENDPOINT.send{ value: msgFee.nativeFee }(params, refundAddress);
return receipt.guid;
}

receive() external payable {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
bool payInLzToken;
}

struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}

struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}

struct Origin {
uint32 srcEid;
bytes32 sender;
uint64 nonce;
}

interface ILayerZeroEndpointV2 {
event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);

event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);

event PacketDelivered(Origin origin, address receiver);

event LzReceiveAlert(
address indexed receiver,
address indexed executor,
Origin origin,
bytes32 guid,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);

event LzTokenSet(address token);

event DelegateSet(address sender, address delegate);

function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);

function send(
MessagingParams calldata _params,
address _refundAddress
) external payable returns (MessagingReceipt memory);

function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;

function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);

function initializable(Origin calldata _origin, address _receiver) external view returns (bool);

function lzReceive(
Origin calldata _origin,
address _receiver,
bytes32 _guid,
bytes calldata _message,
bytes calldata _extraData
) external payable;

// oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;

function setLzToken(address _lzToken) external;

function lzToken() external view returns (address);

function nativeToken() external view returns (address);

function setDelegate(address _delegate) external;
}
Loading
Loading