-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: market factories implementation
- Loading branch information
1 parent
ba8bf86
commit d1d06dd
Showing
28 changed files
with
1,100 additions
and
773 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 |
---|---|---|
@@ -1,44 +1,76 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// Gearbox Protocol. Generalized leverage for DeFi protocols | ||
// (c) Gearbox Foundation, 2024. | ||
pragma solidity ^0.8.17; | ||
pragma solidity ^0.8.23; | ||
|
||
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol"; | ||
import {IVotingContract} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVotingContract.sol"; | ||
|
||
import {IAddressProvider} from "../interfaces/IAddressProvider.sol"; | ||
import {IMarketConfigurator} from "../interfaces/IMarketConfigurator.sol"; | ||
import {IBytecodeRepository} from "../interfaces/IBytecodeRepository.sol"; | ||
import {IMarketConfiguratorFactory} from "../interfaces/IMarketConfiguratorFactory.sol"; | ||
|
||
import { | ||
AP_BYTECODE_REPOSITORY, | ||
AP_MARKET_CONFIGURATOR_FACTORY, | ||
NO_VERSION_CONTROL | ||
} from "../libraries/ContractLiterals.sol"; | ||
import {Call} from "../interfaces/Types.sol"; | ||
|
||
import {IMarketConfiguratorFactory} from "../interfaces/IMarketConfiguratorFactory.sol"; | ||
|
||
abstract contract AbstractFactory is IVersion { | ||
address public immutable addressProvider; | ||
address public immutable bytecodeRepository; | ||
|
||
address public immutable marketConfiguratorFactory; | ||
|
||
address public immutable addressProvider; | ||
|
||
error CallerIsNotMarketConfiguratorException(); | ||
|
||
modifier marketConfiguratorOnly() { | ||
modifier marketConfiguratorsOnly() { | ||
_ensureCallerIsMarketConfigurator(); | ||
_; | ||
} | ||
|
||
constructor(address addressProvider_) { | ||
addressProvider = addressProvider_; | ||
bytecodeRepository = _getContract(AP_BYTECODE_REPOSITORY, NO_VERSION_CONTROL); | ||
marketConfiguratorFactory = _getContract(AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL); | ||
} | ||
|
||
function _ensureCallerIsMarketConfigurator() internal view { | ||
if (IMarketConfiguratorFactory(marketConfiguratorFactory).isMarketConfigurator(msg.sender)) { | ||
revert CallerIsNotMarketConfiguratorException(); | ||
} | ||
_; | ||
} | ||
|
||
constructor(address _addressProvider) { | ||
marketConfiguratorFactory = | ||
IAddressProvider(_addressProvider).getAddressOrRevert(AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL); | ||
function _getLatestContract(bytes32 key) internal view returns (address) { | ||
return IAddressProvider(addressProvider).getLatestAddressOrRevert(key); | ||
} | ||
|
||
function _getContract(bytes32 key, uint256 version_) internal view returns (address) { | ||
return IAddressProvider(addressProvider).getAddressOrRevert(key, version_); | ||
} | ||
|
||
bytecodeRepository = | ||
IAddressProvider(_addressProvider).getAddressOrRevert(AP_BYTECODE_REPOSITORY, NO_VERSION_CONTROL); | ||
function _deploy(bytes32 type_, uint256 version_, bytes memory constructorParams, bytes32 salt) | ||
internal | ||
returns (address) | ||
{ | ||
return IBytecodeRepository(bytecodeRepository).deploy(type_, version_, constructorParams, salt); | ||
} | ||
|
||
addressProvider = _addressProvider; | ||
function _deployByDomain( | ||
bytes32 domain, | ||
bytes32 postfix, | ||
uint256 version_, | ||
bytes memory constructorParams, | ||
bytes32 salt | ||
) internal returns (address) { | ||
return | ||
IBytecodeRepository(bytecodeRepository).deployByDomain(domain, postfix, version_, constructorParams, salt); | ||
} | ||
|
||
function _isVotingContract(address contract_) internal view returns (bool) { | ||
try IVotingContract(contract_).voter() returns (address) { | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.