From c6a81fed5cb5adda70aebf62f63c4ddd9783cdd7 Mon Sep 17 00:00:00 2001 From: halaprix Date: Mon, 11 Mar 2024 15:54:02 +0100 Subject: [PATCH 1/2] fix: fix eth weth --- packages/dma-library/package.json | 2 +- .../src/operations/aave/auto/withdraw-to-debt.ts | 15 ++++++++++++--- .../src/operations/aave/auto/withdraw.ts | 10 ++++++++-- .../src/operations/spark/auto/withdraw-to-debt.ts | 15 ++++++++++++--- .../src/operations/spark/auto/withdraw.ts | 10 ++++++++-- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/packages/dma-library/package.json b/packages/dma-library/package.json index fc532e39..ecfbe25a 100644 --- a/packages/dma-library/package.json +++ b/packages/dma-library/package.json @@ -1,6 +1,6 @@ { "name": "@oasisdex/dma-library", - "version": "0.5.21-dma-v2-workers.29-auto-withdraw-to-ltv", + "version": "0.5.21-dma-v2-workers.30-auto-withdraw-to-ltv", "typings": "lib/index.d.ts", "types": "lib/index.d.ts", "main": "lib/index.js", diff --git a/packages/dma-library/src/operations/aave/auto/withdraw-to-debt.ts b/packages/dma-library/src/operations/aave/auto/withdraw-to-debt.ts index cb6ebee7..27441551 100644 --- a/packages/dma-library/src/operations/aave/auto/withdraw-to-debt.ts +++ b/packages/dma-library/src/operations/aave/auto/withdraw-to-debt.ts @@ -25,7 +25,10 @@ export const withdrawToDebt: AaveV3WithdrawToDebtOperation = async args => { const { network } = args const withdrawCollateralFromAAVE = actions.aave.v3.aaveV3Withdraw(args.network, { - asset: args.collateralTokenAddress, + asset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, amount: args.withdrawAmount, to: args.proxy, }) @@ -33,13 +36,19 @@ export const withdrawToDebt: AaveV3WithdrawToDebtOperation = async args => { const collectFeeAfterWithdraw = actions.common.collectFee( args.network, { - asset: args.collateralTokenAddress, + asset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, }, [1], ) const swapCollateralTokensForDebtTokens = actions.common.swap(network, { - fromAsset: args.collateralTokenAddress, + fromAsset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, toAsset: args.debtIsEth ? args.addresses.tokens.WETH : args.debtTokenAddress, amount: args.swapAmount, receiveAtLeast: args.receiveAtLeast, diff --git a/packages/dma-library/src/operations/aave/auto/withdraw.ts b/packages/dma-library/src/operations/aave/auto/withdraw.ts index f73e70c4..1ee21751 100644 --- a/packages/dma-library/src/operations/aave/auto/withdraw.ts +++ b/packages/dma-library/src/operations/aave/auto/withdraw.ts @@ -21,7 +21,10 @@ export const withdraw: AaveV3WithdrawOperation = async args => { const { network } = args const withdrawCollateralFromAAVE = actions.aave.v3.aaveV3Withdraw(args.network, { - asset: args.collateralTokenAddress, + asset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, amount: args.withdrawAmount, to: args.proxy, }) @@ -29,7 +32,10 @@ export const withdraw: AaveV3WithdrawOperation = async args => { const collectFeeAfterWithdraw = actions.common.collectFee( args.network, { - asset: args.collateralTokenAddress, + asset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, }, [1], ) diff --git a/packages/dma-library/src/operations/spark/auto/withdraw-to-debt.ts b/packages/dma-library/src/operations/spark/auto/withdraw-to-debt.ts index c5910e4e..8667c6d9 100644 --- a/packages/dma-library/src/operations/spark/auto/withdraw-to-debt.ts +++ b/packages/dma-library/src/operations/spark/auto/withdraw-to-debt.ts @@ -25,7 +25,10 @@ export const withdrawToDebt: SparkWithdrawToDebtOperation = async args => { const { network } = args const withdrawCollateralFromSpark = actions.spark.withdraw(args.network, { - asset: args.collateralTokenAddress, + asset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, amount: args.withdrawAmount, to: args.proxy, }) @@ -33,13 +36,19 @@ export const withdrawToDebt: SparkWithdrawToDebtOperation = async args => { const collectFeeAfterWithdraw = actions.common.collectFee( args.network, { - asset: args.collateralTokenAddress, + asset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, }, [1], ) const swapCollateralTokensForDebtTokens = actions.common.swap(network, { - fromAsset: args.collateralTokenAddress, + fromAsset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, toAsset: args.debtIsEth ? args.addresses.tokens.WETH : args.debtTokenAddress, amount: args.withdrawAmount, receiveAtLeast: args.receiveAtLeast, diff --git a/packages/dma-library/src/operations/spark/auto/withdraw.ts b/packages/dma-library/src/operations/spark/auto/withdraw.ts index cae7e191..f5cab5d6 100644 --- a/packages/dma-library/src/operations/spark/auto/withdraw.ts +++ b/packages/dma-library/src/operations/spark/auto/withdraw.ts @@ -21,7 +21,10 @@ export const withdraw: SparkWithdrawOperation = async args => { const { network } = args const withdrawCollateralFromSpark = actions.spark.withdraw(args.network, { - asset: args.collateralTokenAddress, + asset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, amount: args.withdrawAmount, to: args.proxy, }) @@ -29,7 +32,10 @@ export const withdraw: SparkWithdrawOperation = async args => { const collectFeeAfterWithdraw = actions.common.collectFee( args.network, { - asset: args.collateralTokenAddress, + asset: + args.collateralTokenAddress.toLowerCase() == args.addresses.tokens.ETH.toLowerCase() + ? args.addresses.tokens.WETH + : args.collateralTokenAddress, }, [1], ) From 15d484240684760a53998070cac71eeaad852158 Mon Sep 17 00:00:00 2001 From: halaprix Date: Mon, 11 Mar 2024 20:05:58 +0100 Subject: [PATCH 2/2] chore: bump --- packages/dma-library/package.json | 2 +- .../strategies/aave/auto/withdraw-to-ltv/index.ts | 8 ++++---- .../strategies/spark/auto/withdraw-to-ltv/index.ts | 13 +++++-------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/dma-library/package.json b/packages/dma-library/package.json index ecfbe25a..40a87c0c 100644 --- a/packages/dma-library/package.json +++ b/packages/dma-library/package.json @@ -1,6 +1,6 @@ { "name": "@oasisdex/dma-library", - "version": "0.5.21-dma-v2-workers.30-auto-withdraw-to-ltv", + "version": "0.5.21-dma-v2-workers.31-auto-withdraw-to-ltv", "typings": "lib/index.d.ts", "types": "lib/index.d.ts", "main": "lib/index.js", diff --git a/packages/dma-library/src/strategies/aave/auto/withdraw-to-ltv/index.ts b/packages/dma-library/src/strategies/aave/auto/withdraw-to-ltv/index.ts index 3fe9ffc1..39e332ce 100644 --- a/packages/dma-library/src/strategies/aave/auto/withdraw-to-ltv/index.ts +++ b/packages/dma-library/src/strategies/aave/auto/withdraw-to-ltv/index.ts @@ -1,4 +1,4 @@ -import { ONE, ZERO } from "@dma-common/constants"; +import { ZERO } from '@dma-common/constants' import { withdraw as withdrawOp } from '@dma-library/operations/aave/auto/withdraw' import { withdrawToDebt } from '@dma-library/operations/aave/auto/withdraw-to-debt' import { getAaveTokenAddress } from '@dma-library/strategies/aave/common' @@ -47,7 +47,7 @@ export const withdraw: AaveV3WithdrawToLTV = async (args, dependencies) => { if (args.shouldWithdrawToDebt) { const FEE = new BigNumber(20) const FEE_BASIS = new BigNumber(10000) - const feeAmount = amountToWithdraw.times(FEE.div(FEE_BASIS)).integerValue(BigNumber.ROUND_FLOOR); + const feeAmount = amountToWithdraw.times(FEE.div(FEE_BASIS)).integerValue(BigNumber.ROUND_FLOOR) const amountToSwap = amountToWithdraw.minus(feeAmount) const { swapData } = await getSwapDataHelper({ args: { @@ -76,7 +76,7 @@ export const withdraw: AaveV3WithdrawToLTV = async (args, dependencies) => { swapAmount: amountToSwap, swapData: `${swapData.exchangeCalldata}`, debtTokenAddress: getTokenAddressFromDependencies(dependencies, debtTokenSymbol), - debtIsEth: debtTokenSymbol === 'ETH', + debtIsEth: debtTokenSymbol === 'WETH' || debtTokenSymbol === 'ETH', proxy: dependencies.proxy, addresses: dependencies.addresses, network: dependencies.network, @@ -97,7 +97,7 @@ export const withdraw: AaveV3WithdrawToLTV = async (args, dependencies) => { dependencies, currentPosition.collateral.symbol, ), - collateralIsEth: collateralTokenSymbol === 'ETH', + collateralIsEth: collateralTokenSymbol === 'ETH' || collateralTokenSymbol === 'WETH', proxy: dependencies.proxy, addresses: dependencies.addresses, network: dependencies.network, diff --git a/packages/dma-library/src/strategies/spark/auto/withdraw-to-ltv/index.ts b/packages/dma-library/src/strategies/spark/auto/withdraw-to-ltv/index.ts index 0e3c6f49..c204a9a3 100644 --- a/packages/dma-library/src/strategies/spark/auto/withdraw-to-ltv/index.ts +++ b/packages/dma-library/src/strategies/spark/auto/withdraw-to-ltv/index.ts @@ -1,4 +1,4 @@ -import { ZERO } from "@dma-common/constants"; +import { ZERO } from '@dma-common/constants' import { withdraw as withdrawOp } from '@dma-library/operations/spark/auto/withdraw' import { withdrawToDebt } from '@dma-library/operations/spark/auto/withdraw-to-debt' import { getAaveTokenAddress } from '@dma-library/strategies/aave/common' @@ -45,7 +45,7 @@ export const withdraw: SparkWithdrawToLTV = async (args, dependencies) => { if (args.shouldWithdrawToDebt) { const FEE = new BigNumber(20) const FEE_BASIS = new BigNumber(10000) - const feeAmount = amountToWithdraw.times(FEE.div(FEE_BASIS)).integerValue(BigNumber.ROUND_FLOOR); + const feeAmount = amountToWithdraw.times(FEE.div(FEE_BASIS)).integerValue(BigNumber.ROUND_FLOOR) const amountToSwap = amountToWithdraw.minus(feeAmount) const { swapData } = await getSwapDataHelper({ args: { @@ -74,7 +74,7 @@ export const withdraw: SparkWithdrawToLTV = async (args, dependencies) => { swapAmount: amountToSwap, swapData: `${swapData.exchangeCalldata}`, debtTokenAddress: getTokenAddressFromDependencies(dependencies, debtTokenSymbol), - debtIsEth: debtTokenSymbol === 'ETH', + debtIsEth: debtTokenSymbol === 'WETH' || debtTokenSymbol === 'ETH', proxy: dependencies.proxy, addresses: dependencies.addresses, network: dependencies.network, @@ -95,7 +95,7 @@ export const withdraw: SparkWithdrawToLTV = async (args, dependencies) => { dependencies, currentPosition.collateral.symbol, ), - collateralIsEth: collateralTokenSymbol === 'ETH', + collateralIsEth: collateralTokenSymbol === 'WETH' || collateralTokenSymbol === 'ETH', proxy: dependencies.proxy, addresses: dependencies.addresses, network: dependencies.network, @@ -141,10 +141,7 @@ function determineWithdrawalAmount( return amountToWithdraw } -function getTokenAddressFromDependencies( - deps: SparkWithdrawDependencies, - symbol: string, -) { +function getTokenAddressFromDependencies(deps: SparkWithdrawDependencies, symbol: string) { const address = deps.addresses.tokens[symbol] if (!address) {