Skip to content

Commit

Permalink
Add relayer to bootstrap script
Browse files Browse the repository at this point in the history
  • Loading branch information
yorhodes committed Nov 22, 2024
1 parent aa714c3 commit 53c047f
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 21 deletions.
4 changes: 4 additions & 0 deletions bootstrap.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 35 additions & 21 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
# screen -r supersim
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"devDependencies": {
"@hyperlane-xyz/cli": "^7.1.0"
Expand Down
84 changes: 84 additions & 0 deletions script/HyperlaneSignIntent.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 53c047f

Please sign in to comment.