-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
31 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 4 additions & 8 deletions
12
packages/dma-library/src/strategies/aave/borrow/change-debt.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
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<AAVETokens> & WithDebtChange<AAVETokens>, | ||
{ addresses, provider }: IViewPositionDependencies<AaveLikeStrategyAddresses>, | ||
) => Promise<AavePosition> | ||
|
||
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 }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters