Skip to content

Commit

Permalink
Migration to dojo v0.7.1 (#76)
Browse files Browse the repository at this point in the history
* ⬆️ bump dojo to v0.7.1
  • Loading branch information
bal7hazar authored Jun 18, 2024
1 parent ded3282 commit ab4fde3
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down Expand Up @@ -60,7 +60,7 @@ dependencies = [

[[package]]
name = "origami"
version = "0.7.0-alpha.5"
version = "0.7.0"
dependencies = [
"cubit",
"dojo",
Expand Down
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ 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 = ["[email protected]"]

[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" }
4 changes: 2 additions & 2 deletions crates/src/algebra/vec2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Vec2Impl<T, impl TCopy: Copy<T>, impl TDrop: Drop<T>> of Vec2Trait<T> {

// 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
Expand All @@ -63,7 +63,7 @@ impl Vec2Impl<T, impl TCopy: Copy<T>, impl TDrop: Drop<T>> of Vec2Trait<T> {

// 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 TMul: Mul<T>, impl TAdd: Add<T>>(self: Vec2<T>, rhs: Vec2<T>) -> T {
(self.x * rhs.x) + (self.y * rhs.y)
Expand Down
6 changes: 4 additions & 2 deletions crates/src/defi/auction/gda.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion crates/src/defi/auction/vrgda.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ impl TVRGDATrait<T, +VRGDAVarsTrait<T>, +VRGDATargetTimeTrait<T>> 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
///
Expand Down
3 changes: 2 additions & 1 deletion crates/src/random/deck.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion crates/src/rating/elo.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 15 additions & 4 deletions examples/chess/src/actions.cairo
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -16,7 +25,9 @@ mod actions {
#[abi(embed_v0)]
impl IActionsImpl of IActions<ContractState> {
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();

Expand Down Expand Up @@ -111,7 +122,7 @@ mod actions {
game_id
}
fn move(
world: IWorldDispatcher,
ref world: IWorldDispatcher,
curr_position: Vec2,
next_position: Vec2,
caller: ContractAddress,
Expand Down
14 changes: 8 additions & 6 deletions examples/hex_map/src/actions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,13 +67,13 @@ mod actions {
#[abi(embed_v0)]
impl ActionsImpl of IActions<ContractState> {
// 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();

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions examples/hex_map/src/noise.cairo
Original file line number Diff line number Diff line change
@@ -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
//
//

Expand Down Expand Up @@ -59,7 +60,7 @@ mod tests {

#[test]
fn test_gradient() {
// seems inconsistent
// seems inconsistent

let mut i = 5;

Expand Down
11 changes: 7 additions & 4 deletions examples/market/src/models/market.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions examples/market/src/systems/liquidity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -27,7 +27,7 @@ mod Liquidity {

#[abi(embed_v0)]
impl LiquidityImpl of ILiquidity<ContractState> {
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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions examples/market/src/systems/trade.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use dojo::world::IWorldDispatcher;

#[dojo::interface]
trait ITrade<TContractState> {
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]
Expand All @@ -20,7 +20,7 @@ mod Trade {

#[abi(embed_v0)]
impl TradeImpl of ITrade<ContractState> {
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);
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 12 additions & 6 deletions examples/matchmaker/src/helpers/bitmap.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions examples/projectile/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fn main() -> (usize, Array::<Fixed>, Array::<Fixed>) {
// 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;
Expand Down Expand Up @@ -43,7 +43,7 @@ fn main() -> (usize, Array::<Fixed>, Array::<Fixed>) {
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');
Expand Down
Loading

0 comments on commit ab4fde3

Please sign in to comment.