Articles
No Results
Article

TEAL ALGO Oracle in Algorand Layer-1

Price is a fundamental component of economic transactions. It is the multiplier required to calculate the amount of value exchanged between participants. In a blockchain, the ability to reference a price on-chain enables a seamless and trustless transaction environment, especially for automated transactions and smart contracts. Oracles are the entities in charge of broadcasting off-chain data such as market price to the blockchain, and serve as a source of truth that allows on-chain dApps to measure the value of assets referenced within a transaction.
Rand Labs has recently revealed a novel architecture for an Algorand Oracle that facilitates the swap of two assets fully on-chain, you can read more about the testnet implementation here.
We have committed additional resources to the project and have successfully evolved the Oracle from our initial prototype into a TEAL-compatible ALGO/USD on-chain Oracle using Coinbase.com as the data source. The revamped Oracle is now in production and running on Algorand’s MainNet.
The TEAL ALGO Oracle will inspire and enable a new generation of financial products in the crypto ecosystem. For the first time in a high performance public-permissionless blockchain, the Oracle runs on layer 1 of the protocol. This means that any Algorand user or application will be able to reference the market price of an asset inside of their transaction (including atomic transfers) with negligible fees and receive a confirmation in under five seconds, only possible due to its unique Pure Proof-of-Stake consensus based on VRF primitives, introduced initially by Silvio Micali, Michael Rabin and Salil Vadha. This infrastructure will democratize access to DeFi products and services which are cost prohibitive for sub-$1k transactions on other blockchain platforms. Developers will have the choice over what data provider they use for their oracle, and the authenticity of the published data can be verified using signed messages of the provider that will come in the next iteration of this technology.

How does it work?

For the implementation, a price submitter is needed where the price is attached to the Note field of the transaction with the Oracle’s signature. Any TEAL code using this Oracle data must pay a fee that is used to cover the on-chain price submitter’s transaction fees. Since the TEAL ALGO Oracle contract can be referenced by any dApp, the service can potentially run continuously if enough applications integrate it into their stack. In addition, dApps (such as an on-chain Decentralized Exchange) can increase their Byzantine Fault Tolerance by using multiple price sources, since the price submitter could provide up to three price sources signed by different entities in a single transaction.

Price Submitter

Each round, the price submitter generates a transaction containing a Message Pack in the Note field that includes the price, timestamp and signed TEAL code that is used to verify the signed price within an atomic transfer.

E.g.:

{
  “decimals”: 4,
  “last_trade_at”: “2020–08–18T19:06:34.944785Z”,
  “price”: 5853,
  “signature”: {
    “l”: {
      “type”: “Buffer”,
      “data”: [ 1, …, 16 ]
    },
    “sig”: {
      “type”: “Buffer”,
      “data”: [ 157, …, 15 ]
    }
  },
  “timestamp”: “2020–08–18T19:24:44.078Z”
}

To use the Oracle, users must create a group transaction with one transaction paying the Oracle fee, only the transaction free in this version, while the other transactions can reference the signed price in any way related to user needs. For a complete explanation, refer to this article and also this on-chain example in testnet.
You can view the TEAL ALGO Oracle working tirelessly here: PRICEP3G2F5L6ZG5WTJIAKEQW4OJJ3FM4XVFQDZI7M2VBTFVUHTTR2AU2U
We open sourced the code to empower all developers and apps with the ability to implement custom TEAL Oracles that broadcast any type of data to Algorand’s Layer 1. A wide range of off-chain data can be brought on-chain by a variation of this Algorand TEAL Oracle, including stock prices, or fiat currency pair exchange rates, smart contract data from other chains, weather and sensor data, just to name a few.
The TEAL ALGO Oracle has a transaction fee of .001 ALGOs/block to record the ALGO/USD price from Coinbase in each Algorand block.

Borderless Capital Contribution

Borderless Capital has sponsored this research since its inception, and has further committed to bootstrap the initiative by funding the TEAL ALGO Oracle contract with enough ALGOs for it to run for one year. Now, any developer or dApp can use the TEAL ALGO Oracle at no cost. After that period, developers and apps can fuel the Oracle by sending it 0.001 ALGOs for each block they would like the Oracle to operate for, and the Oracle will produce a new on-chain price which can be referenced by any TEAL contracts (both stateless or stateful).

“We see the opportunity to sponsor the TEAL ALGO Oracle as a continued demonstration of our commitment to push the limits of Blockchain technology. This initiative may be one of the most significant additions to Algorand’s infrastructure to date. It not only provides one of the core building blocks for Algorand’s Finance 3.0 and DeFi ecosystem, it also inspires other developers to utilize this technology to develop their own innovations” ~ David Garcia, founding managing partner of Borderless Capital.

smart contracts

atomic transfer

Oracle

teal

August 26, 2020