ts: fix threshold price computation in token conditional swaps

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2023-08-10 16:16:05 +02:00
parent 25a90580fd
commit c7cc7c248c
1 changed files with 6 additions and 5 deletions

View File

@ -1875,15 +1875,16 @@ export class TokenConditionalSwap {
}
getThresholdPriceUi(group: Group): number {
const a = I80F48.fromNumber(this.priceLowerLimit);
const b = I80F48.fromNumber(this.priceUpperLimit);
const buyBank = this.getBuyToken(group);
const sellBank = this.getSellToken(group);
const o = buyBank.price.div(sellBank.price);
const a = toUiSellPerBuyTokenPrice(this.priceLowerLimit, sellBank, buyBank);
const b = toUiSellPerBuyTokenPrice(this.priceUpperLimit, sellBank, buyBank);
const o = buyBank.uiPrice / sellBank.uiPrice;
// Choose the price closest to oracle
if (o.sub(a).abs().lt(o.sub(b).abs())) {
if (Math.abs(o - a) < Math.abs(o - b)) {
return this.getPriceLowerLimitUi(group);
}
return this.getPriceUpperLimitUi(group);