Teacher Performance Bonus Contract
What it does:
Automatically calculates and distributes bonuses to teachers based on student performance, course completion rates, or other predefined metrics.
Why it matters:
Aligns teacher incentives with educational outcomes, encourages quality teaching, ensures transparent and fair bonus distribution, and reduces administrative overhead.
How it works:
-
School or platform funds the bonus pool on-chain
-
Teacher performance metrics (grades, completion rates, student feedback) are reported
-
Smart contract calculates bonus amounts based on predefined rules or thresholds
-
Bonuses are automatically released to teachers’ wallets
-
Teachers and administrators can audit calculations and payouts
-
Unclaimed or surplus funds remain in the pool or can be reallocated
-
Full transaction history and metrics are immutably stored
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title TeacherPerformanceBonus
* @author Nam
* @notice Distributes bonuses to teachers based on performance metrics
*/
contract TeacherPerformanceBonus {
address public admin;
uint256 public teacherCount;
struct Teacher {
address payable teacherAddress;
uint256 performanceScore; // 0 - 100
uint256 bonusClaimed;
}
mapping(uint256 => Teacher) public teachers;
// -------------------- EVENTS --------------------
event TeacherRegistered(uint256 indexed teacherId, address indexed teacher);
event PerformanceUpdated(uint256 indexed teacherId, uint256 score);
event BonusClaimed(uint256 indexed teacherId, uint256 amount);
event PoolFunded(address indexed donor, uint256 amount);
// -------------------- MODIFIERS --------------------
modifier onlyAdmin() {
require(msg.sender == admin, "Not admin");
_;
}
// -------------------- CONSTRUCTOR --------------------
constructor() {
admin = msg.sender;
}
// -------------------- TEACHER MANAGEMENT --------------------
function registerTeacher(address payable _teacherAddress) external onlyAdmin {
require(_teacherAddress != address(0), "Invalid address");
teacherCount += 1;
teachers[teacherCount] = Teacher({
teacherAddress: _teacherAddress,
performanceScore: 0,
bonusClaimed: 0
});
emit TeacherRegistered(teacherCount, _teacherAddress);
}
function updatePerformance(uint256 _teacherId, uint256 _score) external onlyAdmin {
require(_teacherId 0, "Invalid teacher ID");
require(_score 0, "No funds in pool");
uint256 bonus = calculateBonus(t.performanceScore);
require(bonus > 0, "No bonus");
t.bonusClaimed += bonus;
payable(t.teacherAddress).transfer(bonus);
emit BonusClaimed(_teacherId, bonus);
}
function calculateBonus(uint256 _score) internal view returns (uint256) {
// Simple proportional bonus: score% of contract balance
uint256 bonus = (address(this).balance * _score) / 100;
return bonus;
}
// -------------------- FUNDING --------------------
function fundPool() external payable {
require(msg.value > 0, "No funds sent");
emit PoolFunded(msg.sender, msg.value);
}
receive() external payable {}
}