Skip to main content

bulk_client/msgs/
subaccounts.rs

1use std::sync::Arc;
2use serde::{Deserialize, Serialize};
3use solana_keypair::Pubkey;
4use crate::transaction::ActionMeta;
5
6
7// ─────────────────────────────────────────────────────────────────────────────
8// Type of transfer
9// ─────────────────────────────────────────────────────────────────────────────
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub enum TransferKind {
14    #[serde(rename = "internal")]
15    Internal,
16    #[serde(rename = "external")]
17    External,
18}
19
20impl Default for TransferKind {
21    fn default() -> Self {
22        Self::Internal
23    }
24}
25
26// ─────────────────────────────────────────────────────────────────────────────
27// Actions
28// ─────────────────────────────────────────────────────────────────────────────
29
30#[derive(Clone, Debug, Serialize, Deserialize)]
31#[serde(rename_all = "camelCase")]
32pub struct CreateSubAccount {
33    /// sub-account name
34    pub name: Arc<str>,
35    /// which asset in margin to transfer to sub-account
36    #[serde(default, skip_serializing_if = "Option::is_none")]
37    pub margin_symbol: Option<Arc<str>>,
38    /// amount of margin to transfer
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub margin_amount: Option<f64>,
41
42    #[serde(skip)]
43    pub meta: ActionMeta,
44}
45
46#[derive(Clone, Debug, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct RemoveSubAccount {
49    /// sub-account to be removed
50    #[serde(with = "crate::msgs::serde_pubkey")]
51    pub to_remove: Pubkey,
52
53    #[serde(skip)]
54    pub meta: ActionMeta,
55}
56
57
58#[derive(Clone, Debug, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct Transfer {
61    /// transfer type
62    #[serde(rename = "k", default)]
63    pub kind: TransferKind,
64
65    /// pubkey of account to transfer from
66    #[serde(with = "crate::msgs::serde_pubkey")]
67    pub from: Pubkey,
68    /// pubkey of account to transfer to
69    #[serde(with = "crate::msgs::serde_pubkey")]
70    pub to: Pubkey,
71
72    /// which asset in margin to transfer
73    pub margin_symbol: Arc<str>,
74    /// amount of instrument to transfer
75    pub margin_amount: f64,
76
77    #[serde(skip)]
78    pub meta: ActionMeta,
79}