Nour/improved rotation (#290)

* improved rotation

* fix bugs

* only parse slot if necessary

* add metrics for ws source

* add select by recent slot to utils

* fix solana web3.js version

---------

Co-authored-by: wphan <william@drift.trade>
This commit is contained in:
moosecat
2024-12-03 13:47:02 -08:00
committed by GitHub
parent d539622b13
commit 2a6899384c
10 changed files with 307 additions and 383 deletions

View File

@@ -472,3 +472,18 @@ export type SubscriberLookup = {
openbook?: OpenbookV2Subscriber;
};
};
export const selectMostRecentBySlot = (responses: any[]): any => {
const parsedResponses = responses
.map((response) => {
try {
return JSON.parse(response);
} catch {
return null;
}
})
.filter((parsed) => parsed && typeof parsed.slot === 'number');
return parsedResponses.reduce((mostRecent, current) => {
return !mostRecent || current.slot > mostRecent.slot ? current : mostRecent;
}, null);
};