diff --git a/client/apps/docs/utils/formatting.tsx b/client/apps/docs/utils/formatting.tsx index 5dda8b5d2e..6e56d6155a 100644 --- a/client/apps/docs/utils/formatting.tsx +++ b/client/apps/docs/utils/formatting.tsx @@ -10,11 +10,11 @@ export function formatNumberWithSpaces(number: number): string { export const formatAmount = (amount: number) => { if (amount < 1) { - return `${amount * 1000}`; - } else if (amount < 1000) { + return `${amount * EternumGlobalConfig.resources.resourcePrecision}`; + } else if (amount < EternumGlobalConfig.resources.resourcePrecision) { return `${amount.toFixed(amount % 1 === 0 ? 0 : (amount % 1) % 0.1 === 0 ? 1 : 2)}K`; } else { - return `${(amount / 1000).toFixed(amount % 1000 === 0 ? 0 : (amount % 1000) % 10 === 0 ? 1 : 2)}M`; + return `${(amount / EternumGlobalConfig.resources.resourcePrecision).toFixed(amount % EternumGlobalConfig.resources.resourcePrecision === 0 ? 0 : (amount % EternumGlobalConfig.resources.resourcePrecision) % 10 === 0 ? 1 : 2)}M`; } }; diff --git a/client/apps/game/src/hooks/helpers/battles/__test__/__mock__.tsx b/client/apps/game/src/hooks/helpers/battles/__test__/__mock__.tsx index cbc4494425..9abc4c9dd6 100644 --- a/client/apps/game/src/hooks/helpers/battles/__test__/__mock__.tsx +++ b/client/apps/game/src/hooks/helpers/battles/__test__/__mock__.tsx @@ -1,4 +1,4 @@ -import { BattleSide } from "@bibliothecadao/eternum"; +import { BattleSide, EternumGlobalConfig } from "@bibliothecadao/eternum"; import { Components, ComponentValue } from "@dojoengine/recs"; import { BattleInfo } from "../useBattles"; @@ -33,8 +33,14 @@ export const generateMockBattle = ( }, attackers_resources_escrow_id: 1n, defenders_resources_escrow_id: 1n, - attack_army_health: { current: isAttackerAlive ? 1000n : CONSIDERED_AS_DEAD_HEALTH, lifetime: 1000n }, - defence_army_health: { current: isDefenderAlive ? 1000n : CONSIDERED_AS_DEAD_HEALTH, lifetime: 1000n }, + attack_army_health: { + current: isAttackerAlive ? EternumGlobalConfig.resources.resourcePrecision : CONSIDERED_AS_DEAD_HEALTH, + lifetime: EternumGlobalConfig.resources.resourcePrecision + }, + defence_army_health: { + current: isDefenderAlive ? EternumGlobalConfig.resources.resourcePrecision : CONSIDERED_AS_DEAD_HEALTH, + lifetime: EternumGlobalConfig.resources.resourcePrecision + }, attack_delta: 1n, defence_delta: 1n, last_updated: 1n, diff --git a/client/apps/game/src/ui/components/resources/realm-transfer.tsx b/client/apps/game/src/ui/components/resources/realm-transfer.tsx index 72b781feab..31bd232538 100644 --- a/client/apps/game/src/ui/components/resources/realm-transfer.tsx +++ b/client/apps/game/src/ui/components/resources/realm-transfer.tsx @@ -6,7 +6,7 @@ import Button from "@/ui/elements/Button"; import { NumberInput } from "@/ui/elements/NumberInput"; import { ResourceIcon } from "@/ui/elements/ResourceIcon"; import { calculateDonkeysNeeded, currencyFormat, getTotalResourceWeight, multiplyByPrecision } from "@/ui/utils/utils"; -import { ResourcesIds, findResourceById } from "@bibliothecadao/eternum"; +import { EternumGlobalConfig, ResourcesIds, findResourceById } from "@bibliothecadao/eternum"; import { Dispatch, SetStateAction, memo, useCallback, useEffect, useMemo, useState } from "react"; import { ID } from "@bibliothecadao/eternum"; @@ -64,7 +64,7 @@ export const RealmTransfer = memo( const cleanedCalls = calls.map(({ sender_entity_id, recipient_entity_id, resources }) => ({ sender_entity_id, recipient_entity_id, - resources: [resources[0], BigInt(Number(resources[1]) * 1000)], + resources: [resources[0], BigInt(Number(resources[1]) * EternumGlobalConfig.resources.resourcePrecision)], })); try { diff --git a/client/apps/game/src/ui/components/structures/construction/StructureConstructionMenu.tsx b/client/apps/game/src/ui/components/structures/construction/StructureConstructionMenu.tsx index 15d96ca8da..f888d5f859 100644 --- a/client/apps/game/src/ui/components/structures/construction/StructureConstructionMenu.tsx +++ b/client/apps/game/src/ui/components/structures/construction/StructureConstructionMenu.tsx @@ -5,6 +5,7 @@ import { Headline } from "@/ui/elements/Headline"; import { ResourceCost } from "@/ui/elements/ResourceCost"; import { multiplyByPrecision } from "@/ui/utils/utils"; import { + EternumGlobalConfig, HYPERSTRUCTURE_CONSTRUCTION_COSTS_SCALED, HYPERSTRUCTURE_CREATION_COSTS, ID, @@ -123,7 +124,7 @@ const StructureInfo = ({ key={index} type="horizontal" resourceId={ResourcesIds.AncientFragment} - amount={cost[Number(resourceId)].min_amount * 1000} + amount={cost[Number(resourceId)].min_amount * EternumGlobalConfig.resources.resourcePrecision} balance={balance.balance} /> ); diff --git a/client/apps/game/src/ui/components/trading/MarketOrderPanel.tsx b/client/apps/game/src/ui/components/trading/MarketOrderPanel.tsx index 749af7cc38..aefb0c7362 100644 --- a/client/apps/game/src/ui/components/trading/MarketOrderPanel.tsx +++ b/client/apps/game/src/ui/components/trading/MarketOrderPanel.tsx @@ -20,6 +20,7 @@ import { } from "@/ui/utils/utils"; import { DONKEY_ENTITY_TYPE, + EternumGlobalConfig, ONE_MONTH, ResourcesIds, findResourceById, @@ -497,7 +498,7 @@ const OrderRow = memo( const OrderCreation = memo( ({ entityId, resourceId, isBuy = false }: { entityId: ID; resourceId: ResourcesIds; isBuy?: boolean }) => { const [loading, setLoading] = useState(false); - const [resource, setResource] = useState(1000); + const [resource, setResource] = useState(EternumGlobalConfig.resources.resourcePrecision); const [lords, setLords] = useState(100); const [bid, setBid] = useState(String(lords / resource)); const { nextBlockTimestamp } = useNextBlockTimestamp(); diff --git a/client/sdk/packages/eternum/src/constants/global.ts b/client/sdk/packages/eternum/src/constants/global.ts index 3a57dd38cb..f9f6b05e5f 100644 --- a/client/sdk/packages/eternum/src/constants/global.ts +++ b/client/sdk/packages/eternum/src/constants/global.ts @@ -46,8 +46,8 @@ export const STAMINA_TRAVEL_COST = 10; export const STAMINA_EXPLORE_COST = 20; // ----- Resources ----- // -export const RESOURCE_PRECISION = 1000; -export const RESOURCE_MULTIPLIER = 1000; +export const RESOURCE_PRECISION = 1_000_000_000; +export const RESOURCE_MULTIPLIER = 1_000_000_000; export const RESOURCE_AMOUNT_PER_TICK = 10; export const STARTING_RESOURCES_INPUT_PRODUCTION_FACTOR = 6; diff --git a/contracts/src/constants.cairo b/contracts/src/constants.cairo index 9de0589bd5..65c2040849 100644 --- a/contracts/src/constants.cairo +++ b/contracts/src/constants.cairo @@ -27,7 +27,7 @@ const GRAMS_PER_KG: u128 = 1_000; const MAX_REALMS_PER_ADDRESS: u16 = 8_000; // resource precision -const RESOURCE_PRECISION: u128 = 1_000; +const RESOURCE_PRECISION: u128 = 1_000_000_000; // WONDER QUEST REWARD BOOST diff --git a/contracts/src/models/combat.cairo b/contracts/src/models/combat.cairo index 6c9cecef24..3b8ab7620b 100644 --- a/contracts/src/models/combat.cairo +++ b/contracts/src/models/combat.cairo @@ -89,10 +89,10 @@ impl HealthImpl of HealthTrait { /// Ensure that if the deduction makes the health less than one troop, /// the troop dies immediately - /// e.g if single troop health = 7 * 1000(normalization), then a troop with 3 soldiers will have - /// health a total health of 7_000 * 3 = 21_000. + /// e.g if single troop health = 7 * RESOURCE_PRECISION(normalization), then a troop with 3 soldiers will have + /// health a total health of 7 * 1_000_000_000 (RP) * 3 = 21_000_000_000 /// if deduction is 80 per second, we want it such that deduction happens - /// at the rate of 80 per second till it takes 7_000 * (3 -1) =14_000 health, + /// at the rate of 80 per second till it takes 7_000_000_000 * (3 -1) =14_000_000_000 health, /// then after that, the next step depletes the health completely. i.e to 0 // note: at this point, we know that diff --git a/contracts/src/systems/bank/contracts/liquidity.cairo b/contracts/src/systems/bank/contracts/liquidity.cairo index 7633b7287d..81b7aab897 100644 --- a/contracts/src/systems/bank/contracts/liquidity.cairo +++ b/contracts/src/systems/bank/contracts/liquidity.cairo @@ -21,7 +21,7 @@ mod liquidity_systems { use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; // Eternum imports use s0_eternum::alias::ID; - use s0_eternum::constants::DEFAULT_NS; + use s0_eternum::constants::{RESOURCE_PRECISION,DEFAULT_NS}; use s0_eternum::constants::ResourceTypes; use s0_eternum::models::bank::liquidity::{Liquidity}; use s0_eternum::models::bank::market::{Market, MarketTrait}; @@ -40,7 +40,7 @@ mod liquidity_systems { resource_type: u8, lords_amount: u128, resource_amount: u128, - // price in lords for 1000 resource + // price in lords for 1 * RESOURCE_PRECISION resource resource_price: u128, add: bool, timestamp: u64, @@ -146,7 +146,7 @@ mod liquidity_systems { ref world: WorldStorage, market: Market, entity_id: ID, lords_amount: u128, resource_amount: u128, add: bool ) { let resource_price = if market.has_liquidity() { - market.quote_amount(1000) + market.quote_amount(1 * RESOURCE_PRECISION) } else { 0 }; diff --git a/contracts/src/systems/bank/contracts/swap.cairo b/contracts/src/systems/bank/contracts/swap.cairo index d458d344d9..eece078ae1 100644 --- a/contracts/src/systems/bank/contracts/swap.cairo +++ b/contracts/src/systems/bank/contracts/swap.cairo @@ -20,7 +20,7 @@ mod swap_systems { use option::OptionTrait; use s0_eternum::alias::ID; - use s0_eternum::constants::DEFAULT_NS; + use s0_eternum::constants::{RESOURCE_PRECISION, DEFAULT_NS}; use s0_eternum::constants::{ResourceTypes, WORLD_CONFIG_ID}; use s0_eternum::models::bank::bank::{Bank}; use s0_eternum::models::bank::market::{Market, MarketTrait}; @@ -46,7 +46,7 @@ mod swap_systems { resource_amount: u128, bank_owner_fees: u128, lp_fees: u128, - // price in lords for 1000 resource + // price in lords for 1 * RESOURCE_PRECISION resource resource_price: u128, buy: bool, timestamp: u64, @@ -98,7 +98,7 @@ mod swap_systems { amount, bank_lords_fee_amount, lps_fee, - market.buy(0, 1, 1000), + market.buy(0, 1, RESOURCE_PRECISION), true ); @@ -152,7 +152,7 @@ mod swap_systems { amount, bank_lords_fee_amount, lps_fee, - market.buy(0, 1, 1000), + market.buy(0, 1, RESOURCE_PRECISION), false ); @@ -185,7 +185,7 @@ mod swap_systems { resource_amount, bank_owner_fees, lp_fees, - resource_price: market.quote_amount(1000), + resource_price: market.quote_amount(RESOURCE_PRECISION), buy, timestamp: starknet::get_block_timestamp() } diff --git a/contracts/src/systems/transport/tests/travel_systems_tests.cairo b/contracts/src/systems/transport/tests/travel_systems_tests.cairo index 79487b6e59..9867b78ff4 100644 --- a/contracts/src/systems/transport/tests/travel_systems_tests.cairo +++ b/contracts/src/systems/transport/tests/travel_systems_tests.cairo @@ -9,7 +9,7 @@ use s0_eternum::alias::ID; use s0_eternum::constants::LevelIndex; use s0_eternum::constants::{REALM_LEVELING_CONFIG_ID, WORLD_CONFIG_ID}; -use s0_eternum::constants::{ResourceTypes, TickIds}; +use s0_eternum::constants::{ResourceTypes, TickIds, RESOURCE_PRECISION}; use s0_eternum::models::combat::{Army, BattleSide, Troops}; use s0_eternum::models::config::{TickConfig, MapConfig, StaminaConfig, StaminaRefillConfig, LevelingConfig, TickImpl}; use s0_eternum::models::map::Tile; @@ -191,8 +191,8 @@ use starknet::contract_address_const; const TICK_INTERVAL_IN_SECONDS: u64 = 200; const MAX_STAMINA: u16 = 30; -const ORIGINAL_WHEAT_BALANCE: u128 = 1000; -const ORIGINAL_FISH_BALANCE: u128 = 1000; +const ORIGINAL_WHEAT_BALANCE: u128 = 1 * RESOURCE_PRECISION; +const ORIGINAL_FISH_BALANCE: u128 = 1 * RESOURCE_PRECISION; fn setup_hex_travel() -> (WorldStorage, ID, Position, ITravelSystemsDispatcher) { let mut world = spawn_eternum(); diff --git a/contracts/src/utils/testing/config.cairo b/contracts/src/utils/testing/config.cairo index 0ba22d3058..88edf09d70 100644 --- a/contracts/src/utils/testing/config.cairo +++ b/contracts/src/utils/testing/config.cairo @@ -108,7 +108,7 @@ fn get_combat_config() -> TroopConfig { crossbowman_strength: 1, advantage_percent: 1000, disadvantage_percent: 1000, - max_troop_count: 10_000_000_000_000 * 1000, + max_troop_count: 10_000_000_000_000 * RESOURCE_PRECISION, pillage_health_divisor: 8, army_free_per_structure: 100, army_extra_per_building: 100, diff --git a/discord-bot/src/events/battle_pillage.rs b/discord-bot/src/events/battle_pillage.rs index 3ab03ae1ac..cb71308c8e 100644 --- a/discord-bot/src/events/battle_pillage.rs +++ b/discord-bot/src/events/battle_pillage.rs @@ -14,6 +14,7 @@ use crate::{ use super::{ToDiscordMessage, UNKNOWN_USER}; +const RESOURCE_PRECISION : u128 = 1_000_000_000; #[derive(CairoSerde, Clone)] pub struct BattlePillage { pub id: u32, @@ -42,7 +43,7 @@ impl ToDiscordMessage for BattlePillage { .pillaged_resources .iter() .map(|(resource_id, amount)| { - format!("{} {}", amount / 1000, ResourceIds::from(*resource_id),) + format!("{} {}", amount / RESOURCE_PRECISION, ResourceIds::from(*resource_id),) }) .collect::>() .join(", ");