Skip to content

Commit

Permalink
Merge pull request #60 from horuslabsio/v3.1.0
Browse files Browse the repository at this point in the history
v0.3.1
  • Loading branch information
Darlington02 authored Dec 18, 2024
2 parents 0ab871e + 950798a commit 1d7db21
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 134 deletions.
78 changes: 15 additions & 63 deletions Scarb.lock
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand All @@ -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",
]
5 changes: 3 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "token_bound_accounts"
version = "0.3.0"
version = "0.3.1"
edition = "2024_07"
authors = ["Horus Labs <[email protected]>"]
description = "A port of ERC6551 to Starknet"
Expand All @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion src/accountV3/accountV3.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/components/account/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/lockable/lockable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/permissionable/permissionable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/presets/account_preset.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/components/signatory/signatory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/upgradeable/upgradeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 2 additions & 40 deletions src/registry/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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<felt252> = array![
token_contract.into(),
token_id.low.into(),
Expand Down Expand Up @@ -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<felt252> = 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::<ContractAddress>::deserialize(ref address).unwrap()
}
}
}
4 changes: 2 additions & 2 deletions src/test_helper/erc721_helper.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ trait IERC721<TContractState> {

#[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);
Expand Down
19 changes: 0 additions & 19 deletions tests/test_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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__();
Expand Down

0 comments on commit 1d7db21

Please sign in to comment.