remove grpc impl, use sdk grpc OrderSubscriber

This commit is contained in:
wphan
2024-12-03 09:28:43 -08:00
parent 2f3f9f1c40
commit 93d6bfb7c1
3 changed files with 55 additions and 314 deletions

View File

@@ -1,6 +1,5 @@
import { DLOB, OrderSubscriber, UserAccount, UserMap } from '@drift-labs/sdk';
import { PublicKey } from '@solana/web3.js';
import { GeyserOrderSubscriber } from './grpc/OrderSubscriberGRPC';
export type DLOBProvider = {
subscribe(): Promise<void>;
@@ -91,45 +90,3 @@ export function getDLOBProviderFromOrderSubscriber(
},
};
}
export function getDLOBProviderFromGrpcOrderSubscriber(
orderSubscriber: GeyserOrderSubscriber
): DLOBProvider {
return {
subscribe: async () => {
await orderSubscriber.subscribe();
},
getDLOB: async (slot: number) => {
return await orderSubscriber.getDLOB(slot);
},
getUniqueAuthorities: () => {
const authorities = new Set<string>();
for (const { userAccount } of orderSubscriber.usersAccounts.values()) {
authorities.add(userAccount.authority.toBase58());
}
const pubkeys = Array.from(authorities).map((a) => new PublicKey(a));
return pubkeys;
},
getUserAccounts: function* () {
for (const [
key,
{ userAccount },
] of orderSubscriber.usersAccounts.entries()) {
yield { userAccount: userAccount, publicKey: new PublicKey(key) };
}
},
getUserAccount: (publicKey) => {
return orderSubscriber.usersAccounts.get(publicKey.toString())
?.userAccount;
},
size(): number {
return orderSubscriber.usersAccounts.size;
},
fetch() {
return orderSubscriber.fetch();
},
getSlot: () => {
return orderSubscriber.getSlot();
},
};
}