Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free the morpho #24

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions contracts/SupplyVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {
using MarketParamsLib for MarketParams;
using MorphoBalancesLib for IMorpho;

IMorpho internal immutable _MORPHO;
IMorpho public immutable MORPHO;

mapping(address => bool) public isRiskManager;
mapping(address => bool) public isAllocator;
Expand All @@ -51,7 +51,7 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {
ERC4626(_asset)
ERC20(_name, _symbol)
{
_MORPHO = IMorpho(morpho);
MORPHO = IMorpho(morpho);

SafeERC20.safeApprove(_asset, morpho, type(uint256).max);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {
onlyRiskManager
{
require(marketParams.borrowableToken == asset(), ErrorsLib.INCONSISTENT_ASSET);
(,,,, uint128 lastUpdate,) = _MORPHO.market(marketParams.id());
(,,,, uint128 lastUpdate,) = MORPHO.market(marketParams.id());
require(lastUpdate != 0, ErrorsLib.MARKET_NOT_CREATED);

Id id = marketParams.id();
Expand Down Expand Up @@ -249,7 +249,7 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {
}

function _supplyBalance(MarketParams memory marketParams) internal view returns (uint256) {
return _MORPHO.expectedSupplyBalance(marketParams, address(this));
return MORPHO.expectedSupplyBalance(marketParams, address(this));
}

function _supplyMorpho(MarketAllocation memory allocation) internal {
Expand All @@ -263,7 +263,7 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {
require(newSupply <= cap, ErrorsLib.SUPPLY_CAP_EXCEEDED);
}

_MORPHO.supply(allocation.marketParams, allocation.assets, 0, address(this), hex"");
MORPHO.supply(allocation.marketParams, allocation.assets, 0, address(this), hex"");
}

function _reallocate(MarketAllocation[] memory withdrawn, MarketAllocation[] memory supplied) internal {
Expand All @@ -272,7 +272,7 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {
for (uint256 i; i < nbWithdrawn; ++i) {
MarketAllocation memory allocation = withdrawn[i];

_MORPHO.withdraw(allocation.marketParams, allocation.assets, 0, address(this), address(this));
MORPHO.withdraw(allocation.marketParams, allocation.assets, 0, address(this), address(this));
}

uint256 nbSupplied = supplied.length;
Expand Down Expand Up @@ -302,8 +302,8 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {

if (toDeposit > 0) {
bytes memory encodedCall =
abi.encodeCall(_MORPHO.supply, (marketParams, toDeposit, 0, address(this), hex""));
(bool success,) = address(_MORPHO).call(encodedCall);
abi.encodeCall(MORPHO.supply, (marketParams, toDeposit, 0, address(this), hex""));
(bool success,) = address(MORPHO).call(encodedCall);

if (success) assets -= toDeposit;
}
Expand All @@ -323,8 +323,8 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {

if (toWithdraw > 0) {
bytes memory encodedCall =
abi.encodeCall(_MORPHO.withdraw, (marketParams, toWithdraw, 0, address(this), address(this)));
(bool success,) = address(_MORPHO).staticcall(encodedCall);
abi.encodeCall(MORPHO.withdraw, (marketParams, toWithdraw, 0, address(this), address(this)));
(bool success,) = address(MORPHO).staticcall(encodedCall);

if (success) assets -= toWithdraw;
}
Expand All @@ -344,8 +344,8 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {

if (toWithdraw > 0) {
bytes memory encodedCall =
abi.encodeCall(_MORPHO.withdraw, (marketParams, toWithdraw, 0, address(this), address(this)));
(bool success,) = address(_MORPHO).call(encodedCall);
abi.encodeCall(MORPHO.withdraw, (marketParams, toWithdraw, 0, address(this), address(this)));
(bool success,) = address(MORPHO).call(encodedCall);

if (success) assets -= toWithdraw;
}
Expand All @@ -362,7 +362,7 @@ contract SupplyVault is ERC4626, Ownable2Step, ISupplyVault {
returns (MarketParams memory marketParams, uint256 withdrawable)
{
marketParams = _config.at(_config.getMarket(id).rank);
(uint256 totalSupply,, uint256 totalBorrow,) = _MORPHO.expectedMarketBalances(marketParams);
(uint256 totalSupply,, uint256 totalBorrow,) = MORPHO.expectedMarketBalances(marketParams);
uint256 available = totalBorrow - totalSupply;
withdrawable = UtilsLib.min(available, assets);
}
Expand Down