diff --git a/Scarb.lock b/Scarb.lock index 1b6e8d4..4b7c06b 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -1,28 +1,11 @@ # Code generated by scarb DO NOT EDIT. version = 1 -[[package]] -name = "openzeppelin" -version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" -dependencies = [ - "openzeppelin_access", - "openzeppelin_account", - "openzeppelin_finance", - "openzeppelin_governance", - "openzeppelin_introspection", - "openzeppelin_merkle_tree", - "openzeppelin_presets", - "openzeppelin_security", - "openzeppelin_token", - "openzeppelin_upgrades", - "openzeppelin_utils", -] - [[package]] name = "openzeppelin_access" version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +source = "registry+https://scarbs.xyz/" +checksum = "sha256:541bb8fdf1ad17fe0d275b00acb9f0d7f56ea5534741e21535ac3fda2c600281" dependencies = [ "openzeppelin_introspection", "openzeppelin_utils", @@ -31,25 +14,18 @@ dependencies = [ [[package]] name = "openzeppelin_account" version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +source = "registry+https://scarbs.xyz/" +checksum = "sha256:c4e11609fdd1f4c3d3004cd1468711bd2ea664739c9e59a4b270567fe4c23ee3" dependencies = [ "openzeppelin_introspection", "openzeppelin_utils", ] -[[package]] -name = "openzeppelin_finance" -version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" -dependencies = [ - "openzeppelin_access", - "openzeppelin_token", -] - [[package]] name = "openzeppelin_governance" version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +source = "registry+https://scarbs.xyz/" +checksum = "sha256:b7e0142d88d69a8c367aea8c9dc7f659f27372551efc23f39a0cf71a189c1302" dependencies = [ "openzeppelin_access", "openzeppelin_introspection", @@ -58,50 +34,25 @@ dependencies = [ [[package]] name = "openzeppelin_introspection" version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" - -[[package]] -name = "openzeppelin_merkle_tree" -version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" - -[[package]] -name = "openzeppelin_presets" -version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" -dependencies = [ - "openzeppelin_access", - "openzeppelin_account", - "openzeppelin_finance", - "openzeppelin_introspection", - "openzeppelin_token", - "openzeppelin_upgrades", -] - -[[package]] -name = "openzeppelin_security" -version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +source = "registry+https://scarbs.xyz/" +checksum = "sha256:892433a4a1ea0fc9cf7cdb01e06ddc2782182abcc188e4ea5dd480906d006cf8" [[package]] name = "openzeppelin_token" version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +source = "registry+https://scarbs.xyz/" +checksum = "sha256:77997a7e217b69674c34b402dc0c7b2210540db66a56087572679c31896eaabb" dependencies = [ "openzeppelin_account", "openzeppelin_governance", "openzeppelin_introspection", ] -[[package]] -name = "openzeppelin_upgrades" -version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" - [[package]] name = "openzeppelin_utils" version = "0.17.0" -source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.17.0#bf5d02c25c989ccc24f3ab42ec649617d3f21289" +source = "registry+https://scarbs.xyz/" +checksum = "sha256:36d93e353f42fd6b824abcd8b4b51c3f5d02c893c5f886ae81403b0368aa5fde" [[package]] name = "snforge_scarb_plugin" @@ -118,8 +69,9 @@ dependencies = [ [[package]] name = "token_bound_accounts" -version = "0.3.0" +version = "0.3.1" dependencies = [ - "openzeppelin", + "openzeppelin_introspection", + "openzeppelin_token", "snforge_std", ] diff --git a/Scarb.toml b/Scarb.toml index aa3c4d3..ead5505 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,6 +1,6 @@ [package] name = "token_bound_accounts" -version = "0.3.0" +version = "0.3.1" edition = "2024_07" authors = ["Horus Labs "] description = "A port of ERC6551 to Starknet" @@ -23,7 +23,8 @@ casm = true [dependencies] starknet = "2.8.2" -openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.17.0" } +openzeppelin_introspection = "0.17.0" +openzeppelin_token = "0.17.0" [dev-dependencies] snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.31.0" } diff --git a/src/accountV3/accountV3.cairo b/src/accountV3/accountV3.cairo index 9570a09..3740540 100644 --- a/src/accountV3/accountV3.cairo +++ b/src/accountV3/accountV3.cairo @@ -8,7 +8,7 @@ pub mod AccountV3 { // IMPORTS // ************************************************************************* use starknet::{ContractAddress, get_caller_address, get_tx_info, ClassHash, account::Call}; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component; use token_bound_accounts::components::account::account::AccountComponent; use token_bound_accounts::components::upgradeable::upgradeable::UpgradeableComponent; diff --git a/src/components/account/account.cairo b/src/components/account/account.cairo index be658e4..996c9a6 100644 --- a/src/components/account/account.cairo +++ b/src/components/account/account.cairo @@ -14,8 +14,8 @@ pub mod AccountComponent { use token_bound_accounts::utils::array_ext::ArrayExt; use token_bound_accounts::interfaces::IAccount::{IAccount, TBA_INTERFACE_ID}; - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::introspection::src5::SRC5Component::{SRC5Impl, InternalImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component::{SRC5Impl, InternalImpl}; // ************************************************************************* // STORAGE diff --git a/src/components/lockable/lockable.cairo b/src/components/lockable/lockable.cairo index 06e6192..ed111df 100644 --- a/src/components/lockable/lockable.cairo +++ b/src/components/lockable/lockable.cairo @@ -9,7 +9,7 @@ pub mod LockableComponent { use token_bound_accounts::components::account::account::AccountComponent; use token_bound_accounts::components::account::account::AccountComponent::AccountPrivateImpl; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component; // ************************************************************************* // STORAGE diff --git a/src/components/permissionable/permissionable.cairo b/src/components/permissionable/permissionable.cairo index 4e0b982..61dbb20 100644 --- a/src/components/permissionable/permissionable.cairo +++ b/src/components/permissionable/permissionable.cairo @@ -9,7 +9,7 @@ pub mod PermissionableComponent { use token_bound_accounts::components::account::account::AccountComponent; use token_bound_accounts::interfaces::IAccount::IAccount; use token_bound_accounts::components::account::account::AccountComponent::AccountPrivateImpl; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component; // ************************************************************************* // STORAGE diff --git a/src/components/presets/account_preset.cairo b/src/components/presets/account_preset.cairo index 7b022cf..ef04eab 100644 --- a/src/components/presets/account_preset.cairo +++ b/src/components/presets/account_preset.cairo @@ -4,7 +4,7 @@ #[starknet::contract] pub mod AccountPreset { use starknet::{ContractAddress, get_caller_address, ClassHash, account::Call}; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component; use token_bound_accounts::components::account::account::AccountComponent; use token_bound_accounts::components::upgradeable::upgradeable::UpgradeableComponent; diff --git a/src/components/signatory/signatory.cairo b/src/components/signatory/signatory.cairo index 4ea2277..42f0e61 100644 --- a/src/components/signatory/signatory.cairo +++ b/src/components/signatory/signatory.cairo @@ -12,7 +12,7 @@ pub mod SignatoryComponent { use token_bound_accounts::components::permissionable::permissionable::PermissionableComponent::PermissionablePrivateImpl; use token_bound_accounts::interfaces::ISRC6::{ISRC6Dispatcher, ISRC6DispatcherTrait}; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component; // ************************************************************************* // STORAGE diff --git a/src/components/upgradeable/upgradeable.cairo b/src/components/upgradeable/upgradeable.cairo index 2af41dc..5f1dd10 100644 --- a/src/components/upgradeable/upgradeable.cairo +++ b/src/components/upgradeable/upgradeable.cairo @@ -9,7 +9,7 @@ pub mod UpgradeableComponent { use token_bound_accounts::components::account::account::AccountComponent; use token_bound_accounts::components::account::account::AccountComponent::AccountPrivateImpl; - use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin_introspection::src5::SRC5Component; // ************************************************************************* // STORAGE diff --git a/src/registry/registry.cairo b/src/registry/registry.cairo index 6123237..7554a29 100644 --- a/src/registry/registry.cairo +++ b/src/registry/registry.cairo @@ -6,12 +6,11 @@ pub mod Registry { // ************************************************************************* // IMPORTS // ************************************************************************* - use core::result::ResultTrait; use core::hash::HashStateTrait; use core::pedersen::PedersenTrait; use starknet::{ - ContractAddress, get_caller_address, get_contract_address, - syscalls::{call_contract_syscall, deploy_syscall}, class_hash::ClassHash, SyscallResultTrait + ContractAddress, get_contract_address, syscalls::deploy_syscall, class_hash::ClassHash, + SyscallResultTrait }; use token_bound_accounts::interfaces::IRegistry::IRegistry; @@ -41,12 +40,6 @@ pub mod Registry { pub token_id: u256, } - // ************************************************************************* - // ERRORS - // ************************************************************************* - pub mod Errors { - pub const CALLER_IS_NOT_OWNER: felt252 = 'Registry: caller is not owner'; - } // ************************************************************************* // EXTERNAL FUNCTIONS @@ -66,9 +59,6 @@ pub mod Registry { salt: felt252, chain_id: felt252 ) -> ContractAddress { - let owner = self._get_owner(token_contract, token_id); - assert(owner == get_caller_address(), Errors::CALLER_IS_NOT_OWNER); - let mut constructor_calldata: Array = array![ token_contract.into(), token_id.low.into(), @@ -122,32 +112,4 @@ pub mod Registry { account_address.try_into().unwrap() } } - - // ************************************************************************* - // PRIVATE FUNCTIONS - // ************************************************************************* - #[generate_trait] - impl internalImpl of InternalTrait { - /// @notice internal function for getting NFT owner - /// @param token_contract contract address of NFT - // @param token_id token ID of NFT - // NB: This function aims for compatibility with all contracts (snake or camel case) but do - // not work as expected on mainnet as low level calls do not return err at the moment. - // Should work for contracts which implements CamelCase but not snake_case until starknet - // v0.15. - fn _get_owner( - self: @ContractState, token_contract: ContractAddress, token_id: u256 - ) -> ContractAddress { - let mut calldata: Array = ArrayTrait::new(); - Serde::serialize(@token_id, ref calldata); - let mut res = call_contract_syscall( - token_contract, selector!("ownerOf"), calldata.span() - ); - if (res.is_err()) { - res = call_contract_syscall(token_contract, selector!("owner_of"), calldata.span()); - } - let mut address = res.unwrap(); - Serde::::deserialize(ref address).unwrap() - } - } } diff --git a/src/test_helper/erc721_helper.cairo b/src/test_helper/erc721_helper.cairo index b957553..0646899 100644 --- a/src/test_helper/erc721_helper.cairo +++ b/src/test_helper/erc721_helper.cairo @@ -7,8 +7,8 @@ trait IERC721 { #[starknet::contract] pub mod ERC721 { - use openzeppelin::introspection::src5::SRC5Component; - use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; + use openzeppelin_introspection::src5::SRC5Component; + use openzeppelin_token::erc721::{ERC721Component, ERC721HooksEmptyImpl}; use starknet::ContractAddress; component!(path: ERC721Component, storage: erc721, event: ERC721Event); diff --git a/tests/test_registry.cairo b/tests/test_registry.cairo index f3dd91a..a97e936 100644 --- a/tests/test_registry.cairo +++ b/tests/test_registry.cairo @@ -68,25 +68,6 @@ fn test_create_account() { assert(TBA_owner == token_owner, 'acct deployed wrongly'); } -#[test] -#[should_panic(expected: ('Registry: caller is not owner',))] -fn test_create_account_should_fail_if_not_nft_owner() { - let (registry_contract_address, erc721_contract_address) = __setup__(); - let registry_dispatcher = IRegistryDispatcher { contract_address: registry_contract_address }; - - // create account - let account_class = declare("AccountPreset").unwrap().contract_class(); - let acct_class_hash = *account_class.class_hash; - registry_dispatcher - .create_account( - acct_class_hash.into(), - erc721_contract_address, - 1.try_into().unwrap(), - 245828, - 'SN_SEPOLIA' - ); -} - #[test] fn test_create_account_emits_event() { let (registry_contract_address, erc721_contract_address) = __setup__();