-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create close-and-remain ops in library using new definitions
- Loading branch information
Showing
7 changed files
with
149 additions
and
73 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
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
64 changes: 0 additions & 64 deletions
64
packages/deploy-configurations/operation-definitions/spark/multiply/close-and-remain.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/deploy-configurations/operation-definitions/spark/multiply/index.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,4 +1,4 @@ | ||
export { getSparkAdjustDownOperationDefinition } from './adjust-down' | ||
export { getSparkAdjustUpOperationDefinition } from './adjust-up' | ||
export { getSparkCloseOperationDefinition } from './close' | ||
export { getSparkCloseAndExitOperationDefinition } from './close-and-exit' | ||
export { getSparkOpenOperationDefinition } from './open' |
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
139 changes: 139 additions & 0 deletions
139
packages/dma-library/src/operations/aave/multiply/v3/close-and-remain.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 |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { getAaveV3CloseAndRemainOperationDefinition } from '@deploy-configurations/operation-definitions' | ||
import { ZERO } from '@dma-common/constants' | ||
import { actions } from '@dma-library/actions' | ||
import { | ||
IOperation, | ||
WithCollateral, | ||
WithDebt, | ||
WithFlashloan, | ||
WithNetwork, | ||
WithPositionAndLockedCollateral, | ||
WithProxy, | ||
WithSwap, | ||
} from '@dma-library/types' | ||
import { WithAaveLikeStrategyAddresses } from '@dma-library/types/operations' | ||
|
||
export type CloseArgs = WithCollateral & | ||
WithDebt & | ||
WithSwap & | ||
WithFlashloan & | ||
WithProxy & | ||
WithPositionAndLockedCollateral & | ||
WithAaveLikeStrategyAddresses & | ||
WithNetwork | ||
|
||
export type AaveV3CloseOperation = ({ | ||
collateral, | ||
debt, | ||
swap, | ||
flashloan, | ||
proxy, | ||
position, | ||
addresses, | ||
network, | ||
}: CloseArgs) => Promise<IOperation> | ||
|
||
export const close: AaveV3CloseOperation = async ({ | ||
collateral, | ||
debt, | ||
swap, | ||
flashloan, | ||
proxy, | ||
position: { | ||
collateral: { amount: collateralAmountToBeSwapped }, | ||
}, | ||
addresses, | ||
network, | ||
}) => { | ||
const setEModeOnCollateral = actions.aave.v3.aaveV3SetEMode(network, { | ||
categoryId: 0, | ||
}) | ||
|
||
const setFlashLoanApproval = actions.common.setApproval(network, { | ||
amount: flashloan.token.amount, | ||
asset: flashloan.token.address, | ||
delegate: addresses.lendingPool, | ||
sumAmounts: false, | ||
}) | ||
|
||
const depositFlashLoan = actions.aave.v3.aaveV3Deposit(network, { | ||
amount: flashloan.token.amount, | ||
asset: flashloan.token.address, | ||
sumAmounts: false, | ||
// setAsCollateral: true | ||
}) | ||
|
||
const withdrawCollateralFromAAVE = actions.aave.v3.aaveV3Withdraw(network, { | ||
asset: collateral.address, | ||
amount: collateralAmountToBeSwapped, | ||
to: proxy.address, | ||
}) | ||
|
||
const swapCollateralTokensForDebtTokens = actions.common.swap(network, { | ||
fromAsset: collateral.address, | ||
toAsset: debt.address, | ||
amount: collateralAmountToBeSwapped || ZERO, | ||
receiveAtLeast: swap.receiveAtLeast, | ||
fee: swap.fee, | ||
withData: swap.data, | ||
collectFeeInFromToken: swap.collectFeeFrom === 'sourceToken', | ||
}) | ||
|
||
const swapActionStorageIndex = 4 | ||
const setDebtTokenApprovalOnLendingPool = actions.common.setApproval( | ||
network, | ||
{ | ||
asset: debt.address, | ||
delegate: addresses.lendingPool, | ||
amount: ZERO, | ||
sumAmounts: true, | ||
}, | ||
[0, 0, swapActionStorageIndex, 0], | ||
) | ||
|
||
const paybackInAAVE = actions.aave.v3.aaveV3Payback(network, { | ||
asset: debt.address, | ||
amount: ZERO, | ||
paybackAll: true, | ||
}) | ||
|
||
const withdrawFlashLoan = actions.aave.v3.aaveV3WithdrawAuto( | ||
network, | ||
{ | ||
asset: flashloan.token.address, | ||
amount: flashloan.token.amount, | ||
to: addresses.operationExecutor, | ||
}, | ||
[1], | ||
) | ||
|
||
const returnDebtFunds = actions.common.returnFunds(network, { | ||
asset: debt.isEth ? addresses.tokens.ETH : debt.address, | ||
}) | ||
|
||
const takeAFlashLoan = actions.common.takeAFlashLoanBalancer(network, { | ||
isDPMProxy: proxy.isDPMProxy, | ||
asset: flashloan.token.address, | ||
flashloanAmount: flashloan.token.amount, | ||
isProxyFlashloan: true, | ||
provider: flashloan.provider, | ||
calls: [ | ||
setFlashLoanApproval, | ||
depositFlashLoan, | ||
withdrawCollateralFromAAVE, | ||
swapCollateralTokensForDebtTokens, | ||
setDebtTokenApprovalOnLendingPool, | ||
paybackInAAVE, | ||
withdrawFlashLoan, | ||
// see deploy-configurations/operation-definitions/aave/v3/close-and-remain.ts | ||
// withdrawCollateral, | ||
returnDebtFunds, | ||
// returnCollateralFunds, | ||
], | ||
}) | ||
|
||
return { | ||
calls: [takeAFlashLoan, setEModeOnCollateral], | ||
operationName: getAaveV3CloseAndRemainOperationDefinition(network).name, | ||
} | ||
} |
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