Skip to content

Commit

Permalink
disable erc components & use u128 instead of u256 for #[key]
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Apr 5, 2024
1 parent 5e1934b commit 61de20f
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 139 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.6.0-alpha.13
DOJO_VERSION: v0.6.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/influenceth/cubit.git#9402f710716b12c21cd1e481c

[[package]]
name = "dojo"
version = "0.5.1"
source = "git+https://github.com/dojoengine/dojo?tag=v0.6.0-alpha.13#5bdcfdff82c7a01443bf603047f4bfe00d210ed6"
version = "0.6.0"
source = "git+https://github.com/dojoengine/dojo?tag=v0.6.0#fc5ad790c1993713e59f3fc65739160f132f29f0"
dependencies = [
"dojo_plugin",
]
Expand Down Expand Up @@ -45,7 +45,7 @@ dependencies = [

[[package]]
name = "origami"
version = "0.6.0-alpha.13"
version = "0.6.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 @@ -9,13 +9,13 @@ members = [
]

[workspace.package]
version = "0.6.0-alpha.13"
version = "0.6.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" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.6.0-alpha.13" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.6.0" }
origami = { path = "crates" }
token = { path = "token" }
40 changes: 20 additions & 20 deletions token/src/erc1155/erc1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod ERC1155 {
operator: ContractAddress,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
value: u256
}

Expand All @@ -37,7 +37,7 @@ mod ERC1155 {
operator: ContractAddress,
from: ContractAddress,
to: ContractAddress,
ids: Array<u256>,
ids: Array<u128>,
values: Array<u256>
}

Expand Down Expand Up @@ -83,7 +83,7 @@ mod ERC1155 {
self.get_meta().symbol
}

fn uri(self: @ContractState, token_id: u256) -> felt252 {
fn uri(self: @ContractState, token_id: u128) -> felt252 {
//assert(self._exists(token_id), Errors::INVALID_TOKEN_ID);
// TODO : concat with id
self.get_uri(token_id)
Expand All @@ -93,13 +93,13 @@ mod ERC1155 {

#[abi(embed_v0)]
impl ERC1155Impl of interface::IERC1155<ContractState> {
fn balance_of(self: @ContractState, account: ContractAddress, id: u256) -> u256 {
fn balance_of(self: @ContractState, account: ContractAddress, id: u128) -> u256 {
assert(account.is_non_zero(), Errors::INVALID_ACCOUNT);
self.get_balance(account, id).amount
}

fn balance_of_batch(
self: @ContractState, accounts: Array<ContractAddress>, ids: Array<u256>
self: @ContractState, accounts: Array<ContractAddress>, ids: Array<u128>
) -> Array<u256> {
assert(ids.len() == accounts.len(), Errors::INVALID_ARRAY_LENGTH);

Expand Down Expand Up @@ -130,7 +130,7 @@ mod ERC1155 {
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
data: Array<u8>
) {
Expand All @@ -147,7 +147,7 @@ mod ERC1155 {
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
ids: Array<u256>,
ids: Array<u128>,
amounts: Array<u256>,
data: Array<u8>
) {
Expand All @@ -163,12 +163,12 @@ mod ERC1155 {

#[abi(embed_v0)]
impl ERC1155CamelOnlyImpl of interface::IERC1155CamelOnly<ContractState> {
fn balanceOf(self: @ContractState, account: ContractAddress, id: u256) -> u256 {
fn balanceOf(self: @ContractState, account: ContractAddress, id: u128) -> u256 {
ERC1155Impl::balance_of(self, account, id)
}

fn balanceOfBatch(
self: @ContractState, accounts: Array<ContractAddress>, ids: Array<u256>
self: @ContractState, accounts: Array<ContractAddress>, ids: Array<u128>
) -> Array<u256> {
ERC1155Impl::balance_of_batch(self, accounts, ids)
}
Expand All @@ -185,7 +185,7 @@ mod ERC1155 {
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
data: Array<u8>
) {
Expand All @@ -195,7 +195,7 @@ mod ERC1155 {
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
ids: Array<u256>,
ids: Array<u128>,
amounts: Array<u256>,
data: Array<u8>
) {
Expand All @@ -217,12 +217,12 @@ mod ERC1155 {
get!(self.world(), get_contract_address(), ERC1155Meta)
}

fn get_uri(self: @ContractState, token_id: u256) -> felt252 {
fn get_uri(self: @ContractState, token_id: u128) -> felt252 {
// TODO : concat with id when we have string type
self.get_meta().base_uri
}

fn get_balance(self: @ContractState, account: ContractAddress, id: u256) -> ERC1155Balance {
fn get_balance(self: @ContractState, account: ContractAddress, id: u128) -> ERC1155Balance {
get!(self.world(), (get_contract_address(), account, id), ERC1155Balance)
}

Expand All @@ -249,7 +249,7 @@ mod ERC1155 {
emit!(self.world(), (Event::ApprovalForAll(approval_for_all_event)));
}

fn set_balance(ref self: ContractState, account: ContractAddress, id: u256, amount: u256) {
fn set_balance(ref self: ContractState, account: ContractAddress, id: u128, amount: u256) {
set!(
self.world(), ERC1155Balance { token: get_contract_address(), account, id, amount }
);
Expand All @@ -259,7 +259,7 @@ mod ERC1155 {
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
) {
self.set_balance(from, id, self.get_balance(from, id).amount - amount);
Expand Down Expand Up @@ -294,7 +294,7 @@ mod ERC1155 {
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
data: Array<u8>
) {
Expand All @@ -312,7 +312,7 @@ mod ERC1155 {
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
ids: Array<u256>,
ids: Array<u128>,
amounts: Array<u256>,
data: Array<u8>
) {
Expand All @@ -338,7 +338,7 @@ mod ERC1155 {
emit!(self.world(), (Event::TransferBatch(transfer_batch_event)));
}

fn _mint(ref self: ContractState, to: ContractAddress, id: u256, amount: u256) {
fn _mint(ref self: ContractState, to: ContractAddress, id: u128, amount: u256) {
assert(to.is_non_zero(), Errors::INVALID_RECEIVER);

self.set_balance(to, id, self.get_balance(to, id).amount + amount);
Expand All @@ -351,7 +351,7 @@ mod ERC1155 {
emit!(self.world(), (Event::TransferSingle(transfer_single_event)));
}

fn _burn(ref self: ContractState, id: u256, amount: u256) {
fn _burn(ref self: ContractState, id: u128, amount: u256) {
let caller = get_caller_address();
assert(self.get_balance(caller, id).amount >= amount, Errors::INSUFFICIENT_BALANCE);

Expand All @@ -372,7 +372,7 @@ mod ERC1155 {
fn _safe_mint(
ref self: ContractState,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
data: Span<felt252>
) {
Expand Down
32 changes: 16 additions & 16 deletions token/src/erc1155/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use starknet::ContractAddress;

#[starknet::interface]
trait IERC1155<TState> {
fn balance_of(self: @TState, account: ContractAddress, id: u256) -> u256;
fn balance_of(self: @TState, account: ContractAddress, id: u128) -> u256;
fn balance_of_batch(
self: @TState, accounts: Array<ContractAddress>, ids: Array<u256>
self: @TState, accounts: Array<ContractAddress>, ids: Array<u128>
) -> Array<u256>;
fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool);
fn is_approved_for_all(
Expand All @@ -14,41 +14,41 @@ trait IERC1155<TState> {
ref self: TState,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
data: Array<u8>
);
fn safe_batch_transfer_from(
ref self: TState,
from: ContractAddress,
to: ContractAddress,
ids: Array<u256>,
ids: Array<u128>,
amounts: Array<u256>,
data: Array<u8>
);
}

#[starknet::interface]
trait IERC1155CamelOnly<TState> {
fn balanceOf(self: @TState, account: ContractAddress, id: u256) -> u256;
fn balanceOf(self: @TState, account: ContractAddress, id: u128) -> u256;
fn balanceOfBatch(
self: @TState, accounts: Array<ContractAddress>, ids: Array<u256>
self: @TState, accounts: Array<ContractAddress>, ids: Array<u128>
) -> Array<u256>;
fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool);
fn isApprovedForAll(self: @TState, account: ContractAddress, operator: ContractAddress) -> bool;
fn safeTransferFrom(
ref self: TState,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
data: Array<u8>
);
fn safeBatchTransferFrom(
ref self: TState,
from: ContractAddress,
to: ContractAddress,
ids: Array<u256>,
ids: Array<u128>,
amounts: Array<u256>,
data: Array<u8>
);
Expand All @@ -58,7 +58,7 @@ trait IERC1155CamelOnly<TState> {
trait IERC1155Metadata<TState> {
fn name(self: @TState) -> felt252;
fn symbol(self: @TState) -> felt252;
fn uri(self: @TState, token_id: u256) -> felt252;
fn uri(self: @TState, token_id: u128) -> felt252;
}

//
Expand All @@ -68,9 +68,9 @@ trait IERC1155Metadata<TState> {
#[starknet::interface]
trait ERC1155ABI<TState> {
// IERC1155
fn balance_of(self: @TState, account: ContractAddress, id: u256) -> u256;
fn balance_of(self: @TState, account: ContractAddress, id: u128) -> u256;
fn balance_of_batch(
self: @TState, accounts: Array<ContractAddress>, ids: Array<u256>
self: @TState, accounts: Array<ContractAddress>, ids: Array<u128>
) -> Array<u256>;
fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool);
fn is_approved_for_all(
Expand All @@ -80,7 +80,7 @@ trait ERC1155ABI<TState> {
ref self: TState,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
data: Array<u8>
);
Expand All @@ -96,20 +96,20 @@ trait ERC1155ABI<TState> {
// IERC1155Metadata
fn name(self: @TState) -> felt252;
fn symbol(self: @TState) -> felt252;
fn uri(self: @TState, token_id: u256) -> felt252;
fn uri(self: @TState, token_id: u128) -> felt252;

// IERC1155CamelOnly
fn balanceOf(self: @TState, account: ContractAddress, id: u256) -> u256;
fn balanceOf(self: @TState, account: ContractAddress, id: u128) -> u256;
fn balanceOfBatch(
self: @TState, accounts: Array<ContractAddress>, ids: Array<u256>
self: @TState, accounts: Array<ContractAddress>, ids: Array<u128>
) -> Array<u256>;
fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool);
fn isApprovedForAll(self: @TState, account: ContractAddress, operator: ContractAddress) -> bool;
fn safeTransferFrom(
ref self: TState,
from: ContractAddress,
to: ContractAddress,
id: u256,
id: u128,
amount: u256,
data: Array<u8>
);
Expand Down
2 changes: 1 addition & 1 deletion token/src/erc1155/models.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ struct ERC1155Balance {
#[key]
account: ContractAddress,
#[key]
id: u256,
id: u128,
amount: u256
}
8 changes: 4 additions & 4 deletions token/src/erc1155/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -696,14 +696,14 @@ fn test__burn_more_than_balance() {
//

fn assert_state_before_transfer(
state: @ERC1155::ContractState, owner: ContractAddress, recipient: ContractAddress, id: u256,
state: @ERC1155::ContractState, owner: ContractAddress, recipient: ContractAddress, id: u128,
) {
assert(ERC1155Impl::balance_of(state, owner, id) == TOKEN_AMOUNT, 'Balance of owner before');
assert(ERC1155Impl::balance_of(state, recipient, id) == 0, 'Balance of recipient before');
}

fn assert_state_after_transfer(
state: @ERC1155::ContractState, owner: ContractAddress, recipient: ContractAddress, id: u256
state: @ERC1155::ContractState, owner: ContractAddress, recipient: ContractAddress, id: u128
) {
assert(ERC1155Impl::balance_of(state, owner, id) == 0, 'Balance of owner after');
assert(
Expand Down Expand Up @@ -760,7 +760,7 @@ fn assert_event_approval_for_all(
}

fn assert_event_transfer_single(
from: ContractAddress, to: ContractAddress, id: u256, amount: u256
from: ContractAddress, to: ContractAddress, id: u128, amount: u256
) {
let event = utils::pop_log::<TransferSingle>(ZERO()).unwrap();
assert(event.from == from, 'Invalid `from`');
Expand All @@ -771,7 +771,7 @@ fn assert_event_transfer_single(
}

fn assert_event_transfer_batch(
from: ContractAddress, to: ContractAddress, ids: Array<u256>, amounts: Array<u256>
from: ContractAddress, to: ContractAddress, ids: Array<u128>, amounts: Array<u256>
) {
let event = utils::pop_log::<TransferBatch>(ZERO()).unwrap();
assert(event.from == from, 'Invalid `from`');
Expand Down
Loading

0 comments on commit 61de20f

Please sign in to comment.