From 1ae8a875074c6d4171e41e4d9b0fff5f2bfb59c2 Mon Sep 17 00:00:00 2001 From: Maxence Raballand Date: Mon, 16 Sep 2024 18:25:07 +0200 Subject: [PATCH] feat: kandel reverve balance --- .changeset/mighty-glasses-cover.md | 5 +++++ src/actions/kandel/view.ts | 21 +++++++++++++++++++++ src/builder/kandel/view.ts | 12 ++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 .changeset/mighty-glasses-cover.md diff --git a/.changeset/mighty-glasses-cover.md b/.changeset/mighty-glasses-cover.md new file mode 100644 index 0000000..8881899 --- /dev/null +++ b/.changeset/mighty-glasses-cover.md @@ -0,0 +1,5 @@ +--- +"@mangrovedao/mgv": patch +--- + +Added base and quote reserve to kandel view function diff --git a/src/actions/kandel/view.ts b/src/actions/kandel/view.ts index 77c9fe7..945856e 100644 --- a/src/actions/kandel/view.ts +++ b/src/actions/kandel/view.ts @@ -16,6 +16,7 @@ import { offeredVolumeParams, provisionOfParams, quoteParams, + reserveBalanceParams, tickSpacingParams, } from '../../builder/kandel/view.js' import { @@ -59,6 +60,8 @@ export type GetKandelStateResult = { pricePoints: number quoteAmount: bigint baseAmount: bigint + reserveBalanceQuote: bigint + reserveBalanceBase: bigint unlockedProvision: bigint totalProvision: bigint kandelStatus: KandelStatus @@ -77,6 +80,8 @@ type KandelInitCallResult = { } baseAmount: bigint quoteAmount: bigint + reserveBalanceQuote: bigint + reserveBalanceBase: bigint unlockedProvision: bigint // mid price from the book midPrice: number @@ -99,6 +104,8 @@ async function kandelInitCall( params, _quoteAmount, _baseAmount, + _reserveBalanceQuote, + _reserveBalanceBase, _base, _quote, _tickSpacing, @@ -140,6 +147,14 @@ async function kandelInitCall( address: kandel, ...offeredVolumeParams(BA.asks), }, + { + address: kandel, + ...reserveBalanceParams(BA.bids), + }, + { + address: kandel, + ...reserveBalanceParams(BA.asks), + }, { address: kandel, ...baseParams, @@ -187,6 +202,10 @@ async function kandelInitCall( const baseAmount = _baseAmount.status === 'success' ? _baseAmount.result : 0n const quoteAmount = _quoteAmount.status === 'success' ? _quoteAmount.result : 0n + const reserveBalanceQuote = + _reserveBalanceQuote.status === 'success' ? _reserveBalanceQuote.result : 0n + const reserveBalanceBase = + _reserveBalanceBase.status === 'success' ? _reserveBalanceBase.result : 0n const asks = bestAsk.status === 'success' @@ -231,6 +250,8 @@ async function kandelInitCall( : { gasprice: 0, gasreq: 0, stepSize: 0, pricePoints: 0 }, baseAmount: reversed ? quoteAmount : baseAmount, quoteAmount: reversed ? baseAmount : quoteAmount, + reserveBalanceQuote: reversed ? reserveBalanceBase : reserveBalanceQuote, + reserveBalanceBase: reversed ? reserveBalanceQuote : reserveBalanceBase, reversed, unlockedProvision: unlockedProvision.status === 'success' ? unlockedProvision.result : 0n, diff --git a/src/builder/kandel/view.ts b/src/builder/kandel/view.ts index 39349c8..e3dee26 100644 --- a/src/builder/kandel/view.ts +++ b/src/builder/kandel/view.ts @@ -12,6 +12,7 @@ export const viewKandelABI = parseAbi([ olKeyABIRaw, 'function baseQuoteTickOffset() public view returns (uint)', 'function params() public view returns (Params memory)', + 'function reserveBalance(uint8 ba) public view returns (uint balance)', 'function offeredVolume(uint8 ba) public view returns (uint volume)', 'function getOffer(uint8 ba, uint index) public view returns (uint offer)', 'function offerIdOfIndex(uint8 ba, uint index) public view returns (uint offerId)', @@ -69,6 +70,17 @@ function parseBA(ba: BA) { return ba === BA.bids ? 0 : 1 } +export function reserveBalanceParams(ba: BA) { + return { + abi: viewKandelABI, + functionName: 'reserveBalance', + args: [parseBA(ba)], + } satisfies Omit< + ContractFunctionParameters, + 'address' + > +} + export function offeredVolumeParams(ba: BA) { return { abi: viewKandelABI,