Skip to content

Commit 214e8cd

Browse files
committed
chore: scarb fmt
1 parent 3940ca2 commit 214e8cd

30 files changed

+331
-337
lines changed

src/accountV3/accountV3.cairo

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ pub mod AccountV3 {
77
// *************************************************************************
88
// IMPORTS
99
// *************************************************************************
10-
use starknet::{ContractAddress, get_caller_address, get_tx_info, ClassHash, account::Call};
1110
use openzeppelin_introspection::src5::SRC5Component;
12-
11+
use starknet::account::Call;
12+
use starknet::{ClassHash, ContractAddress, get_caller_address, get_tx_info};
1313
use token_bound_accounts::components::account::account::AccountComponent;
14-
use token_bound_accounts::components::upgradeable::upgradeable::UpgradeableComponent;
1514
use token_bound_accounts::components::lockable::lockable::LockableComponent;
16-
use token_bound_accounts::components::signatory::signatory::SignatoryComponent;
1715
use token_bound_accounts::components::permissionable::permissionable::PermissionableComponent;
18-
use token_bound_accounts::interfaces::{
19-
IUpgradeable::IUpgradeable, IExecutable::IExecutable, ILockable::ILockable,
20-
ISignatory::ISignatory, IPermissionable::IPermissionable, IAccountV3::IAccountV3
21-
};
16+
use token_bound_accounts::components::signatory::signatory::SignatoryComponent;
17+
use token_bound_accounts::components::upgradeable::upgradeable::UpgradeableComponent;
18+
use token_bound_accounts::interfaces::IAccountV3::IAccountV3;
19+
use token_bound_accounts::interfaces::IExecutable::IExecutable;
20+
use token_bound_accounts::interfaces::ILockable::ILockable;
21+
use token_bound_accounts::interfaces::IPermissionable::IPermissionable;
22+
use token_bound_accounts::interfaces::ISignatory::ISignatory;
23+
use token_bound_accounts::interfaces::IUpgradeable::IUpgradeable;
2224

2325
// *************************************************************************
2426
// COMPONENTS
@@ -57,7 +59,7 @@ pub mod AccountV3 {
5759
#[substorage(v0)]
5860
permissionable: PermissionableComponent::Storage,
5961
#[substorage(v0)]
60-
src5: SRC5Component::Storage
62+
src5: SRC5Component::Storage,
6163
}
6264

6365
// *************************************************************************
@@ -77,7 +79,7 @@ pub mod AccountV3 {
7779
#[flat]
7880
PermissionableEvent: PermissionableComponent::Event,
7981
#[flat]
80-
SRC5Event: SRC5Component::Event
82+
SRC5Event: SRC5Component::Event,
8183
}
8284

8385
// *************************************************************************
@@ -98,7 +100,7 @@ pub mod AccountV3 {
98100
token_id: u256,
99101
registry: ContractAddress,
100102
implementation_hash: felt252,
101-
salt: felt252
103+
salt: felt252,
102104
) {
103105
self.account.initializer(token_contract, token_id, registry, implementation_hash, salt);
104106
}
@@ -119,7 +121,7 @@ pub mod AccountV3 {
119121
operator: ContractAddress,
120122
from: ContractAddress,
121123
token_id: u256,
122-
data: Span<felt252>
124+
data: Span<felt252>,
123125
) -> felt252 {
124126
let (_token_contract, _token_id, _chain_id) = self.account.token();
125127
let tx_info = get_tx_info().unbox();
@@ -144,7 +146,7 @@ pub mod AccountV3 {
144146
operator: ContractAddress,
145147
from: ContractAddress,
146148
token_id: u256,
147-
data: Span<felt252>
149+
data: Span<felt252>,
148150
) -> felt252 {
149151
self.on_erc721_received(operator, from, token_id, data)
150152
}
@@ -171,7 +173,7 @@ pub mod AccountV3 {
171173
/// @param hash The message hash
172174
/// @param signature The signature to be validated
173175
fn is_valid_signature(
174-
self: @ContractState, hash: felt252, signature: Span<felt252>
176+
self: @ContractState, hash: felt252, signature: Span<felt252>,
175177
) -> felt252 {
176178
self.signatory._is_valid_signature(hash, signature)
177179
}
@@ -253,7 +255,7 @@ pub mod AccountV3 {
253255
fn set_permission(
254256
ref self: ContractState,
255257
permissioned_addresses: Array<ContractAddress>,
256-
permissions: Array<bool>
258+
permissions: Array<bool>,
257259
) {
258260
// set permissions
259261
self.permissionable._set_permission(permissioned_addresses, permissions)
@@ -263,7 +265,7 @@ pub mod AccountV3 {
263265
// @param owner tokenbound account owner
264266
// @param permissioned_address address to check permission for
265267
fn has_permission(
266-
self: @ContractState, owner: ContractAddress, permissioned_address: ContractAddress
268+
self: @ContractState, owner: ContractAddress, permissioned_address: ContractAddress,
267269
) -> bool {
268270
self.permissionable._has_permission(owner, permissioned_address)
269271
}

src/components.cairo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod account;
22
pub mod lockable;
33
pub mod permissionable;
4-
pub mod upgradeable;
54
pub mod presets;
65
pub mod signatory;
6+
pub mod upgradeable;

src/components/account/account.cairo

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ pub mod AccountComponent {
33
// *************************************************************************
44
// IMPORTS
55
// *************************************************************************
6-
use starknet::storage::StoragePointerReadAccess;
7-
use core::{
8-
result::ResultTrait, hash::HashStateTrait, pedersen::PedersenTrait, num::traits::zero::Zero
9-
};
10-
use starknet::{
11-
get_tx_info, get_contract_address, ContractAddress, account::Call,
12-
syscalls::call_contract_syscall, storage::StoragePointerWriteAccess
13-
};
14-
use token_bound_accounts::utils::array_ext::ArrayExt;
15-
use token_bound_accounts::interfaces::IAccount::{IAccount, TBA_INTERFACE_ID};
16-
6+
use core::hash::HashStateTrait;
7+
use core::num::traits::zero::Zero;
8+
use core::pedersen::PedersenTrait;
9+
use core::result::ResultTrait;
1710
use openzeppelin_introspection::src5::SRC5Component;
18-
use openzeppelin_introspection::src5::SRC5Component::{SRC5Impl, InternalImpl};
11+
use openzeppelin_introspection::src5::SRC5Component::{InternalImpl, SRC5Impl};
12+
use starknet::account::Call;
13+
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
14+
use starknet::syscalls::call_contract_syscall;
15+
use starknet::{ContractAddress, get_contract_address, get_tx_info};
16+
use token_bound_accounts::interfaces::IAccount::{IAccount, TBA_INTERFACE_ID};
17+
use token_bound_accounts::utils::array_ext::ArrayExt;
1918

2019
// *************************************************************************
2120
// STORAGE
@@ -25,7 +24,7 @@ pub mod AccountComponent {
2524
account_token_contract: ContractAddress, // contract address of NFT
2625
account_token_id: u256, // token ID of NFT
2726
context: Context, // account deployment details
28-
state: u256, // account state
27+
state: u256 // account state
2928
}
3029

3130
// *************************************************************************
@@ -35,7 +34,7 @@ pub mod AccountComponent {
3534
#[derive(Drop, starknet::Event)]
3635
pub enum Event {
3736
TBACreated: TBACreated,
38-
TransactionExecuted: TransactionExecuted
37+
TransactionExecuted: TransactionExecuted,
3938
}
4039

4140
/// @notice Emitted exactly once when the account is initialized
@@ -46,7 +45,7 @@ pub mod AccountComponent {
4645
pub account_address: ContractAddress,
4746
pub parent_account: ContractAddress,
4847
pub token_contract: ContractAddress,
49-
pub token_id: u256
48+
pub token_id: u256,
5049
}
5150

5251
/// @notice Emitted when the account executes a transaction
@@ -58,7 +57,7 @@ pub mod AccountComponent {
5857
pub hash: felt252,
5958
#[key]
6059
pub account_address: ContractAddress,
61-
pub response: Span<Span<felt252>>
60+
pub response: Span<Span<felt252>>,
6261
}
6362

6463
// *************************************************************************
@@ -68,7 +67,7 @@ pub mod AccountComponent {
6867
struct Context {
6968
registry: ContractAddress,
7069
implementation_hash: felt252,
71-
salt: felt252
70+
salt: felt252,
7271
}
7372

7473
// *************************************************************************
@@ -88,7 +87,7 @@ pub mod AccountComponent {
8887
TContractState,
8988
+HasComponent<TContractState>,
9089
+Drop<TContractState>,
91-
impl SRC5: SRC5Component::HasComponent<TContractState>
90+
impl SRC5: SRC5Component::HasComponent<TContractState>,
9291
> of IAccount<ComponentState<TContractState>> {
9392
/// @notice gets the NFT owner
9493
/// @param token_contract the contract address of the NFT
@@ -112,7 +111,7 @@ pub mod AccountComponent {
112111
// @notice check that account supports TBA interface
113112
// @param interface_id interface to be checked against
114113
fn supports_interface(
115-
self: @ComponentState<TContractState>, interface_id: felt252
114+
self: @ComponentState<TContractState>, interface_id: felt252,
116115
) -> bool {
117116
get_dep_component!(self, SRC5).supports_interface(interface_id)
118117
}
@@ -126,7 +125,7 @@ pub mod AccountComponent {
126125
TContractState,
127126
+HasComponent<TContractState>,
128127
+Drop<TContractState>,
129-
impl SRC5: SRC5Component::HasComponent<TContractState>
128+
impl SRC5: SRC5Component::HasComponent<TContractState>,
130129
> of AccountPrivateTrait<TContractState> {
131130
/// @notice initializes the account by setting the initial token contract and token id
132131
fn initializer(
@@ -135,7 +134,7 @@ pub mod AccountComponent {
135134
token_id: u256,
136135
registry: ContractAddress,
137136
implementation_hash: felt252,
138-
salt: felt252
137+
salt: felt252,
139138
) {
140139
let owner = self._get_owner(token_contract, token_id);
141140
assert(owner.is_non_zero(), Errors::UNAUTHORIZED);
@@ -159,16 +158,16 @@ pub mod AccountComponent {
159158
account_address: get_contract_address(),
160159
parent_account: owner,
161160
token_contract,
162-
token_id
163-
}
161+
token_id,
162+
},
164163
);
165164
}
166165

167166
// @notice executes a transaction
168167
// @notice this should be called within an `execute` method in implementation contracts
169168
// @param calls an array of transactions to be executed
170169
fn _execute(
171-
ref self: ComponentState<TContractState>, mut calls: Array<Call>
170+
ref self: ComponentState<TContractState>, mut calls: Array<Call>,
172171
) -> Array<Span<felt252>> {
173172
// update state
174173
self._update_state();
@@ -183,7 +182,7 @@ pub mod AccountComponent {
183182
let response = retdata.span();
184183
self
185184
.emit(
186-
TransactionExecuted { hash, account_address: get_contract_address(), response }
185+
TransactionExecuted { hash, account_address: get_contract_address(), response },
187186
);
188187
retdata
189188
}
@@ -207,12 +206,12 @@ pub mod AccountComponent {
207206
// Should work for contracts which implements CamelCase but not snake_case until starknet
208207
// v0.15.
209208
fn _get_owner(
210-
self: @ComponentState<TContractState>, token_contract: ContractAddress, token_id: u256
209+
self: @ComponentState<TContractState>, token_contract: ContractAddress, token_id: u256,
211210
) -> ContractAddress {
212211
let mut calldata: Array<felt252> = ArrayTrait::new();
213212
Serde::serialize(@token_id, ref calldata);
214213
let mut res = call_contract_syscall(
215-
token_contract, selector!("ownerOf"), calldata.span()
214+
token_contract, selector!("ownerOf"), calldata.span(),
216215
);
217216
if (res.is_err()) {
218217
res = call_contract_syscall(token_contract, selector!("owner_of"), calldata.span());
@@ -237,7 +236,7 @@ pub mod AccountComponent {
237236
token_id: u256,
238237
registry: ContractAddress,
239238
implementation: felt252,
240-
salt: felt252
239+
salt: felt252,
241240
) -> bool {
242241
let constructor_calldata_hash = PedersenTrait::new(0)
243242
.update(token_contract.into())
@@ -274,7 +273,7 @@ pub mod AccountComponent {
274273
/// @notice internal function for executing transactions
275274
/// @param calls An array of transactions to be executed
276275
fn _execute_calls(
277-
ref self: ComponentState<TContractState>, mut calls: Array<Call>
276+
ref self: ComponentState<TContractState>, mut calls: Array<Call>,
278277
) -> Array<Span<felt252>> {
279278
let mut result: Array<Span<felt252>> = ArrayTrait::new();
280279
let mut calls = calls;
@@ -292,12 +291,12 @@ pub mod AccountComponent {
292291
let mut data = array!['multicall-failed', index];
293292
data.append_all(err.span());
294293
panic(data);
295-
}
294+
},
296295
}
297296
},
298-
Option::None(_) => { break (); }
297+
Option::None(_) => { break (); },
299298
};
300-
};
299+
}
301300
result
302301
}
303302
}

src/components/lockable/lockable.cairo

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ pub mod LockableComponent {
33
// *************************************************************************
44
// IMPORTS
55
// *************************************************************************
6-
use starknet::storage::StoragePointerWriteAccess;
7-
use starknet::storage::StoragePointerReadAccess;
8-
use starknet::{ContractAddress, get_caller_address, get_block_timestamp};
9-
6+
use openzeppelin_introspection::src5::SRC5Component;
7+
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
8+
use starknet::{ContractAddress, get_block_timestamp, get_caller_address};
109
use token_bound_accounts::components::account::account::AccountComponent;
1110
use token_bound_accounts::components::account::account::AccountComponent::AccountPrivateImpl;
12-
use openzeppelin_introspection::src5::SRC5Component;
1311

1412
// *************************************************************************
1513
// STORAGE
1614
// *************************************************************************
1715
#[storage]
1816
pub struct Storage {
19-
lock_until: u64
17+
lock_until: u64,
2018
}
2119

2220
// *************************************************************************
@@ -25,7 +23,7 @@ pub mod LockableComponent {
2523
#[event]
2624
#[derive(Drop, starknet::Event)]
2725
pub enum Event {
28-
AccountLocked: AccountLocked
26+
AccountLocked: AccountLocked,
2927
}
3028

3129
/// @notice Emitted when the account is locked
@@ -66,15 +64,15 @@ pub mod LockableComponent {
6664
+HasComponent<TContractState>,
6765
+Drop<TContractState>,
6866
impl Account: AccountComponent::HasComponent<TContractState>,
69-
impl SRC5: SRC5Component::HasComponent<TContractState>
67+
impl SRC5: SRC5Component::HasComponent<TContractState>,
7068
> of LockablePrivateTrait<TContractState> {
7169
// @notice locks an account
7270
// @param lock_until time at which this account will no longer be locked
7371
fn _lock(ref self: ComponentState<TContractState>, lock_until: u64) {
7472
let current_timestamp = get_block_timestamp();
7573
// check that lock_until is not set in the past and is not greater than 1 year
7674
assert(
77-
lock_until <= current_timestamp + YEAR_TO_SECONDS, Errors::EXCEEDS_MAX_LOCK_TIME
75+
lock_until <= current_timestamp + YEAR_TO_SECONDS, Errors::EXCEEDS_MAX_LOCK_TIME,
7876
);
7977
assert(lock_until > current_timestamp, Errors::INVALID_LOCK_TIME);
8078

@@ -91,8 +89,8 @@ pub mod LockableComponent {
9189
AccountLocked {
9290
account: get_caller_address(),
9391
locked_at: current_timestamp,
94-
lock_until: lock_until
95-
}
92+
lock_until: lock_until,
93+
},
9694
);
9795
}
9896

0 commit comments

Comments
 (0)