Initial commit

This commit is contained in:
Test User
2025-11-20 15:35:25 -08:00
commit bfbe3ee8b7
59 changed files with 7187 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title IConfigRegistry
* @notice Interface for configuration registry
* @dev Stores all system parameters and limits
*/
interface IConfigRegistry {
/**
* @notice Emitted when a parameter is updated
* @param param Parameter name (encoded as bytes32)
* @param oldValue Previous value
* @param newValue New value
*/
event ParameterUpdated(
bytes32 indexed param,
uint256 oldValue,
uint256 newValue
);
/**
* @notice Get maximum number of recursive loops
* @return maxLoops Maximum loops allowed
*/
function getMaxLoops() external view returns (uint256 maxLoops);
/**
* @notice Get maximum flash loan size for an asset
* @param asset Asset address
* @return maxFlash Maximum flash loan size
*/
function getMaxFlashSize(address asset) external view returns (uint256 maxFlash);
/**
* @notice Get minimum health factor threshold
* @return minHF Minimum health factor (scaled by 1e18)
*/
function getMinHealthFactor() external view returns (uint256 minHF);
/**
* @notice Get target health factor
* @return targetHF Target health factor (scaled by 1e18)
*/
function getTargetHealthFactor() external view returns (uint256 targetHF);
/**
* @notice Check if an asset is allowed
* @param asset Asset address
* @return allowed True if asset is allowed
*/
function isAllowedAsset(address asset) external view returns (bool allowed);
/**
* @notice Get provider capacity cap
* @param provider Provider identifier (encoded as bytes32)
* @return cap Capacity cap
*/
function getProviderCap(bytes32 provider) external view returns (uint256 cap);
/**
* @notice Update maximum loops
* @param newMaxLoops New maximum loops
*/
function setMaxLoops(uint256 newMaxLoops) external;
/**
* @notice Update maximum flash size for an asset
* @param asset Asset address
* @param newMaxFlash New maximum flash size
*/
function setMaxFlashSize(address asset, uint256 newMaxFlash) external;
/**
* @notice Update minimum health factor
* @param newMinHF New minimum health factor (scaled by 1e18)
*/
function setMinHealthFactor(uint256 newMinHF) external;
/**
* @notice Update target health factor
* @param newTargetHF New target health factor (scaled by 1e18)
*/
function setTargetHealthFactor(uint256 newTargetHF) external;
/**
* @notice Add or remove allowed asset
* @param asset Asset address
* @param allowed Whether asset is allowed
*/
function setAllowedAsset(address asset, bool allowed) external;
/**
* @notice Update provider capacity cap
* @param provider Provider identifier
* @param newCap New capacity cap
*/
function setProviderCap(bytes32 provider, uint256 newCap) external;
}

View File

@@ -0,0 +1,106 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title IFlashLoanRouter
* @notice Interface for multi-provider flash loan router
* @dev Aggregates flash loans from Aave, Balancer, Uniswap, DAI flash mint
*/
interface IFlashLoanRouter {
enum FlashLoanProvider {
AAVE,
BALANCER,
UNISWAP,
DAI_FLASH
}
/**
* @notice Flash loan parameters
* @param asset Asset to borrow
* @param amount Amount to borrow
* @param provider Provider to use (or AUTO for liquidity-weighted)
*/
struct FlashLoanParams {
address asset;
uint256 amount;
FlashLoanProvider provider;
}
/**
* @notice Emitted when flash loan is initiated
* @param asset Asset borrowed
* @param amount Amount borrowed
* @param provider Provider used
*/
event FlashLoanInitiated(
address indexed asset,
uint256 amount,
FlashLoanProvider provider
);
/**
* @notice Emitted when flash loan is repaid
* @param asset Asset repaid
* @param amount Amount repaid (principal + fee)
*/
event FlashLoanRepaid(address indexed asset, uint256 amount);
/**
* @notice Execute a flash loan with callback
* @param params Flash loan parameters
* @param callbackData Data to pass to callback
*/
function flashLoan(
FlashLoanParams memory params,
bytes memory callbackData
) external;
/**
* @notice Execute multi-asset flash loan
* @param params Array of flash loan parameters
* @param callbackData Data to pass to callback
*/
function flashLoanBatch(
FlashLoanParams[] memory params,
bytes memory callbackData
) external;
/**
* @notice Get available liquidity for an asset from a provider
* @param asset Asset address
* @param provider Provider to check
* @return available Available liquidity
*/
function getAvailableLiquidity(
address asset,
FlashLoanProvider provider
) external view returns (uint256 available);
/**
* @notice Get fee for flash loan from a provider
* @param asset Asset address
* @param amount Amount to borrow
* @param provider Provider to check
* @return fee Fee amount
*/
function getFlashLoanFee(
address asset,
uint256 amount,
FlashLoanProvider provider
) external view returns (uint256 fee);
/**
* @notice Callback function executed during flash loan
* @param asset Asset borrowed
* @param amount Amount borrowed
* @param fee Fee for the flash loan
* @param callbackData Data passed from caller
*/
function onFlashLoan(
address asset,
uint256 amount,
uint256 fee,
bytes calldata callbackData
) external returns (bytes32);
}

View File

@@ -0,0 +1,80 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./IFlashLoanRouter.sol";
/**
* @title IKernel
* @notice Interface for Recursive Leverage Kernel
* @dev Implements atomic amortizing cycles
*/
interface IKernel {
/**
* @notice Amortization cycle parameters
* @param targetAsset Asset to convert yield to
* @param maxLoops Maximum number of recursive loops
* @param minHFImprovement Minimum health factor improvement (scaled by 1e18)
*/
struct AmortizationParams {
address targetAsset;
uint256 maxLoops;
uint256 minHFImprovement;
}
/**
* @notice Emitted when amortization cycle executes successfully
* @param cyclesExecuted Number of cycles executed
* @param collateralIncrease Increase in collateral value
* @param debtDecrease Decrease in debt value
* @param hfImprovement Health factor improvement
*/
event AmortizationExecuted(
uint256 cyclesExecuted,
uint256 collateralIncrease,
uint256 debtDecrease,
uint256 hfImprovement
);
/**
* @notice Emitted when invariant check fails
* @param reason Reason for failure
*/
event InvariantFail(string reason);
/**
* @notice Execute an atomic amortizing cycle
* @param params Amortization parameters
* @return success True if cycle succeeded
* @return cyclesExecuted Number of cycles executed
*/
function executeAmortizingCycle(
AmortizationParams memory params
) external returns (bool success, uint256 cyclesExecuted);
/**
* @notice Execute a single amortization step
* @param flashLoanParams Flash loan parameters
* @param targetAsset Asset to convert yield to
* @return collateralAdded Amount of collateral added
* @return debtRepaid Amount of debt repaid
*/
function executeSingleStep(
IFlashLoanRouter.FlashLoanParams memory flashLoanParams,
address targetAsset
) external returns (uint256 collateralAdded, uint256 debtRepaid);
/**
* @notice Verify invariants are satisfied
* @param collateralBefore Previous collateral value
* @param debtBefore Previous debt value
* @param healthFactorBefore Previous health factor
* @return success True if invariants satisfied
* @return reason Failure reason if not successful
*/
function verifyInvariants(
uint256 collateralBefore,
uint256 debtBefore,
uint256 healthFactorBefore
) external view returns (bool success, string memory reason);
}

View File

@@ -0,0 +1,70 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title IOracleAdapter
* @notice Interface for oracle adapter
* @dev Standardizes pricing from multiple oracle sources
*/
interface IOracleAdapter {
enum OracleSource {
AAVE,
CHAINLINK,
UNISWAP_TWAP,
FALLBACK
}
/**
* @notice Price data structure
* @param price Price (scaled by 1e8 for USD pairs)
* @param source Oracle source used
* @param timestamp Timestamp of price update
* @param confidence Confidence score (0-1e18, where 1e18 = 100%)
*/
struct PriceData {
uint256 price;
OracleSource source;
uint256 timestamp;
uint256 confidence;
}
/**
* @notice Get latest price for an asset
* @param asset Asset address
* @return priceData Price data structure
*/
function getPrice(address asset) external view returns (PriceData memory priceData);
/**
* @notice Get latest price with max age requirement
* @param asset Asset address
* @param maxAge Maximum age of price in seconds
* @return priceData Price data structure
*/
function getPriceWithMaxAge(
address asset,
uint256 maxAge
) external view returns (PriceData memory priceData);
/**
* @notice Get aggregated price from multiple sources
* @param asset Asset address
* @return price Aggregated price (scaled by 1e8)
* @return confidence Weighted confidence score
*/
function getAggregatedPrice(address asset) external view returns (uint256 price, uint256 confidence);
/**
* @notice Convert amount from one asset to another using prices
* @param fromAsset Source asset
* @param fromAmount Amount in source asset
* @param toAsset Destination asset
* @return toAmount Amount in destination asset
*/
function convertAmount(
address fromAsset,
uint256 fromAmount,
address toAsset
) external view returns (uint256 toAmount);
}

View File

@@ -0,0 +1,62 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./IPolicyModule.sol";
/**
* @title IPolicyEngine
* @notice Interface for policy engine
* @dev Aggregates policy decisions from multiple modules
*/
interface IPolicyEngine {
/**
* @notice Emitted when a policy module is registered
* @param module Module address
* @param name Module name
*/
event PolicyModuleRegistered(address indexed module, string name);
/**
* @notice Emitted when a policy module is unregistered
* @param module Module address
*/
event PolicyModuleUnregistered(address indexed module);
/**
* @notice Register a policy module
* @param module Module address
*/
function registerPolicyModule(address module) external;
/**
* @notice Unregister a policy module
* @param module Module address
*/
function unregisterPolicyModule(address module) external;
/**
* @notice Evaluate all registered policy modules
* @param actionType Type of action
* @param actionData Action-specific data
* @return allowed True if all modules allow the action
* @return reason Reason for denial (if any module denies)
*/
function evaluateAll(
bytes32 actionType,
bytes memory actionData
) external view returns (bool allowed, string memory reason);
/**
* @notice Get all registered policy modules
* @return modules Array of module addresses
*/
function getPolicyModules() external view returns (address[] memory modules);
/**
* @notice Check if a module is registered
* @param module Module address
* @return registered True if registered
*/
function isRegistered(address module) external view returns (bool registered);
}

View File

@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title IPolicyModule
* @notice Interface for policy modules
* @dev Policy modules enforce governance rules and risk limits
*/
interface IPolicyModule {
/**
* @notice Policy decision result
* @param allowed Whether the action is allowed
* @param reason Reason for denial (if not allowed)
*/
struct PolicyDecision {
bool allowed;
string reason;
}
/**
* @notice Evaluate policy for a proposed action
* @param actionType Type of action (encoded as bytes32)
* @param actionData Action-specific data
* @return decision Policy decision
*/
function evaluate(
bytes32 actionType,
bytes memory actionData
) external view returns (PolicyDecision memory decision);
/**
* @notice Get policy module name
* @return name Module name
*/
function name() external pure returns (string memory name);
/**
* @notice Check if module is enabled
* @return enabled True if enabled
*/
function isEnabled() external view returns (bool enabled);
/**
* @notice Enable or disable the module
* @param enabled New enabled status
*/
function setEnabled(bool enabled) external;
}

View File

@@ -0,0 +1,103 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title IVault
* @notice Interface for DBIS Institutional Vault
* @dev Vault represents a leveraged position with collateral and debt tracking
*/
interface IVault {
/**
* @notice Emitted when a position snapshot is taken
* @param collateralBefore Previous collateral amount
* @param debtBefore Previous debt amount
* @param collateralAfter New collateral amount
* @param debtAfter New debt amount
* @param healthFactorBefore Previous health factor (scaled by 1e18)
* @param healthFactorAfter New health factor (scaled by 1e18)
*/
event PositionSnapshot(
uint256 collateralBefore,
uint256 debtBefore,
uint256 collateralAfter,
uint256 debtAfter,
uint256 healthFactorBefore,
uint256 healthFactorAfter
);
/**
* @notice Emitted when collateral is added to the position
* @param asset Asset address
* @param amount Amount added
*/
event CollateralAdded(address indexed asset, uint256 amount);
/**
* @notice Emitted when debt is repaid
* @param asset Asset address
* @param amount Amount repaid
*/
event DebtRepaid(address indexed asset, uint256 amount);
/**
* @notice Get total collateral value in USD (scaled by 1e8)
*/
function getTotalCollateralValue() external view returns (uint256);
/**
* @notice Get total debt value in USD (scaled by 1e8)
*/
function getTotalDebtValue() external view returns (uint256);
/**
* @notice Get current health factor (scaled by 1e18)
*/
function getHealthFactor() external view returns (uint256);
/**
* @notice Get current LTV (Loan-to-Value ratio, scaled by 1e18)
*/
function getLTV() external view returns (uint256);
/**
* @notice Record addition of collateral
* @param asset Asset address
* @param amount Amount added
*/
function recordCollateralAdded(address asset, uint256 amount) external;
/**
* @notice Record repayment of debt
* @param asset Asset address
* @param amount Amount repaid
*/
function recordDebtRepaid(address asset, uint256 amount) external;
/**
* @notice Take a position snapshot for invariant checking
* @return collateralBefore Previous collateral value
* @return debtBefore Previous debt value
* @return healthFactorBefore Previous health factor
*/
function snapshotPosition()
external
returns (
uint256 collateralBefore,
uint256 debtBefore,
uint256 healthFactorBefore
);
/**
* @notice Verify position improved (invariant check)
* @param collateralBefore Previous collateral value
* @param debtBefore Previous debt value
* @param healthFactorBefore Previous health factor
* @return success True if position improved
*/
function verifyPositionImproved(
uint256 collateralBefore,
uint256 debtBefore,
uint256 healthFactorBefore
) external view returns (bool success);
}