Skip to content

Commit

Permalink
🚧 Partial migration
Browse files Browse the repository at this point in the history
  • Loading branch information
bal7hazar committed Jun 15, 2024
1 parent ded3282 commit 791d25b
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 32 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.0
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.0"
source = "git+https://github.com/dojoengine/dojo?tag=v0.7.0#34b13caa785c1149558d28f1a9d9fbd700c4aa2d"
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.0"
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.0" }
origami = { path = "crates" }
token = { path = "token" }
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
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
8 changes: 4 additions & 4 deletions governance/src/systems/timelock/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod timelock {

#[abi(embed_v0)]
impl TimelockImpl of ITimelock<ContractState> {
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."
Expand All @@ -39,7 +39,7 @@ mod timelock {
}

fn execute_transaction(
world: IWorldDispatcher,
ref world: IWorldDispatcher,
target: ContractAddress,
new_implementation: ClassHash,
eta: u64
Expand Down Expand Up @@ -76,7 +76,7 @@ mod timelock {
}

fn que_transaction(
world: IWorldDispatcher,
ref world: IWorldDispatcher,
target: ContractAddress,
new_implementation: ClassHash,
eta: u64
Expand All @@ -103,7 +103,7 @@ mod timelock {
}

fn cancel_transaction(
world: IWorldDispatcher,
ref world: IWorldDispatcher,
target: ContractAddress,
new_implementation: ClassHash,
eta: u64
Expand Down
23 changes: 19 additions & 4 deletions governance/src/systems/timelock/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

0 comments on commit 791d25b

Please sign in to comment.