This commit is contained in:
Hardhat Chad
2025-06-13 16:05:39 -07:00
parent 1d9b0ebd42
commit b24883d8ff
11 changed files with 59 additions and 5 deletions

View File

@@ -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,

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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 {