-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from sogipec/4626-provider
feat: add an ERC4626 rate provider
- Loading branch information
Showing
4 changed files
with
84 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/interfaces/IERC4626.sol"; | ||
|
||
import "./interfaces/IRateProvider.sol"; | ||
|
||
/** | ||
* @title ERC4626 Rate Provider | ||
* @notice Returns an 18 decimal fixed point number that is the exchange rate of the | ||
* shares of an ERC4626 to the underlying asset | ||
*/ | ||
contract ERC4626RateProvider is IRateProvider { | ||
IERC4626 public immutable erc4626; | ||
uint256 public immutable fixedPointOne; | ||
|
||
constructor(IERC4626 _erc4626) { | ||
erc4626 = _erc4626; | ||
uint256 underlyingDecimals = IERC4626(_erc4626.asset()).decimals(); | ||
// Balancer does not support tokens with more than 18 decimals so this will never underflow | ||
fixedPointOne = 10**(18 + _erc4626.decimals() - underlyingDecimals); | ||
} | ||
|
||
/** | ||
* @return An 18 decimal fixed point number that is the exchange rate of the | ||
* shares of an ERC4626 to the underlying asset | ||
*/ | ||
function getRate() external view override returns (uint256) { | ||
return erc4626.convertToAssets(fixedPointOne); | ||
} | ||
} |
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,35 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./BaseRateProviderFactory.sol"; | ||
import "./ERC4626RateProvider.sol"; | ||
|
||
/** | ||
* @title ERC4626 Rate Provider Factory | ||
* @notice Factory for creating ERC4626RateProviders | ||
* @dev This contract is used to create ERC4626RateProvider contracts. | ||
*/ | ||
contract ERC4626RateProviderFactory is BaseRateProviderFactory { | ||
/** | ||
* @notice Deploys a new ERC4626RateProvider contract using an ERC4626 contract. | ||
* @param erc4626 - The ERC4626 contract. | ||
*/ | ||
function create(IERC4626 erc4626) external returns (ERC4626RateProvider) { | ||
ERC4626RateProvider rateProvider = new ERC4626RateProvider(erc4626); | ||
_onCreate(address(rateProvider)); | ||
return rateProvider; | ||
} | ||
} |
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