-
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 #9 from baileyspraggins/chainlink_rate_factory
ChainlinkRateProviderFactory
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 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,38 @@ | ||
// 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/IBaseRateProviderFactory.sol"; | ||
|
||
/** | ||
* @title Base Rate Provider Factory | ||
* @notice Base Factory for creating RateProviders | ||
* @dev This is a base contract for building factories that create RateProviders. | ||
*/ | ||
contract BaseRateProviderFactory is IBaseRateProviderFactory { | ||
// Mapping of rate providers created by this factory. | ||
mapping(address => bool) private _isRateProviderFromFactory; | ||
|
||
event RateProviderCreated(address indexed rateProvider); | ||
|
||
function isRateProviderFromFactory(address rateProvider) external view returns (bool) { | ||
return _isRateProviderFromFactory[rateProvider]; | ||
} | ||
|
||
function _onCreate(address rateProvider) internal { | ||
_isRateProviderFromFactory[rateProvider] = true; | ||
emit RateProviderCreated(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
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 "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | ||
|
||
import "./BaseRateProviderFactory.sol"; | ||
import "./ChainlinkRateProvider.sol"; | ||
|
||
/** | ||
* @title Chainlink Rate Provider Factory | ||
* @notice Factory for creating ChainlinkRateProviders | ||
* @dev This contract is used to create ChainlinkRateProvider contracts. | ||
* RateProviders created by this factory are to be used in environments | ||
* where the Chainlink registry is not available. | ||
*/ | ||
contract ChainlinkRateProviderFactory is BaseRateProviderFactory { | ||
/** | ||
* @notice Deploys a new ChainlinkRateProvider contract using a price feed. | ||
* @param feed - The Chainlink price feed contract. | ||
*/ | ||
function create(AggregatorV3Interface feed) external returns (ChainlinkRateProvider) { | ||
ChainlinkRateProvider rateProvider = new ChainlinkRateProvider(feed); | ||
_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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; | ||
|
||
interface IBaseRateProviderFactory { | ||
/** | ||
* @dev Checks if a rate provider was created by the derived factory. | ||
* @param rateProvider - Address of the rate provider to check. | ||
* @return bool - True if the rate provider was created by the derived factory. | ||
*/ | ||
function isRateProviderFromFactory(address rateProvider) external view returns (bool); | ||
} |