Open eliotstock opened 2 years ago
I believe this bug is fixed in the current version 3.2.6.
In Fraction.constructor, numerator
and denominator
are always initialized.
public constructor(numerator: BigintIsh, denominator: BigintIsh = JSBI.BigInt(1)) {
this.numerator = JSBI.BigInt(numerator)
this.denominator = JSBI.BigInt(denominator)
}
In Fraction.tryParseFraction, new Fraction(fractionish)
is created when type of fractionish
is BigintIsh (or instance of JSBI, number or string).
private static tryParseFraction(fractionish: BigintIsh | Fraction): Fraction {
if (fractionish instanceof JSBI || typeof fractionish === 'number' || typeof fractionish === 'string')
return new Fraction(fractionish)
if ('numerator' in fractionish && 'denominator' in fractionish) return fractionish
throw new Error('Could not parse fraction')
}
Finally, when fractionish is CurrencyAmount
, CurrencyAmount.constructor always calls Fraction.constructor
with super(numerator, denominator)
, which means numerator
and denominator
are always initialized.
protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh) {
super(numerator, denominator)
invariant(JSBI.lessThanOrEqual(this.quotient, MaxUint256), 'AMOUNT')
this.currency = currency
this.decimalScale = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(currency.decimals))
}
I'm submitting a ... [*] bug report [ ] feature request [ ] question about the decisions made in the repository [ ] question about how to use this project
Summary
Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.) This line:
https://github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/functions/calculate-ratio-amount-in.ts#L12
will throw an Error when the
optimalRatio
passed in is zero, ie. a Fraction with a denominator of 1 but no numerator.Such a Fraction is easily produced by
AlphaRouter.routeToRatio()
here:https://github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/alpha-router.ts#L559
Here's the stack trace from my project code:
In case it matters, the version of JSBI in my codebase is:
"jsbi": "^3.2.4",
whereas in
sdk-core
v3.0.1 it's:"jsbi": "^3.1.4",