Skip to content

Commit

Permalink
Update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Oct 31, 2024
1 parent c46e84f commit 7616c49
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 16 deletions.
8 changes: 4 additions & 4 deletions client/mm/exchange_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ func testFeeAssetTopUp(t *testing.T, baseID, quoteID uint32) {
fiatRates := map[uint32]float64{baseID: 1, quoteID: 1}
u.fiatRates.Store(fiatRates)

u.buyFees = &orderFees{
u.buyFees = &OrderFees{
LotFeeRange: &LotFeeRange{
Max: maxBuyFees,
Estimated: &LotFees{
Expand All @@ -1212,17 +1212,17 @@ func testFeeAssetTopUp(t *testing.T, baseID, quoteID uint32) {
Refund: buyRefundFees,
},
},
bookingFeesPerLot: buyBookingFees,
BookingFeesPerLot: buyBookingFees,
}
u.sellFees = &orderFees{
u.sellFees = &OrderFees{
LotFeeRange: &LotFeeRange{
Max: maxSellFees,
Estimated: &LotFees{
Swap: sellSwapFees,
Redeem: sellRedeemFees,
},
},
bookingFeesPerLot: sellBookingFees,
BookingFeesPerLot: sellBookingFees,
}

setFeeBal := func(base bool, amt int64) {
Expand Down
6 changes: 6 additions & 0 deletions client/webserver/locales/en-us.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,4 +678,10 @@ var EnUS = map[string]*intl.Translation{
"Priority": {T: "Priority"},
"Wallet Balances": {T: "Wallet Balances"},
"Placements": {T: "Placements"},
"Top up fee reserves": {T: "Top up fee reserves"},
"top_up_fee_reserves_tooltip": {T: "When enabled, if the bot's fee reserves run too low, it will be allocated additional available funds from the wallet to be able to cover all configured placements. This is only applicable when the fee asset is neither the base nor quote asset."},
"Allow external transfers": {T: "Allow external transfers"},
"external_transfers_tooltip": {T: "When enabled, the bot will be able to transfer funds between the DEX and the CEX."},
"Internal transfers only": {T: "Internal transfers only"},
"internal_only_tooltip": {T: "When enabled, the bot will be able to use any available funds in the wallet to simulate a transfer between the DEX and the CEX, (i.e. increase the bot's DEX balance and decrease the bot's CEX balance when a withdrawal needs to be made) but no actual transfers will be made."},
}
28 changes: 28 additions & 0 deletions client/webserver/site/src/html/mmsettings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@
<span class="ico-lever fs20 pe-2"></span>
<span class="fs22">Knobs</span>
</div>

{{- /* TOP UP FEE RESERVES */ -}}
<label id="topUpFeeReserveSettings" for="topUpFeeReservesCheckbox" class="fs16 d-flex align-items-center justify-content-between mt-2 pt-2 border-top">
<div class="flex-center">
<input type="checkbox" id="topUpFeeReservesCheckbox" class="form-check-input me-2 mt-0" checked>
<span>[[[Top up fee reserves]]]</span>
</div>
<span class="ico-info fs12" data-tooltip="[[[top_up_fee_reserves_tooltip]]]"></span>
</label>

{{- /* CEX REBALANCE CHECKBOX */ -}}
<label id="cexRebalanceSettings" for="cexRebalanceCheckbox" class="fs16 d-flex align-items-center justify-content-between mt-2 pt-2 border-top">
<div class="flex-center">
Expand All @@ -668,6 +678,24 @@
<span class="ico-info fs12" data-tooltip="[[[enable_rebalance_tooltip]]]"></span>
</label>

{{- /* ALLOW EXTERNAL TRANSFERS */ -}}
<label id="externalTransfersSettings" for="externalTransfersRadio" class="fs16 d-flex align-items-center justify-content-between mt-1 pt-1 ms-2">
<div class="flex-center">
<input type="radio" id="externalTransfersRadio" class="form-check-input me-2 mt-0">
<span>[[[Allow external transfers]]]</span>
</div>
<span class="ico-info fs12" data-tooltip="[[[external_transfers_tooltip]]]"></span>
</label>

{{- /* INTERNAL TRANSFERS ONLY */ -}}
<label id="internalOnlySettings" for="internalOnlyRadio" class="fs16 d-flex align-items-center justify-content-between mt-1 pt-1 ms-2">
<div class="flex-center">
<input type="radio" id="internalOnlyRadio" class="form-check-input me-2 mt-0" checked>
<span>[[[Internal transfers only]]]</span>
</div>
<span class="ico-info fs12" data-tooltip="[[[internal_only_tooltip]]]"></span>
</label>

{{- /* DRIFT TOLERANCE */ -}}
<div id="driftToleranceBox" class="flex-stretch-column">
<div class="d-flex align-items-center justify-content-between mt-2 pt-2 border-top">
Expand Down
30 changes: 24 additions & 6 deletions client/webserver/site/src/js/mm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
StartConfig,
OrderPlacement,
AutoRebalanceConfig,
CEXNotification,
EpochReportNote,
CEXProblemsNote
CEXProblemsNote,
UIConfig,
CEXNotification
} from './registry'
import {
MM,
Expand Down Expand Up @@ -752,7 +753,7 @@ class Bot extends BotMarket {
}

async start () {
const { page, alloc, baseID, quoteID, host, cexName, cfg: { uiConfig: { cexRebalance } } } = this
const { page, alloc, baseID, quoteID, host, cexName, cfg: { uiConfig } } = this

Doc.hide(page.errMsg)
if (cexName && !app().mmStatus.cexes[cexName]?.connected) {
Expand All @@ -772,7 +773,8 @@ class Bot extends BotMarket {
host: host,
alloc: alloc
}
if (cexName && cexRebalance) startConfig.autoRebalance = this.autoRebalanceSettings()

startConfig.autoRebalance = this.autoRebalanceSettings(uiConfig)

try {
app().log('mm', 'starting mm bot', startConfig)
Expand All @@ -786,7 +788,7 @@ class Bot extends BotMarket {
this.hideAllocationDialog()
}

autoRebalanceSettings (): AutoRebalanceConfig {
minTransferAmounts (): [number, number] {
const {
proj: { bProj, qProj, alloc }, baseFeeID, quoteFeeID, cfg: { uiConfig: { baseConfig, quoteConfig } },
baseID, quoteID, cexName, mktID
Expand All @@ -811,7 +813,23 @@ class Bot extends BotMarket {
const minBaseTransfer = Math.round(minB + baseConfig.transferFactor * (maxB - minB))
const [minQ, maxQ] = [mkt.quoteMinWithdraw, Math.max(mkt.quoteMinWithdraw * 2, maxQuote)]
const minQuoteTransfer = Math.round(minQ + quoteConfig.transferFactor * (maxQ - minQ))
return { minBaseTransfer, minQuoteTransfer }
return [minBaseTransfer, minQuoteTransfer]
}

autoRebalanceSettings (uiCfg: UIConfig) : AutoRebalanceConfig | undefined {
if (!uiCfg.cexRebalance && !uiCfg.internalTransfers && !uiCfg.topUpFeeReserves) return
const cfg : AutoRebalanceConfig = {
topUpFeeReserves: uiCfg.topUpFeeReserves,
internalTransfers: uiCfg.internalTransfers,
minBaseTransfer: 0,
minQuoteTransfer: 0
}
if (uiCfg.cexRebalance && this.cexName) {
const [minBaseTransfer, minQuoteTransfer] = this.minTransferAmounts()
cfg.minBaseTransfer = minBaseTransfer
cfg.minQuoteTransfer = minQuoteTransfer
}
return cfg
}

reconfigure () {
Expand Down
73 changes: 67 additions & 6 deletions client/webserver/site/src/js/mmsettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ interface ConfigState {
driftTolerance: number
orderPersistence: number // epochs
cexRebalance: boolean
internalTransfers: boolean
topUpFeeReserves: boolean
disabled: boolean
buyPlacements: OrderPlacement[]
sellPlacements: OrderPlacement[]
Expand Down Expand Up @@ -295,6 +297,9 @@ export default class MarketMakerSettingsPage extends BasePage {
Doc.bind(page.marketHeader, 'click', () => { this.showMarketSelectForm() })
Doc.bind(page.marketFilterInput, 'input', () => { this.sortMarketRows() })
Doc.bind(page.cexRebalanceCheckbox, 'change', () => { this.autoRebalanceChanged() })
Doc.bind(page.topUpFeeReserveSettings, 'change', () => { this.topUpFeeReserveChanged() })
Doc.bind(page.internalOnlyRadio, 'change', () => { this.internalOnlyChanged() })
Doc.bind(page.externalTransfersRadio, 'change', () => { this.externalTransfersChanged() })
Doc.bind(page.switchToAdvanced, 'click', () => { this.showAdvancedConfig() })
Doc.bind(page.switchToQuickConfig, 'click', () => { this.switchToQuickConfig() })
Doc.bind(page.qcMatchBuffer, 'change', () => { this.matchBufferChanged() })
Expand Down Expand Up @@ -594,7 +599,7 @@ export default class MarketMakerSettingsPage extends BasePage {
}) as ConfigState

if (botCfg) {
const { basicMarketMakingConfig: mmCfg, arbMarketMakingConfig: arbMMCfg, simpleArbConfig: arbCfg, uiConfig: { cexRebalance } } = botCfg
const { basicMarketMakingConfig: mmCfg, arbMarketMakingConfig: arbMMCfg, simpleArbConfig: arbCfg, uiConfig } = botCfg
this.creatingNewBot = false
// This is kinda sloppy, but we'll copy any relevant issues from the
// old config into the originalConfig.
Expand All @@ -605,7 +610,9 @@ export default class MarketMakerSettingsPage extends BasePage {
oldCfg.quoteConfig = Object.assign({}, defaultBotAssetConfig, botCfg.uiConfig.quoteConfig)
oldCfg.baseOptions = botCfg.baseWalletOptions || {}
oldCfg.quoteOptions = botCfg.quoteWalletOptions || {}
oldCfg.cexRebalance = cexRebalance
oldCfg.cexRebalance = uiConfig.cexRebalance
oldCfg.internalTransfers = uiConfig.internalTransfers
oldCfg.topUpFeeReserves = uiConfig.topUpFeeReserves

if (mmCfg) {
oldCfg.buyPlacements = mmCfg.buyPlacements
Expand Down Expand Up @@ -648,9 +655,15 @@ export default class MarketMakerSettingsPage extends BasePage {
setMarketElements(document.body, baseID, quoteID, host)
Doc.setVis(botType !== botTypeBasicArb, page.driftToleranceBox, page.switchToAdvanced)
Doc.setVis(Boolean(cexName), ...Doc.applySelector(document.body, '[data-cex-show]'))

Doc.setVis(viewOnly, page.viewOnlyRunning)

const baseFeeAssetID = baseToken?.parentID ?? baseID
const quoteFeeAssetID = quoteToken?.parentID ?? quoteID
let showFeeReserveTopUpSetting = baseFeeAssetID !== baseID && baseFeeAssetID !== quoteID
showFeeReserveTopUpSetting = showFeeReserveTopUpSetting || (quoteFeeAssetID !== baseID && quoteFeeAssetID !== quoteID)
Doc.setVis(showFeeReserveTopUpSetting, page.topUpFeeReserveSettings)
Doc.setVis(cexName, page.cexRebalanceSettings)

if (cexName) setCexElements(document.body, cexName)

await this.fetchMarketReport()
Expand Down Expand Up @@ -1168,12 +1181,55 @@ export default class MarketMakerSettingsPage extends BasePage {
}
}

internalOnlyChanged () {
const checked = Boolean(this.page.internalOnlyRadio.checked)
this.page.externalTransfersRadio.checked = !checked
this.updatedConfig.cexRebalance = !checked
this.updatedConfig.internalTransfers = checked
this.updateAllocations()
}

externalTransfersChanged () {
const checked = Boolean(this.page.externalTransfersRadio.checked)
this.page.internalOnlyRadio.checked = !checked
this.updatedConfig.cexRebalance = checked
this.updatedConfig.internalTransfers = !checked
this.updateAllocations()
}

autoRebalanceChanged () {
const { page, updatedConfig: cfg } = this
cfg.cexRebalance = page.cexRebalanceCheckbox?.checked ?? false
const checked = page.cexRebalanceCheckbox?.checked
Doc.setVis(checked, page.internalOnlySettings, page.externalTransfersSettings)
if (checked && !cfg.cexRebalance && !cfg.internalTransfers) {
// default to external transfers
cfg.cexRebalance = true
page.externalTransfersRadio.checked = true
page.internalOnlyRadio.checked = false
} else if (!checked) {
cfg.cexRebalance = false
cfg.internalTransfers = false
page.externalTransfersRadio.checked = false
page.internalOnlyRadio.checked = false
} else if (cfg.cexRebalance && cfg.internalTransfers) {
// should not happen.. set to default
cfg.internalTransfers = false
page.externalTransfersRadio.checked = true
page.internalOnlyRadio.checked = false
} else {
// set to current values. This case should only be called when the form
// is loaded.
page.externalTransfersRadio.checked = cfg.cexRebalance
page.internalOnlyRadio.checked = cfg.internalTransfers
}

this.updateAllocations()
}

topUpFeeReserveChanged () {
this.updatedConfig.topUpFeeReserves = Boolean(this.page.topUpFeeReservesCheckbox.checked)
}

async submitBotType () {
const loaded = app().loading(this.page.botTypeForm)
try {
Expand Down Expand Up @@ -1620,9 +1676,12 @@ export default class MarketMakerSettingsPage extends BasePage {
this.qcProfitSlider.setValue((profit - defaultProfit.minV) / defaultProfit.range)

if (cexName) {
page.cexRebalanceCheckbox.checked = cfg.cexRebalance
page.cexRebalanceCheckbox.checked = cfg.cexRebalance || cfg.internalTransfers
page.internalOnlyRadio.checked = cfg.internalTransfers
page.externalTransfersRadio.checked = cfg.cexRebalance
this.autoRebalanceChanged()
}
page.topUpFeeReservesCheckbox.checked = cfg.topUpFeeReserves

// Gap strategy
if (!page.gapStrategySelect.options) return
Expand Down Expand Up @@ -1701,7 +1760,9 @@ export default class MarketMakerSettingsPage extends BasePage {
simpleArbLots: cfg.simpleArbLots,
baseConfig: cfg.baseConfig,
quoteConfig: cfg.quoteConfig,
cexRebalance: cfg.cexRebalance
cexRebalance: cfg.cexRebalance,
internalTransfers: cfg.internalTransfers,
topUpFeeReserves: cfg.topUpFeeReserves
},
baseWalletOptions: cfg.baseOptions,
quoteWalletOptions: cfg.quoteOptions
Expand Down
4 changes: 4 additions & 0 deletions client/webserver/site/src/js/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ export interface OrderPlacement {
export interface AutoRebalanceConfig {
minBaseTransfer: number
minQuoteTransfer: number
internalTransfers: boolean
topUpFeeReserves: boolean
}

export interface BasicMarketMakingConfig {
Expand Down Expand Up @@ -809,6 +811,8 @@ export interface UIConfig {
quoteConfig: BotAssetConfig
simpleArbLots?: number
cexRebalance: boolean
internalTransfers: boolean
topUpFeeReserves: boolean
}

export interface StartConfig extends MarketWithHost {
Expand Down

0 comments on commit 7616c49

Please sign in to comment.