use borsh::{BorshDeserialize, BorshSerialize};
use solana_pubkey::Pubkey;
#[derive(Debug, Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
#[borsh(use_discriminant = true)]
#[repr(u8)]
pub enum Side {
Bid = 0,
Ask = 1,
}
impl Side {
pub fn to_api_string(self) -> &'static str {
match self {
Side::Bid => "buy",
Side::Ask => "sell",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
#[borsh(use_discriminant = true)]
#[repr(u8)]
pub enum OrderFlags {
None = 0,
ReduceOnly = 128, }
#[derive(Debug, Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
#[borsh(use_discriminant = true)]
#[repr(u8)]
pub enum SelfTradeBehavior {
Abort = 0,
CancelProvide = 1,
DecrementTake = 2,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct FifoOrderId {
pub price_in_ticks: u64,
pub order_sequence_number: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct CancelId {
pub node_pointer: u32,
pub order_id: FifoOrderId,
}
impl CancelId {
pub fn new(price_in_ticks: u64, order_sequence_number: u64) -> Self {
Self {
node_pointer: 0,
order_id: FifoOrderId {
price_in_ticks,
order_sequence_number,
},
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
#[borsh(use_discriminant = true)]
#[repr(u8)]
pub enum Direction {
GreaterThan = 0,
LessThan = 1,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
#[borsh(use_discriminant = true)]
#[repr(u8)]
pub enum StopLossOrderKind {
IOC = 0,
Limit = 1,
}
pub enum IsolatedCollateralFlow {
TransferFromCrossMargin { collateral: u64 },
Deposit { usdc_amount: u64 },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AccountMeta {
pub pubkey: Pubkey,
pub is_signer: bool,
pub is_writable: bool,
}
impl AccountMeta {
pub fn readonly(pubkey: Pubkey) -> Self {
Self {
pubkey,
is_signer: false,
is_writable: false,
}
}
pub fn writable(pubkey: Pubkey) -> Self {
Self {
pubkey,
is_signer: false,
is_writable: true,
}
}
pub fn readonly_signer(pubkey: Pubkey) -> Self {
Self {
pubkey,
is_signer: true,
is_writable: false,
}
}
pub fn writable_signer(pubkey: Pubkey) -> Self {
Self {
pubkey,
is_signer: true,
is_writable: true,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Instruction {
pub program_id: Pubkey,
pub accounts: Vec<AccountMeta>,
pub data: Vec<u8>,
}
impl From<AccountMeta> for solana_instruction::AccountMeta {
fn from(meta: AccountMeta) -> Self {
Self {
pubkey: meta.pubkey,
is_signer: meta.is_signer,
is_writable: meta.is_writable,
}
}
}
impl From<Instruction> for solana_instruction::Instruction {
fn from(ix: Instruction) -> Self {
Self {
program_id: ix.program_id,
accounts: ix.accounts.into_iter().map(Into::into).collect(),
data: ix.data,
}
}
}