Strategy Contracts

Strategy contracts manage the lifecycle and execution of trading strategies in the Noderr Protocol.

Strategy Lifecycle

┌──────────────┐    ┌──────────────┐    ┌──────────────┐    ┌──────────────┐
│  EVOLUTION   │───▶│    SHADOW    │───▶│     LIVE     │───▶│  DEPRECATED  │
│  (Testing)   │    │ (Paper Trade)│    │ (Real Money) │    │  (Retired)   │
└──────────────┘    └──────────────┘    └──────────────┘    └──────────────┘
│                    │                   │                    │
│ ML Generation      │ Guardian          │ Real              │ Performance
│ Backtesting        │ Validation        │ Execution         │ Decline
│                    │ Monte Carlo       │                   │

Contract Addresses (Base Sepolia)

ContractAddressPurpose
StrategyRegistry0x...Strategy registration
StrategyExecutor0x...Strategy execution
AllocationManager0x...Capital allocation
PerformanceTracker0x...Performance metrics

StrategyRegistry

Central registry for all trading strategies.

Strategy Structure

struct Strategy {
bytes32 id;
string name;
address creator;
StrategyStatus status;
uint256 riskScore;
uint256 maxAllocation;
uint256 createdAt;
bytes32 dnaHash;  // Strategy parameters hash
}
enum StrategyStatus {
EVOLUTION,
SHADOW,
LIVE,
DEPRECATED
}

Key Functions

// Register new strategy
function registerStrategy(
string calldata name,
bytes32 dnaHash,
uint256 riskScore
) external onlyRole(ORACLE_ROLE) returns (bytes32 strategyId);
// Promote strategy to next stage
function promoteStrategy(
bytes32 strategyId,
bytes calldata validationProof
) external onlyRole(GUARDIAN_ROLE);
// Deprecate strategy
function deprecateStrategy(
bytes32 strategyId,
string calldata reason
) external onlyRole(ADMIN_ROLE);
// Get strategy info
function getStrategy(bytes32 strategyId) external view returns (Strategy memory);

Events

event StrategyRegistered(bytes32 indexed strategyId, string name, address creator);
event StrategyPromoted(bytes32 indexed strategyId, StrategyStatus newStatus);
event StrategyDeprecated(bytes32 indexed strategyId, string reason);

StrategyExecutor

Executes trading operations for live strategies.

Execution Flow

// Execute strategy trade
function executeTrade(
bytes32 strategyId,
TradeParams calldata params
) external onlyRole(ORACLE_ROLE) returns (bytes32 tradeId);
struct TradeParams {
address tokenIn;
address tokenOut;
uint256 amountIn;
uint256 minAmountOut;
bytes swapData;
uint256 deadline;
}

Risk Controls

// Check trade against risk limits
function validateTrade(
bytes32 strategyId,
TradeParams calldata params
) internal view {
Strategy memory strategy = registry.getStrategy(strategyId);
// Check position size
require(
params.amountIn <= strategy.maxAllocation * maxPositionPct / 100,
"Position too large"
);
// Check daily volume
require(
dailyVolume[strategyId] + params.amountIn <= maxDailyVolume,
"Daily volume exceeded"
);
// Check slippage
uint256 expectedOut = oracle.getExpectedOutput(params);
require(
params.minAmountOut >= expectedOut * (100 - maxSlippage) / 100,
"Slippage too high"
);
}

AllocationManager

Manages capital allocation across strategies.

Allocation Structure

struct Allocation {
bytes32 strategyId;
uint256 amount;
uint256 percentage;
uint256 lastRebalance;
}

Key Functions

// Set strategy allocation
function setAllocation(
bytes32 strategyId,
uint256 percentage
) external onlyRole(ADMIN_ROLE);
// Rebalance allocations
function rebalance() external onlyRole(ORACLE_ROLE);
// Get current allocations
function getAllocations() external view returns (Allocation[] memory);

Rebalancing Logic

function rebalance() external onlyRole(ORACLE_ROLE) {
Allocation[] memory allocations = getAllocations();
uint256 totalValue = getTotalValue();
for (uint256 i = 0; i < allocations.length; i++) {
uint256 targetValue = totalValue * allocations[i].percentage / 100;
uint256 currentValue = getStrategyValue(allocations[i].strategyId);
if (currentValue > targetValue * (100 + rebalanceThreshold) / 100) {
// Reduce allocation
_reduceAllocation(allocations[i].strategyId, currentValue - targetValue);
} else if (currentValue < targetValue * (100 - rebalanceThreshold) / 100) {
// Increase allocation
_increaseAllocation(allocations[i].strategyId, targetValue - currentValue);
}
}
}

PerformanceTracker

Tracks and records strategy performance metrics.

Metrics Structure

struct PerformanceMetrics {
uint256 totalReturn;
uint256 sharpeRatio;
uint256 maxDrawdown;
uint256 winRate;
uint256 avgTradeSize;
uint256 totalTrades;
uint256 lastUpdate;
}

Key Functions

// Record trade result
function recordTrade(
bytes32 strategyId,
int256 pnl,
uint256 tradeSize
) external onlyRole(EXECUTOR_ROLE);
// Get performance metrics
function getMetrics(bytes32 strategyId) external view returns (PerformanceMetrics memory);
// Calculate Sharpe ratio
function calculateSharpe(bytes32 strategyId) external view returns (uint256);

Integration with Vaults

Strategies are connected to vaults through the Floor Engine:

// Vault allocates to strategy
function allocateToStrategy(
bytes32 strategyId,
uint256 amount
) external onlyVault {
require(registry.getStrategy(strategyId).status == StrategyStatus.LIVE, "Not live");
allocationManager.allocate(strategyId, amount);
}
// Strategy returns profits to vault
function returnProfits(
address vault,
uint256 amount
) external onlyRole(EXECUTOR_ROLE) {
IERC20(asset).transfer(vault, amount);
emit ProfitsReturned(vault, amount);
}

Security Features

Circuit Breaker

// Emergency stop for strategy
function emergencyStop(bytes32 strategyId) external onlyRole(GUARDIAN_ROLE) {
strategies[strategyId].status = StrategyStatus.DEPRECATED;
_closeAllPositions(strategyId);
emit EmergencyStop(strategyId, msg.sender);
}

Position Limits

LimitValue
Max Position Size10% of strategy allocation
Max Daily Volume50% of strategy allocation
Max Slippage2%
Max Drawdown20% (triggers review)

Last Updated: December 2025

results matching ""

    No results matching ""