diff --git a/.changeset/tricky-horses-type.md b/.changeset/tricky-horses-type.md new file mode 100644 index 0000000..5e2f962 --- /dev/null +++ b/.changeset/tricky-horses-type.md @@ -0,0 +1,5 @@ +--- +"@mangrovedao/mgv": patch +--- + +Fixed values for populate diff --git a/biome.json b/biome.json index 8bfeb9e..3f38d0a 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", + "$schema": "https://biomejs.dev/schemas/1.7.2/schema.json", "files": { "ignore": [ "_cjs", diff --git a/src/actions/kandel/getKandelSteps.ts b/src/actions/kandel/getKandelSteps.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/actions/kandel/populate.test.ts b/src/actions/kandel/populate.test.ts new file mode 100644 index 0000000..c0a792f --- /dev/null +++ b/src/actions/kandel/populate.test.ts @@ -0,0 +1,72 @@ +import { parseEther, parseUnits } from 'viem' +import { describe, expect, inject, it } from 'vitest' +import { validateKandelParams } from '~mgv/index.js' +import { getClient } from '~test/src/client.js' +import { getBook } from '../book.js' +import { simulateBind, simulateDeployRouter } from '../smart-router.js' +import { simulatePopulate } from './populate.js' +import { simulateSow } from './sow.js' + +const { smartKandelSeeder } = inject('kandel') +const { wethUSDC } = inject('markets') +const actionParams = inject('mangrove') +const client = getClient() + +describe('populate', () => { + it('populates', async () => { + const { request: sowReq, result: kandel } = await simulateSow( + client, + wethUSDC, + smartKandelSeeder, + { + account: client.account.address, + }, + ) + const hash = await client.writeContract(sowReq) + await client.waitForTransactionReceipt({ hash }) + + const book = await getBook(client, actionParams, wethUSDC) + + const { params, isValid, minProvision } = validateKandelParams({ + minPrice: 2500, + midPrice: 3000, + maxPrice: 3500, + pricePoints: 5n, + market: wethUSDC, + baseAmount: parseEther('1'), + quoteAmount: parseUnits('3000', 18), + stepSize: 1n, + gasreq: 350_000n, + factor: 3, + asksLocalConfig: book.asksConfig, + bidsLocalConfig: book.bidsConfig, + marketConfig: book.marketConfig, + }) + + expect(isValid).toBe(true) + + const { request: deployRouterReq, router } = await simulateDeployRouter( + client, + actionParams, + { + user: client.account.address, + }, + ) + const routerTx = await client.writeContract(deployRouterReq) + await client.waitForTransactionReceipt({ hash: routerTx }) + + const { request: bindReq } = await simulateBind(client, router, { + target: kandel, + }) + const bindTx = await client.writeContract(bindReq) + await client.waitForTransactionReceipt({ hash: bindTx }) + + const { request } = await simulatePopulate(client, kandel, { + ...params, + account: client.account.address, + value: minProvision, + }) + const hash2 = await client.writeContract(request) + await client.waitForTransactionReceipt({ hash: hash2 }) + }) +}) diff --git a/src/actions/kandel/populate.ts b/src/actions/kandel/populate.ts index 5df7951..3d8129c 100644 --- a/src/actions/kandel/populate.ts +++ b/src/actions/kandel/populate.ts @@ -7,7 +7,7 @@ import { populateChunkFromOffsetParams, populateFromOffsetParams, } from '../../builder/kandel/populate.js' -import type { BuiltArgsWithValue } from '../../index.js' +import type { BuiltArgs } from '../../index.js' import type { SimulationParams } from '../../types/actions/simulation.js' import { getAction } from '../../utils/getAction.js' @@ -16,7 +16,7 @@ type SimulationPopulateParams = SimulationParams< 'populateFromOffset' > export type PopulateArgs = PopulateFromOffsetParams & - Omit + Omit export type PopulateResult = SimulateContractReturnType< typeof populateABI, @@ -45,7 +45,7 @@ type SimulationPopulateChunckParams = SimulationParams< > export type PopulateChunkArgs = PopulateChunkFromOffsetParams & - Omit + Omit export type PopulateChunkResult = SimulateContractReturnType< typeof populateABI, diff --git a/src/actions/kandel/sow.test.ts b/src/actions/kandel/sow.test.ts new file mode 100644 index 0000000..01e368c --- /dev/null +++ b/src/actions/kandel/sow.test.ts @@ -0,0 +1,23 @@ +import { isAddress } from 'viem' +import { describe, expect, inject, it } from 'vitest' +import { getClient } from '~test/src/client.js' +import { simulateSow } from './sow.js' + +const { smartKandelSeeder } = inject('kandel') +const { wethUSDC } = inject('markets') +const client = getClient() + +describe('sow', () => { + it('sows', async () => { + const { request, result } = await simulateSow( + client, + wethUSDC, + smartKandelSeeder, + {}, + ) + expect(isAddress(result)).toBe(true) + const tx = await client.writeContract(request) + const receipt = await client.waitForTransactionReceipt({ hash: tx }) + expect(receipt.status).toBe('success') + }) +}) diff --git a/src/lib/kandel/params.ts b/src/lib/kandel/params.ts index 4415ab4..a853e15 100644 --- a/src/lib/kandel/params.ts +++ b/src/lib/kandel/params.ts @@ -101,6 +101,8 @@ export function countBidsAndAsks(distribution: Distribution) { let nAsks = 0n for (let i = 0; i < distribution.asks.length; i++) { if (distribution.asks[i]!.gives !== 0n) nAsks++ + } + for (let i = 0; i < distribution.bids.length; i++) { if (distribution.bids[i]!.gives !== 0n) nBids++ } return { @@ -179,9 +181,12 @@ export function validateKandelParams( const minBaseAmount = minAsk * nAsks const minQuoteAmount = minBid * nBids + const minProvision = - ((gasreq + asksLocalConfig.offer_gasbase) * nAsks + - (gasreq + bidsLocalConfig.offer_gasbase) * nBids) * + ((gasreq + asksLocalConfig.offer_gasbase) * + BigInt(distribution.asks.length) + + (gasreq + bidsLocalConfig.offer_gasbase) * + BigInt(distribution.bids.length)) * marketConfig.gasprice * BigInt(1e6)