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

fix: [GSW-639] Fix out of range liquidity add error #247

Merged
merged 1 commit into from
Dec 12, 2023
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
20 changes: 13 additions & 7 deletions packages/web/src/components/common/pool-graph/PoolGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,15 @@ const PoolGraph: React.FC<PoolGraphProps> = ({
setPositionY(null);
return;
}
const minTick = bin.minTick + defaultMinX;
const maxTick = bin.maxTick + defaultMinX;
const tokenARange = {
min: tickOfPrices[bin.minTick] || null,
max: tickOfPrices[bin.maxTick] || null,
min: tickOfPrices[minTick] || null,
max: tickOfPrices[maxTick] || null,
};
const tokenBRange = {
min: tickOfPrices[-bin.maxTick] || null,
max: tickOfPrices[-bin.minTick] || null,
min: tickOfPrices[-minTick] || null,
max: tickOfPrices[-maxTick] || null,
};
const tokenAAmountStr = makeDisplayTokenAmount(tokenA, bin.reserveTokenA);
const tokenBAmountStr = makeDisplayTokenAmount(tokenA, bin.reserveTokenA);
Expand Down Expand Up @@ -243,9 +245,13 @@ const PoolGraph: React.FC<PoolGraphProps> = ({
}

useEffect(() => {
if (resolvedBins.length > 0) {
if (bins.length > 0) {
new Promise<{ [key in number]: string }>(resolve => {
const tickOfPrices = resolvedBins.flatMap(bin => [bin.minTick, bin.maxTick, -bin.minTick, -bin.maxTick])
const tickOfPrices = bins.flatMap(bin => {
const minTick = bin.minTick;
const maxTick = bin.maxTick;
return [minTick, maxTick, -minTick, -maxTick];
})
.reduce<{ [key in number]: string }>((acc, current) => {
if (!acc[current]) {
acc[current] = tickToPriceStr(current).toString();
Expand All @@ -255,7 +261,7 @@ const PoolGraph: React.FC<PoolGraphProps> = ({
resolve(tickOfPrices);
}).then(setTickOfPrices);
}
}, [resolvedBins]);
}, [bins]);

useEffect(() => {
const svgElement = d3.select(svgRef.current)
Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/hooks/pool/use-select-pool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ export const useSelectPool = ({
const maxPriceGap = maxPrice - currentPrice;

if (maxPriceGap < 0) {
return 100;
return 0;
}
if (minPriceGap < 0) {
return 0;
return 100;
}

const logMin = minPrice <= 0 ?
Math.log(currentPrice / Number(0.0000000001)) :
Math.log(currentPrice / minPrice);
const logMax = Math.log(maxPrice / currentPrice);
return logMin * 100 / (logMin + logMax);
return logMax * 100 / (logMin + logMax);
}, [maxPrice, minPrice, price, fullRange, startPrice, isCreate]);

const feeBoost = useMemo(() => {
Expand Down