Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAL Hookathon - Dynamic Loyalty bond hook #106

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/foundry/contracts/hooks/DynamicBondHook/AccessControl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/access/AccessControl.sol";

contract DynamicBondAccessControl is AccessControl {
bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");

constructor() {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); // Grant the deployer the default admin role
_setupRole(MANAGER_ROLE, msg.sender); // Grant the deployer manager role
}

modifier onlyManager() {
require(hasRole(MANAGER_ROLE, msg.sender), "Caller is not a manager");
_;
}

function grantManagerRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
grantRole(MANAGER_ROLE, account);
}

function revokeManagerRole(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
revokeRole(MANAGER_ROLE, account);
}
}

37 changes: 37 additions & 0 deletions packages/foundry/contracts/hooks/DynamicBondHook/BadgeToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract RewardToken is ERC20 {
address public admin;

// Mapping to track rewards for each user
mapping(address => uint256) public userRewards;

event RewardsDistributed(address indexed user, uint256 amount);

constructor() ERC20("BadgeToken", "RWD") {
admin = msg.sender; // Assign the contract deployer as admin
}

modifier onlyAdmin() {
require(msg.sender == admin, "Not admin");
_;
}

// Function to mint rewards for a user
function distributeRewards(address user, uint256 amount) external onlyAdmin {
userRewards[user] += amount;
_mint(user, amount); // Mint the specified amount of tokens
emit RewardsDistributed(user, amount);
}

// Function to claim rewards
function claimRewards() external {
uint256 amount = userRewards[msg.sender];
require(amount > 0, "No rewards to claim");

userRewards[msg.sender] = 0; // Reset user rewards
_mint(msg.sender, amount); // Mint the tokens to the user
}
}
Loading