From ce3bb3c508a9b2e3b6760f12971269cdc77ee6b0 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 28 Jan 2025 13:45:32 -0500 Subject: [PATCH 01/12] additional options when migrating --- sdks/v4-sdk/src/PositionManager.ts | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index 003468a70..031960547 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -59,11 +59,6 @@ export interface MintSpecificOptions { * Initial price to set on the pool if creating */ sqrtPriceX96?: BigintIsh - - /** - * Whether the mint is part of a migration from V3 to V4. - */ - migrate?: boolean } /** @@ -130,6 +125,22 @@ export interface TransferOptions { tokenId: BigintIsh } +export interface MigrateSpecificOptions { + /** + * Whether the mint is part of a migration from V3 to V4. + */ + migrate: boolean; + /** + * Whether the migrate needs additional transfer or not + */ + additionalTransfer?: AdditionalTransferDetails; +} + +export interface AdditionalTransferDetails { + neededCurrency: Currency; + neededAmount: BigintIsh; +} + export interface PermitDetails { token: string amount: BigintIsh @@ -182,9 +193,10 @@ export interface NFTPermitData { } export type MintOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions +export type MigrateOptions = MintOptions & MigrateSpecificOptions; export type IncreaseLiquidityOptions = CommonOptions & CommonAddLiquidityOptions & ModifyPositionSpecificOptions -export type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions +export type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions | MigrateOptions export type RemoveLiquidityOptions = CommonOptions & RemoveLiquiditySpecificOptions & ModifyPositionSpecificOptions @@ -195,6 +207,10 @@ function isMint(options: AddLiquidityOptions): options is MintOptions { return Object.keys(options).some((k) => k === 'recipient') } +function isMigrate(options: AddLiquidityOptions): options is MigrateOptions { + return Object.keys(options).some((k) => k === 'migrate') +} + function shouldCreatePool(options: MintOptions): boolean { if (options.createPool) { invariant(options.sqrtPriceX96 !== undefined, NO_SQRT_PRICE) @@ -275,7 +291,7 @@ export abstract class V4PositionManager { } // If migrating, we need to settle and sweep both currencies individually - if (isMint(options) && options.migrate) { + if (isMigrate(options) && options.migrate) { // payer is v4 positiion manager planner.addSettle(position.pool.currency0, false) planner.addSettle(position.pool.currency1, false) From ad629814b6be3aaafbe5eb1ac1a087f08c88f674 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 28 Jan 2025 13:58:27 -0500 Subject: [PATCH 02/12] lint --- sdks/v4-sdk/src/PositionManager.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index 031960547..d575f1023 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -129,16 +129,17 @@ export interface MigrateSpecificOptions { /** * Whether the mint is part of a migration from V3 to V4. */ - migrate: boolean; - /** - * Whether the migrate needs additional transfer or not - */ - additionalTransfer?: AdditionalTransferDetails; + migrate: boolean + + /** + * Whether the migrate needs additional transfer or not + */ + additionalTransfer?: AdditionalTransferDetails } export interface AdditionalTransferDetails { - neededCurrency: Currency; - neededAmount: BigintIsh; + neededCurrency: Currency + neededAmount: BigintIsh } export interface PermitDetails { @@ -193,7 +194,7 @@ export interface NFTPermitData { } export type MintOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions -export type MigrateOptions = MintOptions & MigrateSpecificOptions; +export type MigrateOptions = MintOptions & MigrateSpecificOptions export type IncreaseLiquidityOptions = CommonOptions & CommonAddLiquidityOptions & ModifyPositionSpecificOptions export type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions | MigrateOptions From 81c86a10ce84b5df3a82f530d58d97cb3c69854c Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Thu, 30 Jan 2025 20:51:57 -0500 Subject: [PATCH 03/12] re-structure --- sdks/v4-sdk/src/PositionManager.ts | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index d575f1023..c6474d966 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -59,6 +59,11 @@ export interface MintSpecificOptions { * Initial price to set on the pool if creating */ sqrtPriceX96?: BigintIsh + + /** + * Whether the mint is part of a migration from V3 to V4 and the additional currency and amount to send if needed + */ + migrateOptions?: MigrateSpecificOptions } /** @@ -129,17 +134,15 @@ export interface MigrateSpecificOptions { /** * Whether the mint is part of a migration from V3 to V4. */ - migrate: boolean - + migrate?: boolean /** - * Whether the migrate needs additional transfer or not + * The additional currency that needs to be transferred */ - additionalTransfer?: AdditionalTransferDetails -} - -export interface AdditionalTransferDetails { - neededCurrency: Currency - neededAmount: BigintIsh + neededCurrency?: Currency + /** + * The amount of additional currency that needs to be transferred + */ + neededAmount?: BigintIsh } export interface PermitDetails { @@ -194,10 +197,9 @@ export interface NFTPermitData { } export type MintOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions -export type MigrateOptions = MintOptions & MigrateSpecificOptions export type IncreaseLiquidityOptions = CommonOptions & CommonAddLiquidityOptions & ModifyPositionSpecificOptions -export type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions | MigrateOptions +export type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions export type RemoveLiquidityOptions = CommonOptions & RemoveLiquiditySpecificOptions & ModifyPositionSpecificOptions @@ -208,10 +210,6 @@ function isMint(options: AddLiquidityOptions): options is MintOptions { return Object.keys(options).some((k) => k === 'recipient') } -function isMigrate(options: AddLiquidityOptions): options is MigrateOptions { - return Object.keys(options).some((k) => k === 'migrate') -} - function shouldCreatePool(options: MintOptions): boolean { if (options.createPool) { invariant(options.sqrtPriceX96 !== undefined, NO_SQRT_PRICE) @@ -292,7 +290,7 @@ export abstract class V4PositionManager { } // If migrating, we need to settle and sweep both currencies individually - if (isMigrate(options) && options.migrate) { + if (isMint(options) && options.migrateOptions?.migrate) { // payer is v4 positiion manager planner.addSettle(position.pool.currency0, false) planner.addSettle(position.pool.currency1, false) From 88c1c4c7cf29fe164ad1a770153f8d84d57f0904 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Thu, 30 Jan 2025 21:20:41 -0500 Subject: [PATCH 04/12] fix test --- sdks/v4-sdk/src/PositionManager.test.ts | 2 +- sdks/v4-sdk/src/PositionManager.ts | 21 ++------------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.test.ts b/sdks/v4-sdk/src/PositionManager.test.ts index b258efcd3..3800a4757 100644 --- a/sdks/v4-sdk/src/PositionManager.test.ts +++ b/sdks/v4-sdk/src/PositionManager.test.ts @@ -285,7 +285,7 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrate: true, + migrateOptions: { migrate: true }, }) // Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency. diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index c6474d966..da0c11187 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -63,7 +63,7 @@ export interface MintSpecificOptions { /** * Whether the mint is part of a migration from V3 to V4 and the additional currency and amount to send if needed */ - migrateOptions?: MigrateSpecificOptions + migrateOptions?: MigrateOptions } /** @@ -113,24 +113,7 @@ export interface CollectSpecificOptions { recipient: string } -export interface TransferOptions { - /** - * The account sending the NFT. - */ - sender: string - - /** - * The account that should receive the NFT. - */ - recipient: string - - /** - * The id of the token being sent. - */ - tokenId: BigintIsh -} - -export interface MigrateSpecificOptions { +export interface MigrateOptions { /** * Whether the mint is part of a migration from V3 to V4. */ From b669682a3000c18b49ab05cce0814f6abcdd2987 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Fri, 7 Feb 2025 11:19:36 -0500 Subject: [PATCH 05/12] comment --- sdks/v4-sdk/src/PositionManager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index 30557939d..bb22485d6 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -120,11 +120,11 @@ export interface MigrateOptions { */ migrate?: boolean /** - * The additional currency that needs to be transferred + * The additional currency that needs to be transferred if migrating from out of range to in range or out of range to opposite side out of range */ neededCurrency?: Currency /** - * The amount of additional currency that needs to be transferred + * The amount of additional currency that needs to be transferred if migrating from out of range to in range or out of range to opposite side out of range */ neededAmount?: BigintIsh } From eb869abab10367900a90b9443511e8444201a1ea Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Mon, 10 Feb 2025 17:23:55 -0500 Subject: [PATCH 06/12] migrating to position that needs eth --- sdks/v4-sdk/src/PositionManager.test.ts | 39 +++++++++++++++++++++++++ sdks/v4-sdk/src/PositionManager.ts | 4 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/sdks/v4-sdk/src/PositionManager.test.ts b/sdks/v4-sdk/src/PositionManager.test.ts index 8e12eedda..4ca217fef 100644 --- a/sdks/v4-sdk/src/PositionManager.test.ts +++ b/sdks/v4-sdk/src/PositionManager.test.ts @@ -367,6 +367,45 @@ describe('PositionManager', () => { expect(value).toEqual('0x00') }) + it('succeeds when migrating out of range and need to transfer eth', () => { + const position: Position = new Position({ + pool: pool_1_eth, + tickLower: TICK_SPACINGS[FeeAmount.MEDIUM], + tickUpper: TICK_SPACINGS[FeeAmount.MEDIUM] * 2, + liquidity: 1, + }) + const { calldata, value } = V4PositionManager.addCallParameters(position, { + recipient, + slippageTolerance, + deadline, + migrateOptions: { migrate: true, neededCurrency: currency_native, neededAmount: 1 }, + useNative: currency_native, + }) + + // Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency. + const planner = new V4Planner() + const { amount0: amount0Max, amount1: amount1Max } = position.mintAmountsWithSlippage(slippageTolerance) + // Expect position to be minted correctly + planner.addAction(Actions.MINT_POSITION, [ + pool_1_eth.poolKey, + TICK_SPACINGS[FeeAmount.MEDIUM], + TICK_SPACINGS[FeeAmount.MEDIUM] * 2, + 1, + toHex(amount0Max), + toHex(amount1Max), + recipient, + EMPTY_BYTES, + ]) + + planner.addAction(Actions.SETTLE, [toAddress(pool_1_eth.currency0), OPEN_DELTA, false]) + planner.addAction(Actions.SETTLE, [toAddress(pool_1_eth.currency1), OPEN_DELTA, false]) + planner.addAction(Actions.SWEEP, [toAddress(pool_1_eth.currency0), recipient]) + planner.addAction(Actions.SWEEP, [toAddress(pool_1_eth.currency1), recipient]) + expect(calldata).toEqual(V4PositionManager.encodeModifyLiquidities(planner.finalize(), deadline)) + + expect(value).toEqual('0x00') + }) + it('succeeds for batchPermit', () => { const position: Position = new Position({ pool: pool_0_1, diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index bb22485d6..141c0fa1f 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -282,9 +282,11 @@ export abstract class V4PositionManager { let value: string = toHex(0) + let needToSendEth = isMint(options) && options.migrateOptions?.neededCurrency?.isNative + // If migrating, we need to settle and sweep both currencies individually if (isMint(options) && options.migrateOptions?.migrate) { - if (options.useNative) { + if (options.useNative && !needToSendEth) { // unwrap the exact amount needed to send to the pool manager planner.addUnwrap(OPEN_DELTA) // payer is v4 position manager From af3398f889eebd4ab39e7ad229943242f22f4c6f Mon Sep 17 00:00:00 2001 From: diana Date: Tue, 18 Feb 2025 10:16:42 -0500 Subject: [PATCH 07/12] Update sdks/v4-sdk/src/PositionManager.ts Co-authored-by: Alice <34962750+hensha256@users.noreply.github.com> --- sdks/v4-sdk/src/PositionManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index 141c0fa1f..d8a7711af 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -120,7 +120,7 @@ export interface MigrateOptions { */ migrate?: boolean /** - * The additional currency that needs to be transferred if migrating from out of range to in range or out of range to opposite side out of range + * The additional currency that needs to be transferred if migrating (a) from out-of-range to in-range, or (b) from out-of-range to out-of-range on the opposite side */ neededCurrency?: Currency /** From 034362ce3d66cd192251f25c49bd84b98baf0851 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 18 Feb 2025 10:25:06 -0500 Subject: [PATCH 08/12] naming and comment --- sdks/v4-sdk/src/PositionManager.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index d8a7711af..72ea7b59b 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -120,13 +120,13 @@ export interface MigrateOptions { */ migrate?: boolean /** - * The additional currency that needs to be transferred if migrating (a) from out-of-range to in-range, or (b) from out-of-range to out-of-range on the opposite side + * The additional currency that needs to be transferred if migrating (a) from out-of-range to in-range, or (b) from out-of-range to out-of-range on the opposite side */ - neededCurrency?: Currency + inputCurrency?: Currency /** - * The amount of additional currency that needs to be transferred if migrating from out of range to in range or out of range to opposite side out of range + * The amount of additional currency that needs to be transferred if migrating (a) from out-of-range to in-range, or (b) from out-of-range to out-of-range on the opposite side */ - neededAmount?: BigintIsh + inputAmount?: BigintIsh } export interface PermitDetails { From 74b11e4b462d68516544f270ac71860e5ed9eb38 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 18 Feb 2025 10:32:23 -0500 Subject: [PATCH 09/12] fix --- sdks/v4-sdk/src/PositionManager.test.ts | 2 +- sdks/v4-sdk/src/PositionManager.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.test.ts b/sdks/v4-sdk/src/PositionManager.test.ts index 4ca217fef..1b312393b 100644 --- a/sdks/v4-sdk/src/PositionManager.test.ts +++ b/sdks/v4-sdk/src/PositionManager.test.ts @@ -378,7 +378,7 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrateOptions: { migrate: true, neededCurrency: currency_native, neededAmount: 1 }, + migrateOptions: { migrate: true, inputCurrency: currency_native, inputAmount: 1 }, useNative: currency_native, }) diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index 72ea7b59b..aeabe31ba 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -282,7 +282,7 @@ export abstract class V4PositionManager { let value: string = toHex(0) - let needToSendEth = isMint(options) && options.migrateOptions?.neededCurrency?.isNative + let needToSendEth = isMint(options) && options.migrateOptions?.inputCurrency?.isNative // If migrating, we need to settle and sweep both currencies individually if (isMint(options) && options.migrateOptions?.migrate) { From 542273fb77b841103a682bfd59e968476eea2c94 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 18 Feb 2025 11:14:03 -0500 Subject: [PATCH 10/12] migrate specific options --- sdks/v4-sdk/src/PositionManager.test.ts | 7 ++++--- sdks/v4-sdk/src/PositionManager.ts | 27 ++++++++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.test.ts b/sdks/v4-sdk/src/PositionManager.test.ts index 1b312393b..1b7932359 100644 --- a/sdks/v4-sdk/src/PositionManager.test.ts +++ b/sdks/v4-sdk/src/PositionManager.test.ts @@ -300,7 +300,7 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrateOptions: { migrate: true }, + migrate: true, }) // Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency. @@ -338,7 +338,7 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrateOptions: { migrate: true }, + migrate: true, useNative: currency_native, }) @@ -378,7 +378,8 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrateOptions: { migrate: true, inputCurrency: currency_native, inputAmount: 1 }, + migrate: true, + currencyAmount: { inputCurrency: currency_native, inputAmount: 1 }, useNative: currency_native, }) diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index aeabe31ba..7733539f9 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -62,9 +62,9 @@ export interface MintSpecificOptions { sqrtPriceX96?: BigintIsh /** - * Whether the mint is part of a migration from V3 to V4 and the additional currency and amount to send if needed + * Whether the mint is part of a migration from V3 to V4 */ - migrateOptions?: MigrateOptions + migrate?: boolean } /** @@ -114,19 +114,22 @@ export interface CollectSpecificOptions { recipient: string } -export interface MigrateOptions { +export interface MigrateSpecificOptions { /** - * Whether the mint is part of a migration from V3 to V4. + * The additional currency and amount that needs to be transferred if migrating (a) from out-of-range to in-range, or (b) from out-of-range to out-of-range on the opposite side */ - migrate?: boolean + currencyAmount?: CurrencyAmount +} + +export interface CurrencyAmount { /** - * The additional currency that needs to be transferred if migrating (a) from out-of-range to in-range, or (b) from out-of-range to out-of-range on the opposite side + * The additional currency that needs to be transferred */ - inputCurrency?: Currency + inputCurrency: Currency /** - * The amount of additional currency that needs to be transferred if migrating (a) from out-of-range to in-range, or (b) from out-of-range to out-of-range on the opposite side + * The amount of additional currency that needs to be transferred */ - inputAmount?: BigintIsh + inputAmount: BigintIsh } export interface PermitDetails { @@ -180,7 +183,7 @@ export interface NFTPermitData { values: NFTPermitValues } -export type MintOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions +export type MintOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions & MigrateSpecificOptions export type IncreaseLiquidityOptions = CommonOptions & CommonAddLiquidityOptions & ModifyPositionSpecificOptions export type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions @@ -282,10 +285,10 @@ export abstract class V4PositionManager { let value: string = toHex(0) - let needToSendEth = isMint(options) && options.migrateOptions?.inputCurrency?.isNative + let needToSendEth = isMint(options) && options.migrate && options.currencyAmount?.inputCurrency.isNative // If migrating, we need to settle and sweep both currencies individually - if (isMint(options) && options.migrateOptions?.migrate) { + if (isMint(options) && options.migrate) { if (options.useNative && !needToSendEth) { // unwrap the exact amount needed to send to the pool manager planner.addUnwrap(OPEN_DELTA) From 40df03daf5bd263307baaff2f86dc42a688aa942 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 18 Feb 2025 16:48:37 -0500 Subject: [PATCH 11/12] test for transferring extra currency that is not eth --- sdks/v4-sdk/src/PositionManager.test.ts | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/sdks/v4-sdk/src/PositionManager.test.ts b/sdks/v4-sdk/src/PositionManager.test.ts index 1b7932359..3ec4c1ccc 100644 --- a/sdks/v4-sdk/src/PositionManager.test.ts +++ b/sdks/v4-sdk/src/PositionManager.test.ts @@ -407,6 +407,45 @@ describe('PositionManager', () => { expect(value).toEqual('0x00') }) + it('succeeds when migrating out of range and need to transfer extra currency', () => { + const position: Position = new Position({ + pool: pool_0_1, + tickLower: TICK_SPACINGS[FeeAmount.MEDIUM], + tickUpper: TICK_SPACINGS[FeeAmount.MEDIUM] * 2, + liquidity: 1, + }) + const { calldata, value } = V4PositionManager.addCallParameters(position, { + recipient, + slippageTolerance, + deadline, + migrate: true, + currencyAmount: { inputCurrency: currency0, inputAmount: 1 }, + }) + + // Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency. + const planner = new V4Planner() + const { amount0: amount0Max, amount1: amount1Max } = position.mintAmountsWithSlippage(slippageTolerance) + // Expect position to be minted correctly + planner.addAction(Actions.MINT_POSITION, [ + pool_0_1.poolKey, + TICK_SPACINGS[FeeAmount.MEDIUM], + TICK_SPACINGS[FeeAmount.MEDIUM] * 2, + 1, + toHex(amount0Max), + toHex(amount1Max), + recipient, + EMPTY_BYTES, + ]) + + planner.addAction(Actions.SETTLE, [toAddress(pool_0_1.currency0), OPEN_DELTA, false]) + planner.addAction(Actions.SETTLE, [toAddress(pool_0_1.currency1), OPEN_DELTA, false]) + planner.addAction(Actions.SWEEP, [toAddress(pool_0_1.currency0), recipient]) + planner.addAction(Actions.SWEEP, [toAddress(pool_0_1.currency1), recipient]) + expect(calldata).toEqual(V4PositionManager.encodeModifyLiquidities(planner.finalize(), deadline)) + + expect(value).toEqual('0x00') + }) + it('succeeds for batchPermit', () => { const position: Position = new Position({ pool: pool_0_1, From aad7a8cc7aac2b68b7992cb1aebb56a447a1a110 Mon Sep 17 00:00:00 2001 From: dianakocsis Date: Tue, 4 Mar 2025 14:28:52 -0500 Subject: [PATCH 12/12] separate mgirate options --- sdks/v4-sdk/src/PositionManager.test.ts | 14 +++++----- sdks/v4-sdk/src/PositionManager.ts | 35 ++++++++++--------------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/sdks/v4-sdk/src/PositionManager.test.ts b/sdks/v4-sdk/src/PositionManager.test.ts index 3ec4c1ccc..4293cc02f 100644 --- a/sdks/v4-sdk/src/PositionManager.test.ts +++ b/sdks/v4-sdk/src/PositionManager.test.ts @@ -300,7 +300,8 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrate: true, + additionalAmount0: 0, + additionalAmount1: 0, }) // Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency. @@ -338,7 +339,8 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrate: true, + additionalAmount0: 0, + additionalAmount1: 0, useNative: currency_native, }) @@ -378,8 +380,8 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrate: true, - currencyAmount: { inputCurrency: currency_native, inputAmount: 1 }, + additionalAmount0: 1, + additionalAmount1: 0, useNative: currency_native, }) @@ -418,8 +420,8 @@ describe('PositionManager', () => { recipient, slippageTolerance, deadline, - migrate: true, - currencyAmount: { inputCurrency: currency0, inputAmount: 1 }, + additionalAmount0: 1, + additionalAmount1: 0, }) // Rebuild the data with the planner for the expected mint. MUST sweep since we are using the native currency. diff --git a/sdks/v4-sdk/src/PositionManager.ts b/sdks/v4-sdk/src/PositionManager.ts index 7733539f9..0fb2ab213 100644 --- a/sdks/v4-sdk/src/PositionManager.ts +++ b/sdks/v4-sdk/src/PositionManager.ts @@ -1,4 +1,4 @@ -import { BigintIsh, Percent, validateAndParseAddress, NativeCurrency, Currency } from '@uniswap/sdk-core' +import { BigintIsh, Percent, validateAndParseAddress, NativeCurrency } from '@uniswap/sdk-core' import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer' import JSBI from 'jsbi' import { Position } from './entities/position' @@ -60,11 +60,6 @@ export interface MintSpecificOptions { * Initial price to set on the pool if creating */ sqrtPriceX96?: BigintIsh - - /** - * Whether the mint is part of a migration from V3 to V4 - */ - migrate?: boolean } /** @@ -116,20 +111,13 @@ export interface CollectSpecificOptions { export interface MigrateSpecificOptions { /** - * The additional currency and amount that needs to be transferred if migrating (a) from out-of-range to in-range, or (b) from out-of-range to out-of-range on the opposite side + * The additional amount of currency0 that needs to be transferred if needed */ - currencyAmount?: CurrencyAmount -} - -export interface CurrencyAmount { + additionalAmount0: BigintIsh /** - * The additional currency that needs to be transferred + * The additional amount of currency1 that needs to be transferred if needed */ - inputCurrency: Currency - /** - * The amount of additional currency that needs to be transferred - */ - inputAmount: BigintIsh + additionalAmount1: BigintIsh } export interface PermitDetails { @@ -183,10 +171,11 @@ export interface NFTPermitData { values: NFTPermitValues } -export type MintOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions & MigrateSpecificOptions +export type MintOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions +export type MigrateOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions & MigrateSpecificOptions export type IncreaseLiquidityOptions = CommonOptions & CommonAddLiquidityOptions & ModifyPositionSpecificOptions -export type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions +export type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions | MigrateOptions export type RemoveLiquidityOptions = CommonOptions & RemoveLiquiditySpecificOptions & ModifyPositionSpecificOptions @@ -197,6 +186,10 @@ function isMint(options: AddLiquidityOptions): options is MintOptions { return Object.keys(options).some((k) => k === 'recipient') } +function isMigrate(options: AddLiquidityOptions): options is MigrateOptions { + return Object.keys(options).some((k) => k === 'additionalAmount0') +} + function shouldCreatePool(options: MintOptions): boolean { if (options.createPool) { invariant(options.sqrtPriceX96 !== undefined, NO_SQRT_PRICE) @@ -285,10 +278,10 @@ export abstract class V4PositionManager { let value: string = toHex(0) - let needToSendEth = isMint(options) && options.migrate && options.currencyAmount?.inputCurrency.isNative + let needToSendEth = isMigrate(options) && options.useNative && options.additionalAmount0 > '0' // If migrating, we need to settle and sweep both currencies individually - if (isMint(options) && options.migrate) { + if (isMigrate(options)) { if (options.useNative && !needToSendEth) { // unwrap the exact amount needed to send to the pool manager planner.addUnwrap(OPEN_DELTA)