Skip to content

Commit

Permalink
feat: add an ERC4626 rate provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sogipec committed Sep 29, 2023
1 parent 8793212 commit 3328bdb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
39 changes: 39 additions & 0 deletions contracts/ERC4626RateProvider.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 "./interfaces/IRateProvider.sol";
import "@openzeppelin/contracts/interfaces/IERC4626.sol";

/**
* @title ERC4626 Rate Provider
* @notice Returns the value of 1 share of an ERC4626 in terms of the underlying asset
*/
contract ERC4626RateProvider is IRateProvider {
IERC4626 public immutable erc4626;
uint256 public immutable baseDecimals;

constructor(IERC4626 _erc4626) {
erc4626 = _erc4626;
baseDecimals = 10**(_erc4626.decimals());
}

/**
* @return the value of 1 share of an ERC4626 in terms of the underlying asset
*/
function getRate() external view override returns (uint256) {
return erc4626.convertToAssets(baseDecimals);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@chainlink/contracts": "^0.2.1",
"@nomiclabs/hardhat-ethers": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@openzeppelin/contracts": "^4.3.0",
"@openzeppelin/contracts": "^4.7.3",
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.3",
"@types/node": "^14.6.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@
"@types/sinon-chai" "^3.2.3"
"@types/web3" "1.0.19"

"@openzeppelin/contracts@^4.3.0":
version "4.3.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.0.tgz#345236d4ec73ef381ab4907c6ef66fd55e5dedad"
integrity sha512-+uBDl/TrmR0Kch6mq3tuxMex/fK7huR6+fQMae+zJk1K5T+dp0pFl12Hbc+1L6oYMXoyDSBJ8zqhRIntrREDFA==
"@openzeppelin/contracts@^4.7.3":
version "4.9.3"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.3.tgz#00d7a8cf35a475b160b3f0293a6403c511099364"
integrity sha512-He3LieZ1pP2TNt5JbkPA4PNT9WC3gOTOlDcFGJW4Le4QKqwmiNJCRt44APfxMxvq7OugU/cqYuPcSBzOw38DAg==

"@resolver-engine/core@^0.3.3":
version "0.3.3"
Expand Down

0 comments on commit 3328bdb

Please sign in to comment.