Skip to content

Commit

Permalink
Remove post only slide from the core, plan is for wrapper (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
brittcyr authored Aug 26, 2024
1 parent fcf14ea commit d2cb57a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 137 deletions.
8 changes: 5 additions & 3 deletions client/idl/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1228,9 +1228,6 @@
{
"name": "PostOnly"
},
{
"name": "PostOnlySlide"
},
{
"name": "Global"
}
Expand Down Expand Up @@ -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": {
Expand Down
23 changes: 23 additions & 0 deletions client/ts/src/manifest/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion client/ts/src/manifest/types/OrderType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export enum OrderType {
Limit,
ImmediateOrCancel,
PostOnly,
PostOnlySlide,
Global,
}

Expand Down
14 changes: 2 additions & 12 deletions programs/manifest/src/state/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,6 @@ impl<Fixed: DerefOrBorrowMut<MarketFixed>, 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 {
Expand Down Expand Up @@ -586,12 +582,6 @@ impl<Fixed: DerefOrBorrowMut<MarketFixed>, 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 =
Expand Down Expand Up @@ -778,7 +768,7 @@ impl<Fixed: DerefOrBorrowMut<MarketFixed>, 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,
Expand All @@ -801,7 +791,7 @@ impl<Fixed: DerefOrBorrowMut<MarketFixed>, 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 {
Expand Down
5 changes: 1 addition & 4 deletions programs/manifest/src/state/resting_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
117 changes: 0 additions & 117 deletions programs/manifest/tests/cases/place_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected], 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;
Expand Down

0 comments on commit d2cb57a

Please sign in to comment.