EventSubscriber
TheEventSubscriber provides streaming of Drift protocol events from user sub-accounts. It supports multiple backend implementations: WebSocket, RPC polling, and gRPC.
WebSocket Subscription
ws- Shared PubsubClient instancesub_account- Pubkey of the user’s sub-account (use Drift Program ID for all program events)
dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH to receive events from all sub-accounts.
RPC Polling Subscription
provider- RPC provider implementingEventRpcProvidertraitaccount- Account pubkey to monitor
gRPC Subscription
endpoint- gRPC server endpointx_token- Authentication tokensub_account- Account pubkey to monitor
DriftEventStream
A stream of Drift protocol events implementing theStream trait.
Methods
unsubscribe
DriftEvent
Enum representing all Drift protocol events.Variants
OrderFill
OrderCreate
OrderCancel
OrderExpire
OrderCancelMissing
FundingPayment
Swap
OrderTrigger
EventRpcProvider
Trait for custom RPC providers to support polled event subscriptions.RpcClient from solana-rpc-client automatically implements this trait.
Event Parsing
try_parse_log
raw- Raw log string from transaction logssignature- Transaction signaturetx_idx- Index of the log within the transaction
Some(DriftEvent)if the log is a valid Drift eventNoneotherwise