From 7929021c81339c4ef30b18ee0a4ca59cefb78c36 Mon Sep 17 00:00:00 2001 From: Lazy Nina Date: Sun, 3 Nov 2024 21:57:47 -0500 Subject: [PATCH] deprecate fields and fill deprecated fields with deso dex price --- routes/base.go | 16 +++------------- routes/dao_coin_exchange_with_fees.go | 7 +++---- routes/server.go | 2 +- routes/transaction.go | 2 +- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/routes/base.go b/routes/base.go index 8daa0ef1..50194795 100644 --- a/routes/base.go +++ b/routes/base.go @@ -76,7 +76,7 @@ type GetExchangeRateResponse struct { USDCentsPerDeSoReserveExchangeRate uint64 BuyDeSoFeeBasisPoints uint64 USDCentsPerDeSoBlockchainDotCom uint64 - USDCentsPerDeSoCoinbase uint64 + USDCentsPerDeSoCoinbase uint64 // Deprecated SatoshisPerBitCloutExchangeRate uint64 // Deprecated USDCentsPerBitCloutExchangeRate uint64 // Deprecated @@ -132,10 +132,6 @@ func (fes *APIServer) GetExchangeRate(ww http.ResponseWriter, rr *http.Request) func (fes *APIServer) GetExchangeDeSoPrice() uint64 { // We no longer observe a reserve rate. return fes.MostRecentDesoDexPriceUSDCents - //if fes.UsdCentsPerDeSoExchangeRate > fes.USDCentsToDESOReserveExchangeRate { - // return fes.UsdCentsPerDeSoExchangeRate - //} - //return fes.USDCentsToDESOReserveExchangeRate } type BlockchainDeSoTickerResponse struct { @@ -385,14 +381,8 @@ func (fes *APIServer) UpdateUSDCentsToDeSoExchangeRate() { glog.Errorf("UpdateUSDCentsToDeSoExchangeRate: Error fetching exchange rate from DeSoDex: %v", err) } - // Take the max - lastTradePrice, err := stats.Max([]float64{blockchainDotComPrice, gatePrice, desoDexPrice}) - // store the most recent exchange prices - // For now, we are using gate.io as the primary exchange - // for pricing of deso. - //fes.MostRecentCoinbasePriceUSDCents = uint64(coinbasePrice) - fes.MostRecentCoinbasePriceUSDCents = uint64(gatePrice) + fes.MostRecentCoinbasePriceUSDCents = uint64(desoDexPrice) fes.MostRecentBlockchainDotComPriceUSDCents = uint64(blockchainDotComPrice) fes.MostRecentGatePriceUSDCents = uint64(gatePrice) fes.MostRecentDesoDexPriceUSDCents = uint64(desoDexPrice) @@ -400,7 +390,7 @@ func (fes *APIServer) UpdateUSDCentsToDeSoExchangeRate() { // Get the current timestamp and append the current last trade price to the LastTradeDeSoPriceHistory slice timestamp := uint64(time.Now().UnixNano()) fes.LastTradeDeSoPriceHistory = append(fes.LastTradeDeSoPriceHistory, LastTradePriceHistoryItem{ - LastTradePrice: uint64(lastTradePrice), + LastTradePrice: uint64(desoDexPrice), Timestamp: timestamp, }) diff --git a/routes/dao_coin_exchange_with_fees.go b/routes/dao_coin_exchange_with_fees.go index c6720e17..01e16759 100644 --- a/routes/dao_coin_exchange_with_fees.go +++ b/routes/dao_coin_exchange_with_fees.go @@ -956,10 +956,9 @@ func (fes *APIServer) GetQuoteCurrencyPriceInUsd( } else if lowerUsername == "focus" || lowerUsername == "openfund" { - // TODO: We're taking the Coinbase price directly here, but ideally we would get it from - // a function that abstracts away the exchange we're getting it from. We do this for now - // in order to minimize discrepancies with other sources. - desoUsdCents := fes.MostRecentCoinbasePriceUSDCents + // Get the exchange deso price. currently this function + // just returns the price from the deso dex. + desoUsdCents := fes.GetExchangeDeSoPrice() if desoUsdCents == 0 { return "", "", "", fmt.Errorf("GetQuoteCurrencyPriceInUsd: Coinbase DESO price is zero") } diff --git a/routes/server.go b/routes/server.go index b6384640..41430c81 100644 --- a/routes/server.go +++ b/routes/server.go @@ -398,7 +398,7 @@ type APIServer struct { LastTradePriceLookback uint64 // most recent exchange prices fetched - MostRecentCoinbasePriceUSDCents uint64 + MostRecentCoinbasePriceUSDCents uint64 // Deprecated MostRecentBlockchainDotComPriceUSDCents uint64 MostRecentGatePriceUSDCents uint64 MostRecentDesoDexPriceUSDCents uint64 diff --git a/routes/transaction.go b/routes/transaction.go index 61b94deb..41fb3e88 100644 --- a/routes/transaction.go +++ b/routes/transaction.go @@ -1199,7 +1199,7 @@ func (fes *APIServer) GetNanosFromUSDCents(usdCents float64, feeBasisPoints uint } func (fes *APIServer) GetUSDFromNanos(nanos uint64) float64 { - usdCentsPerDeSo := float64(fes.UsdCentsPerDeSoExchangeRate) + usdCentsPerDeSo := float64(fes.GetExchangeDeSoPrice()) return usdCentsPerDeSo * float64(nanos/lib.NanosPerUnit) / 100 }