From ab4fde3d11cd20b09e1ec48ec80796646b7383aa Mon Sep 17 00:00:00 2001 From: Bal7hazar Date: Tue, 18 Jun 2024 13:00:29 +0200 Subject: [PATCH] Migration to dojo v0.7.1 (#76) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⬆️ bump dojo to v0.7.1 --- .github/workflows/ci.yml | 2 +- Scarb.lock | 6 ++--- Scarb.toml | 4 ++-- crates/src/algebra/vec2.cairo | 4 ++-- crates/src/defi/auction/gda.cairo | 6 +++-- crates/src/defi/auction/vrgda.cairo | 3 ++- crates/src/random/deck.cairo | 3 ++- crates/src/rating/elo.cairo | 3 ++- examples/chess/src/actions.cairo | 19 +++++++++++---- examples/hex_map/src/actions.cairo | 14 ++++++----- examples/hex_map/src/noise.cairo | 5 ++-- examples/market/src/models/market.cairo | 11 +++++---- examples/market/src/systems/liquidity.cairo | 8 +++---- examples/market/src/systems/trade.cairo | 8 +++---- examples/matchmaker/src/helpers/bitmap.cairo | 18 ++++++++++----- examples/projectile/src/lib.cairo | 6 ++--- .../src/systems/timelock/contract.cairo | 8 +++---- .../src/systems/timelock/interface.cairo | 23 +++++++++++++++---- 18 files changed, 97 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 069c2fed..5c0b46dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: Origami CI on: [push, pull_request] env: - DOJO_VERSION: v0.7.0-alpha.5 + DOJO_VERSION: v0.7.1 SCARB_VERSION: v2.6.4 jobs: diff --git a/Scarb.lock b/Scarb.lock index 51658815..8558e43e 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -15,8 +15,8 @@ source = "git+https://github.com/notV4l/cubit.git?branch=cairo_2.7#cadb27aa62509 [[package]] name = "dojo" -version = "0.6.0" -source = "git+https://github.com/dojoengine/dojo?tag=v0.7.0-alpha.5#328004d65bbbf7692c26f030b75fa95b7947841d" +version = "0.7.1" +source = "git+https://github.com/dojoengine/dojo?tag=v0.7.1#c4a1feadf1d5c5ecf9593b50c1a2ca2856ae2313" dependencies = [ "dojo_plugin", ] @@ -60,7 +60,7 @@ dependencies = [ [[package]] name = "origami" -version = "0.7.0-alpha.5" +version = "0.7.0" dependencies = [ "cubit", "dojo", diff --git a/Scarb.toml b/Scarb.toml index 29ad1fa1..50f19933 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -11,7 +11,7 @@ members = [ ] [workspace.package] -version = "0.7.0-alpha.5" +version = "0.7.1" description = "Community-maintained libraries for Cairo" homepage = "https://github.com/dojoengine/origami" authors = ["bal7hazar@proton.me"] @@ -19,6 +19,6 @@ authors = ["bal7hazar@proton.me"] [workspace.dependencies] # cubit = { git = "https://github.com/influenceth/cubit.git" } cubit = { git = "https://github.com/notV4l/cubit.git", branch = "cairo_2.7" } -dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.0-alpha.5" } +dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.1" } origami = { path = "crates" } token = { path = "token" } diff --git a/crates/src/algebra/vec2.cairo b/crates/src/algebra/vec2.cairo index e4553cd0..306d2724 100644 --- a/crates/src/algebra/vec2.cairo +++ b/crates/src/algebra/vec2.cairo @@ -40,7 +40,7 @@ impl Vec2Impl, impl TDrop: Drop> of Vec2Trait { // Masks - /// Creates a vector from the elements in `if_true` and `if_false`, + /// Creates a vector from the elements in `if_true` and `if_false`, /// selecting which to use for each element of `self`. /// /// A true element in the mask uses the corresponding element from @@ -63,7 +63,7 @@ impl Vec2Impl, impl TDrop: Drop> of Vec2Trait { // Math - /// Computes the dot product of `self` and `rhs` . + /// Computes the dot product of `self` and `rhs` . // #[inline(always)] is not allowed for functions with impl generic parameters. fn dot, impl TAdd: Add>(self: Vec2, rhs: Vec2) -> T { (self.x * rhs.x) + (self.y * rhs.y) diff --git a/crates/src/defi/auction/gda.cairo b/crates/src/defi/auction/gda.cairo index 4d771490..d86ece3f 100644 --- a/crates/src/defi/auction/gda.cairo +++ b/crates/src/defi/auction/gda.cairo @@ -91,7 +91,8 @@ mod tests { use super::{assert_approx_equal, TOLERANCE}; use super::super::{ContinuousGDA, ContinuousGDATrait}; - // ipynb with calculations at https://colab.research.google.com/drive/14elIFRXdG3_gyiI43tP47lUC_aClDHfB?usp=sharing + // ipynb with calculations at + // https://colab.research.google.com/drive/14elIFRXdG3_gyiI43tP47lUC_aClDHfB?usp=sharing #[test] fn test_price_1() { let auction = ContinuousGDA { @@ -175,7 +176,8 @@ mod tests { assert_approx_equal(price, auction.initial_price, TOLERANCE) } - // ipynb with calculations at https://colab.research.google.com/drive/14elIFRXdG3_gyiI43tP47lUC_aClDHfB?usp=sharing + // ipynb with calculations at + // https://colab.research.google.com/drive/14elIFRXdG3_gyiI43tP47lUC_aClDHfB?usp=sharing #[test] fn test_price_1() { let auction = DiscreteGDA { diff --git a/crates/src/defi/auction/vrgda.cairo b/crates/src/defi/auction/vrgda.cairo index b5a50ca5..31b6b623 100644 --- a/crates/src/defi/auction/vrgda.cairo +++ b/crates/src/defi/auction/vrgda.cairo @@ -25,7 +25,8 @@ impl TVRGDATrait, +VRGDATargetTimeTrait> of VRGDATrait< /// # Arguments /// /// * `time_since_start`: Time since the auction started. - /// * `sold`: Quantity sold. (Not including this unit) eg if this the price for the first unit sold is 0. + /// * `sold`: Quantity sold. (Not including this unit) eg if this the price for the first unit + /// sold is 0. /// /// # Returns /// diff --git a/crates/src/random/deck.cairo b/crates/src/random/deck.cairo index 5d6f3a14..52dfa3aa 100644 --- a/crates/src/random/deck.cairo +++ b/crates/src/random/deck.cairo @@ -42,7 +42,8 @@ trait DeckTrait { /// # Arguments /// * `seed` - A seed to initialize the deck. /// * `number` - The initial number of cards (must be below u128). - /// * `bitmap` - The bitmap, each bit is a card with: 0/1 is in/out (so a null bitmap will create a `new` deck). + /// * `bitmap` - The bitmap, each bit is a card with: 0/1 is in/out (so a null bitmap will + /// create a `new` deck). /// # Returns /// * The initialized `Deck`. fn from_bitmap(seed: felt252, number: u32, bitmap: u128) -> Deck; diff --git a/crates/src/rating/elo.cairo b/crates/src/rating/elo.cairo index 7182a83d..814d1bbf 100644 --- a/crates/src/rating/elo.cairo +++ b/crates/src/rating/elo.cairo @@ -25,7 +25,8 @@ impl EloImpl of EloTrait { /// * `rating_a` - The ELO rating of the player A. /// * `rating_b` - The ELO rating of the player B. /// * `score` - The score of the player A, scaled by 100. 100 = win, 50 = draw, 0 = loss. - /// * `k` - The k-factor or development multiplier used to calculate the change in ELO rating. 20 is the typical value. + /// * `k` - The k-factor or development multiplier used to calculate the change in ELO rating. + /// 20 is the typical value. /// # Returns /// * `change` - The change in ELO rating of player A. /// * `negative` - The directional change of player A's ELO. Opposite sign for player B. diff --git a/examples/chess/src/actions.cairo b/examples/chess/src/actions.cairo index 0bbe5e90..47928e1d 100644 --- a/examples/chess/src/actions.cairo +++ b/examples/chess/src/actions.cairo @@ -1,9 +1,18 @@ use starknet::ContractAddress; use chess::models::piece::Vec2; + #[dojo::interface] trait IActions { - fn move(curr_position: Vec2, next_position: Vec2, caller: ContractAddress, game_id: u32); - fn spawn(white_address: ContractAddress, black_address: ContractAddress) -> u32; + fn move( + ref world: IWorldDispatcher, + curr_position: Vec2, + next_position: Vec2, + caller: ContractAddress, + game_id: u32 + ); + fn spawn( + ref world: IWorldDispatcher, white_address: ContractAddress, black_address: ContractAddress + ) -> u32; } #[dojo::contract] @@ -16,7 +25,9 @@ mod actions { #[abi(embed_v0)] impl IActionsImpl of IActions { fn spawn( - world: IWorldDispatcher, white_address: ContractAddress, black_address: ContractAddress + ref world: IWorldDispatcher, + white_address: ContractAddress, + black_address: ContractAddress ) -> u32 { let game_id = world.uuid(); @@ -111,7 +122,7 @@ mod actions { game_id } fn move( - world: IWorldDispatcher, + ref world: IWorldDispatcher, curr_position: Vec2, next_position: Vec2, caller: ContractAddress, diff --git a/examples/hex_map/src/actions.cairo b/examples/hex_map/src/actions.cairo index 202af13d..979c1643 100644 --- a/examples/hex_map/src/actions.cairo +++ b/examples/hex_map/src/actions.cairo @@ -6,13 +6,15 @@ use hex_map::models::Position; // define the interface #[dojo::interface] trait IActions { - fn spawn(); - fn move(direction: Direction); + fn spawn(ref world: IWorldDispatcher); + fn move(ref world: IWorldDispatcher, direction: Direction); } #[dojo::interface] trait IActionsComputed { - fn next_position(position: Position, direction: Direction) -> Position; + fn next_position( + world: @IWorldDispatcher, position: Position, direction: Direction + ) -> Position; } // dojo decorator @@ -65,13 +67,13 @@ mod actions { #[abi(embed_v0)] impl ActionsImpl of IActions { // ContractState is defined by system decorator expansion - fn spawn() { // Access the world dispatcher for reading. + fn spawn(ref world: IWorldDispatcher) { // Access the world dispatcher for reading. let world = self.world_dispatcher.read(); set!(world, (Position { player: get_caller_address(), vec: Vec2 { x: 10, y: 10 } })); } // Moves player in the provided direction. - fn move(direction: Direction) { + fn move(ref world: IWorldDispatcher, direction: Direction) { // Access the world dispatcher for reading. let world = self.world_dispatcher.read(); @@ -115,7 +117,7 @@ mod tests { let mut models = array![position::TEST_CLASS_HASH]; // deploy world with models - let world = spawn_test_world(models); + let world: IWorldDispatcher = spawn_test_world(models); // deploy systems contract let contract_address = world diff --git a/examples/hex_map/src/noise.cairo b/examples/hex_map/src/noise.cairo index 91a7d671..c3b2dc58 100644 --- a/examples/hex_map/src/noise.cairo +++ b/examples/hex_map/src/noise.cairo @@ -1,6 +1,7 @@ // // -// Unique buisness logic of your world. It imports both the hex from origami and the simplex from cubit +// Unique buisness logic of your world. It imports both the hex from origami and the simplex from +// cubit // // @@ -59,7 +60,7 @@ mod tests { #[test] fn test_gradient() { - // seems inconsistent + // seems inconsistent let mut i = 5; diff --git a/examples/market/src/models/market.cairo b/examples/market/src/models/market.cairo index 90111729..26712ce0 100644 --- a/examples/market/src/models/market.cairo +++ b/examples/market/src/models/market.cairo @@ -148,7 +148,8 @@ impl MarketImpl of MarketTrait { // // Returns: // - // (amount, quantity, shares): The amount of cash and quantity of items added to the market and the shares minted + // (amount, quantity, shares): The amount of cash and quantity of items added to the market and + // the shares minted fn add_liquidity(self: @Market, amount: u128, quantity: u128) -> (u128, u128, Fixed) { // Compute the amount and quantity to add to the market let (amount, quantity) = self.add_liquidity_inner(amount, quantity); @@ -300,7 +301,7 @@ mod tests { let (amount, quantity) = (SCALING_FACTOR * 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'); @@ -343,7 +344,8 @@ mod tests { let _expected_liquidity = FixedTrait::sqrt(expected_amount * expected_quantity); let _final_liquidity = initial_liquidity + liquidity_add; - // assert_precise(expected_liquidity, final_liquidity.into(), 'wrong liquidity', Option::None(())); + // assert_precise(expected_liquidity, final_liquidity.into(), 'wrong liquidity', + // Option::None(())); } #[test] @@ -385,7 +387,8 @@ mod tests { let _expected_liquidity = FixedTrait::sqrt(expected_amount * expected_quantity); let _final_liquidity = initial_liquidity - liquidity_remove; - // assert_precise(expected_liquidity, final_liquidity.into(), 'wrong liquidity', Option::None(())); + // assert_precise(expected_liquidity, final_liquidity.into(), 'wrong liquidity', + // Option::None(())); } #[test] diff --git a/examples/market/src/systems/liquidity.cairo b/examples/market/src/systems/liquidity.cairo index 1ff4f910..e3bd9f82 100644 --- a/examples/market/src/systems/liquidity.cairo +++ b/examples/market/src/systems/liquidity.cairo @@ -8,8 +8,8 @@ use cubit::f128::types::fixed::Fixed; #[dojo::interface] trait ILiquidity { - fn add(item_id: u32, amount: u128, quantity: u128); - fn remove(item_id: u32, shares: Fixed); + fn add(ref world: IWorldDispatcher, item_id: u32, amount: u128, quantity: u128); + fn remove(ref world: IWorldDispatcher, item_id: u32, shares: Fixed); } #[dojo::contract] @@ -27,7 +27,7 @@ mod Liquidity { #[abi(embed_v0)] impl LiquidityImpl of ILiquidity { - fn add(world: IWorldDispatcher, item_id: u32, amount: u128, quantity: u128) { + fn add(ref world: IWorldDispatcher, item_id: u32, amount: u128, quantity: u128) { let player = starknet::get_caller_address(); let item = get!(world, (player, item_id), Item); @@ -75,7 +75,7 @@ mod Liquidity { } - fn remove(world: IWorldDispatcher, item_id: u32, shares: Fixed) { + fn remove(ref world: IWorldDispatcher, item_id: u32, shares: Fixed) { let player = starknet::get_caller_address(); let player_liquidity = get!(world, (player, item_id), Liquidity); diff --git a/examples/market/src/systems/trade.cairo b/examples/market/src/systems/trade.cairo index 77554e16..0cb401c0 100644 --- a/examples/market/src/systems/trade.cairo +++ b/examples/market/src/systems/trade.cairo @@ -4,8 +4,8 @@ use dojo::world::IWorldDispatcher; #[dojo::interface] trait ITrade { - fn buy(item_id: u32, quantity: u128); - fn sell(item_id: u32, quantity: u128); + fn buy(ref world: IWorldDispatcher, item_id: u32, quantity: u128); + fn sell(ref world: IWorldDispatcher, item_id: u32, quantity: u128); } #[dojo::contract] @@ -20,7 +20,7 @@ mod Trade { #[abi(embed_v0)] impl TradeImpl of ITrade { - fn buy(world: IWorldDispatcher, item_id: u32, quantity: u128) { + fn buy(ref world: IWorldDispatcher, item_id: u32, quantity: u128) { let player = starknet::get_caller_address(); let player_cash = get!(world, (player), Cash); @@ -52,7 +52,7 @@ mod Trade { } - fn sell(world: IWorldDispatcher, item_id: u32, quantity: u128) { + fn sell(ref world: IWorldDispatcher, item_id: u32, quantity: u128) { let player = starknet::get_caller_address(); let item = get!(world, (player, item_id), Item); diff --git a/examples/matchmaker/src/helpers/bitmap.cairo b/examples/matchmaker/src/helpers/bitmap.cairo index 6ae61276..d8a14cfa 100644 --- a/examples/matchmaker/src/helpers/bitmap.cairo +++ b/examples/matchmaker/src/helpers/bitmap.cairo @@ -60,9 +60,12 @@ impl Bitmap of BitmapTrait { /// The index of the most significant bit of the number, /// where the least significant bit is at index 0 and the most significant bit is at index 255 - /// Source: https://github.com/lambdaclass/yet-another-swap/blob/main/crates/yas_core/src/libraries/bit_math.cairo - /// # Arguments - /// * `x` - The value for which to compute the most significant bit, must be greater than 0. + /// Source: + /// + /// + /// https://github.com/lambdaclass/yet-another-swap/blob/main/crates/yas_core/src/libraries/bit_math.cairo + /// # Arguments * `x` - The value for which to compute the most significant bit, must be greater + /// than 0. /// # Returns /// * The index of the most significant bit #[inline(always)] @@ -108,9 +111,12 @@ impl Bitmap of BitmapTrait { /// The index of the least significant bit of the number, /// where the least significant bit is at index 0 and the most significant bit is at index 255 - /// Source: https://github.com/lambdaclass/yet-another-swap/blob/main/crates/yas_core/src/libraries/bit_math.cairo - /// # Arguments - /// * `x` - The value for which to compute the least significant bit, must be greater than 0. + /// Source: + /// + /// + /// https://github.com/lambdaclass/yet-another-swap/blob/main/crates/yas_core/src/libraries/bit_math.cairo + /// # Arguments * `x` - The value for which to compute the least significant bit, must be + /// greater than 0. /// # Returns /// * The index of the least significant bit #[inline(always)] diff --git a/examples/projectile/src/lib.cairo b/examples/projectile/src/lib.cairo index 5ae37de5..9d1ead25 100644 --- a/examples/projectile/src/lib.cairo +++ b/examples/projectile/src/lib.cairo @@ -12,8 +12,8 @@ fn main() -> (usize, Array::, Array::) { // v_0_mag_felt: felt252, theta_0_deg_felt: felt252, x_0_felt: felt252, y_0_felt: felt252 // - // Projectile parameters - // + // Projectile parameters + // /// Inputs: to be contract inputs for view function `main` /// Launch velocity magnitude, 0 <= v_0_felt <= 100 let v_0_mag_felt = 100; @@ -43,7 +43,7 @@ fn main() -> (usize, Array::, Array::) { assert(v_0_mag.mag <= 100 * ONE_u128, 'need v_0_mag_felt <= 100'); assert(v_0_mag.mag > 0 * ONE_u128, 'need v_0_mag_felt > 0'); assert(v_0_mag.sign == false, 'need v_0_mag_felt > 0'); - // `theta_0_deg.mag` not exact after conversion, so use 180.0000001 + // `theta_0_deg.mag` not exact after conversion, so use 180.0000001 assert(theta_0_deg.mag <= 180000001 * ONE_u128 / 1000000, '-180 <= theta_0_deg_felt <= 180'); assert(x_0 <= x_max, 'need x_0 <= x_max'); assert(x_0 >= x_min, 'need x_0 >= x_min'); diff --git a/governance/src/systems/timelock/contract.cairo b/governance/src/systems/timelock/contract.cairo index a62dc385..19b878ef 100644 --- a/governance/src/systems/timelock/contract.cairo +++ b/governance/src/systems/timelock/contract.cairo @@ -16,7 +16,7 @@ mod timelock { #[abi(embed_v0)] impl TimelockImpl of ITimelock { - fn initialize(admin: ContractAddress, delay: u64) { + fn initialize(ref world: IWorldDispatcher, admin: ContractAddress, delay: u64) { assert!(!admin.is_zero(), "Timelock::initialize: Admin address cannot be zero."); assert!( delay >= MINIMUM_DELAY, "Timelock::initialize: Delay must exceed minimum delay." @@ -39,7 +39,7 @@ mod timelock { } fn execute_transaction( - world: IWorldDispatcher, + ref world: IWorldDispatcher, target: ContractAddress, new_implementation: ClassHash, eta: u64 @@ -76,7 +76,7 @@ mod timelock { } fn que_transaction( - world: IWorldDispatcher, + ref world: IWorldDispatcher, target: ContractAddress, new_implementation: ClassHash, eta: u64 @@ -103,7 +103,7 @@ mod timelock { } fn cancel_transaction( - world: IWorldDispatcher, + ref world: IWorldDispatcher, target: ContractAddress, new_implementation: ClassHash, eta: u64 diff --git a/governance/src/systems/timelock/interface.cairo b/governance/src/systems/timelock/interface.cairo index ca345061..880eeb42 100644 --- a/governance/src/systems/timelock/interface.cairo +++ b/governance/src/systems/timelock/interface.cairo @@ -2,8 +2,23 @@ use starknet::{ContractAddress, ClassHash}; #[dojo::interface] trait ITimelock { - fn initialize(admin: ContractAddress, delay: u64); - fn execute_transaction(target: ContractAddress, new_implementation: ClassHash, eta: u64); - fn que_transaction(target: ContractAddress, new_implementation: ClassHash, eta: u64); - fn cancel_transaction(target: ContractAddress, new_implementation: ClassHash, eta: u64); + fn initialize(ref world: IWorldDispatcher, admin: ContractAddress, delay: u64); + fn execute_transaction( + ref world: IWorldDispatcher, + target: ContractAddress, + new_implementation: ClassHash, + eta: u64 + ); + fn que_transaction( + ref world: IWorldDispatcher, + target: ContractAddress, + new_implementation: ClassHash, + eta: u64 + ); + fn cancel_transaction( + ref world: IWorldDispatcher, + target: ContractAddress, + new_implementation: ClassHash, + eta: u64 + ); }