// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./e2XUsers1.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract VoucherContract { e2XUsernames public userDataContract; mapping(address => bool) public usedVouchers; mapping(address => string) public voucherCodes; mapping(address => uint256) public e2xCumulativeTotal; event VoucherRedeemed(address indexed member, string voucherId, uint256 tcPointsAwarded, string usdeVoucherCode); event USDeWithdrawn(uint256 amount); event WithdrawAdminChanged(address indexed previousAdmin, address indexed newAdmin); address public owner; address public withdrawAdmin; IERC20 public usdeToken; modifier onlyWithdrawAdmin() { require(msg.sender == withdrawAdmin, "Only withdraw admin can call this function"); _; } modifier onlyOwner() { require(msg.sender == owner, "Only contract owner can call this function"); _; } constructor(address _userDataContract, address _usdeToken, address _withdrawAdmin) { userDataContract = e2XUsernames(_userDataContract); usdeToken = IERC20(_usdeToken); withdrawAdmin = _withdrawAdmin; owner = msg.sender; } function deposit() external { // Deposit 35 USDe tokens uint256 depositAmount = 35 * 10**18; // 35 USDe tokens with 18 decimals usdeToken.transferFrom(msg.sender, address(this), depositAmount); // Transfer 10 USDe tokens to referrer address referrerAddress = userDataContract.getAddressByUser(userDataContract.getData(msg.sender)); require(referrerAddress != address(0), "Referrer not found"); uint256 referrerAmount = 10 * 10**18; // 10 USDe tokens with 18 decimals usdeToken.transfer(referrerAddress, referrerAmount); // Increment e2x cumulative total e2xCumulativeTotal[msg.sender] += 15; } function redeemVoucher(string memory voucherId) external { require(!usedVouchers[msg.sender], "Voucher has already been used"); // Verify the voucher code and mark it as used voucherCodes[msg.sender] = voucherId; usedVouchers[msg.sender] = true; // Increment e2x cumulative total e2xCumulativeTotal[msg.sender] += 15; emit VoucherRedeemed(msg.sender, voucherId, 1500, generateVoucherCode(userDataContract.getData(msg.sender))); } function generateVoucherCode(string memory memberId) internal pure returns (string memory) { // Dummy implementation to generate a unique voucher code return string(abi.encodePacked(memberId, "-USDe20")); } function e2xBurn(address memberAddress) external view returns (uint256) { return e2xCumulativeTotal[memberAddress]; } function withdrawUSDe(uint256 amount) external onlyWithdrawAdmin { require(amount > 0, "Withdrawal amount must be greater than 0"); uint256 balance = usdeToken.balanceOf(address(this)); require(amount <= balance, "Insufficient balance in the contract"); usdeToken.transfer(msg.sender, amount); emit USDeWithdrawn(amount); } function setWithdrawAdmin(address newAdmin) external onlyOwner { require(newAdmin != address(0), "Invalid address"); emit WithdrawAdminChanged(withdrawAdmin, newAdmin); withdrawAdmin = newAdmin; } // Function to query voucher status by e2xdata ID function queryVoucherStatus() external view returns (string memory) { return voucherCodes[msg.sender]; } }