From 88f68d47e539c68975ce726eb7804f4b4bfd8a4d Mon Sep 17 00:00:00 2001 From: bal7hazar Date: Tue, 28 Nov 2023 10:36:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20presets=20-=20R?= =?UTF-8?q?ename=20into=20token=20-=20Add=20token=20into=20workspace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scarb.lock | 9 +- Scarb.toml | 4 +- presets/Scarb.toml | 9 -- presets/src/erc1155/erc1155.cairo | 5 -- presets/src/lib.cairo | 13 --- {presets => token}/.gitignore | 0 {presets => token}/Scarb.lock | 0 token/Scarb.toml | 8 ++ .../src}/erc1155/erc1155.cairo | 56 +------------ .../src}/erc1155/interface.cairo | 0 .../src}/erc1155/models.cairo | 2 + {presets => token}/src/erc1155/tests.cairo | 22 ++--- {presets => token}/src/erc20/erc20.cairo | 16 +--- token/src/erc20/interface.cairo | 24 ++++++ {presets => token}/src/erc20/models.cairo | 16 ++-- {presets => token}/src/erc20/tests.cairo | 18 ++-- {presets => token}/src/erc721/erc721.cairo | 84 +++++++------------ token/src/erc721/interface.cairo | 60 +++++++++++++ {presets => token}/src/erc721/models.cairo | 0 {presets => token}/src/erc721/tests.cairo | 22 ++--- token/src/lib.cairo | 32 +++++++ {presets => token}/src/tests/constants.cairo | 0 .../src/tests/test_erc1155.cairo | 0 .../src/tests/test_erc721.cairo | 0 {presets => token}/src/tests/utils.cairo | 0 25 files changed, 212 insertions(+), 188 deletions(-) delete mode 100644 presets/Scarb.toml delete mode 100644 presets/src/erc1155/erc1155.cairo delete mode 100644 presets/src/lib.cairo rename {presets => token}/.gitignore (100%) rename {presets => token}/Scarb.lock (100%) create mode 100644 token/Scarb.toml rename {presets/src/erc1155 => token/src}/erc1155/erc1155.cairo (84%) rename {presets/src/erc1155 => token/src}/erc1155/interface.cairo (100%) rename {presets/src/erc1155 => token/src}/erc1155/models.cairo (96%) rename {presets => token}/src/erc1155/tests.cairo (97%) rename {presets => token}/src/erc20/erc20.cairo (96%) create mode 100644 token/src/erc20/interface.cairo rename {presets => token}/src/erc20/models.cairo (59%) rename {presets => token}/src/erc20/tests.cairo (97%) rename {presets => token}/src/erc721/erc721.cairo (90%) create mode 100644 token/src/erc721/interface.cairo rename {presets => token}/src/erc721/models.cairo (100%) rename {presets => token}/src/erc721/tests.cairo (98%) create mode 100644 token/src/lib.cairo rename {presets => token}/src/tests/constants.cairo (100%) rename {presets => token}/src/tests/test_erc1155.cairo (100%) rename {presets => token}/src/tests/test_erc721.cairo (100%) rename {presets => token}/src/tests/utils.cairo (100%) diff --git a/Scarb.lock b/Scarb.lock index 7b6f657c..32bdc800 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -38,7 +38,7 @@ dependencies = [ [[package]] name = "origami" -version = "0.1.0" +version = "0.0.0" dependencies = [ "cubit", "dojo", @@ -52,3 +52,10 @@ dependencies = [ "dojo", "origami", ] + +[[package]] +name = "token" +version = "0.0.0" +dependencies = [ + "dojo", +] diff --git a/Scarb.toml b/Scarb.toml index 7c419124..a6c76780 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,8 +1,8 @@ [workspace] -members = ["crates", "examples/*"] +members = ["crates", "examples/*", "token"] [workspace.package] -version = "0.1.0" +version = "0.0.0" description = "Community-maintained libraries for Cairo" homepage = "https://github.com/dojoengine/origami" authors = ["bal7hazar@proton.me"] diff --git a/presets/Scarb.toml b/presets/Scarb.toml deleted file mode 100644 index 67dbbe95..00000000 --- a/presets/Scarb.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "presets" -version = "0.0.0" -description = "Implementations of ERC standards for the Dojo framework." -homepage = "https://github.com/dojoengine/origami/tree/presets" - -[dependencies] -dojo = { git = "https://github.com/dojoengine/dojo.git", rev = "d62ec8a" } -openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "4eafccf" } \ No newline at end of file diff --git a/presets/src/erc1155/erc1155.cairo b/presets/src/erc1155/erc1155.cairo deleted file mode 100644 index aeb7f33a..00000000 --- a/presets/src/erc1155/erc1155.cairo +++ /dev/null @@ -1,5 +0,0 @@ -mod erc1155; -mod models; -mod interface; - -use erc1155::ERC1155; diff --git a/presets/src/lib.cairo b/presets/src/lib.cairo deleted file mode 100644 index c6129437..00000000 --- a/presets/src/lib.cairo +++ /dev/null @@ -1,13 +0,0 @@ -mod erc721 { - mod models; - mod erc721; - use erc721::ERC721; - #[cfg(test)] - mod tests; -} - -#[cfg(test)] -mod tests { - mod constants; - mod utils; -} diff --git a/presets/.gitignore b/token/.gitignore similarity index 100% rename from presets/.gitignore rename to token/.gitignore diff --git a/presets/Scarb.lock b/token/Scarb.lock similarity index 100% rename from presets/Scarb.lock rename to token/Scarb.lock diff --git a/token/Scarb.toml b/token/Scarb.toml new file mode 100644 index 00000000..7e3eaf76 --- /dev/null +++ b/token/Scarb.toml @@ -0,0 +1,8 @@ +[package] +name = "token" +version = "0.0.0" +description = "Implementations of ERC standards for the Dojo framework." +homepage = "https://github.com/dojoengine/origami/tree/presets" + +[dependencies] +dojo.workspace = true \ No newline at end of file diff --git a/presets/src/erc1155/erc1155/erc1155.cairo b/token/src/erc1155/erc1155.cairo similarity index 84% rename from presets/src/erc1155/erc1155/erc1155.cairo rename to token/src/erc1155/erc1155.cairo index ff633a30..331fcefc 100644 --- a/presets/src/erc1155/erc1155/erc1155.cairo +++ b/token/src/erc1155/erc1155.cairo @@ -1,8 +1,8 @@ #[starknet::contract] mod ERC1155 { - use dojo_erc::token::erc1155::models::{ERC1155Meta, ERC1155OperatorApproval, ERC1155Balance}; - use dojo_erc::token::erc1155::interface; - use dojo_erc::token::erc1155::interface::{IERC1155, IERC1155CamelOnly}; + use token::erc1155::models::{ERC1155Meta, ERC1155OperatorApproval, ERC1155Balance}; + use token::erc1155::interface; + use token::erc1155::interface::{IERC1155, IERC1155CamelOnly}; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; use starknet::ContractAddress; use starknet::{get_caller_address, get_contract_address}; @@ -73,26 +73,6 @@ mod ERC1155 { self.initializer(name, symbol, base_uri); } - // - // External - // - - // #[external(v0)] - // impl SRC5Impl of ISRC5 { - // fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { - // let unsafe_state = src5::SRC5::unsafe_new_contract_state(); - // src5::SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id) - // } - // } - - // #[external(v0)] - // impl SRC5CamelImpl of ISRC5Camel { - // fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { - // let unsafe_state = src5::SRC5::unsafe_new_contract_state(); - // src5::SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) - // } - // } - #[external(v0)] impl ERC1155MetadataImpl of interface::IERC1155Metadata { fn name(self: @ContractState) -> felt252 { @@ -297,11 +277,6 @@ mod ERC1155 { fn initializer(ref self: ContractState, name: felt252, symbol: felt252, base_uri: felt252) { let meta = ERC1155Meta { token: get_contract_address(), name, symbol, base_uri }; set!(self.world(), (meta)); - // let mut unsafe_state = src5::SRC5::unsafe_new_contract_state(); - // src5::SRC5::InternalImpl::register_interface(ref unsafe_state, interface::IERC721_ID); - // src5::SRC5::InternalImpl::register_interface( - // ref unsafe_state, interface::IERC721_METADATA_ID - // ); } fn _is_approved_for_all_or_owner( @@ -329,9 +304,6 @@ mod ERC1155 { data: Array ) { self.update_balances(from, to, id, amount); - // assert( - // _check_on_erc1155_received(from, to, id, data), Errors::SAFE_TRANSFER_FAILED - // ); self .emit_event( @@ -359,9 +331,6 @@ mod ERC1155 { let id = *ids_span.pop_front().unwrap(); let amount = *amounts_span.pop_front().unwrap(); self.update_balances(from, to, id, amount); - // assert( - // _check_on_erc1155_received(from, to, id, data), Errors::SAFE_TRANSFER_FAILED - // ); }; self @@ -413,25 +382,6 @@ mod ERC1155 { data: Span ) { self._mint(to, id, amount); - // assert( - // _check_on_erc1155_received(Zeroable::zero(), to, id, data), - // Errors::SAFE_MINT_FAILED - // ); } } -//#[internal] -// fn _check_on_erc1155_received( -// from: ContractAddress, to: ContractAddress, token_id: u256, data: Span -// ) -> bool { -// if (DualCaseSRC5 { contract_address: to } -// .supports_interface(interface::IERC1155_RECEIVER_ID)) { -// DualCaseERC1155Receiver { contract_address: to } -// .on_erc1155_received( -// get_caller_address(), from, token_id, data -// ) == interface::IERC1155_RECEIVER_ID -// } else { -// DualCaseSRC5 { contract_address: to }.supports_interface(account::interface::ISRC6_ID) -// } -// } - } diff --git a/presets/src/erc1155/erc1155/interface.cairo b/token/src/erc1155/interface.cairo similarity index 100% rename from presets/src/erc1155/erc1155/interface.cairo rename to token/src/erc1155/interface.cairo diff --git a/presets/src/erc1155/erc1155/models.cairo b/token/src/erc1155/models.cairo similarity index 96% rename from presets/src/erc1155/erc1155/models.cairo rename to token/src/erc1155/models.cairo index 3e1861e3..a448b469 100644 --- a/presets/src/erc1155/erc1155/models.cairo +++ b/token/src/erc1155/models.cairo @@ -1,3 +1,5 @@ +// Starknet imports + use starknet::ContractAddress; #[derive(Model, Copy, Drop, Serde)] diff --git a/presets/src/erc1155/tests.cairo b/token/src/erc1155/tests.cairo similarity index 97% rename from presets/src/erc1155/tests.cairo rename to token/src/erc1155/tests.cairo index 6951695b..3447581b 100644 --- a/presets/src/erc1155/tests.cairo +++ b/token/src/erc1155/tests.cairo @@ -1,16 +1,16 @@ -use dojo_erc::tests::utils; -use dojo_erc::tests::constants::{ +use token::tests::utils; +use token::tests::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, OPERATOR, OTHER, NAME, SYMBOL, URI, TOKEN_ID, TOKEN_AMOUNT, TOKEN_ID_2, TOKEN_AMOUNT_2 }; -use dojo_erc::token::erc1155::ERC1155::ERC1155Impl; -use dojo_erc::token::erc1155::ERC1155::ERC1155CamelOnlyImpl; -use dojo_erc::token::erc1155::ERC1155::ERC1155MetadataImpl; -use dojo_erc::token::erc1155::ERC1155::InternalImpl; -use dojo_erc::token::erc1155::ERC1155::WorldInteractionsImpl; -use dojo_erc::token::erc1155::ERC1155::{TransferSingle, TransferBatch, ApprovalForAll}; -use dojo_erc::token::erc1155::ERC1155; +use token::erc1155::ERC1155::ERC1155Impl; +use token::erc1155::ERC1155::ERC1155CamelOnlyImpl; +use token::erc1155::ERC1155::ERC1155MetadataImpl; +use token::erc1155::ERC1155::InternalImpl; +use token::erc1155::ERC1155::WorldInteractionsImpl; +use token::erc1155::ERC1155::{TransferSingle, TransferBatch, ApprovalForAll}; +use token::erc1155::ERC1155; use starknet::ContractAddress; use starknet::contract_address_const; use starknet::testing; @@ -18,11 +18,11 @@ use zeroable::Zeroable; use dojo::test_utils::spawn_test_world; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; -use dojo_erc::token::erc1155::models::{ +use token::erc1155::models::{ ERC1155Meta, erc_1155_meta, ERC1155OperatorApproval, erc_1155_operator_approval, ERC1155Balance, erc_1155_balance }; -use dojo_erc::token::erc1155::ERC1155::_worldContractMemberStateTrait; +use token::erc1155::ERC1155::_worldContractMemberStateTrait; use debug::PrintTrait; // diff --git a/presets/src/erc20/erc20.cairo b/token/src/erc20/erc20.cairo similarity index 96% rename from presets/src/erc20/erc20.cairo rename to token/src/erc20/erc20.cairo index d21be836..7550d963 100644 --- a/presets/src/erc20/erc20.cairo +++ b/token/src/erc20/erc20.cairo @@ -1,20 +1,12 @@ -// External imports - -use openzeppelin::token::erc20::interface; - #[starknet::contract] mod ERC20 { - use dojo_erc::token::erc20_models::{ERC20Allowance, ERC20Balance, ERC20Meta}; + use token::erc20::models::{ERC20Allowance, ERC20Balance, ERC20Meta}; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; + use token::erc20::interface; use integer::BoundedInt; use starknet::ContractAddress; use starknet::{get_caller_address, get_contract_address}; use zeroable::Zeroable; - use debug::PrintTrait; - - // Local imports - - use super::interface::{IERC20, IERC20CamelOnly}; #[storage] @@ -71,7 +63,7 @@ mod ERC20 { // #[external(v0)] - impl ERC20Impl of IERC20 { + impl ERC20Impl of interface::IERC20 { fn name(self: @ContractState) -> felt252 { self.get_meta().name } @@ -127,7 +119,7 @@ mod ERC20 { } #[external(v0)] - impl ERC20CamelOnlyImpl of IERC20CamelOnly { + impl ERC20CamelOnlyImpl of interface::IERC20CamelOnly { fn totalSupply(self: @ContractState) -> u256 { ERC20Impl::total_supply(self) } diff --git a/token/src/erc20/interface.cairo b/token/src/erc20/interface.cairo new file mode 100644 index 00000000..e0778409 --- /dev/null +++ b/token/src/erc20/interface.cairo @@ -0,0 +1,24 @@ +use starknet::ContractAddress; + +#[starknet::interface] +trait IERC20 { + fn name(self: @TState) -> felt252; + fn symbol(self: @TState) -> felt252; + fn decimals(self: @TState) -> u8; + fn total_supply(self: @TState) -> u256; + fn balance_of(self: @TState, account: ContractAddress) -> u256; + fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; + fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; + fn transfer_from( + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ) -> bool; + fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; +} + +trait IERC20CamelOnly { + fn totalSupply(self: @TState) -> u256; + fn balanceOf(self: @TState, account: ContractAddress) -> u256; + fn transferFrom( + ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 + ) -> bool; +} diff --git a/presets/src/erc20/models.cairo b/token/src/erc20/models.cairo similarity index 59% rename from presets/src/erc20/models.cairo rename to token/src/erc20/models.cairo index f19cda5c..13612f0f 100644 --- a/presets/src/erc20/models.cairo +++ b/token/src/erc20/models.cairo @@ -1,27 +1,31 @@ +// Starknet imports + +use starknet::ContractAddress; + #[derive(Model, Copy, Drop, Serde)] struct ERC20Balance { #[key] - token: starknet::ContractAddress, + token: ContractAddress, #[key] - account: starknet::ContractAddress, + account: ContractAddress, amount: u256, } #[derive(Model, Copy, Drop, Serde)] struct ERC20Allowance { #[key] - token: starknet::ContractAddress, + token: ContractAddress, #[key] - owner: starknet::ContractAddress, + owner: ContractAddress, #[key] - spender: starknet::ContractAddress, + spender: ContractAddress, amount: u256, } #[derive(Model, Copy, Drop, Serde)] struct ERC20Meta { #[key] - token: starknet::ContractAddress, + token: ContractAddress, name: felt252, symbol: felt252, total_supply: u256, diff --git a/presets/src/erc20/tests.cairo b/token/src/erc20/tests.cairo similarity index 97% rename from presets/src/erc20/tests.cairo rename to token/src/erc20/tests.cairo index 669cfc7c..7db32972 100644 --- a/presets/src/erc20/tests.cairo +++ b/token/src/erc20/tests.cairo @@ -1,15 +1,15 @@ use integer::BoundedInt; use integer::u256; use integer::u256_from_felt252; -use dojo_erc::tests::utils; -use dojo_erc::tests::constants::{ +use token::tests::utils; +use token::tests::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, NAME, SYMBOL, DECIMALS, SUPPLY, VALUE }; -use dojo_erc::token::erc20::ERC20::Approval; -use dojo_erc::token::erc20::ERC20::ERC20Impl; -use dojo_erc::token::erc20::ERC20::InternalImpl; -use dojo_erc::token::erc20::ERC20::Transfer; -use dojo_erc::token::erc20::ERC20; +use token::erc20::ERC20::Approval; +use token::erc20::ERC20::ERC20Impl; +use token::erc20::ERC20::InternalImpl; +use token::erc20::ERC20::Transfer; +use token::erc20::ERC20; use starknet::ContractAddress; use starknet::contract_address_const; use starknet::testing; @@ -17,10 +17,10 @@ use zeroable::Zeroable; use dojo::test_utils::spawn_test_world; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; -use dojo_erc::token::erc20_models::{ +use token::erc20::models::{ ERC20Allowance, erc_20_allowance, ERC20Balance, erc_20_balance, ERC20Meta, erc_20_meta }; -use dojo_erc::token::erc20::ERC20::_worldContractMemberStateTrait; +use token::erc20::ERC20::_worldContractMemberStateTrait; use debug::PrintTrait; // diff --git a/presets/src/erc721/erc721.cairo b/token/src/erc721/erc721.cairo similarity index 90% rename from presets/src/erc721/erc721.cairo rename to token/src/erc721/erc721.cairo index 4a181988..36d75b89 100644 --- a/presets/src/erc721/erc721.cairo +++ b/token/src/erc721/erc721.cairo @@ -1,67 +1,27 @@ -// External imports - -use openzeppelin::token::erc721::interface; - #[starknet::contract] mod ERC721 { - // Core imports - + use token::erc721::models::{ + ERC721Meta, ERC721OperatorApproval, ERC721Owner, ERC721Balance, ERC721TokenApproval + }; + use token::erc721::interface; + use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; use integer::BoundedInt; - use zeroable::Zeroable; - - // Starknet imports - use starknet::ContractAddress; use starknet::{get_caller_address, get_contract_address}; + use zeroable::Zeroable; - // Dojo imports - - use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; - - // External imports - - use openzeppelin::token::erc721::erc721::ERC721; - use openzeppelin::introspection::interface::{ISRC5, ISRC5Camel}; - use openzeppelin::introspection::src5::SRC5Component; - - // Internal imports - - use presets::erc721::models::{ - ERC721Meta, ERC721OperatorApproval, ERC721Owner, ERC721Balance, ERC721TokenApproval, - }; - - // Local imports - - use super::interface; - - // Components - - component!(path: SRC5Component, storage: src5, event: SRC5Event); - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - #[abi(embed_v0)] - impl SRC5CamelImpl = SRC5Component::SRC5CamelImpl; - impl SRC5InternalImpl = SRC5Component::InternalImpl; - impl SRC5EventCopy of Copy {} - - // Storage #[storage] struct Storage { _world: ContractAddress, - #[substorage(v0)] - src5: SRC5Component::Storage } - // Events - #[event] #[derive(Copy, Drop, starknet::Event)] enum Event { Transfer: Transfer, Approval: Approval, - ApprovalForAll: ApprovalForAll, - SRC5Event: SRC5Component::Event, + ApprovalForAll: ApprovalForAll } #[derive(Copy, Drop, starknet::Event)] @@ -94,6 +54,8 @@ mod ERC721 { const INVALID_RECEIVER: felt252 = 'ERC721: invalid receiver'; const ALREADY_MINTED: felt252 = 'ERC721: token already minted'; const WRONG_SENDER: felt252 = 'ERC721: wrong sender'; + const SAFE_MINT_FAILED: felt252 = 'ERC721: safe mint failed'; + const SAFE_TRANSFER_FAILED: felt252 = 'ERC721: safe transfer failed'; } #[constructor] @@ -111,10 +73,6 @@ mod ERC721 { self._mint(recipient, token_id); } - // - // External - // - #[external(v0)] impl ERC721MetadataImpl of interface::IERC721Metadata { fn name(self: @ContractState) -> felt252 { @@ -135,7 +93,8 @@ mod ERC721 { #[external(v0)] impl ERC721MetadataCamelOnlyImpl of interface::IERC721MetadataCamelOnly { fn tokenURI(self: @ContractState, tokenId: u256) -> felt252 { - self.token_uri(tokenId) + assert(self._exists(tokenId), Errors::INVALID_TOKEN_ID); + self.get_uri(tokenId) } } @@ -197,8 +156,7 @@ mod ERC721 { assert( self._is_approved_or_owner(get_caller_address(), token_id), Errors::UNAUTHORIZED ); - // TODO: move to real safe transfer when support of SRC6 is enabled - self.transfer_from(from, to, token_id); + self._safe_transfer(from, to, token_id, data); } } @@ -332,8 +290,6 @@ mod ERC721 { fn initializer(ref self: ContractState, name: felt252, symbol: felt252, base_uri: felt252) { let meta = ERC721Meta { token: get_contract_address(), name, symbol, base_uri }; set!(self.world(), (meta)); - self.src5.register_interface(interface::IERC721_ID); - self.src5.register_interface(interface::IERC721_METADATA_ID); } fn _owner_of(self: @ContractState, token_id: u256) -> ContractAddress { @@ -414,5 +370,21 @@ mod ERC721 { self.emit_event(Transfer { from: owner, to: Zeroable::zero(), token_id }); } + + fn _safe_mint( + ref self: ContractState, to: ContractAddress, token_id: u256, data: Span + ) { + self._mint(to, token_id); + } + + fn _safe_transfer( + ref self: ContractState, + from: ContractAddress, + to: ContractAddress, + token_id: u256, + data: Span + ) { + self._transfer(from, to, token_id); + } } } diff --git a/token/src/erc721/interface.cairo b/token/src/erc721/interface.cairo new file mode 100644 index 00000000..730ad2e0 --- /dev/null +++ b/token/src/erc721/interface.cairo @@ -0,0 +1,60 @@ +use starknet::ContractAddress; + +const IERC721_ID: felt252 = 0x33eb2f84c309543403fd69f0d0f363781ef06ef6faeb0131ff16ea3175bd943; +const IERC721_METADATA_ID: felt252 = + 0x6069a70848f907fa57668ba1875164eb4dcee693952468581406d131081bbd; +const IERC721_RECEIVER_ID: felt252 = + 0x3a0dff5f70d80458ad14ae37bb182a728e3c8cdda0402a5daa86620bdf910bc; + +#[starknet::interface] +trait IERC721 { + fn balance_of(self: @TState, account: ContractAddress) -> u256; + fn owner_of(self: @TState, token_id: u256) -> ContractAddress; + fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256); + fn safe_transfer_from( + ref self: TState, + from: ContractAddress, + to: ContractAddress, + token_id: u256, + data: Span + ); + fn approve(ref self: TState, to: ContractAddress, token_id: u256); + fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); + fn get_approved(self: @TState, token_id: u256) -> ContractAddress; + fn is_approved_for_all( + self: @TState, owner: ContractAddress, operator: ContractAddress + ) -> bool; +} + +#[starknet::interface] +trait IERC721CamelOnly { + fn balanceOf(self: @TState, account: ContractAddress) -> u256; + fn ownerOf(self: @TState, tokenId: u256) -> ContractAddress; + fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256); + fn safeTransferFrom( + ref self: TState, + from: ContractAddress, + to: ContractAddress, + tokenId: u256, + data: Span + ); + fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); + fn getApproved(self: @TState, tokenId: u256) -> ContractAddress; + fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool; +} + +// +// IERC721Metadata +// + +#[starknet::interface] +trait IERC721Metadata { + fn name(self: @TState) -> felt252; + fn symbol(self: @TState) -> felt252; + fn token_uri(self: @TState, token_id: u256) -> felt252; +} + +#[starknet::interface] +trait IERC721MetadataCamelOnly { + fn tokenURI(self: @TState, tokenId: u256) -> felt252; +} diff --git a/presets/src/erc721/models.cairo b/token/src/erc721/models.cairo similarity index 100% rename from presets/src/erc721/models.cairo rename to token/src/erc721/models.cairo diff --git a/presets/src/erc721/tests.cairo b/token/src/erc721/tests.cairo similarity index 98% rename from presets/src/erc721/tests.cairo rename to token/src/erc721/tests.cairo index 778a4814..646daaa2 100644 --- a/presets/src/erc721/tests.cairo +++ b/token/src/erc721/tests.cairo @@ -20,22 +20,22 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; // Internal imports -use presets::tests::utils; -use presets::tests::constants::{ +use token::tests::utils; +use token::tests::constants::{ ZERO, OWNER, SPENDER, RECIPIENT, OPERATOR, OTHER, NAME, SYMBOL, URI, TOKEN_ID }; -use presets::erc721::ERC721::ERC721Impl; -use presets::erc721::ERC721::ERC721CamelOnlyImpl; -use presets::erc721::ERC721::ERC721MetadataImpl; -use presets::erc721::ERC721::InternalImpl; -use presets::erc721::ERC721::WorldInteractionsImpl; -use presets::erc721::ERC721::{Approval, ApprovalForAll, Transfer}; -use presets::erc721::ERC721; -use presets::erc721::models::{ +use token::erc721::ERC721::ERC721Impl; +use token::erc721::ERC721::ERC721CamelOnlyImpl; +use token::erc721::ERC721::ERC721MetadataImpl; +use token::erc721::ERC721::InternalImpl; +use token::erc721::ERC721::WorldInteractionsImpl; +use token::erc721::ERC721::{Approval, ApprovalForAll, Transfer}; +use token::erc721::ERC721; +use token::erc721::models::{ ERC721Meta, erc_721_meta, ERC721OperatorApproval, erc_721_operator_approval, ERC721Owner, erc_721_owner, ERC721Balance, erc_721_balance, ERC721TokenApproval, erc_721_token_approval }; -use presets::erc721::ERC721::_worldContractMemberStateTrait; +use token::erc721::ERC721::_worldContractMemberStateTrait; // // Setup diff --git a/token/src/lib.cairo b/token/src/lib.cairo new file mode 100644 index 00000000..bc0ed295 --- /dev/null +++ b/token/src/lib.cairo @@ -0,0 +1,32 @@ +mod erc20 { + mod interface; + mod models; + mod erc20; + use erc20::ERC20; + #[cfg(test)] + mod tests; +} + +mod erc721 { + mod interface; + mod models; + mod erc721; + use erc721::ERC721; + #[cfg(test)] + mod tests; +} + +mod erc1155 { + mod interface; + mod models; + mod erc1155; + use erc1155::ERC1155; + #[cfg(test)] + mod tests; +} + +#[cfg(test)] +mod tests { + mod constants; + mod utils; +} diff --git a/presets/src/tests/constants.cairo b/token/src/tests/constants.cairo similarity index 100% rename from presets/src/tests/constants.cairo rename to token/src/tests/constants.cairo diff --git a/presets/src/tests/test_erc1155.cairo b/token/src/tests/test_erc1155.cairo similarity index 100% rename from presets/src/tests/test_erc1155.cairo rename to token/src/tests/test_erc1155.cairo diff --git a/presets/src/tests/test_erc721.cairo b/token/src/tests/test_erc721.cairo similarity index 100% rename from presets/src/tests/test_erc721.cairo rename to token/src/tests/test_erc721.cairo diff --git a/presets/src/tests/utils.cairo b/token/src/tests/utils.cairo similarity index 100% rename from presets/src/tests/utils.cairo rename to token/src/tests/utils.cairo