diff --git a/sdks/v3-sdk/src/entities/route.ts b/sdks/v3-sdk/src/entities/route.ts index 7b7d6ff8e..4bd490328 100644 --- a/sdks/v3-sdk/src/entities/route.ts +++ b/sdks/v3-sdk/src/entities/route.ts @@ -61,28 +61,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.token0) - ? { - nextInput: pool.token1, - price: price.multiply(pool.token0Price), - } - : { - nextInput: pool.token0, - price: price.multiply(pool.token1Price), - } - }, - this.pools[0].token0.equals(this.input.wrapped) - ? { - nextInput: this.pools[0].token1, - price: this.pools[0].token0Price, - } - : { - nextInput: this.pools[0].token0, - price: this.pools[0].token1Price, - } - ).price + const price = this.pools.slice(1).reduce((price, pool) => { + return price.multiply(pool.priceOf(price.quoteCurrency)) + }, this.pools[0].priceOf(this.input.wrapped)) return (this._midPrice = new Price(this.input, this.output, price.denominator, price.numerator)) }