chore(XPToken): use XP Contribution for providers functions

This commit is contained in:
Andrea Franz
2024-10-08 10:57:15 +02:00
parent 4b787d478f
commit 0a5563e387
2 changed files with 15 additions and 11 deletions

View File

@@ -5,9 +5,9 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IXPProvider } from "./interfaces/IXPProvider.sol";
contract XPToken is Ownable {
string public name = "XP Token";
string public symbol = "XP";
uint8 public decimals = 18;
string public constant name = "XP Token";
string public constant symbol = "XP";
uint256 public constant decimals = 18;
uint256 public totalSupply;
@@ -37,21 +37,25 @@ contract XPToken is Ownable {
xpProviders.pop();
}
function getXPProviders() external view returns (IXPProvider[] memory) {
return xpProviders;
}
function balanceOf(address account) public view returns (uint256) {
uint256 userTotalXP = 0;
uint256 systemTotalXP = 0;
uint256 userTotalXPContribution = 0;
uint256 totalXPContribution = 0;
for (uint256 i = 0; i < xpProviders.length; i++) {
IXPProvider provider = xpProviders[i];
userTotalXP += provider.getUserXP(account);
systemTotalXP += provider.getTotalXP();
userTotalXPContribution += provider.getUserXPContribution(account);
totalXPContribution += provider.getTotalXPContribution();
}
if (systemTotalXP == 0) {
if (totalXPContribution == 0) {
return 0;
}
return (totalSupply * userTotalXP) / systemTotalXP;
return (totalSupply * userTotalXPContribution) / totalXPContribution;
}
function transfer(address, uint256) external pure returns (bool) {

View File

@@ -2,6 +2,6 @@
pragma solidity ^0.8.26;
interface IXPProvider {
function getTotalXP() external view returns (uint256);
function getUserXP(address user) external view returns (uint256);
function getTotalXPContribution() external view returns (uint256);
function getUserXPContribution(address user) external view returns (uint256);
}