@@ -136,80 +136,8 @@ export const useOpenPositionDeposit = () => {
136
136
return openPositionDeposit
137
137
}
138
138
139
- /*** ACTIONS ***/
140
-
141
- // Opening a mint and LP position and depositing
142
- export const useOpenPositionDeposit = ( ) => {
143
- const { squeethPool } = useAtomValue ( addressesAtom )
144
- const address = useAtomValue ( addressAtom )
145
- const contract = useAtomValue ( controllerHelperHelperContractAtom )
146
- const handleTransaction = useHandleTransaction ( )
147
- const getDebtAmount = useGetDebtAmount ( )
148
- const squeethPoolContract = useAtomValue ( squeethPoolContractAtom )
149
- const isWethToken0 = useAtomValue ( isWethToken0Atom )
150
- const openPositionDeposit = useAppCallback (
151
- async ( squeethToMint : BigNumber , lowerTickInput : number , upperTickInput : number , vaultId : number , collatRatio : number , slippage : number , withdrawAmount : number , onTxConfirmed ?: ( ) => void ) => {
152
- if ( ! contract || ! address || ! squeethPoolContract ) return null
153
-
154
- const mintWSqueethAmount = fromTokenAmount ( squeethToMint , OSQUEETH_DECIMALS )
155
- const ethDebtPromise = getDebtAmount ( mintWSqueethAmount )
156
- const poolStatePromise = getPoolState ( squeethPoolContract )
157
-
158
- // Calculate prices from ticks
159
- const [ ethDebt , { tick, tickSpacing } ] = await Promise . all ( [ ethDebtPromise , poolStatePromise ] )
160
- const lowerTick = nearestUsableTick ( lowerTickInput , Number ( tickSpacing ) )
161
- const upperTick = nearestUsableTick ( upperTickInput , Number ( tickSpacing ) )
162
- const sqrtLowerPrice = new BigNumber ( TickMath . getSqrtRatioAtTick ( lowerTick ) . toString ( ) ) . div ( x96 )
163
- const sqrtUpperPrice = new BigNumber ( TickMath . getSqrtRatioAtTick ( upperTick ) . toString ( ) ) . div ( x96 )
164
- const squeethPrice = isWethToken0 ? new BigNumber ( 1 ) . div ( new BigNumber ( TickMath . getSqrtRatioAtTick ( Number ( tick ) ) . toString ( ) ) . div ( x96 ) . pow ( 2 ) )
165
- : new BigNumber ( TickMath . getSqrtRatioAtTick ( Number ( tick ) ) . toString ( ) ) . div ( x96 ) . pow ( 2 )
166
- const sqrtSqueethPrice = squeethPrice . sqrt ( )
167
- const collateralToMint = ethDebt . multipliedBy ( collatRatio )
168
-
169
- // Lx = x * (sqrtSqueethPrice * sqrtUpperPrice) / (sqrtUpperPrice - sqrtSqueethPrice)
170
- // y = Lx * (sqrtSqueethPrice - sqrtLowerPrice)
171
- const liquidity = mintWSqueethAmount . times ( sqrtSqueethPrice . times ( sqrtUpperPrice ) ) . div ( sqrtUpperPrice . minus ( sqrtSqueethPrice ) )
172
- const collateralToLp = sqrtUpperPrice . lt ( sqrtSqueethPrice ) ? liquidity . times ( sqrtUpperPrice . minus ( sqrtLowerPrice ) )
173
- : sqrtSqueethPrice . lt ( sqrtLowerPrice ) ? new BigNumber ( 0 )
174
- : liquidity . times ( sqrtSqueethPrice . minus ( sqrtLowerPrice ) )
175
-
176
- const amount0 = isWethToken0 ? collateralToLp : mintWSqueethAmount
177
- const amount1 = isWethToken0 ? mintWSqueethAmount : collateralToLp
178
- const amount0Min = amount0 . times ( new BigNumber ( 1 ) . minus ( slippage ) ) . toFixed ( 0 )
179
- const amount1Min = amount1 . times ( new BigNumber ( 1 ) . minus ( slippage ) ) . toFixed ( 0 )
180
-
181
- const collateralToWithdraw = new BigNumber ( withdrawAmount )
182
-
183
- const flashloanWMintDepositNftParams = {
184
- wPowerPerpPool : squeethPool ,
185
- vaultId : vaultId ,
186
- wPowerPerpAmount : mintWSqueethAmount . toFixed ( 0 ) ,
187
- collateralToDeposit : collateralToMint . toFixed ( 0 ) ,
188
- collateralToFlashloan : collateralToMint . toFixed ( 0 ) ,
189
- collateralToLp : collateralToLp . toFixed ( 0 ) ,
190
- collateralToWithdraw : collateralToWithdraw . toFixed ( 0 ) ,
191
- amount0Min,
192
- amount1Min,
193
- lowerTick : lowerTick ,
194
- upperTick : upperTick ,
195
- }
196
-
197
- return handleTransaction (
198
- contract . methods . flashloanWMintLpDepositNft ( flashloanWMintDepositNftParams ) . send ( {
199
- from : address ,
200
- value : collateralToLp . plus ( collateralToMint ) . minus ( collateralToWithdraw ) . toFixed ( 0 ) ,
201
- } ) ,
202
- onTxConfirmed ,
203
- )
204
- } ,
205
- [ address , squeethPool , contract , handleTransaction , getDebtAmount , squeethPoolContract , isWethToken0 ] ,
206
- )
207
-
208
- return openPositionDeposit
209
- }
210
-
211
139
// Close position with flashloan
212
- export const useClosePosition = ( ) => {
140
+ export const useFlashClosePosition = ( ) => {
213
141
const address = useAtomValue ( addressAtom )
214
142
const controllerHelperContract = useAtomValue ( controllerHelperHelperContractAtom )
215
143
const controllerContract = useAtomValue ( controllerContractAtom )
0 commit comments