-
Notifications
You must be signed in to change notification settings - Fork 116
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
base: main
Are you sure you want to change the base?
Changes from all commits
ce3bb3c
ad62981
81c86a1
616bc64
88c1c4c
b3e1f44
b669682
eb869ab
af3398f
034362c
74b11e4
542273f
40df03d
08c1256
aad7a8c
ab18592
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
/** | ||
|
@@ -114,21 +109,15 @@ export interface CollectSpecificOptions { | |
recipient: string | ||
} | ||
|
||
export interface TransferOptions { | ||
dianakocsis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export interface MigrateSpecificOptions { | ||
/** | ||
* The account sending the NFT. | ||
* The additional amount of currency0 that needs to be transferred if needed | ||
*/ | ||
sender: string | ||
|
||
additionalAmount0: BigintIsh | ||
/** | ||
* The account that should receive the NFT. | ||
* The additional amount of currency1 that needs to be transferred if needed | ||
*/ | ||
recipient: string | ||
|
||
/** | ||
* The id of the token being sent. | ||
*/ | ||
tokenId: BigintIsh | ||
additionalAmount1: BigintIsh | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -183,9 +172,10 @@ export interface NFTPermitData { | |
} | ||
|
||
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 | ||
|
||
|
@@ -196,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) | ||
|
@@ -284,9 +278,11 @@ export abstract class V4PositionManager { | |
|
||
let value: string = toHex(0) | ||
|
||
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 (options.useNative) { | ||
if (isMigrate(options)) { | ||
if (options.useNative && !needToSendEth) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the case where neededCurrency is ETH and the position is in WETH this path should still be taken i think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the opposite right? it would need to wrap not unwrap |
||
// unwrap the exact amount needed to send to the pool manager | ||
planner.addUnwrap(OPEN_DELTA) | ||
// payer is v4 position manager | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would love a test for non-eth too, and for ETH-WETH wrapping combos if they are to be supported too