Skip to content

Instantly share code, notes, and snippets.

@brotherlymite
Created September 16, 2025 07:51
Show Gist options
  • Select an option

  • Save brotherlymite/1ac9781fe940a11f006c51caf5858e33 to your computer and use it in GitHub Desktop.

Select an option

Save brotherlymite/1ac9781fe940a11f006c51caf5858e33 to your computer and use it in GitHub Desktop.
diff --git a/src/contracts/modules/RangeValidationModule.sol b/src/contracts/modules/RangeValidationModule.sol
index 6e2601a..74a1263 100644
--- a/src/contracts/modules/RangeValidationModule.sol
+++ b/src/contracts/modules/RangeValidationModule.sol
@@ -1,10 +1,10 @@
-// SPDX-License-Identifier: BUSL-1.1
+// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import {IOwnable} from 'aave-address-book/common/IOwnable.sol';
import {IRangeValidationModule} from '../../interfaces/IRangeValidationModule.sol';
-import {IEdgeAgentHub} from '../../interfaces/IEdgeAgentHub.sol';
+import {IAgentHub} from '../../interfaces/IAgentHub.sol';
/**
* @title RangeValidationModule
@@ -23,10 +23,10 @@ contract RangeValidationModule is IRangeValidationModule {
mapping(bytes32 configId => AgentConfig) internal _rangeConfigs;
- modifier onlyHubOwnerOrAgentAdmin(address edgeHub, uint256 agentId) {
+ modifier onlyHubOwnerOrAgentAdmin(address agentHub, uint256 agentId) {
require(
- msg.sender == IEdgeAgentHub(edgeHub).getAgentAdmin(agentId) ||
- msg.sender == IOwnable(edgeHub).owner(),
+ msg.sender == IAgentHub(agentHub).getAgentAdmin(agentId) ||
+ msg.sender == IOwnable(agentHub).owner(),
OnlyHubOwnerOrAgentAdmin(msg.sender)
);
_;
@@ -34,91 +34,105 @@ contract RangeValidationModule is IRangeValidationModule {
/// @inheritdoc IRangeValidationModule
function validate(
- address edgeHub,
+ address agentHub,
uint256 agentId,
+ address market,
RangeValidationInput calldata input
- ) external view returns (bool) {
- bytes32 configId = _getRangeConfigId(edgeHub, agentId, input.updateType);
+ ) public view returns (bool) {
+ bytes32 configId = _getRangeConfigId(agentHub, agentId, input.updateType);
AgentConfig storage agentConfig = _rangeConfigs[configId];
-
- RangeConfig memory config = agentConfig.marketConfig[input.market];
+ RangeConfig memory config = agentConfig.marketConfig[market];
// if config is not set for a specific market, fallback to the default configuration
if (config.maxIncrease == 0 && config.maxDecrease == 0) {
config = agentConfig.defaultConfig;
}
+
return _validateRange(input.from, input.to, config);
}
+ /// @inheritdoc IRangeValidationModule
+ function validate(
+ address agentHub,
+ uint256 agentId,
+ address market,
+ RangeValidationInput[] calldata input
+ ) external view returns (bool) {
+ for (uint256 i = 0; i < input.length; i++) {
+ if (!validate(agentHub, agentId, market, input[i])) return false;
+ }
+ return true;
+ }
+
/// @inheritdoc IRangeValidationModule
function setDefaultRangeConfig(
- address edgeHub,
+ address agentHub,
uint256 agentId,
string calldata updateType,
RangeConfig calldata config
- ) external onlyHubOwnerOrAgentAdmin(edgeHub, agentId) {
+ ) external onlyHubOwnerOrAgentAdmin(agentHub, agentId) {
require(
!config.isDecreaseRelative || config.maxDecrease <= 100_00,
InvalidMaxRelativeDecrease(config.maxDecrease)
);
- bytes32 configId = _getRangeConfigId(edgeHub, agentId, updateType);
+ bytes32 configId = _getRangeConfigId(agentHub, agentId, updateType);
_rangeConfigs[configId].defaultConfig = config;
- emit DefaultRangeConfigSet(edgeHub, agentId, updateType, config);
+ emit DefaultRangeConfigSet(agentHub, agentId, updateType, config);
}
/// @inheritdoc IRangeValidationModule
function setRangeConfigByMarket(
- address edgeHub,
+ address agentHub,
uint256 agentId,
address market,
string calldata updateType,
RangeConfig calldata config
- ) external onlyHubOwnerOrAgentAdmin(edgeHub, agentId) {
+ ) external onlyHubOwnerOrAgentAdmin(agentHub, agentId) {
require(
!config.isDecreaseRelative || config.maxDecrease <= 100_00,
InvalidMaxRelativeDecrease(config.maxDecrease)
);
- bytes32 configId = _getRangeConfigId(edgeHub, agentId, updateType);
+ bytes32 configId = _getRangeConfigId(agentHub, agentId, updateType);
_rangeConfigs[configId].marketConfig[market] = config;
- emit MarketRangeConfigSet(edgeHub, agentId, market, updateType, config);
+ emit MarketRangeConfigSet(agentHub, agentId, market, updateType, config);
}
/// @inheritdoc IRangeValidationModule
function getDefaultRangeConfig(
- address edgeHub,
+ address agentHub,
uint256 agentId,
string calldata updateType
) external view returns (RangeConfig memory) {
- bytes32 configId = _getRangeConfigId(edgeHub, agentId, updateType);
+ bytes32 configId = _getRangeConfigId(agentHub, agentId, updateType);
return _rangeConfigs[configId].defaultConfig;
}
/// @inheritdoc IRangeValidationModule
function getRangeConfigByMarket(
- address edgeHub,
+ address agentHub,
uint256 agentId,
address market,
string calldata updateType
) external view returns (RangeConfig memory) {
- bytes32 configId = _getRangeConfigId(edgeHub, agentId, updateType);
+ bytes32 configId = _getRangeConfigId(agentHub, agentId, updateType);
return _rangeConfigs[configId].marketConfig[market];
}
/**
* @notice method to get the range configuration id, unique to each configuration
- * @param edgeHub address of the edgeHub contract of the agent
- * @param agentId id of the agent configured on the edgeHub
+ * @param agentHub address of the agentHub contract of the agent
+ * @param agentId id of the agent configured on the agentHub
* @param updateType updateType for which to get configuration id
* @return id unique to each configuration, which is used to set and get range configuration
*/
function _getRangeConfigId(
- address edgeHub,
+ address agentHub,
uint256 agentId,
string calldata updateType
) internal pure returns (bytes32) {
- return keccak256(abi.encode(edgeHub, agentId, updateType));
+ return keccak256(abi.encode(agentHub, agentId, updateType));
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment