1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! Withdrawal models: withdrawals, their history rows and states.
use alloy_primitives::Address;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::{Amount, MoveId, Revision, VenueId, WithdrawalId, open_enum};
open_enum! {
/// A withdrawal's progress at its venue.
pub enum WithdrawalState {
/// Waiting to be submitted.
Queued = "queued",
/// Being submitted; becomes `unknown` after a minute.
Submitting = "submitting",
/// `unknown`: maybe submitted. Never resend it.
Uncertain = "unknown",
/// Acknowledged by the venue; arrival unconfirmed.
Relayed = "relayed",
/// Rejected by the venue, or never started in time.
Refused = "refused",
}
}
open_enum! {
/// Whether funds leave the venue or move to another account on it.
pub enum WithdrawalKind {
/// Out of the venue.
Withdrawal = "withdrawal",
/// To another account on the same venue.
Send = "send",
}
}
open_enum! {
/// A Hyperliquid balance other than the perps margin.
pub enum Dex {
/// A standard account's trade.xyz balance.
Xyz = "xyz",
}
}
/// A withdrawal or same-venue send.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Withdrawal {
/// The withdrawal.
pub id: WithdrawalId,
/// The move it feeds a bridge for.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub move_id: Option<MoveId>,
/// The venue it leaves.
pub venue: VenueId,
/// `Xyz` when it left a standard Hyperliquid account's trade.xyz balance.
#[serde(deserialize_with = "super::required")]
pub from_dex: Option<Dex>,
/// Withdrawal or send.
pub kind: WithdrawalKind,
/// In `venue` base units; on Aster the venue fee included.
pub amount: Amount,
/// A send's recipient; a withdrawal's receiving address.
pub destination: Address,
/// Progress at the venue.
pub state: WithdrawalState,
/// The venue's withdrawal or transfer id once relayed (Polymarket, Aster).
#[serde(deserialize_with = "super::required")]
pub venue_ref: Option<String>,
/// Why it failed.
#[serde(deserialize_with = "super::required")]
pub error: Option<String>,
/// When it was prepared.
pub created_at: DateTime<Utc>,
/// When the venue acknowledged it.
#[serde(deserialize_with = "super::required")]
pub relayed_at: Option<DateTime<Utc>>,
}
/// A withdrawal as withdrawal history lists it, with its revision.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WithdrawalHistoryRow {
/// The withdrawal.
#[serde(flatten)]
pub withdrawal: Withdrawal,
/// Newer state has a higher revision.
pub revision: Revision,
}
/// One chain an Aster withdrawal may go to, with its own limit (`GET /v1/withdrawals/chains`).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WithdrawalChain {
/// The chain id `POST /v1/withdrawals/prepare` takes as `chain_id`.
pub chain_id: u64,
/// The withdrawal's `destination Chain`: `BSC`, `Arbitrum` or `ETH`.
pub name: String,
/// What may leave the margin to this chain now, its fee included, in Aster base units.
pub withdrawable: Amount,
/// Aster's fee to this chain, taken out of the signed amount.
pub fee: Amount,
}
/// The chains a venue's withdrawals may go to, read from the venue now.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WithdrawalChains {
/// The venue (Aster).
pub venue: VenueId,
/// Each chain with its own limit and fee.
pub chains: Vec<WithdrawalChain>,
}
#[cfg(test)]
mod tests;