Remove mango-macro

This commit is contained in:
Christian Kamm 2022-12-08 13:36:51 +01:00
parent a29a736ba2
commit 57e4510b08
12 changed files with 55 additions and 115 deletions

10
Cargo.lock generated
View File

@ -3089,15 +3089,6 @@ dependencies = [
"libc",
]
[[package]]
name = "mango-macro"
version = "0.0.1"
dependencies = [
"bytemuck",
"quote 1.0.21",
"syn 1.0.103",
]
[[package]]
name = "mango-v4"
version = "0.1.0"
@ -3118,7 +3109,6 @@ dependencies = [
"itertools 0.10.5",
"lazy_static",
"log 0.4.17",
"mango-macro",
"margin-trade",
"num 0.4.0",
"num_enum",

View File

@ -1,12 +0,0 @@
[package]
name = "mango-macro"
version = "0.0.1"
edition = "2018"
[lib]
proc-macro = true
[dependencies]
syn = "1.0.89"
bytemuck = "1.8.0"
quote = "1.0.16"

View File

@ -1,20 +0,0 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};
#[proc_macro_derive(Pod)]
pub fn pod(input: TokenStream) -> TokenStream {
let DeriveInput { ident, data, .. } = parse_macro_input!(input);
match data {
syn::Data::Struct(_) => {
quote! {
unsafe impl bytemuck::Zeroable for #ident {}
unsafe impl bytemuck::Pod for #ident {}
}
}
_ => panic!(),
}
.into()
}

View File

@ -31,7 +31,6 @@ checked_math = { path = "../../lib/checked_math" }
derivative = "2.2.0"
fixed = { version = "=1.11.0", features = ["serde", "borsh"] } # todo: higher versions don't work
fixed-macro = "^1.1.1"
mango-macro = { path = "../../mango-macro" }
num_enum = "0.5.1"
pyth-sdk-solana = "0.1.0"
serde = "^1.0"
@ -59,4 +58,4 @@ margin-trade = { path = "../margin-trade", features = ["cpi"] }
itertools = "0.10.3"
rand = "0.8.4"
lazy_static = "1.4.0"
num = "0.4.0"
num = "0.4.0"

View File

@ -124,8 +124,7 @@ pub fn perp_consume_events(ctx: Context<PerpConsumeEvents>, limit: usize) -> Res
market_index: perp_market.perp_market_index,
taker_side: fill.taker_side as u8,
maker_slot: fill.maker_slot,
market_fees_applied: fill.market_fees_applied,
maker_out: fill.maker_out,
maker_out: fill.maker_out(),
timestamp: fill.timestamp,
seq_num: fill.seq_num,
maker: fill.maker,

View File

@ -93,7 +93,6 @@ pub struct FillLog {
pub market_index: u16,
pub taker_side: u8, // side from the taker's POV
pub maker_slot: u8,
pub market_fees_applied: bool,
pub maker_out: bool, // true if maker order quantity == 0
pub timestamp: u64,
pub seq_num: u64, // note: usize same as u64

View File

@ -65,13 +65,11 @@ pub fn load_market_state<'a>(
}
/// Copied over from serum dex
#[derive(Copy, Clone)]
#[derive(Copy, Clone, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(C, packed)]
pub struct OrderBookStateHeader {
pub account_flags: u64, // Initialized, (Bids or Asks)
}
unsafe impl bytemuck::Zeroable for OrderBookStateHeader {}
unsafe impl bytemuck::Pod for OrderBookStateHeader {}
pub fn load_bids_mut<'a>(
sm: &serum_dex::state::MarketState,

View File

@ -869,19 +869,16 @@ impl<
let pa = self.perp_position_mut(perp_market_index)?;
pa.settle_funding(perp_market);
let side = fill.taker_side.invert_side();
let side = fill.taker_side().invert_side();
let (base_change, quote_change) = fill.base_quote_change(side);
let quote = cm!(I80F48::from(perp_market.quote_lot_size) * I80F48::from(quote_change));
let fees = cm!(quote.abs() * fill.maker_fee);
if !fill.market_fees_applied {
cm!(perp_market.fees_accrued += fees);
}
pa.record_trade(perp_market, base_change, quote);
pa.record_fee(fees);
cm!(pa.maker_volume += quote.abs().to_num::<u64>());
if fill.maker_out {
if fill.maker_out() {
self.remove_perp_order(fill.maker_slot as usize, base_change.abs())
} else {
match side {
@ -905,7 +902,7 @@ impl<
let pa = self.perp_position_mut(perp_market_index)?;
pa.settle_funding(perp_market);
let (base_change, quote_change) = fill.base_quote_change(fill.taker_side);
let (base_change, quote_change) = fill.base_quote_change(fill.taker_side());
pa.remove_taker_trade(base_change, quote_change);
// fees are assessed at time of trade; no need to assess fees here
let quote_change_native =

View File

@ -2,7 +2,6 @@ use std::mem::size_of;
use anchor_lang::prelude::*;
use bytemuck::{cast_mut, cast_ref};
use mango_macro::Pod;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use static_assertions::const_assert_eq;
@ -64,7 +63,7 @@ pub fn fixed_price_lots(price_data: u64) -> i64 {
/// Each InnerNode has exactly two children, which are either InnerNodes themselves,
/// or LeafNodes. The children share the top `prefix_len` bits of `key`. The left
/// child has a 0 in the next bit, and the right a 1.
#[derive(Copy, Clone, Pod, AnchorSerialize, AnchorDeserialize)]
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable, AnchorSerialize, AnchorDeserialize)]
#[repr(C)]
pub struct InnerNode {
pub tag: u8, // NodeTag
@ -120,12 +119,22 @@ impl InnerNode {
}
/// LeafNodes represent an order in the binary tree
#[derive(Debug, Copy, Clone, PartialEq, Eq, Pod, AnchorSerialize, AnchorDeserialize)]
#[derive(
Debug,
Copy,
Clone,
PartialEq,
Eq,
bytemuck::Pod,
bytemuck::Zeroable,
AnchorSerialize,
AnchorDeserialize,
)]
#[repr(C)]
pub struct LeafNode {
pub tag: u8, // NodeTag
pub owner_slot: u8,
pub order_type: PostOrderType, // this was added for TradingView move order
pub order_type: u8, // PostOrderType, this was added for TradingView move order
pub padding: [u8; 1],
@ -171,7 +180,7 @@ impl LeafNode {
Self {
tag: NodeTag::LeafNode.into(),
owner_slot,
order_type,
order_type: order_type.into(),
padding: Default::default(),
time_in_force,
padding2: Default::default(),
@ -205,7 +214,7 @@ impl LeafNode {
}
}
#[derive(Copy, Clone, Pod)]
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
pub struct FreeNode {
pub(crate) tag: u8, // NodeTag

View File

@ -1,7 +1,6 @@
use crate::error::MangoError;
use anchor_lang::prelude::*;
use fixed::types::I80F48;
use mango_macro::Pod;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use static_assertions::const_assert_eq;
use std::mem::size_of;
@ -177,15 +176,16 @@ pub enum EventType {
Liquidate,
}
#[derive(Copy, Clone, Debug, Pod, AnchorSerialize, AnchorDeserialize)]
#[derive(
Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable, AnchorSerialize, AnchorDeserialize,
)]
#[repr(C)]
pub struct FillEvent {
pub event_type: u8,
pub taker_side: Side, // side from the taker's POV
pub maker_out: bool, // true if maker order quantity == 0
pub taker_side: u8, // Side, from the taker's POV
pub maker_out: u8, // 1 if maker order quantity == 0
pub maker_slot: u8,
pub market_fees_applied: bool,
pub padding: [u8; 3],
pub padding: [u8; 4],
pub timestamp: u64,
pub seq_num: u64,
@ -230,10 +230,9 @@ impl FillEvent {
) -> FillEvent {
Self {
event_type: EventType::Fill as u8,
taker_side,
maker_out,
taker_side: taker_side.into(),
maker_out: maker_out.into(),
maker_slot,
market_fees_applied: true, // Since mango v3.3.5, market fees are adjusted at matching time
padding: Default::default(),
timestamp,
seq_num,
@ -263,13 +262,22 @@ impl FillEvent {
),
}
}
pub fn taker_side(&self) -> Side {
self.taker_side.try_into().unwrap()
}
pub fn maker_out(&self) -> bool {
self.maker_out == 1
}
}
#[derive(Copy, Clone, Debug, Pod, AnchorSerialize, AnchorDeserialize)]
#[derive(
Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable, AnchorSerialize, AnchorDeserialize,
)]
#[repr(C)]
pub struct OutEvent {
pub event_type: u8,
pub side: Side,
pub side: u8, // Side
pub owner_slot: u8,
padding0: [u8; 5],
pub timestamp: u64,
@ -292,7 +300,7 @@ impl OutEvent {
) -> Self {
Self {
event_type: EventType::Out.into(),
side,
side: side.into(),
owner_slot,
padding0: [0; 5],
timestamp,
@ -302,4 +310,8 @@ impl OutEvent {
padding1: [0; EVENT_SIZE - 64],
}
}
pub fn side(&self) -> Side {
self.side.try_into().unwrap()
}
}

View File

@ -977,7 +977,6 @@ export interface FillEvent extends Event {
takerSide: PerpOrderType;
makerOut: boolean;
makerSlot: number;
marketFeesApplied: boolean;
timestamp: BN;
seqNum: BN;
maker: PublicKey;

View File

@ -5397,9 +5397,7 @@ export type MangoV4 = {
},
{
"name": "orderType",
"type": {
"defined": "PostOrderType"
}
"type": "u8"
},
{
"name": "padding",
@ -5609,28 +5607,22 @@ export type MangoV4 = {
},
{
"name": "takerSide",
"type": {
"defined": "Side"
}
"type": "u8"
},
{
"name": "makerOut",
"type": "bool"
"type": "u8"
},
{
"name": "makerSlot",
"type": "u8"
},
{
"name": "marketFeesApplied",
"type": "bool"
},
{
"name": "padding",
"type": {
"array": [
"u8",
3
4
]
}
},
@ -5709,9 +5701,7 @@ export type MangoV4 = {
},
{
"name": "side",
"type": {
"defined": "Side"
}
"type": "u8"
},
{
"name": "ownerSlot",
@ -6490,11 +6480,6 @@ export type MangoV4 = {
"type": "u8",
"index": false
},
{
"name": "marketFeesApplied",
"type": "bool",
"index": false
},
{
"name": "makerOut",
"type": "bool",
@ -12763,9 +12748,7 @@ export const IDL: MangoV4 = {
},
{
"name": "orderType",
"type": {
"defined": "PostOrderType"
}
"type": "u8"
},
{
"name": "padding",
@ -12975,28 +12958,22 @@ export const IDL: MangoV4 = {
},
{
"name": "takerSide",
"type": {
"defined": "Side"
}
"type": "u8"
},
{
"name": "makerOut",
"type": "bool"
"type": "u8"
},
{
"name": "makerSlot",
"type": "u8"
},
{
"name": "marketFeesApplied",
"type": "bool"
},
{
"name": "padding",
"type": {
"array": [
"u8",
3
4
]
}
},
@ -13075,9 +13052,7 @@ export const IDL: MangoV4 = {
},
{
"name": "side",
"type": {
"defined": "Side"
}
"type": "u8"
},
{
"name": "ownerSlot",
@ -13856,11 +13831,6 @@ export const IDL: MangoV4 = {
"type": "u8",
"index": false
},
{
"name": "marketFeesApplied",
"type": "bool",
"index": false
},
{
"name": "makerOut",
"type": "bool",