From ec1abb1b7c3a012188df2a31c27d4ba8817f1b08 Mon Sep 17 00:00:00 2001 From: Nuelo Date: Fri, 25 Oct 2024 18:50:29 +0100 Subject: [PATCH 1/5] feat: add emit event to receiveDonation function --- contracts/src/fund.cairo | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index afe686e..d67a7a9 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -41,7 +41,8 @@ mod Fund { #[derive(Drop, starknet::Event)] enum Event { DonationWithdraw: DonationWithdraw, - NewVoteReceived: NewVoteReceived + NewVoteReceived: NewVoteReceived, + DonationReceived: DonationReceived, } #[derive(Drop, starknet::Event)] @@ -59,6 +60,15 @@ mod Fund { pub fund: ContractAddress, pub votes: u32 } + + #[derive(Drop, starknet::Event)] + pub struct DonationReceived { + #[key] + pub donor_address: ContractAddress, + pub donated_strks: u256, + pub current_balance: u256, + pub fund_contract_address: ContractAddress, + } // ************************************************************************* // STORAGE // ************************************************************************* @@ -160,6 +170,17 @@ mod Fund { if self.current_goal_state.read() >= self.goal.read() { self.state.write(FundStates::CLOSED); } + + // Emit receiveDonation event + self + .emit( + DonationReceived { + donor_address: get_caller_address(), + fund_contract_address: get_contract_address(), + current_balance: self.current_goal_state.read(), + donated_strks: strks, + } + ) } fn getCurrentGoalState(self: @ContractState) -> u256 { return self.current_goal_state.read(); @@ -187,7 +208,8 @@ mod Fund { contract_address: starknet_contract_address }; let balance = starknet_dispatcher.balance_of(get_contract_address()); - //TODO: Calculate balance to deposit in owner address and in fund manager address (95% and 5%), also transfer the amount to fund manager address. + //TODO: Calculate balance to deposit in owner address and in fund manager address (95% + //and 5%), also transfer the amount to fund manager address. starknet_dispatcher.transfer(self.getOwner(), balance); assert(self.getCurrentGoalState() != 0, 'Fund hasnt reached its goal yet'); self.setState(4); From 163c07faf341b884d8f7017b738a3f51bee2ca3e Mon Sep 17 00:00:00 2001 From: Nuelo Date: Fri, 25 Oct 2024 22:36:59 +0100 Subject: [PATCH 2/5] fix: typo and code formatting --- contracts/src/fund.cairo | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index d67a7a9..364350a 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -64,7 +64,7 @@ mod Fund { #[derive(Drop, starknet::Event)] pub struct DonationReceived { #[key] - pub donor_address: ContractAddress, + pub donator_address: ContractAddress, pub donated_strks: u256, pub current_balance: u256, pub fund_contract_address: ContractAddress, @@ -208,8 +208,7 @@ mod Fund { contract_address: starknet_contract_address }; let balance = starknet_dispatcher.balance_of(get_contract_address()); - //TODO: Calculate balance to deposit in owner address and in fund manager address (95% - //and 5%), also transfer the amount to fund manager address. + //TODO: Calculate balance to deposit in owner address and in fund manager address (95% and 5%), also transfer the amount to fund manager address. starknet_dispatcher.transfer(self.getOwner(), balance); assert(self.getCurrentGoalState() != 0, 'Fund hasnt reached its goal yet'); self.setState(4); From 4781a183aa58fb7c378bd9c9774d9089f46224e6 Mon Sep 17 00:00:00 2001 From: Nuelo Date: Sat, 26 Oct 2024 04:29:07 +0100 Subject: [PATCH 3/5] fix: compilation issue --- contracts/src/fund.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index 9dc2d09..d3f9a66 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -178,7 +178,7 @@ mod Fund { self .emit( DonationReceived { - donor_address: get_caller_address(), + donator_address: get_caller_address(), fund_contract_address: get_contract_address(), current_balance: self.current_goal_state.read(), donated_strks: strks, From d46965ad32b56c1bc6e0be1a81136e69bcae41cb Mon Sep 17 00:00:00 2001 From: Nuelo Date: Sat, 26 Oct 2024 05:05:55 +0100 Subject: [PATCH 4/5] fix: typo --- contracts/src/fund.cairo | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index d3f9a66..d1d912e 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -64,9 +64,9 @@ mod Fund { #[derive(Drop, starknet::Event)] pub struct DonationReceived { #[key] - pub donator_address: ContractAddress, - pub donated_strks: u256, pub current_balance: u256, + pub donated_strks: u256, + pub donator_address: ContractAddress, pub fund_contract_address: ContractAddress, } // ************************************************************************* @@ -178,10 +178,10 @@ mod Fund { self .emit( DonationReceived { - donator_address: get_caller_address(), - fund_contract_address: get_contract_address(), current_balance: self.current_goal_state.read(), donated_strks: strks, + donator_address: get_caller_address(), + fund_contract_address: get_contract_address(), } ) } From 964db5d62862b273bf96641a425a31341b3501eb Mon Sep 17 00:00:00 2001 From: Nuelo Date: Sat, 26 Oct 2024 10:44:47 +0100 Subject: [PATCH 5/5] refact: change key for donationreceived struct --- contracts/src/fund.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/src/fund.cairo b/contracts/src/fund.cairo index d1d912e..33f75ed 100644 --- a/contracts/src/fund.cairo +++ b/contracts/src/fund.cairo @@ -64,9 +64,9 @@ mod Fund { #[derive(Drop, starknet::Event)] pub struct DonationReceived { #[key] + pub donator_address: ContractAddress, pub current_balance: u256, pub donated_strks: u256, - pub donator_address: ContractAddress, pub fund_contract_address: ContractAddress, } // *************************************************************************