Skip to content

Commit

Permalink
feat: deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Bryce committed Nov 16, 2024
1 parent 2d660ae commit 01ae312
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
24 changes: 24 additions & 0 deletions contracts/chaintrap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
71 changes: 71 additions & 0 deletions contracts/chaintrap/scripts/DeployChaintrapArena.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;

import {console2 as console} from "forge-std-1.9.4/Script.sol";
import {DeployScriptBase} from "./common/DeployScriptBase.sol";

import {ChaintrapArena} from "src/arena.sol";

import "./constants.sol";

contract DeployChaintrapArenaScript is DeployScriptBase {

ChaintrapArena arena; // saved by _run() for the benefit of test() methods

function help() public pure {
console.log("-s run() -s test() | -s env() | -s testenv()");
}

function run() public {
startBroadcast();
_env(false);
_run();
vm.stopBroadcast();
}

function runf() public {
startFork();
_env(false);
_run();
vm.stopPrank();
}

function _run() public {

arena = new ChaintrapArena();
arena.idempotentInit();
console.log("%x", address(arena));
}

function test() public {
runf();
}

// --- environments

function env() public view {_env(true);}

function _env(bool show) public view {
// !NOTE: That env file parsing in foundry is super senstive to syntax errors
// - miss a 0x prefix and the key wont be available to envUint
// - make a // comment instead of a # bash style and the whole env will
// be missing

// run env

// test env
// holderPub = vm.envOr("HOLDER_PUB", vm.envOr("POLYZONE_PUB", address(0)));
// account deployment env

if (!show)
return;

console.log("--- chain:");
console.log("FORK_BLOCK: %d", FORK_BLOCK);
console.log("RPC", vm.rpcUrl("rpc"));

console.log("--- game:");
console.log("CHAINTRAP_ADDR: %x", address(arena));
}
}

28 changes: 28 additions & 0 deletions contracts/chaintrap/scripts/common/ActionScriptBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;
import {Test} from "forge-std-1.9.4/Test.sol";
import {Script} from "forge-std-1.9.4/Script.sol";

contract ActionScriptBase is Script {

string RPC;
uint256 fork;

function createFork(uint256 forkBlock) internal {
RPC = vm.rpcUrl("rpc");
fork = vm.createFork(RPC, forkBlock);
vm.selectFork(fork);
}

function startBroadcast(string memory keyName) internal {
// If keyName is not set, the script is assumed to be run with --ledger
uint256 key = 0;
if (bytes(keyName).length != 0)
key = vm.envOr(keyName, uint256(0));
if (key != 0) {
vm.startBroadcast(key);
return;
}
vm.startBroadcast();
}
}
30 changes: 30 additions & 0 deletions contracts/chaintrap/scripts/common/DeployScriptBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;

import {console2 as console } from "forge-std-1.9.4/Test.sol";
import {ActionScriptBase} from "./ActionScriptBase.sol";

contract DeployScriptBase is ActionScriptBase {

uint256 forkDeployKey;
address forkDeployAddr;

uint256 FORK_BLOCK;

function startFork() internal {

FORK_BLOCK = vm.envOr("FORK_BLOCK", uint256(0));
createFork(FORK_BLOCK);
(forkDeployAddr, forkDeployKey) = makeAddrAndKey("FORK_DEPLOY_KEY");
vm.deal(forkDeployAddr, 1 << 128);
vm.startPrank(forkDeployAddr);
}

function startBroadcast() internal {
startBroadcast("DEPLOY_KEY");
}
function startBroadcastPub() internal {
startBroadcast("DEPLOY_PUB");
}
}

3 changes: 3 additions & 0 deletions contracts/chaintrap/scripts/constants.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;
uint256 constant DEFAULT_FORK_BLOCK = 0;

0 comments on commit 01ae312

Please sign in to comment.