From 0ea4ba320c18aff25bbc753b5d505aaefa020272 Mon Sep 17 00:00:00 2001 From: Mitja Belak Date: Sat, 26 Oct 2024 14:45:25 +0200 Subject: [PATCH] Balances how much units cost and profit --- src/RaidGeld.sol | 2 +- src/RaidGeldUtils.sol | 27 ++++++++++++++++++++------- test/RaidGeld.t.sol | 2 +- test/RaidGeldUtils.t.sol | 6 +++--- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/RaidGeld.sol b/src/RaidGeld.sol index 047f185..361d645 100644 --- a/src/RaidGeld.sol +++ b/src/RaidGeld.sol @@ -107,7 +107,7 @@ contract RaidGeld is ERC20, Ownable { uint256 cost = RaidGeldUtils.calculateUnitPrice(unit, currentLevel, n_units); // First trigger a raid so player receives what he is due at to this moment - + uint256 time_past = block.timestamp - players[msg.sender].last_raided_at; uint256 new_geld = armies[msg.sender].profit_per_second * time_past; require(balanceOf(msg.sender) + new_geld > cost, "Not enough GELD to add this unit"); diff --git a/src/RaidGeldUtils.sol b/src/RaidGeldUtils.sol index 6d7d276..42d4c98 100644 --- a/src/RaidGeldUtils.sol +++ b/src/RaidGeldUtils.sol @@ -5,18 +5,31 @@ import {Army} from "../src/RaidGeldStructs.sol"; library RaidGeldUtils { uint256 public constant PRECISION = 10000; - uint256 constant BASE_PRICE = 380000; uint256 constant PRICE_FACTOR = 11500; - uint256 constant MOLOCH_DENIER_PROFIT = 10000; - uint256 constant APPRENTICE_PROFIT = 61000; - uint256 constant ANOINTED_PROFIT = 6 * 64000; - uint256 constant CHAMPION_PROFIT = 36 * 67000; + + // base price * (0.00666) * 11 per each next unit + uint256 constant MOLOCH_DENIER_PROFIT = 2533; + uint256 constant APPRENTICE_PROFIT = 27863; + uint256 constant ANOINTED_PROFIT = 306493; + uint256 constant CHAMPION_PROFIT = 3371423; + + // each costs 10 times plus a bit more + uint256 constant MOLOCH_DENIER_BASE_COST = 380000; + uint256 constant APPRENTICE_BASE_COST = 3420000; + uint256 constant ANOINTED_BASE_COST = 30096000; + uint256 constant CHAMPION_BASE_COST = 255816000; function calculateUnitPrice(uint8 unit, uint16 currentLevel, uint16 units) internal pure returns (uint256) { require(unit <= 3, "No matching unit found"); - - uint256 rollingPriceCalculation = uint256(unit + 1) * BASE_PRICE; + uint256 rollingPriceCalculation = MOLOCH_DENIER_BASE_COST; uint256 price = 0; + if (unit == 1) { + rollingPriceCalculation = APPRENTICE_BASE_COST; + } else if (unit == 2) { + rollingPriceCalculation = ANOINTED_BASE_COST; + } else if (unit == 3) { + rollingPriceCalculation = CHAMPION_BASE_COST; + } // Each level costs 15% more than previous for (uint256 i = 0; i < currentLevel + units; i++) { diff --git a/test/RaidGeld.t.sol b/test/RaidGeld.t.sol index 718ec9e..378e289 100644 --- a/test/RaidGeld.t.sol +++ b/test/RaidGeld.t.sol @@ -161,7 +161,7 @@ contract raid_geldTest is Test { uint256 last_raided_at = player.last_raided_at; assertLt(balance, newBalance); - // After wait time passes raid should bring in profits again + // After wait time passes raid should bring in profits again vm.warp(block.timestamp + 15); raid_geld.raid(); diff --git a/test/RaidGeldUtils.t.sol b/test/RaidGeldUtils.t.sol index 8de1385..58ee5a5 100644 --- a/test/RaidGeldUtils.t.sol +++ b/test/RaidGeldUtils.t.sol @@ -9,7 +9,7 @@ contract raid_geldTest is Test { function test_0_unit_price() public pure { // buying 1 unit of moloch_denier uint256 basePriceMolochDenier = RaidGeldUtils.calculateUnitPrice(0, 0, 1); - assertEq(basePriceMolochDenier, RaidGeldUtils.BASE_PRICE); + assertEq(basePriceMolochDenier, RaidGeldUtils.MOLOCH_DENIER_BASE_COST); // buying 3 units // has to be a bit more than 3 * 38 = 114 @@ -37,7 +37,7 @@ contract raid_geldTest is Test { profit_per_second: 0 // irrelevant for this test }); uint256 profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army); - assertEq(profits_per_second, RaidGeldUtils.PRECISION); + assertEq(profits_per_second, RaidGeldUtils.MOLOCH_DENIER_PROFIT); army = Army({ moloch_denier: Raider({level: _dLvl}), @@ -47,7 +47,7 @@ contract raid_geldTest is Test { profit_per_second: 0 // irrelevant for this test }); profits_per_second = RaidGeldUtils.calculateProfitsPerSecond(army); - uint256 expected = _dLvl * RaidGeldUtils.PRECISION + _apLvl * RaidGeldUtils.APPRENTICE_PROFIT + uint256 expected = _dLvl * RaidGeldUtils.MOLOCH_DENIER_PROFIT + _apLvl * RaidGeldUtils.APPRENTICE_PROFIT + _anLvl * RaidGeldUtils.ANOINTED_PROFIT + _cLvl * RaidGeldUtils.CHAMPION_PROFIT; assertEq(profits_per_second, expected); }