From 3c8a995b5425ca554c230f9e75c8c42af69bc9e6 Mon Sep 17 00:00:00 2001 From: halaprix Date: Tue, 13 Aug 2024 20:49:08 +0200 Subject: [PATCH] chore: use maker for dai flashloans --- packages/dma-library/package.json | 2 +- .../src/strategies/morphoblue/multiply/adjust.ts | 6 ++++-- .../dma-library/src/strategies/morphoblue/multiply/close.ts | 5 ++++- .../dma-library/src/strategies/morphoblue/multiply/open.ts | 4 +++- .../dma-library/src/utils/flashloan/resolve-provider.ts | 4 +++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/dma-library/package.json b/packages/dma-library/package.json index 44319a1b9..95ec5e9ab 100644 --- a/packages/dma-library/package.json +++ b/packages/dma-library/package.json @@ -1,6 +1,6 @@ { "name": "@oasisdex/dma-library", - "version": "0.6.62", + "version": "0.6.63", "typings": "lib/index.d.ts", "types": "lib/index.d.ts", "main": "lib/index.js", diff --git a/packages/dma-library/src/strategies/morphoblue/multiply/adjust.ts b/packages/dma-library/src/strategies/morphoblue/multiply/adjust.ts index c93b48038..6938e7b6b 100644 --- a/packages/dma-library/src/strategies/morphoblue/multiply/adjust.ts +++ b/packages/dma-library/src/strategies/morphoblue/multiply/adjust.ts @@ -236,6 +236,8 @@ async function buildOperation( }) const network = await getNetwork(dependencies.provider) + const isDai = + args.position.marketParams.loanToken.toLowerCase() === dependencies.addresses.DAI.toLowerCase() const morphoBlueMarket = { loanToken: args.position.marketParams.loanToken, @@ -302,7 +304,7 @@ async function buildOperation( address: args.position.marketParams.loanToken, }, amount: Domain.debtToCollateralSwapFlashloan(swapAmountBeforeFees), - provider: FlashloanProvider.Balancer, + provider: isDai ? FlashloanProvider.DssFlash : FlashloanProvider.Balancer, }, } @@ -327,7 +329,7 @@ async function buildOperation( address: args.position.marketParams.loanToken, }, amount: Domain.collateralToDebtSwapFlashloan(swapData.minToTokenAmount), - provider: FlashloanProvider.Balancer, + provider: isDai ? FlashloanProvider.DssFlash : FlashloanProvider.Balancer, }, } diff --git a/packages/dma-library/src/strategies/morphoblue/multiply/close.ts b/packages/dma-library/src/strategies/morphoblue/multiply/close.ts index b7864ef4d..974011dd4 100644 --- a/packages/dma-library/src/strategies/morphoblue/multiply/close.ts +++ b/packages/dma-library/src/strategies/morphoblue/multiply/close.ts @@ -224,6 +224,9 @@ async function buildOperation( ? swapData.fromTokenAmount.plus(preSwapFee) : lockedCollateralAmount + const isDai = + args.position.marketParams.loanToken.toLowerCase() === dependencies.addresses.DAI.toLowerCase() + const closeArgs = { collateral: { address: collateralToken.address, @@ -245,7 +248,7 @@ async function buildOperation( amount: Domain.debtToCollateralSwapFlashloan(amountToFlashloan), address: position.marketParams.loanToken, }, - provider: FlashloanProvider.Balancer, + provider: isDai ? FlashloanProvider.DssFlash : FlashloanProvider.Balancer, amount: Domain.debtToCollateralSwapFlashloan(amountToFlashloan), }, position: { diff --git a/packages/dma-library/src/strategies/morphoblue/multiply/open.ts b/packages/dma-library/src/strategies/morphoblue/multiply/open.ts index 07dae6f87..7ef036ef3 100644 --- a/packages/dma-library/src/strategies/morphoblue/multiply/open.ts +++ b/packages/dma-library/src/strategies/morphoblue/multiply/open.ts @@ -348,6 +348,8 @@ async function buildOperation( }) const network = await getNetwork(dependencies.provider) + const isDai = + position.marketParams.loanToken.toLowerCase() === dependencies.addresses.DAI.toLowerCase() const openMultiplyArgs: MorphoBlueOpenOperationArgs = { morphoBlueMarket: { @@ -385,7 +387,7 @@ async function buildOperation( address: position.marketParams.loanToken, }, amount: Domain.debtToCollateralSwapFlashloan(swapAmountBeforeFees), - provider: FlashloanProvider.Balancer, + provider: isDai ? FlashloanProvider.DssFlash : FlashloanProvider.Balancer, }, position: { type: positionType, diff --git a/packages/dma-library/src/utils/flashloan/resolve-provider.ts b/packages/dma-library/src/utils/flashloan/resolve-provider.ts index ca4de4b09..694bd3e27 100644 --- a/packages/dma-library/src/utils/flashloan/resolve-provider.ts +++ b/packages/dma-library/src/utils/flashloan/resolve-provider.ts @@ -25,7 +25,9 @@ export function resolveFlashloanProvider({ if (lendingProtocol === 'Spark' && debtToken !== 'DAI') { return FlashloanProvider.Balancer } - + if (lendingProtocol === 'MorphoBlue' && debtToken !== 'DAI') { + return FlashloanProvider.Balancer + } if ( lendingProtocol === 'AAVE_V3' && aaveIsolatedCollateralTokens.includes(collateralToken.toUpperCase())