-
Notifications
You must be signed in to change notification settings - Fork 3
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 #17 from Gearbox-protocol/market-generation
feat: factory-driven architecture
- Loading branch information
Showing
69 changed files
with
4,571 additions
and
4,318 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,95 @@ | ||
// 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 {APOwnerTrait} from "../traits/APOwnerTrait.sol"; | ||
import {IAddressProviderV3_1} from "../interfaces/IAddressProviderV3_1.sol"; | ||
import {AP_BYTECODE_REPOSITORY, NO_VERSION_CONTROL} from "../libraries/ContractLiterals.sol"; | ||
import {IVotingContract} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVotingContract.sol"; | ||
import {VotingContractStatus} from "@gearbox-protocol/core-v3/contracts/interfaces/IGearStakingV3.sol"; | ||
|
||
abstract contract AbstractFactory is APOwnerTrait { | ||
address immutable bytecodeRepository; | ||
import {AbstractDeployer} from "../helpers/AbstractDeployer.sol"; | ||
|
||
error CallerIsNotMarketConfiguratorException(); | ||
import {IFactory} from "../interfaces/factories/IFactory.sol"; | ||
import {IMarketConfigurator} from "../interfaces/IMarketConfigurator.sol"; | ||
import {IMarketConfiguratorFactory} from "../interfaces/IMarketConfiguratorFactory.sol"; | ||
import {Call} from "../interfaces/Types.sol"; | ||
|
||
modifier marketConfiguratorOnly() { | ||
if (IAddressProviderV3_1(addressProvider).isMarketConfigurator(msg.sender)) { | ||
revert CallerIsNotMarketConfiguratorException(); | ||
} | ||
import {AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL} from "../libraries/ContractLiterals.sol"; | ||
|
||
abstract contract AbstractFactory is AbstractDeployer, IFactory { | ||
// --------------- // | ||
// STATE VARIABLES // | ||
// --------------- // | ||
|
||
address public immutable override marketConfiguratorFactory; | ||
|
||
// --------- // | ||
// MODIFIERS // | ||
// --------- // | ||
|
||
modifier onlyMarketConfigurators() { | ||
_ensureCallerIsMarketConfigurator(); | ||
_; | ||
} | ||
|
||
constructor(address _addressProvider) APOwnerTrait(_addressProvider) { | ||
bytecodeRepository = | ||
IAddressProviderV3_1(_addressProvider).getAddressOrRevert(AP_BYTECODE_REPOSITORY, NO_VERSION_CONTROL); | ||
// ----------- // | ||
// CONSTRUCTOR // | ||
// ----------- // | ||
|
||
constructor(address addressProvider_) AbstractDeployer(addressProvider_) { | ||
marketConfiguratorFactory = _getContract(AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL); | ||
} | ||
|
||
// ------------- // | ||
// CONFIGURATION // | ||
// ------------- // | ||
|
||
function configure(address, bytes calldata callData) external virtual override returns (Call[] memory) { | ||
revert ForbiddenConfigurationCallException(bytes4(callData)); | ||
} | ||
|
||
function emergencyConfigure(address, bytes calldata callData) external virtual override returns (Call[] memory) { | ||
revert ForbiddenEmergencyConfigurationCallException(bytes4(callData)); | ||
} | ||
|
||
// --------- // | ||
// INTERNALS // | ||
// --------- // | ||
|
||
function _ensureCallerIsMarketConfigurator() internal view { | ||
if (IMarketConfiguratorFactory(marketConfiguratorFactory).isMarketConfigurator(msg.sender)) { | ||
revert CallerIsNotMarketConfiguratorException(msg.sender); | ||
} | ||
} | ||
|
||
function _isVotingContract(address votingContract) internal view returns (bool) { | ||
try IVotingContract(votingContract).voter() returns (address) { | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
function _setVotingContractStatus(address votingContract, bool allowed) internal view returns (Call memory) { | ||
return Call({ | ||
target: marketConfiguratorFactory, | ||
callData: abi.encodeCall( | ||
IMarketConfiguratorFactory.setVotingContractStatus, | ||
(votingContract, allowed ? VotingContractStatus.ALLOWED : VotingContractStatus.UNVOTE_ONLY) | ||
) | ||
}); | ||
} | ||
|
||
function _addToAccessList(address marketConfigurator, address target) internal view returns (Call memory) { | ||
return Call({ | ||
target: marketConfigurator, | ||
callData: abi.encodeCall(IMarketConfigurator.addToAccessList, (target, address(this))) | ||
}); | ||
} | ||
|
||
function _removeFromAccessList(address marketConfigurator, address target) internal view returns (Call memory) { | ||
return Call({ | ||
target: marketConfigurator, | ||
callData: abi.encodeCall(IMarketConfigurator.removeFromAccessList, (target, address(this))) | ||
}); | ||
} | ||
} |
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,97 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
// Gearbox Protocol. Generalized leverage for DeFi protocols | ||
// (c) Gearbox Foundation, 2024. | ||
pragma solidity ^0.8.23; | ||
|
||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol"; | ||
import {IPoolV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolV3.sol"; | ||
import {IContractsRegister} from "../interfaces/extensions/IContractsRegister.sol"; | ||
import {IMarketFactory} from "../interfaces/factories/IMarketFactory.sol"; | ||
import {IMarketConfigurator} from "../interfaces/IMarketConfigurator.sol"; | ||
import {Call} from "../interfaces/Types.sol"; | ||
import {AbstractFactory} from "./AbstractFactory.sol"; | ||
|
||
abstract contract AbstractMarketFactory is AbstractFactory, IMarketFactory { | ||
// ------------ // | ||
// MARKET HOOKS // | ||
// ------------ // | ||
|
||
function onCreateMarket(address, address, address, address, address, address) | ||
external | ||
virtual | ||
override | ||
returns (Call[] memory) | ||
{} | ||
|
||
function onShutdownMarket(address) external virtual override returns (Call[] memory) {} | ||
|
||
function onCreateCreditSuite(address) external virtual override returns (Call[] memory) {} | ||
|
||
function onShutdownCreditSuite(address) external virtual override returns (Call[] memory) {} | ||
|
||
function onUpdatePriceOracle(address, address, address) external virtual override returns (Call[] memory) {} | ||
|
||
function onUpdateInterestRateModel(address, address, address) external virtual override returns (Call[] memory) {} | ||
|
||
function onUpdateRateKeeper(address, address, address) external virtual override returns (Call[] memory) {} | ||
|
||
function onUpdateLossLiquidator(address, address, address) external virtual override returns (Call[] memory) {} | ||
|
||
function onAddToken(address, address, address) external virtual override returns (Call[] memory) {} | ||
|
||
// --------- // | ||
// INTERNALS // | ||
// --------- // | ||
|
||
function _validateDefaultConstructorParams(address pool, bytes calldata constructorParams) internal view { | ||
(address decodedPool, address decodedAddressProvider) = abi.decode(constructorParams[:64], (address, address)); | ||
if (decodedPool != pool || decodedAddressProvider != addressProvider) { | ||
revert InvalidConstructorParamsException(); | ||
} | ||
} | ||
|
||
function _acl(address pool) internal view returns (address) { | ||
return IPoolV3(pool).acl(); | ||
} | ||
|
||
function _marketConfigurator(address pool) internal view returns (address) { | ||
return Ownable(_acl(pool)).owner(); | ||
} | ||
|
||
function _contractsRegister(address pool) internal view returns (address) { | ||
return IMarketConfigurator(_marketConfigurator(pool)).contractsRegister(); | ||
} | ||
|
||
function _underlying(address pool) internal view returns (address) { | ||
return IPoolV3(pool).asset(); | ||
} | ||
|
||
function _quotaKeeper(address pool) internal view returns (address) { | ||
return IPoolV3(pool).poolQuotaKeeper(); | ||
} | ||
|
||
function _interestRateModel(address pool) internal view returns (address) { | ||
return IPoolV3(pool).interestRateModel(); | ||
} | ||
|
||
function _priceOracle(address pool) internal view returns (address) { | ||
return IContractsRegister(_contractsRegister(pool)).getPriceOracle(pool); | ||
} | ||
|
||
function _lossLiquidator(address pool) internal view returns (address) { | ||
return IContractsRegister(_contractsRegister(pool)).getLossLiquidator(pool); | ||
} | ||
|
||
function _rateKeeper(address quotaKeeper) internal view returns (address) { | ||
return IPoolQuotaKeeperV3(quotaKeeper).gauge(); | ||
} | ||
|
||
function _isQuotedToken(address quotaKeeper, address token) internal view returns (bool) { | ||
return IPoolQuotaKeeperV3(quotaKeeper).isQuotedToken(token); | ||
} | ||
|
||
function _quota(address quotaKeeper, address token) internal view returns (uint96 quota) { | ||
(,,, quota,,) = IPoolQuotaKeeperV3(quotaKeeper).getTokenQuotaParams(token); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.