diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fee75dc0..711f5995 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.6.0-alpha.13 + DOJO_VERSION: v0.6.0 SCARB_VERSION: v2.6.4 jobs: diff --git a/Scarb.lock b/Scarb.lock index 8ec6135f..ca8796db 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -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", ] @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "origami" -version = "0.6.0-alpha.13" +version = "0.6.0" dependencies = [ "cubit", "dojo", diff --git a/Scarb.toml b/Scarb.toml index 6ff8da8d..a787a887 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -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 = ["bal7hazar@proton.me"] [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" } diff --git a/token/src/erc1155/erc1155.cairo b/token/src/erc1155/erc1155.cairo index 4a603678..dfa3edc6 100644 --- a/token/src/erc1155/erc1155.cairo +++ b/token/src/erc1155/erc1155.cairo @@ -28,7 +28,7 @@ mod ERC1155 { operator: ContractAddress, from: ContractAddress, to: ContractAddress, - id: u256, + id: u128, value: u256 } @@ -37,7 +37,7 @@ mod ERC1155 { operator: ContractAddress, from: ContractAddress, to: ContractAddress, - ids: Array, + ids: Array, values: Array } @@ -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) @@ -93,13 +93,13 @@ mod ERC1155 { #[abi(embed_v0)] impl ERC1155Impl of interface::IERC1155 { - 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, ids: Array + self: @ContractState, accounts: Array, ids: Array ) -> Array { assert(ids.len() == accounts.len(), Errors::INVALID_ARRAY_LENGTH); @@ -130,7 +130,7 @@ mod ERC1155 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - id: u256, + id: u128, amount: u256, data: Array ) { @@ -147,7 +147,7 @@ mod ERC1155 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - ids: Array, + ids: Array, amounts: Array, data: Array ) { @@ -163,12 +163,12 @@ mod ERC1155 { #[abi(embed_v0)] impl ERC1155CamelOnlyImpl of interface::IERC1155CamelOnly { - 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, ids: Array + self: @ContractState, accounts: Array, ids: Array ) -> Array { ERC1155Impl::balance_of_batch(self, accounts, ids) } @@ -185,7 +185,7 @@ mod ERC1155 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - id: u256, + id: u128, amount: u256, data: Array ) { @@ -195,7 +195,7 @@ mod ERC1155 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - ids: Array, + ids: Array, amounts: Array, data: Array ) { @@ -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) } @@ -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 } ); @@ -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); @@ -294,7 +294,7 @@ mod ERC1155 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - id: u256, + id: u128, amount: u256, data: Array ) { @@ -312,7 +312,7 @@ mod ERC1155 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - ids: Array, + ids: Array, amounts: Array, data: Array ) { @@ -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); @@ -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); @@ -372,7 +372,7 @@ mod ERC1155 { fn _safe_mint( ref self: ContractState, to: ContractAddress, - id: u256, + id: u128, amount: u256, data: Span ) { diff --git a/token/src/erc1155/interface.cairo b/token/src/erc1155/interface.cairo index e29a6626..0ddb715b 100644 --- a/token/src/erc1155/interface.cairo +++ b/token/src/erc1155/interface.cairo @@ -2,9 +2,9 @@ use starknet::ContractAddress; #[starknet::interface] trait 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, ids: Array + self: @TState, accounts: Array, ids: Array ) -> Array; fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); fn is_approved_for_all( @@ -14,7 +14,7 @@ trait IERC1155 { ref self: TState, from: ContractAddress, to: ContractAddress, - id: u256, + id: u128, amount: u256, data: Array ); @@ -22,7 +22,7 @@ trait IERC1155 { ref self: TState, from: ContractAddress, to: ContractAddress, - ids: Array, + ids: Array, amounts: Array, data: Array ); @@ -30,9 +30,9 @@ trait IERC1155 { #[starknet::interface] trait 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, ids: Array + self: @TState, accounts: Array, ids: Array ) -> Array; fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); fn isApprovedForAll(self: @TState, account: ContractAddress, operator: ContractAddress) -> bool; @@ -40,7 +40,7 @@ trait IERC1155CamelOnly { ref self: TState, from: ContractAddress, to: ContractAddress, - id: u256, + id: u128, amount: u256, data: Array ); @@ -48,7 +48,7 @@ trait IERC1155CamelOnly { ref self: TState, from: ContractAddress, to: ContractAddress, - ids: Array, + ids: Array, amounts: Array, data: Array ); @@ -58,7 +58,7 @@ trait IERC1155CamelOnly { trait 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; } // @@ -68,9 +68,9 @@ trait IERC1155Metadata { #[starknet::interface] trait ERC1155ABI { // 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, ids: Array + self: @TState, accounts: Array, ids: Array ) -> Array; fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); fn is_approved_for_all( @@ -80,7 +80,7 @@ trait ERC1155ABI { ref self: TState, from: ContractAddress, to: ContractAddress, - id: u256, + id: u128, amount: u256, data: Array ); @@ -96,12 +96,12 @@ trait ERC1155ABI { // 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, ids: Array + self: @TState, accounts: Array, ids: Array ) -> Array; fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); fn isApprovedForAll(self: @TState, account: ContractAddress, operator: ContractAddress) -> bool; @@ -109,7 +109,7 @@ trait ERC1155ABI { ref self: TState, from: ContractAddress, to: ContractAddress, - id: u256, + id: u128, amount: u256, data: Array ); diff --git a/token/src/erc1155/models.cairo b/token/src/erc1155/models.cairo index a448b469..b1462ec6 100644 --- a/token/src/erc1155/models.cairo +++ b/token/src/erc1155/models.cairo @@ -30,6 +30,6 @@ struct ERC1155Balance { #[key] account: ContractAddress, #[key] - id: u256, + id: u128, amount: u256 } diff --git a/token/src/erc1155/tests.cairo b/token/src/erc1155/tests.cairo index 2821445e..92ff5ec7 100644 --- a/token/src/erc1155/tests.cairo +++ b/token/src/erc1155/tests.cairo @@ -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( @@ -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::(ZERO()).unwrap(); assert(event.from == from, 'Invalid `from`'); @@ -771,7 +771,7 @@ fn assert_event_transfer_single( } fn assert_event_transfer_batch( - from: ContractAddress, to: ContractAddress, ids: Array, amounts: Array + from: ContractAddress, to: ContractAddress, ids: Array, amounts: Array ) { let event = utils::pop_log::(ZERO()).unwrap(); assert(event.from == from, 'Invalid `from`'); diff --git a/token/src/erc721/erc721.cairo b/token/src/erc721/erc721.cairo index d8df7511..25c102f7 100644 --- a/token/src/erc721/erc721.cairo +++ b/token/src/erc721/erc721.cairo @@ -28,14 +28,14 @@ mod ERC721 { struct Transfer { from: ContractAddress, to: ContractAddress, - token_id: u256 + token_id: u128 } #[derive(Copy, Drop, starknet::Event)] struct Approval { owner: ContractAddress, approved: ContractAddress, - token_id: u256 + token_id: u128 } #[derive(Copy, Drop, starknet::Event)] @@ -66,7 +66,7 @@ mod ERC721 { symbol: felt252, base_uri: felt252, recipient: ContractAddress, - token_id: u256 + token_id: u128 ) { self._world.write(world); self.initializer(name, symbol, base_uri); @@ -83,7 +83,7 @@ mod ERC721 { self.get_meta().symbol } - fn token_uri(self: @ContractState, token_id: u256) -> felt252 { + fn token_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) @@ -92,7 +92,7 @@ mod ERC721 { #[abi(embed_v0)] impl ERC721MetadataCamelOnlyImpl of interface::IERC721MetadataCamelOnly { - fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { + fn tokenURI(self: @ContractState, tokenId: u128) -> felt252 { assert(self._exists(tokenId), Errors::INVALID_TOKEN_ID); self.get_uri(tokenId) } @@ -105,11 +105,11 @@ mod ERC721 { self.get_balance(account).amount } - fn owner_of(self: @ContractState, token_id: u256) -> ContractAddress { + fn owner_of(self: @ContractState, token_id: u128) -> ContractAddress { self._owner_of(token_id) } - fn get_approved(self: @ContractState, token_id: u256) -> ContractAddress { + fn get_approved(self: @ContractState, token_id: u128) -> ContractAddress { assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); self.get_token_approval(token_id).address } @@ -120,7 +120,7 @@ mod ERC721 { self.get_operator_approval(owner, operator).approved } - fn approve(ref self: ContractState, to: ContractAddress, token_id: u256) { + fn approve(ref self: ContractState, to: ContractAddress, token_id: u128) { let owner = self._owner_of(token_id); let caller = get_caller_address(); @@ -138,7 +138,7 @@ mod ERC721 { } fn transfer_from( - ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u256 + ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u128 ) { assert( self._is_approved_or_owner(get_caller_address(), token_id), Errors::UNAUTHORIZED @@ -150,7 +150,7 @@ mod ERC721 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - token_id: u256, + token_id: u128, data: Span ) { assert( @@ -166,11 +166,11 @@ mod ERC721 { ERC721Impl::balance_of(self, account) } - fn ownerOf(self: @ContractState, tokenId: u256) -> ContractAddress { + fn ownerOf(self: @ContractState, tokenId: u128) -> ContractAddress { ERC721Impl::owner_of(self, tokenId) } - fn getApproved(self: @ContractState, tokenId: u256) -> ContractAddress { + fn getApproved(self: @ContractState, tokenId: u128) -> ContractAddress { ERC721Impl::get_approved(self, tokenId) } @@ -185,7 +185,7 @@ mod ERC721 { } fn transferFrom( - ref self: ContractState, from: ContractAddress, to: ContractAddress, tokenId: u256 + ref self: ContractState, from: ContractAddress, to: ContractAddress, tokenId: u128 ) { ERC721Impl::transfer_from(ref self, from, to, tokenId) } @@ -194,7 +194,7 @@ mod ERC721 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - tokenId: u256, + tokenId: u128, data: Span ) { ERC721Impl::safe_transfer_from(ref self, from, to, tokenId, data) @@ -215,7 +215,7 @@ mod ERC721 { get!(self.world(), get_contract_address(), ERC721Meta) } - 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 } @@ -224,11 +224,11 @@ mod ERC721 { get!(self.world(), (get_contract_address(), account), ERC721Balance) } - fn get_owner_of(self: @ContractState, token_id: u256) -> ERC721Owner { + fn get_owner_of(self: @ContractState, token_id: u128) -> ERC721Owner { get!(self.world(), (get_contract_address(), token_id), ERC721Owner) } - fn get_token_approval(self: @ContractState, token_id: u256) -> ERC721TokenApproval { + fn get_token_approval(self: @ContractState, token_id: u128) -> ERC721TokenApproval { get!(self.world(), (get_contract_address(), token_id), ERC721TokenApproval) } @@ -242,7 +242,7 @@ mod ERC721 { ref self: ContractState, owner: ContractAddress, to: ContractAddress, - token_id: u256, + token_id: u128, emit: bool ) { set!( @@ -278,7 +278,7 @@ mod ERC721 { set!(self.world(), ERC721Balance { token: get_contract_address(), account, amount }); } - fn set_owner(ref self: ContractState, token_id: u256, address: ContractAddress) { + fn set_owner(ref self: ContractState, token_id: u128, address: ContractAddress) { set!(self.world(), ERC721Owner { token: get_contract_address(), token_id, address }); } } @@ -290,7 +290,7 @@ mod ERC721 { set!(self.world(), (meta)); } - fn _owner_of(self: @ContractState, token_id: u256) -> ContractAddress { + fn _owner_of(self: @ContractState, token_id: u128) -> ContractAddress { let owner = self.get_owner_of(token_id).address; match owner.is_zero() { bool::False(()) => owner, @@ -298,13 +298,13 @@ mod ERC721 { } } - fn _exists(self: @ContractState, token_id: u256) -> bool { + fn _exists(self: @ContractState, token_id: u128) -> bool { let owner = self.get_owner_of(token_id).address; owner.is_non_zero() } fn _is_approved_or_owner( - self: @ContractState, spender: ContractAddress, token_id: u256 + self: @ContractState, spender: ContractAddress, token_id: u128 ) -> bool { let owner = self._owner_of(token_id); let is_approved_for_all = ERC721Impl::is_approved_for_all(self, owner, spender); @@ -313,7 +313,7 @@ mod ERC721 { || spender == ERC721Impl::get_approved(self, token_id) } - fn _approve(ref self: ContractState, to: ContractAddress, token_id: u256) { + fn _approve(ref self: ContractState, to: ContractAddress, token_id: u128) { let owner = self._owner_of(token_id); assert(owner != to, Errors::APPROVAL_TO_OWNER); @@ -330,7 +330,7 @@ mod ERC721 { self.set_operator_approval(owner, operator, approved); } - fn _mint(ref self: ContractState, to: ContractAddress, token_id: u256) { + fn _mint(ref self: ContractState, to: ContractAddress, token_id: u128) { assert(!to.is_zero(), Errors::INVALID_RECEIVER); assert(!self._exists(token_id), Errors::ALREADY_MINTED); @@ -344,7 +344,7 @@ mod ERC721 { } fn _transfer( - ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u256 + ref self: ContractState, from: ContractAddress, to: ContractAddress, token_id: u128 ) { assert(!to.is_zero(), Errors::INVALID_RECEIVER); let owner = self._owner_of(token_id); @@ -363,7 +363,7 @@ mod ERC721 { emit!(self.world(), (Event::Transfer(transfer_event))); } - fn _burn(ref self: ContractState, token_id: u256) { + fn _burn(ref self: ContractState, token_id: u128) { let owner = self._owner_of(token_id); // Implicit clear approvals, no need to emit an event @@ -379,7 +379,7 @@ mod ERC721 { } fn _safe_mint( - ref self: ContractState, to: ContractAddress, token_id: u256, data: Span + ref self: ContractState, to: ContractAddress, token_id: u128, data: Span ) { self._mint(to, token_id); } @@ -388,7 +388,7 @@ mod ERC721 { ref self: ContractState, from: ContractAddress, to: ContractAddress, - token_id: u256, + token_id: u128, data: Span ) { self._transfer(from, to, token_id); diff --git a/token/src/erc721/interface.cairo b/token/src/erc721/interface.cairo index d257cc95..726ce572 100644 --- a/token/src/erc721/interface.cairo +++ b/token/src/erc721/interface.cairo @@ -9,18 +9,18 @@ const IERC721_RECEIVER_ID: felt252 = #[starknet::interface] trait IERC721 { fn balance_of(self: @TState, account: ContractAddress) -> u256; - fn owner_of(self: @TState, token_id: u256) -> ContractAddress; + fn owner_of(self: @TState, token_id: u128) -> ContractAddress; fn safe_transfer_from( ref self: TState, from: ContractAddress, to: ContractAddress, - token_id: u256, + token_id: u128, data: Span ); - fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256); - fn approve(ref self: TState, to: ContractAddress, token_id: u256); + fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u128); + fn approve(ref self: TState, to: ContractAddress, token_id: u128); fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); - fn get_approved(self: @TState, token_id: u256) -> ContractAddress; + fn get_approved(self: @TState, token_id: u128) -> ContractAddress; fn is_approved_for_all( self: @TState, owner: ContractAddress, operator: ContractAddress ) -> bool; @@ -30,29 +30,29 @@ trait IERC721 { trait IERC721Metadata { fn name(self: @TState) -> felt252; fn symbol(self: @TState) -> felt252; - fn token_uri(self: @TState, token_id: u256) -> felt252; + fn token_uri(self: @TState, token_id: u128) -> felt252; } #[starknet::interface] trait IERC721CamelOnly { fn balanceOf(self: @TState, account: ContractAddress) -> u256; - fn ownerOf(self: @TState, tokenId: u256) -> ContractAddress; + fn ownerOf(self: @TState, tokenId: u128) -> ContractAddress; fn safeTransferFrom( ref self: TState, from: ContractAddress, to: ContractAddress, - tokenId: u256, + tokenId: u128, data: Span ); - fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256); + fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u128); fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); - fn getApproved(self: @TState, tokenId: u256) -> ContractAddress; + fn getApproved(self: @TState, tokenId: u128) -> ContractAddress; fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool; } #[starknet::interface] trait IERC721MetadataCamelOnly { - fn tokenURI(self: @TState, tokenId: u256) -> felt252; + fn tokenURI(self: @TState, tokenId: u128) -> felt252; } // @@ -63,18 +63,18 @@ trait IERC721MetadataCamelOnly { trait ERC721ABI { // IERC721 fn balance_of(self: @TState, account: ContractAddress) -> u256; - fn owner_of(self: @TState, token_id: u256) -> ContractAddress; + fn owner_of(self: @TState, token_id: u128) -> ContractAddress; fn safe_transfer_from( ref self: TState, from: ContractAddress, to: ContractAddress, - token_id: u256, + token_id: u128, data: Span ); - fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256); - fn approve(ref self: TState, to: ContractAddress, token_id: u256); + fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u128); + fn approve(ref self: TState, to: ContractAddress, token_id: u128); fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); - fn get_approved(self: @TState, token_id: u256) -> ContractAddress; + fn get_approved(self: @TState, token_id: u128) -> ContractAddress; fn is_approved_for_all( self: @TState, owner: ContractAddress, operator: ContractAddress ) -> bool; @@ -82,25 +82,25 @@ trait ERC721ABI { // IERC721Metadata fn name(self: @TState) -> felt252; fn symbol(self: @TState) -> felt252; - fn token_uri(self: @TState, token_id: u256) -> felt252; + fn token_uri(self: @TState, token_id: u128) -> felt252; // IERC721CamelOnly fn balanceOf(self: @TState, account: ContractAddress) -> u256; - fn ownerOf(self: @TState, tokenId: u256) -> ContractAddress; + fn ownerOf(self: @TState, tokenId: u128) -> ContractAddress; fn safeTransferFrom( ref self: TState, from: ContractAddress, to: ContractAddress, - tokenId: u256, + tokenId: u128, data: Span ); - fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256); + fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u128); fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); - fn getApproved(self: @TState, tokenId: u256) -> ContractAddress; + fn getApproved(self: @TState, tokenId: u128) -> ContractAddress; fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool; // IERC721MetadataCamelOnly - fn tokenURI(self: @TState, tokenId: u256) -> felt252; + fn tokenURI(self: @TState, tokenId: u128) -> felt252; } // @@ -113,7 +113,7 @@ trait IERC721Receiver { self: @TState, operator: ContractAddress, from: ContractAddress, - token_id: u256, + token_id: u128, data: Span ) -> felt252; } @@ -124,7 +124,7 @@ trait IERC721ReceiverCamel { self: @TState, operator: ContractAddress, from: ContractAddress, - tokenId: u256, + tokenId: u128, data: Span ) -> felt252; } diff --git a/token/src/erc721/models.cairo b/token/src/erc721/models.cairo index 6128b7b3..989c800e 100644 --- a/token/src/erc721/models.cairo +++ b/token/src/erc721/models.cairo @@ -27,7 +27,7 @@ struct ERC721Owner { #[key] token: ContractAddress, #[key] - token_id: u256, + token_id: u128, address: ContractAddress } @@ -45,6 +45,6 @@ struct ERC721TokenApproval { #[key] token: ContractAddress, #[key] - token_id: u256, + token_id: u128, address: ContractAddress, } diff --git a/token/src/erc721/tests.cairo b/token/src/erc721/tests.cairo index d8c3a4a2..8236271c 100644 --- a/token/src/erc721/tests.cairo +++ b/token/src/erc721/tests.cairo @@ -1,7 +1,6 @@ // Core imports use integer::u256; -use integer::u256_from_felt252; use zeroable::Zeroable; use debug::PrintTrait; @@ -157,14 +156,14 @@ fn test_owner_of() { #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_owner_of_non_minted() { let state = setup(); - ERC721Impl::owner_of(@state, u256_from_felt252(7)); + ERC721Impl::owner_of(@state, 7); } #[test] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_token_uri_non_minted() { let state = setup(); - ERC721MetadataImpl::token_uri(@state, u256_from_felt252(7)); + ERC721MetadataImpl::token_uri(@state, 7); } #[test] @@ -182,7 +181,7 @@ fn test_get_approved() { #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_get_approved_nonexistent() { let mut state = setup(); - ERC721Impl::get_approved(@state, u256_from_felt252(7)); + ERC721Impl::get_approved(@state, 7); } #[test] @@ -1316,7 +1315,7 @@ fn assert_state_before_transfer( state: @ERC721::ContractState, owner: ContractAddress, recipient: ContractAddress, - token_id: u256 + token_id: u128 ) { assert(ERC721Impl::owner_of(state, token_id) == owner, 'Ownership before'); assert(ERC721Impl::balance_of(state, owner) == 1, 'Balance of owner before'); @@ -1327,7 +1326,7 @@ fn assert_state_after_transfer( state: @ERC721::ContractState, owner: ContractAddress, recipient: ContractAddress, - token_id: u256 + token_id: u128 ) { assert(ERC721Impl::owner_of(state, token_id) == recipient, 'Ownership after'); assert(ERC721Impl::balance_of(state, owner) == 0, 'Balance of owner after'); @@ -1340,7 +1339,7 @@ fn assert_state_before_mint(state: @ERC721::ContractState, recipient: ContractAd } fn assert_state_after_mint( - state: @ERC721::ContractState, recipient: ContractAddress, token_id: u256 + state: @ERC721::ContractState, recipient: ContractAddress, token_id: u128 ) { assert(ERC721Impl::owner_of(state, token_id) == recipient, 'Ownership after'); assert(ERC721Impl::balance_of(state, recipient) == 1, 'Balance of recipient after'); @@ -1357,7 +1356,7 @@ fn assert_event_approval_for_all( utils::assert_no_events_left(ZERO()); } -fn assert_event_approval(owner: ContractAddress, approved: ContractAddress, token_id: u256) { +fn assert_event_approval(owner: ContractAddress, approved: ContractAddress, token_id: u128) { let event = utils::pop_log::(ZERO()).unwrap(); assert(event.owner == owner, 'Invalid `owner`'); assert(event.approved == approved, 'Invalid `approved`'); @@ -1365,7 +1364,7 @@ fn assert_event_approval(owner: ContractAddress, approved: ContractAddress, toke utils::assert_no_events_left(ZERO()); } -fn assert_event_transfer(from: ContractAddress, to: ContractAddress, token_id: u256) { +fn assert_event_transfer(from: ContractAddress, to: ContractAddress, token_id: u128) { let event = utils::pop_log::(ZERO()).unwrap(); assert(event.from == from, 'Invalid `from`'); assert(event.to == to, 'Invalid `to`'); diff --git a/token/src/lib.cairo b/token/src/lib.cairo index 50b962e5..12e10b3e 100644 --- a/token/src/lib.cairo +++ b/token/src/lib.cairo @@ -1,27 +1,27 @@ -mod components { - mod introspection { - mod src5; - } +// mod components { +// mod introspection { +// mod src5; +// } - mod security { - mod initializable; - } +// mod security { +// mod initializable; +// } - mod token { - mod erc20 { - mod erc20_allowance; - mod erc20_balance; - mod erc20_bridgeable; - mod erc20_burnable; - mod erc20_metadata; - mod erc20_mintable; - } +// mod token { +// mod erc20 { +// mod erc20_allowance; +// mod erc20_balance; +// mod erc20_bridgeable; +// mod erc20_burnable; +// mod erc20_metadata; +// mod erc20_mintable; +// } - mod erc721 {} - } +// mod erc721 {} +// } - mod tests; -} +// mod tests; +// } mod erc20 { mod interface; @@ -50,13 +50,13 @@ mod erc1155 { mod tests; } -mod presets { - mod erc20 { - mod bridgeable; - #[cfg(test)] - mod tests_bridgeable; - } -} +// mod presets { +// mod erc20 { +// mod bridgeable; +// #[cfg(test)] +// mod tests_bridgeable; +// } +// } #[cfg(test)] mod tests { diff --git a/token/src/tests/constants.cairo b/token/src/tests/constants.cairo index cca24ae1..5824d07b 100644 --- a/token/src/tests/constants.cairo +++ b/token/src/tests/constants.cairo @@ -9,9 +9,9 @@ const VALUE: u256 = 300; const ROLE: felt252 = 'ROLE'; const OTHER_ROLE: felt252 = 'OTHER_ROLE'; const URI: felt252 = 'URI'; -const TOKEN_ID: u256 = 21; +const TOKEN_ID: u128 = 21; const TOKEN_AMOUNT: u256 = 42; -const TOKEN_ID_2: u256 = 2; +const TOKEN_ID_2: u128 = 2; const TOKEN_AMOUNT_2: u256 = 69; const PUBKEY: felt252 = 'PUBKEY'; const OTHER_ID: felt252 = 'OTHER_ID';