Skip to content

Commit

Permalink
Merge pull request #158 from Gianfranco99/feat/issue-136-emit-event-w…
Browse files Browse the repository at this point in the history
…hen-fund-contract-is-deployed

[feat] Emit event when fund contract is deployed #136
  • Loading branch information
EmmanuelAR authored Oct 26, 2024
2 parents d79050a + d670464 commit 1083b6c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contracts/src/constants/funds/fund_manager_constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
pub mod FundManagerConstants {
pub const FUND_MANAGER_ADDRESS: felt252 =
0x00a885638f5167da8c38f115077c23ed7411539ea8f019ef09ec025d0c52d0ff;
}
}
4 changes: 3 additions & 1 deletion contracts/src/fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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},};

// *************************************************************************
Expand Down
30 changes: 30 additions & 0 deletions contracts/src/fundManager.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractState> {
fn newFund(ref self: ContractState, name: felt252, goal: u256) {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion contracts/tests/test_fund.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 1083b6c

Please sign in to comment.