-
Notifications
You must be signed in to change notification settings - Fork 80
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
fix(router-sdk): Address wrapped/native currency conditions in mixed routes with v4 #81
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Currency, Token } from '@uniswap/sdk-core' | ||
import { Pool as V4Pool } from '@uniswap/v4-sdk' | ||
import { Pair } from '@uniswap/v2-sdk' | ||
import { Pool as V3Pool } from '@uniswap/v3-sdk' | ||
|
||
type TPool = Pair | V3Pool | V4Pool | ||
|
||
export function isValidTokenPath(prevPool: TPool, currentPool: TPool, inputToken: Currency): boolean { | ||
if (currentPool.involvesToken(inputToken as Token)) return true | ||
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. this should always be true if inputToken is not native right, a comment could be helpful 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 have to put 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 kind of want to go into v2/v3-sdks change these inputs to |
||
|
||
// throw if both v4 pools, native/wrapped tokens not interchangeable in v4 | ||
if (prevPool instanceof V4Pool && currentPool instanceof V4Pool) return false | ||
|
||
// v2/v3 --> v4 valid if v2/v3 output is the wrapped version of the v4 pool native currency | ||
if (currentPool instanceof V4Pool) { | ||
if (currentPool.token0.wrapped.equals(inputToken) || currentPool.token1.wrapped.equals(inputToken)) return true | ||
} | ||
|
||
// v4 --> v2/v3 valid if v4 output is the native version of the v2/v3 wrapped token | ||
if (prevPool instanceof V4Pool) { | ||
if (currentPool.involvesToken(inputToken.wrapped)) return true | ||
} | ||
|
||
return false | ||
} |
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.
nit: as I was coding v4 routing in SOR, I realized getting this type exported can be beneficial
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.
yah I also need to DRY and put this somewhere, I keep meaning to do taht
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.
I'm afraid of needing new approvals, so I'm just gonna merge..