Skip to content

Commit

Permalink
use the latest edition of scarb
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Jan 10, 2024
1 parent e114e4b commit ad6b357
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 119 deletions.
7 changes: 7 additions & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ version = "0.1.0"
description = "Contracts for governance of Starknet-native protocols"
homepage = "https://ekubo.org"
cairo-version = "2.4.3"
edition = '2023_10'



[dependencies]
starknet = "=2.4.3"

[[target.starknet-contract]]
allowed-libfuncs-list.name = "audited"
casm = true

[tool.fmt]
sort-module-level-items = true
12 changes: 6 additions & 6 deletions src/airdrop.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::array::{Array};
use governance::interfaces::erc20::{IERC20Dispatcher};
use starknet::{ContractAddress};
use array::{Array};

#[derive(Copy, Drop, Serde, Hash, PartialEq)]
struct Claim {
Expand All @@ -25,11 +25,11 @@ trait IAirdrop<TStorage> {

#[starknet::contract]
mod Airdrop {
use super::{IAirdrop, ContractAddress, Claim, IERC20Dispatcher};
use core::array::{ArrayTrait, SpanTrait};
use core::hash::{LegacyHash};
use governance::interfaces::erc20::{IERC20DispatcherTrait};
use hash::{LegacyHash};
use array::{ArrayTrait, SpanTrait};
use starknet::{ContractAddressIntoFelt252};
use super::{IAirdrop, ContractAddress, Claim, IERC20Dispatcher};

fn lt<X, +Copy<X>, +Into<X, u256>>(lhs: @X, rhs: @X) -> bool {
let a: u256 = (*lhs).into();
Expand All @@ -43,9 +43,9 @@ mod Airdrop {
Option::Some(proof_element) => {
compute_pedersen_root(
if lt(@current, proof_element) {
pedersen::pedersen(current, *proof_element)
core::pedersen::pedersen(current, *proof_element)
} else {
pedersen::pedersen(*proof_element, current)
core::pedersen::pedersen(*proof_element, current)
},
proof
)
Expand Down
29 changes: 14 additions & 15 deletions src/airdrop_test.cairo
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use governance::governance_token::{
IGovernanceTokenDispatcherTrait, GovernanceToken, IGovernanceTokenDispatcher
};
use array::{ArrayTrait};
use debug::PrintTrait;
use core::array::{ArrayTrait};
use core::hash::{LegacyHash};
use core::option::{OptionTrait};

use core::result::{Result, ResultTrait};
use core::traits::{TryInto, Into};
use governance::airdrop::{
IAirdropDispatcher, IAirdropDispatcherTrait, Airdrop, Airdrop::compute_pedersen_root, Claim,
Airdrop::lt
};
use hash::{LegacyHash};
use governance::governance_token::{
IGovernanceTokenDispatcherTrait, GovernanceToken, IGovernanceTokenDispatcher
};
use governance::governance_token_test::{deploy as deploy_token};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use starknet::class_hash::Felt252TryIntoClassHash;
use starknet::testing::{pop_log};
use starknet::{
get_contract_address, deploy_syscall, ClassHash, contract_address_const, ContractAddress
};
use starknet::testing::{pop_log};
use governance::governance_token_test::{deploy as deploy_token};
use starknet::class_hash::Felt252TryIntoClassHash;
use traits::{TryInto, Into};

use result::{Result, ResultTrait};
use option::{OptionTrait};

fn deploy(token: ContractAddress, root: felt252) -> IAirdropDispatcher {
let mut constructor_args: Array<felt252> = ArrayTrait::new();
Expand Down Expand Up @@ -189,9 +188,9 @@ fn test_claim_two_claims() {
let leaf_b = LegacyHash::hash(0, claim_b);

let root = if lt(@leaf_a, @leaf_b) {
pedersen::pedersen(leaf_a, leaf_b)
core::pedersen::pedersen(leaf_a, leaf_b)
} else {
pedersen::pedersen(leaf_b, leaf_a)
core::pedersen::pedersen(leaf_b, leaf_a)
};

let airdrop = deploy(token.contract_address, root);
Expand Down
12 changes: 6 additions & 6 deletions src/call_trait.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use core::array::{ArrayTrait, SpanTrait};
use core::hash::{LegacyHash, HashStateTrait, Hash};
use core::result::{ResultTrait};
use core::traits::{Into};
use starknet::account::{Call};
use starknet::{ContractAddress, ContractAddressIntoFelt252};
use array::{ArrayTrait, SpanTrait};
use traits::{Into};
use hash::{LegacyHash};
use starknet::{SyscallResult, syscalls::call_contract_syscall};
use starknet::account::{Call};
use result::{ResultTrait};

impl HashCall<S, +hash::HashStateTrait<S>, +Drop<S>, +Copy<S>> of hash::Hash<@Call, S> {
impl HashCall<S, +HashStateTrait<S>, +Drop<S>, +Copy<S>> of Hash<@Call, S> {
fn update_state(state: S, value: @Call) -> S {
let mut s = state.update((*value.to).into()).update(*value.selector);

Expand Down
9 changes: 4 additions & 5 deletions src/call_trait_test.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use debug::PrintTrait;
use core::array::{Array, ArrayTrait};
use core::hash::{LegacyHash};
use core::serde::{Serde};
use governance::call_trait::{CallTrait, HashCall};
use starknet::{contract_address_const, account::{Call}};
use array::{Array, ArrayTrait};
use governance::governance_token_test::{deploy as deploy_token};
use serde::{Serde};
use hash::{LegacyHash};
use starknet::{contract_address_const, account::{Call}};

#[test]
#[available_gas(300000000)]
Expand Down
12 changes: 6 additions & 6 deletions src/factory.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use starknet::{ContractAddress};
use governance::airdrop::{IAirdropDispatcher};
use governance::governance_token::{IGovernanceTokenDispatcher};
use governance::governor::{Config as GovernorConfig};
use governance::governor::{IGovernorDispatcher};
use governance::governance_token::{IGovernanceTokenDispatcher};
use governance::airdrop::{IAirdropDispatcher};
use governance::timelock::{ITimelockDispatcher};
use starknet::{ContractAddress};

#[derive(Copy, Drop, Serde)]
struct AirdropConfig {
Expand Down Expand Up @@ -43,13 +43,13 @@ trait IFactory<TContractState> {

#[starknet::contract]
mod Factory {
use core::result::{ResultTrait};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use starknet::{ClassHash, deploy_syscall, get_caller_address};
use super::{
IFactory, DeploymentParameters, DeploymentResult, ContractAddress,
IGovernanceTokenDispatcher, IAirdropDispatcher, IGovernorDispatcher, ITimelockDispatcher
};
use core::result::{ResultTrait};
use starknet::{ClassHash, deploy_syscall, get_caller_address};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};

#[storage]
struct Storage {
Expand Down
31 changes: 15 additions & 16 deletions src/factory_test.cairo
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
use array::{ArrayTrait};
use debug::PrintTrait;
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use governance::governor::{Config as GovernorConfig};
use core::array::{ArrayTrait};
use core::option::{OptionTrait};

use core::result::{Result, ResultTrait};
use core::traits::{TryInto};
use governance::airdrop::{Airdrop};
use governance::airdrop::{IAirdropDispatcherTrait};
use governance::factory::{
IFactoryDispatcher, IFactoryDispatcherTrait, Factory, DeploymentParameters, AirdropConfig,
TimelockConfig,
};
use governance::governance_token::{GovernanceToken};
use governance::governance_token::{IGovernanceTokenDispatcherTrait};
use governance::governor::{Config as GovernorConfig};
use governance::governor::{Governor};

use governance::governor::{IGovernorDispatcherTrait};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use governance::timelock::{ITimelockDispatcherTrait};
use governance::timelock::{Timelock};
use governance::airdrop::{Airdrop};
use starknet::class_hash::{Felt252TryIntoClassHash};
use starknet::testing::{set_contract_address, set_block_timestamp, pop_log};
use starknet::{
get_contract_address, deploy_syscall, ClassHash, contract_address_const, ContractAddress,
};
use starknet::class_hash::{Felt252TryIntoClassHash};
use starknet::testing::{set_contract_address, set_block_timestamp, pop_log};
use traits::{TryInto};

use governance::governor::{IGovernorDispatcherTrait};
use governance::governance_token::{IGovernanceTokenDispatcherTrait};
use governance::airdrop::{IAirdropDispatcherTrait};
use governance::timelock::{ITimelockDispatcherTrait};

use result::{Result, ResultTrait};
use option::{OptionTrait};

fn deploy() -> IFactoryDispatcher {
let mut constructor_args: Array<felt252> = ArrayTrait::new();
Expand Down
12 changes: 6 additions & 6 deletions src/governance_token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ trait IGovernanceToken<TStorage> {

#[starknet::contract]
mod GovernanceToken {
use core::integer::{u256_safe_divmod, u256_as_non_zero};
use core::num::traits::zero::{Zero};
use core::option::{OptionTrait};
use core::traits::{Into, TryInto};
use governance::interfaces::erc20::{IERC20};
use super::{IGovernanceToken, ContractAddress};
use traits::{Into, TryInto};
use option::{OptionTrait};
use starknet::{get_caller_address, get_block_timestamp, StorePacking};
use zeroable::{Zeroable};
use integer::{u256_safe_divmod, u256_as_non_zero};
use super::{IGovernanceToken, ContractAddress};

#[derive(Copy, Drop, PartialEq)]
struct DelegatedSnapshot {
Expand Down Expand Up @@ -81,7 +81,7 @@ mod GovernanceToken {
self
.emit(
Transfer {
from: Zeroable::zero(), to: get_caller_address(), value: total_supply.into()
from: Zero::zero(), to: get_caller_address(), value: total_supply.into()
}
);
}
Expand Down
20 changes: 10 additions & 10 deletions src/governance_token_test.cairo
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use array::{ArrayTrait};
use debug::PrintTrait;
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use core::array::{ArrayTrait};
use core::num::traits::zero::{Zero};
use core::option::{OptionTrait};
use core::result::{Result, ResultTrait};
use core::traits::{TryInto};

use governance::governance_token::{
IGovernanceTokenDispatcher, IGovernanceTokenDispatcherTrait, GovernanceToken,
GovernanceToken::{DelegatedSnapshotStorePacking, DelegatedSnapshot},
};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use starknet::class_hash::Felt252TryIntoClassHash;
use starknet::testing::{set_contract_address, set_block_timestamp, pop_log};
use starknet::{
get_contract_address, deploy_syscall, ClassHash, contract_address_const, ContractAddress,
};
use starknet::class_hash::Felt252TryIntoClassHash;
use starknet::testing::{set_contract_address, set_block_timestamp, pop_log};
use traits::{TryInto};

use result::{Result, ResultTrait};
use option::{OptionTrait};

fn deploy(
name: felt252, symbol: felt252, supply: u128
Expand Down Expand Up @@ -414,7 +414,7 @@ fn test_delegate_undelegate() {
token.delegate(delegatee);

set_block_timestamp(5);
token.delegate(Zeroable::zero());
token.delegate(Zero::zero());
set_block_timestamp(8);

assert(token.get_delegated(delegatee) == 0, 'delegated');
Expand Down
22 changes: 11 additions & 11 deletions src/governor.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use core::array::{Array};
use core::integer::{u128_safe_divmod, u128_as_non_zero};
use core::option::{Option, OptionTrait};
use core::traits::{Into, TryInto};
use governance::governance_token::{IGovernanceTokenDispatcher, IGovernanceTokenDispatcherTrait};
use starknet::{ContractAddress, StorePacking};
use array::{Array};
use starknet::account::{Call};
use option::{Option, OptionTrait};
use integer::{u128_safe_divmod, u128_as_non_zero};
use traits::{Into, TryInto};
use starknet::{ContractAddress, StorePacking};

#[derive(Copy, Drop, Serde, PartialEq)]
struct ProposalTimestamps {
Expand Down Expand Up @@ -81,15 +81,15 @@ trait IGovernor<TStorage> {

#[starknet::contract]
mod Governor {
use core::hash::{LegacyHash};
use core::num::traits::zero::{Zero};
use governance::call_trait::{HashCall, CallTrait};
use governance::governance_token::{IGovernanceTokenDispatcherTrait};
use starknet::{get_block_timestamp, get_caller_address, contract_address_const};
use super::{
ContractAddress, Array, IGovernor, IGovernanceTokenDispatcher, Config, ProposalInfo, Call,
ProposalTimestamps
};
use starknet::{get_block_timestamp, get_caller_address, contract_address_const};
use governance::call_trait::{HashCall, CallTrait};
use governance::governance_token::{IGovernanceTokenDispatcherTrait};
use zeroable::{Zeroable};
use hash::{LegacyHash};


#[derive(starknet::Event, Drop)]
Expand Down Expand Up @@ -295,7 +295,7 @@ mod Governor {
let data = call.execute();

self.emit(Executed { id, });

data
}

Expand Down
30 changes: 15 additions & 15 deletions src/governor_test.cairo
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
use core::array::SpanTrait;
use array::{ArrayTrait};
use debug::PrintTrait;
use core::array::{ArrayTrait};
use core::num::traits::zero::{Zero};
use core::option::{OptionTrait};

use core::result::{Result, ResultTrait};
use core::serde::Serde;
use core::traits::{TryInto};

use governance::call_trait::{CallTrait};
use governance::governance_token::{IGovernanceTokenDispatcher, IGovernanceTokenDispatcherTrait};
use governance::governance_token_test::{deploy as deploy_token};
use governance::governor::{
IGovernorDispatcher, IGovernorDispatcherTrait, Governor, Config, ProposalInfo,
ProposalTimestamps
};
use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait};
use governance::governance_token::{IGovernanceTokenDispatcher, IGovernanceTokenDispatcherTrait};
use governance::call_trait::{CallTrait};
use starknet::account::{Call};
use governance::timelock::{ITimelockDispatcher, ITimelockDispatcherTrait};
use governance::timelock_test::{single_call, transfer_call, deploy as deploy_timelock};
use governance::{test_utils as utils};
use governance::timelock::{ITimelockDispatcher, ITimelockDispatcherTrait};
use starknet::account::{Call};
use starknet::class_hash::Felt252TryIntoClassHash;
use starknet::{
get_contract_address, deploy_syscall, ClassHash, contract_address_const, ContractAddress,
get_block_timestamp, testing::{set_block_timestamp, set_contract_address}
};
use starknet::class_hash::Felt252TryIntoClassHash;
use traits::{TryInto};

use result::{Result, ResultTrait};
use option::{OptionTrait};
use governance::governance_token_test::{deploy as deploy_token};
use serde::Serde;
use zeroable::{Zeroable};


fn deploy(voting_token: IGovernanceTokenDispatcher, config: Config) -> IGovernorDispatcher {
Expand Down Expand Up @@ -668,7 +668,7 @@ fn test_verify_votes_are_counted_over_voting_weight_smoothing_duration_from_star
set_block_timestamp(current_timestamp); // 20 seconds before voting starts
// undelegate 20 seconds before voting starts, so only 1/3rd of voting power is counted for voter1
set_contract_address(voter1);
token.delegate(Zeroable::zero());
token.delegate(Zero::zero());

current_timestamp += 20;
set_block_timestamp(current_timestamp); // voting starts
Expand Down
Loading

0 comments on commit ad6b357

Please sign in to comment.