Skip to content

Commit

Permalink
Update 0.7.0 alpha.4 (dojoengine#66)
Browse files Browse the repository at this point in the history
* replace Model with #[dojo::model]
* use selector! for grant_writer
  • Loading branch information
notV4l authored May 24, 2024
1 parent 8253b43 commit 274faaf
Show file tree
Hide file tree
Showing 27 changed files with 98 additions and 56 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.2
DOJO_VERSION: v0.7.0-alpha.4
SCARB_VERSION: v2.6.4

jobs:
Expand Down
4 changes: 2 additions & 2 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source = "git+https://github.com/influenceth/cubit.git?rev=8eacc2b#8eacc2b1d952d
[[package]]
name = "dojo"
version = "0.6.0"
source = "git+https://github.com/dojoengine/dojo?tag=v0.7.0-alpha.2#f648e870fc48d004e770559ab61a3a8537e4624c"
source = "git+https://github.com/dojoengine/dojo?tag=v0.7.0-alpha.4#aa5b534ebc4d82c18c6334ae7f3d236e77313c90"
dependencies = [
"dojo_plugin",
]
Expand Down Expand Up @@ -53,7 +53,7 @@ dependencies = [

[[package]]
name = "origami"
version = "0.6.0"
version = "0.7.0-alpha.2"
dependencies = [
"cubit",
"dojo",
Expand Down
2 changes: 1 addition & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ authors = ["[email protected]"]

[workspace.dependencies]
cubit = { git = "https://github.com/influenceth/cubit.git", rev = "8eacc2b" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.0-alpha.2" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.0-alpha.4" }
origami = { path = "crates" }
token = { path = "token" }
10 changes: 5 additions & 5 deletions examples/bridge/sn/src/tests/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ fn setup() -> (IWorldDispatcher, IDojoTokenDispatcher, IDojoBridgeDispatcher) {
};

// setup auth for dojo_token
world.grant_writer('ERC20AllowanceModel', dojo_token_dispatcher.contract_address);
world.grant_writer('ERC20BalanceModel', dojo_token_dispatcher.contract_address);
world.grant_writer('ERC20MetadataModel', dojo_token_dispatcher.contract_address);
world.grant_writer('ERC20BridgeableModel', dojo_token_dispatcher.contract_address);
world.grant_writer(selector!("ERC20AllowanceModel"), dojo_token_dispatcher.contract_address);
world.grant_writer(selector!("ERC20BalanceModel"), dojo_token_dispatcher.contract_address);
world.grant_writer(selector!("ERC20MetadataModel"), dojo_token_dispatcher.contract_address);
world.grant_writer(selector!("ERC20BridgeableModel"), dojo_token_dispatcher.contract_address);

// setup auth for dojo_bridge
world.grant_writer('DojoBridgeModel', dojo_bridge_dispatcher.contract_address);
world.grant_writer(selector!("DojoBridgeModel"), dojo_bridge_dispatcher.contract_address);


// initialize dojo_token
Expand Down
6 changes: 4 additions & 2 deletions examples/chess/src/models/game.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use chess::models::player::Color;
use starknet::ContractAddress;

#[derive(Model, Drop, Serde)]
#[dojo::model]
#[derive(Drop, Serde)]
struct Game {
#[key]
game_id: u32,
Expand All @@ -10,7 +11,8 @@ struct Game {
black: ContractAddress
}

#[derive(Model, Drop, Serde)]
#[dojo::model]
#[derive(Drop, Serde)]
struct GameTurn {
#[key]
game_id: u32,
Expand Down
3 changes: 2 additions & 1 deletion examples/chess/src/models/piece.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use chess::models::player::Color;
use starknet::ContractAddress;

#[derive(Model, Drop, Serde)]
#[dojo::model]
#[derive(Drop, Serde)]
struct Piece {
#[key]
game_id: u32,
Expand Down
3 changes: 2 additions & 1 deletion examples/chess/src/models/player.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ enum Color {
None,
}

#[derive(Model, Drop, Serde)]
#[dojo::model]
#[derive(Drop, Serde)]
struct Player {
#[key]
game_id: u32,
Expand Down
3 changes: 2 additions & 1 deletion examples/hex_map/src/models.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ struct Vec2 {
y: u32
}

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct Position {
#[key]
player: ContractAddress,
Expand Down
3 changes: 2 additions & 1 deletion examples/market/src/models/cash.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct Cash {
#[key]
player: ContractAddress,
Expand Down
3 changes: 2 additions & 1 deletion examples/market/src/models/item.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct Item {
#[key]
player: ContractAddress,
Expand Down
23 changes: 10 additions & 13 deletions examples/market/src/models/liquidity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use starknet::ContractAddress;

// Dojo imports

use dojo::database::introspect::{Struct, Ty, Introspect, Member, serialize_member};
use dojo::database::introspect::{Struct, Ty, Introspect, Member, Layout};

// External imports

Expand All @@ -16,14 +16,13 @@ const SCALING_FACTOR: u128 = 10000;

impl IntrospectFixed of Introspect<Fixed> {
#[inline(always)]
fn size() -> usize {
2
fn size() -> Option<usize> {
Option::Some(2)
}

#[inline(always)]
fn layout(ref layout: Array<u8>) {
layout.append(128);
layout.append(1);
fn layout() -> Layout {
Layout::Fixed(array![128, 1].span())
}

#[inline(always)]
Expand All @@ -33,20 +32,18 @@ impl IntrospectFixed of Introspect<Fixed> {
name: 'Fixed',
attrs: array![].span(),
children: array![
serialize_member(
@Member { name: 'mag', ty: Ty::Primitive('u128'), attrs: array![].span() }
),
serialize_member(
@Member { name: 'sign', ty: Ty::Primitive('bool'), attrs: array![].span() }
)
Member { name: 'mag', attrs: array![].span(), ty: Ty::Primitive('u128') },
Member { name: 'sign', attrs: array![].span(), ty: Ty::Primitive('bool') },
]
.span()
}
)
}
}

#[derive(Model, Copy, Drop, Serde)]

#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct Liquidity {
#[key]
player: ContractAddress,
Expand Down
3 changes: 2 additions & 1 deletion examples/market/src/models/market.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use cubit::f128::types::fixed::{Fixed, FixedTrait};

const SCALING_FACTOR: u128 = 10000;

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct Market {
#[key]
item_id: u32,
Expand Down
3 changes: 2 additions & 1 deletion examples/matchmaker/src/models/league.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ mod errors {
const LEAGUE_NOT_SUBSCRIBED: felt252 = 'League: player not subscribed';
}

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct League {
#[key]
registry_id: u32,
Expand Down
3 changes: 2 additions & 1 deletion examples/matchmaker/src/models/player.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ mod errors {
const PLAYER_NOT_SUBSCRIBED: felt252 = 'Player: not subscribed';
}

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct Player {
#[key]
registry_id: u32,
Expand Down
3 changes: 2 additions & 1 deletion examples/matchmaker/src/models/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ mod errors {
const REGISTRY_LEAGUE_NOT_FOUND: felt252 = 'Registry: league not found';
}

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct Registry {
#[key]
id: u32,
Expand Down
3 changes: 2 additions & 1 deletion examples/matchmaker/src/models/slot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use starknet::ContractAddress;
use matchmaker::constants::ZERO;
use matchmaker::models::player::{Player, PlayerTrait};

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct Slot {
#[key]
registry_id: u32,
Expand Down
3 changes: 2 additions & 1 deletion token/src/components/introspection/src5.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const ISRC5_ID: felt252 = 0x3f918d17e5ee77373b56385708f855659a07f75997f365cf8774
/// Model
///

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct SRC5Model {
#[key]
token: ContractAddress,
Expand Down
3 changes: 2 additions & 1 deletion token/src/components/security/initializable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use starknet::ContractAddress;
/// Model
///

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct InitializableModel {
#[key]
token: ContractAddress,
Expand Down
10 changes: 8 additions & 2 deletions token/src/components/tests/token/erc20/test_erc20_balance.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ fn setup() -> (IWorldDispatcher, IERC20BalanceMockDispatcher) {
};

// setup auth
world.grant_writer('ERC20AllowanceModel', erc20_balance_mock_dispatcher.contract_address);
world.grant_writer('ERC20BalanceModel', erc20_balance_mock_dispatcher.contract_address);
world
.grant_writer(
selector!("ERC20AllowanceModel"), erc20_balance_mock_dispatcher.contract_address
);
world
.grant_writer(
selector!("ERC20BalanceModel"), erc20_balance_mock_dispatcher.contract_address
);

// initialize contracts
erc20_balance_mock_dispatcher.initializer(SUPPLY, OWNER());
Expand Down
3 changes: 2 additions & 1 deletion token/src/components/token/erc20/erc20_allowance.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use starknet::ContractAddress;
/// Model
///

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC20AllowanceModel {
#[key]
token: ContractAddress,
Expand Down
3 changes: 2 additions & 1 deletion token/src/components/token/erc20/erc20_balance.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use starknet::ContractAddress;
/// Model
///

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC20BalanceModel {
#[key]
token: ContractAddress,
Expand Down
3 changes: 2 additions & 1 deletion token/src/components/token/erc20/erc20_bridgeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use starknet::ContractAddress;
/// Model
///

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC20BridgeableModel {
#[key]
token: ContractAddress,
Expand Down
3 changes: 2 additions & 1 deletion token/src/components/token/erc20/erc20_metadata.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use starknet::ContractAddress;
/// Model
///

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC20MetadataModel {
#[key]
token: ContractAddress,
Expand Down
9 changes: 6 additions & 3 deletions token/src/erc1155/models.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC1155Meta {
#[key]
token: ContractAddress,
Expand All @@ -11,7 +12,8 @@ struct ERC1155Meta {
base_uri: felt252,
}

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC1155OperatorApproval {
#[key]
token: ContractAddress,
Expand All @@ -23,7 +25,8 @@ struct ERC1155OperatorApproval {
}


#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC1155Balance {
#[key]
token: ContractAddress,
Expand Down
9 changes: 6 additions & 3 deletions token/src/erc20/models.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC20Balance {
#[key]
token: ContractAddress,
Expand All @@ -11,7 +12,8 @@ struct ERC20Balance {
amount: u256,
}

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC20Allowance {
#[key]
token: ContractAddress,
Expand All @@ -22,7 +24,8 @@ struct ERC20Allowance {
amount: u256,
}

#[derive(Model, Copy, Drop, Serde)]
#[dojo::model]
#[derive(Copy, Drop, Serde)]
struct ERC20Meta {
#[key]
token: ContractAddress,
Expand Down
Loading

0 comments on commit 274faaf

Please sign in to comment.