|
| 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