From c6eee30a76cc2d86fc3f89a06e86243833fbf07c Mon Sep 17 00:00:00 2001 From: halaprix Date: Thu, 4 Apr 2024 12:30:29 +0200 Subject: [PATCH 1/3] fix: fix fees --- .../common/close-to-coll-swap-data.ts | 55 +++++-------------- 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/packages/dma-library/src/strategies/common/close-to-coll-swap-data.ts b/packages/dma-library/src/strategies/common/close-to-coll-swap-data.ts index e9d37214c..0efbcd05b 100644 --- a/packages/dma-library/src/strategies/common/close-to-coll-swap-data.ts +++ b/packages/dma-library/src/strategies/common/close-to-coll-swap-data.ts @@ -1,6 +1,5 @@ import { Address } from '@deploy-configurations/types/address' import { FEE_BASE, ONE, TEN, ZERO } from '@dma-common/constants' -import { areAddressesEqual } from '@dma-common/utils/addresses' import { calculateFee } from '@dma-common/utils/swap' import { SAFETY_MARGIN } from '@dma-library/strategies/aave-like/multiply/close/constants' import { GetSwapData } from '@dma-library/types/common' @@ -65,7 +64,7 @@ export async function getSwapDataForCloseToCollateral({ colPrice, collateralTokenPrecision, _outstandingDebt, - fee, + fee.div(new BigNumber(FEE_BASE).plus(fee)), slippage, ) @@ -74,47 +73,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. From 3047a2a3a3d7f0a46c7a8f8a42c2b23b6d7a4d79 Mon Sep 17 00:00:00 2001 From: halaprix Date: Thu, 4 Apr 2024 12:41:06 +0200 Subject: [PATCH 2/3] chore: remove redundant parameter --- .../src/strategies/aave-like/multiply/close/close.ts | 2 -- packages/dma-library/src/strategies/ajna/multiply/close.ts | 1 - .../src/strategies/common/close-to-coll-swap-data.ts | 2 -- .../dma-library/src/strategies/morphoblue/multiply/close.ts | 1 - 4 files changed, 6 deletions(-) diff --git a/packages/dma-library/src/strategies/aave-like/multiply/close/close.ts b/packages/dma-library/src/strategies/aave-like/multiply/close/close.ts index 35a8af412..d61ff4ede 100644 --- a/packages/dma-library/src/strategies/aave-like/multiply/close/close.ts +++ b/packages/dma-library/src/strategies/aave-like/multiply/close/close.ts @@ -111,8 +111,6 @@ async function getAaveSwapDataToCloseToCollateral( debtPrice: debtTokenPrice, outstandingDebt: dependencies.currentPosition.debt.amount, slippage, - // Needs to be WETH for isETH comparison - ETHAddress: addresses.tokens.WETH, getSwapData: dependencies.getSwapData, }) } diff --git a/packages/dma-library/src/strategies/ajna/multiply/close.ts b/packages/dma-library/src/strategies/ajna/multiply/close.ts index 5cc3ea621..385a6f011 100644 --- a/packages/dma-library/src/strategies/ajna/multiply/close.ts +++ b/packages/dma-library/src/strategies/ajna/multiply/close.ts @@ -155,7 +155,6 @@ async function getAjnaSwapDataToCloseToCollateral( debtPrice, slippage: args.slippage, outstandingDebt, - ETHAddress: dependencies.WETH, getSwapData: dependencies.getSwapData, }) } diff --git a/packages/dma-library/src/strategies/common/close-to-coll-swap-data.ts b/packages/dma-library/src/strategies/common/close-to-coll-swap-data.ts index 0efbcd05b..36f9b1c10 100644 --- a/packages/dma-library/src/strategies/common/close-to-coll-swap-data.ts +++ b/packages/dma-library/src/strategies/common/close-to-coll-swap-data.ts @@ -21,7 +21,6 @@ interface GetSwapDataToCloseToCollateralArgs { debtPrice: BigNumber outstandingDebt: BigNumber slippage: BigNumber - ETHAddress: Address getSwapData: GetSwapData __feeOverride?: BigNumber } @@ -33,7 +32,6 @@ export async function getSwapDataForCloseToCollateral({ debtPrice, outstandingDebt, slippage, - ETHAddress, getSwapData, __feeOverride, }: GetSwapDataToCloseToCollateralArgs) { diff --git a/packages/dma-library/src/strategies/morphoblue/multiply/close.ts b/packages/dma-library/src/strategies/morphoblue/multiply/close.ts index 94aa1cb6e..b7864ef4d 100644 --- a/packages/dma-library/src/strategies/morphoblue/multiply/close.ts +++ b/packages/dma-library/src/strategies/morphoblue/multiply/close.ts @@ -179,7 +179,6 @@ async function getMorphoSwapDataToCloseToCollateral( debtPrice, slippage: args.slippage, outstandingDebt, - ETHAddress: dependencies.addresses.ETH, getSwapData: dependencies.getSwapData, }) } From 3da288eee26886dc41eaa474b6b1906d1c53410b Mon Sep 17 00:00:00 2001 From: halaprix Date: Fri, 5 Apr 2024 16:32:49 +0200 Subject: [PATCH 3/3] chore: bump version and publish --- packages/dma-library/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dma-library/package.json b/packages/dma-library/package.json index 85e56df84..d7dd771b2 100644 --- a/packages/dma-library/package.json +++ b/packages/dma-library/package.json @@ -1,6 +1,6 @@ { "name": "@oasisdex/dma-library", - "version": "0.6.50", + "version": "0.6.51", "typings": "lib/index.d.ts", "types": "lib/index.d.ts", "main": "lib/index.js",