diff --git a/src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx b/src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx index 62cb213c08..f8f41898e9 100644 --- a/src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx +++ b/src/front/shared/pages/Exchange/QuickSwap/univ3/MintPosition.tsx @@ -49,6 +49,7 @@ function MintPosition(props) { slippage, intl, owner, + } = props console.log('>>>> MIN POSITION', props) @@ -111,6 +112,54 @@ function MintPosition(props) { }, [token0Address, token1Address]) const [ activeFee, setActiveFee ] = useState(0) + + const [ poolInfo, setPoolInfo ] = useState(false) + const [ isPoolFetching, setIsPoolFetching ] = useState(false) + + useEffect(() => { + if (poolsByFee[activeFee]) { + // Fetching pool info + setIsPoolFetching(true) + console.log('>>> FETCHING POOL INFO') + actions.uniswap.getUserPoolLiquidityV3({ + owner, + baseCurrency, + chainId, + poolAddress: poolsByFee[activeFee], + }).then(({ pool }) => { + console.log('>>> POOL INFO', pool) + setPoolInfo(pool) + setIsPoolFetching(false) + }).catch((err) => { + console.log('>ERR getUserPoolLiquidityV3', err) + }) + } else { + setIsPoolFetching(false) + } + }, [ activeFee, poolsByFee ]) + + useEffect(() => { + console.log('>>> CHANGED POOL INFO OR SIDE') + if (poolInfo) { + const { + currentPrice, + currentPrice: { + buyOneOfToken0, + buyOneOfToken1, + }, + } = poolInfo + console.log('>>> POOL PRICE', currentPrice) + setStartPrice( + Number( + (viewSide == VIEW_SIDE.A_TO_B) + ? buyOneOfToken1 + : buyOneOfToken0 + ) + ) + } else { + setStartPrice(0) + } + }, [ poolInfo, viewSide ]) const isWrappedToken0 = actions.uniswap.isWrappedToken({ chainId, tokenAddress: token0Address }) const isWrappedToken1 = actions.uniswap.isWrappedToken({ chainId, tokenAddress: token1Address }) @@ -266,47 +315,49 @@ function MintPosition(props) { /* @to-do - need optimize code size */ const calcAmount = (amount, token) => { + console.log('>> CALC AMOUNT', viewSide, token, amount) if (viewSide == VIEW_SIDE.A_TO_B) { if (token == TOKEN._0) { - const _amount1 = actions.uniswap.addLiquidityV3CalcAmount({ - amountIn: amount, + const perTokenPrice = actions.uniswap.addLiquidityV3CalcAmount({ + amountIn: 1, price: startPrice, priceHigh: token0HighPrice, priceLow: token0LowerPrice, }).toNumber() + const _amount1 = new BigNumber(amount).dividedBy(perTokenPrice).toNumber() setAmount0(amount) setAmount1(_amount1) } if (token == TOKEN._1) { - const perTokenPrice = actions.uniswap.addLiquidityV3CalcAmount({ - amountIn: 1, + const _amount0 = actions.uniswap.addLiquidityV3CalcAmount({ + amountIn: amount, price: startPrice, priceHigh: token0HighPrice, priceLow: token0LowerPrice, }).toNumber() - const _amount0 = new BigNumber(amount).dividedBy(perTokenPrice).toNumber() + console.log('>>> _amount0', _amount0) setAmount0(_amount0) setAmount1(amount) } } else { if (token == TOKEN._1) { - const _amount0 = actions.uniswap.addLiquidityV3CalcAmount({ - amountIn: amount, + const perTokenPrice = actions.uniswap.addLiquidityV3CalcAmount({ + amountIn: 1, price: startPrice, priceHigh: token1HighPrice, priceLow: token1LowerPrice, }).toNumber() - setAmount1(amount) + const _amount0 = new BigNumber(amount).dividedBy(perTokenPrice).toNumber() setAmount0(_amount0) + setAmount1(amount) } if (token == TOKEN._0) { - const perTokenPrice = actions.uniswap.addLiquidityV3CalcAmount({ - amountIn: 1, + const _amount1 = actions.uniswap.addLiquidityV3CalcAmount({ + amountIn: amount, price: startPrice, priceHigh: token1HighPrice, priceLow: token1LowerPrice, }).toNumber() - const _amount1 = new BigNumber(amount).dividedBy(perTokenPrice).toNumber() setAmount1(_amount1) setAmount0(amount) } @@ -464,7 +515,7 @@ function MintPosition(props) { )} - {!poolsByFee[activeFee] && ( + {!poolsByFee[activeFee] ? (
+ ) : ( + + )} + /> )}

@@ -498,13 +565,13 @@ function MintPosition(props) {

{(viewSide == VIEW_SIDE.A_TO_B) ? ( <> - {!startPriceIsLower && renderDepositToken0()} - {!startPriceIsHigh && renderDepositToken1()} + {!startPriceIsLower && renderDepositToken1()} + {!startPriceIsHigh && renderDepositToken0()} ) : ( <> - {!startPriceIsLower && renderDepositToken1()} - {!startPriceIsHigh && renderDepositToken0()} + {!startPriceIsLower && renderDepositToken0()} + {!startPriceIsHigh && renderDepositToken1()} )}
diff --git a/src/front/shared/pages/Exchange/QuickSwap/univ3/ui/PriceInput.tsx b/src/front/shared/pages/Exchange/QuickSwap/univ3/ui/PriceInput.tsx index 51f0515966..6796cbd7b6 100644 --- a/src/front/shared/pages/Exchange/QuickSwap/univ3/ui/PriceInput.tsx +++ b/src/front/shared/pages/Exchange/QuickSwap/univ3/ui/PriceInput.tsx @@ -6,7 +6,7 @@ type PriceInputProps = { price: number label: any, disabled?: boolean - onChange: (amount:number) => void + onChange?: (amount:number) => void onBlur?: () => void tokenA: string, tokenB: string, diff --git a/src/front/shared/redux/actions/uniswap.ts b/src/front/shared/redux/actions/uniswap.ts index 775bd81fb4..12b560c832 100644 --- a/src/front/shared/redux/actions/uniswap.ts +++ b/src/front/shared/redux/actions/uniswap.ts @@ -476,19 +476,6 @@ const returnSwapMethod = (params) => { } } -const createPoolV3 = async (params) => { -} - -const addLiquidityPositionsV3 = async (params) => { -} -/* -const getSqrtRatioAtTick = (tick) => { - //const ret = new BigNumber(1.0001).exponentiatedBy(tick).multipliedBy( new BigNumber(2).exponentiatedBy(96) ) - //console.log(ret, ret.toString()) -// sqrt(1.0001^tick) * 2^96 -} -*/ - const getClosestLowTick = (tick, tickSpacing) => { return Math.floor(tick / tickSpacing) * tickSpacing; } @@ -535,7 +522,6 @@ const getTickAtSqrtRatio = (sqrtPriceX96) => { const tQ96 = new BigNumber(sqrtPriceX96).dividedBy(Q96).toNumber() console.log(tQ96) let tick = Math.floor(Math.log(tQ96**2)/Math.log(1.0001)) - console.log('>>> getTickAtSqrtRatio', tick) return tick } @@ -777,8 +763,6 @@ const getSqrtRatioAtTick = (tick) => { return result; } -window.getSqrtRatioAtTick = getSqrtRatioAtTick - const addLiquidityV3CalcAmount = (params) => { const { amountIn, @@ -861,9 +845,6 @@ const getTokenAmountsV3 = (params) => { sqrtRatioB, } } -window.getTokenAmountsV3 = getTokenAmountsV3 - -window.getUserPoolLiquidityV3 = getUserPoolLiquidityV3 const isWrappedToken = ({ chainId, tokenAddress }) => { const wrappedAddress = constants.ADDRESSES.WrapperCurrency[chainId]