Skip to content

Commit c623dbd

Browse files
quiet-nodemwb-al
authored andcommitted
feat: Implement LayerZero WHBAR Cross-Chain Bridge with Comprehensive E2E Testing (hiero-ledger#3821)
Signed-off-by: Logan Nguyen <[email protected]>
1 parent 4a074f0 commit c623dbd

File tree

20 files changed

+2646
-10
lines changed

20 files changed

+2646
-10
lines changed
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
1-
# Hedera Network Configuration
2-
HEDERA_CHAIN_ID=
1+
# =============================================================================
2+
# HEDERA NETWORK CONFIGURATION
3+
# =============================================================================
4+
5+
# Hedera JSON-RPC endpoint URL (e.g. https://testnet.hashio.io/api)
36
HEDERA_RPC_URL=
7+
8+
# Hedera account private key
49
HEDERA_PK=
10+
11+
# Hedera block explorer URL (e.g. https://hashscan.io/testnet)
12+
HEDERA_BLOCK_EXPLORER_URL=
13+
14+
# LayerZero V2 Endpoint for Hedera Network (e.g. 0x6EDCE65403992e310A62460808c4b910D972f10f for Hedera Testnet)
15+
# Find LZ Endpoint V2 at https://docs.layerzero.network/v2/deployments/deployed-contracts
516
HEDERA_LZ_ENDPOINT_V2=
17+
18+
# LayerZero Endpoint ID (EID) for Hedera Network (e.g. 40267 for Hedera Testnet)
19+
# Find LZ EID V2 at https://docs.layerzero.network/v2/deployments/deployed-contracts
620
HEDERA_LZ_EID_V2=
721

8-
# Sepolia Network Configuration
9-
SEPOLIA_CHAIN_ID=
22+
# =============================================================================
23+
# SEPOLIA NETWORK CONFIGURATION
24+
# =============================================================================
25+
26+
# Sepolia JSON-RPC endpoint URL (e.g. https://sepolia.infura.io/v3/YOUR_INFURA_PROJECT_ID)
1027
SEPOLIA_RPC_URL=
28+
29+
# Sepolia account private key
1130
SEPOLIA_PK=
12-
SEPOLIA_LZ_ENDPOINT_V2=
13-
SEPOLIA_LZ_EID_V2=
31+
32+
# Sepolia block explorer URL (e.g. https://sepolia.etherscan.io)
33+
SEPOLIA_BLOCK_EXPLORER_URL=
34+
35+
# LayerZero V2 Endpoint for Sepolia Testnet
36+
SEPOLIA_LZ_ENDPOINT_V2=0x6EDCE65403992e310A62460808c4b910D972f10f
37+
38+
# LayerZero Endpoint ID (EID) for Sepolia Testnet
39+
SEPOLIA_LZ_EID_V2=40161
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.22;
3+
4+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5+
6+
contract ERC20Mock is ERC20 {
7+
uint8 decimalsArg = 18;
8+
9+
constructor(uint256 _initialMint, uint8 _decimals) ERC20("ERC20Mock", "E20M") {
10+
_mint(msg.sender, _initialMint);
11+
decimalsArg = _decimals;
12+
}
13+
14+
function decimals() public view override returns (uint8) {
15+
return decimalsArg;
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.22;
3+
4+
import {OFTAdapter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFTAdapter.sol";
5+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
6+
7+
contract ExampleOFTAdapter is OFTAdapter {
8+
constructor(
9+
address _token,
10+
address _lzEndpoint,
11+
address _owner
12+
) OFTAdapter(_token, _lzEndpoint, _owner) Ownable(_owner) {}
13+
}

tools/hedera-crosschain-bridge/contracts/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
/**
5+
* @title SimpleReceiver
6+
* @dev A minimal contract that can receive tokens/ETH
7+
* Used as a test receiver for cross-chain transfers
8+
*/
9+
contract SimpleReceiver {
10+
/**
11+
* @dev Allows the contract to receive ETH/HBAR/tokens
12+
*/
13+
receive() external payable {}
14+
15+
/**
16+
* @dev Fallback function to receive ETH/HBAR/tokens
17+
*/
18+
fallback() external payable {}
19+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.22;
3+
4+
// the contract is based on WETH9 with updated solidity versions and functions
5+
contract WHBAR {
6+
string public name = "Wrapped HBAR";
7+
string public symbol = "WHBAR";
8+
uint8 public decimals = 8;
9+
10+
event Approval(address indexed src, address indexed guy, uint wad);
11+
event Transfer(address indexed src, address indexed dst, uint wad);
12+
event Deposit(address indexed dst, uint wad);
13+
event Withdrawal(address indexed src, uint wad);
14+
15+
mapping(address => uint) public balanceOf;
16+
mapping(address => mapping(address => uint)) public allowance;
17+
18+
fallback() external payable {
19+
deposit();
20+
}
21+
22+
receive() external payable {
23+
deposit();
24+
}
25+
26+
function deposit() public payable {
27+
balanceOf[msg.sender] += msg.value;
28+
29+
emit Deposit(msg.sender, msg.value);
30+
}
31+
32+
function withdraw(uint wad) public {
33+
require(balanceOf[msg.sender] >= wad);
34+
35+
balanceOf[msg.sender] -= wad;
36+
payable(msg.sender).transfer(wad);
37+
38+
emit Withdrawal(msg.sender, wad);
39+
}
40+
41+
function totalSupply() public view returns (uint) {
42+
return address(this).balance;
43+
}
44+
45+
function approve(address guy, uint wad) public returns (bool) {
46+
allowance[msg.sender][guy] = wad;
47+
48+
emit Approval(msg.sender, guy, wad);
49+
50+
return true;
51+
}
52+
53+
function transfer(address dst, uint wad) public returns (bool) {
54+
return transferFrom(msg.sender, dst, wad);
55+
}
56+
57+
function transferFrom(address src, address dst, uint wad) public returns (bool) {
58+
require(balanceOf[src] >= wad);
59+
60+
if (src != msg.sender && allowance[src][msg.sender] !=
61+
type(uint256).max) {
62+
require(allowance[src][msg.sender] >= wad);
63+
allowance[src][msg.sender] -= wad;
64+
}
65+
66+
balanceOf[src] -= wad;
67+
balanceOf[dst] += wad;
68+
69+
emit Transfer(src, dst, wad);
70+
71+
return true;
72+
}
73+
}

tools/hedera-crosschain-bridge/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"name": "hedera-crosschain-bridge",
3-
"scripts": {},
3+
"scripts": {
4+
"deploy-whbar": "hardhat run scripts/deployments/deploy-whbar.ts",
5+
"deploy-erc20": "hardhat run scripts/deployments/deploy-erc20.ts",
6+
"deploy-oftAdapter": "hardhat run scripts/deployments/deploy-oft-adapter.ts",
7+
"deployment-script-test": "hardhat test --grep @deployment-test",
8+
"whbar-e2e-test": "hardhat test --grep @whbar-bridge"
9+
},
410
"license": "Apache-2.0",
511
"devDependencies": {
612
"@layerzerolabs/lz-evm-oapp-v2": "^3.0.98",
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
SCRIPTS_PLACE_HOLDER
1+
# Scripts
2+
3+
This directory contains various scripts designed to streamline development and deployment workflows for the Hedera Crosschain Bridge project. All scripts follow standardized practices to ensure consistency across different environments and use cases.
4+
5+
## Available Script Categories
6+
7+
### Deployments
8+
9+
Smart contract deployment scripts for various blockchain networks. Includes scripts for deploying ERC20 tokens, OFT adapters, and WHBAR tokens across supported networks.
10+
11+
See the [Deployment Guide](./deployments/README.md) for detailed documentation, configuration, and troubleshooting guides.

0 commit comments

Comments
 (0)