The Scriptorium
Smart Assembly code templates and tools for on-chain development in Eve Frontier.
← Back to Example Code
SSU Fuel Monitor
Resource HarvestingAn SSU (Smart Storage Unit) extension that tracks fuel consumption, emits alerts when fuel drops below a configurable threshold, and logs refueling events. Useful for monitoring remote deployments.
ssufuelmonitoringalerts
ssu-fuel-monitor.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @title SSUFuelMonitor
* @notice Monitors fuel levels on a Smart Storage Unit and emits
* low-fuel alerts when the level drops below a threshold.
*/
contract SSUFuelMonitor {
address public owner;
uint256 public fuelLevel;
uint256 public alertThreshold;
uint256 public totalConsumed;
event FuelAdded(uint256 amount, uint256 newLevel);
event FuelConsumed(uint256 amount, uint256 remaining);
event LowFuelAlert(uint256 remaining, uint256 threshold);
constructor(uint256 _alertThreshold) {
owner = msg.sender;
alertThreshold = _alertThreshold;
fuelLevel = 0;
totalConsumed = 0;
}
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
function addFuel(uint256 _amount) external onlyOwner {
require(_amount > 0, "Amount must be positive");
fuelLevel += _amount;
emit FuelAdded(_amount, fuelLevel);
}
function consumeFuel(uint256 _amount) external onlyOwner {
require(_amount <= fuelLevel, "Insufficient fuel");
fuelLevel -= _amount;
totalConsumed += _amount;
emit FuelConsumed(_amount, fuelLevel);
if (fuelLevel <= alertThreshold) {
emit LowFuelAlert(fuelLevel, alertThreshold);
}
}
function setAlertThreshold(uint256 _threshold) external onlyOwner {
alertThreshold = _threshold;
}
function getFuelStatus()
external
view
returns (uint256 current, uint256 threshold, uint256 consumed)
{
return (fuelLevel, alertThreshold, totalConsumed);
}
}