|
|
|
|
@ -3,28 +3,39 @@ 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";
|
|
|
|
|
|
|
|
|
|
contract RaidGeld is ERC20, Ownable {
|
|
|
|
|
|
|
|
|
|
uint256 public constant MANTISSA = 1e4;
|
|
|
|
|
|
|
|
|
|
uint256 public constant BUY_IN_AMOUNT = 0.00005 ether;
|
|
|
|
|
uint256 public constant BUY_IN_AMOUNT = 0.0005 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 private constant weth = IERC20(Constants.WETH);
|
|
|
|
|
// RGCVII token
|
|
|
|
|
ERC20 public daoToken;
|
|
|
|
|
// RGCVII pool
|
|
|
|
|
address public pool;
|
|
|
|
|
// Uniswap
|
|
|
|
|
ISwapRouter02 private constant router = ISwapRouter02(Constants.SWAP_ROUTER_02);
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
@ -32,27 +43,14 @@ contract RaidGeld is ERC20, Ownable {
|
|
|
|
|
BUY_IN_DAO_TOKEN_AMOUNT = 50 * 10 ** daoToken.decimals();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init_player(address player) private {
|
|
|
|
|
// Mint some starting tokens to the player
|
|
|
|
|
_mint(msg.sender, INITIAL_GELD);
|
|
|
|
|
_mint(player, INITIAL_GELD);
|
|
|
|
|
|
|
|
|
|
// Set initial states
|
|
|
|
|
players[msg.sender] =
|
|
|
|
|
players[player] =
|
|
|
|
|
Player({total_minted: INITIAL_GELD, created_at: block.timestamp, last_raided_at: block.timestamp});
|
|
|
|
|
armies[msg.sender] = Army({
|
|
|
|
|
armies[player] = Army({
|
|
|
|
|
moloch_denier: Raider({level: 0}),
|
|
|
|
|
apprentice: Raider({level: 0}),
|
|
|
|
|
anointed: Raider({level: 0}),
|
|
|
|
|
@ -61,6 +59,36 @@ contract RaidGeld is ERC20, Ownable {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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");
|
|
|
|
|
weth.approve(address(router), amountIn);
|
|
|
|
|
ISwapRouter02.ExactInputSingleParams memory params = ISwapRouter02
|
|
|
|
|
.ExactInputSingleParams({
|
|
|
|
|
tokenIn: WETH,
|
|
|
|
|
tokenOut: DAI,
|
|
|
|
|
fee: 3000,
|
|
|
|
|
recipient: msg.sender,
|
|
|
|
|
amountIn: amountIn,
|
|
|
|
|
amountOutMinimum: amountOutMin,
|
|
|
|
|
sqrtPriceLimitX96: 0
|
|
|
|
|
});
|
|
|
|
|
router.exactInputSingle(params);
|
|
|
|
|
init_player();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|