diff --git a/packages/dma-library/src/strategies/aave-like/borrow/open-deposit-borrow/open-deposit-borrow.ts b/packages/dma-library/src/strategies/aave-like/borrow/open-deposit-borrow/open-deposit-borrow.ts index ef04d55bd..dce84bb1a 100644 --- a/packages/dma-library/src/strategies/aave-like/borrow/open-deposit-borrow/open-deposit-borrow.ts +++ b/packages/dma-library/src/strategies/aave-like/borrow/open-deposit-borrow/open-deposit-borrow.ts @@ -4,7 +4,6 @@ import { resolveAaveLikeOperations } from '@dma-library/operations/aave-like' import * as AaveCommon from '@dma-library/strategies/aave/common' import { getAaveTokenAddress } from '@dma-library/strategies/aave/common' import { IOperation } from '@dma-library/types' -import { AaveVersion } from '@dma-library/types/aave' import * as SwapUtils from '@dma-library/utils/swap' import { isAaveView, resolveAavelikeViews } from '@dma-library/views/aave-like' import { IPosition } from '@domain' @@ -127,10 +126,7 @@ async function resolveCurrentPositionForProtocol( if (isAaveView(view)) { if (!version) throw new Error('Version must be defined when using Aave view') - return await view.getCurrentPosition( - { ...args, proxy: dependencies.proxy }, - { ...dependencies, protocolVersion: version as AaveVersion }, - ) + return await view[version]({ ...args, proxy: dependencies.proxy }, { ...dependencies }) } - return await view.getCurrentPosition({ ...args, proxy: dependencies.proxy }, { ...dependencies }) + return await view({ ...args, proxy: dependencies.proxy }, { ...dependencies }) } diff --git a/packages/dma-library/src/strategies/aave/borrow/change-debt.ts b/packages/dma-library/src/strategies/aave/borrow/change-debt.ts index 54ed8cd68..44b81c5ca 100644 --- a/packages/dma-library/src/strategies/aave/borrow/change-debt.ts +++ b/packages/dma-library/src/strategies/aave/borrow/change-debt.ts @@ -1,8 +1,8 @@ import { ZERO } from '@dma-common/constants' import { AaveLikeStrategyAddresses } from '@dma-library/operations/aave-like' import { IViewPositionDependencies, IViewPositionParams, WithDebtChange } from '@dma-library/types' -import { AavePosition, AAVETokens, AaveVersion } from '@dma-library/types/aave' -import { getCurrentPosition } from '@dma-library/views/aave' +import { AavePosition, AAVETokens } from '@dma-library/types/aave' +import { views } from '@dma-library/views' export type AaveV2ChangeDebt = ( args: IViewPositionParams & WithDebtChange, @@ -10,18 +10,14 @@ export type AaveV2ChangeDebt = ( ) => Promise export const changeDebt: AaveV2ChangeDebt = async (args, { addresses, provider }) => { - const currentPosition = await getCurrentPosition(args, { + const currentPosition = await views.aave.v2(args, { addresses, provider, - protocolVersion: AaveVersion.v2, }) if (currentPosition.debt.amount.gt(ZERO)) { throw new Error('Debt must be zero to change debt') } - return await getCurrentPosition( - { ...args, debtToken: args.newDebtToken }, - { addresses, provider, protocolVersion: AaveVersion.v2 }, - ) + return await views.aave.v2({ ...args, debtToken: args.newDebtToken }, { addresses, provider }) } diff --git a/packages/dma-library/src/strategies/aave/index.ts b/packages/dma-library/src/strategies/aave/index.ts index 0e460b3c2..6c45dd014 100644 --- a/packages/dma-library/src/strategies/aave/index.ts +++ b/packages/dma-library/src/strategies/aave/index.ts @@ -1,7 +1,7 @@ import { getAaveProtocolData } from '@dma-library/protocols/aave/get-aave-protocol-data' import { PositionTransition } from '@dma-library/types' import { AaveVersion } from '@dma-library/types/aave' -import { getCurrentPosition } from '@dma-library/views/aave' +import { views } from '@dma-library/views' import { AaveV2ChangeDebt, changeDebt } from './borrow/change-debt' import { AaveV2DepositBorrow, AaveV3DepositBorrow, depositBorrow } from './borrow/deposit-borrow' @@ -34,7 +34,7 @@ export const aave: { v2: { changeDebt: AaveV2ChangeDebt depositBorrow: AaveV2DepositBorrow - openDepositAndBorrowDebt: AaveV2OpenDepositBorrow + openDepositBorrow: AaveV2OpenDepositBorrow paybackWithdraw: AaveV2PaybackWithdraw } v3: { @@ -82,16 +82,16 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v2, - getCurrentPosition, + getCurrentPosition: views.aave.v2, getProtocolData: getAaveProtocolData, }, }), - openDepositAndBorrowDebt: (args, dependencies) => + openDepositBorrow: (args, dependencies) => openDepositBorrow(args, { ...dependencies, protocol: { version: AaveVersion.v2, - getCurrentPosition, + getCurrentPosition: views.aave.v2, getProtocolData: getAaveProtocolData, }, }), @@ -100,7 +100,7 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v2, - getCurrentPosition, + getCurrentPosition: views.aave.v2, getProtocolData: getAaveProtocolData, }, }), @@ -111,7 +111,7 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v3, - getCurrentPosition, + getCurrentPosition: views.aave.v3, getProtocolData: getAaveProtocolData, }, }), @@ -120,7 +120,7 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v3, - getCurrentPosition, + getCurrentPosition: views.aave.v3, getProtocolData: getAaveProtocolData, }, }), @@ -129,7 +129,7 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v3, - getCurrentPosition, + getCurrentPosition: views.aave.v3, getProtocolData: getAaveProtocolData, }, }), @@ -142,7 +142,7 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v2, - getCurrentPosition, + getCurrentPosition: views.aave.v2, getProtocolData: getAaveProtocolData, }, }), @@ -153,7 +153,7 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v2, - getCurrentPosition, + getCurrentPosition: views.aave.v2, getProtocolData: getAaveProtocolData, }, }), @@ -164,7 +164,7 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v3, - getCurrentPosition, + getCurrentPosition: views.aave.v3, getProtocolData: getAaveProtocolData, }, }), @@ -175,7 +175,7 @@ export const aave: { ...dependencies, protocol: { version: AaveVersion.v3, - getCurrentPosition, + getCurrentPosition: views.aave.v3, getProtocolData: getAaveProtocolData, }, }), diff --git a/packages/dma-library/src/strategies/spark/borrow/deposit-borrow/types.ts b/packages/dma-library/src/strategies/spark/borrow/deposit-borrow/types.ts index 398ea9cf0..82684d5ff 100644 --- a/packages/dma-library/src/strategies/spark/borrow/deposit-borrow/types.ts +++ b/packages/dma-library/src/strategies/spark/borrow/deposit-borrow/types.ts @@ -6,7 +6,10 @@ export type SparkDepositBorrowArgs = StrategyParams.WithAaveLikeBorrowStrategyAr StrategyParams.WithDepositCollateral & StrategyParams.WithBorrowDebt -export type SparkDepositBorrowDependencies = StrategyParams.WithAaveLikeStrategyDependencies & +export type SparkDepositBorrowDependencies = Omit< + StrategyParams.WithAaveLikeStrategyDependencies, + 'protocolType' +> & StrategyParams.WithOptionalSwap export type IDepositBorrowStrategy = Strategies.IStrategy & { diff --git a/packages/dma-library/src/strategies/spark/borrow/open-deposit-borrow/types.ts b/packages/dma-library/src/strategies/spark/borrow/open-deposit-borrow/types.ts index f6246cbae..9682faa37 100644 --- a/packages/dma-library/src/strategies/spark/borrow/open-deposit-borrow/types.ts +++ b/packages/dma-library/src/strategies/spark/borrow/open-deposit-borrow/types.ts @@ -9,7 +9,10 @@ export type SparkOpenDepositBorrowArgs = SparkDepositBorrowArgs type IOpenDepositBorrowStrategy = IDepositBorrowStrategy -export type SparkOpenDepositBorrowDependencies = SparkDepositBorrowDependencies & +export type SparkOpenDepositBorrowDependencies = Omit< + SparkDepositBorrowDependencies, + 'currentPosition' +> & StrategyParams.WithPositionType export type SparkOpenDepositBorrow = ( args: SparkOpenDepositBorrowArgs, diff --git a/packages/dma-library/src/views/aave/index.ts b/packages/dma-library/src/views/aave/index.ts index 323b41ef0..f0f07c2a8 100644 --- a/packages/dma-library/src/views/aave/index.ts +++ b/packages/dma-library/src/views/aave/index.ts @@ -3,7 +3,6 @@ import * as AaveCommon from '@dma-library/strategies/aave/common' import { AavePosition } from '@dma-library/types/aave' import { AaveGetCurrentPositionArgs, - AaveGetCurrentPositionDependencies, AaveV2GetCurrentPositionDependencies, AaveV3GetCurrentPositionDependencies, } from '@dma-library/views/aave/types' @@ -16,7 +15,6 @@ export { AaveV3GetCurrentPositionDependencies, } export type AaveView = { - getCurrentPosition: AaveGetCurrentPosition v2: ( args: AaveGetCurrentPositionArgs, dependencies: Omit, @@ -27,29 +25,6 @@ export type AaveView = { ) => Promise } -export type AaveGetCurrentPosition = ( - args: AaveGetCurrentPositionArgs, - addresses: AaveGetCurrentPositionDependencies, -) => Promise - -export const getCurrentPosition: AaveGetCurrentPosition = async (args, dependencies) => { - if ( - AaveCommon.isV2( - dependencies, - ) - ) { - return getCurrentPositionAaveV2(args, dependencies) - } else if ( - AaveCommon.isV3( - dependencies, - ) - ) { - return getCurrentPositionAaveV3(args, dependencies) - } else { - throw new Error('Invalid Aave version') - } -} - export type AaveV2GetCurrentPosition = ( args: AaveGetCurrentPositionArgs, dependencies: AaveV2GetCurrentPositionDependencies, diff --git a/packages/dma-library/src/views/index.ts b/packages/dma-library/src/views/index.ts index 3dca1c9cc..c5f0e628b 100644 --- a/packages/dma-library/src/views/index.ts +++ b/packages/dma-library/src/views/index.ts @@ -3,10 +3,9 @@ import { AaveVersion } from '@dma-library/types/aave' import { AaveView, getCurrentPositionAaveV2, getCurrentPositionAaveV3 } from './aave' import type { GetEarnData } from './ajna' import { getEarnPosition, getPosition } from './ajna' -import { getCurrentPosition, SparkView } from './spark' +import { getCurrentSparkPosition, SparkView } from './spark' const aave: AaveView = { - getCurrentPosition, v2: (args, dependencies) => getCurrentPositionAaveV2(args, { ...dependencies, @@ -18,9 +17,7 @@ const aave: AaveView = { protocolVersion: AaveVersion.v3, }), } -const spark: SparkView = { - getCurrentPosition: getCurrentPosition, -} +const spark: SparkView = getCurrentSparkPosition const ajna = { getPosition, getEarnPosition, diff --git a/packages/dma-library/src/views/spark/index.ts b/packages/dma-library/src/views/spark/index.ts index abc739c46..c3dc212b3 100644 --- a/packages/dma-library/src/views/spark/index.ts +++ b/packages/dma-library/src/views/spark/index.ts @@ -8,16 +8,14 @@ import { } from '@dma-library/views/spark/types' import BigNumber from 'bignumber.js' -export type SparkView = { - getCurrentPosition: SparkGetCurrentPosition -} +export type SparkView = SparkGetCurrentPosition export type SparkGetCurrentPosition = ( args: SparkGetCurrentPositionArgs, addresses: SparkGetCurrentPositionDependencies, ) => Promise -export const getCurrentPosition: SparkGetCurrentPosition = async (args, dependencies) => { +export const getCurrentSparkPosition: SparkGetCurrentPosition = async (args, dependencies) => { const debtToken = args.debtToken const collateralToken = args.collateralToken const { collateralTokenAddress, debtTokenAddress } = AaveCommon.getAaveTokenAddresses(