Using DIA with Stacks
DIA's Clarity Contracts
Chain
Address
Example
(define-constant MIN-SBTC-BALANCE u100)
(define-constant ERR_READING_SBTC_BALANCE (err u7001))
(define-constant ERR_NOT_ENOUGH_SBTC (err u7002))
(define-constant ERR_NOT_OWNER (err u7003))
(define-constant SBTC-PRICE-EXPO 8)
(define-map whitelist
principal
bool
)
(define-public (check-eligibility)
(let (
(sbtc-price-data (unwrap-panic (contract-call? 'SP1G48FZ4Y7JY8G2Z0N51QTCYGBQ6F4J43J77BQC0.dia-oracle
get-value "sBTC/USD"
)))
(sbtc-usd-price (to-int (get value sbtc-price-data)))
(price-denomination (pow 10 SBTC-PRICE-EXPO))
(adjusted-price (to-uint (/ sbtc-usd-price price-denomination)))
(user-sbtc-balance (unwrap!
(contract-call? 'SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token
get-balance-available tx-sender
)
ERR_READING_SBTC_BALANCE
))
)
(if (> (/ (* user-sbtc-balance adjusted-price) (to-uint price-denomination))
MIN-SBTC-BALANCE
)
(ok (map-set whitelist tx-sender true))
ERR_NOT_ENOUGH_SBTC
)
)
)
Additional Resources
Last updated
Was this helpful?