-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robin Bryce
committed
Nov 16, 2024
1 parent
2d660ae
commit 01ae312
Showing
5 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |