diff --git a/contracts/src/constants/funds/fund_manager_constants.cairo b/contracts/src/constants/funds/fund_manager_constants.cairo index 6af52a0..59c7a6d 100644 --- a/contracts/src/constants/funds/fund_manager_constants.cairo +++ b/contracts/src/constants/funds/fund_manager_constants.cairo @@ -4,4 +4,4 @@ pub mod FundManagerConstants { pub const FUND_MANAGER_ADDRESS: felt252 = 0x00a885638f5167da8c38f115077c23ed7411539ea8f019ef09ec025d0c52d0ff; -} \ No newline at end of file +} diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index f1b4d79..9f11734 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -31,7 +31,9 @@ mod Fund { use starknet::get_contract_address; use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use gostarkme::constants::{funds::{state_constants::FundStates},}; - use gostarkme::constants::{funds::{fund_constants::FundConstants, fund_manager_constants::FundManagerConstants},}; + use gostarkme::constants::{ + funds::{fund_constants::FundConstants, fund_manager_constants::FundManagerConstants}, + }; use gostarkme::constants::{funds::{starknet_constants::StarknetConstants},}; // ************************************************************************* diff --git a/contracts/src/fundManager.cairo b/contracts/src/fundManager.cairo index ffa562f..8266d7e 100755 --- a/contracts/src/fundManager.cairo +++ b/contracts/src/fundManager.cairo @@ -45,9 +45,29 @@ mod FundManager { self.current_id.write(1); } + + // *************************************************************************************** + // EVENTS + // *************************************************************************************** + #[event] + #[derive(Drop, starknet::Event)] + pub enum Event { + FundDeployed: FundDeployed, + } + + #[derive(Drop, starknet::Event)] + pub struct FundDeployed { + #[key] + pub owner: ContractAddress, + pub fund_address: ContractAddress, + pub fund_id: u128, + } + + // *************************************************************************************** // EXTERNALS // *************************************************************************************** + #[abi(embed_v0)] impl FundManagerImpl of super::IFundManager { fn newFund(ref self: ContractState, name: felt252, goal: u256) { @@ -60,7 +80,17 @@ mod FundManager { self.fund_class_hash.read(), 12345, call_data.span(), false ) .unwrap(); + self.funds.write(self.current_id.read(), new_fund_address); + self + .emit( + FundDeployed { + owner: get_caller_address(), + fund_address: new_fund_address, + fund_id: self.current_id.read() + } + ); + self.current_id.write(self.current_id.read() + 1); } fn getCurrentId(self: @ContractState) -> u128 { diff --git a/contracts/tests/test_fund.cairo b/contracts/tests/test_fund.cairo index 6788ad9..23b13ce 100644 --- a/contracts/tests/test_fund.cairo +++ b/contracts/tests/test_fund.cairo @@ -97,7 +97,7 @@ fn test_set_goal() { let dispatcher = IFundDispatcher { contract_address }; let goal = dispatcher.getGoal(); assert(goal == GOAL(), 'Invalid goal'); - start_cheat_caller_address_global(FUND_MANAGER()); + start_cheat_caller_address_global(FUND_MANAGER()); dispatcher.setGoal(123); let new_goal = dispatcher.getGoal(); assert(new_goal == 123, 'Set goal method not working')