From 0555782ecaab65ace6d6015e49d04e603fc41b37 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Thu, 4 Dec 2025 00:53:05 +0000 Subject: [PATCH] init --- src/core/modes/inter/index.test.ts | 34 +++++++++++++++--------------- src/core/modes/inter/index.ts | 6 ++++++ src/core/modes/intra/index.ts | 6 ++++++ 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/core/modes/inter/index.test.ts b/src/core/modes/inter/index.test.ts index c5f41e62..8063e9b9 100644 --- a/src/core/modes/inter/index.test.ts +++ b/src/core/modes/inter/index.test.ts @@ -86,19 +86,19 @@ describe("Test findBestInterOrderbookTrade", () => { { orderbook: "0xorderbook1", id: "order1", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, { orderbook: "0xorderbook1", id: "order2", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, ], [ { orderbook: "0xorderbook2", id: "order3", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, ], ]; @@ -158,12 +158,12 @@ describe("Test findBestInterOrderbookTrade", () => { { orderbook: "0xorderbook1", id: "order1", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, { orderbook: "0xorderbook1", id: "order2", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, ], ]; @@ -211,14 +211,14 @@ describe("Test findBestInterOrderbookTrade", () => { { orderbook: "0xorderbook1", id: "order1", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, ], [ { orderbook: "0xorderbook2", id: "order2", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, ], ]; @@ -291,27 +291,27 @@ describe("Test findBestInterOrderbookTrade", () => { { orderbook: "0xorderbook1", id: "order1", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, { orderbook: "0xorderbook1", id: "order2", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, { orderbook: "0xorderbook1", id: "order3", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, { orderbook: "0xorderbook1", id: "order4", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, // should be ignored { orderbook: "0xorderbook1", id: "order5", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, // should be ignored ], ]; @@ -348,7 +348,7 @@ describe("Test findBestInterOrderbookTrade", () => { { orderbook: "0xorderbook1", id: "order1", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, ], ]; @@ -379,7 +379,7 @@ describe("Test findBestInterOrderbookTrade", () => { counterpartyOrderDetails: { orderbook: "0xorderbook1", id: "order1", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, signer, maximumInputFixed: 1000n, @@ -395,17 +395,17 @@ describe("Test findBestInterOrderbookTrade", () => { { orderbook: "0xorderbook1", id: "order1", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, { orderbook: "0xorderbook1", id: "order2", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, { orderbook: "0xorderbook1", id: "order3", - takeOrder: { struct: { order: { type: Order.Type.V4 } } }, + takeOrder: { struct: { order: { type: Order.Type.V4 } }, quote: {} }, }, ], ]; diff --git a/src/core/modes/inter/index.ts b/src/core/modes/inter/index.ts index 91136e3f..85fda135 100644 --- a/src/core/modes/inter/index.ts +++ b/src/core/modes/inter/index.ts @@ -61,6 +61,12 @@ export async function findBestInterOrderbookTrade( counterparties.push(...cps); return cps.map((counterpartyOrderDetails) => { + if (!orderDetails.takeOrder.quote || !counterpartyOrderDetails.takeOrder.quote) { + return Result.err({ + type: TradeType.InterOrderbook, + spanAttributes: {}, + }) as SimulationResult; + } return InterOrderbookTradeSimulator.withArgs({ type: TradeType.InterOrderbook, solver: this, diff --git a/src/core/modes/intra/index.ts b/src/core/modes/intra/index.ts index c350a005..c0a78cb9 100644 --- a/src/core/modes/intra/index.ts +++ b/src/core/modes/intra/index.ts @@ -112,6 +112,12 @@ export async function findBestIntraOrderbookTrade( // run simulations for top 3 counterparty orders const promises = counterpartyOrders.slice(0, 3).map((counterparty) => { + if (!orderDetails.takeOrder.quote || !counterparty.takeOrder.quote) { + return Result.err({ + type: TradeType.IntraOrderbook, + spanAttributes: {}, + }) as SimulationResult; + } return IntraOrderbookTradeSimulator.withArgs({ type: TradeType.IntraOrderbook, solver: this,