Skip to content

Commit

Permalink
Merge pull request #1614 from bancorprotocol/issue-#1613
Browse files Browse the repository at this point in the history
[Simulator] quick fix - send opposite budget to the result
  • Loading branch information
GrandSchtroumpf authored Dec 18, 2024
2 parents 918200e + 792b8d5 commit e040682
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 23 deletions.
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

0 comments on commit e040682

Please sign in to comment.