pub struct DriftClientBackend { /* private fields */ }
Expand description
Provides the heavy-lifting and network facing features of the SDK It is intended to be a singleton
Implementations§
Source§impl DriftClientBackend
impl DriftClientBackend
Sourcepub fn is_grpc_subscribed(&self) -> bool
pub fn is_grpc_subscribed(&self) -> bool
Returns true if DriftClientBackend
is subscribed via gRPC
pub fn try_get_perp_market_account_and_slot( &self, market_index: u16, ) -> Option<DataAndSlot<PerpMarket>>
pub fn try_get_spot_market_account_and_slot( &self, market_index: u16, ) -> Option<DataAndSlot<SpotMarket>>
pub fn try_get_oracle_price_data_and_slot( &self, market: MarketId, ) -> Option<Oracle>
Sourcepub fn try_get_oracle_price_data_and_slot_checked(
&self,
market: MarketId,
) -> Option<Oracle>
pub fn try_get_oracle_price_data_and_slot_checked( &self, market: MarketId, ) -> Option<Oracle>
Same as try_get_oracle_price_data_and_slot
but checks the oracle pubkey has not changed
this can be useful if the oracle address changes in the program
Sourcepub async fn get_account<T: AccountDeserialize>(
&self,
account: &Pubkey,
) -> SdkResult<T>
pub async fn get_account<T: AccountDeserialize>( &self, account: &Pubkey, ) -> SdkResult<T>
Fetch account
as an Anchor account type T
Sourcepub async fn get_account_with_slot<T: AccountDeserialize>(
&self,
account: &Pubkey,
) -> SdkResult<DataAndSlot<T>>
pub async fn get_account_with_slot<T: AccountDeserialize>( &self, account: &Pubkey, ) -> SdkResult<DataAndSlot<T>>
Fetch account
as an Anchor account type T
along with the retrieved slot
Sourcepub async fn get_user_account(&self, account: &Pubkey) -> SdkResult<User>
pub async fn get_user_account(&self, account: &Pubkey) -> SdkResult<User>
Fetch account
as a drift User account
uses latest cached if subscribed, otherwise falls back to network query
Sourcepub fn try_get_account<T: AccountDeserialize>(
&self,
account: &Pubkey,
) -> SdkResult<T>
pub fn try_get_account<T: AccountDeserialize>( &self, account: &Pubkey, ) -> SdkResult<T>
Try to fetch account
as T
using latest local value
requires account was previously subscribed too.
Sourcepub async fn get_latest_blockhash(&self) -> SdkResult<Hash>
pub async fn get_latest_blockhash(&self) -> SdkResult<Hash>
Returns latest blockhash
uses latest cached if subscribed, otherwise falls back to network query
Sourcepub async fn sign_and_send(
&self,
wallet: &Wallet,
tx: VersionedMessage,
recent_block_hash: Hash,
) -> SdkResult<Signature>
pub async fn sign_and_send( &self, wallet: &Wallet, tx: VersionedMessage, recent_block_hash: Hash, ) -> SdkResult<Signature>
Sign and send a tx to the network
Returns the signature on success
Sourcepub async fn sign_and_send_with_config(
&self,
wallet: &Wallet,
tx: VersionedMessage,
recent_block_hash: Hash,
config: RpcSendTransactionConfig,
) -> SdkResult<Signature>
pub async fn sign_and_send_with_config( &self, wallet: &Wallet, tx: VersionedMessage, recent_block_hash: Hash, config: RpcSendTransactionConfig, ) -> SdkResult<Signature>
Sign and send a tx to the network with custom send config allows setting commitment level, retries, etc.
Returns the signature on success
Sourcepub async fn oracle_price(&self, market: MarketId) -> SdkResult<i64>
pub async fn oracle_price(&self, market: MarketId) -> SdkResult<i64>
Fetch the live oracle price for market
Uses latest local value from an OracleMap
if subscribed, falls back to network query
Sourcepub async fn get_oracle(&self, market: MarketId) -> SdkResult<Oracle>
pub async fn get_oracle(&self, market: MarketId) -> SdkResult<Oracle>
Fetch live oracle data for market
Uses latest local value from an OracleMap
if subscribed, falls back to network query
Auto Trait Implementations§
impl !Freeze for DriftClientBackend
impl !RefUnwindSafe for DriftClientBackend
impl Send for DriftClientBackend
impl Sync for DriftClientBackend
impl Unpin for DriftClientBackend
impl !UnwindSafe for DriftClientBackend
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more