-
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: add WithdrawAuto and correct dumb mistakes
- Loading branch information
Showing
7 changed files
with
218 additions
and
111 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
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: 7 additions & 5 deletions
12
packages/dma-contracts/contracts/actions/morpho-blue/Withdraw.sol
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
49 changes: 49 additions & 0 deletions
49
packages/dma-contracts/contracts/actions/morpho-blue/WithdrawAuto.sol
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,49 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity ^0.8.15; | ||
|
||
import { Executable } from "../common/Executable.sol"; | ||
import { UseStorageSlot, StorageSlot, Write, Read } from "../../libs/UseStorageSlot.sol"; | ||
import { ServiceRegistry } from "../../core/ServiceRegistry.sol"; | ||
import { WithdrawData } from "../../core/types/MorphoBlue.sol"; | ||
import { MORPHO_BLUE } from "../../core/constants/MorphoBlue.sol"; | ||
import { IMorpho } from "../../interfaces/morpho-blue/IMorpho.sol"; | ||
import { UseRegistry } from "../../libs/UseRegistry.sol"; | ||
|
||
/** | ||
* @title Withdraw | MorphoBlue Action contract | ||
* @notice Withdraw collateral from Morpho Blue's lending pool | ||
* with the amount to withdraw being read from an OperationStorage slot | ||
*/ | ||
contract MorphoBlueWithdrawAuto is Executable, UseStorageSlot, UseRegistry { | ||
using Write for StorageSlot.TransactionStorage; | ||
using Read for StorageSlot.TransactionStorage; | ||
|
||
constructor(address _registry) UseRegistry(ServiceRegistry(_registry)) {} | ||
|
||
/** | ||
* @param data Encoded calldata that conforms to the WithdrawData struct | ||
*/ | ||
function execute(bytes calldata data, uint8[] memory paramsMap) external payable override { | ||
WithdrawData memory withdraw = parseInputs(data); | ||
|
||
uint256 mappedWithdrawAmount = store().readUint( | ||
bytes32(0), | ||
paramsMap[0] | ||
); | ||
|
||
IMorpho morphoBlue = IMorpho(getRegisteredService(MORPHO_BLUE)); | ||
morphoBlue.withdrawCollateral( | ||
withdraw.marketParams, | ||
mappedWithdrawAmount, | ||
address(this), | ||
withdraw.to | ||
); | ||
|
||
store().write(bytes32(mappedWithdrawAmount)); | ||
} | ||
|
||
function parseInputs(bytes memory _callData) public pure returns (WithdrawData memory params) { | ||
return abi.decode(_callData, (WithdrawData)); | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -24,4 +24,5 @@ struct PaybackData { | |
MarketParams marketParams; | ||
uint256 amount; | ||
address onBehalf; | ||
bool paybackAll; | ||
} |
Oops, something went wrong.