ts: drop the premium calculators chunk size for tcs swap, we were overestimating slippage before

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2023-08-25 15:20:00 +02:00
parent 5fd31270f6
commit ea02670003
1 changed files with 28 additions and 10 deletions

View File

@ -3587,26 +3587,44 @@ export class MangoClient {
allowCreatingBorrows: boolean,
expiryTimestamp: number | null,
): Promise<MangoSignatureStatus> {
const maxBuy =
maxBuyUi == Number.MAX_SAFE_INTEGER
? U64_MAX_BN
: toNative(maxBuyUi, buyBank.mintDecimals);
const maxSell =
maxSellUi == Number.MAX_SAFE_INTEGER
? U64_MAX_BN
: toNative(maxSellUi, sellBank.mintDecimals);
let maxBuy, maxSell, buyAmountInUsd, sellAmountInUsd;
if (maxBuyUi == Number.MAX_SAFE_INTEGER) {
maxBuy = U64_MAX_BN;
} else {
buyAmountInUsd = maxBuyUi * buyBank.uiPrice;
maxBuy = toNative(maxBuyUi, buyBank.mintDecimals);
}
if (maxSellUi == Number.MAX_SAFE_INTEGER) {
maxSell = U64_MAX_BN;
} else {
sellAmountInUsd = maxSellUi * sellBank.uiPrice;
maxSell = toNative(maxSellUi, sellBank.mintDecimals);
}
// Used for computing optimal premium
let liqorTcsChunkSizeInUsd = Math.min(buyAmountInUsd, sellAmountInUsd);
if (liqorTcsChunkSizeInUsd > 5000) {
liqorTcsChunkSizeInUsd = 5000;
}
// For small TCS swaps, reduce chunk size to 1000 USD
else {
liqorTcsChunkSizeInUsd = 1000;
}
const expiryTimestampBn =
expiryTimestamp !== null ? new BN(expiryTimestamp) : U64_MAX_BN;
if (!pricePremium) {
if (maxBuy.eq(U64_MAX_BN)) {
maxSell.toNumber() * sellBank.uiPrice;
}
const buyTokenPriceImpact = group.getPriceImpactByTokenIndex(
buyBank.tokenIndex,
5000,
liqorTcsChunkSizeInUsd,
);
const sellTokenPriceImpact = group.getPriceImpactByTokenIndex(
sellBank.tokenIndex,
5000,
liqorTcsChunkSizeInUsd,
);
pricePremium =
((1 + buyTokenPriceImpact / 100) * (1 + sellTokenPriceImpact / 100) -