diff --git a/packages/dma-library/package.json b/packages/dma-library/package.json index 3fb09e5b..59e6d865 100644 --- a/packages/dma-library/package.json +++ b/packages/dma-library/package.json @@ -1,6 +1,6 @@ { "name": "@oasisdex/dma-library", - "version": "0.6.6-automation", + "version": "0.6.7-auto-rc2", "typings": "lib/index.d.ts", "types": "lib/index.d.ts", "main": "lib/index.js", 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 14f185bf..2ad14f2f 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 @@ -16,6 +16,12 @@ export const close: AaveLikeClose = async (args, dependencies) => { ? getAaveSwapDataToCloseToCollateral : getAaveSwapDataToCloseToDebt + if (!args.debtCoverage.isZero()) { + dependencies.currentPosition.debt.amount = dependencies.currentPosition.debt.amount.plus( + args.debtCoverage, + ) + } + const collateralTokenAddress = getAaveTokenAddress(args.collateralToken, dependencies.addresses) const debtTokenAddress = getAaveTokenAddress(args.debtToken, dependencies.addresses) const flashloanArgs = diff --git a/packages/dma-library/src/strategies/aave-like/multiply/close/types.ts b/packages/dma-library/src/strategies/aave-like/multiply/close/types.ts index 146ae629..720b1284 100644 --- a/packages/dma-library/src/strategies/aave-like/multiply/close/types.ts +++ b/packages/dma-library/src/strategies/aave-like/multiply/close/types.ts @@ -5,6 +5,7 @@ import { WithFlashLoanArgs } from '@dma-library/types/strategy-params' import { BigNumber } from 'bignumber.js' export type AaveLikeCloseArgs = StrategyParams.WithAaveLikeMultiplyStrategyArgs & + StrategyParams.WithDebtCoverage & StrategyParams.WithCloseToCollateralFlag & Partial diff --git a/packages/dma-library/src/strategies/morphoblue/multiply/adjust.ts b/packages/dma-library/src/strategies/morphoblue/multiply/adjust.ts index c93b4803..76bcb709 100644 --- a/packages/dma-library/src/strategies/morphoblue/multiply/adjust.ts +++ b/packages/dma-library/src/strategies/morphoblue/multiply/adjust.ts @@ -12,6 +12,7 @@ import { SwapData, } from '@dma-library/types' import { SummerStrategy } from '@dma-library/types/ajna/ajna-strategy' +import * as StrategyParams from '@dma-library/types/strategy-params' import * as SwapUtils from '@dma-library/utils/swap' import * as Domain from '@domain' import { isRiskIncreasing } from '@domain/utils' @@ -38,14 +39,14 @@ export interface MorphoAdjustMultiplyPayload { } export type MorphoAdjustRiskStrategy = ( - args: MorphoAdjustMultiplyPayload, + args: MorphoAdjustMultiplyPayload & StrategyParams.WithDebtCoverage, dependencies: MorphoMultiplyDependencies, ) => Promise> const positionType: PositionType = 'Multiply' export const adjustMultiply: MorphoAdjustRiskStrategy = ( - args: MorphoAdjustMultiplyPayload, + args: MorphoAdjustMultiplyPayload & StrategyParams.WithDebtCoverage, dependencies: MorphoMultiplyDependencies, ) => { if (isRiskIncreasing(args.riskRatio.loanToValue, args.position.riskRatio.loanToValue)) { @@ -83,6 +84,10 @@ const adjustRiskUp: MorphoAdjustRiskStrategy = async (args, dependencies) => { }, } + if (!args.debtCoverage.isZero()) { + mappedPosition.debtAmount = mappedPosition.debtAmount.plus(args.debtCoverage) + } + // Simulate adjust const riskIsIncreasing = true const simulatedAdjustment = await simulateAdjustment( diff --git a/packages/dma-library/src/strategies/morphoblue/multiply/close.ts b/packages/dma-library/src/strategies/morphoblue/multiply/close.ts index a053dc5d..573b2775 100644 --- a/packages/dma-library/src/strategies/morphoblue/multiply/close.ts +++ b/packages/dma-library/src/strategies/morphoblue/multiply/close.ts @@ -15,6 +15,7 @@ import { SwapData, } from '@dma-library/types' import { StrategyError, StrategyWarning } from '@dma-library/types/ajna/ajna-validations' +import * as StrategyParams from "@dma-library/types/strategy-params"; import { encodeOperation } from '@dma-library/utils/operation' import * as SwapUtils from '@dma-library/utils/swap' import * as Domain from '@domain' @@ -33,7 +34,7 @@ export interface MorphoCloseMultiplyPayload { } export type MorphoCloseStrategy = ( - args: MorphoCloseMultiplyPayload, + args: MorphoCloseMultiplyPayload & StrategyParams.WithDebtCoverage, dependencies: MorphoMultiplyDependencies, ) => Promise> @@ -41,8 +42,11 @@ const positionType: PositionType = 'Multiply' export const closeMultiply: MorphoCloseStrategy = async (args, dependencies) => { const position = args.position - console.log("MB Close Multiply") - console.log("shouldCloseToCollateral", args.shouldCloseToCollateral) + + if (!args.debtCoverage.isZero()) { + position.debtAmount = position.debtAmount.plus(args.debtCoverage) + } + const getSwapData = args.shouldCloseToCollateral ? getMorphoSwapDataToCloseToCollateral : getMorphoSwapDataToCloseToDebt @@ -50,12 +54,10 @@ export const closeMultiply: MorphoCloseStrategy = async (args, dependencies) => args.position.marketParams.collateralToken, dependencies.provider, ) - console.log("collateralTokenSymbol", collateralTokenSymbol) const debtTokenSymbol = await getTokenSymbol( args.position.marketParams.loanToken, dependencies.provider, ) - console.log("debtTokenSymbol", debtTokenSymbol) const { swapData, collectFeeFrom, preSwapFee } = await getSwapData( args, @@ -157,7 +159,6 @@ async function getMorphoSwapDataToCloseToCollateral( collateralTokenSymbol: string, debtTokenSymbol: string, ) { - console.log("Morpho Clsoing to Coll...") const outstandingDebt = amountToWei(position.debtAmount, args.quoteTokenPrecision).integerValue( BigNumber.ROUND_DOWN, )