diff --git a/api/src/event.rs b/api/src/event.rs index dcd5bdb..1d89984 100644 --- a/api/src/event.rs +++ b/api/src/event.rs @@ -97,6 +97,86 @@ pub struct OpenEvent { pub ts: i64, } +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] +pub struct CommitEvent { + /// The authority of the commit transaction. + pub authority: Pubkey, + + /// The id of the block. + pub block_id: u64, + + /// The amount of hashpower committed. + pub amount: u64, + + /// The total amount of hashpower this user has committed. + pub commitment: u64, + + /// The timestamp of the event. + pub ts: i64, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] +pub struct UncommitEvent { + /// The authority of the commit transaction. + pub authority: Pubkey, + + /// The id of the block. + pub block_id: u64, + + /// The amount of hashpower committed. + pub amount: u64, + + /// The total amount of hashpower this user has committed. + pub commitment: u64, + + /// The timestamp of the event. + pub ts: i64, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] +pub struct DepositEvent { + /// The authority of the commit transaction. + pub authority: Pubkey, + + /// The id of the block. + pub block_id: u64, + + /// The amount of ORE collateral deposited. + pub amount: u64, + + /// The total amount of ORE this user has deposited as collateral. + pub capacity: u64, + + /// The timestamp of the event. + pub ts: i64, +} + +#[repr(C)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] +pub struct WithdrawEvent { + /// The authority of the commit transaction. + pub authority: Pubkey, + + /// The id of the block. + pub block_id: u64, + + /// The amount of ORE collateral withdrawn. + pub amount: u64, + + /// The total amount of ORE this user has deposited as collateral. + pub capacity: u64, + + /// The timestamp of the event. + pub ts: i64, +} + event!(SwapEvent); event!(RewardEvent); event!(OpenEvent); +event!(CommitEvent); +event!(DepositEvent); +event!(WithdrawEvent); +event!(UncommitEvent); diff --git a/program/src/commit.rs b/program/src/commit.rs index a17b92d..d262a95 100644 --- a/program/src/commit.rs +++ b/program/src/commit.rs @@ -94,5 +94,15 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul // Update block. permit.amount += amount; + // Emit event. + CommitEvent { + authority: *signer_info.key, + block_id: block.id, + amount, + commitment: permit.amount, + ts: clock.unix_timestamp, + } + .log_return(); + Ok(()) } diff --git a/program/src/deposit.rs b/program/src/deposit.rs index d078a5f..6669e42 100644 --- a/program/src/deposit.rs +++ b/program/src/deposit.rs @@ -63,5 +63,15 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu amount, )?; + // Emit event. + DepositEvent { + authority: *signer_info.key, + block_id: block.id, + amount, + capacity: stake.capacity, + ts: clock.unix_timestamp, + } + .log_return(); + Ok(()) } diff --git a/program/src/uncommit.rs b/program/src/uncommit.rs index 5f3db3b..8cd2395 100644 --- a/program/src/uncommit.rs +++ b/program/src/uncommit.rs @@ -59,5 +59,15 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes permit_info.close(signer_info)?; } + // Emit event. + UncommitEvent { + authority: *signer_info.key, + block_id: block.id, + commitment: permit.amount, + amount, + ts: clock.unix_timestamp, + } + .log_return(); + Ok(()) } diff --git a/program/src/withdraw.rs b/program/src/withdraw.rs index 8a58f83..95e2b7a 100644 --- a/program/src/withdraw.rs +++ b/program/src/withdraw.rs @@ -53,5 +53,15 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes stake_info.close(signer_info)?; } + // Emit event. + WithdrawEvent { + authority: *signer_info.key, + block_id: stake.block_id, + amount, + capacity: stake.capacity, + ts: clock.unix_timestamp, + } + .log_return(); + Ok(()) }