From d741f42a0c591b1b51d9549b062fa397829798ac Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Tue, 10 Dec 2024 11:26:59 -0500 Subject: [PATCH 1/3] rm DLOBApiClient --- sdk/src/dlob/DLOB.ts | 13 -- sdk/src/dlob/DLOBApiClient.ts | 39 ------ sdk/src/dlob/dlobIdl.json | 248 ---------------------------------- 3 files changed, 300 deletions(-) delete mode 100644 sdk/src/dlob/DLOBApiClient.ts delete mode 100644 sdk/src/dlob/dlobIdl.json diff --git a/sdk/src/dlob/DLOB.ts b/sdk/src/dlob/DLOB.ts index 00b5ec0b6..52fc07ede 100644 --- a/sdk/src/dlob/DLOB.ts +++ b/sdk/src/dlob/DLOB.ts @@ -170,19 +170,6 @@ export class DLOB { return true; } - public initFromOrders(dlobOrders: DLOBOrders, slot: number): boolean { - if (this.initialized) { - return false; - } - - for (const { user, order } of dlobOrders) { - this.insertOrder(order, user.toString(), slot, false); - } - - this.initialized = true; - return true; - } - public handleOrderRecord(record: OrderRecord, slot: number): void { this.insertOrder(record.order, record.user.toString(), slot, false); } diff --git a/sdk/src/dlob/DLOBApiClient.ts b/sdk/src/dlob/DLOBApiClient.ts deleted file mode 100644 index 0975beff5..000000000 --- a/sdk/src/dlob/DLOBApiClient.ts +++ /dev/null @@ -1,39 +0,0 @@ -import fetch from 'node-fetch'; -import { DLOBOrdersCoder } from './DLOBOrders'; -import { DLOB } from './DLOB'; - -type DLOBApiClientConfig = { - url: string; -}; - -export class DLOBApiClient { - url: string; - dlobCoder = DLOBOrdersCoder.create(); - lastSeenDLOB: DLOB; - lastSeenSlot = 0; - - constructor(config: DLOBApiClientConfig) { - this.url = config.url; - } - - public async getDLOB(slot: number): Promise { - const r = await fetch(this.url); - if (!r.ok) { - throw new Error( - `Failed to fetch DLOB from ${this.url}. Status: ${r.status}, ${r.statusText}` - ); - } - - const resp = await r.json(); - const responseSlot = resp['slot']; - if (responseSlot > this.lastSeenSlot) { - const dlobOrdersBuffer = Buffer.from(resp['data'], 'base64'); - const dlobOrders = this.dlobCoder.decode(Buffer.from(dlobOrdersBuffer)); - const dlob = new DLOB(); - dlob.initFromOrders(dlobOrders, slot); - this.lastSeenDLOB = dlob; - this.lastSeenSlot = responseSlot; - } - return this.lastSeenDLOB; - } -} diff --git a/sdk/src/dlob/dlobIdl.json b/sdk/src/dlob/dlobIdl.json deleted file mode 100644 index e56fa3099..000000000 --- a/sdk/src/dlob/dlobIdl.json +++ /dev/null @@ -1,248 +0,0 @@ -{ - "version": "2.0.0", - "name": "dlob", - "instructions": [], - "accounts": [], - "types": [ - { - "name": "DLOBOrders", - "type": { - "vec": { - "defined": "DLOBOrder" - } - } - }, - { - "name": "DLOBOrder", - "type": { - "kind": "struct", - "fields": [ - { - "name": "user", - "type": "publicKey" - }, - { - "name": "order", - "type": { - "defined": "Order" - } - } - ] - } - }, - { - "name": "Order", - "type": { - "kind": "struct", - "fields": [ - { - "name": "slot", - "type": "u64" - }, - { - "name": "price", - "type": "u64" - }, - { - "name": "baseAssetAmount", - "type": "u64" - }, - { - "name": "baseAssetAmountFilled", - "type": "u64" - }, - { - "name": "quoteAssetAmountFilled", - "type": "u64" - }, - { - "name": "triggerPrice", - "type": "u64" - }, - { - "name": "auctionStartPrice", - "type": "u64" - }, - { - "name": "auctionEndPrice", - "type": "u64" - }, - { - "name": "maxTs", - "type": "i64" - }, - { - "name": "oraclePriceOffset", - "type": "i32" - }, - { - "name": "orderId", - "type": "u32" - }, - { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "status", - "type": { - "defined": "OrderStatus" - } - }, - { - "name": "orderType", - "type": { - "defined": "OrderType" - } - }, - { - "name": "marketType", - "type": { - "defined": "MarketType" - } - }, - { - "name": "userOrderId", - "type": "u8" - }, - { - "name": "existingPositionDirection", - "type": { - "defined": "PositionDirection" - } - }, - { - "name": "direction", - "type": { - "defined": "PositionDirection" - } - }, - { - "name": "reduceOnly", - "type": "bool" - }, - { - "name": "postOnly", - "type": "bool" - }, - { - "name": "immediateOrCancel", - "type": "bool" - }, - { - "name": "triggerCondition", - "type": { - "defined": "OrderTriggerCondition" - } - }, - { - "name": "auctionDuration", - "type": "u8" - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 3 - ] - } - } - ] - } - }, - { - "name": "OrderStatus", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Init" - }, - { - "name": "Open" - }, - { - "name": "Filled" - }, - { - "name": "Canceled" - } - ] - } - }, - { - "name": "OrderType", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Market" - }, - { - "name": "Limit" - }, - { - "name": "TriggerMarket" - }, - { - "name": "TriggerLimit" - }, - { - "name": "Oracle" - } - ] - } - }, - { - "name": "OrderTriggerCondition", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Above" - }, - { - "name": "Below" - }, - { - "name": "TriggeredAbove" - }, - { - "name": "TriggeredBelow" - } - ] - } - }, - { - "name": "MarketType", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Spot" - }, - { - "name": "Perp" - } - ] - } - }, - { - "name": "PositionDirection", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Long" - }, - { - "name": "Short" - } - ] - } - } - ], - "events": [], - "errors": [] -} \ No newline at end of file From 4a1467a11124fd40ade881be4afd05a8b56cfdc9 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Tue, 10 Dec 2024 11:28:31 -0500 Subject: [PATCH 2/3] rm methods user event records --- sdk/src/dlob/DLOB.ts | 67 -------------------------------------------- 1 file changed, 67 deletions(-) diff --git a/sdk/src/dlob/DLOB.ts b/sdk/src/dlob/DLOB.ts index 52fc07ede..9294ea803 100644 --- a/sdk/src/dlob/DLOB.ts +++ b/sdk/src/dlob/DLOB.ts @@ -170,73 +170,6 @@ export class DLOB { return true; } - public handleOrderRecord(record: OrderRecord, slot: number): void { - this.insertOrder(record.order, record.user.toString(), slot, false); - } - - public handleOrderActionRecord( - record: OrderActionRecord, - slot: number - ): void { - if (isOneOfVariant(record.action, ['place', 'expire'])) { - return; - } - - if (isVariant(record.action, 'trigger')) { - if (record.taker !== null) { - const takerOrder = this.getOrder(record.takerOrderId, record.taker); - if (takerOrder) { - this.trigger(takerOrder, record.taker, slot, false); - } - } - - if (record.maker !== null) { - const makerOrder = this.getOrder(record.makerOrderId, record.maker); - if (makerOrder) { - this.trigger(makerOrder, record.maker, slot, false); - } - } - } else if (isVariant(record.action, 'fill')) { - if (record.taker !== null) { - const takerOrder = this.getOrder(record.takerOrderId, record.taker); - if (takerOrder) { - this.updateOrder( - takerOrder, - record.taker, - slot, - record.takerOrderCumulativeBaseAssetAmountFilled - ); - } - } - - if (record.maker !== null) { - const makerOrder = this.getOrder(record.makerOrderId, record.maker); - if (makerOrder) { - this.updateOrder( - makerOrder, - record.maker, - slot, - record.makerOrderCumulativeBaseAssetAmountFilled - ); - } - } - } else if (isVariant(record.action, 'cancel')) { - if (record.taker !== null) { - const takerOrder = this.getOrder(record.takerOrderId, record.taker); - if (takerOrder) { - this.delete(takerOrder, record.taker, slot); - } - } - - if (record.maker !== null) { - const makerOrder = this.getOrder(record.makerOrderId, record.maker); - if (makerOrder) { - this.delete(makerOrder, record.maker, slot); - } - } - } - } - public insertOrder( order: Order, userAccount: string, From 4d172437cda6e97b08d34f7eb3ac01805aeb8e3a Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Tue, 10 Dec 2024 11:34:40 -0500 Subject: [PATCH 3/3] rm getVammNodeGenerator --- sdk/src/dlob/DLOB.ts | 16 +++------------- sdk/src/dlob/NodeList.ts | 17 ----------------- 2 files changed, 3 insertions(+), 30 deletions(-) diff --git a/sdk/src/dlob/DLOB.ts b/sdk/src/dlob/DLOB.ts index 9294ea803..03d4d29b9 100644 --- a/sdk/src/dlob/DLOB.ts +++ b/sdk/src/dlob/DLOB.ts @@ -1,4 +1,4 @@ -import { getOrderSignature, getVammNodeGenerator, NodeList } from './NodeList'; +import { getOrderSignature, NodeList } from './NodeList'; import { BASE_PRECISION, BN, @@ -1181,7 +1181,7 @@ export class DLOB { */ *getAsks( marketIndex: number, - fallbackAsk: BN | undefined, + _fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, @@ -1196,11 +1196,6 @@ export class DLOB { this.getRestingLimitAsks(marketIndex, slot, marketType, oraclePriceData), ]; - const marketTypeStr = getVariant(marketType) as MarketTypeStr; - if (marketTypeStr === 'perp' && fallbackAsk) { - generatorList.push(getVammNodeGenerator(fallbackAsk)); - } - yield* this.getBestNode( generatorList, oraclePriceData, @@ -1231,7 +1226,7 @@ export class DLOB { */ *getBids( marketIndex: number, - fallbackBid: BN | undefined, + _fallbackBid: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, @@ -1246,11 +1241,6 @@ export class DLOB { this.getRestingLimitBids(marketIndex, slot, marketType, oraclePriceData), ]; - const marketTypeStr = getVariant(marketType) as MarketTypeStr; - if (marketTypeStr === 'perp' && fallbackBid) { - generatorList.push(getVammNodeGenerator(fallbackBid)); - } - yield* this.getBestNode( generatorList, oraclePriceData, diff --git a/sdk/src/dlob/NodeList.ts b/sdk/src/dlob/NodeList.ts index ab2dd235d..ab1169bcb 100644 --- a/sdk/src/dlob/NodeList.ts +++ b/sdk/src/dlob/NodeList.ts @@ -172,20 +172,3 @@ export class NodeList } } } - -export function* getVammNodeGenerator( - price: BN | undefined -): Generator { - if (!price) { - return; - } - yield { - getPrice: () => price, - isVammNode: () => true, - order: undefined, - userAccount: undefined, - isUserProtectedMaker: false, - isBaseFilled: () => false, - haveFilled: false, - }; -}