Skip to content

Commit

Permalink
deprecate fields and fill deprecated fields with deso dex price
Browse files Browse the repository at this point in the history
  • Loading branch information
lazynina committed Nov 4, 2024
1 parent cf4079c commit 7929021
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
16 changes: 3 additions & 13 deletions routes/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type GetExchangeRateResponse struct {
USDCentsPerDeSoReserveExchangeRate uint64
BuyDeSoFeeBasisPoints uint64
USDCentsPerDeSoBlockchainDotCom uint64
USDCentsPerDeSoCoinbase uint64
USDCentsPerDeSoCoinbase uint64 // Deprecated

SatoshisPerBitCloutExchangeRate uint64 // Deprecated
USDCentsPerBitCloutExchangeRate uint64 // Deprecated
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -385,22 +381,16 @@ 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)

// 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,
})

Expand Down
7 changes: 3 additions & 4 deletions routes/dao_coin_exchange_with_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion routes/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion routes/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 7929021

Please sign in to comment.