mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Split up calculateShare into 4 distinct methods
Reduce visibility to package scope Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
3fda949526
commit
ec25722d08
5 changed files with 49 additions and 40 deletions
|
@ -32,7 +32,7 @@ public final class BurnOutputModel {
|
|||
private final long date;
|
||||
private final int cycleIndex;
|
||||
|
||||
public BurnOutputModel(long amount,
|
||||
BurnOutputModel(long amount,
|
||||
long decayedAmount,
|
||||
int height,
|
||||
String txId,
|
||||
|
|
|
@ -42,8 +42,9 @@ public final class BurningManCandidate {
|
|||
private double effectiveBurnOutputShare; // limited to boostedIssuanceShare
|
||||
private final List<CompensationModel> compensationModels = new ArrayList<>();
|
||||
private final List<BurnOutputModel> burnOutputModels = new ArrayList<>();
|
||||
private Optional<String> mostRecentAddress = Optional.empty();
|
||||
|
||||
public BurningManCandidate() {
|
||||
BurningManCandidate() {
|
||||
}
|
||||
|
||||
public void addBurnOutputModel(BurnOutputModel burnOutputModel) {
|
||||
|
@ -70,18 +71,27 @@ public final class BurningManCandidate {
|
|||
|
||||
accumulatedDecayedCompensationAmount += compensationModel.getDecayedAmount();
|
||||
accumulatedCompensationAmount += compensationModel.getAmount();
|
||||
|
||||
mostRecentAddress = compensationModels.stream()
|
||||
.max(Comparator.comparing(CompensationModel::getHeight))
|
||||
.map(CompensationModel::getAddress);
|
||||
}
|
||||
|
||||
public void calculateShare(double totalIssuanceWeight,
|
||||
double totalBurnOutputWeight,
|
||||
long burnTarget,
|
||||
long averageDistributionPerCycle) {
|
||||
public void calculateIssuanceShare(double totalIssuanceWeight) {
|
||||
issuanceShare = totalIssuanceWeight > 0 ? accumulatedDecayedCompensationAmount / totalIssuanceWeight : 0;
|
||||
boostedIssuanceShare = issuanceShare * BurningManService.ISSUANCE_BOOST_FACTOR;
|
||||
}
|
||||
|
||||
public void calculateBurnOutputShare(double totalBurnOutputWeight) {
|
||||
burnOutputShare = totalBurnOutputWeight > 0 ? accumulatedDecayedBurnAmount / totalBurnOutputWeight : 0;
|
||||
effectiveBurnOutputShare = Math.min(boostedIssuanceShare, burnOutputShare);
|
||||
}
|
||||
|
||||
public void calculateExpectedRevenue(long averageDistributionPerCycle) {
|
||||
expectedRevenue = Math.round(effectiveBurnOutputShare * averageDistributionPerCycle);
|
||||
}
|
||||
|
||||
public void calculateAllowedBurnAmount(long burnTarget) {
|
||||
double maxBurnAmount = burnTarget + BurningManService.BURN_TARGET_BOOST_AMOUNT;
|
||||
if (issuanceShare > 0 && maxBurnAmount > 0 && effectiveBurnOutputShare < boostedIssuanceShare) {
|
||||
// We reduce it with what he had already burned
|
||||
|
@ -91,14 +101,6 @@ public final class BurningManCandidate {
|
|||
} else {
|
||||
allowedBurnAmount = 0;
|
||||
}
|
||||
|
||||
expectedRevenue = Math.round(averageDistributionPerCycle * effectiveBurnOutputShare);
|
||||
}
|
||||
|
||||
public Optional<String> getMostRecentAddress() {
|
||||
return compensationModels.stream()
|
||||
.max(Comparator.comparing(CompensationModel::getHeight))
|
||||
.map(CompensationModel::getAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -184,10 +184,17 @@ class BurningManService {
|
|||
double totalDecayedBurnAmounts = burningManCandidates.stream()
|
||||
.mapToDouble(BurningManCandidate::getAccumulatedDecayedBurnAmount)
|
||||
.sum();
|
||||
long averageDistributionPerCycle = getAverageDistributionPerCycle(chainHeight);
|
||||
long burnTarget = getBurnTarget(chainHeight, burningManCandidates);
|
||||
|
||||
burningManCandidates.forEach(candidate ->
|
||||
candidate.calculateShare(totalDecayedCompensationAmounts, totalDecayedBurnAmounts, burnTarget, getAverageDistributionPerCycle(chainHeight)));
|
||||
burningManCandidates.forEach(candidate -> {
|
||||
candidate.calculateIssuanceShare(totalDecayedCompensationAmounts);
|
||||
candidate.calculateBurnOutputShare(totalDecayedBurnAmounts);
|
||||
candidate.calculateExpectedRevenue(averageDistributionPerCycle);
|
||||
candidate.calculateAllowedBurnAmount(burnTarget);
|
||||
}
|
||||
);
|
||||
|
||||
return burningManCandidatesByName;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import lombok.Getter;
|
|||
@Getter
|
||||
@EqualsAndHashCode
|
||||
public final class CompensationModel {
|
||||
public static CompensationModel fromCompensationRequest(String address,
|
||||
static CompensationModel fromCompensationRequest(String address,
|
||||
long amount,
|
||||
long decayedAmount,
|
||||
int height,
|
||||
|
@ -43,7 +43,7 @@ public final class CompensationModel {
|
|||
cycleIndex);
|
||||
}
|
||||
|
||||
public static CompensationModel fromGenesisOutput(String address,
|
||||
static CompensationModel fromGenesisOutput(String address,
|
||||
long amount,
|
||||
long decayedAmount,
|
||||
int height,
|
||||
|
|
|
@ -30,7 +30,7 @@ public final class ReimbursementModel {
|
|||
private final long date;
|
||||
private final int cycleIndex;
|
||||
|
||||
public ReimbursementModel(long amount,
|
||||
ReimbursementModel(long amount,
|
||||
int height,
|
||||
long date,
|
||||
int cycleIndex) {
|
||||
|
|
Loading…
Add table
Reference in a new issue