-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(universal-router-sdk): Supports Mixed Routes with V4 (#145)
- Loading branch information
Showing
9 changed files
with
359 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Currency, Token } from '@uniswap/sdk-core' | ||
import { Pool as V4Pool } from '@uniswap/v4-sdk' | ||
import { TPool } from '@uniswap/router-sdk/dist/utils/TPool' | ||
|
||
export function getPathCurrency(currency: Currency, pool: TPool): Currency { | ||
// return currency if the currency matches a currency of the pool | ||
if (pool.involvesToken(currency as Token)) { | ||
return currency | ||
|
||
// return if currency.wrapped if pool involves wrapped currency | ||
} else if (pool.involvesToken(currency.wrapped as Token)) { | ||
return currency.wrapped | ||
|
||
// return native currency if pool involves native version of wrapped currency (only applies to V4) | ||
} else if (pool instanceof V4Pool) { | ||
if (pool.token0.wrapped.equals(currency)) { | ||
return pool.token0 | ||
} else if (pool.token1.wrapped.equals(currency)) { | ||
return pool.token1 | ||
} | ||
|
||
// otherwise the token is invalid | ||
} else { | ||
throw new Error(`Expected currency ${currency.symbol} to be either ${pool.token0.symbol} or ${pool.token1.symbol}`) | ||
} | ||
|
||
return currency // this line needed for typescript to compile | ||
} |
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
Oops, something went wrong.