From 2b18c0936cc9066008358784b32de750f3d6d4b5 Mon Sep 17 00:00:00 2001 From: Moody Salem Date: Fri, 15 Mar 2024 09:20:32 -0400 Subject: [PATCH] separate airdrop from the other contracts --- src/airdrop.cairo | 2 +- src/airdrop_test.cairo | 15 +-------------- src/call_trait_test.cairo | 2 +- src/e2e_test.cairo | 5 +---- src/factory.cairo | 28 ++-------------------------- src/factory_test.cairo | 22 ---------------------- src/staker_test.cairo | 2 +- src/test/test_token.cairo | 15 +++++++++++++++ src/timelock_test.cairo | 2 +- 9 files changed, 23 insertions(+), 70 deletions(-) diff --git a/src/airdrop.cairo b/src/airdrop.cairo index c76693a..a3ef7c1 100644 --- a/src/airdrop.cairo +++ b/src/airdrop.cairo @@ -12,7 +12,7 @@ pub struct Claim { pub amount: u128, } -#[derive(Copy, Drop, Serde, Hash, PartialEq, Debug, starknet::Store)] +#[derive(Copy, Drop, Serde, PartialEq, Debug, starknet::Store)] pub struct Config { // the root of the airdrop pub root: felt252, diff --git a/src/airdrop_test.cairo b/src/airdrop_test.cairo index e361252..d0853e1 100644 --- a/src/airdrop_test.cairo +++ b/src/airdrop_test.cairo @@ -10,26 +10,13 @@ use governance::airdrop::{ Airdrop::{compute_pedersen_root, hash_function, hash_claim, compute_root_of_group}, Claim }; use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait}; -use governance::test::test_token::{TestToken}; +use governance::test::test_token::{TestToken, deploy as deploy_token}; use starknet::testing::{pop_log, set_block_timestamp}; use starknet::{ get_contract_address, syscalls::{deploy_syscall}, ClassHash, contract_address_const, ContractAddress }; - -pub(crate) fn deploy_token(owner: ContractAddress, amount: u128) -> IERC20Dispatcher { - let mut constructor_args: Array = ArrayTrait::new(); - Serde::serialize(@(owner, amount), ref constructor_args); - - let (address, _) = deploy_syscall( - TestToken::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_args.span(), true - ) - .expect('DEPLOY_TOKEN_FAILED'); - IERC20Dispatcher { contract_address: address } -} - - fn deploy_with_refundee( token: ContractAddress, root: felt252, refundable_timestamp: u64, refund_to: ContractAddress ) -> IAirdropDispatcher { diff --git a/src/call_trait_test.cairo b/src/call_trait_test.cairo index 04f5089..a40d385 100644 --- a/src/call_trait_test.cairo +++ b/src/call_trait_test.cairo @@ -1,7 +1,7 @@ use core::array::{Array, ArrayTrait}; use core::hash::{LegacyHash}; use core::serde::{Serde}; -use governance::airdrop_test::{deploy_token}; +use governance::test::test_token::{deploy as deploy_token}; use governance::call_trait::{CallTrait, HashCall}; use starknet::{contract_address_const, get_contract_address, account::{Call}}; diff --git a/src/e2e_test.cairo b/src/e2e_test.cairo index 38c736c..c68637f 100644 --- a/src/e2e_test.cairo +++ b/src/e2e_test.cairo @@ -3,9 +3,7 @@ use core::option::{OptionTrait}; use core::result::{Result}; use core::traits::{TryInto}; -use governance::airdrop::{Airdrop}; -use governance::airdrop::{IAirdropDispatcherTrait}; -use governance::airdrop_test::{deploy_token}; +use governance::test::test_token::{deploy as deploy_token}; use governance::factory::{ IFactoryDispatcher, IFactoryDispatcherTrait, Factory, DeploymentParameters, DeploymentResult, }; @@ -45,7 +43,6 @@ impl DefaultDeploymentParameters of Default { proposal_creation_threshold: 20 }, timelock_config: TimelockConfig { delay: 30, window: 90, }, - airdrop_config: Option::None } } } diff --git a/src/factory.cairo b/src/factory.cairo index 10b6bf6..bebf7b0 100644 --- a/src/factory.cairo +++ b/src/factory.cairo @@ -10,7 +10,6 @@ use starknet::{ContractAddress}; pub struct DeploymentParameters { pub governor_config: GovernorConfig, pub timelock_config: TimelockConfig, - pub airdrop_config: Option, } #[derive(Copy, Drop, Serde)] @@ -18,7 +17,6 @@ pub struct DeploymentResult { pub staker: IStakerDispatcher, pub governor: IGovernorDispatcher, pub timelock: ITimelockDispatcher, - pub airdrop: Option, } // This contract makes it easy to deploy a set of governance contracts from a block explorer just by specifying parameters @@ -35,13 +33,12 @@ pub mod Factory { use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait}; use starknet::{ClassHash, syscalls::{deploy_syscall}, get_caller_address, get_contract_address}; use super::{ - IFactory, DeploymentParameters, DeploymentResult, ContractAddress, IAirdropDispatcher, - IGovernorDispatcher, ITimelockDispatcher, IStakerDispatcher + IFactory, DeploymentParameters, DeploymentResult, ContractAddress, IGovernorDispatcher, + ITimelockDispatcher, IStakerDispatcher }; #[storage] struct Storage { - airdrop_class_hash: ClassHash, staker_class_hash: ClassHash, governor_class_hash: ClassHash, timelock_class_hash: ClassHash, @@ -50,12 +47,10 @@ pub mod Factory { #[constructor] fn constructor( ref self: ContractState, - airdrop_class_hash: ClassHash, staker_class_hash: ClassHash, governor_class_hash: ClassHash, timelock_class_hash: ClassHash ) { - self.airdrop_class_hash.write(airdrop_class_hash); self.staker_class_hash.write(staker_class_hash); self.governor_class_hash.write(governor_class_hash); self.timelock_class_hash.write(timelock_class_hash); @@ -89,24 +84,6 @@ pub mod Factory { ) .unwrap(); - let airdrop = match params.airdrop_config { - Option::Some(config) => { - let mut airdrop_constructor_args: Array = ArrayTrait::new(); - Serde::serialize(@(token, config), ref airdrop_constructor_args); - - let (airdrop_address, _) = deploy_syscall( - class_hash: self.airdrop_class_hash.read(), - contract_address_salt: 0, - calldata: airdrop_constructor_args.span(), - deploy_from_zero: false, - ) - .unwrap(); - - Option::Some(IAirdropDispatcher { contract_address: airdrop_address }) - }, - Option::None => { Option::None } - }; - let mut timelock_constructor_args: Array = ArrayTrait::new(); Serde::serialize( @(governor_address, params.timelock_config.delay, params.timelock_config.window), @@ -122,7 +99,6 @@ pub mod Factory { .unwrap(); DeploymentResult { - airdrop, staker: IStakerDispatcher { contract_address: staker_address }, governor: IGovernorDispatcher { contract_address: governor_address }, timelock: ITimelockDispatcher { contract_address: timelock_address } diff --git a/src/factory_test.cairo b/src/factory_test.cairo index e1117e4..d1246ef 100644 --- a/src/factory_test.cairo +++ b/src/factory_test.cairo @@ -3,9 +3,6 @@ use core::option::{OptionTrait}; use core::result::{Result}; use core::traits::{TryInto}; -use governance::airdrop::{Airdrop, Config as AirdropConfig}; -use governance::airdrop::{IAirdropDispatcherTrait}; -use governance::airdrop_test::{deploy_token}; use governance::factory::{ IFactoryDispatcher, IFactoryDispatcherTrait, Factory, DeploymentParameters, }; @@ -25,7 +22,6 @@ pub(crate) fn deploy() -> IFactoryDispatcher { let mut constructor_args: Array = ArrayTrait::new(); Serde::serialize( @( - Airdrop::TEST_CLASS_HASH, Staker::TEST_CLASS_HASH, Governor::TEST_CLASS_HASH, Timelock::TEST_CLASS_HASH @@ -54,13 +50,6 @@ fn test_deploy() { .deploy( token, DeploymentParameters { - airdrop_config: Option::Some( - AirdropConfig { - root: 'root', - refundable_timestamp: 312, - refund_to: contract_address_const::<'refund'>(), - } - ), governor_config: GovernorConfig { voting_start_delay: 0, voting_period: 180, @@ -72,17 +61,6 @@ fn test_deploy() { } ); - let drop = result.airdrop.unwrap(); - assert_eq!( - drop.get_config(), - AirdropConfig { - root: 'root', - refundable_timestamp: 312, - refund_to: contract_address_const::<'refund'>(), - } - ); - assert_eq!(drop.get_token(), token); - assert_eq!(result.staker.get_token(), token); assert_eq!(result.governor.get_staker().contract_address, result.staker.contract_address); diff --git a/src/staker_test.cairo b/src/staker_test.cairo index ed936f1..53ba0fc 100644 --- a/src/staker_test.cairo +++ b/src/staker_test.cairo @@ -3,7 +3,7 @@ use core::num::traits::zero::{Zero}; use core::option::{OptionTrait}; use core::result::{Result, ResultTrait}; use core::traits::{TryInto}; -use governance::airdrop_test::{deploy_token}; +use governance::test::test_token::{deploy as deploy_token}; use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait}; use governance::staker::{ diff --git a/src/test/test_token.cairo b/src/test/test_token.cairo index 5e72122..b0c5d04 100644 --- a/src/test/test_token.cairo +++ b/src/test/test_token.cairo @@ -71,3 +71,18 @@ pub(crate) mod TestToken { } } } + +use starknet::{ContractAddress, syscalls::{deploy_syscall}}; +use governance::interfaces::erc20::{IERC20Dispatcher}; + +#[cfg(test)] +pub(crate) fn deploy(owner: ContractAddress, amount: u128) -> IERC20Dispatcher { + let mut constructor_args: Array = ArrayTrait::new(); + Serde::serialize(@(owner, amount), ref constructor_args); + + let (address, _) = deploy_syscall( + TestToken::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_args.span(), true + ) + .expect('DEPLOY_TOKEN_FAILED'); + IERC20Dispatcher { contract_address: address } +} diff --git a/src/timelock_test.cairo b/src/timelock_test.cairo index b4020ab..71a4ff8 100644 --- a/src/timelock_test.cairo +++ b/src/timelock_test.cairo @@ -1,5 +1,5 @@ use core::array::{Array, ArrayTrait, SpanTrait}; -use governance::airdrop_test::{deploy_token}; +use governance::test::test_token::{deploy as deploy_token}; use governance::interfaces::erc20::{IERC20Dispatcher, IERC20DispatcherTrait}; use governance::timelock::{ ITimelockDispatcher, ITimelockDispatcherTrait, Timelock, TimelockConfig,