Skip to content

Commit

Permalink
chore: v3 structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Aug 15, 2024
1 parent 48898f3 commit 0e88371
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 44 deletions.
6 changes: 3 additions & 3 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ version = 1

[[package]]
name = "snforge_std"
version = "0.20.1"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.20.1#fea2db8f2b20148cc15ee34b08de12028eb42942"
version = "0.27.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de"

[[package]]
name = "token_bound_accounts"
version = "0.2.1"
version = "0.3.0"
dependencies = [
"snforge_std",
]
4 changes: 1 addition & 3 deletions src/account/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ mod AccountComponent {
}

fn __validate_deploy__(
self: @ComponentState<TContractState>,
class_hash: felt252,
contract_address_salt: felt252,
ref self: ComponentState<TContractState>, token_contract: ContractAddress, token_id: u256
) -> felt252 {
self._validate_transaction()
}
Expand Down
3 changes: 3 additions & 0 deletions src/components.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod lockable;
mod permissionable;
mod upgradeable;
1 change: 1 addition & 0 deletions src/components/lockable.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod lockable;
1 change: 1 addition & 0 deletions src/components/lockable/lockable.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// lockable component
1 change: 1 addition & 0 deletions src/components/permissionable.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod permissionable;
1 change: 1 addition & 0 deletions src/components/permissionable/permissionable.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// permissionable component
1 change: 1 addition & 0 deletions src/components/upgradeable.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod upgradeable;
File renamed without changes.
4 changes: 1 addition & 3 deletions src/interfaces/IAccount.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ trait IAccount<TContractState> {
fn is_valid_signer(self: @TContractState, signer: ContractAddress) -> felt252;
fn __validate__(ref self: TContractState, calls: Array<Call>) -> felt252;
fn __validate_declare__(self: @TContractState, class_hash: felt252) -> felt252;
fn __validate_deploy__(
self: @TContractState, class_hash: felt252, contract_address_salt: felt252
) -> felt252;
fn __validate_deploy__(ref self: TContractState, token_contract: ContractAddress, token_id: u256) -> felt252;
fn __execute__(ref self: TContractState, calls: Array<Call>) -> Array<Span<felt252>>;
fn token(self: @TContractState) -> (ContractAddress, u256);
fn owner(self: @TContractState) -> ContractAddress;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ mod account;
mod interfaces;
mod presets;
mod test_helper;
mod upgradeable;
mod components;
2 changes: 1 addition & 1 deletion src/presets/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod Account {
use starknet::{ContractAddress, get_caller_address};
use starknet::ClassHash;
use token_bound_accounts::account::AccountComponent;
use token_bound_accounts::upgradeable::UpgradeableComponent;
use token_bound_accounts::components::upgradeable::upgradeable::UpgradeableComponent;
use token_bound_accounts::interfaces::IUpgradeable::IUpgradeable;

component!(path: AccountComponent, storage: account, event: AccountEvent);
Expand Down
4 changes: 2 additions & 2 deletions src/registry/registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ mod Registry {
use core::pedersen::PedersenTrait;
use starknet::{
ContractAddress, get_caller_address, syscalls::call_contract_syscall, class_hash::ClassHash,
class_hash::Felt252TryIntoClassHash, syscalls::deploy_syscall, SyscallResultTrait
class_hash::Felt252TryIntoClassHash, syscalls::deploy_syscall, SyscallResultTrait, storage::Map
};
use token_bound_accounts::interfaces::IERC721::{IERC721DispatcherTrait, IERC721Dispatcher};
use token_bound_accounts::interfaces::IRegistry::IRegistry;

#[storage]
struct Storage {
registry_deployed_accounts: LegacyMap<
registry_deployed_accounts: Map<
(ContractAddress, u256), u8
>, // tracks no. of deployed accounts by registry for an NFT
}
Expand Down
16 changes: 8 additions & 8 deletions src/test_helper/account_upgrade.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ trait IUpgradedAccount<TContractState> {
fn __validate__(ref self: TContractState, calls: Array<Call>) -> felt252;
fn __validate_declare__(self: @TContractState, class_hash: felt252) -> felt252;
fn __validate_deploy__(
self: @TContractState,
class_hash: felt252,
contract_address_salt: felt252,
public_key: felt252
ref self: TContractState,
_public_key: felt252,
token_contract: ContractAddress,
token_id: u256
) -> felt252;
fn __execute__(ref self: TContractState, calls: Array<Call>) -> Array<Span<felt252>>;
fn token(self: @TContractState) -> (ContractAddress, u256);
Expand Down Expand Up @@ -107,10 +107,10 @@ mod UpgradedAccount {
}

fn __validate_deploy__(
self: @ContractState,
class_hash: felt252,
contract_address_salt: felt252,
public_key: felt252
ref self: ContractState,
_public_key: felt252,
token_contract: ContractAddress,
token_id: u256
) -> felt252 {
self.validate_transaction()
}
Expand Down
12 changes: 6 additions & 6 deletions src/test_helper/erc721_helper.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ mod ERC721 {
use starknet::ContractAddress;
use starknet::get_caller_address;
use core::zeroable::Zeroable;
use starknet::contract_address_to_felt252;
use starknet::{contract_address_to_felt252, storage::Map};

#[storage]
struct Storage {
name: felt252,
symbol: felt252,
owners: LegacyMap::<u256, ContractAddress>,
balances: LegacyMap::<ContractAddress, u256>,
token_approvals: LegacyMap::<u256, ContractAddress>,
operator_approvals: LegacyMap::<(ContractAddress, ContractAddress), bool>,
token_uri: LegacyMap<u256, felt252>,
owners: Map::<u256, ContractAddress>,
balances: Map::<ContractAddress, u256>,
token_approvals: Map::<u256, ContractAddress>,
operator_approvals: Map::<(ContractAddress, ContractAddress), bool>,
token_uri: Map<u256, felt252>,
}

#[event]
Expand Down
18 changes: 4 additions & 14 deletions src/test_helper/simple_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ trait ISimpleAccount<TContractState> {
) -> felt252;
fn __validate__(ref self: TContractState, calls: Array<Call>) -> felt252;
fn __validate_declare__(self: @TContractState, class_hash: felt252) -> felt252;
fn __validate_deploy__(
self: @TContractState,
class_hash: felt252,
contract_address_salt: felt252,
public_key: felt252
) -> felt252;
fn __validate_deploy__(ref self: TContractState, public_key: felt252) -> felt252;
fn __execute__(ref self: TContractState, calls: Array<Call>) -> Array<Span<felt252>>;
}

Expand All @@ -33,8 +28,8 @@ mod SimpleAccount {
}

#[constructor]
fn constructor(ref self: ContractState, _public_key: felt252) {
self._public_key.write(_public_key);
fn constructor(ref self: ContractState, public_key: felt252) {
self._public_key.write(public_key);
}

#[abi(embed_v0)]
Expand All @@ -54,12 +49,7 @@ mod SimpleAccount {
self._is_valid_signature(hash, signature)
}

fn __validate_deploy__(
self: @ContractState,
class_hash: felt252,
contract_address_salt: felt252,
public_key: felt252
) -> felt252 {
fn __validate_deploy__(ref self: ContractState, public_key: felt252) -> felt252 {
self.validate_transaction()
}

Expand Down
3 changes: 0 additions & 3 deletions src/upgradeable.cairo

This file was deleted.

0 comments on commit 0e88371

Please sign in to comment.