Skip to content

Commit

Permalink
Merge pull request #10 from sogipec/4626-provider
Browse files Browse the repository at this point in the history
feat: add an ERC4626 rate provider
  • Loading branch information
0xSpraggins authored Oct 26, 2023
2 parents 8793212 + bd2818c commit bca02e9
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
44 changes: 44 additions & 0 deletions contracts/ERC4626RateProvider.sol
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);
}
}
35 changes: 35 additions & 0 deletions contracts/ERC4626RateProviderFactory.sol
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;
}
}
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 bca02e9

Please sign in to comment.