Getting Started

In this quick guide, we will help you add OrFeed to your smart contract.

Here's a quick tutorial video that explains the basics of OrFeed.



At the top of your smart contract or in a referenced file in your dApp project, include this interface.

If you're using Solidity 0.5.0+:

pragma experimental ABIEncoderV2;

interface OrFeedInterface {
  function getExchangeRate ( string calldata fromSymbol, string calldata  toSymbol, string calldata venue, uint256 amount ) external view returns ( uint256 );
  function getTokenDecimalCount ( address tokenAddress ) external view returns ( uint256 );
  function getTokenAddress ( string calldata  symbol ) external view returns ( address );
  function getSynthBytes32 ( string calldata  symbol ) external view returns ( bytes32 );
  function getForexAddress ( string calldata symbol ) external view returns ( address );
  function arb(address  fundsReturnToAddress,  address liquidityProviderContractAddress, string[] calldata   tokens,  uint256 amount, string[] calldata  exchanges) external payable returns (bool);
}

Under Solidity 0.5.0:

interface OrFeedInterface {
  function getExchangeRate ( string fromSymbol, string toSymbol, string venue, uint256 amount ) external view returns ( uint256 );
  function getTokenDecimalCount ( address tokenAddress ) external view returns ( uint256 );
  function getTokenAddress ( string symbol ) external view returns ( address );
  function getSynthBytes32 ( string symbol ) external view returns ( bytes32 );
  function getForexAddress ( string symbol ) external view returns ( address );
  function arb(address fundsReturnToAddress, address liquidityProviderContractAddress, string[] tokens,  uint256 amount, string[] exchanges) payable returns (bool);
}

Initializing

To initialize OrFeed, simply include this code in your smart contract:

OrFeedInterface orfeed= OrFeedInterface(0x8316B082621CFedAB95bf4a44a1d4B64a6ffc336)


Get The Current Price

One of the best things about OrFeed is that OrFeed automatically detects which kind of asset you are looking for (though the data can come from different providers), as the parameter of "venue" when making the getExchangeRate call. For example, you can get the price for ETH/USD the same way you get the price for JPY/ETH.

//the third blank parameter is venue or the oracle code that you would like to receive the data from, as there can be multiple oracles providing data on the same pair. Blank is the default oracle for a pair.
uint jpyusdPrice = orfeed.getExchangeRate("JPY", "USD", "DEFAULT", 100000);
// returns 920 (or $920.00)

As solidity does not have decimals, all responses are in integers. To determine how many decimals you should calculate with, you can call the getTokenDecimalCount external function for both your assets in the conversion. If you receive a response of 0, either the pair you are sending is not included in the free feed, you are requesting a premium feed and not subscribed, or oracles for the subscriber OrFeed premium feed do not yet support it (and you can fix this by becoming an OrFeed oracle!). Most popular crypto tokens and five of the most popular forex pairs are included in the free feed, and will always remain free.

Note: Replace "DEFAULT" with the oracle provider you would like data from. Due to the way Bancor works with swaps/liquidity paths, you can simply use "BANCOR" when querying Bancor. Because ERC-20s have many, many integers and zero decimals (in the actual smart contracts), when getting prices from token to token, be sure to use very large amounts.... 1000000000 DAI is less than one penny, for example, due to divisibility at 18.

Other Examples


uint price = orfeed.getExchangeRate("ETH", "USDC", "UNISWAPBYSYMBOLV1", 100000000000000);
OrFeed supports Uniswap v2 as follows:

uint price = orfeed.getExchangeRate("ETH", "USDC", "UNISWAPBYSYMBOLV2", 100000000000000);


uint price = orfeed.getExchangeRate("BTC", "DAI", "SELL-UNISWAP-EXCHANGE", 100);
uint price = orfeed.getExchangeRate("BTC", "DAI", "SELL-UNISWAP-EXCHANGE", 100);


uint price = orfeed.getExchangeRate("ETH", "DAI", "BANCOR", 1000000000000000);


Experimental:
uint price = orfeed.getExchangeRate("AAPL", "USD", "PROVIDER1", 1);


Note:
You can register a provider name and connect it to your custom oracle contract (DNS-style) via the OrFeed Oracle Registry: here by calling the registerOracle function. An example of an oracle smart contract that will be compatible with the OrFeed proxy contract is available in /contracts/examples/ProvideDataExamples/userGeneratedOracleExample.sol on Github (very simple example that either returns 500 or 2) Once you deploy your contract and register it to the registry (paying a small amount of ETH to prevent spamming of names), you can check/verify your registration by calling the getOracleAddress function.
As more reputable, as well as trustless, oracle smart contracts register within the OrFeed registry, we will update a new list as a reference.



The above are all examples of synchronous data for pricing. More docs regarding grabbing asynchronous pricing, as well as event outcome data, from Chainlink, Augur, and other data providers coming soon.

Understanding the OrFeed.arb function

Primer

Trianglular arbitrage enables a user to perform a multi-point exchange of funds between specified Assets on supported decentralized exchanges. The orfeed.arb method also supports a simple 2-way exchange, in addition to 3+ way.

OrFeed Angle

OrFeed Angle provides a user interface to engage in triangle arbitrage and test OrFeed's arb method. Configuring the Angle system with your wallet of choice will require approving access between the OrFeed contract and one of your tokens. For example, in order to perform arbitrage between USDC, ETH and DAI a user will be required to confirm an approval transaction for the first of the three tokens (USDC in this case).

OrFeed Arb method

The OrFeed contract provides a function called `arb` which is used to perform a streamlined triangular arbitrage operation.

Example of the Arb method

Provided in this repository is a smart contract which uses the arb function in conjunction with a flash loan as a source of funds.
Arb function used with a Flash Loan

Parameters of the arb method

`address fundsReturnToAddress` - After execution this is the address funds are sent to to conclude the operation
`address liquidityProviderContractAddress` - The address that will be used as a source of liquidity. Can be the same value as `fundsReturnToAddress`
`string[] tokens` - An array containing the symbols or 2 or three tokens to be arbitraged
`uint256 amount` - The amount of funds that will be used for the arbitrage
`string[] exchanges` - An array containing the names of 2 or 3 exchange which will be used during the arbitrage


Demo

Try out the getExchangeRate method here:



To test full functionality, please visit the Dapp Page On Etherscan




OrFeed Oracle Network

Here's a quick 1-pager (click to download PDF) that explains the basics of how the OrFeed oracle network works:


All free price data comes from decentralized platforms on the Ethereum blockchain, such as Kyber Network, Uniswap Exchange and Synthetix. These mostly include cryptocurrency, foreign exchange and some public equity prices.
Many dApps need/will need access to pricing data from specific exchanges for the above (free) assets or other data like ETF, mutual fund, bond, interest rate, or other data. These feeds are provided by the OrFeed Oracle Network.

But how does this work?

It's quite simple. Anyone can become an OrFeed provider, granted they can stake Ethereum. Currently, it costs .5 ETH as a deposit (stake) to provide a feed for one pair. If the prices you provide deviate by 2% or more (this becomes tighter as more adoption arrives) at any moment, your funds are sent to the OrFeed DAO, and others can purchase that feed to become the provider. The price to become a provider of a feed increases based on the demand and systematic risk that oracles provide to OrFeed subscribers.

To subscribe to OrFeed, users simply send in the monthly subscribers' fee (set each month by the OrFeed DAO and currently .05ETH). This grants unlimited access to all premium feeds to a users' smart contract. 90% of all subscription costs (rents) are sent to the feed provider. 10% is sent to the OrFeed DAO to monitor and police the accuracy of feed provider data.


Join The OrFeed Network

Currently, OrFeed is in alpha. To be one of the first to receive the smart contract address for purchasing OrFeed provisions as soon as its release, please send an email with the subject "Orfeed Oracle Network" to support@proofsuite.com. Sign-up form coming soon. Emails will be sent in the order they are received.


Contribute To OrFeed

We welcome you to join us in providing the most reliable pricing data to Ethereum dApps! If you see anything wrong, have ideas, or would like to add a feature, please send a pull request on our develop branch here.