From 468e95626acf065f97f7aefc5c21865663ec7577 Mon Sep 17 00:00:00 2001 From: Credence Date: Sat, 27 Jul 2024 01:12:29 +0100 Subject: [PATCH 1/3] update to cairo 2.7.0 --- .github/workflows/test-contracts.yml | 2 +- .tool-versions | 2 +- contracts/Scarb.lock | 4 +- contracts/Scarb.toml | 4 +- contracts/src/constants.cairo | 4 +- contracts/src/lib.cairo | 8 +- contracts/src/models/bank/bank.cairo | 2 +- contracts/src/models/bank/liquidity.cairo | 14 +-- contracts/src/models/bank/market.cairo | 12 +- contracts/src/models/buildings.cairo | 6 +- contracts/src/models/capacity.cairo | 2 +- contracts/src/models/combat.cairo | 28 ++--- contracts/src/models/config.cairo | 50 ++++---- contracts/src/models/guild.cairo | 6 +- contracts/src/models/hyperstructure.cairo | 4 +- contracts/src/models/level.cairo | 4 +- contracts/src/models/map.cairo | 2 +- contracts/src/models/metadata.cairo | 6 +- contracts/src/models/movable.cairo | 4 +- contracts/src/models/name.cairo | 4 +- contracts/src/models/order.cairo | 2 +- contracts/src/models/owner.cairo | 4 +- contracts/src/models/population.cairo | 2 +- contracts/src/models/position.cairo | 12 +- contracts/src/models/production.cairo | 14 +-- contracts/src/models/quantity.cairo | 6 +- contracts/src/models/realm.cairo | 2 +- contracts/src/models/resources.cairo | 26 ++-- contracts/src/models/road.cairo | 2 +- contracts/src/models/stamina.cairo | 2 +- contracts/src/models/structure.cairo | 4 +- contracts/src/models/trade.cairo | 4 +- contracts/src/models/weight.cairo | 2 +- contracts/src/systems.cairo | 56 ++++----- .../src/systems/bank/contracts/bank.cairo | 2 +- .../systems/bank/contracts/liquidity.cairo | 2 +- .../src/systems/bank/contracts/swap.cairo | 2 +- contracts/src/systems/bank/tests/swap.cairo | 2 +- contracts/src/systems/combat/contracts.cairo | 113 +++++++++--------- .../combat/tests/battle_leave_test.cairo | 2 +- .../systems/hyperstructure/contracts.cairo | 2 +- .../src/systems/leveling/contracts.cairo | 2 +- .../tests/internal_leveling_tests.cairo | 20 ++-- .../leveling/tests/realm_leveling_tests.cairo | 6 +- contracts/src/systems/map/contracts.cairo | 4 +- contracts/src/systems/map/tests.cairo | 2 +- .../src/systems/resources/contracts.cairo | 20 ++-- .../resource_transfer_system_tests.cairo | 12 +- .../trade/contracts/trade_systems.cairo | 4 +- .../trade_systems_tests/accept_order.cairo | 12 +- .../trade_systems_tests/cancel_order.cairo | 10 +- .../transport/contracts/donkey_systems.cairo | 2 +- .../transport/contracts/road_systems.cairo | 4 +- .../transport/contracts/travel_systems.cairo | 12 +- .../tests/travel_systems_tests.cairo | 8 +- contracts/src/utils.cairo | 14 +-- contracts/src/utils/map.cairo | 4 +- contracts/src/utils/map/biomes.cairo | 2 +- contracts/src/utils/map/constants.cairo | 40 +++---- contracts/src/utils/math.cairo | 20 ++-- contracts/src/utils/number.cairo | 4 +- contracts/src/utils/random.cairo | 10 +- contracts/src/utils/testing/config.cairo | 11 +- contracts/src/utils/testing/world.cairo | 2 +- scripts/deploy.sh | 4 +- 65 files changed, 326 insertions(+), 334 deletions(-) diff --git a/.github/workflows/test-contracts.yml b/.github/workflows/test-contracts.yml index 7f5c577c8..a84ef4dce 100644 --- a/.github/workflows/test-contracts.yml +++ b/.github/workflows/test-contracts.yml @@ -35,7 +35,7 @@ jobs: steps: - name: Download Dojo release artifact run: | - curl -L -o dojo-linux-x86_64.tar.gz https://github.com/dojoengine/dojo/releases/download/v1.0.0-alpha.1/dojo_v1.0.0-alpha.1_linux_amd64.tar.gz + curl -L -o dojo-linux-x86_64.tar.gz https://github.com/dojoengine/dojo/releases/download/v1.0.0-alpha.3/dojo_v1.0.0-alpha.3_linux_amd64.tar.gz tar -xzf dojo-linux-x86_64.tar.gz sudo mv sozo /usr/local/bin/ - name: Checkout repository diff --git a/.tool-versions b/.tool-versions index 8f7adfd7b..c0021b247 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.6.5 \ No newline at end of file +scarb 2.7.0-rc.4 \ No newline at end of file diff --git a/contracts/Scarb.lock b/contracts/Scarb.lock index 211d0e41b..92b84aa16 100644 --- a/contracts/Scarb.lock +++ b/contracts/Scarb.lock @@ -42,7 +42,7 @@ source = "git+https://github.com/dojoengine/cubit?branch=cairo_2.7#53020b6320a10 [[package]] name = "dojo" version = "0.7.3" -source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-alpha.2#8a1a652d9ea06f141645316f22e3916a148403ec" +source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-alpha.3#a6a7724380169372336e886fb36f31f56e7d0d8a" dependencies = [ "dojo_plugin", ] @@ -50,7 +50,7 @@ dependencies = [ [[package]] name = "dojo_plugin" version = "0.7.3" -source = "git+https://github.com/dojoengine/dojo?rev=d90b52b#d90b52b89749ac8af82f352dc08aa0b1378cfae6" +source = "git+https://github.com/dojoengine/dojo?rev=71b1f1a4#71b1f1a467534cbeeb901356f41e612ed4187bd1" [[package]] name = "eternum" diff --git a/contracts/Scarb.toml b/contracts/Scarb.toml index 007ead9f3..7fca226dd 100755 --- a/contracts/Scarb.toml +++ b/contracts/Scarb.toml @@ -6,7 +6,7 @@ version = "0.6.8" sierra-replace-ids = true [dependencies] -dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.2" } +dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.3" } alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "cairo-v2.5.4" } alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "cairo-v2.5.4" } cubit = { git = "https://github.com/dojoengine/cubit", branch = "cairo_2.7" } @@ -29,8 +29,6 @@ world_address = "0x161b08e252b353008665e85ab5dcb0044a61186eb14b999657d14c04c94c8 [[target.dojo]] -[lib] - [tool.dojo.world] seed = "eternum" name = "Realms: Eternum" diff --git a/contracts/src/constants.cairo b/contracts/src/constants.cairo index c494379ef..97deb800c 100644 --- a/contracts/src/constants.cairo +++ b/contracts/src/constants.cairo @@ -131,7 +131,7 @@ mod ResourceTypes { const LORDS: u8 = 253; const WHEAT: u8 = 254; const FISH: u8 = 255; -// note: update _resource_type_to_position + // note: update _resource_type_to_position // function is any new resources are added } @@ -241,7 +241,7 @@ fn get_resources_without_earthenshards() -> Span { } fn get_resources_without_earthenshards_probs() -> Span { - // 35 + // 35 return array![1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].span(); } diff --git a/contracts/src/lib.cairo b/contracts/src/lib.cairo index fa00c4ed8..42f2a634c 100644 --- a/contracts/src/lib.cairo +++ b/contracts/src/lib.cairo @@ -1,6 +1,6 @@ -mod alias; -mod constants; -mod models; +pub mod alias; +pub mod constants; +pub mod models; mod systems; -mod utils; +pub mod utils; diff --git a/contracts/src/models/bank/bank.cairo b/contracts/src/models/bank/bank.cairo index 062cad6b4..ff9e3bd11 100644 --- a/contracts/src/models/bank/bank.cairo +++ b/contracts/src/models/bank/bank.cairo @@ -4,7 +4,7 @@ use starknet::ContractAddress; // Used as helper struct throughout the world #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Bank { +pub struct Bank { #[key] entity_id: u128, owner_fee_num: u128, diff --git a/contracts/src/models/bank/liquidity.cairo b/contracts/src/models/bank/liquidity.cairo index 18bc4bd19..945118167 100644 --- a/contracts/src/models/bank/liquidity.cairo +++ b/contracts/src/models/bank/liquidity.cairo @@ -1,11 +1,5 @@ -// External imports - use cubit::f128::types::fixed::{Fixed, FixedTrait}; - -// Dojo imports - -use dojo::database::introspect::{Struct, Ty, Introspect, Member}; -// Starknet imports +use dojo::model::introspect::{Struct, Ty, Introspect, Member}; use starknet::ContractAddress; @@ -16,8 +10,8 @@ impl IntrospectFixed of Introspect { } #[inline(always)] - fn layout() -> dojo::database::introspect::Layout { - dojo::database::introspect::Layout::Fixed(array![128, 1].span()) + fn layout() -> dojo::model::Layout { + dojo::model::Layout::Fixed(array![128, 1].span()) } #[inline(always)] @@ -38,7 +32,7 @@ impl IntrospectFixed of Introspect { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Liquidity { +pub struct Liquidity { #[key] bank_entity_id: u128, #[key] diff --git a/contracts/src/models/bank/market.cairo b/contracts/src/models/bank/market.cairo index 0911a5cc9..c32a5198f 100644 --- a/contracts/src/models/bank/market.cairo +++ b/contracts/src/models/bank/market.cairo @@ -2,7 +2,7 @@ use cubit::f128::types::fixed::{Fixed, FixedTrait}; // Dojo imports -use dojo::database::introspect::{Struct, Ty, Introspect, Member}; +use dojo::model::introspect::{Struct, Ty, Introspect, Member}; // Starknet imports use starknet::ContractAddress; @@ -14,8 +14,8 @@ impl IntrospectFixed of Introspect { } #[inline(always)] - fn layout() -> dojo::database::introspect::Layout { - dojo::database::introspect::Layout::Fixed(array![128, 1].span()) + fn layout() -> dojo::model::Layout { + dojo::model::Layout::Fixed(array![128, 1].span()) } #[inline(always)] @@ -36,7 +36,7 @@ impl IntrospectFixed of Introspect { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Market { +pub struct Market { #[key] bank_entity_id: u128, #[key] @@ -68,7 +68,7 @@ impl MarketCustomImpl of MarketCustomTrait { numerator / denominator } - // Here the user gets the requested output but pays more in price to + // Here the user gets the requested output but pays more in price to // account for lp fees. i.e fees are paid in input token fn get_output_price( fee_rate_num: u128, fee_rate_denom: u128, output_amount: u128, input_reserve: u128, output_reserve: u128 @@ -467,7 +467,7 @@ mod tests { let (amount, quantity) = (2, 20); // pool 1:10 let (amount_add, quantity_add, liquidity_add, _) = market.add_liquidity(amount, quantity); - // Assert + // Assert assert(amount_add == amount, 'wrong cash amount'); assert(quantity_add == quantity, 'wrong item quantity'); diff --git a/contracts/src/models/buildings.cairo b/contracts/src/models/buildings.cairo index 55b245511..9dcc660bd 100644 --- a/contracts/src/models/buildings.cairo +++ b/contracts/src/models/buildings.cairo @@ -19,7 +19,7 @@ use eternum::models::resources::{Resource, ResourceCustomImpl, ResourceCost}; #[derive(PartialEq, Copy, Drop, Serde)] #[dojo::model] -struct Building { +pub struct Building { #[key] outer_col: u128, #[key] @@ -37,7 +37,7 @@ struct Building { #[derive(PartialEq, Copy, Drop, Serde)] #[dojo::model] -struct BuildingQuantityv2 { +pub struct BuildingQuantityv2 { #[key] entity_id: u128, #[key] @@ -429,7 +429,7 @@ impl BuildingCustomImpl of BuildingCustomTrait { assert!(!building.is_active(), "space is occupied"); - // set building + // set building building.entity_id = world.uuid().into(); building.category = category; building.outer_entity_id = outer_entity_id; diff --git a/contracts/src/models/capacity.cairo b/contracts/src/models/capacity.cairo index fef554e10..ea29ae916 100644 --- a/contracts/src/models/capacity.cairo +++ b/contracts/src/models/capacity.cairo @@ -4,7 +4,7 @@ use eternum::models::weight::{Weight}; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Capacity { +pub struct Capacity { #[key] entity_id: u128, weight_gram: u128, diff --git a/contracts/src/models/combat.cairo b/contracts/src/models/combat.cairo index 6bb6f8b2f..4205a287e 100644 --- a/contracts/src/models/combat.cairo +++ b/contracts/src/models/combat.cairo @@ -30,7 +30,7 @@ const STRENGTH_PRECISION: u256 = 10_000; #[derive(Copy, Drop, Serde, Default)] #[dojo::model] -struct Health { +pub struct Health { #[key] entity_id: u128, current: u128, @@ -76,8 +76,8 @@ impl HealthCustomImpl of HealthCustomTrait { } // this condition is here in case - // self.current < deduction which would make - // num_steps = 0 but that would cause the + // self.current < deduction which would make + // num_steps = 0 but that would cause the // "inaccurate winner invariant" error so we make it // at least 1. max(num_steps, 1) @@ -292,7 +292,7 @@ impl ArmyQuantityTracker of ArmyQuantityTrackerTrait { #[derive(Copy, Drop, Serde, Default)] #[dojo::model] -struct Army { +pub struct Army { #[key] entity_id: u128, troops: Troops, @@ -387,7 +387,7 @@ impl ArmyCustomImpl of ArmyCustomTrait { #[derive(Copy, Drop, Serde, Default)] #[dojo::model] -struct Protector { +pub struct Protector { #[key] entity_id: u128, army_id: u128, @@ -402,7 +402,7 @@ impl ProtectorCustomImpl of ProtectorCustomTrait { #[derive(Copy, Drop, Serde, Default)] #[dojo::model] -struct Protectee { +pub struct Protectee { #[key] army_id: u128, protectee_id: u128 @@ -430,7 +430,7 @@ impl ProtecteeCustomImpl of ProtecteeCustomTrait { #[derive(Copy, Drop, Serde, Default)] #[dojo::model] -struct Battle { +pub struct Battle { #[key] entity_id: u128, attack_army: BattleArmy, @@ -529,7 +529,7 @@ impl BattleEscrowImpl of BattleEscrowTrait { let winner_side: BattleSide = self.winner(); let to_army_dead = to_army.troops.count().is_zero(); - // the reason for checking if `to_army_dead` is `true` is that + // the reason for checking if `to_army_dead` is `true` is that // it's possible for the battle be a draw and both sides die in the process. // if this edge case occurs, we assume they both lost for the purpose of this // function. They both forfeit their balances. @@ -1209,7 +1209,7 @@ mod tests { let attack_army_stone: Resource = get!(world, (attack_army.entity_id, ResourceTypes::STONE), Resource); assert_eq!(attack_army_stone.balance, defence_army_stone_resource.balance); } -// #[test] + // #[test] // fn test_show_battle() { // let attack_troop_each = 240_000; // let defence_troop_each = 10_000; @@ -1221,10 +1221,10 @@ mod tests { // print!("\n\n Attack Army health: {} \n\n", battle.attack_army_health.current); // print!("\n\n Defence delta: {} \n\n", battle.defence_delta); -// print!("\n\n Defence Army health: {} \n\n", battle.defence_army_health.current); + // print!("\n\n Defence Army health: {} \n\n", battle.defence_army_health.current); // print!("\n\n Attack delta: {} \n\n", battle.attack_delta); -// print!("\n\n Scale A: {} \n\n",battle.attack_army.troops.count() / + // print!("\n\n Scale A: {} \n\n",battle.attack_army.troops.count() / // battle.defence_army.troops.count()); // print!("\n\n Scale B: {} \n\n", battle.defence_army.troops.count() // /battle.attack_army.troops.count()); @@ -1232,7 +1232,7 @@ mod tests { // print!("\n\n Duration in Minutes: {} \n\n", battle.duration_left / 60); // print!("\n\n Duration in Hours: {} \n\n", battle.duration_left / (60 * 60)); -// let divisior = 8; + // let divisior = 8; // let attacker_h_left = battle.attack_army_health.current - (battle.defence_delta.into() * // (battle.duration_left.into() / divisior )); // let attacker_ratio = (battle.attack_army_health.current - attacker_h_left) * 100 / @@ -1242,8 +1242,8 @@ mod tests { // let defence_ratio = (battle.defence_army_health.current - defence_h_left) * 100 / // battle.defence_army_health.current; -// print!("\n\n Pillage Attacker Loss: {}, Ratio is {}% \n\n", attacker_h_left, attacker_ratio); + // print!("\n\n Pillage Attacker Loss: {}, Ratio is {}% \n\n", attacker_h_left, attacker_ratio); // print!("\n\n Pillage Defender Loss: {}, Ratio is {}% \n\n", defence_h_left, defence_ratio); -// } + // } } diff --git a/contracts/src/models/config.cairo b/contracts/src/models/config.cairo index dd91de385..d05f443ee 100644 --- a/contracts/src/models/config.cairo +++ b/contracts/src/models/config.cairo @@ -14,7 +14,7 @@ use starknet::ContractAddress; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct WorldConfig { +pub struct WorldConfig { #[key] config_id: u128, admin_address: ContractAddress, @@ -23,7 +23,7 @@ struct WorldConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct RealmFreeMintConfig { +pub struct RealmFreeMintConfig { #[key] config_id: u128, detached_resource_id: u128, @@ -33,7 +33,7 @@ struct RealmFreeMintConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct RoadConfig { +pub struct RoadConfig { #[key] config_id: u128, resource_cost_id: u128, @@ -43,7 +43,7 @@ struct RoadConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct HyperstructureResourceConfig { +pub struct HyperstructureResourceConfig { #[key] config_id: u128, #[key] @@ -54,11 +54,11 @@ struct HyperstructureResourceConfig { // capacity // TODO: should rename into something that shows // that it's a config for one specific entity type? -// and not the same as world config +// and not the same as world config // e.g. EntityTypeCapacityConfig? #[derive(Copy, Drop, Serde)] #[dojo::model] -struct CapacityConfig { +pub struct CapacityConfig { #[key] config_id: u128, #[key] @@ -77,7 +77,7 @@ impl CapacityConfigCustomImpl of CapacityConfigCustomTrait { // speed #[derive(Copy, Drop, Serde)] #[dojo::model] -struct SpeedConfig { +pub struct SpeedConfig { #[key] config_id: u128, #[key] @@ -89,7 +89,7 @@ struct SpeedConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct MapExploreConfig { +pub struct MapExploreConfig { #[key] config_id: u128, wheat_burn_amount: u128, @@ -101,7 +101,7 @@ struct MapExploreConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct TickConfig { +pub struct TickConfig { #[key] config_id: u128, #[key] @@ -111,7 +111,7 @@ struct TickConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct StaminaConfig { +pub struct StaminaConfig { #[key] config_id: u128, #[key] @@ -121,7 +121,7 @@ struct StaminaConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct MercenariesConfig { +pub struct MercenariesConfig { #[key] config_id: u128, troops: Troops, @@ -170,7 +170,7 @@ impl TickImpl of TickTrait { // weight #[derive(Copy, Drop, Serde)] #[dojo::model] -struct WeightConfig { +pub struct WeightConfig { #[key] config_id: u128, #[key] @@ -190,7 +190,7 @@ impl WeightConfigCustomImpl of WeightConfigCustomTrait { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct LevelingConfig { +pub struct LevelingConfig { #[key] config_id: u128, decay_interval: u64, @@ -213,7 +213,7 @@ struct LevelingConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct ProductionConfig { +pub struct ProductionConfig { #[key] resource_type: u8, // production amount per tick @@ -227,7 +227,7 @@ struct ProductionConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct BankConfig { +pub struct BankConfig { #[key] config_id: u128, lords_cost: u128, @@ -237,7 +237,7 @@ struct BankConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct BuildingConfig { +pub struct BuildingConfig { #[key] config_id: u128, #[key] @@ -265,7 +265,7 @@ impl BuildingConfigCustomImpl of BuildingConfigCustomTrait { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct TroopConfig { +pub struct TroopConfig { #[key] config_id: u128, health: u32, @@ -277,15 +277,15 @@ struct TroopConfig { // By setting the divisor to 8, the max health that can be taken from the weaker army // during pillage is 100 / 8 = 12.5% . Adjust this value to change that. // - // The closer the armies are in strength and health, the closer they both - // get to losing 12.5% each. If an army is far stronger than the order, + // The closer the armies are in strength and health, the closer they both + // get to losing 12.5% each. If an army is far stronger than the order, // they lose a small precentage (it goes closer to 0% health loss) while the - // weak army's loss is closer to 12.5% + // weak army's loss is closer to 12.5% pillage_health_divisor: u8, // the number of armies that can be created per structure // before military buildings are required to create more army_free_per_structure: u8, - // the number of additional armies that can be create with + // the number of additional armies that can be create with // each new military building army_extra_per_building: u8, } @@ -301,7 +301,7 @@ impl TroopConfigCustomImpl of TroopConfigCustomTrait { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct BattleConfig { +pub struct BattleConfig { #[key] entity_id: u128, max_tick_duration: u64, @@ -317,7 +317,7 @@ impl BattleConfigCustomImpl of BattleConfigCustomTrait { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct BuildingCategoryPopConfig { +pub struct BuildingCategoryPopConfig { #[key] config_id: u128, #[key] @@ -328,7 +328,7 @@ struct BuildingCategoryPopConfig { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct PopulationConfig { +pub struct PopulationConfig { #[key] config_id: u128, base_population: u32, @@ -350,7 +350,7 @@ impl HyperstructureConfigCustomImpl of HyperstructureConfigCustomTrait { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct HasClaimedStartingResources { +pub struct HasClaimedStartingResources { #[key] entity_id: u128, #[key] diff --git a/contracts/src/models/guild.cairo b/contracts/src/models/guild.cairo index 6e7c50187..ed75376f3 100644 --- a/contracts/src/models/guild.cairo +++ b/contracts/src/models/guild.cairo @@ -2,7 +2,7 @@ use starknet::ContractAddress; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Guild { +pub struct Guild { #[key] entity_id: u128, is_public: bool, @@ -11,7 +11,7 @@ struct Guild { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct GuildMember { +pub struct GuildMember { #[key] address: ContractAddress, guild_entity_id: u128 @@ -19,7 +19,7 @@ struct GuildMember { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct GuildWhitelist { +pub struct GuildWhitelist { #[key] address: ContractAddress, #[key] diff --git a/contracts/src/models/hyperstructure.cairo b/contracts/src/models/hyperstructure.cairo index 128c9be75..57bb6d7d1 100644 --- a/contracts/src/models/hyperstructure.cairo +++ b/contracts/src/models/hyperstructure.cairo @@ -2,7 +2,7 @@ use starknet::ContractAddress; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Progress { +pub struct Progress { #[key] hyperstructure_entity_id: u128, #[key] @@ -12,7 +12,7 @@ struct Progress { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Contribution { +pub struct Contribution { #[key] hyperstructure_entity_id: u128, #[key] diff --git a/contracts/src/models/level.cairo b/contracts/src/models/level.cairo index b129df87e..42c2cd70b 100644 --- a/contracts/src/models/level.cairo +++ b/contracts/src/models/level.cairo @@ -7,7 +7,7 @@ use eternum::models::resources::{ResourceCost}; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Level { +pub struct Level { #[key] entity_id: u128, level: u64, @@ -163,7 +163,7 @@ mod tests { cost_percentage_scaled: 4611686018427387904 }; - // set level + // set level // tier 1 let level = Level { entity_id: 1, level: 1, valid_until: 1000 }; let multiplier = level.get_index_multiplier(leveling_config, LevelIndex::FOOD, REALM_LEVELING_START_TIER); diff --git a/contracts/src/models/map.cairo b/contracts/src/models/map.cairo index 7ffc51679..8212650ed 100644 --- a/contracts/src/models/map.cairo +++ b/contracts/src/models/map.cairo @@ -3,7 +3,7 @@ use eternum::utils::map::biomes::Biome; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Tile { +pub struct Tile { #[key] _col: u128, #[key] diff --git a/contracts/src/models/metadata.cairo b/contracts/src/models/metadata.cairo index 4187afd2c..b9cfc507e 100644 --- a/contracts/src/models/metadata.cairo +++ b/contracts/src/models/metadata.cairo @@ -4,7 +4,7 @@ use eternum::alias::ID; // to the list of components which we already have #[derive(Copy, Drop, Serde)] #[dojo::model] -struct EntityMetadata { +pub struct EntityMetadata { #[key] entity_id: u128, entity_type: u128, @@ -15,10 +15,10 @@ struct EntityMetadata { // e.g. in a caravan, you want to store the list of entities in the caravan // using an index and the foreign key // see CreateCaravan for an example -// TODO: change ForeignKey to CaravanMember and stop using general purpose components +// TODO: change ForeignKey to CaravanMember and stop using general purpose components #[derive(Copy, Drop, Serde)] #[dojo::model] -struct ForeignKey { +pub struct ForeignKey { #[key] foreign_key: felt252, entity_id: u128, diff --git a/contracts/src/models/movable.cairo b/contracts/src/models/movable.cairo index 1858a7598..6a0fa6f04 100644 --- a/contracts/src/models/movable.cairo +++ b/contracts/src/models/movable.cairo @@ -6,7 +6,7 @@ use eternum::models::position::Coord; // speed seconds per km #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Movable { +pub struct Movable { #[key] entity_id: u128, sec_per_km: u16, @@ -38,7 +38,7 @@ impl MovableCustomImpl of MovableCustomTrait { // without having to attach a Movable component to the order #[derive(Copy, Drop, Serde)] #[dojo::model] -struct ArrivalTime { +pub struct ArrivalTime { #[key] entity_id: u128, arrives_at: u64, diff --git a/contracts/src/models/name.cairo b/contracts/src/models/name.cairo index cad8bb8a0..a2d307729 100644 --- a/contracts/src/models/name.cairo +++ b/contracts/src/models/name.cairo @@ -1,6 +1,6 @@ #[derive(Copy, Drop, Serde)] #[dojo::model] -struct AddressName { +pub struct AddressName { #[key] address: felt252, name: felt252 @@ -8,7 +8,7 @@ struct AddressName { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct EntityName { +pub struct EntityName { #[key] entity_id: u128, name: felt252 diff --git a/contracts/src/models/order.cairo b/contracts/src/models/order.cairo index b3535cfc0..e72a33a89 100644 --- a/contracts/src/models/order.cairo +++ b/contracts/src/models/order.cairo @@ -1,6 +1,6 @@ #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Orders { +pub struct Orders { #[key] order_id: u128, hyperstructure_count: u128 diff --git a/contracts/src/models/owner.cairo b/contracts/src/models/owner.cairo index 5d85d9469..35e5fe2ec 100644 --- a/contracts/src/models/owner.cairo +++ b/contracts/src/models/owner.cairo @@ -6,7 +6,7 @@ use starknet::ContractAddress; // contract address owning an entity #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Owner { +pub struct Owner { #[key] entity_id: u128, address: ContractAddress, @@ -15,7 +15,7 @@ struct Owner { // entity owning an entity #[derive(Copy, Drop, Serde, Default)] #[dojo::model] -struct EntityOwner { +pub struct EntityOwner { #[key] entity_id: u128, entity_owner_id: u128, diff --git a/contracts/src/models/population.cairo b/contracts/src/models/population.cairo index a92b453fa..2cf5d473f 100644 --- a/contracts/src/models/population.cairo +++ b/contracts/src/models/population.cairo @@ -3,7 +3,7 @@ use eternum::models::buildings::{BuildingCategory}; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Population { +pub struct Population { #[key] entity_id: u128, population: u32, // current population diff --git a/contracts/src/models/position.cairo b/contracts/src/models/position.cairo index 6ff19b085..b417ad3e0 100644 --- a/contracts/src/models/position.cairo +++ b/contracts/src/models/position.cairo @@ -138,7 +138,7 @@ impl CoordImpl of CoordTrait { // https://www.redblobgames.com/grids/hexagons/#neighbors-offset if self.y & 1 == 0 { - // where self.y (row) is even + // where self.y (row) is even match direction { Direction::East(()) => Coord { x: self.x + 1, y: self.y }, Direction::NorthEast(()) => Coord { x: self.x + 1, y: self.y + 1 }, @@ -185,7 +185,7 @@ impl CoordIntoCube of Into { let col: i128 = self.x.try_into().unwrap(); let row: i128 = self.y.try_into().unwrap(); let q = col - ((row - (self.y % 2).try_into().unwrap()) / 2); - // (self.y % 2) and not (col % 2) because col is i128 + // (self.y % 2) and not (col % 2) because col is i128 // and modulo for negative numbers is different if it // was col, it would be (col & 1) where `&` is bitwise AND let r = row; @@ -212,7 +212,7 @@ impl TravelImpl, +Copy, +Drop> of TravelTrait { #[derive(PartialEq, Copy, Drop, Serde, Default)] #[dojo::model] -struct Position { +pub struct Position { #[key] entity_id: u128, x: u128, @@ -336,7 +336,7 @@ mod tests { // #[test] - // fn test_get_zone() { + // fn test_get_zone() { // let a = Position { entity_id: 0, x: 1333333, y: 200000 }; // let zone = a.get_zone(); // assert(zone == 4, 'zone should be 4'); @@ -355,7 +355,7 @@ mod tests { } - //- Even row + //- Even row #[test] fn test_neighbor_even_row_east() { @@ -402,7 +402,7 @@ mod tests { } - //- Odd row + //- Odd row #[test] fn test_neighbor_odd_row_east() { diff --git a/contracts/src/models/production.cairo b/contracts/src/models/production.cairo index 7b676d04e..ce3a5b15f 100644 --- a/contracts/src/models/production.cairo +++ b/contracts/src/models/production.cairo @@ -10,7 +10,7 @@ use starknet::get_block_timestamp; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Production { +pub struct Production { #[key] entity_id: u128, #[key] @@ -148,7 +148,7 @@ impl ProductionRateImpl of ProductionRateTrait { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct ProductionInput { +pub struct ProductionInput { #[key] output_resource_type: u8, #[key] @@ -159,9 +159,9 @@ struct ProductionInput { #[generate_trait] impl ProductionInputCustomImpl of ProductionInputCustomTrait { - /// Production ends when any input material runs out of balance so what this - /// function does is that it finds the first input resource to run out of balance that - /// returns the tick it runs out + /// Production ends when any input material runs out of balance so what this + /// function does is that it finds the first input resource to run out of balance that + /// returns the tick it runs out fn first_input_finish_tick(production: @Production, world: IWorldDispatcher) -> u64 { let production_config = get!(world, *production.resource_type, ProductionConfig); let tick_config = TickImpl::get_default_tick_config(world); @@ -197,7 +197,7 @@ impl ProductionInputCustomImpl of ProductionInputCustomTrait { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct ProductionOutput { +pub struct ProductionOutput { #[key] input_resource_type: u8, #[key] @@ -207,7 +207,7 @@ struct ProductionOutput { #[generate_trait] impl ProductionOutputCustomImpl of ProductionOutputCustomTrait { - /// Updates end ticks for dependent resources based + /// Updates end ticks for dependent resources based /// on changes in this resource's balance. fn sync_all_inputs_exhaustion_ticks_for(resource: @Resource, world: IWorldDispatcher) { let resource = *resource; diff --git a/contracts/src/models/quantity.cairo b/contracts/src/models/quantity.cairo index 90f62284a..2c575c264 100644 --- a/contracts/src/models/quantity.cairo +++ b/contracts/src/models/quantity.cairo @@ -1,11 +1,11 @@ use eternum::alias::ID; // not all entities are just a single object, some can be multiple. -// e.g. a group of free transport units can be a single entity with +// e.g. a group of free transport units can be a single entity with // a quantity component to show how many there are. #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Quantity { +pub struct Quantity { #[key] entity_id: u128, value: u128, @@ -32,7 +32,7 @@ impl QuantityCustomImpl of QuantityCustomTrait { // we need to update it everytime a free transport unit is created of destroyed. #[derive(Copy, Drop, Serde)] #[dojo::model] -struct QuantityTracker { +pub struct QuantityTracker { #[key] entity_id: felt252, count: u128, diff --git a/contracts/src/models/realm.cairo b/contracts/src/models/realm.cairo index ba173dd29..83f8f5975 100644 --- a/contracts/src/models/realm.cairo +++ b/contracts/src/models/realm.cairo @@ -6,7 +6,7 @@ use traits::Into; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Realm { +pub struct Realm { #[key] entity_id: u128, realm_id: u128, diff --git a/contracts/src/models/resources.cairo b/contracts/src/models/resources.cairo index 68655acca..62e11bb77 100644 --- a/contracts/src/models/resources.cairo +++ b/contracts/src/models/resources.cairo @@ -17,7 +17,7 @@ use eternum::utils::math::{is_u256_bit_set, set_u256_bit, min}; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Resource { +pub struct Resource { #[key] entity_id: u128, #[key] @@ -41,7 +41,7 @@ impl ResourceDisplay of Display { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct ResourceAllowance { +pub struct ResourceAllowance { #[key] owner_entity_id: u128, #[key] @@ -53,7 +53,7 @@ struct ResourceAllowance { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct ResourceCost { +pub struct ResourceCost { #[key] entity_id: u128, #[key] @@ -65,7 +65,7 @@ struct ResourceCost { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct DetachedResource { +pub struct DetachedResource { #[key] entity_id: u128, #[key] @@ -77,7 +77,7 @@ struct DetachedResource { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct OwnedResourcesTracker { +pub struct OwnedResourcesTracker { #[key] entity_id: u128, resource_types: u256 @@ -85,7 +85,7 @@ struct OwnedResourcesTracker { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct ResourceTransferLock { +pub struct ResourceTransferLock { #[key] entity_id: u128, release_at: u64, @@ -323,11 +323,11 @@ mod tests_resource_traits { fn setup() -> (IWorldDispatcher, u128, u128, Span<(u8, u128)>) { // SCENERIO - // There are two buildings in the structure. One producing + // There are two buildings in the structure. One producing // something which consumes `2` wood per tick. The only important // thing about the first building is that it consumes wood. // - // Then the other building is a wood building which produces + // Then the other building is a wood building which produces // `50` wood per tick. The cost of producing wood is `3` gold per tick. // // The entity has 100 gold initially. @@ -336,7 +336,7 @@ mod tests_resource_traits { let world = spawn_eternum(); let config_systems_address = deploy_system(world, config_systems::TEST_CLASS_HASH); - // set tick config + // set tick config let tick_config = TickConfig { config_id: WORLD_CONFIG_ID, tick_id: TickIds::DEFAULT, tick_interval_in_seconds: 5 }; @@ -375,7 +375,7 @@ mod tests_resource_traits { input_finish_tick: 0 }; - // set gold resource balance + // set gold resource balance let initial_gold_balance = 100; let mut gold_resource = Resource { @@ -407,7 +407,7 @@ mod tests_resource_traits { // check wood balance after 3 ticks let wood_resource = ResourceCustomImpl::get(world, (entity_id, ResourceTypes::WOOD)); - // wood production = 50 + // wood production = 50 // wood consumption = 3 assert_eq!(wood_resource.balance, (50 - 2) * tick_passed.into()); @@ -449,9 +449,9 @@ mod tests_resource_traits { // check that wood production end tick was computed correctly // wood production should end when gold balance finishes. - // + // // now we have 104 gold, so wood production should end at tick 34 - // the calculation being, 104 / 3 = 34.66 // 34 + // the calculation being, 104 / 3 = 34.66 // 34 let wood_production: Production = get!(world, (entity_id, ResourceTypes::WOOD), Production); assert_eq!(wood_production.input_finish_tick, 34); } diff --git a/contracts/src/models/road.cairo b/contracts/src/models/road.cairo index ca0f8dda9..e0c75f189 100644 --- a/contracts/src/models/road.cairo +++ b/contracts/src/models/road.cairo @@ -8,7 +8,7 @@ use eternum::models::position::Coord; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Road { +pub struct Road { #[key] start_coord_x: u128, #[key] diff --git a/contracts/src/models/stamina.cairo b/contracts/src/models/stamina.cairo index b3f73a6db..a3963d9eb 100644 --- a/contracts/src/models/stamina.cairo +++ b/contracts/src/models/stamina.cairo @@ -7,7 +7,7 @@ use eternum::{ #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Stamina { +pub struct Stamina { #[key] entity_id: u128, amount: u16, diff --git a/contracts/src/models/structure.cairo b/contracts/src/models/structure.cairo index 427992c9b..021f48b1e 100644 --- a/contracts/src/models/structure.cairo +++ b/contracts/src/models/structure.cairo @@ -7,7 +7,7 @@ use traits::Into; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Structure { +pub struct Structure { #[key] entity_id: u128, category: StructureCategory @@ -49,7 +49,7 @@ impl StructureCategoryIntoFelt252 of Into { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct StructureCount { +pub struct StructureCount { #[key] coord: Coord, count: u8 diff --git a/contracts/src/models/trade.cairo b/contracts/src/models/trade.cairo index 03a73a0d7..2cf0c8508 100644 --- a/contracts/src/models/trade.cairo +++ b/contracts/src/models/trade.cairo @@ -2,7 +2,7 @@ use eternum::alias::ID; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Trade { +pub struct Trade { #[key] trade_id: u128, maker_id: u128, @@ -19,7 +19,7 @@ struct Trade { #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Status { +pub struct Status { #[key] trade_id: u128, value: u128, diff --git a/contracts/src/models/weight.cairo b/contracts/src/models/weight.cairo index ed85b2be9..f66cf8959 100644 --- a/contracts/src/models/weight.cairo +++ b/contracts/src/models/weight.cairo @@ -2,7 +2,7 @@ use eternum::models::capacity::{Capacity, CapacityCustomTrait}; use eternum::models::quantity::{Quantity}; #[derive(Copy, Drop, Serde)] #[dojo::model] -struct Weight { +pub struct Weight { #[key] entity_id: u128, value: u128, diff --git a/contracts/src/systems.cairo b/contracts/src/systems.cairo index 53dda4e42..ad5dfffe2 100644 --- a/contracts/src/systems.cairo +++ b/contracts/src/systems.cairo @@ -1,69 +1,69 @@ -mod config { - mod contracts; +pub mod config { + pub mod contracts; #[cfg(test)] mod tests; } -mod realm { - mod contracts; +pub mod realm { + pub mod contracts; #[cfg(test)] mod tests; } -mod trade { - mod contracts; +pub mod trade { + pub mod contracts; #[cfg(test)] mod tests; } -mod resources { - mod contracts; +pub mod resources { + pub mod contracts; #[cfg(test)] mod tests; } -mod transport { - mod contracts; +pub mod transport { + pub mod contracts; #[cfg(test)] mod tests; } -mod leveling { - mod contracts; +pub mod leveling { + pub mod contracts; #[cfg(test)] mod tests; } -mod name { - mod contracts; +pub mod name { + pub mod contracts; } -mod hyperstructure { - mod contracts; +pub mod hyperstructure { + pub mod contracts; #[cfg(test)] mod tests; } -mod buildings { - mod contracts; +pub mod buildings { + pub mod contracts; #[cfg(test)] mod tests; } -mod map { - mod contracts; +pub mod map { + pub mod contracts; #[cfg(test)] mod tests; } -mod dev { - mod contracts; +pub mod dev { + pub mod contracts; } -mod combat { - mod contracts; +pub mod combat { + pub mod contracts; #[cfg(test)] mod tests; } -mod bank { - mod contracts; +pub mod bank { + pub mod contracts; #[cfg(test)] mod tests; } -mod guild { - mod contracts; +pub mod guild { + pub mod contracts; #[cfg(test)] mod tests; } diff --git a/contracts/src/systems/bank/contracts/bank.cairo b/contracts/src/systems/bank/contracts/bank.cairo index 704c54c2f..4b5ff7754 100644 --- a/contracts/src/systems/bank/contracts/bank.cairo +++ b/contracts/src/systems/bank/contracts/bank.cairo @@ -77,7 +77,7 @@ mod bank_systems { } #[generate_trait] - impl InternalBankSystemsImpl of BankSystemsTrait { + pub impl InternalBankSystemsImpl of BankSystemsTrait { fn pickup_resources_from_bank( world: IWorldDispatcher, bank_entity_id: u128, entity_id: u128, resources: Span<(u8, u128)>, ) -> ID { diff --git a/contracts/src/systems/bank/contracts/liquidity.cairo b/contracts/src/systems/bank/contracts/liquidity.cairo index b9d765a51..0a4cef4c7 100644 --- a/contracts/src/systems/bank/contracts/liquidity.cairo +++ b/contracts/src/systems/bank/contracts/liquidity.cairo @@ -132,7 +132,7 @@ mod liquidity_systems { } #[generate_trait] - impl InternalLiquiditySystemsImpl of InternalLiquiditySystemsTrait { + pub impl InternalLiquiditySystemsImpl of InternalLiquiditySystemsTrait { fn emit_event( world: IWorldDispatcher, market: Market, diff --git a/contracts/src/systems/bank/contracts/swap.cairo b/contracts/src/systems/bank/contracts/swap.cairo index 31b35cade..a595a7301 100644 --- a/contracts/src/systems/bank/contracts/swap.cairo +++ b/contracts/src/systems/bank/contracts/swap.cairo @@ -150,7 +150,7 @@ mod swap_systems { } #[generate_trait] - impl InternalSwapSystemsImpl of InternalSwapSystemsTrait { + pub impl InternalSwapSystemsImpl of InternalSwapSystemsTrait { fn emit_event( world: IWorldDispatcher, market: Market, diff --git a/contracts/src/systems/bank/tests/swap.cairo b/contracts/src/systems/bank/tests/swap.cairo index 72532562c..ce28986d8 100644 --- a/contracts/src/systems/bank/tests/swap.cairo +++ b/contracts/src/systems/bank/tests/swap.cairo @@ -190,7 +190,7 @@ fn test_swap_buy_with_fees() { let market = get!(world, (bank_entity_id, ResourceTypes::WOOD), Market); let liquidity = get!(world, (bank_entity_id, player, ResourceTypes::WOOD), Liquidity); - // 10_000 (reserve) + 11_235 (lords cost) + // 10_000 (reserve) + 11_235 (lords cost) assert(market.lords_amount == 11_235, 'market.lords_amount'); // 10000 (reserve) - 1000 (result) assert(market.resource_amount == 9000, 'market.resource_amount'); diff --git a/contracts/src/systems/combat/contracts.cairo b/contracts/src/systems/combat/contracts.cairo index fded1a6a3..db95941b5 100644 --- a/contracts/src/systems/combat/contracts.cairo +++ b/contracts/src/systems/combat/contracts.cairo @@ -3,9 +3,9 @@ use eternum::models::{combat::{Troops, Battle, BattleSide}}; #[dojo::interface] trait ICombatContract { /// Creates an army entity. - /// + /// /// This function allows the creation of two types of armies: - /// + /// /// 1. **Defensive Army**: /// - Assigned to protect a specific structure. /// - Cannot move or hold resources. @@ -13,13 +13,13 @@ trait ICombatContract { /// - Only one defensive army is allowed per structure. Attempting to create more than one for /// the same structure will result in an error. /// - Specify `is_defensive_army` as `true` to create this type of army. - /// + /// /// 2. **Roaming Army**: /// - Can move freely across the map. /// - Engages in exploring hexes, joining battles, and pillaging structures. /// - There is no limit to the number of roaming armies you can create. /// - Specify `is_defensive_army` as `false` to create this type of army. - /// + /// /// # Preconditions: /// - The caller must own the entity identified by `army_owner_id`. /// @@ -48,14 +48,14 @@ trait ICombatContract { /// Delete an army /// - army must not be a defensive army /// - army must be dead (in battle or otherwise) - /// + /// fn army_delete(ref world: IWorldDispatcher, army_id: u128); /// Purchases and adds troops to an existing army entity. /// /// # Preconditions: /// - The caller must own the entity identified by `payer_id`. /// - The payer and the army must be at the same position. E.g - /// if the payer is a structure (a realm for example), the army + /// if the payer is a structure (a realm for example), the army /// must be at the realm in order to add troops to its army. /// /// # Arguments: @@ -97,12 +97,12 @@ trait ICombatContract { /// 2. **Troop Transfer**: /// - Decreases the number of troops, health, and quantity in the `from_army_id`. /// - Increases the number of troops, health, and quantity in the `to_army_id`. - /// + /// /// # Note: - /// It is important to know that you can only transfer troops with full health from - /// one army to another. e.g if the first army has + /// It is important to know that you can only transfer troops with full health from + /// one army to another. e.g if the first army has /// `FirstArmy(100 knights, 100 paladins,100 crossbowman)` but it went to battle and now - /// it only has half it's initial `Health`` left, you'll only be able to transfer half, i.e + /// it only has half it's initial `Health`` left, you'll only be able to transfer half, i.e /// `(100 knights, 100 paladins,100 crossbowman)``, to the SecondArmy. /// /// # Returns: @@ -114,7 +114,7 @@ trait ICombatContract { /// # Preconditions: /// - The caller must own the `attacking_army_id`. /// - Both `attacking_army_id` and `defending_army_id` must not already be in battle. - /// If the attacked army is in a battle that has ended, it is automatically forced + /// If the attacked army is in a battle that has ended, it is automatically forced /// to leave the battle. /// - Both armies must be at the same location. /// @@ -140,26 +140,26 @@ trait ICombatContract { /// - Sets the battle position and resets the battle delta. /// /// # Note: - /// This is how the deposited resources are escrowed. Whenever any army joins a - /// battle, the items which they are securing are locked from being transferred - /// and they will also not be able to receive resources. - /// + /// This is how the deposited resources are escrowed. Whenever any army joins a + /// battle, the items which they are securing are locked from being transferred + /// and they will also not be able to receive resources. + /// /// For example; - /// - If an army is not a defensive army, the items they are securing are the items they hold. + /// - If an army is not a defensive army, the items they are securing are the items they hold. /// So we lock these items. We also transfer the items into the battle escrow pool - /// - /// - If an army is a defensive army, the items they are securing are the items owned + /// + /// - If an army is a defensive army, the items they are securing are the items owned /// by the structure they are protecting and so these items are lock. The structures can't /// receive or send any resources. - /// + /// /// However, for a couple of reasons, we do not transfer resources owned by structures into the - /// escrow pool because if a structure is producing resources, it would be impossible to + /// escrow pool because if a structure is producing resources, it would be impossible to /// continously donate resources into the battle escrow. Even if it was possible, it would take /// too much gas. - /// + /// /// Instead, what we do is that we just lock up the structure's resources and if you win the battle /// against the structure, you can continuously pillage it without being sent back to your base. - /// + /// /// # Returns: /// * None fn battle_start(ref world: IWorldDispatcher, attacking_army_id: u128, defending_army_id: u128) -> u128; @@ -170,7 +170,7 @@ trait ICombatContract { /// - The specified `battle_side` must be either `BattleSide::Attack` or `BattleSide::Defence`. /// - The caller must own the `army_id`. /// - The battle must be ongoing. - /// - The army must not already be in a battle. + /// - The army must not already be in a battle. /// - The army must be at the same location as the battle. /// /// # Arguments: @@ -202,11 +202,11 @@ trait ICombatContract { /// - Resets the battle delta with the troop configuration. /// /// # Note: - /// When an army joins a battle, its protected resources are locked and transferred - /// to the battle escrow. This ensures that resources cannot be transferred in or out - /// of the army while it is engaged in the battle. - /// - /// For defensive armies, the resources owned by the structures they protect are locked + /// When an army joins a battle, its protected resources are locked and transferred + /// to the battle escrow. This ensures that resources cannot be transferred in or out + /// of the army while it is engaged in the battle. + /// + /// For defensive armies, the resources owned by the structures they protect are locked /// but not transferred into the escrow to avoid continuous donation issues. /// see. the `battle_start` function for more info on this /// @@ -214,7 +214,7 @@ trait ICombatContract { /// * None fn battle_join(ref world: IWorldDispatcher, battle_id: u128, battle_side: BattleSide, army_id: u128); - /// Allows an army to leave an ongoing battle, releasing its resources and restoring its mobility + /// Allows an army to leave an ongoing battle, releasing its resources and restoring its mobility /// (if it was previously mobile). /// /// # Preconditions: @@ -248,25 +248,25 @@ trait ICombatContract { /// /// # Notes on Reward: /// - If you leave in the middle of a battle that doesn't yet have a decided outcome, - /// you lose all the resources deposited in the battle escrow. - /// + /// you lose all the resources deposited in the battle escrow. + /// /// Because Structures` rescources are not deposited into escrow, and so we can't make /// them lose all their resources, structure defensive armies CAN NOT leave a battle until /// it is done. There must be a winner, loser or it must have been a draw - /// + /// /// - If you leave after a battle has ended; - /// a. if you won, you leave with your initial resources and you also take a portion + /// a. if you won, you leave with your initial resources and you also take a portion /// of the resources deposited in escrow by the opposing team based on the number /// of troops you contributed to the battle. - /// - /// This method has the downside that a big army can just swoop in, close to the + /// + /// This method has the downside that a big army can just swoop in, close to the /// end of the battle, and take the giant share of the loot. But such is life. - /// + /// /// If you won against a structure, you can pillage them to infinity. - /// + /// /// b. if you lost, you lose all the resources deposited in escrow /// c. if the battle was drawn, you can leave with your deposited resources - /// + /// /// # Returns: /// * None fn battle_leave(ref world: IWorldDispatcher, battle_id: u128, army_id: u128); @@ -278,7 +278,7 @@ trait ICombatContract { /// - The entity being pillaged (`structure_id`) must be a valid structure. /// - The attacking army (`army_id`) must not be currently in battle. /// - The attacking army must be at the same location as the structure. - /// - If the structure has a protecting army in battle, the attacking army must join the battle + /// - If the structure has a protecting army in battle, the attacking army must join the battle /// or wait till the structure's defensive army is done with the battle. /// /// # Arguments: @@ -298,15 +298,16 @@ trait ICombatContract { /// 3. **Pillage Calculation**: /// - Calculates the strength of the attacking and defending armies based on their troops and health. /// - Uses a probabilistic model to determine if the pillaging attempt is successful. - /// - Randomly selects resources from the structure to pillage, considering army capacity and resource availability. + /// - Randomly selects resources from the structure to pillage, considering army capacity and resource + /// availability. /// 4. **Outcome Effects**: /// - If the pillage attempt is successful, transfers resources from the structure to the attacking army. /// - Optionally destroys a building within the structure based on specific conditions. - /// - Deducts health from both armies involved in the battle. + /// - Deducts health from both armies involved in the battle. /// If any army is dead, no health is deducted. - /// + /// /// 5. **Final Actions**: - /// - Handles the movement of the attacking army back to its owner after a successful pillage, + /// - Handles the movement of the attacking army back to its owner after a successful pillage, /// if continuous pillaging is not possible. /// - Emits a `PillageEvent` to signify the outcome of the pillage action. /// @@ -481,7 +482,7 @@ mod combat_systems { let mut army: Army = get!(world, army_id, Army); if army.is_in_battle() { - // update army health and troop count + // update army health and troop count let mut battle: Battle = get!(world, army.battle_id, Battle); InternalCombatImpl::update_battle_and_army(world, ref battle, ref army); @@ -498,7 +499,7 @@ mod combat_systems { battle_army.troops.add(troops); battle_army_lifetime.troops.add(troops); - // add troop health to battle army health + // add troop health to battle army health let troop_config = TroopConfigCustomImpl::get(world); battle_army_health.increase_by(troops.full_health(troop_config)); @@ -588,7 +589,7 @@ mod combat_systems { if defending_army.battle_id.is_non_zero() { // defending army appears to be in battle // so we want to update the defending army's battle status - // to see if the battle has ended. if it has ended, then the + // to see if the battle has ended. if it has ended, then the // army will be removed from the battle let mut defending_army_battle: Battle = get!(world, defending_army.battle_id, Battle); InternalCombatImpl::update_battle_and_army(world, ref defending_army_battle, ref defending_army); @@ -644,7 +645,7 @@ mod combat_systems { set!(world, (defending_army_movable)); } - // create battle + // create battle let mut battle: Battle = Default::default(); battle.entity_id = battle_id; battle.attack_army = attacking_army.into(); @@ -661,7 +662,7 @@ mod combat_systems { battle.deposit_balance(world, attacking_army, attacking_army_protectee); battle.deposit_balance(world, defending_army, defending_army_protectee); - // set battle position + // set battle position let mut battle_position: Position = Default::default(); battle_position.entity_id = battle_id; battle_position.x = attacking_army_position.x; @@ -698,7 +699,7 @@ mod combat_systems { let mut caller_army_health: Health = get!(world, army_id, Health); caller_army_health.assert_alive("Your army"); - // caller army health sanity check + // caller army health sanity check assert!( caller_army_health.current == caller_army.troops.full_health(troop_config), "caller health sanity check fail" @@ -737,7 +738,7 @@ mod combat_systems { battle_army.troops.add(caller_army.troops); battle_army_lifetime.troops.add(caller_army.troops); - // add caller army heath to battle army health + // add caller army heath to battle army health battle_army_health.increase_by(caller_army_health.current); // update battle @@ -791,7 +792,7 @@ mod combat_systems { let structure_position: Position = get!(world, structure_id, Position); claimer_army_position.assert_same_location(structure_position.into()); - // ensure structure has no army protecting it + // ensure structure has no army protecting it let structure_army_id: u128 = get!(world, structure_id, Protector).army_id; if structure_army_id.is_non_zero() { let mut structure_army: Army = get!(world, structure_army_id, Army); @@ -948,7 +949,7 @@ mod combat_systems { if structure.category == StructureCategory::Realm { // all buildings are at most 4 directions from the center - // so first we pick a random between within 1 and 4 + // so first we pick a random between within 1 and 4 // with higher probability of high numbers let mut chosen_direction_count: u8 = *random::choices( @@ -1105,7 +1106,7 @@ mod combat_systems { #[generate_trait] - impl InternalCombatImpl of InternalCombatTrait { + pub impl InternalCombatImpl of InternalCombatTrait { fn create_attacking_army( world: IWorldDispatcher, army_owner_id: u128, owner_address: starknet::ContractAddress ) -> u128 { @@ -1150,7 +1151,7 @@ mod combat_systems { // Defensive armies can only be assigned as structure protectors get!(world, army_owner_id, Structure).assert_is_structure(); - // ensure the structure does not have a defensive army + // ensure the structure does not have a defensive army let mut structure_protector: Protector = get!(world, army_owner_id, Protector); structure_protector.assert_has_no_defensive_army(); @@ -1166,7 +1167,7 @@ mod combat_systems { fn create_base_army( world: IWorldDispatcher, army_owner_id: u128, owner_address: starknet::ContractAddress ) -> u128 { - // ensure army owner is a structure + // ensure army owner is a structure get!(world, army_owner_id, Structure).assert_is_structure(); // ensure owner has enough military buildings to create army @@ -1250,7 +1251,7 @@ mod combat_systems { position.x = 0; position.y = 0; set!(world, (position)); - // reset components connected to army + // reset components connected to army // let ( // owner, // position, diff --git a/contracts/src/systems/combat/tests/battle_leave_test.cairo b/contracts/src/systems/combat/tests/battle_leave_test.cairo index 5e960ce2c..7b0dfd060 100644 --- a/contracts/src/systems/combat/tests/battle_leave_test.cairo +++ b/contracts/src/systems/combat/tests/battle_leave_test.cairo @@ -247,7 +247,7 @@ fn test_battle_leave_by_winner() { combat_system_dispatcher.battle_leave(battle_id, player_1_army_id); // ensure the player_1 took all the reward from the contest pot - // the player_1's gold balance should now be triple since it took + // the player_1's gold balance should now be triple since it took // (player_2 and player 3)'s gold balance after battle ended let player_1_gold_resource: Resource = ResourceCustomImpl::get(world, (player_1_army_id, ResourceTypes::GOLD)); assert_eq!(ARMY_GOLD_RESOURCE_AMOUNT * 3, player_1_gold_resource.balance); diff --git a/contracts/src/systems/hyperstructure/contracts.cairo b/contracts/src/systems/hyperstructure/contracts.cairo index a528909e6..0fbc54315 100644 --- a/contracts/src/systems/hyperstructure/contracts.cairo +++ b/contracts/src/systems/hyperstructure/contracts.cairo @@ -117,7 +117,7 @@ mod hyperstructure_systems { #[generate_trait] - impl InternalHyperstructureSystemsImpl of InternalHyperstructureSystemsTrait { + pub impl InternalHyperstructureSystemsImpl of InternalHyperstructureSystemsTrait { fn handle_contribution( world: IWorldDispatcher, hyperstructure_entity_id: u128, diff --git a/contracts/src/systems/leveling/contracts.cairo b/contracts/src/systems/leveling/contracts.cairo index 158c91459..ed36753a7 100644 --- a/contracts/src/systems/leveling/contracts.cairo +++ b/contracts/src/systems/leveling/contracts.cairo @@ -41,7 +41,7 @@ mod leveling_systems { #[generate_trait] - impl InternalLevelingSystemsImpl of InternalLevelingSystemsTrait { + pub impl InternalLevelingSystemsImpl of InternalLevelingSystemsTrait { fn get_realm_level_bonus(world: IWorldDispatcher, realm_entity_id: ID, leveling_index: u8) -> u128 { let level = get!(world, (realm_entity_id), Level); let leveling_config: LevelingConfig = get!(world, REALM_LEVELING_CONFIG_ID, LevelingConfig); diff --git a/contracts/src/systems/leveling/tests/internal_leveling_tests.cairo b/contracts/src/systems/leveling/tests/internal_leveling_tests.cairo index e8af7cc4a..b472c766f 100644 --- a/contracts/src/systems/leveling/tests/internal_leveling_tests.cairo +++ b/contracts/src/systems/leveling/tests/internal_leveling_tests.cairo @@ -24,7 +24,7 @@ mod internal_leveling_systems { fn setup() -> (IWorldDispatcher, u128) { let world = spawn_eternum(); - // define leveling config + // define leveling config let decay_scaled: u128 = 1844674407370955161; let base_multiplier: u128 = 25; @@ -95,7 +95,7 @@ mod internal_leveling_systems { let level = get!(world, (entity_id), Level); assert(level.level == 0, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); // assert resources are the right amount @@ -111,7 +111,7 @@ mod internal_leveling_systems { let level = get!(world, entity_id, Level); assert(level.level == 1, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); // assert resources are the right amount @@ -130,7 +130,7 @@ mod internal_leveling_systems { let level = get!(world, entity_id, Level); assert(level.level == 2, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); let coal_resource = get!(world, (entity_id, ResourceTypes::COAL), Resource); @@ -142,7 +142,7 @@ mod internal_leveling_systems { let level = get!(world, entity_id, Level); assert(level.level == 3, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); let obsidian_resource = get!(world, (entity_id, ResourceTypes::OBSIDIAN), Resource); @@ -154,7 +154,7 @@ mod internal_leveling_systems { let level = get!(world, entity_id, Level); assert(level.level == 4, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); let wheat_resource = get!(world, (entity_id, ResourceTypes::WHEAT), Resource); @@ -163,25 +163,25 @@ mod internal_leveling_systems { let level = get!(world, entity_id, Level); assert(level.level == 5, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); let level = get!(world, entity_id, Level); assert(level.level == 6, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); let level = get!(world, entity_id, Level); assert(level.level == 7, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); let level = get!(world, entity_id, Level); assert(level.level == 8, 'wrong level'); - // level up + // level up leveling::level_up(world, entity_id, LEVELING_CONFIG_ID); let level = get!(world, entity_id, Level); diff --git a/contracts/src/systems/leveling/tests/realm_leveling_tests.cairo b/contracts/src/systems/leveling/tests/realm_leveling_tests.cairo index 6e5bbdf5c..9272f6978 100644 --- a/contracts/src/systems/leveling/tests/realm_leveling_tests.cairo +++ b/contracts/src/systems/leveling/tests/realm_leveling_tests.cairo @@ -87,7 +87,7 @@ fn test_level_up_realm() { let level = get!(world, (realm_entity_id), Level); assert(level.level == 0, 'wrong level'); - // level up + // level up leveling_systems_dispatcher.level_up_realm(realm_entity_id,); let realm_wheat = get!(world, (realm_entity_id, ResourceTypes::WHEAT), Resource); @@ -110,7 +110,7 @@ fn test_level_up_not_realm_owner() { // set unknown caller starknet::testing::set_contract_address(contract_address_const::<'unknown'>()); - // level up + // level up leveling_systems_dispatcher.level_up_realm(realm_entity_id,); } @@ -124,6 +124,6 @@ fn test_level_up_not_realm() { // set abritrary realm entity id let realm_entity_id = 8888888; - // level up + // level up leveling_systems_dispatcher.level_up_realm(realm_entity_id,); } diff --git a/contracts/src/systems/map/contracts.cairo b/contracts/src/systems/map/contracts.cairo index 268f72b65..7f433b1b0 100644 --- a/contracts/src/systems/map/contracts.cairo +++ b/contracts/src/systems/map/contracts.cairo @@ -89,14 +89,14 @@ mod map_systems { InternalMapSystemsImpl::explore(world, unit_id, next_coord, exploration_reward); InternalMapSystemsImpl::discover_shards_mine(world, next_coord); - // travel to explored tile location + // travel to explored tile location InternalTravelSystemsImpl::travel_hex(world, unit_id, current_coord, array![direction].span()); } } #[generate_trait] - impl InternalMapSystemsImpl of InternalMapSystemsTrait { + pub impl InternalMapSystemsImpl of InternalMapSystemsTrait { fn explore(world: IWorldDispatcher, entity_id: u128, coord: Coord, reward: Span<(u8, u128)>) -> Tile { let mut tile: Tile = get!(world, (coord.x, coord.y), Tile); assert(tile.explored_at == 0, 'already explored'); diff --git a/contracts/src/systems/map/tests.cairo b/contracts/src/systems/map/tests.cairo index 04b13ee53..6b80701b6 100644 --- a/contracts/src/systems/map/tests.cairo +++ b/contracts/src/systems/map/tests.cairo @@ -86,7 +86,7 @@ fn test_map_explore() { assert_eq!(explored_tile.explored_by_id, realm_army_unit_id, "wrong realm owner"); assert_eq!(explored_tile.explored_at, TIMESTAMP, "wrong exploration time"); - // ensure that the right amount of food was burnt + // ensure that the right amount of food was burnt let expected_wheat_balance = INITIAL_WHEAT_BALANCE - MAP_EXPLORE_WHEAT_BURN_AMOUNT; let expected_fish_balance = INITIAL_FISH_BALANCE - MAP_EXPLORE_FISH_BURN_AMOUNT; let (realm_wheat, realm_fish) = ResourceFoodImpl::get(world, realm_entity_id); diff --git a/contracts/src/systems/resources/contracts.cairo b/contracts/src/systems/resources/contracts.cairo index fdab4ae92..a86c28f3d 100644 --- a/contracts/src/systems/resources/contracts.cairo +++ b/contracts/src/systems/resources/contracts.cairo @@ -59,8 +59,8 @@ mod resource_systems { /// /// * `entity_id` - The id of the entity approving the resources. /// * `recipient_entity_id` - The id of the entity being approved. - /// * `resources` - The resources to approve. - /// + /// * `resources` - The resources to approve. + /// fn approve(ref world: IWorldDispatcher, entity_id: ID, recipient_entity_id: ID, resources: Span<(u8, u128)>) { assert(entity_id != recipient_entity_id, 'self approval'); assert(resources.len() != 0, 'no resource to approve'); @@ -90,15 +90,15 @@ mod resource_systems { } /// Send a resource from an entity to another. This involves - /// one way transportation of resources from one entity's location - /// to another. This would be useful to gift out resources or for other + /// one way transportation of resources from one entity's location + /// to another. This would be useful to gift out resources or for other /// similar purposes /// /// # Arguments /// /// * `sender_entity_id` - The id of the entity sending the resources. /// * `recipient_entity_id` - The id of the entity receiving the resources. - /// * `resources` - The resources to transfer. + /// * `resources` - The resources to transfer. /// /// # Returns /// the resource chest id @@ -124,8 +124,8 @@ mod resource_systems { /// /// * `owner_entity_id` - The id of the entity resource owner /// * `recipient_entity_id` - The id of the entity receiving resources. - /// * `resources` - The resources to transfer. - /// + /// * `resources` - The resources to transfer. + /// /// # Returns /// the resource chest id /// @@ -169,7 +169,7 @@ mod resource_systems { } #[generate_trait] - impl InternalResourceSystemsImpl of InternalResourceSystemsTrait { + pub impl InternalResourceSystemsImpl of InternalResourceSystemsTrait { fn transfer( world: IWorldDispatcher, owner_id: ID, @@ -195,11 +195,11 @@ mod resource_systems { let mut resources_felt_arr: Array = array![]; let mut resources_clone = resources.clone(); - // ensure resource spending is not locked + // ensure resource spending is not locked let owner_resource_lock: ResourceTransferLock = get!(world, owner_id, ResourceTransferLock); owner_resource_lock.assert_not_locked(); - // ensure resource receipt is not locked + // ensure resource receipt is not locked let recipient_resource_lock: ResourceTransferLock = get!(world, actual_recipient_id, ResourceTransferLock); recipient_resource_lock.assert_not_locked(); loop { diff --git a/contracts/src/systems/resources/tests/resource_transfer_system_tests.cairo b/contracts/src/systems/resources/tests/resource_transfer_system_tests.cairo index 39165d216..606e95642 100644 --- a/contracts/src/systems/resources/tests/resource_transfer_system_tests.cairo +++ b/contracts/src/systems/resources/tests/resource_transfer_system_tests.cairo @@ -143,7 +143,7 @@ mod resource_transfer_system_tests { world, (Resource { entity_id: sender_entity_id.into(), resource_type: ResourceTypes::DONKEY, balance: 0 },) ); - // set receiving entity capacity, and weight config + // set receiving entity capacity, and weight config set!( world, ( @@ -169,11 +169,11 @@ mod resource_transfer_system_tests { ) ); - // transfer resources + // transfer resources starknet::testing::set_contract_address(contract_address_const::<'owner_entity'>()); - // should fail because total capacity - // is 10,000 and total weight is 11,000 + // should fail because total capacity + // is 10,000 and total weight is 11,000 resource_systems_dispatcher .send( sender_entity_id.into(), @@ -189,7 +189,7 @@ mod resource_transfer_system_tests { fn test_transfer__not_owner() { let (_, resource_systems_dispatcher) = setup(); - // transfer resources + // transfer resources starknet::testing::set_contract_address(contract_address_const::<'unknown'>()); resource_systems_dispatcher.send(1, 2, array![(ResourceTypes::STONE, 400), (ResourceTypes::WOOD, 700),].span()); @@ -211,7 +211,7 @@ mod resource_transfer_system_tests { let receiver_entity_id = 12_u64; make_owner_and_receiver(world, sender_entity_id, receiver_entity_id); - // transfer resources + // transfer resources starknet::testing::set_contract_address(contract_address_const::<'owner_entity'>()); resource_systems_dispatcher diff --git a/contracts/src/systems/trade/contracts/trade_systems.cairo b/contracts/src/systems/trade/contracts/trade_systems.cairo index 85e34830c..0cd233dfb 100644 --- a/contracts/src/systems/trade/contracts/trade_systems.cairo +++ b/contracts/src/systems/trade/contracts/trade_systems.cairo @@ -223,12 +223,12 @@ mod trade_systems { let ts = starknet::get_block_timestamp(); assert(trade.expires_at > ts, 'trade expired'); - // verify taker if it's a direct offer + // verify taker if it's a direct offer if trade.taker_id != 0 { assert(trade.taker_id == taker_id, 'not the taker'); } - // update trade + // update trade trade.taker_id = taker_id; set!(world, (trade)); diff --git a/contracts/src/systems/trade/tests/trade_systems_tests/accept_order.cairo b/contracts/src/systems/trade/tests/trade_systems_tests/accept_order.cairo index 08ce4e1dd..d5122b5e2 100644 --- a/contracts/src/systems/trade/tests/trade_systems_tests/accept_order.cairo +++ b/contracts/src/systems/trade/tests/trade_systems_tests/accept_order.cairo @@ -41,7 +41,7 @@ fn setup(direct_trade: bool) -> (IWorldDispatcher, u128, u128, u128, ITradeSyste let config_systems_address = deploy_system(world, config_systems::TEST_CLASS_HASH); - // set speed configuration + // set speed configuration ITransportConfigDispatcher { contract_address: config_systems_address } .set_speed_config(DONKEY_ENTITY_TYPE, 10); // 10km per sec @@ -153,7 +153,7 @@ fn test_accept_order_free_trade() { fn test_accept_order_direct_trade() { let (world, trade_id, _, taker_id, trade_systems_dispatcher) = setup(true); - // accept order + // accept order trade_systems_dispatcher .accept_order( taker_id, @@ -183,7 +183,7 @@ fn test_not_trade_taker_id() { let (world, trade_id, _, _, trade_systems_dispatcher) = setup(true); // the setup states the trade is a direct offer - // so here we are checking to see that the person + // so here we are checking to see that the person // who wants to accept is the intended recepient let taker_id = 9999; // set arbitrarily @@ -192,7 +192,7 @@ fn test_not_trade_taker_id() { // create order with a caller that isnt the owner of maker_id starknet::testing::set_contract_address(contract_address_const::<'takers_other_realm'>()); - // accept order + // accept order trade_systems_dispatcher .accept_order( taker_id, @@ -211,7 +211,7 @@ fn test_caller_not_taker() { // create order with a caller that isnt the owner of taker_id starknet::testing::set_contract_address(contract_address_const::<'some_unknown'>()); - // accept order + // accept order trade_systems_dispatcher .accept_order( taker_id, @@ -236,7 +236,7 @@ fn test_transport_not_enough_donkey_capacity() { starknet::testing::set_contract_address(contract_address_const::<'taker'>()); - // accept order + // accept order trade_systems_dispatcher .accept_order( taker_id, diff --git a/contracts/src/systems/trade/tests/trade_systems_tests/cancel_order.cairo b/contracts/src/systems/trade/tests/trade_systems_tests/cancel_order.cairo index ce1174052..e9b975f40 100644 --- a/contracts/src/systems/trade/tests/trade_systems_tests/cancel_order.cairo +++ b/contracts/src/systems/trade/tests/trade_systems_tests/cancel_order.cairo @@ -35,7 +35,7 @@ fn setup() -> (IWorldDispatcher, u128, u128, u128, ITradeSystemsDispatcher) { let config_systems_address = deploy_system(world, config_systems::TEST_CLASS_HASH); - // set speed configuration + // set speed configuration ITransportConfigDispatcher { contract_address: config_systems_address } .set_speed_config(DONKEY_ENTITY_TYPE, 10); // 10km per sec @@ -109,7 +109,7 @@ fn test_cancel() { let _trade = get!(world, trade_id, Trade); - // cancel order + // cancel order starknet::testing::set_contract_address(contract_address_const::<'maker'>()); trade_systems_dispatcher .cancel_order(trade_id, array![(ResourceTypes::STONE, 100), (ResourceTypes::GOLD, 100),].span()); @@ -133,11 +133,11 @@ fn test_cancel() { fn test_cancel_after_acceptance() { let (world, trade_id, _, _, trade_systems_dispatcher) = setup(); - // accept order + // accept order set!(world, (Status { trade_id, value: TradeStatus::ACCEPTED, }),); - // cancel order + // cancel order starknet::testing::set_contract_address(contract_address_const::<'maker'>()); trade_systems_dispatcher .cancel_order(trade_id, array![(ResourceTypes::STONE, 100), (ResourceTypes::GOLD, 100),].span()); @@ -153,7 +153,7 @@ fn test_cancel_caller_not_maker() { // set caller to an unknown address starknet::testing::set_contract_address(contract_address_const::<'unknown'>()); - // cancel order + // cancel order trade_systems_dispatcher .cancel_order(trade_id, array![(ResourceTypes::STONE, 100), (ResourceTypes::GOLD, 100),].span()); } diff --git a/contracts/src/systems/transport/contracts/donkey_systems.cairo b/contracts/src/systems/transport/contracts/donkey_systems.cairo index 77ef0f975..57a19fde4 100644 --- a/contracts/src/systems/transport/contracts/donkey_systems.cairo +++ b/contracts/src/systems/transport/contracts/donkey_systems.cairo @@ -17,7 +17,7 @@ mod donkey_systems { #[generate_trait] - impl InternalDonkeySystemsImpl of InternalDonkeySystemsTrait { + pub impl InternalDonkeySystemsImpl of InternalDonkeySystemsTrait { fn burn_donkey(world: IWorldDispatcher, payer_id: ID, weight: u128) { // get number of donkeys needed let donkey_amount = Self::get_donkey_needed(world, weight); diff --git a/contracts/src/systems/transport/contracts/road_systems.cairo b/contracts/src/systems/transport/contracts/road_systems.cairo index c677ace81..fae3056b7 100644 --- a/contracts/src/systems/transport/contracts/road_systems.cairo +++ b/contracts/src/systems/transport/contracts/road_systems.cairo @@ -22,8 +22,8 @@ mod road_systems { impl RoadSystemsImpl of super::IRoadSystems { /// Create a road between two coordinates on the map. /// - /// Note: when you creat a road from A -> B, - /// you also automatically create a road from B -> A. + /// Note: when you creat a road from A -> B, + /// you also automatically create a road from B -> A. /// /// # Arguments /// diff --git a/contracts/src/systems/transport/contracts/travel_systems.cairo b/contracts/src/systems/transport/contracts/travel_systems.cairo index 7ba6a79fa..5da83907d 100644 --- a/contracts/src/systems/transport/contracts/travel_systems.cairo +++ b/contracts/src/systems/transport/contracts/travel_systems.cairo @@ -54,8 +54,8 @@ mod travel_systems { /// Travel to a destination /// /// This system can be called to move an entity from - /// its current location to another coordinate on the map. It - // is however crucial that the entity has all the necessary + /// its current location to another coordinate on the map. It + // is however crucial that the entity has all the necessary // models or components allowing it to move (i.e it must be movable) /// /// # Arguments @@ -107,7 +107,7 @@ mod travel_systems { } #[generate_trait] - impl InternalTravelSystemsImpl of InternalTravelSystemsTrait { + pub impl InternalTravelSystemsImpl of InternalTravelSystemsTrait { fn assert_tile_explored(world: IWorldDispatcher, coord: Coord) { let mut tile: Tile = get!(world, (coord.x, coord.y), Tile); assert(tile.explored_by_id != 0, 'tile not explored'); @@ -153,7 +153,7 @@ mod travel_systems { // ensure tile is explored Self::assert_tile_explored(world, to_coord); - // add coord to travel path + // add coord to travel path travel_path.append(to_coord); index += 1; @@ -174,7 +174,7 @@ mod travel_systems { ) ); - // emit travel event + // emit travel event let entityOwner = get!(world, transport_id, EntityOwner); emit!( world, @@ -231,7 +231,7 @@ mod travel_systems { ) ); - // emit travel event + // emit travel event let owner = get!(world, transport_id, Owner); emit!( world, diff --git a/contracts/src/systems/transport/tests/travel_systems_tests.cairo b/contracts/src/systems/transport/tests/travel_systems_tests.cairo index 0f48a1fdc..1098f9f26 100644 --- a/contracts/src/systems/transport/tests/travel_systems_tests.cairo +++ b/contracts/src/systems/transport/tests/travel_systems_tests.cairo @@ -93,7 +93,7 @@ fn test_travel() { starknet::testing::set_contract_address(contract_address_const::<'travelling_entity'>()); travel_systems_dispatcher.travel(travelling_entity_id.into(), destination_coord); - // verify arrival time and position of travelling_entity + // verify arrival time and position of travelling_entity let travelling_entity_arrival_time = get!(world, travelling_entity_id, ArrivalTime); let new_travelling_entity_position = get!(world, travelling_entity_id, Position); @@ -166,7 +166,7 @@ fn test_travel_with_realm_bonus() { starknet::testing::set_contract_address(contract_address_const::<'travelling_entity'>()); travel_systems_dispatcher.travel(travelling_entity_id.into(), destination_coord); - // verify arrival time and position of travelling_entity + // verify arrival time and position of travelling_entity let travelling_entity_arrival_time = get!(world, travelling_entity_id, ArrivalTime); let new_travelling_entity_position = get!(world, travelling_entity_id, Position); assert(travelling_entity_arrival_time.arrives_at == 6800000, 'arrival time not correct'); @@ -252,7 +252,7 @@ fn test_travel_with_realm_and_order_bonus() { starknet::testing::set_contract_address(contract_address_const::<'travelling_entity'>()); travel_systems_dispatcher.travel(travelling_entity_id.into(), destination_coord); - // verify arrival time and position of travelling_entity + // verify arrival time and position of travelling_entity let travelling_entity_arrival_time = get!(world, travelling_entity_id, ArrivalTime); let new_travelling_entity_position = get!(world, travelling_entity_id, Position); @@ -306,7 +306,7 @@ fn test_travel_with_road() { travel_systems_dispatcher.travel(travelling_entity_id.into(), destination_coord); - // verify arrival time and position of travelling_entity + // verify arrival time and position of travelling_entity let travelling_entity_arrival_time = get!(world, travelling_entity_id, ArrivalTime); let new_travelling_entity_position = get!(world, travelling_entity_id, Position); diff --git a/contracts/src/utils.cairo b/contracts/src/utils.cairo index dbb430328..b7e7105c2 100644 --- a/contracts/src/utils.cairo +++ b/contracts/src/utils.cairo @@ -1,8 +1,8 @@ -mod map; -mod math; -mod number; -mod random; +pub mod map; +pub mod math; +pub mod number; +pub mod random; #[cfg(test)] -mod testing; -mod unpack; -mod vrgda; +pub mod testing; +pub mod unpack; +pub mod vrgda; diff --git a/contracts/src/utils/map.cairo b/contracts/src/utils/map.cairo index 2b218f84e..753284707 100644 --- a/contracts/src/utils/map.cairo +++ b/contracts/src/utils/map.cairo @@ -1,2 +1,2 @@ -mod biomes; -mod constants; +pub mod biomes; +pub mod constants; diff --git a/contracts/src/utils/map/biomes.cairo b/contracts/src/utils/map/biomes.cairo index aa1925368..72ae85d81 100644 --- a/contracts/src/utils/map/biomes.cairo +++ b/contracts/src/utils/map/biomes.cairo @@ -4,7 +4,7 @@ use cubit::f128::types::vec3::{Vec3, Vec3Trait}; use eternum::utils::map::constants::fixed_constants as fc; #[derive(Copy, Drop, Serde, Introspect)] -enum Biome { +pub enum Biome { DeepOcean, Ocean, Beach, diff --git a/contracts/src/utils/map/constants.cairo b/contracts/src/utils/map/constants.cairo index 08d904e02..3914e7c73 100644 --- a/contracts/src/utils/map/constants.cairo +++ b/contracts/src/utils/map/constants.cairo @@ -1,57 +1,57 @@ -mod fixed_constants { +pub mod fixed_constants { use cubit::f128::types::fixed::{FixedTrait, Fixed, ONE_u128, HALF_u128}; #[inline(always)] - fn _0() -> Fixed { + pub fn _0() -> Fixed { FixedTrait::ZERO() } #[inline(always)] - fn _0_1() -> Fixed { + pub fn _0_1() -> Fixed { FixedTrait::new(1844674407370955161, false) } #[inline(always)] - fn _0_16() -> Fixed { + pub fn _0_16() -> Fixed { FixedTrait::new(2951479051793528258, false) } #[inline(always)] - fn _0_2() -> Fixed { + pub fn _0_2() -> Fixed { FixedTrait::new(3689348814741910323, false) } #[inline(always)] - fn _0_25() -> Fixed { + pub fn _0_25() -> Fixed { FixedTrait::new(4611686018427387904, false) } #[inline(always)] - fn _0_3() -> Fixed { + pub fn _0_3() -> Fixed { FixedTrait::new(5534023222112865484, false) } #[inline(always)] - fn _0_33() -> Fixed { + pub fn _0_33() -> Fixed { FixedTrait::new(6087425544324152033, false) } #[inline(always)] - fn _0_4() -> Fixed { + pub fn _0_4() -> Fixed { FixedTrait::new(7378697629483820646, false) } #[inline(always)] - fn _0_5() -> Fixed { + pub fn _0_5() -> Fixed { FixedTrait::new(HALF_u128, false) } #[inline(always)] - fn _0_53() -> Fixed { + pub fn _0_53() -> Fixed { FixedTrait::new(9776774359066062356, false) } @@ -61,50 +61,50 @@ mod fixed_constants { } #[inline(always)] - fn _0_66() -> Fixed { + pub fn _0_66() -> Fixed { FixedTrait::new(12174851088648304066, false) } #[inline(always)] - fn _0_7() -> Fixed { + pub fn _0_7() -> Fixed { FixedTrait::new(12912720851596686131, false) } #[inline(always)] - fn _0_72() -> Fixed { + pub fn _0_72() -> Fixed { FixedTrait::new(13281655733070877163, false) } #[inline(always)] - fn _0_8() -> Fixed { + pub fn _0_8() -> Fixed { FixedTrait::new(14757395258967641292, false) } #[inline(always)] - fn _0_83() -> Fixed { + pub fn _0_83() -> Fixed { FixedTrait::new(15310797581178927841, false) } #[inline(always)] - fn _0_9() -> Fixed { + pub fn _0_9() -> Fixed { FixedTrait::new(16602069666338596454, false) } #[inline(always)] - fn _1() -> Fixed { + pub fn _1() -> Fixed { FixedTrait::ONE() } #[inline(always)] - fn _2() -> Fixed { + pub fn _2() -> Fixed { FixedTrait::new_unscaled(2, false) } #[inline(always)] - fn _100() -> Fixed { + pub fn _100() -> Fixed { FixedTrait::new_unscaled(100, false) } } diff --git a/contracts/src/utils/math.cairo b/contracts/src/utils/math.cairo index 1ffbd0436..831007e2e 100644 --- a/contracts/src/utils/math.cairo +++ b/contracts/src/utils/math.cairo @@ -6,7 +6,7 @@ use alexandria_math::U32BitShift; /// * `exp` - The exponent. /// # Returns /// * `felt252` - The result of base raised to the power of exp. -fn pow(base: felt252, exp: felt252) -> felt252 { +pub fn pow(base: felt252, exp: felt252) -> felt252 { match exp { 0 => 1, _ => base * pow(base, exp - 1), @@ -14,7 +14,7 @@ fn pow(base: felt252, exp: felt252) -> felt252 { } -fn min, impl TCopy: Copy, impl TDrop: Drop>(a: T, b: T) -> T { +pub fn min, impl TCopy: Copy, impl TDrop: Drop>(a: T, b: T) -> T { return if (a < b) { return a; } else { @@ -22,7 +22,7 @@ fn min, impl TCopy: Copy, impl TDrop: Drop }; } -fn max, impl TCopy: Copy, impl TDrop: Drop>(a: T, b: T) -> T { +pub fn max, impl TCopy: Copy, impl TDrop: Drop>(a: T, b: T) -> T { return if (a > b) { return a; } else { @@ -34,7 +34,7 @@ fn max, impl TCopy: Copy, impl TDrop: Drop ///////// U32 Bit Manipulation ///////// /// Check whether a bit is set in a u32 number -fn is_u32_bit_set(number: u32, position: u8) -> bool { +pub fn is_u32_bit_set(number: u32, position: u8) -> bool { assert!(position <= 31, "position must be within the values of 0 and 31 (inclusive)"); if (number & U32BitShift::shl(1, position.into())) > 0 { @@ -44,7 +44,7 @@ fn is_u32_bit_set(number: u32, position: u8) -> bool { } /// Set a bit to a value in a u32 number -fn set_u32_bit(number: u32, position: u8, value: bool) -> u32 { +pub fn set_u32_bit(number: u32, position: u8, value: bool) -> u32 { assert!(position <= 31, "position must be within the values of 0 and 31 (inclusive)"); let value = if (value == true) { @@ -60,7 +60,7 @@ fn set_u32_bit(number: u32, position: u8, value: bool) -> u32 { ///////// U256 Bit Manipulation ///////// /// Check whether a bit is set in a u256 number -fn is_u256_bit_set(number: u256, position: u8) -> bool { +pub fn is_u256_bit_set(number: u256, position: u8) -> bool { if (number & U256BitShift::shl(1, position.into())) > 0 { return true; } @@ -68,7 +68,7 @@ fn is_u256_bit_set(number: u256, position: u8) -> bool { } /// Set a bit to a value in a u256 number -fn set_u256_bit(number: u256, position: u8, value: bool) -> u256 { +pub fn set_u256_bit(number: u256, position: u8, value: bool) -> u256 { let value = if (value == true) { 1 } else { @@ -78,18 +78,18 @@ fn set_u256_bit(number: u256, position: u8, value: bool) -> u256 { return (number & ~mask) | ((U256BitShift::shl(value, position.into())) & mask); } -trait PercentageTrait { +pub trait PercentageTrait { fn get(value: T, numerator: u64) -> T; } -impl PercentageImpl, +Div, +Into, +Copy, +Drop> of PercentageTrait { +pub impl PercentageImpl, +Div, +Into, +Copy, +Drop> of PercentageTrait { fn get(value: T, numerator: u64) -> T { return (value * numerator.into()) / PercentageValueImpl::_100().into(); } } #[generate_trait] -impl PercentageValueImpl of PercentageValueTrait { +pub impl PercentageValueImpl of PercentageValueTrait { fn _1() -> u64 { 100 } diff --git a/contracts/src/utils/number.cairo b/contracts/src/utils/number.cairo index c92af627d..b9f65fc1c 100644 --- a/contracts/src/utils/number.cairo +++ b/contracts/src/utils/number.cairo @@ -1,11 +1,11 @@ // copy pasta from https://github.com/gizatechxyz/orion/tree/main/src/operators -trait NumberTrait { +pub trait NumberTrait { fn abs(self: T) -> T; } -impl i128Number of NumberTrait { +pub impl i128Number of NumberTrait { fn abs(self: i128) -> i128 { if self >= 0 { return self; diff --git a/contracts/src/utils/random.cairo b/contracts/src/utils/random.cairo index 0b96f7dff..880e9aebd 100644 --- a/contracts/src/utils/random.cairo +++ b/contracts/src/utils/random.cairo @@ -6,7 +6,7 @@ use core::poseidon::poseidon_hash_span; /// salt: u128 /// salt used when generating the seed /// upper_bound: u128 -/// The upper_bound of possible values +/// The upper_bound of possible values /// i.e output will be from 0 to upper_bound - 1. /// /// Returns: @@ -24,7 +24,7 @@ fn make_seed_from_transaction_hash(salt: u128) -> u256 { .into(); } -/// Return a k sized list of population elements chosen with replacement. +/// Return a k sized list of population elements chosen with replacement. /// /// If the relative weights or cumulative weights are not specified, /// the selections are made with equal probability. @@ -37,7 +37,7 @@ fn make_seed_from_transaction_hash(salt: u128) -> u256 { /// cum_weights: Span /// The cumulative weights of each population element. /// This is to be used in place of weights to speed up calculations -/// if the sum of weights is already available. +/// if the sum of weights is already available. /// k: u128 /// The number of elements to sample. /// @@ -97,7 +97,7 @@ fn choices, impl TDrop: Drop>( break; } - // update salt by any number + // update salt by any number // just to make it different salt += 18; @@ -118,7 +118,7 @@ fn choices, impl TDrop: Drop>( } -/// Given a list of values, return a list of the same length, +/// Given a list of values, return a list of the same length, /// where each element is the sum of the previous values. /// /// Args: diff --git a/contracts/src/utils/testing/config.cairo b/contracts/src/utils/testing/config.cairo index e12215169..ffe959982 100644 --- a/contracts/src/utils/testing/config.cairo +++ b/contracts/src/utils/testing/config.cairo @@ -95,10 +95,9 @@ fn set_mercenaries_config(config_systems_address: ContractAddress) { fn set_weight_config(config_systems_address: ContractAddress) { let resource_weights = get_resource_weights(); let mut i = 0; - while i < resource_weights - .len() { - let (resource_id, weight) = *resource_weights.at(i); - IWeightConfigDispatcher { contract_address: config_systems_address }.set_weight_config(resource_id, weight); - i += 1; - } + while i < resource_weights.len() { + let (resource_id, weight) = *resource_weights.at(i); + IWeightConfigDispatcher { contract_address: config_systems_address }.set_weight_config(resource_id, weight); + i += 1; + } } diff --git a/contracts/src/utils/testing/world.cairo b/contracts/src/utils/testing/world.cairo index baee3044e..9d53f53ad 100644 --- a/contracts/src/utils/testing/world.cairo +++ b/contracts/src/utils/testing/world.cairo @@ -1,5 +1,5 @@ use core::array::{ArrayTrait, SpanTrait}; -use dojo::test_utils::spawn_test_world; +use dojo::utils::test::spawn_test_world; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; use eternum::models::bank::bank::bank; use eternum::models::bank::liquidity::liquidity; diff --git a/scripts/deploy.sh b/scripts/deploy.sh index c92c08b56..95d001de8 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -11,13 +11,13 @@ slot deployments delete eternum-23 torii slot deployments delete eternum-23 katana echo "Deploying world to Realms L3..." -slot deployments create eternum-24 katana --version v1.0.0-alpha.1 --invoke-max-steps 25000000 --disable-fee true --block-time 1000 +slot deployments create eternum-24 katana --version v1.0.0-alpha.3 --invoke-max-steps 25000000 --disable-fee true --block-time 1000 echo "Migrating world..." sozo --profile prod migrate apply --name eternum echo "Setting up remote indexer on slot..." -slot deployments create eternum-24 torii --version v1.0.0-alpha.1 --world 0x161b08e252b353008665e85ab5dcb0044a61186eb14b999657d14c04c94c824 --rpc https://api.cartridge.gg/x/eternum-24/katana --start-block 0 --index-pending true +slot deployments create eternum-24 torii --version v1.0.0-alpha.3 --world 0x161b08e252b353008665e85ab5dcb0044a61186eb14b999657d14c04c94c824 --rpc https://api.cartridge.gg/x/eternum-24/katana --start-block 0 --index-pending true bun --env-file=../client/.env.production ../config/index.ts From d288d194281096744920a0836101bd54af2668ec Mon Sep 17 00:00:00 2001 From: Credence Date: Sat, 27 Jul 2024 01:20:16 +0100 Subject: [PATCH 2/3] contracts: update workflow to print resource usage --- .github/workflows/test-contracts.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-contracts.yml b/.github/workflows/test-contracts.yml index a84ef4dce..f4a5535de 100644 --- a/.github/workflows/test-contracts.yml +++ b/.github/workflows/test-contracts.yml @@ -45,7 +45,7 @@ jobs: cd contracts && sozo build - name: Run Dojo Test for ${{ matrix.test }} run: | - cd contracts && sozo test -f ${{ matrix.test }} + cd contracts && sozo test -f ${{ matrix.test }} --print-resource-usage test-scarb-fmt: needs: [setup-environment] From 08be71c830530ceb6643422533682bea9afcc225 Mon Sep 17 00:00:00 2001 From: Credence Date: Sat, 27 Jul 2024 01:31:09 +0100 Subject: [PATCH 3/3] update workflow --- .github/workflows/test-contracts.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-contracts.yml b/.github/workflows/test-contracts.yml index f4a5535de..90ac6d8c1 100644 --- a/.github/workflows/test-contracts.yml +++ b/.github/workflows/test-contracts.yml @@ -54,5 +54,5 @@ jobs: - uses: actions/checkout@v3 - uses: software-mansion/setup-scarb@v1 with: - scarb-version: "2.6.5" + scarb-version: "2.7.0-rc.4" - run: cd contracts && scarb fmt --check