Skip to content

feat(v4-sdk): additional options when migrating #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions sdks/v4-sdk/src/PositionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we are pulling out migrate into its own object; might need to change trading api impl

}

/**
Expand Down Expand Up @@ -130,6 +125,23 @@ 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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not too bad it seems on the Trading API side to send in; curious how to derive the amount, seems it wouldnt bee to tedious to compute from earlier convos


export interface PermitDetails {
token: string
amount: BigintIsh
Expand Down Expand Up @@ -182,9 +194,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

Expand All @@ -195,6 +208,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)
Expand Down Expand Up @@ -275,7 +292,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)
Expand Down
Loading