Merge branch 'master' into mainnet-beta

This commit is contained in:
wphan
2023-11-21 13:04:18 -08:00
4 changed files with 19 additions and 19 deletions

View File

@@ -115,5 +115,9 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
`orderbook_${marketType}_${l2Args.marketIndex}`, `orderbook_${marketType}_${l2Args.marketIndex}`,
JSON.stringify(l2Formatted) JSON.stringify(l2Formatted)
); );
this.redisClient.client.set(
`last_update_orderbook_${marketType}_${l2Args.marketIndex}`,
JSON.stringify(l2Formatted)
);
} }
} }

View File

@@ -184,7 +184,6 @@ const main = async () => {
}); });
const dlobCoder = DLOBOrdersCoder.create(); const dlobCoder = DLOBOrdersCoder.create();
const slotSubscriber = new SlotSubscriber(connection, {});
const lamportsBalance = await connection.getBalance(wallet.publicKey); const lamportsBalance = await connection.getBalance(wallet.publicKey);
logger.info( logger.info(
@@ -199,12 +198,11 @@ const main = async () => {
logger.error(e); logger.error(e);
}); });
await slotSubscriber.subscribe(); setInterval(async () => {
slotSubscriber.eventEmitter.on('newSlot', async (slot: number) => {
await lastSlotReceivedMutex.runExclusive(async () => { await lastSlotReceivedMutex.runExclusive(async () => {
lastSlotReceived = slot; lastSlotReceived = bulkAccountLoader.getSlot();
}); });
}); }, ORDERBOOK_UPDATE_INTERVAL);
const userMap = new UserMap( const userMap = new UserMap(
driftClient, driftClient,
@@ -217,7 +215,7 @@ const main = async () => {
accountLoader: new BulkAccountLoader( accountLoader: new BulkAccountLoader(
connection, connection,
stateCommitment, stateCommitment,
ORDERBOOK_UPDATE_INTERVAL * 10 0
), ),
}); });
await userStatsMap.subscribe(); await userStatsMap.subscribe();
@@ -225,7 +223,7 @@ const main = async () => {
const dlobSubscriber = new DLOBSubscriber({ const dlobSubscriber = new DLOBSubscriber({
driftClient, driftClient,
dlobSource: userMap, dlobSource: userMap,
slotSource: slotSubscriber, slotSource: bulkAccountLoader,
updateFrequency: ORDERBOOK_UPDATE_INTERVAL, updateFrequency: ORDERBOOK_UPDATE_INTERVAL,
}); });
await dlobSubscriber.subscribe(); await dlobSubscriber.subscribe();
@@ -255,7 +253,7 @@ const main = async () => {
// object with userAccount key and orders object serialized // object with userAccount key and orders object serialized
const orders: Array<any> = []; const orders: Array<any> = [];
const oracles: Array<any> = []; const oracles: Array<any> = [];
const slot = slotSubscriber.currentSlot; const slot = bulkAccountLoader.getSlot();
for (const market of driftClient.getPerpMarketAccounts()) { for (const market of driftClient.getPerpMarketAccounts()) {
const oracle = driftClient.getOracleDataForPerpMarket( const oracle = driftClient.getOracleDataForPerpMarket(
@@ -299,7 +297,7 @@ const main = async () => {
app.get('/orders/json', async (_req, res, next) => { app.get('/orders/json', async (_req, res, next) => {
try { try {
// object with userAccount key and orders object serialized // object with userAccount key and orders object serialized
const slot = slotSubscriber.currentSlot; const slot = bulkAccountLoader.getSlot();
const orders: Array<any> = []; const orders: Array<any> = [];
const oracles: Array<any> = []; const oracles: Array<any> = [];
for (const market of driftClient.getPerpMarketAccounts()) { for (const market of driftClient.getPerpMarketAccounts()) {
@@ -462,7 +460,7 @@ const main = async () => {
res.end( res.end(
JSON.stringify({ JSON.stringify({
slot: slotSubscriber.currentSlot, slot: bulkAccountLoader.getSlot(),
data: dlobCoder.encode(dlobOrders).toString('base64'), data: dlobCoder.encode(dlobOrders).toString('base64'),
}) })
); );
@@ -551,7 +549,7 @@ const main = async () => {
.getDLOB() .getDLOB()
.getRestingLimitBids( .getRestingLimitBids(
normedMarketIndex, normedMarketIndex,
slotSubscriber.getSlot(), bulkAccountLoader.getSlot(),
normedMarketType, normedMarketType,
oracle oracle
) )
@@ -562,7 +560,7 @@ const main = async () => {
.getDLOB() .getDLOB()
.getRestingLimitAsks( .getRestingLimitAsks(
normedMarketIndex, normedMarketIndex,
slotSubscriber.getSlot(), bulkAccountLoader.getSlot(),
normedMarketType, normedMarketType,
oracle oracle
) )

View File

@@ -17,6 +17,7 @@ import {
QUOTE_PRECISION, QUOTE_PRECISION,
PRICE_PRECISION, PRICE_PRECISION,
getVariant, getVariant,
ZERO,
} from '@drift-labs/sdk'; } from '@drift-labs/sdk';
import { logger, setLogLevel } from '../utils/logger'; import { logger, setLogLevel } from '../utils/logger';
@@ -181,7 +182,10 @@ const main = async () => {
slot: fill.slot, slot: fill.slot,
action: 'fill', action: 'fill',
actionExplanation: getVariant(fill.actionExplanation), actionExplanation: getVariant(fill.actionExplanation),
referrerReward: convertToNumber(fill.referrerReward, QUOTE_PRECISION), referrerReward: convertToNumber(
fill.referrerReward ?? ZERO,
QUOTE_PRECISION
),
}; };
}) })
) )

View File

@@ -93,12 +93,6 @@ async function main() {
subscribers.forEach((ws) => { subscribers.forEach((ws) => {
ws.send(JSON.stringify({ channel: subscribedChannel, data: message })); ws.send(JSON.stringify({ channel: subscribedChannel, data: message }));
}); });
// Save and persist last message
lastMessageRetriever.client.set(
`last_update_${subscribedChannel}`,
message
);
}); });
redisClient.client.on('error', (error) => { redisClient.client.on('error', (error) => {