From 53c047ff42bc41759048dea2b9817c1784180b9b Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Fri, 22 Nov 2024 14:12:17 -0500 Subject: [PATCH] Add relayer to bootstrap script --- bootstrap.config | 4 ++ bootstrap.sh | 56 +++++++++++++-------- package.json | 3 ++ script/HyperlaneSignIntent.s.sol | 84 ++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 21 deletions(-) create mode 100644 script/HyperlaneSignIntent.s.sol diff --git a/bootstrap.config b/bootstrap.config index 5355ba3..9aefa11 100644 --- a/bootstrap.config +++ b/bootstrap.config @@ -2,6 +2,10 @@ DEFAULT_DEPLOYER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 DEFAULT_SPONSOR=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 DEFAULT_ALLOCATOR=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC DEFAULT_CLAIMANT=0x90F79bf6EB2c4f870365E785982E1f101E93b906 +DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +SPONSOR_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d +ALLOCATOR_PRIVATE_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a +CLAIMANT_PRIVATE_KEY=0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6 DEFAULT_ID=0x30585dd299e03d12fa4293bc0000000000000000000000000000000000000000 PERMIT2_FACTORY_DEPLOYER=0xD32Ff78579352cA78f416120A9f68b65c410871b PERMIT2_FACTORY_ADDRESS=0x4e59b44847b379578588920cA78FbF26c0B4956C diff --git a/bootstrap.sh b/bootstrap.sh index 05d26e6..ae9bee1 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -34,7 +34,12 @@ load_env echo "Starting supersim..." # Start supersim in a new screen session -screen -dmS supersim supersim +# screen -dmS supersim supersim + +# TODO: revert +anvil --port 8545 --chain-id 900 & +anvil --port 9545 --chain-id 901 & +anvil --port 9546 --chain-id 902 & # Wait a moment for supersim to start sleep 1 @@ -108,40 +113,49 @@ echo "All contract deployments completed." # - deploy an AlwaysOKSponsor and deposit some tokens using AlwaysOKAllocator to it ## NOTE: this is where arbiter deployments and test scripts will go! -hyperlane() { +deploy_hyperlane() { + # cleanup old artifacts + rm ./configs/chains/*/addresses.yaml + # anvil account (derives to to $DEFAULT_DEPLOYER address) export HYP_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - export LOG_LEVEL=debug npx hyperlane core deploy --skip-confirmation --config ./configs/core-config.yaml --registry ./configs --overrides "" --chain l1 - MAILBOX_ONE=$(cat ./configs/chains/l1/addresses.yaml | yq '.mailbox') - DOMAIN_ONE=$(cat ./configs/chains/l1/metadata.yaml | yq '.domainId') - ARBITER_ONE=$(forge create HyperlaneArbiter --rpc-url $CHAIN_ONE_RPC --from $DEFAULT_DEPLOYER --unlocked --constructor-args $MAILBOX_ONE $THE_COMPACT_ADDRESS --json | jq '.deployedTo') + export MAILBOX_ONE=$(cat ./configs/chains/l1/addresses.yaml | yq '.mailbox') + export DOMAIN_ONE=$(cat ./configs/chains/l1/metadata.yaml | yq '.domainId') + export ARBITER_ONE=$(forge create HyperlaneArbiter --json --rpc-url $CHAIN_ONE_RPC --from $DEFAULT_DEPLOYER --unlocked --constructor-args $MAILBOX_ONE $THE_COMPACT_ADDRESS | jq -r '.deployedTo') npx hyperlane core deploy --skip-confirmation --config ./configs/core-config.yaml --registry ./configs --overrides "" --chain opchaina - MAILBOX_TWO=$(cat ./configs/chains/opchaina/addresses.yaml | yq '.mailbox') - DOMAIN_TWO=$(cat ./configs/chains/opchaina/metadata.yaml | yq '.domainId') - ARBITER_TWO=$(forge create HyperlaneArbiter --rpc-url $CHAIN_TWO_RPC --from $DEFAULT_DEPLOYER --unlocked --constructor-args $MAILBOX_TWO $THE_COMPACT_ADDRESS --json | jq '.deployedTo') + export MAILBOX_TWO=$(cat ./configs/chains/opchaina/addresses.yaml | yq '.mailbox') + export DOMAIN_TWO=$(cat ./configs/chains/opchaina/metadata.yaml | yq '.domainId') + export ARBITER_TWO=$(forge create HyperlaneArbiter --json --rpc-url $CHAIN_TWO_RPC --from $DEFAULT_DEPLOYER --unlocked --constructor-args $MAILBOX_TWO $THE_COMPACT_ADDRESS | jq -r '.deployedTo') npx hyperlane core deploy --skip-confirmation --config ./configs/core-config.yaml --registry ./configs --overrides "" --chain opchainb - MAILBOX_THREE=$(cat ./configs/chains/opchainb/addresses.yaml | yq '.mailbox') - DOMAIN_THREE=$(cat ./configs/chains/opchainb/metadata.yaml | yq '.domainId') - ARBITER_THREE=$(forge create HyperlaneArbiter --rpc-url $CHAIN_THREE_RPC --from $DEFAULT_DEPLOYER --unlocked --constructor-args $MAILBOX_TWO $THE_COMPACT_ADDRESS --json | jq '.deployedTo') + export MAILBOX_THREE=$(cat ./configs/chains/opchainb/addresses.yaml | yq '.mailbox') + export DOMAIN_THREE=$(cat ./configs/chains/opchainb/metadata.yaml | yq '.domainId') + export ARBITER_THREE=$(forge create HyperlaneArbiter --json --rpc-url $CHAIN_THREE_RPC --from $DEFAULT_DEPLOYER --unlocked --constructor-args $MAILBOX_TWO $THE_COMPACT_ADDRESS | jq -r '.deployedTo') - cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_ONE_RPC $ARBITER_ONE "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_TWO $ARBITER_TWO - cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_ONE_RPC $ARBITER_ONE "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_THREE $ARBITER_THREE + cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_ONE_RPC $ARBITER_ONE "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_TWO $(yarn leftpad $ARBITER_TWO) + cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_ONE_RPC $ARBITER_ONE "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_THREE $(yarn leftpad $ARBITER_THREE) - cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_ONE_RPC $ARBITER_TWO "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_ONE $ARBITER_ONE - cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_ONE_RPC $ARBITER_TWO "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_THREE $ARBITER_THREE + cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_TWO_RPC $ARBITER_TWO "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_ONE $(yarn leftpad $ARBITER_ONE) + cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_TWO_RPC $ARBITER_TWO "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_THREE $(yarn leftpad $ARBITER_THREE) - cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_ONE_RPC $ARBITER_THREE "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_ONE $ARBITER_ONE - cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_ONE_RPC $ARBITER_THREE "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_TWO $ARBITER_TWO + cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_THREE_RPC $ARBITER_THREE "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_ONE $(yarn leftpad $ARBITER_ONE) + cast send --unlocked --from $DEFAULT_DEPLOYER --rpc-url $CHAIN_THREE_RPC $ARBITER_THREE "enrollRemoteRouter(uint32,bytes32)" $DOMAIN_TWO $(yarn leftpad $ARBITER_TWO) } -hyperlane +deploy_hyperlane + +# start relayer +npx hyperlane relayer --chains l1,opchaina,opchainb --registry ./configs --overrides "" & + +# sign intent and fill on destination +export DOMAIN_ONE_SEPARATOR=$(cast call $THE_COMPACT_ADDRESS "DOMAIN_SEPARATOR()" --rpc-url $CHAIN_ONE_RPC) +forge script script/HyperlaneSignIntent.s.sol --broadcast --rpc-url $CHAIN_TWO_RPC --private-key $CLAIMANT_PRIVATE_KEY -vvvv # Wait a moment before switching over to supersim screen -sleep 0.1 +# sleep 0.1 # Switch over to supersim screen (then ctrl+c to shut down) -screen -r supersim \ No newline at end of file +# screen -r supersim diff --git a/package.json b/package.json index 2572efa..5b505c2 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,9 @@ "dependencies": { "@hyperlane-xyz/core": "^5.8.0" }, + "scripts": { + "leftpad": "node -e \"console.log('0x' + '0'.repeat(32*2 - (process.argv[1].slice(2).length)) + process.argv[1].slice(2))\"" + }, "packageManager": "yarn@4.5.1", "devDependencies": { "@hyperlane-xyz/cli": "^7.1.0" diff --git a/script/HyperlaneSignIntent.s.sol b/script/HyperlaneSignIntent.s.sol new file mode 100644 index 0000000..b444aea --- /dev/null +++ b/script/HyperlaneSignIntent.s.sol @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {Script, console} from "forge-std/Script.sol"; + +import {Compact} from "the-compact/src/types/EIP712Types.sol"; +import {HyperlaneArbiter, Intent} from "src/HyperlaneArbiter.sol"; + +contract HyperlaneSignIntent is Script { + HyperlaneArbiter destinationArbiter; + uint32 destination; + + uint32 origin; + address arbiter; + address allocator; + address sponsor; + address claimant; + bytes32 domainSeparator; + + uint256 sponsorPrivateKey; + uint256 allocatorPrivateKey; + + uint256 id; + + function setUp() public { + // origin commitments + arbiter = vm.envAddress("ARBITER_ONE"); + origin = uint32(vm.envUint("DOMAIN_ONE")); + domainSeparator = vm.envBytes32("DOMAIN_ONE_SEPARATOR"); + allocator = vm.envAddress("DEFAULT_ALLOCATOR"); + sponsor = vm.envAddress("DEFAULT_SPONSOR"); + id = vm.envUint("DEFAULT_ID"); + + sponsorPrivateKey = vm.envUint("SPONSOR_PRIVATE_KEY"); + allocatorPrivateKey = vm.envUint("ALLOCATOR_PRIVATE_KEY"); + + // destination fill interface + claimant = vm.envAddress("DEFAULT_CLAIMANT"); + address _destinationArbiter = vm.envAddress("ARBITER_TWO"); + destination = uint32(vm.envUint("DOMAIN_TWO")); + destinationArbiter = HyperlaneArbiter(_destinationArbiter); + } + + function run() public { + uint256 amount = 1e18; + address token = address(0x0); // native value + uint256 nonce = 0; + uint256 expires = block.timestamp + 1000; + uint256 fee = amount; + uint32 chainId = destination; + + Intent memory intent = Intent(fee, chainId, address(token), sponsor, amount); + Compact memory compact = Compact(arbiter, sponsor, nonce, expires, id, amount); + + bytes32 witness = destinationArbiter.hash(intent); + + bytes32 claimHash = keccak256( + abi.encode( + keccak256( + "Compact(address arbiter,address sponsor,uint256 nonce,uint256 expires,uint256 id,uint256 amount,Intent intent)Intent(uint256 fee,uint32 chainId,address token,address recipient,uint256 amount)" + ), + arbiter, + sponsor, + nonce, + expires, + id, + amount, + witness + ) + ); + + bytes32 digest = keccak256(abi.encodePacked(bytes2(0x1901), domainSeparator, claimHash)); + + (bytes32 r, bytes32 vs) = vm.signCompact(sponsorPrivateKey, digest); + bytes memory sponsorSignature = abi.encodePacked(r, vs); + + (r, vs) = vm.signCompact(allocatorPrivateKey, digest); + bytes memory allocatorSignature = abi.encodePacked(r, vs); + + vm.startBroadcast(); + destinationArbiter.fill{value: amount}(origin, compact, intent, allocatorSignature, sponsorSignature); + vm.stopBroadcast(); + } +}