Skip to content

Commit 97c63bf

Browse files
richard998821anonrichard
authored
Feature/core composer (#9)
* feat:add HyperCore Composer for bridge * test: add HyperCore Composer test * refactor: extract the same internal logic for warpAndbridge * feat:add mainnet composer deploy * delete unused readme --------- Co-authored-by: anon <anon@emailhub.kr> Co-authored-by: richard <richard@noreply.google.com>
1 parent d46bab4 commit 97c63bf

5 files changed

Lines changed: 1054 additions & 98 deletions
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.26;
3+
4+
import "forge-std/Script.sol";
5+
import "forge-std/console2.sol";
6+
7+
import {DStockHyperCoreComposer} from "../src/DStockHyperCoreComposer.sol";
8+
9+
/// @notice Deploy DStockHyperCoreComposer on HyperEVM and configure BNB1 token.
10+
/// @dev Run with --rpc-url <HYPEREVM_RPC> [--broadcast]
11+
///
12+
/// Required env:
13+
/// - DEPLOYER_PK (or ADMIN_PK)
14+
/// - LZ_ENDPOINT
15+
/// - OWNER_ADDRESS
16+
/// - BNB1_OFT_ADDRESS
17+
///
18+
/// Optional env (defaults shown):
19+
/// - BNB1_TOKEN_INDEX (414)
20+
/// - BNB1_DECIMAL_DIFF (9)
21+
contract DeployHyperCoreComposer is Script {
22+
function run() external {
23+
uint256 adminPk = vm.envOr("DEPLOYER_PK", uint256(0));
24+
if (adminPk == 0) {
25+
adminPk = vm.envUint("ADMIN_PK");
26+
}
27+
address endpoint = vm.envAddress("LZ_ENDPOINT");
28+
address owner = vm.envAddress("OWNER_ADDRESS");
29+
address bnb1Oft = vm.envAddress("BNB1_OFT_ADDRESS");
30+
31+
uint64 bnb1Index = uint64(vm.envOr("BNB1_TOKEN_INDEX", uint256(414)));
32+
int8 bnb1DecimalDiff = int8(int256(vm.envOr("BNB1_DECIMAL_DIFF", uint256(9))));
33+
34+
vm.startBroadcast(adminPk);
35+
36+
DStockHyperCoreComposer composer = new DStockHyperCoreComposer(endpoint, owner);
37+
composer.configureToken(bnb1Oft, bnb1Index, bnb1DecimalDiff);
38+
39+
vm.stopBroadcast();
40+
41+
console2.log("DStockHyperCoreComposer:", address(composer));
42+
console2.log("Configured BNB1 OFT:", bnb1Oft);
43+
console2.log("BNB1 token index:", bnb1Index);
44+
console2.log("BNB1 decimal diff:", bnb1DecimalDiff);
45+
}
46+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.26;
3+
4+
import "forge-std/Script.sol";
5+
import "forge-std/console2.sol";
6+
7+
import {DStockComposerRouter} from "../src/DStockComposerRouter.sol";
8+
9+
/// @notice Mainnet experiment for direct BSC native -> HyperCore via router + composer.
10+
/// @dev Calls router.wrapAndBridgeNativeToComposer(...).
11+
///
12+
/// Required env:
13+
/// - DEPLOYER_PK
14+
/// - ROUTER_PROXY
15+
/// - COMPOSER_ADDRESS
16+
///
17+
/// Optional env (defaults shown):
18+
/// - RECEIVER_ADDRESS (deployer)
19+
/// - DST_EID (30367)
20+
/// - BRIDGE_AMOUNT_WEI (100000000000000) // 0.0001 BNB
21+
/// - MIN_AMOUNT_LD (0)
22+
/// - MIN_MSG_VALUE (0)
23+
/// - EXTRA_OPTIONS_HEX (required for compose execution; must include lzReceive + lzCompose)
24+
contract MainnetRouterBridgeToHyperCoreExperiment is Script {
25+
struct RunConfig {
26+
address routerAddr;
27+
address composer;
28+
address receiver;
29+
uint32 dstEid;
30+
uint256 amountNative;
31+
uint256 minAmountLD;
32+
uint256 minMsgValue;
33+
bytes options;
34+
}
35+
36+
function run() external {
37+
uint256 pk = vm.envUint("DEPLOYER_PK");
38+
address deployer = vm.addr(pk);
39+
40+
RunConfig memory cfg;
41+
cfg.routerAddr = vm.envAddress("ROUTER_PROXY");
42+
cfg.composer = vm.envAddress("COMPOSER_ADDRESS");
43+
cfg.receiver = vm.envOr("RECEIVER_ADDRESS", deployer);
44+
cfg.dstEid = uint32(vm.envOr("DST_EID", uint256(30367)));
45+
cfg.amountNative = vm.envOr("BRIDGE_AMOUNT_WEI", uint256(100_000_000_000_000));
46+
cfg.minAmountLD = vm.envOr("MIN_AMOUNT_LD", uint256(0));
47+
cfg.minMsgValue = vm.envOr("MIN_MSG_VALUE", uint256(0));
48+
cfg.options = vm.envBytes("EXTRA_OPTIONS_HEX");
49+
50+
DStockComposerRouter router = DStockComposerRouter(payable(cfg.routerAddr));
51+
52+
uint256 fee = router.quoteWrapAndBridgeNativeToComposer(
53+
cfg.amountNative,
54+
cfg.dstEid,
55+
bytes32(uint256(uint160(cfg.composer))),
56+
cfg.options,
57+
cfg.minMsgValue,
58+
cfg.receiver
59+
);
60+
61+
uint256 totalValue = cfg.amountNative + fee;
62+
63+
console2.log("Router:", cfg.routerAddr);
64+
console2.log("Composer:", cfg.composer);
65+
console2.log("Receiver:", cfg.receiver);
66+
console2.log("Amount Native:", cfg.amountNative);
67+
console2.log("Quoted LZ Fee:", fee);
68+
console2.log("Total msg.value:", totalValue);
69+
70+
vm.startBroadcast(pk);
71+
72+
uint256 amountSentLD = router.wrapAndBridgeNativeToComposer{value: totalValue}(
73+
cfg.amountNative,
74+
cfg.dstEid,
75+
bytes32(uint256(uint160(cfg.composer))),
76+
cfg.options,
77+
cfg.minAmountLD,
78+
cfg.minMsgValue,
79+
cfg.receiver
80+
);
81+
82+
vm.stopBroadcast();
83+
84+
console2.log("Bridged share amountLD:", amountSentLD);
85+
}
86+
}

0 commit comments

Comments
 (0)