classic-terra / oracle-feeder

Oracle Feeder Daemon
Apache License 2.0
6 stars 8 forks source link

No SDR prices available anymore #28

Closed StrathCole closed 11 months ago

StrathCole commented 11 months ago

It seems, exchangerate.host changed their policy to closed usage. All (or at least most) oracle price servers who used the service, don't have an API key, but calling the api without key is no longer possible.

So the chain currently has no SDR price anymore. And as it's the core currency for the MM … 🤷‍♂️ It stopped working ~ Block 14723744. Which was ~2 days ago.

You can see that https://terra-classic-lcd.publicnode.com/terra/oracle/v1beta1/denoms/exchange_rates has no usdr in the exchange rates anymore. Also curl -s http://127.0.0.1:8532/latest | jq '.prices[] | select(.denom == "SDR")' on the oracle server returns an empty result.

It also means that stable-to-stable swaps are currently non-functional.

StrathCole commented 11 months ago

A possible solution to work around the common issue of only a single (or none) source for SDR, it would maybe be an idea to calculate a pseudo-SDR ourselves.

Regarding https://www.imf.org/en/News/Articles/2022/07/29/pr22281-press-release-imf-determines-new-currency-amounts-for-the-sdr-valuation-basket the basket only changes each 5 years, so next time in 2027.

The current formula would be: SDR value in USD=(0.57813⋅USD)+(0.37379⋅EUR)+(1.0993⋅CNY)+(13.452⋅JPY)+(0.080870⋅GBP)

So as we have values for EUR, CNY, JPY, GBP available, we could calculate the SDR value in USD with that formula in the price feeder. It may not be 100% the same value as published by the IMF daily, but it would represent the same factors of each currency.

StrathCole commented 11 months ago
curl -s http://127.0.0.1:8532/latest | jq '[.prices[] | 
        select(.denom == "GBP" or .denom == "EUR" or .denom == "CNY" or .denom == "JPY") | 
        {(.denom): (.price | tonumber)}] | 
        add | 
        (0.57813 + (.EUR * 0.37379) + (.CNY * 1.0993) + (.JPY * 13.452) + (.GBP * 0.080870))'

Result: 1.31140786

Which nearly matches yesterday's official IMF value of 1.311320 published on https://www.imf.org/external/np/fin/data/rms_sdrv.aspx

aeuser999 commented 11 months ago

Comments: Just a note though that there are other SDR Providers (FastForex is $9 a month - was just added in 3 months back to help keep SDR pricing from a single source of failure, also the other fiat providers were also fixed to work for SDR pricing as well [although a bit higher than $9 a month]).

What is interesting is that many are still voting with SDR sources:

Yet, it is seeing 0.0 as an actual price rather than an abstain (so that probably needs to be fixed):

A Potential Code Update Here is an adjustment to make ExchangeRate work (both non-API and API):

I hope that helps out a little bit, and that you each have a great day today :)

StrathCole commented 11 months ago

Just a note though that there are other SDR Providers (FastForex is $9 a month - was just added in 3 months back to help keep SDR pricing from a single source of failure, also the other fiat providers were also fixed to work for SDR pricing as well [although a bit higher than $9 a month]).

The issue is that with high probability most are not using any price services that cost that much, especially not in the current LUNC price situation. And even with using FastForex now, it would be back at a single provider (exchangerate would now cost ~$40/m). So the question is if using external sources for SDR is necessary at all. After all it's only a combination of other currencies which we have more (free) sources for, I think.

aeuser999 commented 11 months ago

@StrathCole : here is a fix that works with ExchangeRate both without api key and with api key (tested it), just did not create a pull request (although you can pull the whole repo and test with, just rename default-test.js to default.js):

StrathCole commented 11 months ago

@StrathCole : here is a fix that works with ExchangeRate both without api key and with api key (tested it), just did not create a pull request (although you can pull the whole repo and test with, just rename default-test.js to default.js):

* [aeuser999/test_oracle_feeder@141872a](https://github.com/aeuser999/test_oracle_feeder/commit/141872a89fb5ddeb5b915c8d8b8380600eec02a5)

Looks good and seems to return valid results. The question is, if it is necessary to use these SDR prices or if it is better to calculate it ourselve from the other fiat prices which we have more sources of I think? https://github.com/classic-terra/oracle-feeder/pull/30

From the values I would guess that the er-api doesn't match the IMF value either, but we still rely on the external SDR source(s) then.

IMF (official source) reports: 1.311320 currently for yesterday (28th), er-api reports 1,30979, the manual calculation from on-chain oracle rates (above PR) gives 1.31140786