Skip to content

Commit

Permalink
fix: attempt to fix issue with close-to-coll on spark
Browse files Browse the repository at this point in the history
  • Loading branch information
zerotucks committed Apr 13, 2024
1 parent 1b75e1d commit 95a6ab1
Showing 1 changed file with 14 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function getSwapDataForCloseToCollateral({
colPrice,
collateralTokenPrecision,
_outstandingDebt,
fee,
fee.div(new BigNumber(FEE_BASE).plus(fee)),
slippage,
)

Expand All @@ -74,47 +74,21 @@ export async function getSwapDataForCloseToCollateral({
// there is a deviation threshold value that shows how much the prices on/off chain might differ
// When there is a 1inch swap, we use real-time market price. To calculate that,
// A preflight request is sent to calculate the existing market price.
const debtIsEth = areAddressesEqual(debtToken.address, ETHAddress)
const collateralIsEth = areAddressesEqual(collateralToken.address, ETHAddress)

if (debtIsEth) {
debtPrice = ONE.times(TEN.pow(debtTokenPrecision))
} else {
const debtPricePreflightSwapData = await getSwapData(
debtToken.address,
ETHAddress,
_outstandingDebt,
slippage,
undefined,
true, // inverts swap mock in tests ignored in prod
)
debtPrice = new BigNumber(
debtPricePreflightSwapData.toTokenAmount
.div(debtPricePreflightSwapData.fromTokenAmount)
.times(TEN.pow(debtTokenPrecision))
.toFixed(0),
)
}
debtPrice = ONE.times(TEN.pow(debtTokenPrecision))

if (collateralIsEth) {
colPrice = ONE.times(TEN.pow(collateralTokenPrecision))
} else {
const colPricePreflightSwapData =
!collateralIsEth &&
(await getSwapData(
collateralToken.address,
ETHAddress,
collateralNeeded.integerValue(BigNumber.ROUND_DOWN),
slippage,
))
const colPricePreflightSwapData = await getSwapData(
collateralToken.address,
debtToken.address,
collateralNeeded.integerValue(BigNumber.ROUND_DOWN),
slippage,
)

colPrice = new BigNumber(
colPricePreflightSwapData.toTokenAmount
.div(colPricePreflightSwapData.fromTokenAmount)
.times(TEN.pow(collateralTokenPrecision))
.toFixed(0),
)
}
colPrice = new BigNumber(
colPricePreflightSwapData.toTokenAmount
.div(colPricePreflightSwapData.fromTokenAmount)
.times(TEN.pow(collateralTokenPrecision))
.toFixed(0),
)

// 4. Get Swap Data
// This is the actual swap data that will be used in the transaction.
Expand Down

0 comments on commit 95a6ab1

Please sign in to comment.