ts: fix threshold price computation in token conditional swaps
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
25a90580fd
commit
c7cc7c248c
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue