@@ -940,10 +940,19 @@ func (fes *APIServer) GetQuoteCurrencyPriceInUsdEndpoint(ww http.ResponseWriter,
940940 }
941941}
942942
943- // TODO: When we boot up the Focus AMM, we need to update this value. The FOCUS floor price
944- // is set to $0.001 in DESO, so using a DESO price of $6 gets this value = $0.001 / $6. When
945- // we launch, we need use the updated DESO price and update this value.
946- const FOCUS_FLOOR_PRICE_DESO_NANOS = 166666
943+ // The FOCUS floor price is set to $0.001 in DESO.
944+ // On testnet, focus launched when DESO was at a price of $6 gets this value = $0.001 / $6. When
945+ // focus launches on mainnet, the FOCUS_FLOOR_PRICE_DESO_NANOS_MAINNET value needs to be updated
946+ // based on the price of DESO at launch.
947+ const FOCUS_FLOOR_PRICE_DESO_NANOS_TESTNET = 166666
948+ const FOCUS_FLOOR_PRICE_DESO_NANOS_MAINNET = 166666 // TODO: UPDATE ME.
949+
950+ func GetFocusFloorPriceDESONanos (isTestnet bool ) uint64 {
951+ if isTestnet {
952+ return FOCUS_FLOOR_PRICE_DESO_NANOS_TESTNET
953+ }
954+ return FOCUS_FLOOR_PRICE_DESO_NANOS_MAINNET
955+ }
947956
948957func (fes * APIServer ) GetQuoteCurrencyPriceInUsd (
949958 quoteCurrencyPublicKey string ) (_midmarket string , _bid string , _ask string , _err error ) {
@@ -960,7 +969,7 @@ func (fes *APIServer) GetQuoteCurrencyPriceInUsd(
960969
961970 usdcPKID := utxoView .GetPKIDForPublicKey (usdcProfileEntry .PublicKey )
962971 midMarketPrice , highestBidPrice , lowestAskPrice , err := fes .GetHighestBidAndLowestAskPriceFromPKIDs (
963- & lib .ZeroPKID , usdcPKID .PKID , utxoView , 0 )
972+ & lib .ZeroPKID , usdcPKID .PKID , utxoView , 0 , false )
964973 if err != nil {
965974 return "" , "" , "" , fmt .Errorf ("GetQuoteCurrencyPriceInUsd: Error getting price for DESO: %v" , err )
966975 }
@@ -1010,11 +1019,11 @@ func (fes *APIServer) GetQuoteCurrencyPriceInUsd(
10101019 // Find the highest bid price and the lowest ask price
10111020 highestBidPrice := float64 (0.0 )
10121021 if lowerUsername == "focus" {
1013- highestBidPrice = float64 (FOCUS_FLOOR_PRICE_DESO_NANOS ) / float64 (lib .NanosPerUnit )
1022+ highestBidPrice = float64 (GetFocusFloorPriceDESONanos ( fes . Params . NetworkType == lib . NetworkType_TESTNET ) ) / float64 (lib .NanosPerUnit )
10141023 }
10151024 var lowestAskPrice , midPriceDeso float64
10161025 midPriceDeso , highestBidPrice , lowestAskPrice , err = fes .GetHighestBidAndLowestAskPriceFromPKIDs (
1017- pkid .PKID , & lib .ZeroPKID , utxoView , highestBidPrice )
1026+ pkid .PKID , & lib .ZeroPKID , utxoView , highestBidPrice , lowerUsername == "focus" )
10181027 if err != nil {
10191028 return "" , "" , "" , fmt .Errorf ("GetQuoteCurrencyPriceInUsd: Error getting price: %v" , err )
10201029 }
@@ -1040,6 +1049,7 @@ func (fes *APIServer) GetHighestBidAndLowestAskPriceFromPKIDs(
10401049 quotePkid * lib.PKID ,
10411050 utxoView * lib.UtxoView ,
10421051 initialHighestBidPrice float64 ,
1052+ isFocus bool ,
10431053) (float64 , float64 , float64 , error ) {
10441054 ordersBuyingCoin1 , err := utxoView .GetAllDAOCoinLimitOrdersForThisDAOCoinPair (
10451055 basePkid , quotePkid )
@@ -1094,10 +1104,21 @@ func (fes *APIServer) GetHighestBidAndLowestAskPriceFromPKIDs(
10941104 }
10951105 }
10961106 if highestBidPrice != 0.0 && lowestAskPrice != math .MaxFloat64 {
1107+ // It's possible that the floor bid is greater than the
1108+ // lowest ask. In this case, we simply return the highest bid
1109+ // for all three prices.
1110+ if isFocus && highestBidPrice > lowestAskPrice {
1111+ return highestBidPrice , highestBidPrice , highestBidPrice , nil
1112+ }
10971113 midPrice := (highestBidPrice + lowestAskPrice ) / 2.0
10981114
10991115 return midPrice , highestBidPrice , lowestAskPrice , nil
11001116 }
1117+ // Special case for FOCUS which has a floor bid. We only
1118+ // hit this case if we don't have any ASK orders.
1119+ if isFocus {
1120+ return highestBidPrice , highestBidPrice , highestBidPrice , nil
1121+ }
11011122 return 0 , 0 , 0 , fmt .Errorf ("GetQuoteCurrencyPriceInUsd: Error calculating price" )
11021123}
11031124
0 commit comments