Skip to content

Commit

Permalink
Merge pull request #12 from OasisDEX/jt/publish/coverage-fix
Browse files Browse the repository at this point in the history
feat(lib-coverag): Update version to 0.6.1-auto
  • Loading branch information
zerotucks authored Jun 19, 2024
2 parents a625963 + f1f20e8 commit 96b2905
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/dma-library/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<StrategyParams.WithFlashLoanArgs>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -38,14 +39,14 @@ export interface MorphoAdjustMultiplyPayload {
}

export type MorphoAdjustRiskStrategy = (
args: MorphoAdjustMultiplyPayload,
args: MorphoAdjustMultiplyPayload & StrategyParams.WithDebtCoverage,
dependencies: MorphoMultiplyDependencies,
) => Promise<SummerStrategy<MorphoBluePosition>>

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)) {
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 7 additions & 6 deletions packages/dma-library/src/strategies/morphoblue/multiply/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -33,29 +34,30 @@ export interface MorphoCloseMultiplyPayload {
}

export type MorphoCloseStrategy = (
args: MorphoCloseMultiplyPayload,
args: MorphoCloseMultiplyPayload & StrategyParams.WithDebtCoverage,
dependencies: MorphoMultiplyDependencies,
) => Promise<SummerStrategy<MorphoBluePosition>>

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
const collateralTokenSymbol = await getTokenSymbol(
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,
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit 96b2905

Please sign in to comment.