Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix dojo merge issue & token_id to ContractAddress #20

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 19 additions & 46 deletions src/attributes/attributes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ use debug::PrintTrait;

#[derive(Drop, starknet::Event)]
struct AttributeAssigned {
set_token_id: u256,
set_token_id: ContractAddress,
attribute_id: felt252
}

#[derive(Drop, starknet::Event)]
struct AttributeRemoved {
set_token_id: u256,
set_token_id: ContractAddress,
attribute_id: felt252
}

#[derive(Drop, Serde)]
struct AttributeAssignData {
set_owner: ContractAddress,
set_token_id: felt252,
set_token_id: ContractAddress,
attribute_id: felt252,
shape: Array<PackedShapeItem>,
fts: Array<FTSpec>,
Expand All @@ -46,7 +46,7 @@ struct AttributeAssignData {
#[derive(Drop, Serde)]
struct AttributeRemoveData {
set_owner: ContractAddress,
set_token_id: felt252,
set_token_id: ContractAddress,
attribute_id: felt252
}

Expand All @@ -59,7 +59,7 @@ enum AttributeHandlerData {
fn assign_attributes(
ctx: Context,
set_owner: ContractAddress,
set_token_id: felt252,
set_token_id: ContractAddress,
mut attributes: Array<felt252>,
shape: @Array<PackedShapeItem>,
fts: @Array<FTSpec>,
Expand All @@ -69,7 +69,7 @@ fn assign_attributes(
}

assert(set_owner.is_non_zero(), 'Bad input');
assert(set_token_id != 0, 'Bad input');
assert(set_token_id.is_non_zero(), 'Bad input');

loop {
if (attributes.len() == 0) {
Expand All @@ -81,29 +81,15 @@ fn assign_attributes(
};

// Update the cumulative balance
// TODO: replace wen merge on dojo
// let balance = ERC1155BalanceTrait::balance_of(
// ctx.world, CUM_BALANCE_TOKEN(), CB_ATTRIBUTES(), set_token_id
// );
let balance = get!(
ctx.world, (CUM_BALANCE_TOKEN(), CB_ATTRIBUTES(), set_token_id), ERC1155Balance
)
.amount;
set!(
ctx.world,
ERC1155Balance {
token: CUM_BALANCE_TOKEN(),
token_id: CB_ATTRIBUTES().into(),
account: set_token_id.try_into().unwrap(),
amount: balance + attributes.len().into()
}
ERC1155BalanceTrait::unchecked_increase_balance(
ctx.world, CUM_BALANCE_TOKEN(), set_token_id, CB_ATTRIBUTES(), attributes.len().into()
);
}

fn inner_attribute_assign(
ctx: Context,
set_owner: ContractAddress,
set_token_id: felt252,
set_token_id: ContractAddress,
attribute_id: felt252,
shape: @Array<PackedShapeItem>,
fts: @Array<FTSpec>,
Expand Down Expand Up @@ -132,18 +118,21 @@ fn inner_attribute_assign(
},
};

emit!(ctx.world, AttributeAssigned { set_token_id: set_token_id.into(), attribute_id });
emit!(ctx.world, AttributeAssigned { set_token_id: set_token_id, attribute_id });
}

fn remove_attributes(
ctx: Context, set_owner: ContractAddress, set_token_id: felt252, mut attributes: Array<felt252>
ctx: Context,
set_owner: ContractAddress,
set_token_id: ContractAddress,
mut attributes: Array<felt252>
) {
if attributes.len() == 0 {
return ();
}

assert(set_owner.is_non_zero(), 'Bad input');
assert(set_token_id != 0, 'Bad input');
assert(set_token_id.is_non_zero(), 'Bad input');

loop {
if (attributes.len() == 0) {
Expand All @@ -153,29 +142,13 @@ fn remove_attributes(
};

// Update the cumulative balance
// TODO: replace wen merge on dojo
// let balance = ERC1155BalanceTrait::balance_of(
// ctx.world, CUM_BALANCE_TOKEN(), CB_ATTRIBUTES(), set_token_id
// );

let balance = get!(
ctx.world, (CUM_BALANCE_TOKEN(), CB_ATTRIBUTES(), set_token_id), ERC1155Balance
)
.amount;

set!(
ctx.world,
ERC1155Balance {
token: CUM_BALANCE_TOKEN(),
token_id: CB_ATTRIBUTES().into(),
account: set_token_id.try_into().unwrap(),
amount: balance - attributes.len().into()
}
ERC1155BalanceTrait::unchecked_decrease_balance(
ctx.world, CUM_BALANCE_TOKEN(), set_token_id, CB_ATTRIBUTES(), attributes.len().into()
);
}

fn remove_attribute_inner(
ctx: Context, set_owner: ContractAddress, set_token_id: felt252, attribute_id: felt252,
ctx: Context, set_owner: ContractAddress, set_token_id: ContractAddress, attribute_id: felt252,
) {
assert(attribute_id != 0, 'Bad input');

Expand All @@ -199,6 +172,6 @@ fn remove_attribute_inner(
},
}

emit!(ctx.world, AttributeRemoved { set_token_id: set_token_id.into(), attribute_id });
emit!(ctx.world, AttributeRemoved { set_token_id, attribute_id });
}

4 changes: 2 additions & 2 deletions src/box_nft/unboxing.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn get_booklet_id_for_box(box_id: felt252) -> felt252 {
fn unbox(world: IWorldDispatcher, owner: ContractAddress, box_id: felt252) {
// Burn the box
// TODO: use event-emitting variant
dojo_erc::erc1155::components::ERC1155BalanceTrait::transfer_tokens(
dojo_erc::erc1155::components::ERC1155BalanceTrait::unchecked_transfer_tokens(
world,
get_world_config(world).box,
owner,
Expand All @@ -103,7 +103,7 @@ fn unbox(world: IWorldDispatcher, owner: ContractAddress, box_id: felt252) {

// Mint a booklet
// TODO: use event-emitting variant
dojo_erc::erc1155::components::ERC1155BalanceTrait::transfer_tokens(
dojo_erc::erc1155::components::ERC1155BalanceTrait::unchecked_transfer_tokens(
world,
get_world_config(world).booklet,
Zeroable::zero(),
Expand Down
7 changes: 1 addition & 6 deletions src/briq_token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod BriqToken {
ERC1155SafeBatchTransferFromParams, ERC1155MintParams, ERC1155BurnParams
};

use briq_protocol::upgradeable::{IUpgradeable, UpgradeableTrait};
use briq_protocol::upgradeable::{IUpgradeable, UpgradeableTrait, Upgraded};

const UNLIMITED_ALLOWANCE: felt252 =
3618502788666131213697322783095070105623107215331596699973092056135872020480;
Expand Down Expand Up @@ -62,11 +62,6 @@ mod BriqToken {
approved: bool
}

#[derive(Clone, Drop, Serde, PartialEq, starknet::Event)]
struct Upgraded {
class_hash: ClassHash,
}

#[starknet::interface]
trait IERC1155Events<ContractState> {
fn on_transfer_single(ref self: ContractState, event: TransferSingle);
Expand Down
10 changes: 5 additions & 5 deletions src/briq_token/systems.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ fn update_nocheck(
world, token, to, *ids_span.pop_front().unwrap()
);
if amnt != @0 && balance == 0 {
ERC1155BalanceTrait::transfer_tokens(
ERC1155BalanceTrait::unchecked_transfer_tokens(
world,
CUM_BALANCE_TOKEN(),
Zeroable::zero(),
to,
array![CB_BRIQ().into()].span(),
array![CB_BRIQ()].span(),
array![1].span()
);
};
};

ERC1155BalanceTrait::transfer_tokens(world, token, from, to, ids.span(), amounts.span());
ERC1155BalanceTrait::unchecked_transfer_tokens(world, token, from, to, ids.span(), amounts.span());

let mut ids_span = ids.span();
let mut amounts_span = amounts.span();
Expand All @@ -62,12 +62,12 @@ fn update_nocheck(
world, token, from, *ids_span.pop_front().unwrap()
);
if amnt != @0 && balance == 0 {
ERC1155BalanceTrait::transfer_tokens(
ERC1155BalanceTrait::unchecked_transfer_tokens(
world,
CUM_BALANCE_TOKEN(),
from,
Zeroable::zero(),
array![CB_BRIQ().into()].span(),
array![CB_BRIQ()].span(),
array![1].span()
);
};
Expand Down
8 changes: 4 additions & 4 deletions src/cumulative_balance.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ fn CUM_BALANCE_TOKEN() -> ContractAddress {
'cum_balance'.try_into().unwrap()
}

fn CB_BRIQ() -> ContractAddress {
'briq'.try_into().unwrap()
fn CB_BRIQ() -> felt252 {
'briq'
}

fn CB_ATTRIBUTES() -> ContractAddress {
'attributes'.try_into().unwrap()
fn CB_ATTRIBUTES() -> felt252 {
'attributes'
}
8 changes: 2 additions & 6 deletions src/generic_erc1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod GenericERC1155 {

use briq_protocol::world_config::AdminTrait;
use briq_protocol::utils::PartialEqArray;
use briq_protocol::upgradeable::{IUpgradeable, UpgradeableTrait};
use briq_protocol::upgradeable::{IUpgradeable, UpgradeableTrait, Upgraded};


const UNLIMITED_ALLOWANCE: felt252 =
Expand Down Expand Up @@ -62,11 +62,7 @@ mod GenericERC1155 {
approved: bool
}

#[derive(Clone, Drop, Serde, PartialEq, starknet::Event)]
struct Upgraded {
class_hash: ClassHash,
}


#[starknet::interface]
trait IERC1155Events<ContractState> {
fn on_transfer_single(ref self: ContractState, event: TransferSingle);
Expand Down
7 changes: 1 addition & 6 deletions src/set_nft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod SetNft {

use briq_protocol::world_config::AdminTrait;
use briq_protocol::utils::PartialEqArray;
use briq_protocol::upgradeable::{IUpgradeable, UpgradeableTrait};
use briq_protocol::upgradeable::{IUpgradeable, UpgradeableTrait, Upgraded};


#[storage]
Expand Down Expand Up @@ -59,11 +59,6 @@ mod SetNft {
approved: bool
}

#[derive(Clone, Drop, Serde, PartialEq, starknet::Event)]
struct Upgraded {
class_hash: ClassHash,
}

#[event]
#[derive(Drop, PartialEq, starknet::Event)]
enum Event {
Expand Down
Loading
Loading