Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make imports more compact #509

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions starknet/src/authenticators/eth_sig.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use starknet::{ContractAddress, EthAddress};
use starknet::SyscallResult;
use starknet::{ContractAddress, EthAddress, SyscallResult};
use sx::types::{Strategy, IndexedStrategy, Choice};

#[starknet::interface]
Expand Down Expand Up @@ -48,9 +47,11 @@ mod EthSigAuthenticator {
use starknet::{ContractAddress, EthAddress, syscalls::call_contract_syscall};
use core::array::{ArrayTrait, SpanTrait};
use clone::Clone;
use sx::space::space::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{Strategy, IndexedStrategy, Choice, UserAddress};
use sx::utils::{signatures, legacy_hash::LegacyHashEthAddress};
use sx::{
space::space::{ISpaceDispatcher, ISpaceDispatcherTrait},
types::{Strategy, IndexedStrategy, Choice, UserAddress},
utils::{signatures, legacy_hash::LegacyHashEthAddress}
};

#[storage]
struct Storage {
Expand Down
17 changes: 10 additions & 7 deletions starknet/src/authenticators/eth_tx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ trait IEthTxAuthenticator<TContractState> {
#[starknet::contract]
mod EthTxAuthenticator {
use super::IEthTxAuthenticator;
use starknet::{ContractAddress, EthAddress, Felt252TryIntoEthAddress, EthAddressIntoFelt252};
use starknet::syscalls::call_contract_syscall;
use core::serde::Serde;
use core::array::{ArrayTrait, SpanTrait};
use starknet::{
ContractAddress, EthAddress, Felt252TryIntoEthAddress, EthAddressIntoFelt252,
syscalls::call_contract_syscall
};
use core::{serde::Serde, array::{ArrayTrait, SpanTrait}};
use traits::{PartialEq, TryInto, Into};
use option::OptionTrait;
use zeroable::Zeroable;
use sx::space::space::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{UserAddress, Strategy, IndexedStrategy, Choice};
use sx::utils::constants::{PROPOSE_SELECTOR, VOTE_SELECTOR, UPDATE_PROPOSAL_SELECTOR};
use sx::{
space::space::{ISpaceDispatcher, ISpaceDispatcherTrait},
types::{UserAddress, Strategy, IndexedStrategy, Choice},
utils::constants::{PROPOSE_SELECTOR, VOTE_SELECTOR, UPDATE_PROPOSAL_SELECTOR}
};

#[storage]
struct Storage {
Expand Down
7 changes: 4 additions & 3 deletions starknet/src/authenticators/stark_sig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ mod StarkSigAuthenticator {
use starknet::{ContractAddress, info};
use core::array::{ArrayTrait, SpanTrait};
use serde::Serde;
use sx::space::space::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{Strategy, IndexedStrategy, UserAddress, Choice};
use sx::utils::stark_eip712;
use sx::{
space::space::{ISpaceDispatcher, ISpaceDispatcherTrait},
types::{Strategy, IndexedStrategy, UserAddress, Choice}, utils::stark_eip712
};

#[storage]
struct Storage {
Expand Down
6 changes: 4 additions & 2 deletions starknet/src/authenticators/stark_tx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ mod StarkTxAuthenticator {
use super::IStarkTxAuthenticator;
use starknet::{ContractAddress, info};
use core::array::ArrayTrait;
use sx::space::space::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{UserAddress, Strategy, IndexedStrategy, Choice};
use sx::{
space::space::{ISpaceDispatcher, ISpaceDispatcherTrait},
types::{UserAddress, Strategy, IndexedStrategy, Choice},
};

#[storage]
struct Storage {}
Expand Down
3 changes: 1 addition & 2 deletions starknet/src/authenticators/vanilla.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use starknet::ContractAddress;
use starknet::SyscallResult;
use starknet::{ContractAddress, SyscallResult};

#[starknet::interface]
trait IVanillaAuthenticator<TContractState> {
Expand Down
6 changes: 2 additions & 4 deletions starknet/src/execution_strategies/eth_relayer.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#[starknet::contract]
mod EthRelayerExecutionStrategy {
use starknet::syscalls::send_message_to_l1_syscall;
use starknet::info::get_caller_address;
use sx::interfaces::IExecutionStrategy;
use sx::types::{Proposal};
use starknet::{syscalls::send_message_to_l1_syscall, info::get_caller_address};
use sx::{interfaces::IExecutionStrategy, types::Proposal};

#[external(v0)]
impl EthRelayerExecutionStrategy of IExecutionStrategy<ContractState> {
Expand Down
3 changes: 1 addition & 2 deletions starknet/src/external/ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Migrated lib to v2
#[starknet::contract]
mod Ownable {
use starknet::ContractAddress;
use starknet::get_caller_address;
use starknet::{ContractAddress, get_caller_address};
use zeroable::Zeroable;

#[storage]
Expand Down
11 changes: 5 additions & 6 deletions starknet/src/factory/factory.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use starknet::ContractAddress;
use starknet::ClassHash;
use starknet::{ContractAddress, ClassHash};

#[starknet::interface]
trait IFactory<TContractState> {
Expand All @@ -15,10 +14,10 @@ trait IFactory<TContractState> {
#[starknet::contract]
mod Factory {
use super::IFactory;
use starknet::ContractAddress;
use starknet::contract_address_const;
use starknet::syscalls::{deploy_syscall, call_contract_syscall};
use starknet::ClassHash;
use starknet::{
ContractAddress, ClassHash, contract_address_const,
syscalls::{deploy_syscall, call_contract_syscall}
};
use result::ResultTrait;
use array::{ArrayTrait, SpanTrait};
use sx::utils::constants::INITIALIZE_SELECTOR;
Expand Down
3 changes: 1 addition & 2 deletions starknet/src/interfaces/i_account.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use array::ArrayTrait;
use array::SpanTrait;
use array::{ArrayTrait, SpanTrait};
use starknet::account::Call;
use starknet::ContractAddress;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#[starknet::contract]
mod ProposingPowerProposalValidationStrategy {
use sx::interfaces::IProposalValidationStrategy;
use sx::types::{UserAddress, IndexedStrategy, IndexedStrategyTrait, Strategy};
use sx::interfaces::{IVotingStrategyDispatcher, IVotingStrategyDispatcherTrait};
use starknet::ContractAddress;
use starknet::info;
use sx::{
interfaces::{
IProposalValidationStrategy, IVotingStrategyDispatcher, IVotingStrategyDispatcherTrait
},
types::{UserAddress, IndexedStrategy, IndexedStrategyTrait, Strategy},
utils::{bits::BitSetter, proposition_power::_validate}
};
use starknet::{ContractAddress, info};
use traits::{Into, TryInto};
use option::OptionTrait;
use result::ResultTrait;
use array::{ArrayTrait, SpanTrait};
use serde::Serde;
use sx::utils::bits::BitSetter;
use box::BoxTrait;
use clone::Clone;
use sx::utils::proposition_power::_validate;

#[storage]
struct Storage {}
Expand Down
38 changes: 20 additions & 18 deletions starknet/src/space/space.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,33 @@ trait ISpace<TContractState> {
#[starknet::contract]
mod Space {
use super::ISpace;
use starknet::storage_access::{StorePacking, StoreUsingPacking};
use starknet::{ClassHash, ContractAddress, info, Store, syscalls};
use starknet::{
storage_access::{StorePacking, StoreUsingPacking}, ClassHash, ContractAddress, info, Store,
syscalls
};
use zeroable::Zeroable;
use array::{ArrayTrait, SpanTrait};
use clone::Clone;
use option::OptionTrait;
use hash::LegacyHash;
use traits::{Into, TryInto};

use sx::interfaces::{
IProposalValidationStrategyDispatcher, IProposalValidationStrategyDispatcherTrait,
IVotingStrategyDispatcher, IVotingStrategyDispatcherTrait, IExecutionStrategyDispatcher,
IExecutionStrategyDispatcherTrait
};
use sx::types::{
UserAddress, Choice, FinalizationStatus, Strategy, IndexedStrategy, Proposal,
PackedProposal, IndexedStrategyTrait, IndexedStrategyImpl, UpdateSettingsCalldata,
NoUpdateU32, NoUpdateStrategy, NoUpdateArray
use sx::{
interfaces::{
IProposalValidationStrategyDispatcher, IProposalValidationStrategyDispatcherTrait,
IVotingStrategyDispatcher, IVotingStrategyDispatcherTrait, IExecutionStrategyDispatcher,
IExecutionStrategyDispatcherTrait
},
types::{
UserAddress, Choice, FinalizationStatus, Strategy, IndexedStrategy, Proposal,
PackedProposal, IndexedStrategyTrait, IndexedStrategyImpl, UpdateSettingsCalldata,
NoUpdateU32, NoUpdateStrategy, NoUpdateArray
},
utils::{
reinitializable::{Reinitializable}, ReinitializableImpl, bits::BitSetter,
legacy_hash::LegacyHashChoice, constants::INITIALIZE_SELECTOR
},
external::ownable::Ownable
};
use sx::utils::reinitializable::Reinitializable;
use sx::utils::ReinitializableImpl;
use sx::utils::bits::BitSetter;
use sx::utils::legacy_hash::LegacyHashChoice;
use sx::external::ownable::Ownable;
use sx::utils::constants::INITIALIZE_SELECTOR;

#[storage]
struct Storage {
Expand Down
10 changes: 4 additions & 6 deletions starknet/src/types/proposal.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use sx::types::user_address::UserAddressTrait;
use clone::Clone;
use serde::Serde;
use starknet::ContractAddress;
use starknet::storage_access::StorePacking;
use starknet::Store;
use sx::utils::math::pow;
use starknet::{ContractAddress, storage_access::StorePacking, Store};
use sx::{
utils::math::pow, types::{FinalizationStatus, UserAddress, user_address::UserAddressTrait}
};
use traits::{Into, TryInto};
use sx::types::{FinalizationStatus, UserAddress};
use option::OptionTrait;
use debug::PrintTrait;

Expand Down
3 changes: 1 addition & 2 deletions starknet/src/utils/merkle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use core::traits::Into;
use array::{ArrayTrait, Span, SpanTrait};
use option::OptionTrait;
use serde::Serde;
use sx::types::UserAddress;
use clone::Clone;
use hash::{LegacyHash};
use sx::utils::legacy_hash::LegacyHashSpanFelt252;
use sx::{types::UserAddress, utils::legacy_hash::LegacyHashSpanFelt252};

/// Leaf struct for the merkle tree
#[derive(Copy, Clone, Drop, Serde)]
Expand Down
13 changes: 7 additions & 6 deletions starknet/src/utils/proposition_power.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use sx::interfaces::IProposalValidationStrategy;
use sx::types::{UserAddress, IndexedStrategy, IndexedStrategyTrait, Strategy};
use sx::interfaces::{IVotingStrategyDispatcher, IVotingStrategyDispatcherTrait};
use starknet::ContractAddress;
use starknet::info;
use sx::{
interfaces::{
IProposalValidationStrategy, IVotingStrategyDispatcher, IVotingStrategyDispatcherTrait
},
types::{UserAddress, IndexedStrategy, IndexedStrategyTrait, Strategy}, utils::bits::BitSetter
};
use starknet::{ContractAddress, info};
use traits::{Into, TryInto};
use option::OptionTrait;
use result::ResultTrait;
use array::{ArrayTrait, SpanTrait};
use serde::Serde;
use sx::utils::bits::BitSetter;
use box::BoxTrait;
use clone::Clone;

Expand Down
3 changes: 1 addition & 2 deletions starknet/src/utils/reinitializable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ trait IReinitializable<TContractState> {
#[starknet::contract]
mod Reinitializable {
use super::IReinitializable;
use starknet::ContractAddress;
use starknet::syscalls::call_contract_syscall;
use starknet::{ContractAddress, syscalls::call_contract_syscall};
use core::array::{ArrayTrait, SpanTrait};

#[storage]
Expand Down
19 changes: 11 additions & 8 deletions starknet/src/utils/signatures.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ use traits::Into;
use clone::Clone;
use core::keccak;
use integer::u256_from_felt252;
use sx::types::{Strategy, IndexedStrategy, Choice};
use sx::utils::Felt252ArrayIntoU256Array;
use sx::utils::math::pow;
use sx::utils::constants::{
DOMAIN_TYPEHASH_LOW, DOMAIN_TYPEHASH_HIGH, ETHEREUM_PREFIX, STRATEGY_TYPEHASH_LOW,
STRATEGY_TYPEHASH_HIGH, INDEXED_STRATEGY_TYPEHASH_LOW, INDEXED_STRATEGY_TYPEHASH_HIGH,
PROPOSE_TYPEHASH_LOW, PROPOSE_TYPEHASH_HIGH, VOTE_TYPEHASH_LOW, VOTE_TYPEHASH_HIGH,
UPDATE_PROPOSAL_TYPEHASH_LOW, UPDATE_PROPOSAL_TYPEHASH_HIGH
use sx::{
types::{Strategy, IndexedStrategy, Choice},
utils::{
Felt252ArrayIntoU256Array, math::pow,
constants::{
DOMAIN_TYPEHASH_LOW, DOMAIN_TYPEHASH_HIGH, ETHEREUM_PREFIX, STRATEGY_TYPEHASH_LOW,
STRATEGY_TYPEHASH_HIGH, INDEXED_STRATEGY_TYPEHASH_LOW, INDEXED_STRATEGY_TYPEHASH_HIGH,
PROPOSE_TYPEHASH_LOW, PROPOSE_TYPEHASH_HIGH, VOTE_TYPEHASH_LOW, VOTE_TYPEHASH_HIGH,
UPDATE_PROPOSAL_TYPEHASH_LOW, UPDATE_PROPOSAL_TYPEHASH_HIGH
}
}
};

impl ContractAddressIntoU256 of Into<ContractAddress, u256> {
Expand Down
3 changes: 0 additions & 3 deletions starknet/src/utils/single_slot_proof.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use core::zeroable::Zeroable;
use array::ArrayTrait;

// Each word is 64 bits
#[derive(Serde, Option, Drop)]
struct StorageSlot {
Expand Down
22 changes: 12 additions & 10 deletions starknet/src/utils/stark_eip712.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ use array::{ArrayTrait, SpanTrait};
use traits::Into;
use box::BoxTrait;
use serde::Serde;
use sx::types::{Strategy, IndexedStrategy, Choice};
use sx::utils::{
struct_hash::StructHash,
constants::{
STARKNET_MESSAGE, DOMAIN_TYPEHASH, PROPOSE_TYPEHASH, VOTE_TYPEHASH,
UPDATE_PROPOSAL_TYPEHASH, ERC165_ACCOUNT_INTERFACE_ID, ERC165_OLD_ACCOUNT_INTERFACE_ID
use sx::{
types::{Strategy, IndexedStrategy, Choice},
utils::{
struct_hash::StructHash,
constants::{
STARKNET_MESSAGE, DOMAIN_TYPEHASH, PROPOSE_TYPEHASH, VOTE_TYPEHASH,
UPDATE_PROPOSAL_TYPEHASH, ERC165_ACCOUNT_INTERFACE_ID, ERC165_OLD_ACCOUNT_INTERFACE_ID
}
},
interfaces::{
AccountABIDispatcher, AccountABIDispatcherTrait, AccountCamelABIDispatcher,
AccountCamelABIDispatcherTrait
}
};
use sx::interfaces::{
AccountABIDispatcher, AccountABIDispatcherTrait, AccountCamelABIDispatcher,
AccountCamelABIDispatcherTrait
};

fn verify_propose_sig(
domain_hash: felt252,
Expand Down
14 changes: 8 additions & 6 deletions starknet/src/utils/struct_hash.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use array::{ArrayTrait, SpanTrait};
use hash::LegacyHash;
use serde::Serde;
use sx::types::{Strategy, IndexedStrategy};
use sx::utils::{
constants::{
STARKNET_MESSAGE, DOMAIN_TYPEHASH, STRATEGY_TYPEHASH, INDEXED_STRATEGY_TYPEHASH,
U256_TYPEHASH, PROPOSE_TYPEHASH, VOTE_TYPEHASH, UPDATE_PROPOSAL_TYPEHASH
use sx::{
types::{Strategy, IndexedStrategy},
utils::{
constants::{
STARKNET_MESSAGE, DOMAIN_TYPEHASH, STRATEGY_TYPEHASH, INDEXED_STRATEGY_TYPEHASH,
U256_TYPEHASH, PROPOSE_TYPEHASH, VOTE_TYPEHASH, UPDATE_PROPOSAL_TYPEHASH
},
legacy_hash::LegacyHashSpanFelt252,
}
};
use sx::utils::legacy_hash::LegacyHashSpanFelt252;

trait StructHash<T> {
fn struct_hash(self: @T) -> felt252;
Expand Down
7 changes: 4 additions & 3 deletions starknet/src/voting_strategies/eth_balance_of.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
mod EthBalanceOfVotingStrategy {
use traits::Into;
use starknet::{EthAddress, ContractAddress};
use sx::interfaces::IVotingStrategy;
use sx::types::{UserAddress, UserAddressTrait};
use sx::utils::single_slot_proof::SingleSlotProof;
use sx::{
interfaces::IVotingStrategy, types::{UserAddress, UserAddressTrait},
utils::single_slot_proof::SingleSlotProof
};

#[storage]
struct Storage {}
Expand Down
6 changes: 3 additions & 3 deletions starknet/src/voting_strategies/merkle_whitelist.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[starknet::contract]
mod MerkleWhitelistVotingStrategy {
use sx::interfaces::IVotingStrategy;
use sx::{
interfaces::IVotingStrategy, types::UserAddress, utils::merkle::{assert_valid_proof, Leaf}
};
use serde::Serde;
use sx::types::UserAddress;
use array::{ArrayTrait, Span, SpanTrait};
use option::OptionTrait;
use sx::utils::merkle::{assert_valid_proof, Leaf};

const LEAF_SIZE: usize = 4; // Serde::<Leaf>::serialize().len()

Expand Down
3 changes: 1 addition & 2 deletions starknet/src/voting_strategies/vanilla.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[starknet::contract]
mod VanillaVotingStrategy {
use sx::interfaces::IVotingStrategy;
use sx::types::UserAddress;
use sx::{interfaces::IVotingStrategy, types::UserAddress};
use starknet::ContractAddress;

#[storage]
Expand Down