Skip to content

Commit

Permalink
feat: Fix kandel division by 0. (#76)
Browse files Browse the repository at this point in the history
* feat: Fix kandel division by 0.

* test: Fix variable name in validateKandelParams function
  • Loading branch information
maxencerb authored Jun 3, 2024
1 parent d2e5c72 commit ccf2f05
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-pants-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mangrovedao/mgv": patch
---

Fix kandel division by 0
27 changes: 26 additions & 1 deletion src/lib/kandel/params.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { describe, expect, inject, it } from 'vitest'
import { getBook } from '~mgv/actions/book.js'
import { getClient } from '~test/src/client.js'
import {
humanPriceToRawPrice,
rawPriceToHumanPrice,
} from '../human-readable.js'
import { priceFromTick, tickFromPrice } from '../tick.js'
import { getKandelPositionRawParams } from './params.js'
import { getKandelPositionRawParams, validateKandelParams } from './params.js'

const { wethUSDC } = inject('markets')
const params = inject('mangrove')

const client = getClient()

describe('kandel params', () => {
it('kandel position raw params', () => {
Expand Down Expand Up @@ -34,4 +39,24 @@ describe('kandel params', () => {
const endPrice = rawPriceToHumanPrice(priceFromTick(endTick), wethUSDC)
expect(endPrice).toApproximateEqual(3500)
})

it('validateKandelParams', async () => {
const book = await getBook(client, params, wethUSDC)

const _test = validateKandelParams({
minPrice: 3100,
midPrice: 3000,
maxPrice: 3500,
pricePoints: 10n,
market: wethUSDC,
baseAmount: 10n,
quoteAmount: 10n,
stepSize: 1n,
gasreq: 250_000n,
factor: 3,
asksLocalConfig: book.asksConfig,
bidsLocalConfig: book.bidsConfig,
marketConfig: book.marketConfig,
})
})
})
4 changes: 2 additions & 2 deletions src/lib/kandel/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export function validateKandelParams(

const { nBids, nAsks } = countBidsAndAsks(distribution)
// asks gives base and bids gives quote
const askGives = params.baseAmount / nAsks
const bidGives = params.quoteAmount / nBids
const askGives = nAsks > 0 ? params.baseAmount / nAsks : 0n
const bidGives = nBids > 0 ? params.quoteAmount / nBids : 0n

distribution = changeGives(distribution, bidGives, askGives)

Expand Down

0 comments on commit ccf2f05

Please sign in to comment.