Usage of DIA Oracles on Stacks

dApps building on Stacks can utilize DIA oracles to obtain up-to-date asset price information. These deployed oracles are suitable for use in production environments. They come with a list of supported assets and settings. However, if dApps require a custom oracle with a different set of assets and configurations, they should contact DIA on Telegram.

Oracle Details

ChainAddress
MainnetSP1G48FZ4Y7JY8G2Z0N51QTCYGBQ6F4J43J77BQC0.dia-oracle
TestnetST1S5ZGRZV5K4S9205RWPRTX9RGS9JV40KQMR4G1J.dia-oracle

Oracle Configuration

Pricing MethodologyMAIR
Deviation (%) & Refresh Frequency5% and 120 seconds
Heartbeat15 minutes

Asset Feeds

The Stacks oracle includes the following asset feeds:
Asset TickerAsset BlockchainAsset AddressAsset Sources
STXStacks0x0000000000000000000000000000000000000000STX Market
stSTXStacksSP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-tokenstSTX Market
DIKOStacksSP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-tokenDIKO Market
WELSHStacksSP3NE50GEXFG9SZGTT51P40X2CKYSZ5CC4ZTZ7A2G.welshcorgicoin-tokenWELSH Market
VELARStacksSP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.velar-tokenVELAR Market
ALEXStacksSP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.age000-governance-tokenALEX Market
sBTCStacksSM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-tokensBTC Market
aeUSDCStacksSP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-aeusdcaeUSDC Market
USDhStacksSPN5AKG35QZSK2M8GAMR4AFX45659RJHDW353HSG.usdh-token-v1USDh Market
BTCBitcoin0x0000000000000000000000000000000000000000BTC Market

How to Access Data

You can query for assets like "STX/USD" or "stSTX/USD" in the get-value() read function. It returns two values:
  1. The price of STX/USD with 8 decimals
  2. The timestamp of the last update (UTC timezone)
Below is the DIA oracle contract implementation in Clarity:
(impl-trait .trait-dia-oracle.dia-oracle-trait)

(define-constant err-unauthorized (err u100))

(define-data-var oracle-updater principal tx-sender)

(define-map values
    (string-ascii 32)
    { value: uint, timestamp: uint }
)

(define-public (set-value (key (string-ascii 32)) (value uint) (timestamp uint))
    (begin
        (try! (check-is-oracle-updater))
        (update-value { key: key, value: value, timestamp: timestamp })
        (ok true)
    )
)

(define-public (set-multiple-values (entries (list 10 { key: (string-ascii 32), value: uint, timestamp: uint })))
    (begin
        (try! (check-is-oracle-updater))
        (map update-value entries)
        (ok true)
    )
)

(define-public (change-oracle-updater (new-oracle-updater principal))
    (begin
        ;; #[filter(new-oracle-updater)]
        (try! (check-is-oracle-updater))
        (var-set oracle-updater new-oracle-updater)
        (print
            {
                action: "oracle-updater-changed",
                data: { old-updater: tx-sender, new-updater: new-oracle-updater }
            }
        )
        (ok true)
    )
)

(define-read-only (get-oracle-updater)
    (var-get oracle-updater)
)

(define-read-only (get-value (key (string-ascii 32)))
    (ok (default-to { value: u0, timestamp: u0 } (map-get? values key)))
)

(define-private (check-is-oracle-updater)
    (ok (asserts! (is-eq tx-sender (var-get oracle-updater)) err-unauthorized))
)

(define-private (update-value (entry { key: (string-ascii 32), value: uint, timestamp: uint }))
    (begin
        (map-set values
            (get key entry)
            { value: (get value entry), timestamp: (get timestamp entry) }
        )
        (print { action: "updated", data: entry })
    )
)
Learn more about DIA’s data sourcing and data computation architecture.

Support

For developer assistance, connect with the DIA team directly on Discord or Telegram. Developers seeking other specialized, production-grade oracle with tailored price feeds and configurations can initiate the request by contacting the DIA BD Team via Telegram.