Compare commits

..

No commits in common. "aaf1c0fd4649f939a433aff8ef334d6d142baea5" and "07f6b3cefe4e5f2f468f4653aa8d5435ae0de11e" have entirely different histories.

9 changed files with 30 additions and 78 deletions

6
.gitmodules vendored
View File

@ -4,9 +4,3 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/v3-periphery"]
path = lib/v3-periphery
url = https://github.com/uniswap/v3-periphery
[submodule "lib/v3-core"]
path = lib/v3-core
url = https://github.com/uniswap/v3-core

View File

@ -100,7 +100,7 @@ const PlayerProvider = ({ children }: { children: ReactNode }) => {
abi,
address: contractAddress,
functionName: 'register',
value: parseEther("0.0005"),
value: parseEther("0.00005"),
})
}, [writeContract])

@ -1 +0,0 @@
Subproject commit e3589b192d0be27e100cd0daaf6c97204fdb1899

@ -1 +0,0 @@
Subproject commit 80f26c86c57b8a5e4b913f42844d4c8bd274d058

View File

@ -1,3 +1 @@
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
@uniswap/v3-periphery/contracts/=lib/v3-periphery/contracts
@uniswap/v3-core/contracts/=lib/v3-core/contracts

View File

@ -3,6 +3,7 @@ pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol";
import {RaidGeld} from "../src/RaidGeld.sol";
import {Constants} from "../src/Constants.sol";
contract RaidGeldScript is Script, Constants {

View File

@ -5,6 +5,4 @@ contract Constants {
//base addresses
address public constant DAO_TOKEN = 0x11dC980faf34A1D082Ae8A6a883db3A950a3c6E8;
address public constant POOL = 0x27004f6d0c1bB7979367D32Ba9d6DF6d61A18926;
address public constant WETH = 0x4200000000000000000000000000000000000006;
address public constant SWAP_ROUTER = 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD;
}

View File

@ -3,40 +3,28 @@ pragma solidity ^0.8.13;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import {RaidGeldUtils} from "../src/RaidGeldUtils.sol";
import {Army, Player, Raider} from "../src/RaidGeldStructs.sol";
import "../src/Constants.sol";
contract RaidGeld is ERC20, Ownable, Constants {
contract RaidGeld is ERC20, Ownable {
uint256 public constant MANTISSA = 1e4;
uint256 public constant BUY_IN_AMOUNT = 0.0005 ether;
uint256 public constant BUY_IN_AMOUNT = 0.00005 ether;
uint256 public immutable BUY_IN_DAO_TOKEN_AMOUNT;
uint256 public constant INITIAL_GELD = 50 * MANTISSA;
mapping(address => Player) private players;
mapping(address => Army) private armies;
// WETH
IERC20 public immutable weth = IERC20(WETH);
// RGCVII token
ERC20 public daoToken;
// RGCVII pool
address public pool;
// Uniswap
ISwapRouter private constant router = ISwapRouter(SWAP_ROUTER);
// Modifier for functions that should only be available to registered players
modifier onlyPlayer() {
require(players[msg.sender].created_at != 0, "Not an initiated player");
_;
}
// Modifier for functions that should only be available to non initialized players
modifier newPlayer() {
require(players[msg.sender].created_at == 0, "Whoops, player already exists :)");
_;
}
constructor(address _daoToken, address _pool) ERC20("Raid Geld", "GELD") Ownable(msg.sender) {
daoToken = ERC20(_daoToken);
@ -44,13 +32,27 @@ contract RaidGeld is ERC20, Ownable, Constants {
BUY_IN_DAO_TOKEN_AMOUNT = 50 * 10 ** daoToken.decimals();
}
function init_player(address player) private {
// This effectively registers the user
function register() external payable {
require(players[msg.sender].created_at == 0, "Whoops, player already exists :)");
if (msg.value != 0) {
require(msg.value == BUY_IN_AMOUNT, "Incorrect buy in amount");
} else {
//@notice this is not safe for arbitrary tokens, which may not follow the interface eg. USDT
//@notice but should be fine for the DAO token
require(
daoToken.transferFrom(msg.sender, address(this), BUY_IN_DAO_TOKEN_AMOUNT),
"Failed to transfer DAO tokens"
);
}
// Mint some starting tokens to the player
_mint(player, INITIAL_GELD);
_mint(msg.sender, INITIAL_GELD);
// Set initial states
players[player] =
players[msg.sender] =
Player({total_minted: INITIAL_GELD, created_at: block.timestamp, last_raided_at: block.timestamp});
armies[player] = Army({
armies[msg.sender] = Army({
moloch_denier: Raider({level: 0}),
apprentice: Raider({level: 0}),
anointed: Raider({level: 0}),
@ -59,36 +61,6 @@ contract RaidGeld is ERC20, Ownable, Constants {
});
}
// New player want to register with ETH
function register_eth() external payable newPlayer {
require(weth.transferFrom(msg.sender, address(this), BUY_IN_AMOUNT), "Make sure to send exactly 0.0005 eth");
TransferHelper.safeApprove(WETH, address(router), BUY_IN_AMOUNT);
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: WETH,
tokenOut: DAO_TOKEN,
fee: 10000,
recipient: address(this),
deadline: block.timestamp,
amountIn: BUY_IN_AMOUNT,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
router.exactInputSingle(params);
init_player(msg.sender);
}
// New player wants to register with dao
function register_dao() external payable newPlayer {
//@notice this is not safe for arbitrary tokens, which may not follow the interface eg. USDT
//@notice but should be fine for the DAO token
require(
daoToken.transferFrom(msg.sender, address(this), BUY_IN_DAO_TOKEN_AMOUNT),
"Failed to transfer DAO tokens"
);
// Init player
init_player(msg.sender);
}
// Override for default number of decimals
function decimals() public view virtual override returns (uint8) {
return 4;

View File

@ -3,13 +3,12 @@ pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol";
import {stdStorage, StdStorage} from "forge-std/Test.sol";
import {RaidGeld, Army, Player} from "../src/RaidGeld.sol";
import "../src/RaidGeldUtils.sol";
import {Constants} from "../src/Constants.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
contract raid_geldTest is Test, Constants {
using stdStorage for StdStorage;
RaidGeld public raid_geld;
@ -29,23 +28,15 @@ contract raid_geldTest is Test, Constants {
function fundAccount(address _acc) private {
vm.deal(_acc, 10 ether);
stdstore.target(DAO_TOKEN).sig("balanceOf(address)").with_key(_acc).checked_write(100 ether);
stdstore.target(WETH).sig("balanceOf(address)").with_key(_acc).checked_write(100 ether);
}
function getPoolLiquidity() public view {
IUniswapV3Pool pool = IUniswapV3Pool(POOL);
console.log(pool.liquidity());
}
function registerPlayer() private {
getPoolLiquidity();
raid_geld.weth().approve(address(raid_geld), raid_geld.BUY_IN_AMOUNT());
raid_geld.register_eth();
raid_geld.register{value: raid_geld.BUY_IN_AMOUNT()}();
}
function registerPlayerWithDaoToken() private {
raid_geld.daoToken().approve(address(raid_geld), raid_geld.BUY_IN_DAO_TOKEN_AMOUNT());
raid_geld.register_dao();
raid_geld.register();
}
function test_00_no_fallback() public {
@ -139,7 +130,7 @@ contract raid_geldTest is Test, Constants {
function test_03_02_RGCVII_funds_can_be_withdrawn() public {
uint256 initialBalance = raid_geld.daoToken().balanceOf(address(raid_geld));
// Switch to Player 1 and register it
vm.startPrank(player1);
registerPlayerWithDaoToken();
@ -148,7 +139,7 @@ contract raid_geldTest is Test, Constants {
vm.startPrank(owner);
raid_geld.withdraw_dao();
uint256 newBalance = raid_geld.daoToken().balanceOf(address(owner));
uint256 newContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld));
uint256 newContractBalance = raid_geld.daoToken().balanceOf(address(raid_geld));
// contract balance should be empty
assertEq(newContractBalance, 0);