Merge pull request #147 from drift-labs/master

cleanup
This commit is contained in:
Nour Alharithi
2024-04-17 09:30:16 -07:00
committed by GitHub
3 changed files with 24 additions and 63 deletions

View File

@@ -6,7 +6,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@coral-xyz/anchor": "^0.29.0", "@coral-xyz/anchor": "^0.29.0",
"@drift-labs/sdk": "2.78.0-beta.0", "@drift-labs/sdk": "2.79.0-beta.2",
"@opentelemetry/api": "^1.1.0", "@opentelemetry/api": "^1.1.0",
"@opentelemetry/auto-instrumentations-node": "^0.31.1", "@opentelemetry/auto-instrumentations-node": "^0.31.1",
"@opentelemetry/exporter-prometheus": "^0.31.0", "@opentelemetry/exporter-prometheus": "^0.31.0",

View File

@@ -7,11 +7,9 @@ import morgan from 'morgan';
import { Commitment, Connection, Keypair, PublicKey } from '@solana/web3.js'; import { Commitment, Connection, Keypair, PublicKey } from '@solana/web3.js';
import { import {
BulkAccountLoader,
DLOBNode, DLOBNode,
DLOBSubscriber, DLOBSubscriber,
DriftClient, DriftClient,
DriftClientSubscriptionConfig,
DriftEnv, DriftEnv,
SlotSubscriber, SlotSubscriber,
Wallet, Wallet,
@@ -92,7 +90,7 @@ const serverPort = process.env.PORT || 6969;
export const ORDERBOOK_UPDATE_INTERVAL = 1000; export const ORDERBOOK_UPDATE_INTERVAL = 1000;
const WS_FALLBACK_FETCH_INTERVAL = ORDERBOOK_UPDATE_INTERVAL * 10; const WS_FALLBACK_FETCH_INTERVAL = ORDERBOOK_UPDATE_INTERVAL * 10;
const SLOT_STALENESS_TOLERANCE = const SLOT_STALENESS_TOLERANCE =
parseInt(process.env.SLOT_STALENESS_TOLERANCE) || 20; parseInt(process.env.SLOT_STALENESS_TOLERANCE) || 35;
const ROTATION_COOLDOWN = parseInt(process.env.ROTATION_COOLDOWN) || 5000; const ROTATION_COOLDOWN = parseInt(process.env.ROTATION_COOLDOWN) || 5000;
const useWebsocket = process.env.USE_WEBSOCKET?.toLowerCase() === 'true'; const useWebsocket = process.env.USE_WEBSOCKET?.toLowerCase() === 'true';
const useRedis = process.env.USE_REDIS?.toLowerCase() === 'true'; const useRedis = process.env.USE_REDIS?.toLowerCase() === 'true';
@@ -226,63 +224,32 @@ const main = async (): Promise<void> => {
commitment: stateCommitment, commitment: stateCommitment,
}); });
// only set when polling const slotSubscriber = new SlotSubscriber(connection, {
let bulkAccountLoader: BulkAccountLoader | undefined; resubTimeoutMs: 5000,
});
// only set when using websockets await slotSubscriber.subscribe();
let slotSubscriber: SlotSubscriber | undefined;
let accountSubscription: DriftClientSubscriptionConfig;
if (!useWebsocket) {
bulkAccountLoader = new BulkAccountLoader(
connection,
stateCommitment,
ORDERBOOK_UPDATE_INTERVAL
);
accountSubscription = {
type: 'polling',
accountLoader: bulkAccountLoader,
};
} else {
accountSubscription = {
type: 'websocket',
commitment: stateCommitment,
};
slotSubscriber = new SlotSubscriber(connection, {
resubTimeoutMs: 5000,
});
await slotSubscriber.subscribe();
}
driftClient = new DriftClient({ driftClient = new DriftClient({
connection, connection,
wallet, wallet,
programID: clearingHousePublicKey, programID: clearingHousePublicKey,
accountSubscription, accountSubscription: {
env: driftEnv,
});
let subscriptionConfig;
if (useWebsocket) {
subscriptionConfig = {
type: 'websocket', type: 'websocket',
commitment: stateCommitment, commitment: stateCommitment,
resyncIntervalMs: WS_FALLBACK_FETCH_INTERVAL, resubTimeoutMs: 60_000,
}; },
} else { env: driftEnv,
subscriptionConfig = { });
type: 'polling',
frequency: ORDERBOOK_UPDATE_INTERVAL,
commitment: stateCommitment,
};
}
let updatesReceivedTotal = 0; let updatesReceivedTotal = 0;
const orderSubscriber = new OrderSubscriber({ const orderSubscriber = new OrderSubscriber({
driftClient, driftClient,
subscriptionConfig, subscriptionConfig: {
type: 'websocket',
commitment: stateCommitment,
resubTimeoutMs: 10_000,
resyncIntervalMs: WS_FALLBACK_FETCH_INTERVAL,
},
}); });
orderSubscriber.eventEmitter.on( orderSubscriber.eventEmitter.on(
'updateReceived', 'updateReceived',
@@ -690,11 +657,7 @@ const main = async (): Promise<void> => {
let l2Formatted: any; let l2Formatted: any;
if (useRedis) { if (useRedis) {
if ( if (!isSpot && `${includeVamm}`?.toLowerCase() === 'true') {
!isSpot &&
`${includeVamm}`?.toLowerCase() === 'true' &&
`${includeOracle}`?.toLowerCase() === 'true'
) {
let redisL2: string; let redisL2: string;
const redisClient = perpMarketRedisMap.get(normedMarketIndex).client; const redisClient = perpMarketRedisMap.get(normedMarketIndex).client;
if (parseInt(adjustedDepth as string) === 5) { if (parseInt(adjustedDepth as string) === 5) {
@@ -726,8 +689,7 @@ const main = async (): Promise<void> => {
} else if ( } else if (
isSpot && isSpot &&
`${includeSerum}`?.toLowerCase() === 'true' && `${includeSerum}`?.toLowerCase() === 'true' &&
`${includePhoenix}`?.toLowerCase() === 'true' && `${includePhoenix}`?.toLowerCase() === 'true'
`${includeOracle}`?.toLowerCase() === 'true'
) { ) {
let redisL2: string; let redisL2: string;
const redisClient = spotMarketRedisMap.get(normedMarketIndex).client; const redisClient = spotMarketRedisMap.get(normedMarketIndex).client;
@@ -866,8 +828,7 @@ const main = async (): Promise<void> => {
if (useRedis) { if (useRedis) {
if ( if (
!isSpot && !isSpot &&
normedParam['includeVamm']?.toLowerCase() === 'true' && normedParam['includeVamm']?.toLowerCase() === 'true'
normedParam['includeOracle']?.toLowerCase() === 'true'
) { ) {
let redisL2: string; let redisL2: string;
const redisClient = const redisClient =

View File

@@ -115,10 +115,10 @@
enabled "2.0.x" enabled "2.0.x"
kuler "^2.0.0" kuler "^2.0.0"
"@drift-labs/sdk@2.78.0-beta.0": "@drift-labs/sdk@2.79.0-beta.2":
version "2.78.0-beta.0" version "2.79.0-beta.2"
resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.78.0-beta.0.tgz#5b33c41c561825ebef8849fdc71a76194715d5be" resolved "https://registry.yarnpkg.com/@drift-labs/sdk/-/sdk-2.79.0-beta.2.tgz#0b339759ceabd16334744db371843a9af3d6de36"
integrity sha512-Z/+NY15Du9zRjA9ExIZFsNhxwE0OY5JGdfiu5wPk2mjRmOneEu71sltu5Z+yA89z8nGw/s0oZKdAsQnUZLzX6A== integrity sha512-gXgLiw60KK+fBHA78oVy/ydZKDJe9vyJva8ab1rTQEtSpHA2rGGTKQRcpmfV0qOkRM4O4e54FwNg6SOSPAUZoQ==
dependencies: dependencies:
"@coral-xyz/anchor" "0.28.1-beta.2" "@coral-xyz/anchor" "0.28.1-beta.2"
"@ellipsis-labs/phoenix-sdk" "^1.4.2" "@ellipsis-labs/phoenix-sdk" "^1.4.2"