Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add locked and unlocked events and emit them #50

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 });
}
}
}
Loading