swap event

This commit is contained in:
Hardhat Chad
2025-06-06 13:05:25 -07:00
parent 64152ca223
commit edbdb28958
6 changed files with 9 additions and 1 deletions

View File

@@ -5,6 +5,9 @@ use crate::state::SwapDirection;
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
pub struct SwapEvent {
/// The block id.
pub block_id: u64,
/// Swap direction.
pub direction: u64,

View File

@@ -52,6 +52,7 @@ impl Market {
// Produce swap result.
let base_out = base_via_ask + base_via_curve;
let swap_event = SwapEvent {
block_id: 0,
direction: SwapDirection::Buy as u64,
base_to_transfer: base_out as u64,
quote_to_transfer: quote_in,

View File

@@ -57,6 +57,7 @@ impl Market {
// Produce swap result.
let swap_event = SwapEvent {
block_id: 0,
direction: SwapDirection::Buy as u64,
base_to_transfer: base_out as u64,
quote_to_transfer: quote_in as u64,

View File

@@ -61,6 +61,7 @@ impl Market {
// Produce swap result.
let quote_out = quote_via_bid + quote_via_curve;
let swap_event = SwapEvent {
block_id: 0,
direction: SwapDirection::Sell as u64,
base_to_transfer: base_in as u64,
quote_to_transfer: quote_out as u64,

View File

@@ -59,6 +59,7 @@ impl Market {
// Produce swap result.
let swap_event = SwapEvent {
block_id: 0,
direction: SwapDirection::Sell as u64,
base_to_transfer: base_in as u64,
quote_to_transfer: quote_out as u64,

View File

@@ -49,7 +49,8 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
token_program.is_program(&spl_token::ID)?;
// Update market state.
let swap_result = market.swap(amount, direction, precision, clock)?;
let mut swap_result = market.swap(amount, direction, precision, clock)?;
swap_result.block_id = block.id;
swap_result.log_return();
// Get transfer amounts and accounts.