Skip to content

Commit 4864468

Browse files
kenrogersgitbook-bot
authored andcommitted
GITBOOK-317: Add oracles
1 parent 60ff74b commit 4864468

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
* [Stack with a Pool](guides-and-tutorials/stack-stx/stack-with-a-pool.md)
107107
* [Increase Stacked Position](guides-and-tutorials/stack-stx/increase-stacking.md)
108108
* [Stop Stacking](guides-and-tutorials/stack-stx/stop-stacking.md)
109+
* [Oracles](guides-and-tutorials/oracles.md)
109110
* [Community Tutorials](guides-and-tutorials/community-tutorials.md)
110111

111112
## 📚 Reference

guides-and-tutorials/oracles.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Oracles
2+
3+
## Price‑Feed Oracles on Stacks
4+
5+
Smart contracts written in **Clarity** run in a deterministic sandbox: they can read data in the Stacks and Bitcoin chainstate, but _nothing else_. Whenever your dApp needs the latest **BTC/USD**, **STX/BTC**, or any other market price, you’ll rely on an **oracle** to bring that data on‑chain in a verifiable way.
6+
7+
This page lays out _why_ price‑feed oracles matter on Stacks and link to the specific oracle provider docs for instructions on how to integrate them.
8+
9+
***
10+
11+
### Why you need a price‑feed oracle
12+
13+
Here are some possible scenarios where you might need an oracle.
14+
15+
| On‑chain need | Typical Stacks use case | What the oracle supplies |
16+
| ------------------------------------ | ---------------------------------------------- | ----------------------------------- |
17+
| **Liquidations & collateral ratios** | Lending / borrowing protocols, margin trading | Signed price updated every N blocks |
18+
| **Stablecoin peg maintenance** | BTC‑backed or exogenous‑collateral stablecoins | Reference BTC/USD (or other) price |
19+
| **AMM curve calculations** | DEXs that tune fees or rebalance pools | Time‑weighted average price (TWAP) |
20+
| **Derivatives settlement** | Options, futures, or perpetual swaps | Final settlement price at expiry |
21+
22+
> **Rule of thumb:** if your contract’s math depends on a real‑time market price, you need a price‑feed oracle.
23+
24+
### Oracle Providers
25+
26+
There are two oracle providers that Stacks builders are currently using for their data needs: Pyth and DIA.
27+
28+
Pyth is a pull-based oracle and Trust Machines currently maintains the Pyth bridge. You can view docs on how to use Pyth and the associated Clarity contracts on Trust Machine's [GitHub repo for the bridge.](https://github.com/Trust-Machines/stacks-pyth-bridge)
29+
30+
DIA is the other oracle provider Stacks builders frequently use.
31+
32+
There is a documentation guide on how to use DIA oracles with Stacks on [DIA's docs website](https://nexus.diadata.org/how-to-guides/fetch-price-data/chain-specific-guide/stacks).

0 commit comments

Comments
 (0)