Skip to content

Make AccountsListBuilder public #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions crates/src/math/account_map_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ use crate::{
DriftClient, MarketId, SdkError, SdkResult,
};

/// Builds an AccountList of relevant spot, perp, and oracle accounts from rpc
/// Builds a list of users's associated spot, perp, and oracle accounts
///
/// ```example(no_run)
/// let mut builder = AccountsListBuilder::default();
/// let accounts_list = builder.try_build(client, user).expect("build accounts");
/// ```
#[derive(Default)]
pub(crate) struct AccountsListBuilder {
pub struct AccountsListBuilder {
/// placeholder account values populated with real market & oracle account data
perp_accounts: Vec<AccountWithKey>,
spot_accounts: Vec<AccountWithKey>,
oracle_accounts: Vec<AccountWithKey>,
}

impl AccountsListBuilder {
/// Constructs an account map from `user` positions
/// Constructs an accounts list from `user` positions sync
///
/// * `client` - drift client instance
/// * `user` - the account to build against
///
/// It relies on the `client` being subscribed to all the necessary markets and oracles
pub fn try_build(&mut self, client: &DriftClient, user: &User) -> SdkResult<AccountsList> {
Expand Down Expand Up @@ -108,7 +116,11 @@ impl AccountsListBuilder {
})
}

/// Constructs an account map from `user` positions
/// Constructs an accounts list from `user` positions
/// fetching from RPC as necessary
///
/// * `client` - drift client instance
/// * `user` - the account to build against
///
/// like `try_build` but will fall back to network queries to fetch market/oracle accounts as required
/// if the client is already subscribed to necessary market/oracles then no network requests are made.
Expand Down
Loading