Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions sdks/v3-sdk/src/entities/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,9 @@ export class Route<TInput extends Currency, TOutput extends Currency> {
public get midPrice(): Price<TInput, TOutput> {
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))
}
Expand Down
Loading