Skip to content

Commit 12569e4

Browse files
authored
Handle focus floor bid case (#713)
* Handle focus floor bid case * address DH feedback
1 parent ecc10f4 commit 12569e4

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

routes/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (fes *APIServer) GetExchangeRateFromDeSoDex() (float64, error) {
350350

351351
usdcPKID := utxoView.GetPKIDForPublicKey(usdcProfileEntry.PublicKey)
352352

353-
midPriceUSD, _, _, err := fes.GetHighestBidAndLowestAskPriceFromPKIDs(&lib.ZeroPKID, usdcPKID.PKID, utxoView, 0)
353+
midPriceUSD, _, _, err := fes.GetHighestBidAndLowestAskPriceFromPKIDs(&lib.ZeroPKID, usdcPKID.PKID, utxoView, 0, false)
354354
if err != nil {
355355
return 0, err
356356
}

routes/dao_coin_exchange_with_fees.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = 40000
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

948957
func (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
}
@@ -1009,12 +1018,14 @@ func (fes *APIServer) GetQuoteCurrencyPriceInUsd(
10091018
}
10101019
// Find the highest bid price and the lowest ask price
10111020
highestBidPrice := float64(0.0)
1012-
if lowerUsername == "focus" {
1013-
highestBidPrice = float64(FOCUS_FLOOR_PRICE_DESO_NANOS) / float64(lib.NanosPerUnit)
1021+
isFocus := lowerUsername == "focus"
1022+
if isFocus {
1023+
isTestnet := fes.Params.NetworkType == lib.NetworkType_TESTNET
1024+
highestBidPrice = float64(GetFocusFloorPriceDESONanos(isTestnet)) / float64(lib.NanosPerUnit)
10141025
}
10151026
var lowestAskPrice, midPriceDeso float64
10161027
midPriceDeso, highestBidPrice, lowestAskPrice, err = fes.GetHighestBidAndLowestAskPriceFromPKIDs(
1017-
pkid.PKID, &lib.ZeroPKID, utxoView, highestBidPrice)
1028+
pkid.PKID, &lib.ZeroPKID, utxoView, highestBidPrice, isFocus)
10181029
if err != nil {
10191030
return "", "", "", fmt.Errorf("GetQuoteCurrencyPriceInUsd: Error getting price: %v", err)
10201031
}
@@ -1040,6 +1051,7 @@ func (fes *APIServer) GetHighestBidAndLowestAskPriceFromPKIDs(
10401051
quotePkid *lib.PKID,
10411052
utxoView *lib.UtxoView,
10421053
initialHighestBidPrice float64,
1054+
isFocus bool,
10431055
) (float64, float64, float64, error) {
10441056
ordersBuyingCoin1, err := utxoView.GetAllDAOCoinLimitOrdersForThisDAOCoinPair(
10451057
basePkid, quotePkid)
@@ -1094,10 +1106,21 @@ func (fes *APIServer) GetHighestBidAndLowestAskPriceFromPKIDs(
10941106
}
10951107
}
10961108
if highestBidPrice != 0.0 && lowestAskPrice != math.MaxFloat64 {
1109+
// It's possible that the floor bid is greater than the
1110+
// lowest ask. In this case, we simply return the highest bid
1111+
// for all three prices.
1112+
if isFocus && highestBidPrice > lowestAskPrice {
1113+
return highestBidPrice, highestBidPrice, highestBidPrice, nil
1114+
}
10971115
midPrice := (highestBidPrice + lowestAskPrice) / 2.0
10981116

10991117
return midPrice, highestBidPrice, lowestAskPrice, nil
11001118
}
1119+
// Special case for FOCUS which has a floor bid. We only
1120+
// hit this case if we don't have any ASK orders.
1121+
if isFocus {
1122+
return highestBidPrice, highestBidPrice, highestBidPrice, nil
1123+
}
11011124
return 0, 0, 0, fmt.Errorf("GetQuoteCurrencyPriceInUsd: Error calculating price")
11021125
}
11031126

0 commit comments

Comments
 (0)