use serde::{Deserialize, Serialize, Serializer};
use std::collections::HashMap;
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TokenPriceRequest {
#[serde(rename = "ids")]
#[serde(serialize_with = "to_comma_string")]
pub token_mints: Vec<String>,
pub vs_token: Option<String>,
pub show_extra_info: Option<bool>,
}
impl TokenPriceRequest {
pub fn new(token_mints: &[String]) -> Self {
Self {
token_mints: token_mints.to_vec(),
vs_token: None,
show_extra_info: None,
}
}
pub fn with_vs_token(mut self, vs_token: &str) -> Self {
self.vs_token = Some(vs_token.to_string());
self
}
pub fn with_show_extra_info(mut self, show_extra_info: bool) -> Self {
self.show_extra_info = Some(show_extra_info);
self
}
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TokenPrice {
pub id: String,
#[serde(rename = "type")]
pub data_type: String,
pub price: String,
#[serde(default)]
pub extra_info: Option<serde_json::Value>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TokenPriceResponse {
pub data: HashMap<String, TokenPrice>,
pub time_taken: f64,
}
pub fn to_comma_string<S>(vec: &[String], serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&vec.join(","))
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TokenInfoResponse {
pub address: String,
pub name: String,
pub symbol: String,
pub decimals: i32,
#[serde(rename = "logoURI")]
pub logo_uri: Option<String>,
pub tags: Vec<Option<String>>,
pub daily_volume: Option<f64>,
pub created_at: String,
pub freeze_authority: Option<String>,
pub mint_authority: Option<String>,
pub permanent_delegate: Option<String>,
pub minted_at: Option<String>,
pub extensions: HashMap<String, String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct NewTokens {
pub mint: String,
pub created_at: String,
pub metadata_updated_at: u64,
pub name: String,
pub symbol: String,
pub decimals: u32,
pub logo_uri: Option<String>,
pub known_markets: Vec<String>,
pub mint_authority: Option<String>,
pub freeze_authority: Option<String>,
}