Skip to content

Commit

Permalink
take 2
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Jun 24, 2022
1 parent 220494d commit 6631281
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 30 deletions.
1 change: 0 additions & 1 deletion client/asset/btc/btc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2813,7 +2813,6 @@ func testPreRedeem(t *testing.T, segwit bool, walletType string) {
defer shutdown()

preRedeem, err := wallet.PreRedeem(&asset.PreRedeemForm{
LotSize: 123456, // Doesn't actually matter
Lots: 5,
AssetConfig: tBTC,
})
Expand Down
1 change: 0 additions & 1 deletion client/asset/dcr/dcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2507,7 +2507,6 @@ func TestPreRedeem(t *testing.T) {
defer shutdown()

preRedeem, err := wallet.PreRedeem(&asset.PreRedeemForm{
LotSize: 123456, // Doesn't actually matter
Lots: 5,
AssetConfig: tDCR,
})
Expand Down
4 changes: 0 additions & 4 deletions client/asset/estimation.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ type PreSwap struct {

// PreRedeemForm can be used to get a redemption estimate.
type PreRedeemForm struct {
// LotSize is the lot size for the calculation. For quote assets, LotSize
// should be based on either the user's limit order rate, or some measure
// of the current market rate.
LotSize uint64
// Lots is the number of lots in the order.
Lots uint64
// FeeSuggestion is a suggested fee from the server.
Expand Down
1 change: 0 additions & 1 deletion client/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,6 @@ func TestPreRedeem(t *testing.T) {
defer shutdown()

form := &asset.PreRedeemForm{
LotSize: 123456,
Lots: 5,
FeeSuggestion: 100,
AssetConfig: tETH,
Expand Down
20 changes: 4 additions & 16 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3728,7 +3728,6 @@ func (c *Core) MaxBuy(host string, base, quote uint32, rate uint64) (*MaxOrderEs
}

preRedeem, err := baseWallet.PreRedeem(&asset.PreRedeemForm{
LotSize: lotSize,
Lots: maxBuy.Lots,
FeeSuggestion: redeemFeeSuggestion,
AssetConfig: baseAsset,
Expand All @@ -3747,7 +3746,7 @@ func (c *Core) MaxBuy(host string, base, quote uint32, rate uint64) (*MaxOrderEs
// market. Redemption estimates are based on the provided rate. If a rate of
// zero is specified, the orderbook's mid-gap rate will be used for the
// estimate.
func (c *Core) MaxSell(host string, base, quote uint32, rate uint64) (*MaxOrderEstimate, error) {
func (c *Core) MaxSell(host string, base, quote uint32) (*MaxOrderEstimate, error) {
baseAsset, quoteAsset, baseWallet, quoteWallet, err := c.marketWallets(host, base, quote)
if err != nil {
return nil, err
Expand Down Expand Up @@ -3793,17 +3792,7 @@ func (c *Core) MaxSell(host string, base, quote uint32, rate uint64) (*MaxOrderE
return nil, fmt.Errorf("%s wallet MaxOrder error: %v", unbip(base), err)
}

if rate == 0 {
rate, err = book.MidGap()
if err != nil {
return nil, fmt.Errorf("error calculating market rate for %s at %s: %v", mktID, host, err)
}
}

lotSize = calc.BaseToQuote(rate, lotSize)

preRedeem, err := quoteWallet.PreRedeem(&asset.PreRedeemForm{
LotSize: lotSize,
Lots: maxSell.Lots,
FeeSuggestion: redeemFeeSuggestion,
})
Expand Down Expand Up @@ -4206,13 +4195,13 @@ func (c *Core) PreOrder(form *TradeForm) (*OrderEstimate, error) {
return nil, fmt.Errorf("failed to get redeem fee suggestion for %s at %s", unbip(wallets.toAsset.ID), form.Host)
}

fromLotSize, toLotSize := lotSize, calc.BaseToQuote(rate, lotSize)
swapLotSize := lotSize
if !form.Sell {
fromLotSize, toLotSize = toLotSize, fromLotSize
swapLotSize = calc.BaseToQuote(rate, lotSize)
}

swapEstimate, err := wallets.fromWallet.PreSwap(&asset.PreSwapForm{
LotSize: fromLotSize,
LotSize: swapLotSize,
Lots: lots,
AssetConfig: wallets.fromAsset,
RedeemConfig: wallets.toAsset,
Expand All @@ -4225,7 +4214,6 @@ func (c *Core) PreOrder(form *TradeForm) (*OrderEstimate, error) {
}

redeemEstimate, err := wallets.toWallet.PreRedeem(&asset.PreRedeemForm{
LotSize: toLotSize,
Lots: lots,
FeeSuggestion: redeemFeeSuggestion,
SelectedOptions: form.Options,
Expand Down
3 changes: 1 addition & 2 deletions client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,12 +938,11 @@ func (s *WebServer) apiMaxSell(w http.ResponseWriter, r *http.Request) {
Host string `json:"host"`
Base uint32 `json:"base"`
Quote uint32 `json:"quote"`
Rate uint64 `json:"rate"`
}{}
if !readPost(w, r, form) {
return
}
maxSell, err := s.core.MaxSell(form.Host, form.Base, form.Quote, form.Rate)
maxSell, err := s.core.MaxSell(form.Host, form.Base, form.Quote)
if err != nil {
s.writeAPIError(w, fmt.Errorf("max order estimation error: %w", err))
return
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func (c *TCore) MaxBuy(host string, base, quote uint32, rate uint64) (*core.MaxO
}, nil
}

func (c *TCore) MaxSell(host string, base, quote uint32, rate uint64) (*core.MaxOrderEstimate, error) {
func (c *TCore) MaxSell(host string, base, quote uint32) (*core.MaxOrderEstimate, error) {
mktID, _ := dex.MarketName(base, quote)
lotSize := tExchanges[host].Markets[mktID].LotSize
midGap, maxQty := getMarketStats(mktID)
Expand Down
3 changes: 1 addition & 2 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,7 @@ export default class MarketsPage extends BasePage {
if (mkt.maxSellRequested) return
mkt.maxSellRequested = true
// We only fetch pre-sell once per balance update, so don't delay.
const rate = this.isLimit() ? this.adjustedRate() : 0
this.scheduleMaxEstimate('/api/maxsell', { rate }, 0, (res: MaxSell) => {
this.scheduleMaxEstimate('/api/maxsell', {}, 0, (res: MaxSell) => {
mkt.maxSellRequested = false
mkt.maxSell = res.maxSell
mkt.sellBalance = baseWallet.balance.available
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type clientCore interface {
Orders(*core.OrderFilter) ([]*core.Order, error)
Order(oid dex.Bytes) (*core.Order, error)
MaxBuy(host string, base, quote uint32, rate uint64) (*core.MaxOrderEstimate, error)
MaxSell(host string, base, quote uint32, rate uint64) (*core.MaxOrderEstimate, error)
MaxSell(host string, base, quote uint32) (*core.MaxOrderEstimate, error)
AccountExport(pw []byte, host string) (*core.Account, error)
AccountImport(pw []byte, account core.Account) error
AccountDisable(pw []byte, host string) error
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/webserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (c *TCore) Order(oid dex.Bytes) (*core.Order, error) { return nil, n
func (c *TCore) MaxBuy(host string, base, quote uint32, rate uint64) (*core.MaxOrderEstimate, error) {
return nil, nil
}
func (c *TCore) MaxSell(host string, base, quote uint32, rate uint64) (*core.MaxOrderEstimate, error) {
func (c *TCore) MaxSell(host string, base, quote uint32) (*core.MaxOrderEstimate, error) {
return nil, nil
}
func (c *TCore) PreOrder(*core.TradeForm) (*core.OrderEstimate, error) {
Expand Down

0 comments on commit 6631281

Please sign in to comment.