-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add getRetiredPools() instead of getRewardAddressesOfRetiredPools to …
…track exact deposit amount
- Loading branch information
Showing
15 changed files
with
112 additions
and
52 deletions.
There are no files selected for viewing
15 changes: 9 additions & 6 deletions
15
calculation/src/main/java/org/cardanofoundation/rewards/calculation/DepositsCalculation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
package org.cardanofoundation.rewards.calculation; | ||
|
||
import org.cardanofoundation.rewards.calculation.config.NetworkConfig; | ||
import org.cardanofoundation.rewards.calculation.domain.RetiredPool; | ||
|
||
import java.math.BigInteger; | ||
import static org.cardanofoundation.rewards.calculation.util.BigNumberUtils.multiply; | ||
import java.util.Set; | ||
|
||
public class DepositsCalculation { | ||
|
||
public static BigInteger calculateDepositsInEpoch(BigInteger depositsInPreviousEpoch, | ||
BigInteger transactionDepositsInEpoch, | ||
int retiredPoolsInEpoch, | ||
NetworkConfig networkConfig) { | ||
Set<RetiredPool> retiredPoolsInEpoch) { | ||
BigInteger deposits = BigInteger.ZERO; | ||
deposits = deposits.add(transactionDepositsInEpoch); | ||
deposits = deposits.subtract( | ||
multiply(retiredPoolsInEpoch, networkConfig.getPoolDepositInLovelace())); | ||
|
||
//add deposits of retired pools | ||
var refundAmount = retiredPoolsInEpoch.stream() | ||
.reduce(BigInteger.ZERO, (sum, retiredPool) -> sum.add(retiredPool.getDepositAmount()), BigInteger::add); | ||
|
||
deposits = deposits.subtract(refundAmount); | ||
return depositsInPreviousEpoch.add(deposits); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
calculation/src/main/java/org/cardanofoundation/rewards/calculation/domain/RetiredPool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.cardanofoundation.rewards.calculation.domain; | ||
|
||
import lombok.*; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Objects; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RetiredPool { | ||
private String poolId; | ||
private String rewardAddress; | ||
private BigInteger depositAmount; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
RetiredPool that = (RetiredPool) o; | ||
return Objects.equals(poolId, that.poolId) && Objects.equals(rewardAddress, that.rewardAddress); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(poolId, rewardAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.