price.move 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. module pyth::price {
  2. use pyth::i64::I64;
  3. /// A price with a degree of uncertainty, represented as a price +- a confidence interval.
  4. ///
  5. /// The confidence interval roughly corresponds to the standard error of a normal distribution.
  6. /// Both the price and confidence are stored in a fixed-point numeric representation,
  7. /// `x * (10^expo)`, where `expo` is the exponent.
  8. //
  9. /// Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how
  10. /// to how this price safely.
  11. struct Price has copy, drop, store {
  12. price: I64,
  13. /// Confidence interval around the price
  14. conf: u64,
  15. /// The exponent
  16. expo: I64,
  17. /// Unix timestamp of when this price was computed
  18. timestamp: u64,
  19. }
  20. public fun new(price: I64, conf: u64, expo: I64, timestamp: u64): Price {
  21. Price {
  22. price: price,
  23. conf: conf,
  24. expo: expo,
  25. timestamp: timestamp,
  26. }
  27. }
  28. public fun get_price(price: &Price): I64 {
  29. price.price
  30. }
  31. public fun get_conf(price: &Price): u64 {
  32. price.conf
  33. }
  34. public fun get_timestamp(price: &Price): u64 {
  35. price.timestamp
  36. }
  37. public fun get_expo(price: &Price): I64 {
  38. price.expo
  39. }
  40. }