-
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(router-sdk): Prepare router-sdk to fully support mixed routes (#135)
- Loading branch information
Showing
7 changed files
with
97 additions
and
42 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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core' | ||
import { Pool as V4Pool } from '@uniswap/v4-sdk' | ||
import { TPool } from './TPool' | ||
|
||
export function amountWithPathCurrency(amount: CurrencyAmount<Currency>, pool: TPool): CurrencyAmount<Currency> { | ||
return CurrencyAmount.fromFractionalAmount( | ||
getPathCurrency(amount.currency, pool), | ||
amount.numerator, | ||
amount.denominator | ||
) | ||
} | ||
|
||
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.currency0.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 | ||
} |