Skip to content

Commit d97fee0

Browse files
Merge branch 'main' into pod-restarts
2 parents 3b1de5e + d45744b commit d97fee0

File tree

25 files changed

+2752
-80
lines changed

25 files changed

+2752
-80
lines changed

docs/rpc-api.md

Lines changed: 84 additions & 53 deletions
Large diffs are not rendered by default.

packages/ws-server/src/controllers/subscribeController.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import jsonResp from '@hashgraph/json-rpc-server/dist/koaJsonRpc/lib/RpcResponse
1111
import { Context } from 'koa';
1212
import { Logger } from 'pino';
1313

14+
type SubscriptionId = string | undefined;
15+
export interface SubscriptionResponse extends IJsonRpcResponse {
16+
result: SubscriptionId;
17+
}
18+
1419
import { SubscriptionService } from '../service/subscriptionService';
1520
import {
1621
areSubscriptionsEnabled,
@@ -27,15 +32,15 @@ import { ISharedParams } from './jsonRpcController';
2732
* @param {string} event - The event name to subscribe to (e.g., "newHeads").
2833
* @param {Relay} relay - The relay object used for managing WebSocket subscriptions.
2934
* @param {Logger} logger - The logger object used for logging subscription information.
30-
* @returns {string | undefined} Returns the subscription ID.
35+
* @returns {SubscriptionId} Returns the subscription ID.
3136
*/
3237
const subscribeToNewHeads = (
3338
filters: any,
3439
ctx: Context,
3540
event: string,
3641
logger: Logger,
3742
subscriptionService: SubscriptionService,
38-
): string | undefined => {
43+
): SubscriptionId => {
3944
const subscriptionId = subscriptionService.subscribe(ctx.websocket, event, filters);
4045
logger.info(`Subscribed to newHeads, subscriptionId: ${subscriptionId}`);
4146
return subscriptionId;
@@ -51,7 +56,7 @@ const subscribeToNewHeads = (
5156
* @param {Relay} relay - The relay object used for managing WebSocket subscriptions.
5257
* @param {any} logger - The logger object used for logging subscription information.
5358
* @param {RequestDetails} requestDetails - The request details for logging and tracking.
54-
* @returns {{ response: any; subscriptionId: any }} Returns an object containing the response and subscription ID.
59+
* @returns {SubscriptionResponse} Returns an object containing the response and subscription ID.
5560
*/
5661
const handleEthSubscribeNewHeads = (
5762
filters: any,
@@ -61,7 +66,7 @@ const handleEthSubscribeNewHeads = (
6166
logger: Logger,
6267
requestDetails: RequestDetails,
6368
subscriptionService: SubscriptionService,
64-
): IJsonRpcResponse => {
69+
): SubscriptionResponse => {
6570
const wsNewHeadsEnabled = ConfigService.get('WS_NEW_HEADS_ENABLED');
6671

6772
if (!wsNewHeadsEnabled) {
@@ -72,7 +77,7 @@ const handleEthSubscribeNewHeads = (
7277
}
7378

7479
const subscriptionId = subscribeToNewHeads(filters, ctx, event, logger, subscriptionService);
75-
return jsonResp(request.id, null, subscriptionId);
80+
return jsonResp(request.id, null, subscriptionId) as SubscriptionResponse;
7681
};
7782

7883
/**
@@ -86,7 +91,7 @@ const handleEthSubscribeNewHeads = (
8691
* @param {Relay} relay - The relay object used for managing WebSocket subscriptions.
8792
* @param {MirrorNodeClient} mirrorNodeClient - The client for interacting with the MirrorNode API.
8893
* @param {RequestDetails} requestDetails - The request details for logging and tracking.
89-
* @returns {{ response: any; subscriptionId: any }} Returns an object containing the response and subscription ID.
94+
* @returns {Promise<SubscriptionResponse>} Returns an object containing the response and subscription ID.
9095
*/
9196
const handleEthSubscribeLogs = async (
9297
filters: any,
@@ -96,7 +101,7 @@ const handleEthSubscribeLogs = async (
96101
mirrorNodeClient: MirrorNodeClient,
97102
requestDetails: RequestDetails,
98103
subscriptionService: SubscriptionService,
99-
): Promise<IJsonRpcResponse> => {
104+
): Promise<SubscriptionResponse> => {
100105
const validFiltersObject = constructValidLogSubscriptionFilter(filters);
101106

102107
await validateSubscribeEthLogsParams(validFiltersObject, mirrorNodeClient, requestDetails);
@@ -108,7 +113,7 @@ const handleEthSubscribeLogs = async (
108113
throw predefined.INVALID_PARAMETER('filters.address', 'Only one contract address is allowed');
109114
}
110115
const subscriptionId = subscriptionService.subscribe(ctx.websocket, event, validFiltersObject);
111-
return jsonResp(request.id, null, subscriptionId);
116+
return jsonResp(request.id, null, subscriptionId) as SubscriptionResponse;
112117
};
113118

114119
/**
@@ -123,7 +128,7 @@ const handleEthSubscribeLogs = async (
123128
* @param {ConnectionLimiter} args.limiter - The limiter object for managing connection subscriptions.
124129
* @param {Logger} args.logger - The logger object for logging messages and events.
125130
* @param {RequestDetails} args.requestDetails - The request details for logging and tracking.
126-
* @returns {Promise<any>} Returns a promise that resolves with the subscription response.
131+
* @returns {Promise<SubscriptionResponse>} Returns a promise that resolves with the subscription response.
127132
*/
128133
export const handleEthSubscribe = async ({
129134
ctx,
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)