diff --git a/sdks/v4-sdk/src/entities/route.ts b/sdks/v4-sdk/src/entities/route.ts index 7e4156e2b..e5ce73679 100644 --- a/sdks/v4-sdk/src/entities/route.ts +++ b/sdks/v4-sdk/src/entities/route.ts @@ -65,28 +65,9 @@ export class Route { public get midPrice(): Price { if (this._midPrice !== null) return this._midPrice - const price = this.pools.slice(1).reduce( - ({ nextInput, price }, pool) => { - return nextInput.equals(pool.currency0) - ? { - nextInput: pool.currency1, - price: price.multiply(pool.currency0Price), - } - : { - nextInput: pool.currency0, - price: price.multiply(pool.currency1Price), - } - }, - this.pools[0].currency0.equals(this.input) - ? { - nextInput: this.pools[0].currency1, - price: this.pools[0].currency0Price, - } - : { - nextInput: this.pools[0].currency0, - price: this.pools[0].currency1Price, - } - ).price + const price = this.pools.slice(1).reduce((price, pool) => { + return price.multiply(pool.priceOf(price.quoteCurrency)) + }, this.pools[0].priceOf(this.pathInput)) return (this._midPrice = new Price(this.input, this.output, price.denominator, price.numerator)) }