External Price Feeds in ETHLend using Oraclize

Written by sjkelleyjr | Published 2017/12/22
Tech Story Tags: cryptocurrency | tech | fintech | ethereum | blockchain

TLDRvia the TL;DR App

ETHLend is an Ethereum based lending platform that aims to unbank lending and offer blockchain liquidity backed by crypto assets. In short, ETHLend does this by allowing borrowers to put different types of tokens up as collateral for pseudonymous and transparent borrowing and liquidity. While the the idea is simple, in practice, the engineering necessary to provide a rich set of features to the user is non trivial since the ethereum infrastructure is still in it’s infancy. Today we’ll investigate one of the challenges.

Price Feeds

When a user provides a token as collateral to the ETHLend smart contract, the question is: what is this collateral really worth, and who gets to decide this? Is it the lender, or the borrower? or someone else completely?

As an example, perhaps I would like a loan of 10 ETH for my Sunday Lambo shopping. I’m willing to give you 10 DOGE as collateral for this loan. Obviously this is an extreme example, and I would hope no lenders would be willing to take such a laughable loan, however, what about a loan of 1 ETH for 45 OMG?

It becomes clear that we need a way of accessing data outside the ethereum network in order to have an agreed upon standard for fiat, ether, and token values. Rather than letting any one person decide the value, we can allow the market to decide. But how are we going to get this data? It isn’t readily available to the Ethereum blockchain.

Oraclize

Many in blockchain are already familiar with the phenomenal Oraclize service. For those not familiar, a brief explanation from Oraclize themselves:

“Oraclize is a service offering a set of tools and APIs aiming to enhance the power of smart contracts. By providing access to both on-chain and off-chain data, Oraclize allows to find an answer to any query your contract may have.”

Essentially, what Oraclize does, is it empowers smart contracts to access information outside of the blockchain in a trustless way. Want to pay a user ether every time they tweet your hashtag? Oraclize makes this possible. Want to attach a bounty to your stack overflow question? Oraclize makes this possible. The possibilities with the brilliant Oraclize service are endless.

Tying Them Together

ETHLend has developed an Oraclized based smart contract that allows for loans to be requested in USD but transacted on the Ethereum blockchain using the Kraken API for the exchange rate. Internally, ETHLend’s contract keeps the USD/ETH price updated every minute through the EthTicker method. It then exposes this publically to dApp developers through a call to the smart contract’s “ethPriceInUsd” variable. Any time a user would like to create a loan in USD, or even get the exchange rate, this can be readily retrieved and accessible to all ETHLend participants as the agreed upon value. Obviously this contract can easily be extended to any fiat currencies currently trading against ETH, as well as any number of ERC20 tokens as well.

Edge Cases

There are, and will continue to be, a number of different edges cases that may arise in the lending cycle, and ETHLend is continually closing the gap on these. Let’s take a few short toy examples to illustrate how this external price feed comes in handy.

How do we know if the borrower has enough value in the tokens they’ve offered as collateral for a loan? Easy, have the smart contract check the exchange rate for the collateral and the requested loan amount to ensure the borrower and lender are copacetic on the value proposition.

What about when the loan has been filled and the collateral drops or rises in value before the loan is repaid? Crypto is highly volatile after all. With the current ETHLend smart contract, since the loan was presumably created in USD, the volatility of the underlying cryptocurrency is irrelevent. A loan for 500 USD today may involve .625 ETH, and at the time of repayment, 50 ETH, however, as long as the two parties are comfortable treating USD as the pegged currency, they are happy with the outcome. With this new smart contract, they now have the ability to do so, should they choose.

Conclusion

As I said, even a simple concept such as lending on the blockchain is actually fraught with different edge cases. Because of this, ETHLend is always looking out for talented blockchain engineers to contribute!

As we saw, having a way to value currencies in a loan market is of utmost importance for decentralized lending. With Oraclize, ETHLend has this power, and is able to give a much more rich set of functionality to users than it can without Oraclize, making the loan process even more transparent in the process.


Written by sjkelleyjr | crypto @ robinhood | ex-amazon | yAcademy resident | whitehat @ Oak Security & Spearbit | built & sold a tech-newsletter
Published by HackerNoon on 2017/12/22