Skip to content

Commit

Permalink
send opposite budget to the result
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandSchtroumpf committed Dec 18, 2024
1 parent 2dbcce8 commit 398be1e
Showing 1 changed file with 50 additions and 23 deletions.
73 changes: 50 additions & 23 deletions src/pages/simulator/overlapping/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -64,37 +68,60 @@ export const SimulatorInputOverlappingPage = () => {
const submit = (e: FormEvent<HTMLFormElement>) => {
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 (
Expand Down

0 comments on commit 398be1e

Please sign in to comment.