Skip to content

Commit

Permalink
feat: trade no longer links to opposite trade (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-betdex authored Feb 19, 2024
1 parent 025ba1c commit b91a7f1
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 35 deletions.
3 changes: 1 addition & 2 deletions npm-client/docs/types/trade.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@

## Trade

Type: {purchaser: PublicKey, market: PublicKey, order: PublicKey, oppositeTrade: PublicKey, marketOutcomeIndex: [number][9], forOutcome: [boolean][10], stake: BN, price: [number][9], creationTimestamp: BN, payer: PublicKey}
Type: {purchaser: PublicKey, market: PublicKey, order: PublicKey, marketOutcomeIndex: [number][9], forOutcome: [boolean][10], stake: BN, price: [number][9], creationTimestamp: BN, payer: PublicKey}

### Properties

* `purchaser` **PublicKey** 
* `market` **PublicKey** 
* `order` **PublicKey** 
* `oppositeTrade` **PublicKey** 
* `marketOutcomeIndex` **[number][9]** 
* `forOutcome` **[boolean][10]** 
* `stake` **BN** 
Expand Down
1 change: 0 additions & 1 deletion npm-client/types/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export type Trade = {
purchaser: PublicKey;
market: PublicKey;
order: PublicKey;
oppositeTrade: PublicKey;
marketOutcomeIndex: number;
forOutcome: boolean;
stake: BN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub fn create_trade(
purchaser_pk: &Pubkey,
market_pk: &Pubkey,
order_pk: &Pubkey,
opposite_trade_pk: &Pubkey,
outcome_index: u16,
for_outcome: bool,
stake: u64,
Expand All @@ -18,7 +17,6 @@ pub fn create_trade(
trade.purchaser = *purchaser_pk;
trade.market = *market_pk;
trade.order = *order_pk;
trade.opposite_trade = *opposite_trade_pk;
trade.for_outcome = for_outcome;
trade.market_outcome_index = outcome_index;
trade.stake = stake;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ pub fn match_orders(ctx: &mut Context<MatchOrders>) -> Result<()> {
&ctx.accounts.order_against.purchaser,
&ctx.accounts.order_against.market,
&ctx.accounts.order_against.key(),
&ctx.accounts.trade_for.key(),
ctx.accounts.order_against.market_outcome_index,
ctx.accounts.order_against.for_outcome,
stake_matched,
Expand All @@ -163,7 +162,6 @@ pub fn match_orders(ctx: &mut Context<MatchOrders>) -> Result<()> {
&ctx.accounts.order_for.purchaser,
&ctx.accounts.order_for.market,
&ctx.accounts.order_for.key(),
&ctx.accounts.trade_against.key(),
ctx.accounts.order_for.market_outcome_index,
ctx.accounts.order_for.for_outcome,
stake_matched,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ pub fn on_order_match(
maker_order_pk: &Pubkey,
maker_order: &mut Order,
market_position: &mut MarketPosition,
maker_order_trade_pk: &Pubkey,
maker_order_trade: &mut Trade,
taker_order_trade_pk: &Pubkey,
taker_order_trade: &mut Trade,
payer: &Pubkey,
) -> Result<u64> {
Expand Down Expand Up @@ -74,7 +72,6 @@ pub fn on_order_match(
&maker_order.purchaser,
&maker_order.market,
maker_order_pk,
taker_order_trade_pk,
maker_order.market_outcome_index,
maker_order.for_outcome,
stake,
Expand All @@ -89,7 +86,6 @@ pub fn on_order_match(
&taker_order.purchaser,
&maker_order.market,
&taker_order.pk,
maker_order_trade_pk,
taker_order.outcome_index,
taker_order.for_outcome,
stake,
Expand Down Expand Up @@ -169,8 +165,6 @@ mod test {
matches: MatchingQueue::new(10),
};

let maker_order_trade_pk = Pubkey::new_unique();
let taker_order_trade_pk = Pubkey::new_unique();
let mut maker_order_trade = Trade::default();
let mut taker_order_trade = Trade::default();

Expand All @@ -182,9 +176,7 @@ mod test {
&order_pk,
&mut order,
&mut market_position,
&maker_order_trade_pk,
&mut maker_order_trade,
&taker_order_trade_pk,
&mut taker_order_trade,
&payer_pk,
);
Expand Down Expand Up @@ -266,8 +258,6 @@ mod test {
purchaser: Pubkey::new_unique(),
});

let maker_order_trade_pk = Pubkey::new_unique();
let taker_order_trade_pk = Pubkey::new_unique();
let mut maker_order_trade = Trade::default();
let mut taker_order_trade = Trade::default();

Expand All @@ -279,9 +269,7 @@ mod test {
&order_pk,
&mut order,
&mut market_position,
&maker_order_trade_pk,
&mut maker_order_trade,
&taker_order_trade_pk,
&mut taker_order_trade,
&payer_pk,
);
Expand Down Expand Up @@ -359,8 +347,6 @@ mod test {
purchaser: Pubkey::new_unique(),
});

let maker_order_trade_pk = Pubkey::new_unique();
let taker_order_trade_pk = Pubkey::new_unique();
let mut maker_order_trade = Trade::default();
let mut taker_order_trade = Trade::default();

Expand All @@ -372,9 +358,7 @@ mod test {
&order_pk,
&mut order,
&mut market_position,
&maker_order_trade_pk,
&mut maker_order_trade,
&taker_order_trade_pk,
&mut taker_order_trade,
&payer_pk,
);
Expand Down
2 changes: 0 additions & 2 deletions programs/monaco_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ pub mod monaco_protocol {
&ctx.accounts.maker_order.key(),
&mut ctx.accounts.maker_order,
&mut ctx.accounts.market_position,
&ctx.accounts.maker_order_trade.key(),
&mut ctx.accounts.maker_order_trade,
&ctx.accounts.taker_order_trade.key(),
&mut ctx.accounts.taker_order_trade,
&ctx.accounts.crank_operator.key(),
)?;
Expand Down
3 changes: 1 addition & 2 deletions programs/monaco_protocol/src/state/trade_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub struct Trade {
pub purchaser: Pubkey,
pub market: Pubkey,
pub order: Pubkey,
pub opposite_trade: Pubkey,
pub market_outcome_index: u16,
pub for_outcome: bool,
pub stake: u64,
Expand All @@ -19,7 +18,7 @@ pub struct Trade {

impl Trade {
pub const SIZE: usize = DISCRIMINATOR_SIZE
+ (PUB_KEY_SIZE * 4) // purchaser, market, order, opposite_trade
+ (PUB_KEY_SIZE * 3) // purchaser, market, order
+ U16_SIZE // market_outcome_index
+ BOOL_SIZE // for outcome
+ U64_SIZE // stake
Expand Down
8 changes: 0 additions & 8 deletions tests/protocol/crank_matching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ describe("Matching Crank", () => {
againstTrade.purchaser,
againstTrade.market,
againstTrade.order,
againstTrade.oppositeTrade,
againstTrade.marketOutcomeIndex,
againstTrade.forOutcome,
againstTrade.stake.toNumber(),
Expand All @@ -150,7 +149,6 @@ describe("Matching Crank", () => {
purchaser.publicKey,
market.pk,
againstOrderPk,
forTradePk,
1,
false,
integerStake,
Expand All @@ -162,7 +160,6 @@ describe("Matching Crank", () => {
forTrade.purchaser,
forTrade.market,
forTrade.order,
forTrade.oppositeTrade,
forTrade.marketOutcomeIndex,
forTrade.forOutcome,
forTrade.stake.toNumber(),
Expand All @@ -172,7 +169,6 @@ describe("Matching Crank", () => {
purchaser.publicKey,
market.pk,
forOrderPk,
againstTradePk,
1,
true,
integerStake,
Expand Down Expand Up @@ -272,7 +268,6 @@ describe("Matching Crank", () => {
againstTrade.purchaser,
againstTrade.market,
againstTrade.order,
againstTrade.oppositeTrade,
againstTrade.marketOutcomeIndex,
againstTrade.forOutcome,
againstTrade.stake.toNumber(),
Expand All @@ -283,7 +278,6 @@ describe("Matching Crank", () => {
purchaserB.publicKey,
market.pk,
againstOrderPk,
forTradePk,
1,
false,
integerStake,
Expand All @@ -296,7 +290,6 @@ describe("Matching Crank", () => {
forTrade.purchaser,
forTrade.market,
forTrade.order,
forTrade.oppositeTrade,
forTrade.marketOutcomeIndex,
forTrade.forOutcome,
forTrade.stake.toNumber(),
Expand All @@ -307,7 +300,6 @@ describe("Matching Crank", () => {
purchaserA.publicKey,
market.pk,
forOrderPk,
againstTradePk,
1,
true,
integerStake,
Expand Down

0 comments on commit b91a7f1

Please sign in to comment.