BLOG — Updates

107 days ago

1-Click Native Price Oracles Module

Tl;dr

  • Traditional price oracle deployments are cumbersome and their siloed architectures are unscalable in a world of 1000s of Rollups.
  • 1-Click Price Oracles reimagine the oracle architecture by leveraging a unique component of the Rollup stack - the derivation layer.
  • This allows oracle data to be published to- and verified by just a single L2 (Hub) and seamlessly disseminated to all L3s (Spokes).
  • The Native Price Oracles Module is available for all OP Stack Gelato 1-Click Base L3s today.

Traditional Price Oracle

Traditionally, price oracles are deployed on a per network basis (on each Rollup individually). This manual deployment process is cumbersome, expensive, and may require legal agreements to be signed. Whilst adequate for monolithic L1s, It is antithetical to the fully self-service and automated 1-Click Rollup deployment process. In addition, traditional oracles treat the networks they serve as disparate entities, completely isolated from one another. Consequently, oracles perform duplicate computation for each chain.

  1. Price data is fetched from the validator network and published to each chain individually, despite the prices being the same. Furthermore, the accounts (EOAs) executing these transactions incur gas and must all be topped up periodically.
  2. Upon receiving fresh price data, each chain independently verifies the signature generated by the validator network to ensure the data is legitimate.

The traditional oracle architecture, based on the assumptions of isolated blockchains, is unscalable in a world of 1000s of Rollups. Whilst monolithic L1s are in fact isolated, this is not the case for Rollups which do have something in common - the settlement layer.

Gelato 1-Click Native Price Oracles Module

Introducing the Gelato 1-Click Native Price Oracle Module which is natively integrated into the OP Stack and immediately available out of the box for all 1-Click Base L3s. Prices are published to- and verified by a single Rollup (Hub) and disseminated to all other Rollups (Spokes) whilst avoiding the aforementioned duplicate computation and all associated overhead.

The key insight making this possible is that Rollups essentially act as indexers over the L1 allowing us to consume data such as emitted events in a process known as derivation. The derivation layer is a crucial component of the Rollup architecture as it facilitates, among other things, deposits which are initiated on the L1 and executed on the L2. This is what allows users on the L1 to securely deposit tokens to the L2 - one of the key Rollup innovations.

Note: The term L1 simply refers to the Rollups settlement layer. This may itself be a Rollup with its own settlement layer. In our case, L1 actually refers to Base (which is an L2) and L2 to Rollups settling on Base (which are L3s).

Here’s how a deposit works under the hood:

  1. The user invokes a smart contract which locks up tokens on the L1 and emits a deposited event.
  2. Whenever the Rollup enters a new epoch (new L1 block), it iterates through transaction receipts in that block and fetches all deposited event logs.
  3. For all deposited event logs, the Rollup constructs special, corresponding deposit transactions which are included at the top of the next L2 block.

Note: Steps 2 & 3 take place during the derivation process.

The Gelato 1-Click Native Price Oracle Module deploys a forked and slightly modified OP Stack that introduces an additional source to the derivation layer. We first deploy an ´L1PriceOracle´ smart contract which receives price updates from Pyth every two seconds via a Gelato Web3 Function. This smart contract is deployed once on the L1 and shared by all Rollups. It verifies the associated signature to ensure the price update is legitimate and emits a ´PricesUpdated´ event containing all updated price feeds. When the Rollup enters a new epoch, in addition to iterating through all deposited event logs as before, it also iterates through all ´PricesUpdated´ event logs. Just like with deposits, the Rollup then constructs a special top-of-block transaction that updates prices on the L2. This transaction calls a ´L2PriceOracle´ predeploy smart contract which stores prices on-chain and exposes them via a Pyth-like interface.

In summary, prices are pushed to- and verified by a single smart contract living on the L1. On every epoch, Rollups essentially copy the already verified, fresh prices from L1 to L2 during derivation - similar to how deposits are handled. Since publishing & verification is done in a single place, rather than by each Rollup individually, we reduce its complexity from O(n) to O(1).

However, despite avoiding duplicate computation, publishing prices to an L1 such as Ethereum every two seconds is prohibitively expensive. Instead, prices are published to a cheaper L2, in our case Base, and consumed by 1-Click Base L3s. Unlike traditional oracles, 1-Click Oracles actually perform better at scale since costs of publishing & verifying the data is amortized between all Rollups. In essence, the constant cost is divided between many Rollups (1/n). In addition, whenever a new price feed is introduced on the Hub (Base), it is instantly available on all other Rollups without any additional configuration or work required. This allows for the rapid introduction of new price feeds.

The diagram below visualises the architecture and illustrates the flow of an oracle price update:

  1. An off-chain Gelato Web3 Function fetches prices from Pyth every two seconds.
  2. The fresh prices are pushed to the ´L1PriceOracle smart contract on Base.
  3. The ´L1PriceOracle´ smart contract calls the Pyth smart contract to verify the signature and update the price feed. The updated price feed is then subsequently fetched from the Pyth smart contract and emitted in a ´PricesUpdated´ event.
  4. When the 1-Click Base L3 produces a block in a new epoch (whenever there is a new Base block), it indexes the ´PricesUpdated´ event emitted by the ´L1PriceOracle´ smart contract during derivation. The emitted event data is decoded and a system transaction is constructed to update the ´L2PriceOracle´ smart contract on the L3 with the fresh price data.

Watch this YouTube video to learn in detail about the new feature on Gelato for deploying one-click OP Stack Base L3 rollups, featuring the natively integrated price Oracle module. The video covers how to deploy a rollup with this module and explains how to consume the price feeds from a smart contract.

Deploy on Gelato

The 1-Click Native Price Oracle Module is available on Gelato today. To deploy your own OP Stack chain with just a single click, head over to the Gelato RaaS app [insert link]. To learn more about the Native Price Oracle Module check out our documentation.