grpc order subscriber
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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>;
|
||||
@@ -82,3 +83,41 @@ 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<PublicKey>();
|
||||
for (const { userAccount } of orderSubscriber.usersAccounts.values()) {
|
||||
authorities.add(userAccount.authority);
|
||||
}
|
||||
return Array.from(authorities.values());
|
||||
},
|
||||
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();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user