@@ -3,7 +3,7 @@ import { Box, Typography, Divider, InputAdornment } from '@material-ui/core'
3
3
import { ToggleButtonGroup , ToggleButton } from '@material-ui/lab'
4
4
import { makeStyles , createStyles } from '@material-ui/core/styles'
5
5
import { useAtomValue } from 'jotai'
6
- import bn from 'bignumber.js'
6
+ import BigNumber from 'bignumber.js'
7
7
import { TickMath } from '@uniswap/v3-sdk'
8
8
9
9
import { AltPrimaryButton } from '@components/Button'
@@ -144,8 +144,8 @@ const LpSettings: React.FC<{ onComplete: () => void; squeethToMint: string }> =
144
144
const textClasses = useTextStyles ( )
145
145
146
146
const squeethPrice = getWSqueethPositionValue ( 1 )
147
- const collatRatioVal = new bn ( collatRatio ) . div ( 100 ) . toNumber ( )
148
- const slippageAmountVal = new bn ( slippageAmount ) . div ( 100 ) . toNumber ( )
147
+ const collatRatioVal = new BigNumber ( collatRatio ) . div ( 100 ) . toNumber ( )
148
+ const slippageAmountVal = new BigNumber ( slippageAmount ) . div ( 100 ) . toNumber ( )
149
149
150
150
useAppEffect ( ( ) => {
151
151
if ( usingDefaultPriceRange ) {
@@ -154,42 +154,42 @@ const LpSettings: React.FC<{ onComplete: () => void; squeethToMint: string }> =
154
154
return
155
155
}
156
156
157
- const minPriceBN = new bn ( minPrice )
158
- const maxPriceBN = new bn ( maxPrice )
159
- if ( minPriceBN . isLessThanOrEqualTo ( 0 ) || maxPriceBN . isLessThanOrEqualTo ( 0 ) ) {
160
- return
161
- }
162
-
163
- // still not sure about this
164
- // but basically the thought is that lowerPrice is derived from maxPrice since that's in denominator
165
- const lowerPrice = ethPrice . div ( maxPrice ) . integerValue ( bn . ROUND_FLOOR ) . toNumber ( )
166
- const upperPrice = ethPrice . div ( minPrice ) . integerValue ( bn . ROUND_FLOOR ) . toNumber ( )
167
-
168
- const ticks = getTicksFromPriceRange ( lowerPrice , upperPrice )
169
-
157
+ const ticks = getTicksFromPriceRange ( minPrice , maxPrice )
170
158
setLowerTick ( ticks . lowerTick )
171
159
setUpperTick ( ticks . upperTick )
172
160
} , [ usingDefaultPriceRange , minPrice , maxPrice , ethPrice , getTicksFromPriceRange ] )
173
161
174
162
useAppEffect ( ( ) => {
175
- getDepositAmounts ( new bn ( squeethToMint ) , lowerTick , upperTick , 0 , collatRatioVal , 0 ) . then ( ( deposits ) => {
163
+ async function calcDepositAmounts ( ) {
164
+ const deposits = await getDepositAmounts ( new BigNumber ( squeethToMint ) , lowerTick , upperTick , 0 , collatRatioVal , 0 )
176
165
if ( deposits ) {
177
166
setDepositAmounts ( deposits )
178
167
}
179
- } )
168
+ }
169
+
170
+ calcDepositAmounts ( )
180
171
} , [ squeethToMint , lowerTick , upperTick , collatRatioVal , getDepositAmounts ] )
181
172
182
173
const openPosition = useAppCallback ( async ( ) => {
183
174
try {
184
- await openLpPosition ( new bn ( squeethToMint ) , lowerTick , upperTick , 0 , collatRatioVal , slippageAmountVal , 0 , ( ) => {
185
- console . log ( 'successfully deposited' )
186
- onComplete ( )
187
- } )
175
+ await openLpPosition (
176
+ new BigNumber ( squeethToMint ) ,
177
+ lowerTick ,
178
+ upperTick ,
179
+ 0 ,
180
+ collatRatioVal ,
181
+ slippageAmountVal ,
182
+ 0 ,
183
+ ( ) => {
184
+ console . log ( 'successfully deposited' )
185
+ onComplete ( )
186
+ } ,
187
+ )
188
188
} catch ( e ) {
189
189
console . log ( 'transaction failed' )
190
190
console . log ( e )
191
191
}
192
- } , [ squeethToMint , lowerTick , upperTick , collatRatio , slippageAmount , openLpPosition ] )
192
+ } , [ squeethToMint , lowerTick , upperTick , collatRatioVal , slippageAmountVal , openLpPosition , onComplete ] )
193
193
194
194
return (
195
195
< >
0 commit comments