Skip to content

Commit

Permalink
Merge pull request #11 from Trust-Machines/GRNT-1162
Browse files Browse the repository at this point in the history
fix L-07
  • Loading branch information
hackercf authored Dec 5, 2024
2 parents f63e6a0 + 15a9dbc commit ab30354
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions contracts/pyth-oracle-v2.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pyth-storage-trait>))
(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 <pyth-storage-trait>))
Expand Down
9 changes: 9 additions & 0 deletions contracts/pyth-store-v2.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions contracts/pyth-traits-v1.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ab30354

Please sign in to comment.