diff --git a/contracts/BaseRateProviderFactory.sol b/contracts/BaseRateProviderFactory.sol new file mode 100644 index 0000000..9ae4b4f --- /dev/null +++ b/contracts/BaseRateProviderFactory.sol @@ -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 . + +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); + } +} diff --git a/contracts/ChainlinkRateProviderFactory.sol b/contracts/ChainlinkRateProviderFactory.sol new file mode 100644 index 0000000..4e6a5ec --- /dev/null +++ b/contracts/ChainlinkRateProviderFactory.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 "@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; + } +} diff --git a/contracts/interfaces/IBaseRateProviderFactory.sol b/contracts/interfaces/IBaseRateProviderFactory.sol new file mode 100644 index 0000000..5114cb6 --- /dev/null +++ b/contracts/interfaces/IBaseRateProviderFactory.sol @@ -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 . + +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); +}