Terra SDR Arbitrage and Cross-rate Calculation

Background

Terra blockchain core has modules, oracle and market, which characterize the functionality of Terra

Oracle module

  1. The oracle module listens to oracle votes from validators and calculate exchange rates of each token pair
  2. The voting procedure is composed of two step, “prevote” and “vote”
  3. Terra uses SALT mechanism to hide the price inside the oracle prevote so that no one can expect the final exchange rates in advance
  4. Validators are using different price source for calculating oracle vote prices, but the number of sources are limited and fairly publicly known

Market module

  1. The market module allows any Terra ecosystem participants to swap a token to another kind based on most recent available exchange rates
  2. There exists “Tobin Tax”(0.25%) for any market swap, and “Spread Fee”(minimum 2%) for Terra<>Luna swaps

Quick Summary

Summary

  1. An arbitrage trader created roughly KRW 17.4 million in recent 2 months, taking advantage of “bumpy” SDR exchange rates

Strategy

  1. Swap from ukrw to usdr when SDR exchange rate is under-priced
  2. Swap from usdr to ukrw when SDR exchange rate is over-priced
  3. When there exists enough frequency of SDR exchange rate swings which are wider than 2*TOBIN_TAX(0.25%), this strategy is long term profitable
  4. Note that the trader should pay 2*TOBIN_TAX = 0.5% per each trade round(buy&sell SDR over KRW)
  5. If the swing was 0.7% then the trader profits 0.7% — 0.5% = 0.2%

Questions

  1. The condition is enough frequency of wide SDR/KRW exchange rate swings(>0.5%) in very short time
  2. Then, question is, why SDR/KRW exchange rate is frequently shaking up and down?

Analysis

Accumulated swap activity

A trader performed SDR-KRW swap trading for about 2 months, resulting in roughly 18 million KRW profit.

Capital utilized is around 90K SDR, and the player did almost 100 full round trips of swap trade.

Address : terra1qjyllg9cfv0d62axvyw4zswklkl0qa43fu8c6t

Case Study

We researched most recent swap trade round to understand the reason of the bumpy cross-exchange-rate of SDR/KRW

  1. A swap trade round explained

Above table explains that the trader found SDR expensive compared to KRW at height 209458, and immediately became cheaper at height 2090461~2090463.

Even thought the rate difference(profit rate of this round) was very small(about 0.1%) from “swap_rate_after_tax” value, actually it was much larger because the “swap_rate_after_tax” is calculated after the tobin tax 0.25%. Therefore we could guess that the swap rate for SDR/KRW was changed approximately 0.60%(0.1% + 2*0.25%) between 2090458 and 2090461

2. Votes during the trade round

Explanation of rate changes

  1. Note that usdr/ukrw = (usdr/uluna)/(ukrw/uluna)
  2. If we see the above table, the main factor of “changes” are from ukrw/uluna
  3. We see almost no change on “usdr/ukrw” rates
  4. But, we can observe that because median(usdr/uluna) changed 0.61% and median(ukrw/uluna) changed 0.14%, swap rate for usdr/ukrw changed -0.46%
  5. This is happening because Terra calculates median of each luna rates first, and then uses those calculated median to get each cross-rates

Suggested Solution : Alternative cross-rate computation process

  1. Alternative is to calculate each cross-rates from each vote, and then calculate median from calculated cross-rates
  2. From below example, if we apply alternative approach, the cross-rate doesn’t change at all, which is consistent result from the data because we can see that the cross-rates of each validator are not changed!
  3. So, in conclusion, when the state machine calculates each cross-rate, it should first calculate implied cross-rate of each validator, and then get median from those calculated implied cross-rate