Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/access/RoleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ library RoleRegistry {
*/
bytes32 public constant FEE_DISTRIBTOR_ROLE = keccak256("FEE_DISTRIBUTOR_ROLE");


// bytes32 public constant FEE_MANAGER_ROLE = keccak256("FEE_MANAGER");

/**
Expand Down
1 change: 0 additions & 1 deletion src/core/data/OrderStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.24;
import {CommonStructs} from "../../libraries/structs/CommonStructs.sol";
import {AddressUtils} from "../../libraries/utils/AddressUtils.sol";


/**
* @title OrderStorage
* @notice Stores and manages all limit/stop orders for BAOBAB
Expand Down
36 changes: 7 additions & 29 deletions src/core/markets/MarketRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,7 @@ contract MarketRegistry is SecurityBase {
* - This mapping provides the bridge between marketId and actual token address
* - Must be set before positions can be opened in the market
*/
function setQuoteAsset(bytes32 marketId, address quoteAssetAddress)
external
onlyAdmin
{
function setQuoteAsset(bytes32 marketId, address quoteAssetAddress) external onlyAdmin {
if (!marketExists[marketId]) revert MarketRegistry__MarketNotFound();
quoteAssetAddress.validateContract();

Expand All @@ -294,10 +291,7 @@ contract MarketRegistry is SecurityBase {
* @param marketId Market identifier
* @param baseAssetAddress Token address of the base asset
*/
function setBaseAsset(bytes32 marketId, address baseAssetAddress)
external
onlyAdmin
{
function setBaseAsset(bytes32 marketId, address baseAssetAddress) external onlyAdmin {
if (!marketExists[marketId]) revert MarketRegistry__MarketNotFound();
baseAssetAddress.validateContract();

Expand Down Expand Up @@ -347,11 +341,7 @@ contract MarketRegistry is SecurityBase {
riskParameters[marketId].tradingFeeBps = newTradingFeeBps;

emit RiskParametersUpdated(
marketId,
newMaxLeverage,
newMaintenanceMarginBps,
newLiquidationFeeBps,
newTradingFeeBps
marketId, newMaxLeverage, newMaintenanceMarginBps, newLiquidationFeeBps, newTradingFeeBps
);
}

Expand All @@ -366,10 +356,7 @@ contract MarketRegistry is SecurityBase {
* - Market must exist
* - New adapter must be valid contract
*/
function updateOracleAdapter(bytes32 marketId, address newOracleAdapter)
external
onlyAdmin
{
function updateOracleAdapter(bytes32 marketId, address newOracleAdapter) external onlyAdmin {
if (!marketExists[marketId]) revert MarketRegistry__MarketNotFound();
newOracleAdapter.validateContract();

Expand Down Expand Up @@ -418,11 +405,7 @@ contract MarketRegistry is SecurityBase {
* @param marketId Market identifier
* @return Market struct with all metadata
*/
function getMarket(bytes32 marketId)
external
view
returns (CommonStructs.Market memory)
{
function getMarket(bytes32 marketId) external view returns (CommonStructs.Market memory) {
if (!marketExists[marketId]) revert MarketRegistry__MarketNotFound();
return markets[marketId];
}
Expand All @@ -432,11 +415,7 @@ contract MarketRegistry is SecurityBase {
* @param marketId Market identifier
* @return Risk parameters struct
*/
function getRiskParameters(bytes32 marketId)
external
view
returns (CommonStructs.RiskParameters memory)
{
function getRiskParameters(bytes32 marketId) external view returns (CommonStructs.RiskParameters memory) {
if (!marketExists[marketId]) revert MarketRegistry__MarketNotFound();
return riskParameters[marketId];
}
Expand Down Expand Up @@ -488,8 +467,7 @@ contract MarketRegistry is SecurityBase {
* @return True if market exists and is in ACTIVE status
*/
function isMarketActive(bytes32 marketId) external view returns (bool) {
return marketExists[marketId]
&& markets[marketId].status == CommonStructs.MarketStatus.ACTIVE;
return marketExists[marketId] && markets[marketId].status == CommonStructs.MarketStatus.ACTIVE;
}

/**
Expand Down
84 changes: 84 additions & 0 deletions src/core/oracles/ComputedOracleFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;

import {IPriceFeed} from "../../interfaces/IPriceFeed.sol";
import {ComputedOracle} from "./adapters/ComputedOracle.sol";
// import { BaobabOracleRegistry} from "./OracleRegistry.sol";
import {IOracleRegistry} from "../../interfaces/IOracleRegistry.sol";

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {AddressUtils} from "../../libraries/utils/AddressUtils.sol";

/**
* @title ComputedOracleFactory
* @notice Factory for deploying and registering new instances of ComputedOracle.sol.
* @dev Centralizes deployment logic and ensures new oracles are immediately registered.
*/
contract ComputedOracleFactory is Ownable {
using AddressUtils for address;
// The OracleRegistry is immutable because the Factory must always register to the same central hub.
// BaobabOracleRegistry public immutable ORACLE_REGISTRY;

IOracleRegistry public immutable iORACLE_REGISTRY;

event ComputedOracleCreated(
address indexed targetAssetAddress,
address indexed computedOracleAddress,
address inputAssetA,
address inputAssetB
);

error ComputedOracleFactory__ZeroAddressRegistry();
error ComputedOracleFactory__InvalidInputAsset(address asset);

constructor(address oracleRegistry_, address initialOwner) Ownable(initialOwner) {
if (oracleRegistry_ == address(0)) {
revert ComputedOracleFactory__ZeroAddressRegistry();
}
// ORACLE_REGISTRY = BaobabOracleRegistry(oracleRegistry_);
iORACLE_REGISTRY = IOracleRegistry(oracleRegistry_);
}

/**
* @notice Deploys a new ComputedOracle instance and immediately registers it
* with the OracleRegistry under the specified targetAssetAddress.
* @dev Only the owner (governance) can call this.
* @param targetAssetAddress The address representing the derived asset (e.g., the synthetic token address).
* @param feedA The address of the primary input feed (Asset A, e.g., ETH/USD).
* @param feedB The address of the secondary input feed (Asset B, e.g., BTC/USD).
* @return computedOracleAddress The address of the newly deployed ComputedOracle contract.
*/
function deployAndRegisterOracle(
address targetAssetAddress,
address feedA,
address feedB,
ComputedOracle.Operation operation,
uint256 heartbeat
) external onlyOwner returns (address computedOracleAddress) {
// INPUT VALIDATION
feedA.validateNotZero();
feedB.validateNotZero();
targetAssetAddress.validateNotZero();

// DEPLOY THE NEW ORACLE INSTANCE
// The `new` keyword executes the constructor of ComputedOracle.sol.
// The newly deployed contract automatically inherits the security configuration (A, B, Registry)

ComputedOracle newOracle = new ComputedOracle(feedA, feedB, operation);

computedOracleAddress = address(newOracle);

// REGISTER WITH ORACLE REGISTRY

// Assuming OracleRegistry has a function to set the primary feed for an asset.
iORACLE_REGISTRY.setOracle(
targetAssetAddress,
newOracle,
IPriceFeed(address(0)),
heartbeat
);

emit ComputedOracleCreated(targetAssetAddress, computedOracleAddress, feedA, feedB);
return computedOracleAddress;
}
}
Loading
Loading