Tethering a token to USD using the rate oracle

I think one-way conversion is a more useful primitive.

This can be used in the loan application for example (will elaborate in a different post).

The one-way convertible token is defined as follows:

Bob can create a “token box” with a large number of “USD tokens” that can be exchanged for Ergs at the current rate in USD/Erg. The contract in the token box only allows changing Ergs to tokens and not the other way round.

So Bob could create a box with 1 trillion tokens such that anyone can pay ergs and purchase tokens at the inverse rate of USD/ergs. If the rate is 10 USD/Erg, then anyone can purchase X number of tokens by paying X/10 Ergs.

Bob promises to consider these tokens equivalent to USD. In particular, Bob promises:

  1. To give physical USD in exchange for tokens at 1:1 rate.
  2. To accept tokens in lieu of USD at 1:1 rate.

(In our interest free loan example, we only need property 2, though 1 may be useful for other applications)

Bob only sells those tokens via the token box whose code is given below.

 {
  val newSelf = OUTPUTS(0)
  val bobOut = OUTPUTS(1)
 
  val bobNanoErgs = bobOut.value
  val validBobBox = bobOut.propositionBytes == proveDlog(bob).propBytes
 
  val selfTokenID = SELF.tokens(0)._1
  val selfTokenAmt = SELF.tokens(0)._2
 
  val newSelfTokenID = newSelf.tokens(0)._1
  val newSelfTokenAmt = newSelf.tokens(0)._2
  val validTokenID = selfTokenID == newSelfTokenID
  val validProp = newSelf.propositionBytes == SELF.propositionBytes
 
  val tokenDiff = selfTokenAmt - newSelfTokenAmt
  val validNewSelf = validTokenID && validProp
 
  val rateBox = CONTEXT.dataInputs(0)
  val rate = rateBox.R4[Long].get
  val validRateBox = rateBox.tokens(0)._1 == rateTokenID
 
  // rate gives nanoErgs per USDCent
  // Thus, bobNanoErgs NanoErgs will cost bobNanoErgs / rate usd cents
 
  val usdCDiff = bobNanoErgs / rate
 
  tokenDiff <= usdCDiff && validRateBox && validNewSelf && validBobBox
 }

In the interest free loan example, Bob can offer Alice a loan of, say, 100 physical USD in an offchain transaction in return for a box with some collateral in Ergs locked.
Let this be the “loan box”

The loan box says that every month Alice must pay 10 usd tokens and if she misses payment, Bob can initiate a recovery process using her collateral. If all goes well and Alice has paid 100 USD tokens then she can take back her collateral.

Bobs incentive would be to sell the tokens at a slightly higher rate than the current rate.

4 Likes