mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
cleanup
This commit is contained in:
193
api/src/event.rs
193
api/src/event.rs
@@ -1,16 +1,11 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::state::{RewardConfig, SwapDirection};
|
||||
use crate::state::SwapDirection;
|
||||
|
||||
pub enum OreEvent {
|
||||
Commit = 0,
|
||||
Deposit = 1,
|
||||
Mine = 2,
|
||||
Open = 3,
|
||||
Reward = 4,
|
||||
Swap = 5,
|
||||
Uncommit = 6,
|
||||
Withdraw = 7,
|
||||
Mine = 1,
|
||||
Reward = 2,
|
||||
Swap = 3,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -112,186 +107,6 @@ pub struct MineEvent {
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
pub enum RewardsType {
|
||||
Nugget = 0,
|
||||
Lode = 1,
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
||||
/// The id of the block.
|
||||
pub id: u64,
|
||||
|
||||
/// The start slot of the block.
|
||||
pub start_slot: u64,
|
||||
|
||||
/// The base liquidity in the market.
|
||||
pub liquidity_base: u64,
|
||||
|
||||
/// The quote liquidity in the market.
|
||||
pub liquidity_quote: u64,
|
||||
|
||||
/// The reward configuration.
|
||||
pub reward_config: RewardConfig,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct CloseEvent {
|
||||
/// The authority of the close transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub id: u64,
|
||||
|
||||
/// The amount of base (hashpower) liquidity burned.
|
||||
pub burned_base: u64,
|
||||
|
||||
/// The amount of quote (ORE) liquidity burned.
|
||||
pub burned_quote: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct CommitEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The amount of hashpower committed.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of the commit transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The total amount of hashpower committed to the block.
|
||||
pub block_commitment: u64,
|
||||
|
||||
/// The total amount of hashpower this miner has committed to the block.
|
||||
pub permit_commitment: u64,
|
||||
|
||||
/// The fee paid per hash.
|
||||
pub fee: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct UncommitEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The amount of hashpower committed.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of the commit transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The total amount of hashpower committed to the block.
|
||||
pub block_commitment: u64,
|
||||
|
||||
/// The total amount of hashpower this miner has committed to the block.
|
||||
pub permit_commitment: u64,
|
||||
|
||||
/// The fee paid per hash.
|
||||
pub fee: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct DepositEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The amount of ORE collateral deposited.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of the commit transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The total amount of ORE this user has deposited as collateral.
|
||||
pub collateral: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct WithdrawEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The amount of ORE collateral withdrawn.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of the commit transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The total amount of ORE this user has deposited as collateral.
|
||||
pub collateral: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
event!(SwapEvent);
|
||||
event!(RewardEvent);
|
||||
event!(OpenEvent);
|
||||
event!(CommitEvent);
|
||||
event!(DepositEvent);
|
||||
event!(WithdrawEvent);
|
||||
event!(UncommitEvent);
|
||||
event!(MineEvent);
|
||||
event!(CloseEvent);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||
|
||||
#[test]
|
||||
fn test_parse_commit_event() {
|
||||
// Create sample return data
|
||||
let data = "BQAAAAAAAAB9607Qp9I2VxNo2rSPHAz/tR2pJzGu9om7qHP71TpKqciMAwAAAAAAAAAAAAAAAAA2CwUAAAAAAADodkgXAAAAAAAAAAAAAAAAAAAAAAAAADYLBQAAAAAAAB7cDBcAAAAAypo7AAAAAMMQW2gAAAAA";
|
||||
let bytes = BASE64_STANDARD.decode(data).unwrap();
|
||||
|
||||
// Parse into CommitEvent
|
||||
let event: &SwapEvent = bytemuck::try_from_bytes(&bytes).unwrap();
|
||||
|
||||
// Verify fields
|
||||
println!("{:?}", event);
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user