Skip to content

Commit

Permalink
Additional allocation in starved state
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Jul 17, 2024
1 parent 41a9473 commit e97e7fa
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions client/webserver/site/src/js/mm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ interface FundingOutlook {
fundedAndNotBalanced: boolean
}

function parseFundingOptions (f: FundingOutlook): [number, number, FundingSlider | undefined] {
function parseFundingOptions (f: FundingOutlook, canRebalance: boolean): [number, number, FundingSlider | undefined] {
const { cex: { avail: cexAvail, req: cexReq }, dex: { avail: dexAvail, req: dexReq }, transferable } = f

let proposedDex = Math.min(dexAvail, dexReq)
let proposedCex = Math.min(cexAvail, cexReq)
let slider: FundingSlider | undefined
if (f.fundedAndNotBalanced) {

const assetFundedAndNotBalanced = !f.fundedAndBalanced && canRebalance && (dexReq + cexReq <= dexAvail + cexAvail)

if (assetFundedAndNotBalanced) {
// We have everything we need, but not where we need it, and we can
// deposit and withdraw.
if (dexAvail > dexReq) {
Expand Down Expand Up @@ -148,6 +151,9 @@ function parseFundingOptions (f: FundingOutlook): [number, number, FundingSlider
slider.dexRange = slider.right.dex - slider.left.dex
proposedDex = slider.left.dex + (slider.dexRange / 2)
proposedCex = slider.left.cex + (slider.cexRange / 2)
} else if (canRebalance) {
proposedDex = dexAvail
proposedCex = cexAvail
}
return [proposedDex, proposedCex, slider]
}
Expand Down Expand Up @@ -560,14 +566,16 @@ class Bot extends BotMarket {
*/
allocate () {
const f = this.fundingState()

const {
page, marketReport: { baseFiatRate, quoteFiatRate }, baseID, quoteID,
baseFeeID, quoteFeeID, baseFeeFiatRate, quoteFeeFiatRate, cexName,
baseFactor, quoteFactor, baseFeeFactor, quoteFeeFactor
baseFactor, quoteFactor, baseFeeFactor, quoteFeeFactor, cfg: { uiConfig: { cexRebalance } }
} = this

const [proposedDexBase, proposedCexBase, baseSlider] = parseFundingOptions(f.base)
const [proposedDexQuote, proposedCexQuote, quoteSlider] = parseFundingOptions(f.quote)
const canRebalance = Boolean(cexName && cexRebalance)
const [proposedDexBase, proposedCexBase, baseSlider] = parseFundingOptions(f.base, canRebalance)
const [proposedDexQuote, proposedCexQuote, quoteSlider] = parseFundingOptions(f.quote, canRebalance)

const alloc = this.alloc = {
dex: {
Expand Down

0 comments on commit e97e7fa

Please sign in to comment.