Skip to content

Commit

Permalink
Merge pull request #247 from gnoswap-labs/GSW-639-fix-out-of-range-li…
Browse files Browse the repository at this point in the history
…quidity-add-error

fix: [GSW-639] Fix out of range liquidity add error
  • Loading branch information
jinoosss authored Dec 12, 2023
2 parents c67219c + a0a3152 commit ea66ea8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
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

0 comments on commit ea66ea8

Please sign in to comment.