Skip to content

Commit f648310

Browse files
committed
fix: fix collatRatio and slippage values
1 parent 30f8737 commit f648310

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

packages/frontend/src/components/Lp/MintAndLp/LpSettings.tsx

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react'
1+
import React, { useState } from 'react'
22
import { Box, Typography, Divider, InputAdornment } from '@material-ui/core'
33
import { ToggleButtonGroup, ToggleButton } from '@material-ui/lab'
44
import { makeStyles, createStyles } from '@material-ui/core/styles'
@@ -10,6 +10,7 @@ import { AltPrimaryButton } from '@components/Button'
1010
import { useETHPrice } from '@hooks/useETHPrice'
1111
import { useTokenBalance } from '@hooks/contracts/useTokenBalance'
1212
import useAppCallback from '@hooks/useAppCallback'
13+
import useAppEffect from '@hooks/useAppEffect'
1314
import { addressesAtom } from '@state/positions/atoms'
1415
import { useGetWSqueethPositionValue } from '@state/squeethPool/hooks'
1516
import { useGetDepositAmounts, useGetTicksFromPriceRange, useOpenPositionDeposit } from '@state/lp/hooks'
@@ -143,9 +144,13 @@ const LpSettings: React.FC<{ onComplete: () => void; squeethToMint: string }> =
143144
const textClasses = useTextStyles()
144145

145146
const squeethPrice = getWSqueethPositionValue(1)
147+
const collatRatioVal = new bn(collatRatio).div(100).toNumber()
148+
const slippageAmountVal = new bn(slippageAmount).div(100).toNumber()
146149

147-
useEffect(() => {
150+
useAppEffect(() => {
148151
if (usingDefaultPriceRange) {
152+
setLowerTick(TickMath.MIN_TICK)
153+
setUpperTick(TickMath.MAX_TICK)
149154
return
150155
}
151156

@@ -164,32 +169,24 @@ const LpSettings: React.FC<{ onComplete: () => void; squeethToMint: string }> =
164169

165170
setLowerTick(ticks.lowerTick)
166171
setUpperTick(ticks.upperTick)
167-
}, [usingDefaultPriceRange, minPrice, maxPrice, ethPrice])
172+
}, [usingDefaultPriceRange, minPrice, maxPrice, ethPrice, getTicksFromPriceRange])
168173

169-
useEffect(() => {
170-
getDepositAmounts(new bn(squeethToMint), lowerTick, upperTick, 0, collatRatio, 0).then((deposits) => {
174+
useAppEffect(() => {
175+
getDepositAmounts(new bn(squeethToMint), lowerTick, upperTick, 0, collatRatioVal, 0).then((deposits) => {
171176
if (deposits) {
172177
setDepositAmounts(deposits)
173178
}
174179
})
175-
}, [squeethToMint, lowerTick, upperTick, collatRatio])
180+
}, [squeethToMint, lowerTick, upperTick, collatRatioVal, getDepositAmounts])
176181

177182
const openPosition = useAppCallback(async () => {
178183
try {
179-
await openLpPosition(
180-
new bn(squeethToMint),
181-
lowerTick,
182-
upperTick,
183-
0,
184-
collatRatio,
185-
slippageAmount.toNumber(),
186-
0,
187-
() => {
188-
console.log('successfull')
189-
onComplete()
190-
},
191-
)
184+
await openLpPosition(new bn(squeethToMint), lowerTick, upperTick, 0, collatRatioVal, slippageAmountVal, 0, () => {
185+
console.log('successfully deposited')
186+
onComplete()
187+
})
192188
} catch (e) {
189+
console.log('transaction failed')
193190
console.log(e)
194191
}
195192
}, [squeethToMint, lowerTick, upperTick, collatRatio, slippageAmount, openLpPosition])

0 commit comments

Comments
 (0)