Skip to content

Commit

Permalink
feat: add adapter for mellow erc4626 (#141)
Browse files Browse the repository at this point in the history
* feat: add adapter for mellow erc4626

* fix: change type function to constant

* chore: warnings cleanup
  • Loading branch information
Van0k authored Jan 22, 2025
1 parent c314c17 commit f470525
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
8 changes: 7 additions & 1 deletion contracts/adapters/erc4626/ERC4626Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {IERC4626Adapter} from "../../interfaces/erc4626/IERC4626Adapter.sol";
/// @title ERC4626 Vault adapter
/// @notice Implements logic allowing CAs to interact with any standard-compliant ERC4626 vault
contract ERC4626Adapter is AbstractAdapter, IERC4626Adapter {
AdapterType public constant override _gearboxAdapterType = AdapterType.ERC4626_VAULT;
uint16 public constant override _gearboxAdapterVersion = 3_00;

/// @notice Address of the underlying asset of the vault
Expand All @@ -26,6 +25,10 @@ contract ERC4626Adapter is AbstractAdapter, IERC4626Adapter {
/// @notice Mask of the ERC4626 vault shares
uint256 public immutable override sharesMask;

function _gearboxAdapterType() external pure virtual override returns (AdapterType) {
return AdapterType.ERC4626_VAULT;
}

/// @notice Constructor
/// @param _creditManager Credit manager address
/// @param _vault ERC4626 vault address
Expand Down Expand Up @@ -96,6 +99,7 @@ contract ERC4626Adapter is AbstractAdapter, IERC4626Adapter {
/// @dev `receiver` and `owner` are ignored, since they are always set to the credit account address
function withdraw(uint256 assets, address, address)
external
virtual
override
creditFacadeOnly // U:[TV-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
Expand All @@ -110,6 +114,7 @@ contract ERC4626Adapter is AbstractAdapter, IERC4626Adapter {
/// @dev `receiver` and `owner` are ignored, since they are always set to the credit account address
function redeem(uint256 shares, address, address)
external
virtual
override
creditFacadeOnly // U:[TV-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
Expand All @@ -122,6 +127,7 @@ contract ERC4626Adapter is AbstractAdapter, IERC4626Adapter {
/// @param leftoverAmount Amount of vault token to keep on the account
function redeemDiff(uint256 leftoverAmount)
external
virtual
override
creditFacadeOnly // U:[TV-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
Expand Down
35 changes: 35 additions & 0 deletions contracts/adapters/mellow/Mellow4626VaultAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Gearbox Protocol. Generalized leverage for DeFi protocols
// (c) Gearbox Foundation, 2023.
pragma solidity ^0.8.17;

import {ERC4626Adapter} from "../erc4626/ERC4626Adapter.sol";
import {AdapterType} from "@gearbox-protocol/sdk-gov/contracts/AdapterType.sol";
import {NotImplementedException} from "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";

/// @title Mellow ERC4626 Vault adapter
/// @notice Implements logic allowing CAs to interact with a ERC4626 vaults, but with `withdraw` / `redeem` restricted, to avoid
/// CA's being exposed to Mellow's asynchronous withdrawals
contract Mellow4626VaultAdapter is ERC4626Adapter {
AdapterType public constant override _gearboxAdapterType = AdapterType.MELLOW_ERC4626_VAULT;

/// @notice Constructor
/// @param _creditManager Credit manager address
/// @param _vault ERC4626 vault address
constructor(address _creditManager, address _vault) ERC4626Adapter(_creditManager, _vault) {}

/// @dev For Mellow ERC4626 vaults all withdrawals revert to avoid CA's interacting with Mellow's delayed withdrawals
function withdraw(uint256, address, address) external view override creditFacadeOnly returns (uint256, uint256) {
revert NotImplementedException();
}

/// @dev For Mellow ERC4626 vaults all withdrawals revert to avoid CA's interacting with Mellow's delayed withdrawals
function redeem(uint256, address, address) external view override creditFacadeOnly returns (uint256, uint256) {
revert NotImplementedException();
}

/// @dev For Mellow ERC4626 vaults all withdrawals revert to avoid CA's interacting with Mellow's delayed withdrawals
function redeemDiff(uint256) external view override creditFacadeOnly returns (uint256, uint256) {
revert NotImplementedException();
}
}
19 changes: 19 additions & 0 deletions contracts/test/unit/adapters/erc4626/ERC4626Adapter.unit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ pragma solidity ^0.8.17;

import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {ERC4626Adapter} from "../../../../adapters/erc4626/ERC4626Adapter.sol";
import {Mellow4626VaultAdapter} from "../../../../adapters/mellow/Mellow4626VaultAdapter.sol";
import {AdapterUnitTestHelper} from "../AdapterUnitTestHelper.sol";
import {NotImplementedException} from "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";

/// @title ERC-4626 adapter unit test
/// @notice U:[TV]: Unit tests for ERC-4626 tokenized vault adapter
Expand Down Expand Up @@ -168,4 +170,21 @@ contract ERC4626AdapterUnitTest is AdapterUnitTestHelper {
assertEq(tokensToEnable, assetMask, "Incorrect tokensToEnable");
assertEq(tokensToDisable, diffDisableTokenIn ? sharesMask : 0, "Incorrect tokensToDisable");
}

/// @notice U:[TV-9]: withdrawal functions restricted for Mellow adapter
function test_U_TV_09_withdrawal_functions_restricted_for_mellow() public diffTestCases {
adapter = new Mellow4626VaultAdapter(address(creditManager), vault);

vm.expectRevert(NotImplementedException.selector);
vm.prank(creditFacade);
adapter.withdraw(1000, address(0), address(0));

vm.expectRevert(NotImplementedException.selector);
vm.prank(creditFacade);
adapter.redeem(1000, address(0), address(0));

vm.expectRevert(NotImplementedException.selector);
vm.prank(creditFacade);
adapter.redeemDiff(1000);
}
}

0 comments on commit f470525

Please sign in to comment.