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: super narrow option #1052

Merged
merged 1 commit into from
Nov 27, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@oraichain/common-contracts-build": "1.0.35",
"@oraichain/cw-simulate": "^2.8.75",
"@oraichain/oraidex-contracts-build": "1.0.22",
"@oraichain/oraiswap-v3": "1.1.1",
"@oraichain/oraiswap-v3": "^1.1.2",
"@sentry/webpack-plugin": "^2.10.3",
"@testing-library/jest-dom": "^6.5.0",
"@types/classnames": "^2.2.10",
Expand Down
3 changes: 3 additions & 0 deletions src/pages/Pool-V3/components/CreatePositionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const CreatePositionForm: FC<CreatePositionFormProps> = ({ poolId, slippage, sho
cache7Day,
setIsFullRange,
setApr,
setIsSuperNarrow,
setZapApr,
setTokenZap,
setZapAmount,
Expand Down Expand Up @@ -363,12 +364,14 @@ const CreatePositionForm: FC<CreatePositionFormProps> = ({ poolId, slippage, sho
setMaxPrice(value);
if (optionType === OptionType.FULL_RANGE) {
setIsFullRange(false);
setIsSuperNarrow(false);
}
}}
setMinPrice={(value: number) => {
setMinPrice(value);
if (optionType === OptionType.FULL_RANGE) {
setIsFullRange(false);
setIsSuperNarrow(false);
}
}}
zoomIn={zoomIn}
Expand Down
31 changes: 12 additions & 19 deletions src/pages/Pool-V3/hooks/useCreatePositionForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const useCreatePositionForm = (
const [higherTick, setHigherTick] = useState<number>(0);
const [optionType, setOptionType] = useState<OptionType>(OptionType.CUSTOM);
const [isFullRange, setIsFullRange] = useState<boolean>(false);
const [isSuperNarrow, setIsSuperNarrow] = useState<boolean>(false);

const poolId = usePoolDetailV3Reducer('poolId');
const poolKey = usePoolDetailV3Reducer('poolKey');
Expand Down Expand Up @@ -312,13 +313,13 @@ const useCreatePositionForm = (
const higherTick = Math.max(
Number(getMinTick(Number(poolKey.fee_tier.tick_spacing))),
Number(pool.current_tick_index) +
Number(poolKey.fee_tier.tick_spacing) * TICK_SPACING_TO_RANGE[poolKey.fee_tier.tick_spacing]
Number(poolKey.fee_tier.tick_spacing) * TICK_SPACING_TO_RANGE[poolKey.fee_tier.tick_spacing]
);

const lowerTick = Math.min(
Number(getMaxTick(Number(poolKey.fee_tier.tick_spacing))),
Number(pool.current_tick_index) -
Number(poolKey.fee_tier.tick_spacing) * TICK_SPACING_TO_RANGE[poolKey.fee_tier.tick_spacing]
Number(poolKey.fee_tier.tick_spacing) * TICK_SPACING_TO_RANGE[poolKey.fee_tier.tick_spacing]
);

const minPrice = calcPrice(lowerTick, isXToY, tokenX.decimals, tokenY.decimals);
Expand All @@ -340,6 +341,7 @@ const useCreatePositionForm = (
// wide: take the price range of prices in 3m
const handleOptionWide = () => {
setIsFullRange(false);
setIsSuperNarrow(false);
changeHistoricalRange('3mo');
const data = cache3Month?.map(({ time, close }) => ({
time,
Expand Down Expand Up @@ -367,6 +369,7 @@ const useCreatePositionForm = (
const handleOptionNarrow = () => {
setIsFullRange(false);
changeHistoricalRange('7d');
setIsSuperNarrow(true);
// const data = cache7Day?.map(({ time, close }) => ({
// time,
// price: close
Expand All @@ -390,24 +393,12 @@ const useCreatePositionForm = (

setLowerTick(Number(pool.current_tick_index));
setHigherTick(Number(pool.current_tick_index) + Number(poolKey.fee_tier.tick_spacing));
const minPrice = calcPrice(
pool.current_tick_index,
isXToY,
tokenX.decimals,
tokenY.decimals
);
const maxPrice = calcPrice(
pool.current_tick_index + poolKey.fee_tier.tick_spacing,
isXToY,
tokenX.decimals,
tokenY.decimals
);
if (isXToY) {
setMinPrice(minPrice);
setMaxPrice(maxPrice);
setMinPrice(currentPrice);
setMaxPrice(currentPrice);
} else {
setMinPrice(maxPrice);
setMaxPrice(minPrice);
setMinPrice(currentPrice);
setMaxPrice(currentPrice);
}
};

Expand All @@ -427,6 +418,7 @@ const useCreatePositionForm = (

const getCorrespondingTickRange = (priceMin: number, priceMax: number) => {
try {
if (isSuperNarrow) return;
if (isFullRange) {
setLowerTick(getMinTick(Number(poolKey.fee_tier.tick_spacing)));
setHigherTick(getMaxTick(Number(poolKey.fee_tier.tick_spacing)));
Expand Down Expand Up @@ -462,7 +454,7 @@ const useCreatePositionForm = (
return;
}
}

setLowerTick(Math.min(lowerTick, higherTick));
setHigherTick(Math.max(lowerTick, higherTick));
} catch (error) {
Expand Down Expand Up @@ -530,6 +522,7 @@ const useCreatePositionForm = (
zapUsd,
zapApr,
setIsFullRange,
setIsSuperNarrow,
setApr,
setZapApr,
handleOptionCustom,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3397,10 +3397,10 @@
tronweb "5.3.2"
ts-protoc-gen "^0.15.0"

"@oraichain/[email protected].1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@oraichain/oraiswap-v3/-/oraiswap-v3-1.1.1.tgz#868c7e942227b26a26e6bd27065e27cba87af989"
integrity sha512-MZPVpIe6KU2EuwVJsyFpZocoAaZ3BwML+xEaDdR1hOiLZIjhOp0U/gIiDhHM5xwkaI9oXXHAQLHLezqyzF3AxQ==
"@oraichain/oraiswap-v3@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@oraichain/oraiswap-v3/-/oraiswap-v3-1.1.2.tgz#60edd01ef9afae5c1b1ee32425305375ad635039"
integrity sha512-1WCbsDpDoKkuzRo6f8C0PUFPzG80s6LOvsYT47FdYFt+GIe6F10ARDgR26v4J4BddPoguLpLtb2d2T83Rz18/Q==
dependencies:
"@cosmjs/cosmwasm-stargate" "^0.32.4"
"@oraichain/oraidex-common" "^1.1.32"
Expand Down