From d2cb57aafa3538299339391b1fa92901083c36e6 Mon Sep 17 00:00:00 2001 From: Britt Cyr Date: Mon, 26 Aug 2024 17:12:23 -0400 Subject: [PATCH] Remove post only slide from the core, plan is for wrapper (#17) --- client/idl/manifest.json | 8 +- client/ts/src/manifest/errors/index.ts | 23 ++++ client/ts/src/manifest/types/OrderType.ts | 1 - programs/manifest/src/state/market.rs | 14 +-- programs/manifest/src/state/resting_order.rs | 5 +- programs/manifest/tests/cases/place_order.rs | 117 ------------------- 6 files changed, 31 insertions(+), 137 deletions(-) diff --git a/client/idl/manifest.json b/client/idl/manifest.json index d0e5f58af..512dfa590 100644 --- a/client/idl/manifest.json +++ b/client/idl/manifest.json @@ -1228,9 +1228,6 @@ { "name": "PostOnly" }, - { - "name": "PostOnlySlide" - }, { "name": "Global" } @@ -1323,6 +1320,11 @@ "code": 16, "name": "GlobalInsufficient", "msg": "Insufficient funds on global account to rest an order" + }, + { + "code": 17, + "name": "IncorrectAccount", + "msg": "Account key did not match expected" } ], "metadata": { diff --git a/client/ts/src/manifest/errors/index.ts b/client/ts/src/manifest/errors/index.ts index fcb650f90..9b58f7b2d 100644 --- a/client/ts/src/manifest/errors/index.ts +++ b/client/ts/src/manifest/errors/index.ts @@ -393,6 +393,29 @@ createErrorFromNameLookup.set( () => new GlobalInsufficientError(), ); +/** + * IncorrectAccount: 'Account key did not match expected' + * + * @category Errors + * @category generated + */ +export class IncorrectAccountError extends Error { + readonly code: number = 0x11; + readonly name: string = 'IncorrectAccount'; + constructor() { + super('Account key did not match expected'); + if (typeof Error.captureStackTrace === 'function') { + Error.captureStackTrace(this, IncorrectAccountError); + } + } +} + +createErrorFromCodeLookup.set(0x11, () => new IncorrectAccountError()); +createErrorFromNameLookup.set( + 'IncorrectAccount', + () => new IncorrectAccountError(), +); + /** * Attempts to resolve a custom program error from the provided error code. * @category Errors diff --git a/client/ts/src/manifest/types/OrderType.ts b/client/ts/src/manifest/types/OrderType.ts index da04d06a0..878fda767 100644 --- a/client/ts/src/manifest/types/OrderType.ts +++ b/client/ts/src/manifest/types/OrderType.ts @@ -14,7 +14,6 @@ export enum OrderType { Limit, ImmediateOrCancel, PostOnly, - PostOnlySlide, Global, } diff --git a/programs/manifest/src/state/market.rs b/programs/manifest/src/state/market.rs index 2df515174..742ba68ba 100644 --- a/programs/manifest/src/state/market.rs +++ b/programs/manifest/src/state/market.rs @@ -514,10 +514,6 @@ impl, Dynamic: DerefOrBorrowMut<[u8]>> let DynamicAccount { fixed, dynamic } = self.borrow_mut(); - // Most of the time this is the price the user inputs, but on a - // PostOnlySlide, it gets updated. - let mut maker_price: QuoteAtomsPerBaseAtom = price; - let mut current_order_index: DataIndex = if is_bid { fixed.asks_best_index } else { @@ -586,12 +582,6 @@ impl, Dynamic: DerefOrBorrowMut<[u8]>> // Got a match. First make sure we are allowed to match. assert_can_take(order_type)?; - if order_type == OrderType::PostOnlySlide { - // Post only slide creates a zero spread book. - maker_price = other_order.get_price(); - break; - } - // Match the order let other_trader_index: DataIndex = other_order.get_trader_index(); let did_fully_match_resting_order: bool = @@ -778,7 +768,7 @@ impl, Dynamic: DerefOrBorrowMut<[u8]>> let resting_order: RestingOrder = RestingOrder::new( trader_index, remaining_base_atoms, - maker_price, + price, order_sequence_number, last_valid_slot, is_bid, @@ -801,7 +791,7 @@ impl, Dynamic: DerefOrBorrowMut<[u8]>> !is_bid, false, if is_bid { - (remaining_base_atoms.checked_mul(maker_price, false)) + (remaining_base_atoms.checked_mul(price, false)) .unwrap() .into() } else { diff --git a/programs/manifest/src/state/resting_order.rs b/programs/manifest/src/state/resting_order.rs index 5cb1c7b90..c37c04bea 100644 --- a/programs/manifest/src/state/resting_order.rs +++ b/programs/manifest/src/state/resting_order.rs @@ -34,11 +34,8 @@ pub enum OrderType { // Fails if would cross the orderbook. PostOnly = 2, - // Like a post only but slides to a zero spread rather than fail. - PostOnlySlide = 3, - // Global orders are post only but use funds from the global account. - Global = 4, + Global = 3, } unsafe impl bytemuck::Zeroable for OrderType {} unsafe impl bytemuck::Pod for OrderType {} diff --git a/programs/manifest/tests/cases/place_order.rs b/programs/manifest/tests/cases/place_order.rs index b5226d4a6..4f0591090 100644 --- a/programs/manifest/tests/cases/place_order.rs +++ b/programs/manifest/tests/cases/place_order.rs @@ -701,123 +701,6 @@ async fn post_only_fail_test() -> anyhow::Result<()> { Ok(()) } -#[tokio::test] -async fn post_only_slide_test() -> anyhow::Result<()> { - let mut test_fixture: TestFixture = TestFixture::new().await; - test_fixture.claim_seat().await?; - - // Ask for 2@10 - test_fixture.deposit(Token::SOL, 20 * SOL_UNIT_SIZE).await?; - test_fixture - .place_order( - Side::Ask, - 2 * SOL_UNIT_SIZE, - 10, - 0, - NO_EXPIRATION_LAST_VALID_SLOT, - OrderType::Limit, - ) - .await?; - - let second_keypair: Keypair = test_fixture.second_keypair.insecure_clone(); - test_fixture.claim_seat_for_keypair(&second_keypair).await?; - test_fixture - .deposit_for_keypair(Token::USDC, 20_000 * USDC_UNIT_SIZE, &second_keypair) - .await?; - - // Post only slide should slide the order down to 10.0 - test_fixture - .place_order_for_keypair( - Side::Bid, - 1 * SOL_UNIT_SIZE, - 11, - 0, - NO_EXPIRATION_LAST_VALID_SLOT, - OrderType::PostOnlySlide, - &second_keypair, - ) - .await?; - - // To verify that we have 10.00000, withdraw 10 and then unable to do more - test_fixture - .withdraw_for_keypair(Token::USDC, 10_000 * USDC_UNIT_SIZE, &second_keypair) - .await?; - - assert!(test_fixture - .withdraw_for_keypair(Token::USDC, 1_000 * USDC_UNIT_SIZE, &second_keypair) - .await - .is_err()); - assert!(test_fixture - .withdraw_for_keypair(Token::SOL, 1 * SOL_UNIT_SIZE, &second_keypair) - .await - .is_err()); - Ok(()) -} - -#[tokio::test] -async fn post_only_slide_ask_test() -> anyhow::Result<()> { - let mut test_fixture: TestFixture = TestFixture::new().await; - test_fixture.claim_seat().await?; - - // Bid for 1@10 - test_fixture - .deposit(Token::USDC, 20_000 * USDC_UNIT_SIZE) - .await?; - test_fixture - .place_order( - Side::Bid, - 1 * SOL_UNIT_SIZE, - 10, - 0, - NO_EXPIRATION_LAST_VALID_SLOT, - OrderType::Limit, - ) - .await?; - - let second_keypair: Keypair = test_fixture.second_keypair.insecure_clone(); - test_fixture.claim_seat_for_keypair(&second_keypair).await?; - test_fixture - .deposit_for_keypair(Token::SOL, 20 * SOL_UNIT_SIZE, &second_keypair) - .await?; - - // Post only slide should slide the order up to 10.000001 - test_fixture - .place_order_for_keypair( - Side::Ask, - 1 * SOL_UNIT_SIZE, - 9, - 0, - NO_EXPIRATION_LAST_VALID_SLOT, - OrderType::PostOnlySlide, - &second_keypair, - ) - .await?; - - // To verify that we have 1@10.000001, bid 1@12 from main keypair and check results. - test_fixture - .place_order( - Side::Bid, - 1 * SOL_UNIT_SIZE, - 12, - 0, - NO_EXPIRATION_LAST_VALID_SLOT, - OrderType::Limit, - ) - .await?; - - // Second keypair got 10.00001, so withdraw 10 and not any more. - test_fixture - .withdraw_for_keypair(Token::USDC, 10_000 * USDC_UNIT_SIZE, &second_keypair) - .await?; - - assert!(test_fixture - .withdraw_for_keypair(Token::USDC, 1_000 * USDC_UNIT_SIZE, &second_keypair) - .await - .is_err()); - - Ok(()) -} - #[tokio::test] async fn place_order_already_expired_test() -> anyhow::Result<()> { let mut test_fixture: TestFixture = TestFixture::new().await;