Skip to content

Commit

Permalink
Merge pull request #9 from baileyspraggins/chainlink_rate_factory
Browse files Browse the repository at this point in the history
ChainlinkRateProviderFactory
  • Loading branch information
rabmarut authored Jul 17, 2023
2 parents 02dbb4e + 8315a23 commit 8793212
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
38 changes: 38 additions & 0 deletions contracts/BaseRateProviderFactory.sol
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);
}
}
39 changes: 39 additions & 0 deletions contracts/ChainlinkRateProviderFactory.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 "@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;
}
}
24 changes: 24 additions & 0 deletions contracts/interfaces/IBaseRateProviderFactory.sol
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);
}

0 comments on commit 8793212

Please sign in to comment.