constructor

This commit is contained in:
yellow 2024-10-25 22:37:40 +02:00
parent 4bcf23a9ac
commit 9873dfc76b
6 changed files with 31 additions and 13 deletions

View File

@ -4,7 +4,8 @@ Idle game & shitcoin advanture dedicated to cohort VII of Raid Guild.
## Set up for local DEV ## Set up for local DEV
### 1. Run `anvil` to setup local RPC ### 1. Run `anvil` to setup local RPC as a fork of base mainnet
anvil --rpc-url <you'r base mainnet rpc url>
### 2. Deploy contract ### 2. Deploy contract
@ -14,14 +15,14 @@ Either use `./deploy_contract.sh` script (!! change contract values and set priv
Move to `app` dir, install deps via `npm install` and run `npm run dev` to start the dev server. Move to `app` dir, install deps via `npm install` and run `npm run dev` to start the dev server.
#### 3. 1. Run `cast rpc anvil_mine` #### 3. 1. Point Metamask to Anvil network for local dev
This is so time gets set on the local chain, otherwise you will start at 0 time and first mint will give you bajillion GELD. #### 3. 2. Change `app/contract_address.ts` to match your program address if needed
#### 3. 2. Point Metamask to Anvil network for local dev
#### 3. 3. Change `app/contract_address.ts` to match your program address if needed
### 4. Local development requires mining blocks by hand ### 4. Local development requires mining blocks by hand
Call `cast rpc anvil_mine` to mine next block, otherwise it wont ever progress and time "stands still" as far as the game is concerned Call `cast rpc anvil_mine` to mine next block, otherwise it wont ever progress and time "stands still" as far as the game is concerned
### 5. Fork tests
forge test --rpc-url <you'r base mainnet rpc url>

View File

@ -4,14 +4,16 @@ pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol"; import {Script, console} from "forge-std/Script.sol";
import {RaidGeld} from "../src/RaidGeld.sol"; import {RaidGeld} from "../src/RaidGeld.sol";
contract RaidGeldScript is Script { import {Constants} from "../src/Constants.sol";
contract RaidGeldScript is Script, Constants {
RaidGeld public raidgeld; RaidGeld public raidgeld;
function setUp() public {} function setUp() public {}
function run() public { function run() public {
vm.startBroadcast(); vm.startBroadcast();
raidgeld = new RaidGeld(); raidgeld = new RaidGeld(DAO_TOKEN, POOL);
vm.stopBroadcast(); vm.stopBroadcast();
} }
} }

8
src/Constants.sol Normal file
View File

@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract Constants {
//base addresses
address public constant DAO_TOKEN = 0x11dC980faf34A1D082Ae8A6a883db3A950a3c6E8;
address public constant POOL = 0x27004f6d0c1bB7979367D32Ba9d6DF6d61A18926;
}

View File

@ -16,13 +16,19 @@ contract RaidGeld is ERC20, Ownable {
mapping(address => Player) private players; mapping(address => Player) private players;
mapping(address => Army) private armies; mapping(address => Army) private armies;
ERC20 public daoToken;
address public pool;
// Modifier for functions that should only be available to registered players // Modifier for functions that should only be available to registered players
modifier onlyPlayer() { modifier onlyPlayer() {
require(players[msg.sender].created_at != 0, "Not an initiated player"); require(players[msg.sender].created_at != 0, "Not an initiated player");
_; _;
} }
constructor() ERC20("Raid Geld", "GELD") Ownable(msg.sender) {} constructor(address _daoToken, address _pool) ERC20("Raid Geld", "GELD") Ownable(msg.sender) {
daoToken = ERC20(_daoToken);
pool = _pool;
}
// This effectively registers the user // This effectively registers the user
function register() external payable { function register() external payable {

View File

@ -4,8 +4,9 @@ pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol"; import {Test, console} from "forge-std/Test.sol";
import {RaidGeld, Army, Player} from "../src/RaidGeld.sol"; import {RaidGeld, Army, Player} from "../src/RaidGeld.sol";
import "../src/RaidGeldUtils.sol"; import "../src/RaidGeldUtils.sol";
import {Constants} from "../src/Constants.sol";
contract raid_geldTest is Test { contract raid_geldTest is Test, Constants {
RaidGeld public raid_geld; RaidGeld public raid_geld;
address public player1; address public player1;
address public player2; address public player2;
@ -17,7 +18,7 @@ contract raid_geldTest is Test {
vm.deal(owner, 10 ether); vm.deal(owner, 10 ether);
vm.deal(player1, 10 ether); vm.deal(player1, 10 ether);
vm.prank(owner); vm.prank(owner);
raid_geld = new RaidGeld(); raid_geld = new RaidGeld(DAO_TOKEN, POOL);
} }
function registerPlayer() private { function registerPlayer() private {

View File

@ -2,7 +2,7 @@
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol"; import {Test, console} from "forge-std/Test.sol";
import {Army, Raider} from "../src/RaidGeld.sol"; import {Army, Raider} from "../src/RaidGeldStructs.sol";
import "../src/RaidGeldUtils.sol"; import "../src/RaidGeldUtils.sol";
contract raid_geldTest is Test { contract raid_geldTest is Test {