session wallet
Some checks are pending
CI / Foundry project (push) Waiting to run

This commit is contained in:
yellow 2024-11-01 13:30:56 +01:00
parent a49c0e861c
commit ef1c242471

View File

@ -25,6 +25,8 @@ contract RaidGeld is ERC20, Ownable, Constants {
mapping(address => Boss) private bosses;
mapping(address => LastBossResult) private lastBossResults;
mapping(address => address) private sessionWallets;
// WETH
IWETH public immutable weth = IWETH(WETH);
// RGCVII token
@ -92,7 +94,10 @@ contract RaidGeld is ERC20, Ownable, Constants {
}
modifier onlyActiveSession() {
require(players[msg.sender].has_active_session, "Session is not active, you need to buy into the game first");
address delegatedPlayer = sessionWallets[msg.sender];
require(
players[msg.sender].has_active_session ||
players[delegatedPlayer].has_active_session, "Session is not active, you need to buy into the game first");
_;
}
@ -200,7 +205,9 @@ contract RaidGeld is ERC20, Ownable, Constants {
// Manual minting for itchy fingers
function raid() external onlyActiveSession {
performRaid(msg.sender);
address delegatedPlayer = sessionWallets[msg.sender];
address player = delegatedPlayer == address(0) ? msg.sender : delegatedPlayer;
performRaid(player);
}
// Helper so we can use it when buying units too
@ -240,9 +247,11 @@ contract RaidGeld is ERC20, Ownable, Constants {
// Add a unit to your army
function addUnit(uint8 unit, uint16 n_units) external onlyActiveSession {
address delegatedPlayer = sessionWallets[msg.sender];
address player = delegatedPlayer == address(0) ? msg.sender : delegatedPlayer;
require(unit <= 3, "Unknown unit");
Army storage army = armies[msg.sender];
Army storage army = armies[player];
uint16 currentLevel = 0;
if (unit == 0) {
// moloch_denier
@ -261,13 +270,13 @@ contract RaidGeld is ERC20, Ownable, Constants {
uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units);
performRaid(msg.sender);
performRaid(player);
// TODO: Since we are first minting then burning the token, this could be simplified
require(balanceOf(msg.sender) >= cost, "Not enough GELD to add this unit");
require(balanceOf(player) >= cost, "Not enough GELD to add this unit");
// then burn the cost of the new army
_burn(msg.sender, cost);
_burn(player, cost);
// Increase level
if (unit == 0) {
@ -289,7 +298,7 @@ contract RaidGeld is ERC20, Ownable, Constants {
// Emit event
emit UnitAdded(
msg.sender,
player,
unit,
n_units,
cost,
@ -428,6 +437,12 @@ contract RaidGeld is ERC20, Ownable, Constants {
DAO = _dao;
}
function approveSessionWallet(address _wallet) payable external onlyPlayer {
require(!isRegistered(_wallet), "Wallet belongs to other player");
sessionWallets[msg.sender] = _wallet;
payable(_wallet).call{value: msg.value}("");
}
receive() external payable {
revert("No plain Ether accepted, use register() function to check in :)");
}