Skip to content

Commit

Permalink
chore(XPToken): use XP Contribution for providers functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityblast committed Oct 8, 2024
1 parent 768b71e commit 1d6205f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/XPToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/IXPProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 1d6205f

Please sign in to comment.