Merge pull request #159 from drift-labs/master

bulk account loader for phoenix
This commit is contained in:
moosecat
2024-05-16 06:42:55 -07:00
committed by GitHub
2 changed files with 29 additions and 10 deletions

View File

@@ -18,6 +18,8 @@ import {
isVariant, isVariant,
OrderSubscriber, OrderSubscriber,
MarketType, MarketType,
PhoenixSubscriber,
BulkAccountLoader,
} from '@drift-labs/sdk'; } from '@drift-labs/sdk';
import { logger, setLogLevel } from './utils/logger'; import { logger, setLogLevel } from './utils/logger';
@@ -36,7 +38,6 @@ import {
SubscriberLookup, SubscriberLookup,
addOracletoResponse, addOracletoResponse,
errorHandler, errorHandler,
getPhoenixSubscriber,
getSerumSubscriber, getSerumSubscriber,
l2WithBNToStrings, l2WithBNToStrings,
normalizeBatchQueryParams, normalizeBatchQueryParams,
@@ -169,11 +170,20 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => {
const phoenixConfigAccount = const phoenixConfigAccount =
await driftClient.getPhoenixV1FulfillmentConfig(market.phoenixMarket); await driftClient.getPhoenixV1FulfillmentConfig(market.phoenixMarket);
if (isVariant(phoenixConfigAccount.status, 'enabled')) { if (isVariant(phoenixConfigAccount.status, 'enabled')) {
const phoenixSubscriber = getPhoenixSubscriber( const bulkAccountLoader = new BulkAccountLoader(
driftClient, driftClient.connection,
market, stateCommitment,
sdkConfig 5_000
); );
const phoenixSubscriber = new PhoenixSubscriber({
connection: driftClient.connection,
programId: new PublicKey(sdkConfig.PHOENIX),
marketAddress: phoenixConfigAccount.phoenixMarket,
accountSubscription: {
type: 'polling',
accountLoader: bulkAccountLoader,
},
});
await phoenixSubscriber.subscribe(); await phoenixSubscriber.subscribe();
// Test get L2 to know if we should add // Test get L2 to know if we should add
try { try {

View File

@@ -17,12 +17,12 @@ import {
OracleInfo, OracleInfo,
PerpMarketConfig, PerpMarketConfig,
SpotMarketConfig, SpotMarketConfig,
PhoenixSubscriber,
} from '@drift-labs/sdk'; } from '@drift-labs/sdk';
import { logger, setLogLevel } from '../utils/logger'; import { logger, setLogLevel } from '../utils/logger';
import { import {
SubscriberLookup, SubscriberLookup,
getPhoenixSubscriber,
getSerumSubscriber, getSerumSubscriber,
parsePositiveIntArray, parsePositiveIntArray,
sleep, sleep,
@@ -206,11 +206,20 @@ const initializeAllMarketSubscribers = async (driftClient: DriftClient) => {
logger.info( logger.info(
`Loading phoenix subscriber for spot market ${market.marketIndex}` `Loading phoenix subscriber for spot market ${market.marketIndex}`
); );
const phoenixSubscriber = getPhoenixSubscriber( const bulkAccountLoader = new BulkAccountLoader(
driftClient, driftClient.connection,
marketConfig, stateCommitment,
sdkConfig 5_000
); );
const phoenixSubscriber = new PhoenixSubscriber({
connection: driftClient.connection,
programId: new PublicKey(sdkConfig.PHOENIX),
marketAddress: phoenixConfigAccount.phoenixMarket,
accountSubscription: {
type: 'polling',
accountLoader: bulkAccountLoader,
},
});
await phoenixSubscriber.subscribe(); await phoenixSubscriber.subscribe();
// Test get L2 to know if we should add // Test get L2 to know if we should add
try { try {