Welcome to the RedStone Oracle tutorial for technical users! In this guide, we'll walk you through the process of integrating RedStone Oracle into your decentralized applications (DApps). RedStone Oracle is a cutting-edge solution in the decentralized finance (DeFi) space, offering a modular design and three distinct integration models.
RedStone introduces a novel modular design, addressing the limitations of traditional oracle systems. Instead of pushing all data on-chain, RedStone employs a data availability layer, allowing for the broadcast of a large number of assets at high frequencies to a more cost-effective layer. The on-chain update occurs only when required by the protocol, reducing maintenance costs.
RedStone offers three integration models to cater to different smart contract architectures and business requirements:
RedStone Core:
Dynamically injects data into user transactions.
Achieves maximum gas efficiency, ensuring a seamless user experience.
RedStone Classic:
Pushes data into on-chain storage via a relayer.
Provides full control over the data source and update conditions.
RedStone X:
Targets advanced protocols like perpetuals, options, and derivatives.
Eliminates front-running risks by providing price feeds in the next block after user interactions.
RedStone aggregates price feeds from various sources, including off-chain DEXs (Binance, Coinbase, Kraken), on-chain DEXs (Uniswap, Sushiswap, Balancer), and aggregators (CoinmarketCap, Coingecko, Kaiko). The data is processed by independent nodes operated by data providers, ensuring data quality through methodologies like median, TWAP, and LWAP.
Data is packed into a message structure using a decentralized cache layer powered by the Streamr network and RedStone light cache nodes. The packed data is appended to the original transaction message, signed, and submitted to the network.
To enhance security, RedStone employs on-chain aggregation, requiring a minimum number of signatures from authorized data providers for a given data feed. Aggregated values, calculated using parameters like the median value, ensure robustness even if a subset of providers is compromised.
Contract Design:
Emphasize secure contract design.
Pay attention to timestamp validation logic.
Upgradability:
Enable a secure upgradability mechanism for your contract.
Registry Monitoring:
Monitor the RedStone data services registry for changes.
Contract Design:
Design contracts to minimize the need for requesting many data feeds in a single transaction.
Unique Signers:
Use around 10 required unique signers for a balance between security and gas cost efficiency.
Check the benchmarks script and reports for gas consumption based on the number of unique signers and data feeds.
This model is ideal for scenarios where data is automatically appended to user transactions. It's a battle-tested solution in production, protecting over $100M TVL of DeFi protocols.
Install
@redstone-finance/evm-connectorfrom the NPM registry.yarn add @redstone-finance/evm-connectorFor Foundry projects, follow additional installation steps.
Usage:
Adjust your smart contracts to include the necessary libraries.
Adjust JavaScript code in your DApp to inject the additional payload with data feeds.
Refer to the provided TLDR; section for a quick overview.
For testing with Hardhat, use the mock wrapper to override oracle values easily.
Ideal for scenarios where data is pushed on-chain, providing a decisive voice on when and how the price is updated.
Customize the relayer's behavior using environment variables, including relayer iteration interval, update conditions, and more.
Implements a deferred execution pattern, processing transactions in two steps to mitigate front-running risks.
Adjust contracts to execute price-sensitive transactions in two phases.
Deploy a keeper service to fetch the price and trigger execution.
Congratulations! You've completed the RedStone Oracle integration tutorial. By following the provided steps, you've gained insights into RedStone's modular design, integration models, and security considerations. As you integrate RedStone into your DApp, you contribute to the growth and efficiency of decentralized applications in the evolving DeFi landscape.
Feel free to explore additional RedStone features and stay tuned for updates as RedStone continues to innovate in the decentralized finance space. Happy coding! 🚀More in
