# Oracles & DeFi: Insights from the MerlinProtocol **Published by:** [Merlin Protocol](https://paragraph.com/@merlin-protocol/) **Published on:** 2024-06-12 **URL:** https://paragraph.com/@merlin-protocol/oracles-defi-insights-from-the-merlinprotocol ## Content in the burgeoning field of Decentralized Finance (DeFi), the integration of accurate and reliable data is crucial for the smooth functioning of financial applications. Oracles, which serve as bridges between on-chain smart contracts and off-chain data sources, play a pivotal role in this ecosystem. The MerlinProtocol project exemplifies the sophisticated use of oracles, employing both decentralized and ChainLink oracles to manage investment funds effectively. (You can check this article from the Ethereum Foundation about blockchain oracles).Types of Oracles in the MerlinProtocolThe MerlinProtocol utilizes two primary types of oracles, each serving complementary functions. The first type are decentralized oracles integrated with the Uniswap v3 protocol. These oracles provide the latest updated prices for token pairs in the DeFi on-chain market, ensuring real-time data availability for trading decisions. The second type involves oracles connected through the ChainLink protocol, which offer historical price data and periodic token capitalization information, typically challenging to compute on-chain without significant gas costs.Decentralized OraclesDecentralized oracles are distinguished by their ability to eliminate single points of failure. They achieve this through a network of individual data providers, whose inputs are aggregated on-chain. This structure ensures constant data availability and enhances the resilience of the system against individual device or brand vulnerabilities. A key feature of decentralized oracles is their ability to provide data necessary for immediate decisions through immediate-read queries. For example, in the MerlinProtocol, an immediate-read oracle could respond to a “getLastPrice” query, providing up-to-date market prices for traded pairs. This real-time data retrieval is essential for making timely investment decisions.Oracle Design PatternsOracles in the MerlinProtocol adhere to three main architectural patterns: immediate-read, publish-subscribe, and request-response.Immediate-Read Oracles: These oracles provide data on-demand, performing just-in-time queries when information is needed. Once stored in a smart contract’s memory, this data can be accessed by other smart contracts.Publish-Subscribe Oracles: These oracles broadcast data updates to subscribed smart contracts or off-chain controllers whenever new data is available. This pattern is similar to RSS feeds, where subscribers are alerted to new information.Request-Response Oracles: This architecture involves a series of asynchronous interactions between the requester and the oracle, mediated by on-chain and off-chain components. It’s efficient for handling specific data requests, although it can require substantial storage space on smart contracts.ChainLink OraclesChainLink oracles add another layer of sophistication to the MerlinProtocol. These oracles comprise a network of smart contracts that handle data aggregation, reputation tracking, and order placement. ChainLink’s infrastructure allows oracles to connect to any API endpoint via external adapters, facilitating a wide range of data integrations, from market data to traditional payment systems. In the MerlinProtocol, ChainLink oracles gather data from various APIs exposed by financial entities in the crypto world, such as CoinMarketCap. This decentralized data model ensures that no single point of failure exists, with multiple oracles and data aggregators providing redundancy and enhancing the reliability of the data. The ChainLink protocol also includes mechanisms to prevent data manipulation, such as averaging received values and verifying gaps between inputs to ensure meaningful outputs. Customizable parameters like "Deviation Threshold" and "Heartbeat Threshold" allow fine-tuning of the data aggregation process, ensuring high accuracy and timely updates.Practical Application in Investment FundsIn practical terms, the oracles used in the MerlinProtocol enable smart contracts managing investment funds to access essential data like token volumes, prices, transaction numbers, exchange market counts, and volatility metrics. These data points are crucial for dynamically adjusting the assets within a fund based on predefined criteria set by the fund creator. The sporadic frequency of price feed readings aligns with the periodic need to reshape fund assets, ensuring that updates occur only when necessary, thereby optimizing gas usage and reducing operational costs.ConclusionMerlinProtocol is committed to implementing an oracle-based structure that ensures efficiency, security, and reliability. The combined use of decentralized oracles and ChainLink allows the protocol to obtain accurate and timely data, crucial for the dynamic management of investment funds. Decentralized oracles ensure constant data availability, eliminating single points of failure, while ChainLink provides a robust infrastructure for integrating complex and historical data. The diversification of oracles and data aggregators guarantees a resilient system against manipulation attempts and malfunctions. In summary, MerlinProtocol sets a new standard in DeFi fund management, ensuring transparent and secure operations that foster trust and adoption in the system. ## Publication Information - [Merlin Protocol](https://paragraph.com/@merlin-protocol/): Publication homepage - [All Posts](https://paragraph.com/@merlin-protocol/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@merlin-protocol): Subscribe to updates - [Twitter](https://twitter.com/Merlin_Protocol): Follow on Twitter