Skip to content

Commit

Permalink
add better debug methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAndell committed Jun 27, 2024
1 parent 2883c3a commit 40c9305
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down

0 comments on commit 40c9305

Please sign in to comment.