Skip to content

Commit

Permalink
add locked and unlocked events and emit them (#50)
Browse files Browse the repository at this point in the history
* add locked and unlocked events and emit them

* fix changes requested on the PR
  • Loading branch information
mubarak23 authored Sep 5, 2024
1 parent d9e3e2d commit b7c8bb3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions contracts/src/components/escrow/escrow.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,35 @@ pub mod EscrowComponent {
pub const INSUFFICIENT_BALANCE: felt252 = 'Insufficient deposit balance';
}

//
// EVENTS
//
#[event]
#[derive(Drop, starknet::Event)]
pub enum Event {
Locked: Locked,
UnLocked: UnLocked
}

/// Emitted when the escrow is locked
#[derive(Drop, starknet::Event)]
pub struct Locked {
#[key]
pub token: ContractAddress,
pub from: ContractAddress,
pub amount: u256,
}

/// Emitted when the escrow is unlocked
#[derive(Drop, starknet::Event)]
pub struct UnLocked {
#[key]
pub token: ContractAddress,
pub from: ContractAddress,
pub to: ContractAddress,
pub amount: u256,
}

//
// Escrow impl
//
Expand All @@ -46,6 +75,9 @@ pub mod EscrowComponent {
erc20_dispatcher.transfer_from(from, get_contract_address(), amount);

self.deposits.write((from, token), amount + locked_amount);

// emit event
self.emit(Locked { token, from, amount });
}

fn unlock_to(
Expand All @@ -71,6 +103,8 @@ pub mod EscrowComponent {

// update locked amount
self.deposits.write((from, token), locked_amount - amount);
// emit event
self.emit(UnLocked { token, from, to, amount });
}
}
}

0 comments on commit b7c8bb3

Please sign in to comment.