diff --git a/api/src/event.rs b/api/src/event.rs index 8e74d04..7f0cfb4 100644 --- a/api/src/event.rs +++ b/api/src/event.rs @@ -2,9 +2,22 @@ use steel::*; use crate::state::{RewardConfig, SwapDirection}; +pub enum OreEvent { + Swap = 0, + Reward = 1, + Open = 2, + Commit = 3, + Deposit = 4, + Withdraw = 5, + Uncommit = 6, +} + #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct SwapEvent { + /// The event discriminator. + pub disc: u64, + /// The authority of the swap. pub authority: Pubkey, @@ -48,6 +61,9 @@ impl SwapEvent { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct RewardEvent { + /// The event discriminator. + pub disc: u64, + /// The amount of ORE distributed as a reward. pub amount: u64, @@ -75,6 +91,9 @@ pub enum RewardsType { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct OpenEvent { + /// The event discriminator. + pub disc: u64, + /// The signer of the open transaction. pub signer: Pubkey, @@ -119,6 +138,9 @@ pub struct CloseEvent { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct CommitEvent { + /// The event discriminator. + pub disc: u64, + /// The authority of the commit transaction. pub authority: Pubkey, @@ -138,6 +160,9 @@ pub struct CommitEvent { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct UncommitEvent { + /// The event discriminator. + pub disc: u64, + /// The authority of the commit transaction. pub authority: Pubkey, @@ -157,6 +182,9 @@ pub struct UncommitEvent { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct DepositEvent { + /// The event discriminator. + pub disc: u64, + /// The authority of the commit transaction. pub authority: Pubkey, @@ -176,6 +204,9 @@ pub struct DepositEvent { #[repr(C)] #[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)] pub struct WithdrawEvent { + /// The event discriminator. + pub disc: u64, + /// The authority of the commit transaction. pub authority: Pubkey, diff --git a/api/src/state/market/buy_exact_in.rs b/api/src/state/market/buy_exact_in.rs index c95dae1..3fb21dd 100644 --- a/api/src/state/market/buy_exact_in.rs +++ b/api/src/state/market/buy_exact_in.rs @@ -1,6 +1,6 @@ use steel::Pubkey; -use crate::error::OreError; +use crate::{error::OreError, event::OreEvent}; use super::{Market, SwapDirection, TokenType, VirtualLimitOrder}; use crate::event::SwapEvent; @@ -54,6 +54,7 @@ impl Market { // Produce swap result. let base_out = base_via_ask + base_via_curve; let swap_event = SwapEvent { + disc: OreEvent::Swap as u64, authority: Pubkey::default(), block_id: 0, direction: SwapDirection::Buy as u64, diff --git a/api/src/state/market/buy_exact_out.rs b/api/src/state/market/buy_exact_out.rs index 7410f25..6bfd2d6 100644 --- a/api/src/state/market/buy_exact_out.rs +++ b/api/src/state/market/buy_exact_out.rs @@ -1,6 +1,6 @@ use steel::Pubkey; -use crate::error::OreError; +use crate::{error::OreError, event::OreEvent}; use super::{Market, SwapDirection, TokenType, VirtualLimitOrder}; use crate::event::SwapEvent; @@ -59,6 +59,7 @@ impl Market { // Produce swap result. let swap_event = SwapEvent { + disc: OreEvent::Swap as u64, authority: Pubkey::default(), block_id: 0, direction: SwapDirection::Buy as u64, diff --git a/api/src/state/market/sell_exact_in.rs b/api/src/state/market/sell_exact_in.rs index 43b3418..41961a4 100644 --- a/api/src/state/market/sell_exact_in.rs +++ b/api/src/state/market/sell_exact_in.rs @@ -1,6 +1,6 @@ use steel::Pubkey; -use crate::error::OreError; +use crate::{error::OreError, event::OreEvent}; use super::{Market, SwapDirection, TokenType, VirtualLimitOrder}; use crate::event::SwapEvent; @@ -63,6 +63,7 @@ impl Market { // Produce swap result. let quote_out = quote_via_bid + quote_via_curve; let swap_event = SwapEvent { + disc: OreEvent::Swap as u64, authority: Pubkey::default(), block_id: 0, direction: SwapDirection::Sell as u64, diff --git a/api/src/state/market/sell_exact_out.rs b/api/src/state/market/sell_exact_out.rs index fa2e2d5..8ce4eba 100644 --- a/api/src/state/market/sell_exact_out.rs +++ b/api/src/state/market/sell_exact_out.rs @@ -1,6 +1,6 @@ use steel::Pubkey; -use crate::error::OreError; +use crate::{error::OreError, event::OreEvent}; use super::{Market, SwapDirection, TokenType, VirtualLimitOrder}; use crate::event::SwapEvent; @@ -61,6 +61,7 @@ impl Market { // Produce swap result. let swap_event = SwapEvent { + disc: OreEvent::Swap as u64, authority: Pubkey::default(), block_id: 0, direction: SwapDirection::Sell as u64, diff --git a/program/src/close.rs b/program/src/close.rs index 4942701..50cdb68 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -72,6 +72,7 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul // Emit event. RewardEvent { + disc: OreEvent::Reward as u64, amount: block.reward.lode_reward, authority: block.reward.lode_authority, block_id: block.id, diff --git a/program/src/commit.rs b/program/src/commit.rs index d262a95..b8f528d 100644 --- a/program/src/commit.rs +++ b/program/src/commit.rs @@ -96,6 +96,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul // Emit event. CommitEvent { + disc: OreEvent::Commit as u64, authority: *signer_info.key, block_id: block.id, amount, diff --git a/program/src/deposit.rs b/program/src/deposit.rs index 6669e42..568a538 100644 --- a/program/src/deposit.rs +++ b/program/src/deposit.rs @@ -65,6 +65,7 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu // Emit event. DepositEvent { + disc: OreEvent::Deposit as u64, authority: *signer_info.key, block_id: block.id, amount, diff --git a/program/src/mine.rs b/program/src/mine.rs index 220c2ed..dfbb659 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -133,6 +133,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult // Emit event. RewardEvent { + disc: OreEvent::Reward as u64, amount: motherlode_amount, authority: miner.authority, block_id: block.id, @@ -161,6 +162,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult // Emit event. RewardEvent { + disc: OreEvent::Reward as u64, amount: nugget_reward, authority: miner.authority, block_id: block.id, diff --git a/program/src/open.rs b/program/src/open.rs index 225a2c6..c7a6f90 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -225,6 +225,7 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult // Emit event. OpenEvent { + disc: OreEvent::Open as u64, id, start_slot, signer: *signer_info.key, diff --git a/program/src/uncommit.rs b/program/src/uncommit.rs index 8cd2395..0e981b5 100644 --- a/program/src/uncommit.rs +++ b/program/src/uncommit.rs @@ -61,6 +61,7 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes // Emit event. UncommitEvent { + disc: OreEvent::Uncommit as u64, authority: *signer_info.key, block_id: block.id, commitment: permit.amount, diff --git a/program/src/withdraw.rs b/program/src/withdraw.rs index 95e2b7a..a51cf75 100644 --- a/program/src/withdraw.rs +++ b/program/src/withdraw.rs @@ -55,6 +55,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes // Emit event. WithdrawEvent { + disc: OreEvent::Withdraw as u64, authority: *signer_info.key, block_id: stake.block_id, amount,