diff --git a/contracts/pyth-oracle-v2.clar b/contracts/pyth-oracle-v2.clar index 8d5dd97..86354d9 100644 --- a/contracts/pyth-oracle-v2.clar +++ b/contracts/pyth-oracle-v2.clar @@ -12,6 +12,15 @@ ;; Balance insufficient for handling fee (define-constant ERR_BALANCE_INSUFFICIENT (err u402)) +(define-public (get-price + (price-feed-id (buff 32)) + (pyth-storage-address )) + (begin + ;; Check execution flow + (try! (contract-call? .pyth-governance-v1 check-storage-contract pyth-storage-address)) + ;; Perform contract-call + (contract-call? pyth-storage-address read-price-with-staleness-check price-feed-id))) + (define-public (read-price-feed (price-feed-id (buff 32)) (pyth-storage-address )) diff --git a/contracts/pyth-store-v2.clar b/contracts/pyth-store-v2.clar index 63f9fa1..2da08c9 100644 --- a/contracts/pyth-store-v2.clar +++ b/contracts/pyth-store-v2.clar @@ -48,6 +48,15 @@ (let ((entry (unwrap! (map-get? prices price-identifier) (err u404)))) (ok entry))) +(define-read-only (read-price-with-staleness-check (price-identifier (buff 32))) + (let ( + (entry (unwrap! (map-get? prices price-identifier) (err u404))) + (stale-price-threshold (contract-call? .pyth-governance-v1 get-stale-price-threshold)) + (latest-bitcoin-timestamp (unwrap! (get-stacks-block-info? time (- stacks-block-height u1)) ERR_STALE_PRICE)) + ) + (asserts! (>= (get publish-time entry) (+ (- latest-bitcoin-timestamp stale-price-threshold) STACKS_BLOCK_TIME)) ERR_STALE_PRICE) + (ok entry))) + (define-public (write (batch-updates (list 64 { price-identifier: (buff 32), price: int, diff --git a/contracts/pyth-traits-v1.clar b/contracts/pyth-traits-v1.clar index f70bcda..00210cf 100644 --- a/contracts/pyth-traits-v1.clar +++ b/contracts/pyth-traits-v1.clar @@ -32,6 +32,16 @@ prev-publish-time: uint, } uint)) + (read-price-with-staleness-check ((buff 32)) (response { + price: int, + conf: uint, + expo: int, + ema-price: int, + ema-conf: uint, + publish-time: uint, + prev-publish-time: uint, + } uint)) + (write ((list 64 { price-identifier: (buff 32), price: int,