From 40c9305bd865a9e746684e2ca51f0b4fd1df82ac Mon Sep 17 00:00:00 2001 From: AntonAndell Date: Thu, 27 Jun 2024 13:31:16 +0200 Subject: [PATCH] add better debug methods --- .../score/core/rewards/DataSourceImpl.java | 24 +++++++++++++++---- .../score/core/rewards/RewardsImpl.java | 13 ++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) 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 updateSingleUserData(BigInteger currentTime, Bal Map totalWeight = updateTotalWeight(lastUpdateTimestamp, currentTime, balances, externalRewards, readOnlyContext); Map 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 getDataAt(BigInteger day) { sourceData.put("contract_address", getContractAddress()); sourceData.put("workingSupply", getWorkingSupply()); sourceData.put("total_dist", getTotalDist(day, true)); + Address[] externalRewards = getRewardTokens(); + Map 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 getData() { return getDataAt(RewardsImpl.getDay()); } + public Map getUserData(String user) { + Map 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> getDataSources() { return dataSources; } + @External(readonly = true) + public Map> getUserSourceData(String user) { + Map> 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> getDataSourcesAt(BigInteger _day) { Map> dataSources = new HashMap<>();