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:
parent
5fd31270f6
commit
ea02670003
|
@ -3587,26 +3587,44 @@ export class MangoClient {
|
||||||
allowCreatingBorrows: boolean,
|
allowCreatingBorrows: boolean,
|
||||||
expiryTimestamp: number | null,
|
expiryTimestamp: number | null,
|
||||||
): Promise<MangoSignatureStatus> {
|
): Promise<MangoSignatureStatus> {
|
||||||
const maxBuy =
|
let maxBuy, maxSell, buyAmountInUsd, sellAmountInUsd;
|
||||||
maxBuyUi == Number.MAX_SAFE_INTEGER
|
if (maxBuyUi == Number.MAX_SAFE_INTEGER) {
|
||||||
? U64_MAX_BN
|
maxBuy = U64_MAX_BN;
|
||||||
: toNative(maxBuyUi, buyBank.mintDecimals);
|
} else {
|
||||||
const maxSell =
|
buyAmountInUsd = maxBuyUi * buyBank.uiPrice;
|
||||||
maxSellUi == Number.MAX_SAFE_INTEGER
|
maxBuy = toNative(maxBuyUi, buyBank.mintDecimals);
|
||||||
? U64_MAX_BN
|
}
|
||||||
: toNative(maxSellUi, sellBank.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 =
|
const expiryTimestampBn =
|
||||||
expiryTimestamp !== null ? new BN(expiryTimestamp) : U64_MAX_BN;
|
expiryTimestamp !== null ? new BN(expiryTimestamp) : U64_MAX_BN;
|
||||||
|
|
||||||
if (!pricePremium) {
|
if (!pricePremium) {
|
||||||
|
if (maxBuy.eq(U64_MAX_BN)) {
|
||||||
|
maxSell.toNumber() * sellBank.uiPrice;
|
||||||
|
}
|
||||||
const buyTokenPriceImpact = group.getPriceImpactByTokenIndex(
|
const buyTokenPriceImpact = group.getPriceImpactByTokenIndex(
|
||||||
buyBank.tokenIndex,
|
buyBank.tokenIndex,
|
||||||
5000,
|
liqorTcsChunkSizeInUsd,
|
||||||
);
|
);
|
||||||
const sellTokenPriceImpact = group.getPriceImpactByTokenIndex(
|
const sellTokenPriceImpact = group.getPriceImpactByTokenIndex(
|
||||||
sellBank.tokenIndex,
|
sellBank.tokenIndex,
|
||||||
5000,
|
liqorTcsChunkSizeInUsd,
|
||||||
);
|
);
|
||||||
pricePremium =
|
pricePremium =
|
||||||
((1 + buyTokenPriceImpact / 100) * (1 + sellTokenPriceImpact / 100) -
|
((1 + buyTokenPriceImpact / 100) * (1 + sellTokenPriceImpact / 100) -
|
||||||
|
|
Loading…
Reference in New Issue