Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Dojo v1.0.0 alpha.3 #1143

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating to use dojo v1.0.0-alpha.3 in the CI workflow is consistent with the dependency update.

tar -xzf dojo-linux-x86_64.tar.gz
sudo mv sozo /usr/local/bin/
- name: Checkout repository
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the --print-resource-usage flag to the test command is helpful for monitoring test performance and resource usage.


test-scarb-fmt:
needs: [setup-environment]
Expand All @@ -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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.6.5
scarb 2.7.0-rc.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating scarb to 2.7.0-rc.4 aligns with using the latest Cairo version, which is good for compatibility with dojo v1.0.0-alpha.3.

4 changes: 2 additions & 2 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ 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",
]

[[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"
Expand Down
4 changes: 1 addition & 3 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating dojo dependency to v1.0.0-alpha.3 is good to stay current with the latest version.

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" }
Expand All @@ -29,8 +29,6 @@ world_address = "0x161b08e252b353008665e85ab5dcb0044a61186eb14b999657d14c04c94c8

[[target.dojo]]

[lib]

[tool.dojo.world]
seed = "eternum"
name = "Realms: Eternum"
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -241,7 +241,7 @@ fn get_resources_without_earthenshards() -> Span<u8> {
}

fn get_resources_without_earthenshards_probs() -> Span<u128> {
// 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();
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -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;

2 changes: 1 addition & 1 deletion contracts/src/models/bank/bank.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 4 additions & 10 deletions contracts/src/models/bank/liquidity.cairo
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,8 +10,8 @@ impl IntrospectFixed of Introspect<Fixed> {
}

#[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)]
Expand All @@ -38,7 +32,7 @@ impl IntrospectFixed of Introspect<Fixed> {

#[derive(Copy, Drop, Serde)]
#[dojo::model]
struct Liquidity {
pub struct Liquidity {
#[key]
bank_entity_id: u128,
#[key]
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/models/bank/market.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,8 +14,8 @@ impl IntrospectFixed of Introspect<Fixed> {
}

#[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)]
Expand All @@ -36,7 +36,7 @@ impl IntrospectFixed of Introspect<Fixed> {

#[derive(Copy, Drop, Serde)]
#[dojo::model]
struct Market {
pub struct Market {
#[key]
bank_entity_id: u128,
#[key]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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');

Expand Down
6 changes: 3 additions & 3 deletions contracts/src/models/buildings.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -37,7 +37,7 @@ struct Building {

#[derive(PartialEq, Copy, Drop, Serde)]
#[dojo::model]
struct BuildingQuantityv2 {
pub struct BuildingQuantityv2 {
#[key]
entity_id: u128,
#[key]
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/models/capacity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions contracts/src/models/combat.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -1221,18 +1221,18 @@ 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());
// print!("\n\n Duration in Seconds: {} \n\n", battle.duration_left);
// 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 /
Expand All @@ -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);

// }
// }
}
Loading
Loading