Skip to content

Commit

Permalink
Merge pull request #37 from rsproule/feature/server
Browse files Browse the repository at this point in the history
feat: server init
  • Loading branch information
rsproule authored Oct 31, 2023
2 parents b9e640c + 5ffc635 commit 30f99aa
Show file tree
Hide file tree
Showing 22 changed files with 799 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"solidity.formatter": "forge",
"solidity.packageDefaultDependenciesContractsDirectory": "contracts/src",
"solidity.packageDefaultDependenciesDirectory": "contracts/lib",
"editor.formatOnSave": true,
"solidity.compileUsingRemoteVersion": "v0.8.19",
"solidity.enabledAsYouTypeCompilationErrorCheck": true,
Expand Down
34 changes: 34 additions & 0 deletions contracts/broadcast/StartGame.s.sol/5/run-1696540368.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"transactions": [
{
"hash": "0xd1477799ca5f9bdf56384c1f63701fd8232857e449d3ee89c0f8ee0a6b9d6045",
"transactionType": "CALL",
"contractName": null,
"contractAddress": "0xD2605193cc30Be96F69DE74d4c5f5fD286f87650",
"function": null,
"arguments": null,
"transaction": {
"type": "0x02",
"from": "0x3c5cd6c3a8f47443f739597a89a630868f805e2e",
"to": "0xd2605193cc30be96f69de74d4c5f5fd286f87650",
"gas": "0x18838",
"value": "0x0",
"data": "0xbe9a6555",
"nonce": "0x277",
"accessList": []
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [],
"libraries": [],
"pending": [
"0xd1477799ca5f9bdf56384c1f63701fd8232857e449d3ee89c0f8ee0a6b9d6045"
],
"returns": {},
"timestamp": 1696540368,
"chain": 5,
"multi": false,
"commit": "18b1ba4"
}
63 changes: 63 additions & 0 deletions contracts/broadcast/StartGame.s.sol/5/run-1696540399.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"transactions": [
{
"hash": "0xd1477799ca5f9bdf56384c1f63701fd8232857e449d3ee89c0f8ee0a6b9d6045",
"transactionType": "CALL",
"contractName": null,
"contractAddress": "0xD2605193cc30Be96F69DE74d4c5f5fD286f87650",
"function": null,
"arguments": null,
"transaction": {
"type": "0x02",
"from": "0x3c5cd6c3a8f47443f739597a89a630868f805e2e",
"to": "0xd2605193cc30be96f69de74d4c5f5fd286f87650",
"gas": "0x18838",
"value": "0x0",
"data": "0xbe9a6555",
"nonce": "0x277",
"accessList": []
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [
{
"transactionHash": "0xd1477799ca5f9bdf56384c1f63701fd8232857e449d3ee89c0f8ee0a6b9d6045",
"transactionIndex": "0x1",
"blockHash": "0x0f9c292c09042f943f9db32c7796cb6a0ef0e16ba9e8f84bc059a3cc79eab893",
"blockNumber": "0x95c61c",
"from": "0x3c5CD6c3A8f47443f739597A89A630868F805e2e",
"to": "0xD2605193cc30Be96F69DE74d4c5f5fD286f87650",
"cumulativeGasUsed": "0x16dfe",
"gasUsed": "0x11bf6",
"contractAddress": null,
"logs": [
{
"address": "0xD2605193cc30Be96F69DE74d4c5f5fD286f87650",
"topics": [
"0x762f260439bb4be3ef6e4dc2786e2e7bd187d3d80b79057d7a424fe98563e335"
],
"data": "0x",
"blockHash": "0x0f9c292c09042f943f9db32c7796cb6a0ef0e16ba9e8f84bc059a3cc79eab893",
"blockNumber": "0x95c61c",
"transactionHash": "0xd1477799ca5f9bdf56384c1f63701fd8232857e449d3ee89c0f8ee0a6b9d6045",
"transactionIndex": "0x1",
"logIndex": "0x0",
"removed": false
}
],
"status": "0x1",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000100000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000",
"type": "0x2",
"effectiveGasPrice": "0xb2d05e08"
}
],
"libraries": [],
"pending": [],
"returns": {},
"timestamp": 1696540399,
"chain": 5,
"multi": false,
"commit": "18b1ba4"
}
63 changes: 63 additions & 0 deletions contracts/broadcast/StartGame.s.sol/5/run-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"transactions": [
{
"hash": "0xd1477799ca5f9bdf56384c1f63701fd8232857e449d3ee89c0f8ee0a6b9d6045",
"transactionType": "CALL",
"contractName": null,
"contractAddress": "0xD2605193cc30Be96F69DE74d4c5f5fD286f87650",
"function": null,
"arguments": null,
"transaction": {
"type": "0x02",
"from": "0x3c5cd6c3a8f47443f739597a89a630868f805e2e",
"to": "0xd2605193cc30be96f69de74d4c5f5fd286f87650",
"gas": "0x18838",
"value": "0x0",
"data": "0xbe9a6555",
"nonce": "0x277",
"accessList": []
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [
{
"transactionHash": "0xd1477799ca5f9bdf56384c1f63701fd8232857e449d3ee89c0f8ee0a6b9d6045",
"transactionIndex": "0x1",
"blockHash": "0x0f9c292c09042f943f9db32c7796cb6a0ef0e16ba9e8f84bc059a3cc79eab893",
"blockNumber": "0x95c61c",
"from": "0x3c5CD6c3A8f47443f739597A89A630868F805e2e",
"to": "0xD2605193cc30Be96F69DE74d4c5f5fD286f87650",
"cumulativeGasUsed": "0x16dfe",
"gasUsed": "0x11bf6",
"contractAddress": null,
"logs": [
{
"address": "0xD2605193cc30Be96F69DE74d4c5f5fD286f87650",
"topics": [
"0x762f260439bb4be3ef6e4dc2786e2e7bd187d3d80b79057d7a424fe98563e335"
],
"data": "0x",
"blockHash": "0x0f9c292c09042f943f9db32c7796cb6a0ef0e16ba9e8f84bc059a3cc79eab893",
"blockNumber": "0x95c61c",
"transactionHash": "0xd1477799ca5f9bdf56384c1f63701fd8232857e449d3ee89c0f8ee0a6b9d6045",
"transactionIndex": "0x1",
"logIndex": "0x0",
"removed": false
}
],
"status": "0x1",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000100000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000",
"type": "0x2",
"effectiveGasPrice": "0xb2d05e08"
}
],
"libraries": [],
"pending": [],
"returns": {},
"timestamp": 1696540399,
"chain": 5,
"multi": false,
"commit": "18b1ba4"
}
17 changes: 0 additions & 17 deletions contracts/script/FactoryDeployer.s.sol

This file was deleted.

16 changes: 16 additions & 0 deletions contracts/script/StartGame.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { Script, console } from "forge-std/Script.sol";
// import { TankGameFactory } from "src/base/TankGameFactory.sol";
import { TankGame } from "src/base/TankGameV2.sol";

contract StartGameScript is Script {
function run() public {
vm.startBroadcast();
TankGame tankGame = TankGame(0xD2605193cc30Be96F69DE74d4c5f5fD286f87650);

tankGame.start();
vm.stopBroadcast();
}
}
1 change: 0 additions & 1 deletion contracts/script/TankGameDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.19;

import { Script, console } from "forge-std/Script.sol";
// import { TankGameFactory } from "src/base/TankGameFactory.sol";
import { TankGame } from "src/base/TankGameV2.sol";
import { ITankGame } from "src/interfaces/ITankGame.sol";
import { GameView } from "src/view/GameView.sol";
Expand Down
76 changes: 76 additions & 0 deletions contracts/script/TankGameDeployerSim.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { Script, console } from "forge-std/Script.sol";
// import { TankGameFactory } from "src/base/TankGameFactory.sol";
import { TankGame } from "src/base/TankGameV2.sol";
import { ITankGame } from "src/interfaces/ITankGame.sol";
import { GameView } from "src/view/GameView.sol";
import { NonAggression } from "src/hooks/NonAggression.sol";
import { Bounty } from "src/hooks/Bounty.sol";
import { HookFactory } from "src/base/HookFactory.sol";
import { IHooks } from "src/interfaces/IHooks.sol";

contract TankGameDeployerScript is Script {
TankGame public tankGame;

function run() public {
vm.startBroadcast();
address adminAddress = vm.envAddress("ADMIN_ADDRESS");
NamedPlayer[3] memory _staticAddresses = [
NamedPlayer(0x1000000000000000000000000000000000000101, "bot1"),
NamedPlayer(0x1000000000000000000000000000000000000002, "bot2"),
NamedPlayer(adminAddress, "admin")
];

// TankGameFactory factory = new TankGameFactory();
ITankGame.GameSettings memory gs = ITankGame.GameSettings({
playerCount: _staticAddresses.length,
boardSize: 30,
initAPs: 1000,
initHearts: 3,
initShootRange: 3,
epochSeconds: 1 seconds,
buyInMinimum: 0,
revealWaitBlocks: 45 seconds,
root: bytes32(0x0)
});
tankGame = new TankGame(gs, msg.sender);

GameView gameView = new GameView(tankGame);
HookFactory hookFactory = new HookFactory();
console.log("TankGame at address: %s", address(tankGame));
console.log("TankGameView at address: %s", address(gameView));
console.log("HookFactory at address: %s", address(hookFactory));
// join everyone.
for (uint256 i = 0; i < _staticAddresses.length; i++) {
NamedPlayer memory np = _staticAddresses[i];
console.log("Joining %s at address %s", np.name, np.player);
tankGame.join(ITankGame.JoinParams(np.player, new bytes32[](0), np.name));
// for every player give them a default hook for NonAggression and Bounties
// this wont be allowed because hooks only added by owner
// can get around this by allownig the admin to at the beginning
IHooks nonAggro = hookFactory.createHook(tankGame, i + 1, HookFactory.HookRegistry.NonAggression);
IHooks bounty = hookFactory.createHook(tankGame, i + 1, HookFactory.HookRegistry.Bounty);

console.log("Adding bounty hook for %s at address %s", np.name, address(bounty));
console.log("Adding nonaggression hook for %s at address %s", np.name, address(nonAggro));
tankGame.forceAddDefaultHook(i + 1, nonAggro);
tankGame.forceAddDefaultHook(i + 1, bounty);

// done with default hooks. this is temporary solution

// finance this player
// payable(np.player).transfer(0.1 ether); // the piggies are full
}

tankGame.setOwner(address(0));
tankGame.start();
vm.stopBroadcast();
}

struct NamedPlayer {
address player;
string name;
}
}
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "",
"type": "module",
"devDependencies": {
"bun-types": "^1.0.4-canary.20231003T140149"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"scripts": {
"server": "bun run index.ts"
}
}
Loading

0 comments on commit 30f99aa

Please sign in to comment.