|
@@ -13,12 +13,12 @@ use serde::{
|
|
|
use solana_program::pubkey::Pubkey;
|
|
use solana_program::pubkey::Pubkey;
|
|
|
|
|
|
|
|
/// Pyth2wormhole config specific to attestation requests
|
|
/// Pyth2wormhole config specific to attestation requests
|
|
|
-#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
|
|
|
+#[derive(Debug, Deserialize, Serialize, PartialEq)]
|
|
|
pub struct AttestationConfig {
|
|
pub struct AttestationConfig {
|
|
|
pub symbol_groups: Vec<SymbolGroup>,
|
|
pub symbol_groups: Vec<SymbolGroup>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
|
|
|
+#[derive(Debug, Deserialize, Serialize, PartialEq)]
|
|
|
pub struct SymbolGroup {
|
|
pub struct SymbolGroup {
|
|
|
pub group_name: String,
|
|
pub group_name: String,
|
|
|
/// Attestation conditions applied to all symbols in this group
|
|
/// Attestation conditions applied to all symbols in this group
|
|
@@ -26,10 +26,22 @@ pub struct SymbolGroup {
|
|
|
pub symbols: Vec<P2WSymbol>,
|
|
pub symbols: Vec<P2WSymbol>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
|
|
|
+/// Spontaneous attestation triggers. Attestation is triggered if any
|
|
|
|
|
+/// of the active conditions is met. Option<> fields can be
|
|
|
|
|
+/// de-activated with None. All conditions are inactive by default.
|
|
|
|
|
+#[derive(Clone, Default, Debug, Deserialize, Serialize, PartialEq)]
|
|
|
pub struct AttestationConditions {
|
|
pub struct AttestationConditions {
|
|
|
- /// How often to attest
|
|
|
|
|
- pub min_freq_secs: u64,
|
|
|
|
|
|
|
+ /// Baseline, unconditional attestation interval. Attestation is triggered if the specified interval elapsed since last attestation.
|
|
|
|
|
+ #[serde(default)]
|
|
|
|
|
+ pub min_interval_secs: Option<u64>,
|
|
|
|
|
+
|
|
|
|
|
+ /// Trigger attestation if price changes by the specified percentage.
|
|
|
|
|
+ #[serde(default)]
|
|
|
|
|
+ pub price_changed_pct: Option<f32>,
|
|
|
|
|
+
|
|
|
|
|
+ /// Trigger attestation if publish_time changes
|
|
|
|
|
+ #[serde(default)]
|
|
|
|
|
+ pub publish_time_changed: bool,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Config entry for a Pyth product + price pair
|
|
/// Config entry for a Pyth product + price pair
|
|
@@ -50,6 +62,14 @@ pub struct P2WSymbol {
|
|
|
pub price_addr: Pubkey,
|
|
pub price_addr: Pubkey,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+impl ToString for P2WSymbol {
|
|
|
|
|
+ fn to_string(&self) -> String {
|
|
|
|
|
+ self.name
|
|
|
|
|
+ .clone()
|
|
|
|
|
+ .unwrap_or(format!("Unnamed product {}", self.product_addr))
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// Helper methods for strinigified SOL addresses
|
|
// Helper methods for strinigified SOL addresses
|
|
|
|
|
|
|
|
fn pubkey_string_ser<S>(k: &Pubkey, ser: S) -> Result<S::Ok, S::Error>
|
|
fn pubkey_string_ser<S>(k: &Pubkey, ser: S) -> Result<S::Ok, S::Error>
|
|
@@ -78,7 +98,10 @@ mod tests {
|
|
|
fn test_sanity() -> Result<(), ErrBox> {
|
|
fn test_sanity() -> Result<(), ErrBox> {
|
|
|
let fastbois = SymbolGroup {
|
|
let fastbois = SymbolGroup {
|
|
|
group_name: "fast bois".to_owned(),
|
|
group_name: "fast bois".to_owned(),
|
|
|
- conditions: AttestationConditions { min_freq_secs: 5 },
|
|
|
|
|
|
|
+ conditions: AttestationConditions {
|
|
|
|
|
+ min_interval_secs: Some(5),
|
|
|
|
|
+ ..Default::default()
|
|
|
|
|
+ },
|
|
|
symbols: vec![
|
|
symbols: vec![
|
|
|
P2WSymbol {
|
|
P2WSymbol {
|
|
|
name: Some("ETHUSD".to_owned()),
|
|
name: Some("ETHUSD".to_owned()),
|
|
@@ -93,7 +116,10 @@ mod tests {
|
|
|
|
|
|
|
|
let slowbois = SymbolGroup {
|
|
let slowbois = SymbolGroup {
|
|
|
group_name: "slow bois".to_owned(),
|
|
group_name: "slow bois".to_owned(),
|
|
|
- conditions: AttestationConditions { min_freq_secs: 200 },
|
|
|
|
|
|
|
+ conditions: AttestationConditions {
|
|
|
|
|
+ min_interval_secs: Some(200),
|
|
|
|
|
+ ..Default::default()
|
|
|
|
|
+ },
|
|
|
symbols: vec![
|
|
symbols: vec![
|
|
|
P2WSymbol {
|
|
P2WSymbol {
|
|
|
name: Some("CNYAUD".to_owned()),
|
|
name: Some("CNYAUD".to_owned()),
|