@dainprotocol/drift-sdk
Version:
SDK for Drift Protocol
104 lines • 4.75 kB
TypeScript
import { User, DriftClient, UserAccount, OrderRecord, WrappedEvent, DLOB, UserSubscriptionConfig, DataAndSlot, ProtectMakerParamsMap } from '..';
import { PublicKey } from '@solana/web3.js';
import { UserAccountFilterCriteria as UserFilterCriteria, UserMapConfig } from './userMapConfig';
export interface UserMapInterface {
subscribe(): Promise<void>;
unsubscribe(): Promise<void>;
addPubkey(userAccountPublicKey: PublicKey, userAccount?: UserAccount, slot?: number, accountSubscription?: UserSubscriptionConfig): Promise<void>;
has(key: string): boolean;
get(key: string): User | undefined;
getWithSlot(key: string): DataAndSlot<User> | undefined;
mustGet(key: string, accountSubscription?: UserSubscriptionConfig): Promise<User>;
mustGetWithSlot(key: string, accountSubscription?: UserSubscriptionConfig): Promise<DataAndSlot<User>>;
getUserAuthority(key: string): PublicKey | undefined;
updateWithOrderRecord(record: OrderRecord): Promise<void>;
values(): IterableIterator<User>;
valuesWithSlot(): IterableIterator<DataAndSlot<User>>;
entries(): IterableIterator<[string, User]>;
entriesWithSlot(): IterableIterator<[string, DataAndSlot<User>]>;
}
export declare class UserMap implements UserMapInterface {
private userMap;
driftClient: DriftClient;
private connection;
private commitment;
private includeIdle;
private filterByPoolId?;
private additionalFilters?;
private disableSyncOnTotalAccountsChange;
private lastNumberOfSubAccounts;
private subscription;
private stateAccountUpdateCallback;
private decode;
private mostRecentSlot;
private syncConfig;
private syncPromise?;
private syncPromiseResolver;
private throwOnFailedSync;
/**
* Constructs a new UserMap instance.
*/
constructor(config: UserMapConfig);
subscribe(): Promise<void>;
addPubkey(userAccountPublicKey: PublicKey, userAccount?: UserAccount, slot?: number, accountSubscription?: UserSubscriptionConfig): Promise<void>;
has(key: string): boolean;
/**
* gets the User for a particular userAccountPublicKey, if no User exists, undefined is returned
* @param key userAccountPublicKey to get User for
* @returns user User | undefined
*/
get(key: string): User | undefined;
getWithSlot(key: string): DataAndSlot<User> | undefined;
/**
* gets the User for a particular userAccountPublicKey, if no User exists, new one is created
* @param key userAccountPublicKey to get User for
* @returns User
*/
mustGet(key: string, accountSubscription?: UserSubscriptionConfig): Promise<User>;
mustGetWithSlot(key: string, accountSubscription?: UserSubscriptionConfig): Promise<DataAndSlot<User>>;
mustGetUserAccount(key: string): Promise<UserAccount>;
/**
* gets the Authority for a particular userAccountPublicKey, if no User exists, undefined is returned
* @param key userAccountPublicKey to get User for
* @returns authority PublicKey | undefined
*/
getUserAuthority(key: string): PublicKey | undefined;
/**
* implements the {@link DLOBSource} interface
* create a DLOB from all the subscribed users
* @param slot
*/
getDLOB(slot: number, protectedMakerParamsMap?: ProtectMakerParamsMap): Promise<DLOB>;
updateWithOrderRecord(record: OrderRecord): Promise<void>;
updateWithEventRecord(record: WrappedEvent<any>): Promise<void>;
values(): IterableIterator<User>;
valuesWithSlot(): IterableIterator<DataAndSlot<User>>;
entries(): IterableIterator<[string, User]>;
entriesWithSlot(): IterableIterator<[string, DataAndSlot<User>]>;
size(): number;
/**
* Returns a unique list of authorities for all users in the UserMap that meet the filter criteria
* @param filterCriteria: Users must meet these criteria to be included
* @returns
*/
getUniqueAuthorities(filterCriteria?: UserFilterCriteria): PublicKey[];
sync(): Promise<void>;
private getFilters;
/**
* Syncs the UserMap using the default sync method (single getProgramAccounts call with filters).
* This method may fail when drift has too many users. (nodejs response size limits)
* @returns
*/
private defaultSync;
/**
* Syncs the UserMap using the paginated sync method (multiple getMultipleAccounts calls with filters).
* This method is more reliable when drift has many users.
* @returns
*/
private paginatedSync;
unsubscribe(): Promise<void>;
updateUserAccount(key: string, userAccount: UserAccount, slot: number): Promise<void>;
updateLatestSlot(slot: number): void;
getSlot(): number;
}
//# sourceMappingURL=userMap.d.ts.map