Skip to content

Commit

Permalink
chore: use get_world_config & scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Aug 30, 2023
1 parent 6346b29 commit 36bb533
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 56 deletions.
28 changes: 18 additions & 10 deletions src/attributes/attribute_group.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum AttributeGroupOwner {
}

#[derive(Component, Copy, Drop, Serde, SerdeLen)]
struct AttributeGroup {
struct AttributeGroup {
#[key]
attribute_group_id: u64,
owner: AttributeGroupOwner,
Expand All @@ -43,25 +43,25 @@ struct AttributeGroup {


trait AttributeGroupTrait {
fn get_attribute_group(world: IWorldDispatcher, attribute_group_id: u64) -> AttributeGroup ;
fn set_attribute_group(world: IWorldDispatcher, attribute_group: AttributeGroup );
fn get_attribute_group(world: IWorldDispatcher, attribute_group_id: u64) -> AttributeGroup;
fn set_attribute_group(world: IWorldDispatcher, attribute_group: AttributeGroup);
fn exists(world: IWorldDispatcher, attribute_group_id: u64) -> bool;

fn new_attribute_group(
world: IWorldDispatcher,
attribute_group_id: u64,
owner: AttributeGroupOwner,
briq_set_contract_address: ContractAddress
) -> AttributeGroup ;
) -> AttributeGroup;
}

// #[generate_trait]
impl AttributeGroupImpl of AttributeGroupTrait {
fn get_attribute_group(world: IWorldDispatcher, attribute_group_id: u64) -> AttributeGroup {
fn get_attribute_group(world: IWorldDispatcher, attribute_group_id: u64) -> AttributeGroup {
get!(world, (attribute_group_id), AttributeGroup)
}

fn set_attribute_group(world: IWorldDispatcher, attribute_group: AttributeGroup ) {
fn set_attribute_group(world: IWorldDispatcher, attribute_group: AttributeGroup) {
set!(world, (attribute_group));
}

Expand All @@ -75,11 +75,16 @@ impl AttributeGroupImpl of AttributeGroupTrait {
attribute_group_id: u64,
owner: AttributeGroupOwner,
briq_set_contract_address: ContractAddress
) -> AttributeGroup {
) -> AttributeGroup {
assert(attribute_group_id > 0, 'invalid attribute_group_id');
assert(!AttributeGroupTrait::exists(world, attribute_group_id), 'attribute_group already exists');
assert(
!AttributeGroupTrait::exists(world, attribute_group_id),
'attribute_group already exists'
);

AttributeGroup { attribute_group_id: attribute_group_id, owner: owner, briq_set_contract_address }
AttributeGroup {
attribute_group_id: attribute_group_id, owner: owner, briq_set_contract_address
}
}
}

Expand Down Expand Up @@ -148,7 +153,10 @@ mod create_attribute_group {

match owner {
AttributeGroupOwner::Admin(address) => {
emit!(ctx.world, AttributeGroupCreated { attribute_group_id, owner: address, system: '' });
emit!(
ctx.world,
AttributeGroupCreated { attribute_group_id, owner: address, system: '' }
);
},
AttributeGroupOwner::System(system_name) => {
emit!(
Expand Down
18 changes: 10 additions & 8 deletions src/attributes/attributes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ use briq_protocol::cumulative_balance::{CUM_BALANCE_TOKEN, CB_BRIQ, CB_ATTRIBUTE

use dojo::world::{Context, IWorldDispatcher, IWorldDispatcherTrait};
use dojo_erc::erc1155::components::ERC1155Balance;
use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig};
use briq_protocol::world_config::{WorldConfig};

use briq_protocol::attributes::get_attribute_group_id;
use briq_protocol::attributes::attribute_group::{AttributeGroup, AttributeGroupTrait, AttributeGroupOwner};
use briq_protocol::attributes::attribute_group::{
AttributeGroup, AttributeGroupTrait, AttributeGroupOwner
};

use debug::PrintTrait;

Expand Down Expand Up @@ -106,7 +108,9 @@ fn inner_attribute_assign(
assert(attribute_id != 0, 'Bad input');

let attribute_group_id = get_attribute_group_id(attribute_id);
let attribute_group = AttributeGroupTrait::get_attribute_group(ctx.world, attribute_group_id.try_into().unwrap());
let attribute_group = AttributeGroupTrait::get_attribute_group(
ctx.world, attribute_group_id.try_into().unwrap()
);

match attribute_group.owner {
AttributeGroupOwner::Admin(address) => {
Expand Down Expand Up @@ -167,7 +171,9 @@ fn remove_attribute_inner(
assert(attribute_id != 0, 'Bad input');

let attribute_group_id = get_attribute_group_id(attribute_id);
let attribute_group = AttributeGroupTrait::get_attribute_group(ctx.world, attribute_group_id.try_into().unwrap());
let attribute_group = AttributeGroupTrait::get_attribute_group(
ctx.world, attribute_group_id.try_into().unwrap()
);

match attribute_group.owner {
AttributeGroupOwner::Admin(address) => {
Expand All @@ -187,7 +193,3 @@ fn remove_attribute_inner(
emit!(ctx.world, AttributeRemoved { set_token_id: set_token_id.into(), attribute_id });
}





2 changes: 1 addition & 1 deletion src/box_nft/unboxing.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use starknet::ContractAddress;

use dojo::world::IWorldDispatcher;

use briq_protocol::world_config::{get_world_config, AdminTrait};
use briq_protocol::world_config::{get_world_config};

#[derive(Drop, Copy, Serde)]
struct BoxData {
Expand Down
7 changes: 4 additions & 3 deletions src/briq_factory/systems.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ mod BriqFactoryMint {
use zeroable::Zeroable;
use starknet::{ContractAddress, get_contract_address, get_caller_address, get_block_timestamp};

use briq_protocol::world_config::{AdminTrait, get_world_config};
use briq_protocol::world_config::{get_world_config};
use briq_protocol::felt_math::{FeltOrd};
use super::{
BriqsBought, BriqFactoryTrait, BriqFactoryBuyParams, DECIMALS, MIN_PURCHASE, BRIQ_MATERIAL
};
use briq_protocol::world_config::AdminTrait;


#[starknet::interface]
trait IERC20<TState> {
Expand Down Expand Up @@ -110,10 +112,9 @@ mod BriqFactoryInitialize {
use zeroable::Zeroable;
use starknet::ContractAddress;

use briq_protocol::world_config::AdminTrait;

use super::BriqFactoryInitializeParams;
use super::{BriqFactoryStore, BriqFactoryTrait};
use briq_protocol::world_config::AdminTrait;


fn execute(ctx: Context, params: BriqFactoryInitializeParams) {
Expand Down
6 changes: 3 additions & 3 deletions src/set_nft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ mod SetNft {
//

#[constructor]
fn constructor(ref self: ContractState, world: IWorldDispatcher, name:felt252, symbol:felt252) {
fn constructor(
ref self: ContractState, world: IWorldDispatcher, name: felt252, symbol: felt252
) {
self.world.write(world);
self.name_.write(name);
self.symbol_.write(symbol);
Expand Down Expand Up @@ -296,6 +298,4 @@ mod SetNft {
self.emit(event);
}
}


}
8 changes: 4 additions & 4 deletions src/set_nft/systems.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use debug::PrintTrait;
use dojo::world::Context;

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig, get_world_config};
use briq_protocol::world_config::{WorldConfig, get_world_config};
use briq_protocol::cumulative_balance::{CUM_BALANCE_TOKEN, CB_BRIQ, CB_ATTRIBUTES};

use dojo_erc::erc1155::components::OperatorApproval;
Expand Down Expand Up @@ -41,7 +41,7 @@ fn transfer_briqs(
if fts.len() == 0 {
return ();
}
let address = get!(world, (SYSTEM_CONFIG_ID), WorldConfig).briq;
let address = get_world_config(world).briq;
let ftspec = fts.pop_front().unwrap();

briq_protocol::briq_token::systems::update_nocheck(
Expand Down Expand Up @@ -127,7 +127,7 @@ mod set_nft_assembly {
use serde::Serde;

use dojo::world::Context;
use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig};
use briq_protocol::world_config::{WorldConfig};

use briq_protocol::types::{FTSpec, PackedShapeItem};

Expand Down Expand Up @@ -177,7 +177,7 @@ mod set_nft_disassembly {
use dojo::world::Context;
use dojo_erc::erc721::components::{ERC721Owner, ERC721TokenApproval};
use dojo_erc::erc1155::components::OperatorApproval;
use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig, get_world_config};
use briq_protocol::world_config::{WorldConfig, get_world_config};

use briq_protocol::types::{FTSpec, PackedShapeItem};

Expand Down
10 changes: 5 additions & 5 deletions src/shape_verifier.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::Serde;

use dojo::world::{Context, IWorldDispatcher, IWorldDispatcherTrait};
use dojo_erc::erc721::components::{ERC721Balance, ERC721Owner};
use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig};
use briq_protocol::world_config::{AdminTrait, WorldConfig, get_world_config};

use briq_protocol::types::{FTSpec, PackedShapeItem};

Expand Down Expand Up @@ -72,7 +72,7 @@ impl ShapeVerifierImpl of ShapeVerifierTrait {
// TODO -> use update that sends events
dojo_erc::erc1155::components::ERC1155BalanceTrait::transfer_tokens(
world,
get!(world, (SYSTEM_CONFIG_ID), WorldConfig).booklet,
get_world_config(world).booklet,
set_owner,
set_token_id.try_into().unwrap(),
array![attribute_id].span(),
Expand All @@ -90,7 +90,7 @@ impl ShapeVerifierImpl of ShapeVerifierTrait {
// TODO -> use update that sends events
dojo_erc::erc1155::components::ERC1155BalanceTrait::transfer_tokens(
world,
get!(world, (SYSTEM_CONFIG_ID), WorldConfig).booklet,
get_world_config(world).booklet,
set_token_id.try_into().unwrap(),
set_owner,
array![attribute_id].span(),
Expand All @@ -111,7 +111,7 @@ mod register_shape_verifier {
use super::RegisterShapeVerifierData;
use super::ShapeVerifier;

use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig, AdminTrait};
use briq_protocol::world_config::{WorldConfig, AdminTrait};

fn execute(ctx: Context, data: RegisterShapeVerifierData,) {
let RegisterShapeVerifierData{attribute_id, class_hash } = data;
Expand All @@ -125,7 +125,7 @@ mod register_shape_verifier {
#[system]
mod shape_verifier_system {
use dojo::world::Context;
use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig, AdminTrait};
use briq_protocol::world_config::{WorldConfig, AdminTrait};

use super::{ShapeVerifier, ShapeVerifierTrait};
use briq_protocol::attributes::attributes::{
Expand Down
2 changes: 1 addition & 1 deletion src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ mod test_briq_factory;

mod test_upgradeable;

mod test_set_nft_multiple;
mod test_set_nft_multiple;
1 change: 0 additions & 1 deletion src/tests/contract_upgrade.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#[starknet::contract]
mod ContractUpgrade {
use array::ArrayTrait;
Expand Down
1 change: 0 additions & 1 deletion src/tests/test_attributes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use serde::Serde;
use starknet::ContractAddress;

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::world_config::{WorldConfig, SYSTEM_CONFIG_ID};
use briq_protocol::tests::test_utils::{
DefaultWorld, DEFAULT_OWNER, USER1, deploy_default_world, impersonate
};
Expand Down
1 change: 0 additions & 1 deletion src/tests/test_box_nft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use serde::Serde;
use starknet::ContractAddress;

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::world_config::{WorldConfig, SYSTEM_CONFIG_ID};
use briq_protocol::tests::test_utils::{
WORLD_ADMIN, DEFAULT_OWNER, DefaultWorld, deploy_default_world, mint_briqs, impersonate
};
Expand Down
8 changes: 4 additions & 4 deletions src/tests/test_briq_factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use starknet::ContractAddress;
use starknet::info::get_block_timestamp;

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::world_config::{WorldConfig, SYSTEM_CONFIG_ID};
use briq_protocol::tests::test_utils::{WORLD_ADMIN,ETH_ADDRESS, DefaultWorld, deploy_default_world, mint_briqs};
use briq_protocol::tests::test_utils::{
WORLD_ADMIN, ETH_ADDRESS, DefaultWorld, deploy_default_world, mint_briqs
};

use dojo_erc::erc_common::utils::system_calldata;

Expand All @@ -27,7 +28,6 @@ use briq_protocol::felt_math::{FeltOrd, FeltDiv};
use debug::PrintTrait;



fn init_briq_factory(world: IWorldDispatcher, t: felt252, surge_t: felt252,) -> BriqFactoryStore {
world
.execute(
Expand Down Expand Up @@ -207,5 +207,5 @@ fn test_overflows_bad_max_t() {

#[test]
#[available_gas(90000000)]
fn test_briq_factory_buy() {// TODO deploy buy token & test buy
fn test_briq_factory_buy() { // TODO deploy buy token & test buy
}
1 change: 0 additions & 1 deletion src/tests/test_briq_token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use starknet::ClassHash;
use briq_protocol::tests::test_utils::{
deploy_default_world, impersonate, DefaultWorld, DEFAULT_OWNER, WORLD_ADMIN
};
use briq_protocol::world_config::{WorldConfig, SYSTEM_CONFIG_ID};
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::briq_token::BriqToken;
use briq_protocol::briq_token::BriqToken::{Event, Upgraded};
Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_set_nft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use starknet::testing::{set_caller_address, set_contract_address};
use starknet::ContractAddress;

use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use briq_protocol::world_config::{WorldConfig, SYSTEM_CONFIG_ID};
use briq_protocol::tests::test_utils::{
WORLD_ADMIN, DEFAULT_OWNER, DefaultWorld, deploy_default_world, mint_briqs, impersonate
};
Expand All @@ -19,6 +18,7 @@ use dojo_erc::erc1155::interface::IERC1155DispatcherTrait;
use briq_protocol::attributes::attribute_group::{CreateAttributeGroupData, AttributeGroupOwner};
use briq_protocol::shape_verifier::RegisterShapeVerifierData;
use briq_protocol::types::{FTSpec, ShapeItem, ShapePacking, PackedShapeItem};
use briq_protocol::world_config::get_world_config;

use debug::PrintTrait;

Expand Down Expand Up @@ -292,7 +292,7 @@ fn test_simple_mint_attribute_ok() {
'ERC1155MintBurn',
(array![
WORLD_ADMIN().into(),
get!(world, (SYSTEM_CONFIG_ID), WorldConfig).booklet.into(),
get_world_config(world).booklet.into(),
0,
DEFAULT_OWNER().into(),
1,
Expand Down
Loading

0 comments on commit 36bb533

Please sign in to comment.