diff --git a/package.json b/package.json index 0f2896097..eba55b9ce 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,10 @@ "scripts": { "build": "tsc", "clean": "rm -rf dist", - "type-check": "tsc --pretty --noEmit", + "example": "ts-node ts/example.ts", "format": "prettier --check .", - "lint": "eslint . --ext ts --ext tsx --ext js --quiet" + "lint": "eslint . --ext ts --ext tsx --ext js --quiet", + "type-check": "tsc --pretty --noEmit" }, "author": { "name": "Blockworks Foundation", diff --git a/programs/mango-v4/src/instructions/serum3_cancel_order.rs b/programs/mango-v4/src/instructions/serum3_cancel_order.rs index 4d408f20a..47e18c118 100644 --- a/programs/mango-v4/src/instructions/serum3_cancel_order.rs +++ b/programs/mango-v4/src/instructions/serum3_cancel_order.rs @@ -1,54 +1,10 @@ use anchor_lang::prelude::*; -use arrayref::array_refs; -use borsh::{BorshDeserialize, BorshSerialize}; -use num_enum::TryFromPrimitive; -use std::io::Write; - -use serum_dex::matching::Side; +use serum_dex::instruction::CancelOrderInstructionV2; use crate::error::*; use crate::state::*; -/// Unfortunately CancelOrderInstructionV2 isn't borsh serializable. -/// -/// Make a newtype and implement the traits for it. -pub struct CancelOrderInstructionData(pub serum_dex::instruction::CancelOrderInstructionV2); - -impl CancelOrderInstructionData { - // Copy of CancelOrderInstructionV2::unpack(), which we wish were public! - fn unpack(data: &[u8; 20]) -> Option { - let (&side_arr, &oid_arr) = array_refs![data, 4, 16]; - let side = Side::try_from_primitive(u32::from_le_bytes(side_arr).try_into().ok()?).ok()?; - let order_id = u128::from_le_bytes(oid_arr); - Some(Self(serum_dex::instruction::CancelOrderInstructionV2 { - side, - order_id, - })) - } -} - -impl BorshDeserialize for CancelOrderInstructionData { - fn deserialize(buf: &mut &[u8]) -> std::result::Result { - let data: &[u8; 20] = buf[0..20] - .try_into() - .map_err(|e| std::io::Error::new(std::io::ErrorKind::UnexpectedEof, e))?; - *buf = &buf[20..]; - Self::unpack(data).ok_or_else(|| { - std::io::Error::new( - std::io::ErrorKind::InvalidInput, - error!(MangoError::SomeError), - ) - }) - } -} - -impl BorshSerialize for CancelOrderInstructionData { - fn serialize(&self, writer: &mut W) -> std::result::Result<(), std::io::Error> { - // serum_dex uses bincode::serialize() internally, see MarketInstruction::pack() - writer.write_all(&bincode::serialize(&self.0).unwrap())?; - Ok(()) - } -} +use super::Serum3Side; #[derive(Accounts)] pub struct Serum3CancelOrder<'info> { @@ -88,7 +44,8 @@ pub struct Serum3CancelOrder<'info> { pub fn serum3_cancel_order( ctx: Context, - order: CancelOrderInstructionData, + side: Serum3Side, + order_id: u128, ) -> Result<()> { // // Validation @@ -114,12 +71,16 @@ pub fn serum3_cancel_order( // // Cancel // + let order = serum_dex::instruction::CancelOrderInstructionV2 { + side: u8::try_from(side)?.try_into().unwrap(), + order_id, + }; cpi_cancel_order(ctx.accounts, order)?; Ok(()) } -fn cpi_cancel_order(ctx: &Serum3CancelOrder, order: CancelOrderInstructionData) -> Result<()> { +fn cpi_cancel_order(ctx: &Serum3CancelOrder, order: CancelOrderInstructionV2) -> Result<()> { use crate::serum3_cpi; let group = ctx.group.load()?; serum3_cpi::CancelOrder { @@ -132,5 +93,5 @@ fn cpi_cancel_order(ctx: &Serum3CancelOrder, order: CancelOrderInstructionData) open_orders: ctx.open_orders.to_account_info(), open_orders_authority: ctx.group.to_account_info(), } - .cancel_one(&group, order.0) + .cancel_one(&group, order) } diff --git a/programs/mango-v4/src/instructions/serum3_place_order.rs b/programs/mango-v4/src/instructions/serum3_place_order.rs index 198288660..7425db0d5 100644 --- a/programs/mango-v4/src/instructions/serum3_place_order.rs +++ b/programs/mango-v4/src/instructions/serum3_place_order.rs @@ -1,90 +1,37 @@ +use crate::error::MangoError; +use crate::state::*; use anchor_lang::prelude::*; use anchor_spl::token::{Token, TokenAccount}; -use arrayref::array_refs; -use borsh::{BorshDeserialize, BorshSerialize}; use fixed::types::I80F48; +use num_enum::IntoPrimitive; use num_enum::TryFromPrimitive; +use serum_dex::instruction::NewOrderInstructionV3; use serum_dex::matching::Side; -use std::io::Write; -use std::num::NonZeroU64; -use crate::error::*; -use crate::state::*; +/// Copy paste a bunch of enums so that we could AnchorSerialize & AnchorDeserialize them -/// Unfortunately NewOrderInstructionV3 isn't borsh serializable. -/// -/// Make a newtype and implement the traits for it. -pub struct NewOrderInstructionData(pub serum_dex::instruction::NewOrderInstructionV3); - -impl NewOrderInstructionData { - // Copy of NewOrderInstructionV3::unpack(), which we wish were public! - fn unpack(data: &[u8; 46]) -> Option { - let ( - &side_arr, - &price_arr, - &max_coin_qty_arr, - &max_native_pc_qty_arr, - &self_trade_behavior_arr, - &otype_arr, - &client_order_id_bytes, - &limit_arr, - ) = array_refs![data, 4, 8, 8, 8, 4, 4, 8, 2]; - - let side = serum_dex::matching::Side::try_from_primitive( - u32::from_le_bytes(side_arr).try_into().ok()?, - ) - .ok()?; - let limit_price = NonZeroU64::new(u64::from_le_bytes(price_arr))?; - let max_coin_qty = NonZeroU64::new(u64::from_le_bytes(max_coin_qty_arr))?; - let max_native_pc_qty_including_fees = - NonZeroU64::new(u64::from_le_bytes(max_native_pc_qty_arr))?; - let self_trade_behavior = serum_dex::instruction::SelfTradeBehavior::try_from_primitive( - u32::from_le_bytes(self_trade_behavior_arr) - .try_into() - .ok()?, - ) - .ok()?; - let order_type = serum_dex::matching::OrderType::try_from_primitive( - u32::from_le_bytes(otype_arr).try_into().ok()?, - ) - .ok()?; - let client_order_id = u64::from_le_bytes(client_order_id_bytes); - let limit = u16::from_le_bytes(limit_arr); - - Some(Self(serum_dex::instruction::NewOrderInstructionV3 { - side, - limit_price, - max_coin_qty, - max_native_pc_qty_including_fees, - self_trade_behavior, - order_type, - client_order_id, - limit, - })) - } +#[derive(Clone, Copy, TryFromPrimitive, IntoPrimitive, AnchorSerialize, AnchorDeserialize)] +#[repr(u8)] +pub enum Serum3SelfTradeBehavior { + DecrementTake = 0, + CancelProvide = 1, + AbortTransaction = 2, } -impl BorshDeserialize for NewOrderInstructionData { - fn deserialize(buf: &mut &[u8]) -> std::result::Result { - let data: &[u8; 46] = buf[0..46] - .try_into() - .map_err(|e| std::io::Error::new(std::io::ErrorKind::UnexpectedEof, e))?; - *buf = &buf[46..]; - Self::unpack(data).ok_or_else(|| { - std::io::Error::new( - std::io::ErrorKind::InvalidInput, - error!(MangoError::SomeError), - ) - }) - } -} +#[derive(Clone, Copy, TryFromPrimitive, IntoPrimitive, AnchorSerialize, AnchorDeserialize)] +#[repr(u8)] -impl BorshSerialize for NewOrderInstructionData { - fn serialize(&self, writer: &mut W) -> std::result::Result<(), std::io::Error> { - // serum_dex uses bincode::serialize() internally, see MarketInstruction::pack() - writer.write_all(&bincode::serialize(&self.0).unwrap())?; - Ok(()) - } +pub enum Serum3OrderType { + Limit = 0, + ImmediateOrCancel = 1, + PostOnly = 2, +} +#[derive(Clone, Copy, TryFromPrimitive, IntoPrimitive, AnchorSerialize, AnchorDeserialize)] +#[repr(u8)] + +pub enum Serum3Side { + Bid = 0, + Ask = 1, } #[derive(Accounts)] @@ -148,9 +95,17 @@ pub struct Serum3PlaceOrder<'info> { pub token_program: Program<'info, Token>, } +#[allow(clippy::too_many_arguments)] pub fn serum3_place_order( ctx: Context, - order: NewOrderInstructionData, + side: Serum3Side, + limit_price: u64, + max_base_qty: u64, + max_native_quote_qty_including_fees: u64, + self_trade_behavior: Serum3SelfTradeBehavior, + order_type: Serum3OrderType, + client_order_id: u64, + limit: u16, ) -> Result<()> { // // Validation @@ -205,6 +160,16 @@ pub fn serum3_place_order( // Apply the order to serum. Also immediately settle, in case the order // matched against an existing other order. // + let order = serum_dex::instruction::NewOrderInstructionV3 { + side: u8::try_from(side)?.try_into().unwrap(), + limit_price: limit_price.try_into().unwrap(), + max_coin_qty: max_base_qty.try_into().unwrap(), + max_native_pc_qty_including_fees: max_native_quote_qty_including_fees.try_into().unwrap(), + self_trade_behavior: (self_trade_behavior as u8).try_into().unwrap(), + order_type: (order_type as u8).try_into().unwrap(), + client_order_id, + limit, + }; cpi_place_order(ctx.accounts, order)?; cpi_settle_funds(ctx.accounts)?; @@ -247,10 +212,10 @@ pub fn serum3_place_order( Ok(()) } -fn cpi_place_order(ctx: &Serum3PlaceOrder, order: NewOrderInstructionData) -> Result<()> { +fn cpi_place_order(ctx: &Serum3PlaceOrder, order: NewOrderInstructionV3) -> Result<()> { use crate::serum3_cpi; - let order_payer_token_account = match order.0.side { + let order_payer_token_account = match order.side { Side::Bid => &ctx.quote_vault, Side::Ask => &ctx.base_vault, }; @@ -271,7 +236,7 @@ fn cpi_place_order(ctx: &Serum3PlaceOrder, order: NewOrderInstructionData) -> Re order_payer_token_account: order_payer_token_account.to_account_info(), user_authority: ctx.group.to_account_info(), } - .call(&group, order.0) + .call(&group, order) } fn cpi_settle_funds(ctx: &Serum3PlaceOrder) -> Result<()> { diff --git a/programs/mango-v4/src/lib.rs b/programs/mango-v4/src/lib.rs index 2c53bb882..f84d076d7 100644 --- a/programs/mango-v4/src/lib.rs +++ b/programs/mango-v4/src/lib.rs @@ -105,18 +105,37 @@ pub mod mango_v4 { instructions::serum3_create_open_orders(ctx) } + #[allow(clippy::too_many_arguments)] pub fn serum3_place_order( ctx: Context, - order: instructions::NewOrderInstructionData, + side: Serum3Side, + limit_price: u64, + max_base_qty: u64, + max_native_quote_qty_including_fees: u64, + self_trade_behavior: Serum3SelfTradeBehavior, + order_type: Serum3OrderType, + client_order_id: u64, + limit: u16, ) -> Result<()> { - instructions::serum3_place_order(ctx, order) + instructions::serum3_place_order( + ctx, + side, + limit_price, + max_base_qty, + max_native_quote_qty_including_fees, + self_trade_behavior, + order_type, + client_order_id, + limit, + ) } pub fn serum3_cancel_order( ctx: Context, - order: instructions::CancelOrderInstructionData, + side: Serum3Side, + order_id: u128, ) -> Result<()> { - instructions::serum3_cancel_order(ctx, order) + instructions::serum3_cancel_order(ctx, side, order_id) } pub fn serum3_settle_funds(ctx: Context) -> Result<()> { diff --git a/programs/mango-v4/tests/program_test/mango_client.rs b/programs/mango-v4/tests/program_test/mango_client.rs index a0197a605..6dfa33b2f 100644 --- a/programs/mango-v4/tests/program_test/mango_client.rs +++ b/programs/mango-v4/tests/program_test/mango_client.rs @@ -5,6 +5,7 @@ use anchor_lang::solana_program::sysvar::{self, SysvarId}; use anchor_spl::token::{Token, TokenAccount}; use fixed::types::I80F48; use itertools::Itertools; +use mango_v4::instructions::{Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side}; use solana_program::instruction::Instruction; use solana_sdk::instruction; use solana_sdk::signature::{Keypair, Signer}; @@ -838,12 +839,12 @@ impl<'keypair> ClientInstruction for Serum3CreateOpenOrdersInstruction<'keypair> } pub struct Serum3PlaceOrderInstruction<'keypair> { - pub side: u8, + pub side: Serum3Side, pub limit_price: u64, pub max_base_qty: u64, pub max_native_quote_qty_including_fees: u64, - pub self_trade_behavior: u8, - pub order_type: u8, + pub self_trade_behavior: Serum3SelfTradeBehavior, + pub order_type: Serum3OrderType, pub client_order_id: u64, pub limit: u16, @@ -862,21 +863,14 @@ impl<'keypair> ClientInstruction for Serum3PlaceOrderInstruction<'keypair> { ) -> (Self::Accounts, instruction::Instruction) { let program_id = mango_v4::id(); let instruction = Self::Instruction { - order: mango_v4::instructions::NewOrderInstructionData( - serum_dex::instruction::NewOrderInstructionV3 { - side: self.side.try_into().unwrap(), - limit_price: self.limit_price.try_into().unwrap(), - max_coin_qty: self.max_base_qty.try_into().unwrap(), - max_native_pc_qty_including_fees: self - .max_native_quote_qty_including_fees - .try_into() - .unwrap(), - self_trade_behavior: self.self_trade_behavior.try_into().unwrap(), - order_type: self.order_type.try_into().unwrap(), - client_order_id: self.client_order_id, - limit: self.limit, - }, - ), + side: self.side, + limit_price: self.limit_price, + max_base_qty: self.max_base_qty, + max_native_quote_qty_including_fees: self.max_native_quote_qty_including_fees, + self_trade_behavior: self.self_trade_behavior, + order_type: self.order_type, + client_order_id: self.client_order_id, + limit: self.limit, }; let account: MangoAccount = account_loader.load(&self.account).await.unwrap(); @@ -952,7 +946,7 @@ impl<'keypair> ClientInstruction for Serum3PlaceOrderInstruction<'keypair> { } pub struct Serum3CancelOrderInstruction<'keypair> { - pub side: u8, + pub side: Serum3Side, pub order_id: u128, pub account: Pubkey, @@ -970,12 +964,8 @@ impl<'keypair> ClientInstruction for Serum3CancelOrderInstruction<'keypair> { ) -> (Self::Accounts, instruction::Instruction) { let program_id = mango_v4::id(); let instruction = Self::Instruction { - order: mango_v4::instructions::CancelOrderInstructionData( - serum_dex::instruction::CancelOrderInstructionV2 { - side: self.side.try_into().unwrap(), - order_id: self.order_id, - }, - ), + side: self.side, + order_id: self.order_id, }; let account: MangoAccount = account_loader.load(&self.account).await.unwrap(); diff --git a/programs/mango-v4/tests/test_liq_tokens.rs b/programs/mango-v4/tests/test_liq_tokens.rs index 75fae9f5f..1cb21ced1 100644 --- a/programs/mango-v4/tests/test_liq_tokens.rs +++ b/programs/mango-v4/tests/test_liq_tokens.rs @@ -4,7 +4,10 @@ use fixed::types::I80F48; use solana_program_test::*; use solana_sdk::{signature::Keypair, transport::TransportError}; -use mango_v4::state::*; +use mango_v4::{ + instructions::{Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side}, + state::*, +}; use program_test::*; mod program_test; @@ -135,12 +138,12 @@ async fn test_liq_tokens_force_cancel() -> Result<(), TransportError> { send_tx( solana, Serum3PlaceOrderInstruction { - side: 1, // TODO: Ask + side: Serum3Side::Ask, limit_price: 10, // in quote_lot (10) per base lot (100) max_base_qty: 5, // in base lot (100) max_native_quote_qty_including_fees: 600, - self_trade_behavior: 0, - order_type: 0, // TODO: Limit + self_trade_behavior: Serum3SelfTradeBehavior::DecrementTake, + order_type: Serum3OrderType::Limit, client_order_id: 0, limit: 10, account, diff --git a/programs/mango-v4/tests/test_serum.rs b/programs/mango-v4/tests/test_serum.rs index f03054962..53b9acbd0 100644 --- a/programs/mango-v4/tests/test_serum.rs +++ b/programs/mango-v4/tests/test_serum.rs @@ -3,7 +3,10 @@ use solana_program_test::*; use solana_sdk::{signature::Keypair, transport::TransportError}; -use mango_v4::state::*; +use mango_v4::{ + instructions::{Serum3OrderType, Serum3SelfTradeBehavior, Serum3Side}, + state::*, +}; use program_test::*; mod program_test; @@ -137,12 +140,12 @@ async fn test_serum() -> Result<(), TransportError> { send_tx( solana, Serum3PlaceOrderInstruction { - side: 0, // TODO: Bid + side: Serum3Side::Bid, limit_price: 10, // in quote_lot (10) per base lot (100) max_base_qty: 1, // in base lot (100) max_native_quote_qty_including_fees: 100, - self_trade_behavior: 0, - order_type: 0, // TODO: Limit + self_trade_behavior: Serum3SelfTradeBehavior::DecrementTake, + order_type: Serum3OrderType::Limit, client_order_id: 0, limit: 10, account, @@ -172,7 +175,7 @@ async fn test_serum() -> Result<(), TransportError> { send_tx( solana, Serum3CancelOrderInstruction { - side: 0, + side: Serum3Side::Bid, order_id, account, owner, diff --git a/release.sh b/release.sh index a366ac919..cb42b8e0e 100755 --- a/release.sh +++ b/release.sh @@ -15,13 +15,18 @@ anchor build --skip-lint # update types in ts client package cp -v ./target/types/mango_v4.ts ./ts/mango_v4.ts -# publish program -solana --url https://mango.devnet.rpcpool.com program deploy --program-id $PROGRAM_ID \ - -k $WALLET_WITH_FUNDS target/deploy/mango_v4.so +if [[ -z "${NO_DEPLOY}" ]]; then + # publish program + solana --url https://mango.devnet.rpcpool.com program deploy --program-id $PROGRAM_ID \ + -k $WALLET_WITH_FUNDS target/deploy/mango_v4.so + + # publish idl + anchor idl upgrade --provider.cluster https://mango.devnet.rpcpool.com --provider.wallet $WALLET_WITH_FUNDS \ + --filepath target/idl/mango_v4.json $PROGRAM_ID +else + echo "Skipping deployment..." +fi -# publish idl -anchor idl upgrade --provider.cluster https://mango.devnet.rpcpool.com --provider.wallet $WALLET_WITH_FUNDS \ - --filepath target/idl/mango_v4.json $PROGRAM_ID # build npm package # yarn clean && yarn build && cp package.json ./dist/ diff --git a/ts/client.ts b/ts/client.ts index b15b41eaa..4a688346e 100644 --- a/ts/client.ts +++ b/ts/client.ts @@ -35,8 +35,6 @@ export class MangoClient { addDummyType(idl, 'AnyNode'); addDummyType(idl, 'EventQueueHeader'); addDummyType(idl, 'AnyEvent'); - addDummyType(idl, 'instructions::NewOrderInstructionData'); - addDummyType(idl, 'instructions::CancelOrderInstructionData'); addDummyType(idl, 'H'); addDummyType(idl, 'H::Item'); addDummyType(idl, 'NodeHandle'); diff --git a/ts/mango_v4.ts b/ts/mango_v4.ts index 4e2412985..d3cc43a0c 100644 --- a/ts/mango_v4.ts +++ b/ts/mango_v4.ts @@ -717,10 +717,42 @@ export type MangoV4 = { ], "args": [ { - "name": "order", + "name": "side", "type": { - "defined": "instructions::NewOrderInstructionData" + "defined": "Serum3Side" } + }, + { + "name": "limitPrice", + "type": "u64" + }, + { + "name": "maxBaseQty", + "type": "u64" + }, + { + "name": "maxNativeQuoteQtyIncludingFees", + "type": "u64" + }, + { + "name": "selfTradeBehavior", + "type": { + "defined": "Serum3SelfTradeBehavior" + } + }, + { + "name": "orderType", + "type": { + "defined": "Serum3OrderType" + } + }, + { + "name": "clientOrderId", + "type": "u64" + }, + { + "name": "limit", + "type": "u16" } ] }, @@ -780,10 +812,14 @@ export type MangoV4 = { ], "args": [ { - "name": "order", + "name": "side", "type": { - "defined": "instructions::CancelOrderInstructionData" + "defined": "Serum3Side" } + }, + { + "name": "orderId", + "type": "u128" } ] }, @@ -1178,15 +1214,15 @@ export type MangoV4 = { } }, { - "name": "price", + "name": "priceLots", "type": "i64" }, { - "name": "maxBaseQuantity", + "name": "maxBaseLots", "type": "i64" }, { - "name": "maxQuoteQuantity", + "name": "maxQuoteLots", "type": "i64" }, { @@ -1451,47 +1487,9 @@ export type MangoV4 = { } }, { - "name": "perpAccountMap", + "name": "perp", "type": { - "defined": "PerpAccountMap" - } - }, - { - "name": "orderMarket", - "type": { - "array": [ - "u16", - 8 - ] - } - }, - { - "name": "orderSide", - "type": { - "array": [ - { - "defined": "Side" - }, - 8 - ] - } - }, - { - "name": "orders", - "type": { - "array": [ - "i128", - 8 - ] - } - }, - { - "name": "clientOrderIds", - "type": { - "array": [ - "u64", - 8 - ] + "defined": "PerpData" } }, { @@ -1916,41 +1914,41 @@ export type MangoV4 = { } }, { - "name": "basePosition", + "name": "basePositionLots", "type": "i64" }, { - "name": "quotePosition", + "name": "quotePositionNative", "type": { "defined": "I80F48" } }, { - "name": "bidsQuantity", + "name": "bidsBaseLots", "type": "i64" }, { - "name": "asksQuantity", + "name": "asksBaseLots", "type": "i64" }, { - "name": "takerBase", + "name": "takerBaseLots", "type": "i64" }, { - "name": "takerQuote", + "name": "takerQuoteLots", "type": "i64" } ] } }, { - "name": "PerpAccountMap", + "name": "PerpData", "type": { "kind": "struct", "fields": [ { - "name": "values", + "name": "accounts", "type": { "array": [ { @@ -1959,6 +1957,44 @@ export type MangoV4 = { 8 ] } + }, + { + "name": "orderMarket", + "type": { + "array": [ + "u16", + 8 + ] + } + }, + { + "name": "orderSide", + "type": { + "array": [ + { + "defined": "Side" + }, + 8 + ] + } + }, + { + "name": "orderId", + "type": { + "array": [ + "i128", + 8 + ] + } + }, + { + "name": "orderClientId", + "type": { + "array": [ + "u64", + 8 + ] + } } ] } @@ -2178,6 +2214,54 @@ export type MangoV4 = { ] } }, + { + "name": "Serum3SelfTradeBehavior", + "type": { + "kind": "enum", + "variants": [ + { + "name": "DecrementTake" + }, + { + "name": "CancelProvide" + }, + { + "name": "AbortTransaction" + } + ] + } + }, + { + "name": "Serum3OrderType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Limit" + }, + { + "name": "ImmediateOrCancel" + }, + { + "name": "PostOnly" + } + ] + } + }, + { + "name": "Serum3Side", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Bid" + }, + { + "name": "Ask" + } + ] + } + }, { "name": "ProgramInstruction", "type": { @@ -2980,10 +3064,42 @@ export const IDL: MangoV4 = { ], "args": [ { - "name": "order", + "name": "side", "type": { - "defined": "instructions::NewOrderInstructionData" + "defined": "Serum3Side" } + }, + { + "name": "limitPrice", + "type": "u64" + }, + { + "name": "maxBaseQty", + "type": "u64" + }, + { + "name": "maxNativeQuoteQtyIncludingFees", + "type": "u64" + }, + { + "name": "selfTradeBehavior", + "type": { + "defined": "Serum3SelfTradeBehavior" + } + }, + { + "name": "orderType", + "type": { + "defined": "Serum3OrderType" + } + }, + { + "name": "clientOrderId", + "type": "u64" + }, + { + "name": "limit", + "type": "u16" } ] }, @@ -3043,10 +3159,14 @@ export const IDL: MangoV4 = { ], "args": [ { - "name": "order", + "name": "side", "type": { - "defined": "instructions::CancelOrderInstructionData" + "defined": "Serum3Side" } + }, + { + "name": "orderId", + "type": "u128" } ] }, @@ -3441,15 +3561,15 @@ export const IDL: MangoV4 = { } }, { - "name": "price", + "name": "priceLots", "type": "i64" }, { - "name": "maxBaseQuantity", + "name": "maxBaseLots", "type": "i64" }, { - "name": "maxQuoteQuantity", + "name": "maxQuoteLots", "type": "i64" }, { @@ -3714,47 +3834,9 @@ export const IDL: MangoV4 = { } }, { - "name": "perpAccountMap", + "name": "perp", "type": { - "defined": "PerpAccountMap" - } - }, - { - "name": "orderMarket", - "type": { - "array": [ - "u16", - 8 - ] - } - }, - { - "name": "orderSide", - "type": { - "array": [ - { - "defined": "Side" - }, - 8 - ] - } - }, - { - "name": "orders", - "type": { - "array": [ - "i128", - 8 - ] - } - }, - { - "name": "clientOrderIds", - "type": { - "array": [ - "u64", - 8 - ] + "defined": "PerpData" } }, { @@ -4179,41 +4261,41 @@ export const IDL: MangoV4 = { } }, { - "name": "basePosition", + "name": "basePositionLots", "type": "i64" }, { - "name": "quotePosition", + "name": "quotePositionNative", "type": { "defined": "I80F48" } }, { - "name": "bidsQuantity", + "name": "bidsBaseLots", "type": "i64" }, { - "name": "asksQuantity", + "name": "asksBaseLots", "type": "i64" }, { - "name": "takerBase", + "name": "takerBaseLots", "type": "i64" }, { - "name": "takerQuote", + "name": "takerQuoteLots", "type": "i64" } ] } }, { - "name": "PerpAccountMap", + "name": "PerpData", "type": { "kind": "struct", "fields": [ { - "name": "values", + "name": "accounts", "type": { "array": [ { @@ -4222,6 +4304,44 @@ export const IDL: MangoV4 = { 8 ] } + }, + { + "name": "orderMarket", + "type": { + "array": [ + "u16", + 8 + ] + } + }, + { + "name": "orderSide", + "type": { + "array": [ + { + "defined": "Side" + }, + 8 + ] + } + }, + { + "name": "orderId", + "type": { + "array": [ + "i128", + 8 + ] + } + }, + { + "name": "orderClientId", + "type": { + "array": [ + "u64", + 8 + ] + } } ] } @@ -4441,6 +4561,54 @@ export const IDL: MangoV4 = { ] } }, + { + "name": "Serum3SelfTradeBehavior", + "type": { + "kind": "enum", + "variants": [ + { + "name": "DecrementTake" + }, + { + "name": "CancelProvide" + }, + { + "name": "AbortTransaction" + } + ] + } + }, + { + "name": "Serum3OrderType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Limit" + }, + { + "name": "ImmediateOrCancel" + }, + { + "name": "PostOnly" + } + ] + } + }, + { + "name": "Serum3Side", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Bid" + }, + { + "name": "Ask" + } + ] + } + }, { "name": "ProgramInstruction", "type": { diff --git a/ts/types.ts b/ts/types.ts index 12d9f10ec..217a662ce 100644 --- a/ts/types.ts +++ b/ts/types.ts @@ -90,11 +90,7 @@ export class MangoAccount { delegate: PublicKey; tokenAccountMap: unknown; serum3AccountMap: Object; - perpAccountMap: Object; - orderMarket: number[]; - orderSide: unknown; - orders: BN[]; - clientOrderIds: BN[]; + perp: unknown; beingLiquidated: number; isBankrupt: number; accountNum: number; @@ -109,11 +105,7 @@ export class MangoAccount { obj.delegate, obj.tokenAccountMap as { values: TokenAccountDto[] }, obj.serum3AccountMap, - obj.perpAccountMap, - obj.orderMarket, - obj.orderSide, - obj.orders, - obj.clientOrderIds, + obj.perp, obj.beingLiquidated, obj.isBankrupt, obj.accountNum, @@ -129,11 +121,7 @@ export class MangoAccount { delegate: PublicKey, tokenAccountMap: { values: TokenAccountDto[] }, serum3AccountMap: Object, - perpAccountMap: Object, - orderMarket: number[], - orderSide: unknown, - orders: BN[], - clientOrderIds: BN[], + perp: unknown, beingLiquidated: number, isBankrupt: number, accountNum: number,