Youves utilizes the Acurast oracles for the price feeds of the synthetic assets. The oracle scripts are the executables used by the processors to collect data in a verifiable way.
This script implements an on-demand oracle for cryptocurrency and forex price feeds. It's designed to work with the Acurast network, providing reliable and up-to-date price information for various asset pairs. The prices are signed by the oracles, ready for on chain verification.
- Supports multiple cryptocurrency and forex pairs
- Fetches data from various reputable exchanges and APIs
- Implements a caching mechanism to reduce unnecessary API calls
- Calculates median prices to ensure accuracy
- Handles WebSocket connections for real-time price requests
- Includes error handling and logging via Sentry
- BTCUSD, BTCUSDT
- XTZUSD, XTZUSDT
- USDTUSD
- XAUUSD
- CHFUSD
- EURUSD
- Access to processors on the Acurast network
- API keys for various price feed sources (Twelve Data, One Forge, Currency API)
- Clone the repository
- Install dependencies (if any)
- Set up environment variables:
WSS_URLS
: WebSocket URLs for Acurast network, separated by commaCACHE_EPOCH_CRYPTO
: Cache duration for crypto prices in seconds (default: 60 seconds)CACHE_EPOCH_FOREX
: Cache duration for forex prices in seconds (default: 300 seconds)TWELVEDATA_API_KEY
: API key for Twelve DataONE_FORGE_API_KEY
: API key for One ForgeCURRENCY_API_KEY
: API key for Currency APISENTRY_KEY
: Sentry API key for error logging (optional)
Crypto APIs are public but forex prices do require API keys.
The script runs on an acurast processor and is listening for price requests via websocket. To use it:
- Start the script
- Connect to the WebSocket server
- Send a price request in the following format:
[
{ "from": "BTC", "to": "USD", "price": 50000 },
{ "from": "XTZ", "to": "USD", "price": 1.5 }
]
The price field is optional. If a price is not provided in the request then the oracle will just asnwer with the price it fetched.
If you provide a price of your own the oracle will fetch prices and compare his price to the one you provided. If the price difference is within the threshold then it will return your price as valid. So if the oracle returns a different price from what you provided it means that price is not valid.
The return
The script will respond with price information, including signed prices for verification.
The oracle returns a JSON payload with the following structure:
{
"priceInfos": [
{
"from": "BTC",
"to": "USD",
"price": 50000000000,
"epoch": 1689345600
}
// ... other price infos
],
"signedPrices": [
{
"pair": "BTCUSD",
"packedPrice": "0x...",
"signature": "0x..."
}
// ... other signed prices
],
"errors": [
// Any error messages, if applicable
],
"timeInfos": {
"startTimestamp": 1689345610000,
"endTimestamp": 1689345610500,
"executionTime": 500
},
"version": "1.8"
}
priceInfos
: Array of price information for each requested pair.signedPrices
: Array of packed and signed prices for on-chain verification.errors
: Any error messages encountered during price fetching.timeInfos
: Timestamps and execution time of the request.version
: The version of the oracle script.
You can modify the following constants in the script to adjust its behavior:
MINIMUM_SOURCES_PER_PRICE
: Minimum number of sources required for a valid priceDEVIATION_THRESHOLD_PERCENT
: Maximum allowed deviation between prices (calculated with price difference)TRADE_AGE_LIMIT
: Maximum age of trades to be considered valid
Contributions are welcome! Please feel free to submit a Pull Request.
This script is provided as-is. Please use it responsibly and in accordance with the terms of service of the various APIs it utilizes.