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

CombinedRateProviderFactory #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions contracts/CombinedRateProvider.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 "./interfaces/IRateProvider.sol";

contract CombinedRateProvider {
address public rateProvider1;
address public rateProvider2;

constructor(address _rateProvider1, address _rateProvider2) {
rateProvider1 = _rateProvider1;
rateProvider2 = _rateProvider2;
}

// Function to combine both of the rate providers via multiplication
function getRate() external view returns (uint256) {
// rateProvider1 and rateProvider2 must respect the proper interface.
uint256 rate1 = IRateProvider(rateProvider1).getRate();
uint256 rate2 = IRateProvider(rateProvider2).getRate();
return rate1 * rate2 / 1e18; // Multiplies the rates respecting the proper interface together and divides by 1e18 to normalize.
}
}
39 changes: 39 additions & 0 deletions contracts/CombinedRateProviderFactory.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 "./BaseRateProviderFactory.sol";
import "./CombinedRateProvider.sol";

/**
* @title Combined Rate Provider Factory
* @notice This contract is a factory for creating instances of CombinedRateProvider.
* @dev This factory contract allows for the deployment of CombinedRateProvider contracts,
* which are used to combine market rates from two individual rate providers.
*/


contract CombinedRateProviderFactory is BaseRateProviderFactory {
/**
* @notice Deploys a new CombinedRateProvider contract using a price feed.
* @param _rateProvider1 - The first of two rate providers the user wishes to multiply
* @param _rateProvider2 - The second of two rate providers the user wishes to multiply
*/
function create(address _rateProvider1, address _rateProvider2) external returns (CombinedRateProvider) {
CombinedRateProvider rateProvider = new CombinedRateProvider(_rateProvider1, _rateProvider2);
_onCreate(address(rateProvider));
return rateProvider;
}
}