Introducing Views in the Harbinger Price Oracle

Keefer Taylor
5 min readDec 8, 2021

--

By Keefer Taylor, Founder, Tessellated Geometry

Photo by Birger Strahl on Unsplash

In August 2020, we helped to launch Harbinger, a decentralized, self sustaining price oracle on the Tezos network. Since then, thanks its strong on chain governance process, the Tezos network has upgraded 5 times, adding new features and optimizations that improve both the user experience and developer quality of life.

Background

Price Oracles are an important cornerstone of Decentralized Finance (“DeFi”) applications. They work by making off chain data (like the prices of various cryptocurrency assets) available on chain, where it can be consumed and used by other applications.

Harbinger is a decentralized price oracle, written in SmartPy, that is widely used in Tezos DeFi applications. It is notably used by Kolibri (an algorithmic stablecoin) and Tezex (a cross chain exchange). Upcoming applications that will integrate Harbinger include Juster (a prediction market), Yupana (a lending platform), SEXP (a synthetics exchange) and TezFin (a lending platform).

Harbinger was created as a public good that can be used by any application on Tezos. The price oracle is a smart contract which works by receiving data from any entity (a “poster”). The data is signed by a cryptocurrency exchange, such as Coinbase, and as long as the data is signed correctly, the Harbinger smart contracts will make it available on chain.

Several entities, including Tessellated Geometry, already operate posters using open source software. Additionally, anyone can push up to date data on chain using harbinger.live.

Smart Contract Composability

A smart contract is a program that runs on a blockchain. One or more smart contracts placed together, along with a user interface form a decentralized application (a “dapp”). Developers can work with other smart contracts (like Harbinger!) to integrate functionality into their own dapp. In developer terms, the idea of building programs from smaller components of functionality is called “composing” smart contracts.

In the past, Tezos had a callback based mechanism for smart contracts to talk to each other. In non-technical parlance, this means that a smart contract would “call” another contract, asking for data, and the called smart contract would “callback” the original contract with the information requested.

An illustration of callback based programming in smart contracts

While callback based programming enables composability, it has drawbacks. The client smart contract must maintain state while the other program is running which complicates the smart contract code and logic for the programmer. For users, it requires two calls between smart contracts, which consume valuable gas (the cost which users pay to the network in order execute smart contract programs), which ultimately increases transaction size and cost.

Views

The latest Tezos protocol, Hangzhou, contains a new feature for smart contract developers that make their lives easier. Views, introduced in Hangzhou, allow smart contracts to read data from each other without using callbacks.

This feature allows developers to receive data back from smart contracts synchronously, by making a single call to the external smart contract.

An illustration of view based programming in smart contracts

The resulting programming pattern benefits both developers, who no longer have to manage state during callbacks, and users, who will have smaller and cheaper transactions due to the more efficient gas consumption.

View based programming can be used as long as the external smart contract does not need to change its state, or call other smart contracts. These requirements make views a great candidate for use in price oracle contracts such as Harbinger.

Views In Harbinger

Adding views in would Harbinger increase composability of the Harbinger smart contracts, allowing developers to build simpler dapps that consume price data.

During the latest protocol adoption period, we updated the Harbinger smart contracts to contain code which exposes on chain views to smart developers. New Harbinger price oracle contracts were deployed shortly after the upgrade. To our knowledge, this makes Harbinger the first mainstream Tezos contract to use views on chain.

For end users, we ran internal benchmarks which showed that using Harbinger via views instead of callbacks reduced gas consumption 49% (9275 gas units with callbacks vs 4705 gas units with views) and the cost of the transaction by 36% (0.001246 XTZ vs 0.000793 XTZ).

Interested developers can gets started with these contracts here:

Testnet
- Price Oracle: KT19yapgDLPR3CuvK32xJHgxNJigyNxjSr4y
- Normalizer: KT1PMQZxQTrFPJn3pEaj9rvGfJA9Hvx7Z1CL
Mainnet
- Price Oracle: KT19B8uSfiQ8Cxk99ELc7MPccQ9ihyy7jhDU
- Normalizer: KT1KBrn1udLLrGNbQ3n1mWgMVXkr26krj6Nj

Additionally, a demo contract was deployed to testnet which reads data out of Harbinger using the new views. Anyone can call the updateOracleDataPointentrypoint, which will read Harbinger data via a view and store it in the demo contract. The demo contract is at address KT1QdzgvEjByFfXg8jHHFFkzo3HW983zTqnb and the SmartPy source code is here.

Tessellated Geometry is currently posting data to these contracts every 1 minute on testnet, and every 30 minutes on mainnet.

Conclusion

Thanks to Tezos’ strong on chain governance process and regular upgrades, developers can now build applications more easily effectively. The Harbinger price oracle now supports views to make developers lives easier, and we’re excited to open the contracts for developers to integrate them and continue to build the Tezos DeFi ecosystem.

If you’re interested in integrating Harbinger to your application, contributing to the tooling, or helping to post updates for your favorite DeFi applications, feel free to reach out to @keefertaylor, or hello@tessellatedgeometry.com.

Who We Are

Tessellated Geometry is an engineering firm whose mission is to build and grow the proof of stake cryptocurrency ecosystem. We accomplish this by running secure and highly available validators and by contributing public goods to those ecosystems.

We’ve contributed to Tezos in various ways including Tezos protocol amendments, building signing software, and by maintaining Harbinger and monitoring software.

An earlier version of this article incorrectly stated the gas reductions 97% and the fee reduction as 53%. Corrected figures appear above. Thanks to astute readers who pointed out this discrepancy.

--

--