diff --git a/locked-asset/lkmex-transfer/src/events.rs b/locked-asset/lkmex-transfer/src/events.rs new file mode 100644 index 000000000..aa92a16be --- /dev/null +++ b/locked-asset/lkmex-transfer/src/events.rs @@ -0,0 +1,65 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use crate::LockedFunds; + +#[derive(TypeAbi, TopEncode)] +pub struct LkmexTransferEvent { + sender: ManagedAddress, + receiver: ManagedAddress, + locked_funds: LockedFunds, +} + +#[multiversx_sc::module] +pub trait LkmexTransferEventsModule { + fn emit_withdraw_event( + self, + sender: ManagedAddress, + receiver: ManagedAddress, + locked_funds: LockedFunds, + ) { + let event_data = LkmexTransferEvent { + sender, + receiver, + locked_funds, + }; + self.withdraw_event(event_data); + } + + fn emit_cancel_transfer_event( + &self, + sender: ManagedAddress, + receiver: ManagedAddress, + locked_funds: LockedFunds, + ) { + let event_data = LkmexTransferEvent { + sender, + receiver, + locked_funds, + }; + self.cancel_transfer_event(event_data); + } + + fn emit_lock_funds_event( + &self, + sender: ManagedAddress, + receiver: ManagedAddress, + locked_funds: LockedFunds, + ) { + let event_data = LkmexTransferEvent { + sender, + receiver, + locked_funds, + }; + self.lock_funds_event(event_data); + } + + #[event("withdraw_event")] + fn withdraw_event(&self, event_data: LkmexTransferEvent); + + #[event("cancel_transfer_event")] + fn cancel_transfer_event(&self, event_data: LkmexTransferEvent); + + #[event("lock_funds_event")] + fn lock_funds_event(&self, event_data: LkmexTransferEvent); +} diff --git a/locked-asset/lkmex-transfer/src/lib.rs b/locked-asset/lkmex-transfer/src/lib.rs index 88a715d74..993eb4913 100644 --- a/locked-asset/lkmex-transfer/src/lib.rs +++ b/locked-asset/lkmex-transfer/src/lib.rs @@ -6,6 +6,7 @@ multiversx_sc::derive_imports!(); pub mod constants; pub mod energy_transfer; +pub mod events; use common_structs::{Epoch, PaymentsVec}; use permissions_module::Permissions; @@ -29,6 +30,7 @@ pub struct ScheduledTransfer { #[multiversx_sc::contract] pub trait LkmexTransfer: energy_transfer::EnergyTransferModule + + events::LkmexTransferEventsModule + energy_query::EnergyQueryModule + utils::UtilsModule + legacy_token_decode_module::LegacyTokenDecodeModule @@ -67,6 +69,12 @@ pub trait LkmexTransfer: let current_epoch = self.blockchain().get_block_epoch(); receiver_last_transfer_mapper.set(current_epoch); + + let locked_funds = LockedFunds { + funds, + locked_epoch: current_epoch, + }; + self.emit_withdraw_event(sender, receiver, locked_funds); } #[endpoint(cancelTransfer)] @@ -82,6 +90,8 @@ pub trait LkmexTransfer: self.add_energy_to_destination(sender.clone(), &locked_funds.funds); self.send().direct_multi(&sender, &locked_funds.funds); + + self.emit_cancel_transfer_event(sender, receiver, locked_funds); } fn get_unlocked_funds( @@ -124,12 +134,16 @@ pub trait LkmexTransfer: self.deduct_energy_from_sender(sender.clone(), &payments); let current_epoch = self.blockchain().get_block_epoch(); - self.locked_funds(&receiver, &sender).set(LockedFunds { + let locked_funds = LockedFunds { funds: payments, locked_epoch: current_epoch, - }); + }; + self.locked_funds(&receiver, &sender) + .set(locked_funds.clone()); sender_last_transfer_mapper.set(current_epoch); - self.all_senders(&receiver).insert(sender); + self.all_senders(&receiver).insert(sender.clone()); + + self.emit_lock_funds_event(sender, receiver, locked_funds); } fn check_address_on_cooldown(&self, last_transfer_mapper: &SingleValueMapper) {