From fc9a56554b541706326d917f370a93493b7bc6e6 Mon Sep 17 00:00:00 2001
From: Zen-Maxi <85650601+Zen-Maxi@users.noreply.github.com>
Date: Mon, 3 Feb 2025 09:30:05 -0500
Subject: [PATCH] CombinedRateProviderFactory
Adds contract for CombinedRateProviderFactorty and CombinedRateProvider. The purpose of these contracts is to combined two rates in scenarios where the common denomination of assets is not uniform. For example, a rate provider denominated in wstETH and another in wETH cannot be used in a pool pairing. Combining the wstETH denominated rate with wstETH's known rate provider solves this issue with a new contract.
---
contracts/CombinedRateProvider.sol | 35 ++++++++++++++++++++
contracts/CombinedRateProviderFactory.sol | 39 +++++++++++++++++++++++
2 files changed, 74 insertions(+)
create mode 100644 contracts/CombinedRateProvider.sol
create mode 100644 contracts/CombinedRateProviderFactory.sol
diff --git a/contracts/CombinedRateProvider.sol b/contracts/CombinedRateProvider.sol
new file mode 100644
index 0000000..257da1a
--- /dev/null
+++ b/contracts/CombinedRateProvider.sol
@@ -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 .
+
+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.
+ }
+}
diff --git a/contracts/CombinedRateProviderFactory.sol b/contracts/CombinedRateProviderFactory.sol
new file mode 100644
index 0000000..0cd0fd2
--- /dev/null
+++ b/contracts/CombinedRateProviderFactory.sol
@@ -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 .
+
+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;
+ }
+}
\ No newline at end of file