diff --git a/core-contracts/Rewards/src/main/java/network/balanced/score/core/rewards/DataSourceImpl.java b/core-contracts/Rewards/src/main/java/network/balanced/score/core/rewards/DataSourceImpl.java index ac0861272..6d4c15ea1 100644 --- a/core-contracts/Rewards/src/main/java/network/balanced/score/core/rewards/DataSourceImpl.java +++ b/core-contracts/Rewards/src/main/java/network/balanced/score/core/rewards/DataSourceImpl.java @@ -278,10 +278,6 @@ public Map<Address, BigInteger> updateSingleUserData(BigInteger currentTime, Bal Map<Address, BigInteger> totalWeight = updateTotalWeight(lastUpdateTimestamp, currentTime, balances, externalRewards, readOnlyContext); Map<Address, BigInteger> accruedRewards = new HashMap<>(externalRewards.length+1); accruedRewards.put(baln, BigInteger.ZERO); - if (currentUserWeight.equals(totalWeight.get(baln))) { - return accruedRewards; - } - // If the user's current weight is less than the total, update their weight and issue rewards if (balances.prevWorkingBalance.compareTo(BigInteger.ZERO) > 0) { @@ -418,6 +414,13 @@ public Map<String, Object> getDataAt(BigInteger day) { sourceData.put("contract_address", getContractAddress()); sourceData.put("workingSupply", getWorkingSupply()); sourceData.put("total_dist", getTotalDist(day, true)); + Address[] externalRewards = getRewardTokens(); + Map<String, Object> externalData = new HashMap<>(); + for (Address addr : externalRewards) { + externalData.put("external_dist", getTotalExternalDist(day, addr)); + externalData.put("total_weight", getTotalExternalWeight(addr)); + sourceData.put(addr.toString(), externalData); + } return sourceData; } @@ -426,6 +429,19 @@ public Map<String, Object> getData() { return getDataAt(RewardsImpl.getDay()); } + public Map<String, Object> getUserData(String user) { + Map<String, Object> data = new HashMap<>(); + Address[] externalRewards = getRewardTokens(); + data.put("user_weight", getUserWeight(user)); + data.put("balance", getBalance(user)); + data.put("working balance", getWorkingBalance(user, true)); + + for (Address addr : externalRewards) { + data.put(addr.toString() + "_weight", getExternalUserWeight(user,addr)); + } + return data; + } + private BigInteger computeUserRewards(BigInteger prevUserBalance, BigInteger totalWeight, BigInteger userWeight) { BigInteger deltaWeight = totalWeight.subtract(userWeight); return deltaWeight.multiply(prevUserBalance).divide(EXA); diff --git a/core-contracts/Rewards/src/main/java/network/balanced/score/core/rewards/RewardsImpl.java b/core-contracts/Rewards/src/main/java/network/balanced/score/core/rewards/RewardsImpl.java index a4c768361..7db2f9452 100644 --- a/core-contracts/Rewards/src/main/java/network/balanced/score/core/rewards/RewardsImpl.java +++ b/core-contracts/Rewards/src/main/java/network/balanced/score/core/rewards/RewardsImpl.java @@ -247,6 +247,19 @@ public Map<String, Map<String, Object>> getDataSources() { return dataSources; } + @External(readonly = true) + public Map<String, Map<String, Object>> getUserSourceData(String user) { + Map<String, Map<String, Object>> dataSources = new HashMap<>(); + int dataSourcesCount = DataSourceDB.size(); + for (int i = 0; i < dataSourcesCount; i++) { + String name = DataSourceDB.names.get(i); + DataSourceImpl dataSource = DataSourceDB.get(name); + dataSources.put(name, dataSource.getUserData(user)); + } + + return dataSources; + } + @External(readonly = true) public Map<String, Map<String, Object>> getDataSourcesAt(BigInteger _day) { Map<String, Map<String, Object>> dataSources = new HashMap<>();