-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(router-sdk): Address wrapped/native currency conditions in mixed …
…routes with v4 (#81)
- Loading branch information
Showing
5 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
// 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 | ||
} |