From 274faaf7661f4d1ebfc571da0fa827a244285073 Mon Sep 17 00:00:00 2001 From: notV4l <122404722+notV4l@users.noreply.github.com> Date: Fri, 24 May 2024 14:56:47 +0200 Subject: [PATCH] Update 0.7.0 alpha.4 (#66) * replace Model with #[dojo::model] * use selector! for grant_writer --- .github/workflows/ci.yml | 2 +- Scarb.lock | 4 ++-- Scarb.toml | 2 +- examples/bridge/sn/src/tests/tests.cairo | 10 ++++---- examples/chess/src/models/game.cairo | 6 +++-- examples/chess/src/models/piece.cairo | 3 ++- examples/chess/src/models/player.cairo | 3 ++- examples/hex_map/src/models.cairo | 3 ++- examples/market/src/models/cash.cairo | 3 ++- examples/market/src/models/item.cairo | 3 ++- examples/market/src/models/liquidity.cairo | 23 ++++++++----------- examples/market/src/models/market.cairo | 3 ++- examples/matchmaker/src/models/league.cairo | 3 ++- examples/matchmaker/src/models/player.cairo | 3 ++- examples/matchmaker/src/models/registry.cairo | 3 ++- examples/matchmaker/src/models/slot.cairo | 3 ++- token/src/components/introspection/src5.cairo | 3 ++- .../components/security/initializable.cairo | 3 ++- .../token/erc20/test_erc20_balance.cairo | 10 ++++++-- .../token/erc20/erc20_allowance.cairo | 3 ++- .../token/erc20/erc20_balance.cairo | 3 ++- .../token/erc20/erc20_bridgeable.cairo | 3 ++- .../token/erc20/erc20_metadata.cairo | 3 ++- token/src/erc1155/models.cairo | 9 +++++--- token/src/erc20/models.cairo | 9 +++++--- token/src/erc721/models.cairo | 13 +++++++---- .../src/presets/erc20/tests_bridgeable.cairo | 18 +++++++++++---- 27 files changed, 98 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea0c43f6..9f2948d1 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.2 + DOJO_VERSION: v0.7.0-alpha.4 SCARB_VERSION: v2.6.4 jobs: diff --git a/Scarb.lock b/Scarb.lock index a5cfeb0f..cc8fe53f 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -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", ] @@ -53,7 +53,7 @@ dependencies = [ [[package]] name = "origami" -version = "0.6.0" +version = "0.7.0-alpha.2" dependencies = [ "cubit", "dojo", diff --git a/Scarb.toml b/Scarb.toml index e9c3bebd..da352dd0 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -17,6 +17,6 @@ authors = ["bal7hazar@proton.me"] [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" } diff --git a/examples/bridge/sn/src/tests/tests.cairo b/examples/bridge/sn/src/tests/tests.cairo index d6dbb855..537a3a64 100644 --- a/examples/bridge/sn/src/tests/tests.cairo +++ b/examples/bridge/sn/src/tests/tests.cairo @@ -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 diff --git a/examples/chess/src/models/game.cairo b/examples/chess/src/models/game.cairo index 36c06f5a..0c822a00 100644 --- a/examples/chess/src/models/game.cairo +++ b/examples/chess/src/models/game.cairo @@ -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, @@ -10,7 +11,8 @@ struct Game { black: ContractAddress } -#[derive(Model, Drop, Serde)] +#[dojo::model] +#[derive(Drop, Serde)] struct GameTurn { #[key] game_id: u32, diff --git a/examples/chess/src/models/piece.cairo b/examples/chess/src/models/piece.cairo index 7431e14b..29505e7f 100644 --- a/examples/chess/src/models/piece.cairo +++ b/examples/chess/src/models/piece.cairo @@ -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, diff --git a/examples/chess/src/models/player.cairo b/examples/chess/src/models/player.cairo index 4308db98..de9e74cd 100644 --- a/examples/chess/src/models/player.cairo +++ b/examples/chess/src/models/player.cairo @@ -7,7 +7,8 @@ enum Color { None, } -#[derive(Model, Drop, Serde)] +#[dojo::model] +#[derive(Drop, Serde)] struct Player { #[key] game_id: u32, diff --git a/examples/hex_map/src/models.cairo b/examples/hex_map/src/models.cairo index cc549b15..60216950 100644 --- a/examples/hex_map/src/models.cairo +++ b/examples/hex_map/src/models.cairo @@ -7,7 +7,8 @@ struct Vec2 { y: u32 } -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct Position { #[key] player: ContractAddress, diff --git a/examples/market/src/models/cash.cairo b/examples/market/src/models/cash.cairo index d447b317..d2fbb0ce 100644 --- a/examples/market/src/models/cash.cairo +++ b/examples/market/src/models/cash.cairo @@ -2,7 +2,8 @@ use starknet::ContractAddress; -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct Cash { #[key] player: ContractAddress, diff --git a/examples/market/src/models/item.cairo b/examples/market/src/models/item.cairo index 7e395443..7eaa94e6 100644 --- a/examples/market/src/models/item.cairo +++ b/examples/market/src/models/item.cairo @@ -2,7 +2,8 @@ use starknet::ContractAddress; -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct Item { #[key] player: ContractAddress, diff --git a/examples/market/src/models/liquidity.cairo b/examples/market/src/models/liquidity.cairo index 3bac3922..a9add069 100644 --- a/examples/market/src/models/liquidity.cairo +++ b/examples/market/src/models/liquidity.cairo @@ -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 @@ -16,14 +16,13 @@ const SCALING_FACTOR: u128 = 10000; impl IntrospectFixed of Introspect { #[inline(always)] - fn size() -> usize { - 2 + fn size() -> Option { + Option::Some(2) } #[inline(always)] - fn layout(ref layout: Array) { - layout.append(128); - layout.append(1); + fn layout() -> Layout { + Layout::Fixed(array![128, 1].span()) } #[inline(always)] @@ -33,12 +32,8 @@ impl IntrospectFixed of Introspect { 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() } @@ -46,7 +41,9 @@ impl IntrospectFixed of Introspect { } } -#[derive(Model, Copy, Drop, Serde)] + +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct Liquidity { #[key] player: ContractAddress, diff --git a/examples/market/src/models/market.cairo b/examples/market/src/models/market.cairo index 4db5fc98..90111729 100644 --- a/examples/market/src/models/market.cairo +++ b/examples/market/src/models/market.cairo @@ -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, diff --git a/examples/matchmaker/src/models/league.cairo b/examples/matchmaker/src/models/league.cairo index 28e6a2a0..61277647 100644 --- a/examples/matchmaker/src/models/league.cairo +++ b/examples/matchmaker/src/models/league.cairo @@ -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, diff --git a/examples/matchmaker/src/models/player.cairo b/examples/matchmaker/src/models/player.cairo index 69d7e826..e3b4e478 100644 --- a/examples/matchmaker/src/models/player.cairo +++ b/examples/matchmaker/src/models/player.cairo @@ -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, diff --git a/examples/matchmaker/src/models/registry.cairo b/examples/matchmaker/src/models/registry.cairo index 46544a3f..96d95b4e 100644 --- a/examples/matchmaker/src/models/registry.cairo +++ b/examples/matchmaker/src/models/registry.cairo @@ -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, diff --git a/examples/matchmaker/src/models/slot.cairo b/examples/matchmaker/src/models/slot.cairo index c36490b2..ac5018a1 100644 --- a/examples/matchmaker/src/models/slot.cairo +++ b/examples/matchmaker/src/models/slot.cairo @@ -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, diff --git a/token/src/components/introspection/src5.cairo b/token/src/components/introspection/src5.cairo index 1014fc3e..99527093 100644 --- a/token/src/components/introspection/src5.cairo +++ b/token/src/components/introspection/src5.cairo @@ -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, diff --git a/token/src/components/security/initializable.cairo b/token/src/components/security/initializable.cairo index 97498a58..370cf4a0 100644 --- a/token/src/components/security/initializable.cairo +++ b/token/src/components/security/initializable.cairo @@ -6,7 +6,8 @@ use starknet::ContractAddress; /// Model /// -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct InitializableModel { #[key] token: ContractAddress, diff --git a/token/src/components/tests/token/erc20/test_erc20_balance.cairo b/token/src/components/tests/token/erc20/test_erc20_balance.cairo index b3f86396..59b7907f 100644 --- a/token/src/components/tests/token/erc20/test_erc20_balance.cairo +++ b/token/src/components/tests/token/erc20/test_erc20_balance.cairo @@ -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()); diff --git a/token/src/components/token/erc20/erc20_allowance.cairo b/token/src/components/token/erc20/erc20_allowance.cairo index c179bd78..0d69115a 100644 --- a/token/src/components/token/erc20/erc20_allowance.cairo +++ b/token/src/components/token/erc20/erc20_allowance.cairo @@ -4,7 +4,8 @@ use starknet::ContractAddress; /// Model /// -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC20AllowanceModel { #[key] token: ContractAddress, diff --git a/token/src/components/token/erc20/erc20_balance.cairo b/token/src/components/token/erc20/erc20_balance.cairo index c20c200e..10adff56 100644 --- a/token/src/components/token/erc20/erc20_balance.cairo +++ b/token/src/components/token/erc20/erc20_balance.cairo @@ -4,7 +4,8 @@ use starknet::ContractAddress; /// Model /// -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC20BalanceModel { #[key] token: ContractAddress, diff --git a/token/src/components/token/erc20/erc20_bridgeable.cairo b/token/src/components/token/erc20/erc20_bridgeable.cairo index 101175d1..0029c0ed 100644 --- a/token/src/components/token/erc20/erc20_bridgeable.cairo +++ b/token/src/components/token/erc20/erc20_bridgeable.cairo @@ -4,7 +4,8 @@ use starknet::ContractAddress; /// Model /// -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC20BridgeableModel { #[key] token: ContractAddress, diff --git a/token/src/components/token/erc20/erc20_metadata.cairo b/token/src/components/token/erc20/erc20_metadata.cairo index 710deddd..3b91c5d1 100644 --- a/token/src/components/token/erc20/erc20_metadata.cairo +++ b/token/src/components/token/erc20/erc20_metadata.cairo @@ -4,7 +4,8 @@ use starknet::ContractAddress; /// Model /// -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC20MetadataModel { #[key] token: ContractAddress, diff --git a/token/src/erc1155/models.cairo b/token/src/erc1155/models.cairo index 65d8950d..b7e7debe 100644 --- a/token/src/erc1155/models.cairo +++ b/token/src/erc1155/models.cairo @@ -2,7 +2,8 @@ use starknet::ContractAddress; -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC1155Meta { #[key] token: ContractAddress, @@ -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, @@ -23,7 +25,8 @@ struct ERC1155OperatorApproval { } -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC1155Balance { #[key] token: ContractAddress, diff --git a/token/src/erc20/models.cairo b/token/src/erc20/models.cairo index 13612f0f..3f6ec162 100644 --- a/token/src/erc20/models.cairo +++ b/token/src/erc20/models.cairo @@ -2,7 +2,8 @@ use starknet::ContractAddress; -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC20Balance { #[key] token: ContractAddress, @@ -11,7 +12,8 @@ struct ERC20Balance { amount: u256, } -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC20Allowance { #[key] token: ContractAddress, @@ -22,7 +24,8 @@ struct ERC20Allowance { amount: u256, } -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC20Meta { #[key] token: ContractAddress, diff --git a/token/src/erc721/models.cairo b/token/src/erc721/models.cairo index 04f25c2f..aa44c64a 100644 --- a/token/src/erc721/models.cairo +++ b/token/src/erc721/models.cairo @@ -2,7 +2,8 @@ use starknet::ContractAddress; -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC721Meta { #[key] token: ContractAddress, @@ -11,7 +12,8 @@ struct ERC721Meta { base_uri: felt252, } -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC721OperatorApproval { #[key] token: ContractAddress, @@ -22,7 +24,8 @@ struct ERC721OperatorApproval { approved: bool } -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC721Owner { #[key] token: ContractAddress, @@ -31,6 +34,7 @@ struct ERC721Owner { address: ContractAddress } +#[dojo::model] #[derive(Model, Copy, Drop, Serde)] struct ERC721Balance { #[key] @@ -40,7 +44,8 @@ struct ERC721Balance { amount: u256, } -#[derive(Model, Copy, Drop, Serde)] +#[dojo::model] +#[derive(Copy, Drop, Serde)] struct ERC721TokenApproval { #[key] token: ContractAddress, diff --git a/token/src/presets/erc20/tests_bridgeable.cairo b/token/src/presets/erc20/tests_bridgeable.cairo index f61da081..477d34ca 100644 --- a/token/src/presets/erc20/tests_bridgeable.cairo +++ b/token/src/presets/erc20/tests_bridgeable.cairo @@ -74,10 +74,20 @@ fn setup() -> (IWorldDispatcher, IERC20BridgeablePresetDispatcher) { }; // setup auth - world.grant_writer('ERC20AllowanceModel', erc20_bridgeable_dispatcher.contract_address); - world.grant_writer('ERC20BalanceModel', erc20_bridgeable_dispatcher.contract_address); - world.grant_writer('ERC20MetadataModel', erc20_bridgeable_dispatcher.contract_address); - world.grant_writer('ERC20BridgeableModel', erc20_bridgeable_dispatcher.contract_address); + world + .grant_writer( + selector!("ERC20AllowanceModel"), erc20_bridgeable_dispatcher.contract_address + ); + world + .grant_writer(selector!("ERC20BalanceModel"), erc20_bridgeable_dispatcher.contract_address); + world + .grant_writer( + selector!("ERC20MetadataModel"), erc20_bridgeable_dispatcher.contract_address + ); + world + .grant_writer( + selector!("ERC20BridgeableModel"), erc20_bridgeable_dispatcher.contract_address + ); // initialize contracts erc20_bridgeable_dispatcher.initializer(NAME, SYMBOL, SUPPLY, OWNER(), BRIDGE());