@@ -21,7 +21,6 @@ import { PoolKey } from './entities/pool'
21
21
import { toAddress } from './utils/currencyMap'
22
22
import { MSG_SENDER } from './actionConstants'
23
23
import { V4PositionPlanner } from './utils'
24
- import JSBI from 'jsbi'
25
24
26
25
describe ( 'PositionManager' , ( ) => {
27
26
const currency0 = new Token ( 1 , '0x0000000000000000000000000000000000000001' , 18 , 't0' , 'currency0' )
@@ -158,10 +157,6 @@ describe('PositionManager', () => {
158
157
tickUpper : TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
159
158
liquidity : 5000000 ,
160
159
} )
161
-
162
- // These are the max amounts that the user can possibly add to the position
163
- const { amount0, amount1 } = position . mintAmounts
164
-
165
160
const { calldata, value } = V4PositionManager . addCallParameters ( position , {
166
161
recipient,
167
162
slippageTolerance,
@@ -170,18 +165,14 @@ describe('PositionManager', () => {
170
165
171
166
// Rebuild the calldata with the planner for the expected mint.
172
167
// Note that this test verifies that the applied logic in addCallParameters is correct but does not necessarily test the validity of the calldata itself.
173
- const {
174
- amount0 : adjustedAmount0 ,
175
- amount1 : adjustedAmount1 ,
176
- liquidity : liquidityMax ,
177
- } = position . maxAmountsAndLiquidityWithSlippage ( slippageTolerance )
168
+ const { amount0 : amount0Max , amount1 : amount1Max } = position . mintAmountsWithSlippage ( slippageTolerance )
178
169
planner . addAction ( Actions . MINT_POSITION , [
179
170
pool_0_1 . poolKey ,
180
171
- TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
181
172
TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
182
- toHex ( liquidityMax ) ,
183
- toHex ( amount0 ) ,
184
- toHex ( amount1 ) ,
173
+ 5000000 ,
174
+ toHex ( amount0Max ) ,
175
+ toHex ( amount1Max ) ,
185
176
recipient ,
186
177
EMPTY_BYTES ,
187
178
] )
@@ -190,11 +181,6 @@ describe('PositionManager', () => {
190
181
191
182
expect ( calldata ) . toEqual ( V4PositionManager . encodeModifyLiquidities ( planner . finalize ( ) , deadline ) )
192
183
expect ( value ) . toEqual ( '0x00' )
193
-
194
- // The adjusted amounts are less than or equal to the max amounts
195
- expect ( JSBI . lessThanOrEqual ( adjustedAmount0 , amount0 ) ) . toBe ( true )
196
- expect ( JSBI . lessThanOrEqual ( adjustedAmount1 , amount1 ) ) . toBe ( true )
197
- expect ( JSBI . equal ( adjustedAmount0 , amount0 ) || JSBI . equal ( adjustedAmount1 , amount1 ) ) . toBe ( true )
198
184
} )
199
185
200
186
it ( 'succeeds for increase' , ( ) => {
@@ -205,9 +191,6 @@ describe('PositionManager', () => {
205
191
liquidity : 666 ,
206
192
} )
207
193
208
- // These are the max amounts that the user can possibly add to the position
209
- const { amount0, amount1 } = position . mintAmounts
210
-
211
194
const { calldata, value } = V4PositionManager . addCallParameters ( position , {
212
195
tokenId,
213
196
slippageTolerance,
@@ -216,27 +199,18 @@ describe('PositionManager', () => {
216
199
217
200
// Rebuild the calldata with the planner for increase
218
201
const planner = new V4Planner ( )
219
- const {
220
- amount0 : adjustedAmount0 ,
221
- amount1 : adjustedAmount1 ,
222
- liquidity : liquidityMax ,
223
- } = position . maxAmountsAndLiquidityWithSlippage ( slippageTolerance )
202
+ const { amount0 : amount0Max , amount1 : amount1Max } = position . mintAmountsWithSlippage ( slippageTolerance )
224
203
planner . addAction ( Actions . INCREASE_LIQUIDITY , [
225
204
tokenId . toString ( ) ,
226
- toHex ( liquidityMax ) ,
227
- toHex ( amount0 ) ,
228
- toHex ( amount1 ) ,
205
+ 666 ,
206
+ toHex ( amount0Max ) ,
207
+ toHex ( amount1Max ) ,
229
208
EMPTY_BYTES ,
230
209
] )
231
210
// Expect there to be a settle pair call afterwards
232
211
planner . addAction ( Actions . SETTLE_PAIR , [ toAddress ( pool_0_1 . currency0 ) , toAddress ( pool_0_1 . currency1 ) ] )
233
212
expect ( calldata ) . toEqual ( V4PositionManager . encodeModifyLiquidities ( planner . finalize ( ) , deadline ) )
234
213
expect ( value ) . toEqual ( '0x00' )
235
-
236
- // The adjusted amounts are less than or equal to the max amounts
237
- expect ( JSBI . lessThanOrEqual ( adjustedAmount0 , amount0 ) ) . toBe ( true )
238
- expect ( JSBI . lessThanOrEqual ( adjustedAmount1 , amount1 ) ) . toBe ( true )
239
- expect ( JSBI . equal ( adjustedAmount0 , amount0 ) || JSBI . equal ( adjustedAmount1 , amount1 ) ) . toBe ( true )
240
214
} )
241
215
242
216
it ( 'succeeds when createPool is true' , ( ) => {
@@ -246,9 +220,6 @@ describe('PositionManager', () => {
246
220
tickUpper : TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
247
221
liquidity : 90000000000000 ,
248
222
} )
249
-
250
- // These are the max amounts that the user can possibly add to the position
251
- const { amount0, amount1 } = position . mintAmounts
252
223
const { calldata, value } = V4PositionManager . addCallParameters ( position , {
253
224
recipient,
254
225
slippageTolerance,
@@ -264,30 +235,21 @@ describe('PositionManager', () => {
264
235
V4PositionManager . INTERFACE . encodeFunctionData ( 'initializePool' , [ pool_0_1 . poolKey , SQRT_PRICE_1_1 . toString ( ) ] )
265
236
)
266
237
const planner = new V4Planner ( )
267
- const {
268
- amount0 : adjustedAmount0 ,
269
- amount1 : adjustedAmount1 ,
270
- liquidity : liquidityMax ,
271
- } = position . maxAmountsAndLiquidityWithSlippage ( slippageTolerance )
238
+ const { amount0 : amount0Max , amount1 : amount1Max } = position . mintAmountsWithSlippage ( slippageTolerance )
272
239
// Expect position to be minted correctly
273
240
planner . addAction ( Actions . MINT_POSITION , [
274
241
pool_0_1 . poolKey ,
275
242
- TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
276
243
TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
277
- toHex ( liquidityMax ) ,
278
- toHex ( amount0 ) ,
279
- toHex ( amount1 ) ,
244
+ 90000000000000 ,
245
+ toHex ( amount0Max ) ,
246
+ toHex ( amount1Max ) ,
280
247
recipient ,
281
248
EMPTY_BYTES ,
282
249
] )
283
250
planner . addAction ( Actions . SETTLE_PAIR , [ toAddress ( pool_0_1 . currency0 ) , toAddress ( pool_0_1 . currency1 ) ] )
284
251
expect ( calldataList [ 1 ] ) . toEqual ( V4PositionManager . encodeModifyLiquidities ( planner . finalize ( ) , deadline ) )
285
252
expect ( value ) . toEqual ( '0x00' )
286
-
287
- // The adjusted amounts are less than or equal to the max amounts
288
- expect ( JSBI . lessThanOrEqual ( adjustedAmount0 , amount0 ) ) . toBe ( true )
289
- expect ( JSBI . lessThanOrEqual ( adjustedAmount1 , amount1 ) ) . toBe ( true )
290
- expect ( JSBI . equal ( adjustedAmount0 , amount0 ) || JSBI . equal ( adjustedAmount1 , amount1 ) ) . toBe ( true )
291
253
} )
292
254
293
255
it ( 'succeeds when useNative is set' , ( ) => {
@@ -297,9 +259,6 @@ describe('PositionManager', () => {
297
259
tickUpper : TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
298
260
liquidity : 1 ,
299
261
} )
300
-
301
- // These are the max amounts that the user can possibly add to the position
302
- const { amount0, amount1 } = position . mintAmounts
303
262
const { calldata, value } = V4PositionManager . addCallParameters ( position , {
304
263
recipient,
305
264
slippageTolerance,
@@ -310,32 +269,24 @@ describe('PositionManager', () => {
310
269
// Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency.
311
270
312
271
const planner = new V4Planner ( )
313
- const {
314
- amount0 : adjustedAmount0 ,
315
- amount1 : adjustedAmount1 ,
316
- liquidity : liquidityMax ,
317
- } = position . maxAmountsAndLiquidityWithSlippage ( slippageTolerance )
272
+ const { amount0 : amount0Max , amount1 : amount1Max } = position . mintAmountsWithSlippage ( slippageTolerance )
318
273
// Expect position to be minted correctly
319
274
planner . addAction ( Actions . MINT_POSITION , [
320
275
pool_1_eth . poolKey ,
321
276
- TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
322
277
TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
323
- toHex ( liquidityMax ) ,
324
- toHex ( amount0 ) ,
325
- toHex ( amount1 ) ,
278
+ 1 ,
279
+ toHex ( amount0Max ) ,
280
+ toHex ( amount1Max ) ,
326
281
recipient ,
327
282
EMPTY_BYTES ,
328
283
] )
329
284
330
285
planner . addAction ( Actions . SETTLE_PAIR , [ toAddress ( pool_1_eth . currency0 ) , toAddress ( pool_1_eth . currency1 ) ] )
331
286
planner . addAction ( Actions . SWEEP , [ toAddress ( pool_1_eth . currency0 ) , MSG_SENDER ] )
332
287
expect ( calldata ) . toEqual ( V4PositionManager . encodeModifyLiquidities ( planner . finalize ( ) , deadline ) )
333
- expect ( value ) . toEqual ( toHex ( amount0 ) )
334
288
335
- // The adjusted amounts are less than or equal to the max amounts
336
- expect ( JSBI . lessThanOrEqual ( adjustedAmount0 , amount0 ) ) . toBe ( true )
337
- expect ( JSBI . lessThanOrEqual ( adjustedAmount1 , amount1 ) ) . toBe ( true )
338
- expect ( JSBI . equal ( adjustedAmount0 , amount0 ) || JSBI . equal ( adjustedAmount1 , amount1 ) ) . toBe ( true )
289
+ expect ( value ) . toEqual ( toHex ( amount0Max ) )
339
290
} )
340
291
341
292
it ( 'succeeds when migrate is true' , ( ) => {
@@ -345,9 +296,6 @@ describe('PositionManager', () => {
345
296
tickUpper : TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
346
297
liquidity : 1 ,
347
298
} )
348
-
349
- // These are the max amounts that the user can possibly add to the position
350
- const { amount0, amount1 } = position . mintAmounts
351
299
const { calldata, value } = V4PositionManager . addCallParameters ( position , {
352
300
recipient,
353
301
slippageTolerance,
@@ -357,19 +305,15 @@ describe('PositionManager', () => {
357
305
358
306
// Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency.
359
307
const planner = new V4Planner ( )
360
- const {
361
- amount0 : adjustedAmount0 ,
362
- amount1 : adjustedAmount1 ,
363
- liquidity : liquidityMax ,
364
- } = position . maxAmountsAndLiquidityWithSlippage ( slippageTolerance )
308
+ const { amount0 : amount0Max , amount1 : amount1Max } = position . mintAmountsWithSlippage ( slippageTolerance )
365
309
// Expect position to be minted correctly
366
310
planner . addAction ( Actions . MINT_POSITION , [
367
311
pool_0_1 . poolKey ,
368
312
- TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
369
313
TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
370
- toHex ( liquidityMax ) ,
371
- toHex ( amount0 ) ,
372
- toHex ( amount1 ) ,
314
+ 1 ,
315
+ toHex ( amount0Max ) ,
316
+ toHex ( amount1Max ) ,
373
317
recipient ,
374
318
EMPTY_BYTES ,
375
319
] )
@@ -381,11 +325,6 @@ describe('PositionManager', () => {
381
325
expect ( calldata ) . toEqual ( V4PositionManager . encodeModifyLiquidities ( planner . finalize ( ) , deadline ) )
382
326
383
327
expect ( value ) . toEqual ( '0x00' )
384
-
385
- // The adjusted amounts are less than or equal to the max amounts
386
- expect ( JSBI . lessThanOrEqual ( adjustedAmount0 , amount0 ) ) . toBe ( true )
387
- expect ( JSBI . lessThanOrEqual ( adjustedAmount1 , amount1 ) ) . toBe ( true )
388
- expect ( JSBI . equal ( adjustedAmount0 , amount0 ) || JSBI . equal ( adjustedAmount1 , amount1 ) ) . toBe ( true )
389
328
} )
390
329
391
330
it ( 'succeeds when migrating to an eth position' , ( ) => {
@@ -395,9 +334,6 @@ describe('PositionManager', () => {
395
334
tickUpper : TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
396
335
liquidity : 1 ,
397
336
} )
398
-
399
- // These are the max amounts that the user can possibly add to the position
400
- const { amount0, amount1 } = position . mintAmounts
401
337
const { calldata, value } = V4PositionManager . addCallParameters ( position , {
402
338
recipient,
403
339
slippageTolerance,
@@ -408,19 +344,15 @@ describe('PositionManager', () => {
408
344
409
345
// Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency.
410
346
const planner = new V4Planner ( )
411
- const {
412
- amount0 : adjustedAmount0 ,
413
- amount1 : adjustedAmount1 ,
414
- liquidity : liquidityMax ,
415
- } = position . maxAmountsAndLiquidityWithSlippage ( slippageTolerance )
347
+ const { amount0 : amount0Max , amount1 : amount1Max } = position . mintAmountsWithSlippage ( slippageTolerance )
416
348
// Expect position to be minted correctly
417
349
planner . addAction ( Actions . MINT_POSITION , [
418
350
pool_1_eth . poolKey ,
419
351
- TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
420
352
TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
421
- toHex ( liquidityMax ) ,
422
- toHex ( amount0 ) ,
423
- toHex ( amount1 ) ,
353
+ 1 ,
354
+ toHex ( amount0Max ) ,
355
+ toHex ( amount1Max ) ,
424
356
recipient ,
425
357
EMPTY_BYTES ,
426
358
] )
@@ -433,11 +365,6 @@ describe('PositionManager', () => {
433
365
expect ( calldata ) . toEqual ( V4PositionManager . encodeModifyLiquidities ( planner . finalize ( ) , deadline ) )
434
366
435
367
expect ( value ) . toEqual ( '0x00' )
436
-
437
- // The adjusted amounts are less than or equal to the max amounts
438
- expect ( JSBI . lessThanOrEqual ( adjustedAmount0 , amount0 ) ) . toBe ( true )
439
- expect ( JSBI . lessThanOrEqual ( adjustedAmount1 , amount1 ) ) . toBe ( true )
440
- expect ( JSBI . equal ( adjustedAmount0 , amount0 ) || JSBI . equal ( adjustedAmount1 , amount1 ) ) . toBe ( true )
441
368
} )
442
369
443
370
it ( 'succeeds for batchPermit' , ( ) => {
@@ -448,9 +375,6 @@ describe('PositionManager', () => {
448
375
liquidity : 1 ,
449
376
} )
450
377
451
- // These are the max amounts that the user can possibly add to the position
452
- const { amount0, amount1 } = position . mintAmounts
453
-
454
378
const batchPermit : BatchPermitOptions = {
455
379
owner : mockOwner ,
456
380
permitBatch : {
@@ -479,30 +403,21 @@ describe('PositionManager', () => {
479
403
)
480
404
481
405
const planner = new V4Planner ( )
482
- const {
483
- amount0 : adjustedAmount0 ,
484
- amount1 : adjustedAmount1 ,
485
- liquidity : liquidityMax ,
486
- } = position . maxAmountsAndLiquidityWithSlippage ( slippageTolerance )
406
+ const { amount0 : amount0Max , amount1 : amount1Max } = position . mintAmountsWithSlippage ( slippageTolerance )
487
407
488
408
planner . addAction ( Actions . MINT_POSITION , [
489
409
pool_0_1 . poolKey ,
490
410
- TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
491
411
TICK_SPACINGS [ FeeAmount . MEDIUM ] ,
492
- toHex ( liquidityMax ) ,
493
- toHex ( amount0 ) ,
494
- toHex ( amount1 ) ,
412
+ 1 ,
413
+ toHex ( amount0Max ) ,
414
+ toHex ( amount1Max ) ,
495
415
recipient ,
496
416
EMPTY_BYTES ,
497
417
] )
498
418
planner . addAction ( Actions . SETTLE_PAIR , [ toAddress ( pool_0_1 . currency0 ) , toAddress ( pool_0_1 . currency1 ) ] )
499
419
expect ( calldataList [ 1 ] ) . toEqual ( V4PositionManager . encodeModifyLiquidities ( planner . finalize ( ) , deadline ) )
500
420
expect ( value ) . toEqual ( '0x00' )
501
-
502
- // The adjusted amounts are less than or equal to the max amounts
503
- expect ( JSBI . lessThanOrEqual ( adjustedAmount0 , amount0 ) ) . toBe ( true )
504
- expect ( JSBI . lessThanOrEqual ( adjustedAmount1 , amount1 ) ) . toBe ( true )
505
- expect ( JSBI . equal ( adjustedAmount0 , amount0 ) || JSBI . equal ( adjustedAmount1 , amount1 ) ) . toBe ( true )
506
421
} )
507
422
} )
508
423
0 commit comments