You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ecosystem/defi-liquidity/band-oracle.md
+269-2Lines changed: 269 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,273 @@ sidebar_position: 6
16
16
sidebar_label: Band Oracle
17
17
---
18
18
19
-
# Band Oracle on Flow
19
+
# Band Oracle with Cadence
20
20
21
-
[Band Protocol](https://bandprotocol.com/) is a cross-chain data oracle platform that aggregates and connects real-world data and APIs to smart contracts. Band Oracle on Flow provides secure, reliable, and decentralized price feeds for DeFi applications.
21
+
The Band Protocol Oracle contract enables Flow blockchain applications to access real-time price data from the [Band Protocol Oracle network](https://faq.bandprotocol.com/). The oracle provides a comprehensive set of cryptocurrency and fiat currency price quotes from the Band Standard Dataset, making them available to any Cadence application, contract, or transaction.
The Band Oracle contract maintains a decentralized price feed system with three key components:
49
+
50
+
1.**Data Storage**: Price data is stored in a contract-level dictionary `symbolsRefData: {String: RefData}` where each symbol maps to its latest price information.
51
+
52
+
2.**Data Updates**: Authorized BandChain relayers continuously update price data from the Band Protocol network to keep prices current.
53
+
54
+
3.**Data Access**: Any user or contract can query the latest price data through public functions, enabling real-time price integrations.
55
+
56
+
### Data Structure
57
+
58
+
Price data is stored using the `RefData` struct:
59
+
60
+
```cadence
61
+
pub struct RefData {
62
+
// USD-rate, multiplied by 1e9
63
+
pub var rate: UInt64
64
+
// UNIX epoch when data was last resolved
65
+
pub var timestamp: UInt64
66
+
// BandChain request identifier for this data
67
+
pub var requestID: UInt64
68
+
}
69
+
```
70
+
71
+
When querying prices, you receive a `ReferenceData` struct:
72
+
73
+
```cadence
74
+
pub struct ReferenceData {
75
+
// Rate as integer multiplied by 1e18
76
+
pub var integerE18Rate: UInt256
77
+
// Rate as a fixed-point decimal
78
+
pub var fixedPointRate: UFix64
79
+
// Timestamp of base symbol data
80
+
pub var baseTimestamp: UInt64
81
+
// Timestamp of quote symbol data
82
+
pub var quoteTimestamp: UInt64
83
+
}
84
+
```
85
+
86
+
### Data Normalization
87
+
88
+
All price data is stored with a USD conversion rate. When you query for price conversions between two non-USD symbols, the contract derives the rate from their respective USD rates. For example, to get ETH/EUR, the contract calculates: `(ETH/USD) / (EUR/USD)`.
89
+
90
+
## Features
91
+
92
+
### Price Queries
93
+
- Query any supported symbol pair in real-time
94
+
- Get both integer (e18 precision) and fixed-point decimal rates
95
+
- Access timestamp information to verify data freshness
96
+
- Track BandChain request IDs for transparency
97
+
98
+
### Fee Structure
99
+
- Configurable fee system for oracle usage (currently set to zero)
100
+
- Fee collected in FLOW tokens
101
+
- Query current fee using `BandOracle.getFee()`
102
+
103
+
### Event Monitoring
104
+
The contract emits events to notify applications of updates:
-[Band Standard Dataset](https://data.bandprotocol.com/)
277
+
-[Flow Documentation](https://docs.onflow.org/)
278
+
-[Cadence Language Reference](https://cadence-lang.org/)
279
+
280
+
## Support
281
+
282
+
For issues or questions about the Band Oracle on Flow:
283
+
- Check the Band Protocol documentation
284
+
- Engage with the Flow developer community
285
+
286
+
---
287
+
288
+
**Note**: The oracle currently charges no fees for usage, but this may change in the future. Always check `BandOracle.getFee()` before querying to ensure your contract has sufficient FLOW tokens allocated.
0 commit comments