Skip to content

Commit

Permalink
refactor: deploy contracts with forge script
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed May 1, 2024
1 parent 6df4df2 commit fd51601
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
36 changes: 11 additions & 25 deletions permissionless-arbitration/contracts/deploy_anvil.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
#!/bin/bash
RPC_URL="http://127.0.0.1:8545"
PK="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
CONCRETE_FACTORIES=("SingleLevelTournamentFactory" \
"TopTournamentFactory" \
"MiddleTournamentFactory" \
"BottomTournamentFactory")
#!/usr/bin/env bash

deployed_factories=()
for factory in ${CONCRETE_FACTORIES[@]}; do
deployed_at=`forge create $factory --rpc-url=$RPC_URL --private-key=$PK | \
grep "Deployed to: " | \
tr -d '\n' | \
tail -c 42`
deployed_factories+=($deployed_at)
done
set -euo pipefail

deployed_at=`forge create TournamentFactory --rpc-url=$RPC_URL --private-key=$PK --constructor-args \
${deployed_factories[0]} \
${deployed_factories[1]} \
${deployed_factories[2]} \
${deployed_factories[3]} | \
grep "Deployed to: " | \
tr -d '\n' | \
tail -c 42`
INITIAL_HASH=`xxd -p -c32 "${MACHINE_PATH}/hash"`

initial_hash=`xxd -p -c32 $MACHINE_PATH/hash`
export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

cast send --private-key=$PK --rpc-url=$RPC_URL $deployed_at "instantiateTop(bytes32)" 0x$initial_hash
forge script \
script/TopTournament.s.sol \
--fork-url "http://127.0.0.1:8545" \
--broadcast \
--sig "run(bytes32)" \
"${INITIAL_HASH}" \
-vvvv
27 changes: 27 additions & 0 deletions permissionless-arbitration/contracts/script/TopTournament.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

pragma solidity ^0.8.17;

import {Script} from "forge-std/Script.sol";

import {Machine} from "src/Machine.sol";

import "src/tournament/factories/TournamentFactory.sol";

contract TopTournamentScript is Script {
function run(Machine.Hash initialHash) external {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));

TournamentFactory factory = new TournamentFactory(
new SingleLevelTournamentFactory(),
new TopTournamentFactory(),
new MiddleTournamentFactory(),
new BottomTournamentFactory()
);

factory.instantiateTop(initialHash);

vm.stopBroadcast();
}
}
1 change: 1 addition & 0 deletions permissionless-arbitration/lua_node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ WORKDIR "/app/contracts"
ADD ./permissionless-arbitration/contracts/foundry.toml .
ADD ./permissionless-arbitration/contracts/lib/ ./lib/
ADD ./permissionless-arbitration/contracts/src/ ./src/
ADD ./permissionless-arbitration/contracts/script/ ./script/

RUN forge --version
RUN forge build
Expand Down

0 comments on commit fd51601

Please sign in to comment.