Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Simulator] quick fix - send opposite budget to the result #1614

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/screenshots/strategy/overlapping/Overlapping/create/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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