mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-17 07:26:52 +00:00
events
This commit is contained in:
@@ -34,7 +34,7 @@ pub struct Block {
|
||||
|
||||
/// Configuration specifying how rewards are paid out.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct RewardConfig {
|
||||
/// The reward paid to the submitter of the best hash.
|
||||
pub lode_reward: u64,
|
||||
|
||||
@@ -64,6 +64,7 @@ impl Market {
|
||||
base_via_curve: base_via_curve as u64,
|
||||
quote_via_curve: quote_via_curve as u64,
|
||||
quote_fee: quote_fee as u64,
|
||||
ts: 0,
|
||||
};
|
||||
|
||||
// Sanity check swap event.
|
||||
|
||||
@@ -69,6 +69,7 @@ impl Market {
|
||||
base_via_curve: base_via_curve as u64,
|
||||
quote_via_curve: quote_via_curve as u64,
|
||||
quote_fee: quote_fee as u64,
|
||||
ts: 0,
|
||||
};
|
||||
|
||||
// Sanity check swap result.
|
||||
|
||||
@@ -73,6 +73,7 @@ impl Market {
|
||||
base_via_curve: base_via_curve as u64,
|
||||
quote_via_curve: quote_via_curve as u64,
|
||||
quote_fee: quote_fee as u64,
|
||||
ts: 0,
|
||||
};
|
||||
|
||||
// Sanity check swap result.
|
||||
|
||||
@@ -71,6 +71,7 @@ impl Market {
|
||||
base_via_curve: base_via_curve as u64,
|
||||
quote_via_curve: quote_via_curve as u64,
|
||||
quote_fee: quote_fee as u64,
|
||||
ts: 0,
|
||||
};
|
||||
|
||||
// Sanity check swap result.
|
||||
|
||||
@@ -14,19 +14,22 @@ impl Market {
|
||||
clock: Clock,
|
||||
) -> Result<SwapEvent, OreError> {
|
||||
// Update snapshot.
|
||||
self.update_snapshot(clock);
|
||||
self.update_snapshot(&clock);
|
||||
|
||||
// Get invariant.
|
||||
let k_pre = self.k();
|
||||
|
||||
// Execute swap.
|
||||
let swap_event = match (direction, precision) {
|
||||
let mut swap_event = match (direction, precision) {
|
||||
(SwapDirection::Buy, SwapPrecision::ExactIn) => self.buy_exact_in(amount)?,
|
||||
(SwapDirection::Buy, SwapPrecision::ExactOut) => self.buy_exact_out(amount)?,
|
||||
(SwapDirection::Sell, SwapPrecision::ExactIn) => self.sell_exact_in(amount)?,
|
||||
(SwapDirection::Sell, SwapPrecision::ExactOut) => self.sell_exact_out(amount)?,
|
||||
};
|
||||
|
||||
// Update timestamp.
|
||||
swap_event.ts = clock.unix_timestamp;
|
||||
|
||||
// Check invariant.
|
||||
let k_post = self.k();
|
||||
if k_pre > k_post {
|
||||
|
||||
@@ -121,7 +121,7 @@ impl Market {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn update_snapshot(&mut self, clock: Clock) {
|
||||
pub(crate) fn update_snapshot(&mut self, clock: &Clock) {
|
||||
let slot = clock.slot;
|
||||
let snapshot_slot = (slot / SLOT_WINDOW) * SLOT_WINDOW;
|
||||
if snapshot_slot != self.snapshot.slot {
|
||||
|
||||
Reference in New Issue
Block a user