// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./e2XUsernames.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract DataCreditPoints is Ownable { e2XUsernames public userDataContract; IERC20 public e2xToken; uint256 public pointsPerToken; mapping(string => mapping(address => uint256)) public dcpBalance; mapping(address => uint256) public totalDCPBalance; event PointsRatioUpdated(uint256 newPointsPerToken); event DCPUpdated(string e2xUserID, address user, uint256 amount, bool added); constructor(address _userDataContract, address _e2xToken) { userDataContract = e2XUsernames(_userDataContract); e2xToken = IERC20(_e2xToken); pointsPerToken = 100; // 100 DCP per E2X token initially } function setPointsPerToken(uint256 _newPointsPerToken) external onlyOwner { pointsPerToken = _newPointsPerToken; emit PointsRatioUpdated(_newPointsPerToken); } function transferE2XToken(uint256 _amount) external { require(_amount > 0, "Amount must be greater than 0"); require(e2xToken.transferFrom(msg.sender, address(this), _amount), "E2X token transfer failed"); uint256 dcpAmount = _amount * pointsPerToken; string memory e2xUserID = userDataContract.getData(msg.sender); dcpBalance[e2xUserID][msg.sender] += dcpAmount; totalDCPBalance[msg.sender] += dcpAmount; emit DCPUpdated(e2xUserID, msg.sender, dcpAmount, true); } function transferDCP(address _recipient, uint256 _amount) external { require(_amount > 0, "Amount must be greater than 0"); require(dcpBalance[userDataContract.getData(msg.sender)][msg.sender] >= _amount, "Insufficient DCP balance"); dcpBalance[userDataContract.getData(msg.sender)][msg.sender] -= _amount; dcpBalance[userDataContract.getData(_recipient)][_recipient] += _amount; emit DCPUpdated(userDataContract.getData(msg.sender), msg.sender, _amount, false); emit DCPUpdated(userDataContract.getData(_recipient), _recipient, _amount, true); } function withdrawE2XToken(uint256 _amount) external onlyOwner { require(_amount > 0, "Amount must be greater than 0"); require(e2xToken.balanceOf(address(this)) >= _amount, "Insufficient E2X token balance"); require(e2xToken.transfer(owner(), _amount), "E2X token transfer failed"); } // For transferring ownership and migrating the contract function transferToNewContract(address _newContract) external view onlyOwner { require(_newContract != address(0), "Invalid new contract address"); // Implement logic to transfer data to the new contract } function changeAdmin(address _newAdmin) external onlyOwner { require(_newAdmin != address(0), "Invalid admin address"); transferOwnership(_newAdmin); } }