min amount of swap to repay usdc borrow

This commit is contained in:
Adrian Brzeziński 2024-03-13 19:06:49 +01:00
parent 0d0a709f0c
commit 12e2f4f79b
1 changed files with 9 additions and 5 deletions

View File

@ -128,12 +128,16 @@ export const unstakeAndSwap = async (
let swapAlts: AddressLookupTableAccount[] = []
if (borrowed.toNumber() < 0) {
const toRepay = Math.ceil(
(stakeAmountToRepay
? toNativeI80F48(stakeAmountToRepay, stakeBank.mintDecimals)
: borrowed.abs().div(stakeBank.getAssetPrice())
).toNumber() * 1.002,
const toRepay = Math.max(
Math.ceil(
(stakeAmountToRepay
? toNativeI80F48(stakeAmountToRepay, stakeBank.mintDecimals)
: borrowed.abs().div(stakeBank.getAssetPrice())
).toNumber() * 1.002,
),
Math.ceil(toNativeI80F48(0.0001, stakeBank.mintDecimals).toNumber()),
)
console.log(toRepay, '@@@@@@@')
console.log('borrowedSol amount: ', borrowed.toNumber())
console.log('borrow needed to repay for withdraw', toRepay)