From 398be1ea9fdbb60f71e1a5bda31902b68fa632d0 Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Wed, 18 Dec 2024 14:11:29 +0100 Subject: [PATCH] send opposite budget to the result --- src/pages/simulator/overlapping/index.tsx | 73 ++++++++++++++++------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/src/pages/simulator/overlapping/index.tsx b/src/pages/simulator/overlapping/index.tsx index 005cba102..e2fac2106 100644 --- a/src/pages/simulator/overlapping/index.tsx +++ b/src/pages/simulator/overlapping/index.tsx @@ -1,4 +1,8 @@ -import { calculateOverlappingPrices } from '@bancor/carbon-sdk/strategy-management'; +import { + calculateOverlappingBuyBudget, + calculateOverlappingPrices, + calculateOverlappingSellBudget, +} from '@bancor/carbon-sdk/strategy-management'; import { useNavigate } from '@tanstack/react-router'; import { Button } from 'components/common/button'; import { CreateOverlappingStrategy } from 'components/simulator/input/overlapping/CreateOverlappingStrategy'; @@ -64,37 +68,60 @@ export const SimulatorInputOverlappingPage = () => { const submit = (e: FormEvent) => { e.preventDefault(); if (isPending || isError || noBudget) return; + if (!state.baseToken || !state.quoteToken) return; const start = state.start ?? defaultStart(); const end = state.end ?? defaultEnd(); + const search = { + baseToken: state.baseToken.address, + quoteToken: state.quoteToken.address, + buyMin: roundSearchParam(state.buy.min), + buyMax: roundSearchParam(state.buy.max), + buyBudget: roundSearchParam(state.buy.budget), + buyMarginal: '', + buyIsRange: true, + sellMin: roundSearchParam(state.sell.min), + sellMax: roundSearchParam(state.sell.max), + sellBudget: roundSearchParam(state.sell.budget), + sellMarginal: '', + sellIsRange: true, + start: start.toString(), + end: end.toString(), + type: 'overlapping' as const, + spread: state.spread, + }; + + if (search.buyBudget) { + search.sellBudget = calculateOverlappingSellBudget( + state.baseToken.decimals, + state.quoteToken.decimals, + state.buy.min, + state.sell.max, + marketPrice!.toString(), + state.spread, + search.buyBudget + ); + } else { + search.buyBudget = calculateOverlappingBuyBudget( + state.baseToken.decimals, + state.quoteToken.decimals, + state.buy.min, + state.sell.max, + marketPrice!.toString(), + state.spread, + search.sellBudget + ); + } + const { buyPriceMarginal, sellPriceMarginal } = calculateOverlappingPrices( formatNumber(state.buy.min), formatNumber(state.sell.max), marketPrice!.toString(), state.spread ); - - navigate({ - to: '/simulate/result', - search: { - baseToken: state.baseToken?.address || '', - quoteToken: state.quoteToken?.address || '', - buyMin: roundSearchParam(state.buy.min), - buyMax: roundSearchParam(state.buy.max), - buyBudget: roundSearchParam(state.buy.budget), - buyMarginal: roundSearchParam(buyPriceMarginal), - buyIsRange: true, - sellMin: roundSearchParam(state.sell.min), - sellMax: roundSearchParam(state.sell.max), - sellBudget: roundSearchParam(state.sell.budget), - sellMarginal: roundSearchParam(sellPriceMarginal), - sellIsRange: true, - start: start.toString(), - end: end.toString(), - type: 'overlapping', - spread: state.spread, - }, - }); + search.buyMarginal = buyPriceMarginal; + search.sellMarginal = sellPriceMarginal; + navigate({ to: '/simulate/result', search }); }; return (