add logging + small bugfix in unsettled pnl script
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
|||||||
Wallet,
|
Wallet,
|
||||||
ZERO,
|
ZERO,
|
||||||
calculateClaimablePnl,
|
calculateClaimablePnl,
|
||||||
calculatePositionPNL,
|
|
||||||
decodeUser,
|
decodeUser,
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
import { Connection, Keypair } from '@solana/web3.js';
|
import { Connection, Keypair } from '@solana/web3.js';
|
||||||
@@ -41,7 +40,7 @@ const endpoint = process.env.ENDPOINT as string;
|
|||||||
const wsEndpoint = process.env.WS_ENDPOINT as string;
|
const wsEndpoint = process.env.WS_ENDPOINT as string;
|
||||||
const driftEnv = process.env.ENV as string;
|
const driftEnv = process.env.ENV as string;
|
||||||
const chunkSize = Number(process.env.CHUNK_SIZE) || 100;
|
const chunkSize = Number(process.env.CHUNK_SIZE) || 100;
|
||||||
const sleepTimeMs = Number(process.env.SLEEP_TIME_MS) || 5000;
|
const sleepTimeMs = Number(process.env.SLEEP_TIME_MS) || 500;
|
||||||
const delayMs = Number(process.env.DEFAULT_DELAY_MS) || 100;
|
const delayMs = Number(process.env.DEFAULT_DELAY_MS) || 100;
|
||||||
|
|
||||||
const connection = new Connection(endpoint, {
|
const connection = new Connection(endpoint, {
|
||||||
@@ -96,6 +95,7 @@ const main = async () => {
|
|||||||
finishedCount += chunkSize;
|
finishedCount += chunkSize;
|
||||||
|
|
||||||
logger.info(`Wrote ${finishedCount} users, sleeping for ${sleepTimeMs}ms`);
|
logger.info(`Wrote ${finishedCount} users, sleeping for ${sleepTimeMs}ms`);
|
||||||
|
|
||||||
await sleep(sleepTimeMs);
|
await sleep(sleepTimeMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +109,12 @@ const main = async () => {
|
|||||||
} in ${Date.now() - startTime} ms`
|
} in ${Date.now() - startTime} ms`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await sleep(5000);
|
||||||
|
|
||||||
|
logger.info('==== TEST PRINT LOSERS FROM BTC-PERP ====');
|
||||||
|
const losers = await dlobRedisClient.getRaw(`perp_market_1_losers`);
|
||||||
|
logger.info(losers);
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -120,16 +126,23 @@ const writeToDlobRedis = async (userPnlMap: UserPnlMap): Promise<boolean> => {
|
|||||||
const losersRedisKey = `perp_market_${perpMarketIndex}_losers`;
|
const losersRedisKey = `perp_market_${perpMarketIndex}_losers`;
|
||||||
|
|
||||||
// write the new lists
|
// write the new lists
|
||||||
await dlobRedisClient.setRaw(
|
await Promise.all([
|
||||||
gainersRedisKey,
|
dlobRedisClient.setRaw(
|
||||||
JSON.stringify(userPnlMap[perpMarketIndex].gain)
|
gainersRedisKey,
|
||||||
);
|
JSON.stringify(userPnlMap[perpMarketIndex].gain)
|
||||||
await dlobRedisClient.setRaw(
|
),
|
||||||
losersRedisKey,
|
dlobRedisClient.setRaw(
|
||||||
JSON.stringify(userPnlMap[perpMarketIndex].loss)
|
losersRedisKey,
|
||||||
);
|
JSON.stringify(userPnlMap[perpMarketIndex].loss)
|
||||||
|
),
|
||||||
return;
|
]).then(([_winnersResult, _losersResult]) => {
|
||||||
|
logger.info(
|
||||||
|
`Wrote ${userPnlMap[perpMarketIndex].gain.length} users to redis key: ${gainersRedisKey}`
|
||||||
|
);
|
||||||
|
logger.info(
|
||||||
|
`Wrote ${userPnlMap[perpMarketIndex].loss.length} users to redis key: ${losersRedisKey}`
|
||||||
|
);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -151,7 +164,7 @@ const createMarketPnlLeaderboards = (allPnlUsers: AllPnlUsers): UserPnlMap => {
|
|||||||
// store the top 20 winners and losers in each perp market
|
// store the top 20 winners and losers in each perp market
|
||||||
pnlMap[perpMarketIndex] = {
|
pnlMap[perpMarketIndex] = {
|
||||||
gain: sortedPnls.slice(0, 20),
|
gain: sortedPnls.slice(0, 20),
|
||||||
loss: sortedPnls.slice(-20, -1),
|
loss: sortedPnls.slice(-20).reverse(),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -209,22 +222,13 @@ const buildUserMarketLists = (
|
|||||||
false
|
false
|
||||||
)[0];
|
)[0];
|
||||||
|
|
||||||
let marketPnl = calculatePositionPNL(
|
const marketPnl = calculateClaimablePnl(
|
||||||
perpMarketAccount,
|
perpMarketAccount,
|
||||||
|
usdcSpotMarket,
|
||||||
perpPositionWithLpSettle,
|
perpPositionWithLpSettle,
|
||||||
true,
|
|
||||||
oraclePriceData
|
oraclePriceData
|
||||||
);
|
);
|
||||||
|
|
||||||
if (marketPnl.gt(ZERO)) {
|
|
||||||
marketPnl = calculateClaimablePnl(
|
|
||||||
perpMarketAccount,
|
|
||||||
usdcSpotMarket,
|
|
||||||
perpPositionWithLpSettle,
|
|
||||||
oraclePriceData
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return marketPnl.eq(ZERO)
|
return marketPnl.eq(ZERO)
|
||||||
? []
|
? []
|
||||||
: {
|
: {
|
||||||
|
|||||||
Reference in New Issue
Block a user