-
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(v4-sdk): Account for wrapping and unwrapping in v4 (#121)
Co-authored-by: Emily Williams <[email protected]>
- Loading branch information
Showing
5 changed files
with
122 additions
and
12 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,26 @@ | ||
import { Currency, CurrencyAmount } from '@uniswap/sdk-core' | ||
import { Pool } from '../entities/pool' | ||
|
||
export function amountWithPathCurrency(amount: CurrencyAmount<Currency>, pool: Pool): CurrencyAmount<Currency> { | ||
return CurrencyAmount.fromFractionalAmount( | ||
getPathCurrency(amount.currency, pool), | ||
amount.numerator, | ||
amount.denominator | ||
) | ||
} | ||
|
||
export function getPathCurrency(currency: Currency, pool: Pool): Currency { | ||
if (pool.involvesCurrency(currency)) { | ||
return currency | ||
} else if (pool.involvesCurrency(currency.wrapped)) { | ||
return currency.wrapped | ||
} else if (pool.currency0.wrapped.equals(currency)) { | ||
return pool.currency0 | ||
} else if (pool.currency1.wrapped.equals(currency)) { | ||
return pool.currency1 | ||
} else { | ||
throw new Error( | ||
`Expected currency ${currency.symbol} to be either ${pool.currency0.symbol} or ${pool.currency1.symbol}` | ||
) | ||
} | ||
} |