11package org .cardanofoundation .rewards .calculation ;
22
3+ import org .cardanofoundation .rewards .calculation .config .NetworkConfig ;
34import org .cardanofoundation .rewards .calculation .domain .*;
45import org .cardanofoundation .rewards .calculation .enums .MirPot ;
56
1112import java .util .stream .Collectors ;
1213
1314import static org .cardanofoundation .rewards .calculation .PoolRewardsCalculation .calculatePoolRewardInEpoch ;
14- import static org .cardanofoundation .rewards .calculation .constants .RewardConstants .*;
1515import static org .cardanofoundation .rewards .calculation .util .BigNumberUtils .*;
1616import lombok .extern .slf4j .Slf4j ;
1717
@@ -31,10 +31,11 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch,
3131 final HashSet <String > registeredAccountsSinceLastEpoch ,
3232 final HashSet <String > registeredAccountsUntilNow ,
3333 final HashSet <String > sharedPoolRewardAddressesWithoutReward ,
34- final HashSet <String > deregisteredAccountsOnEpochBoundary ) {
34+ final HashSet <String > deregisteredAccountsOnEpochBoundary ,
35+ final NetworkConfig networkConfig ) {
3536 final EpochCalculationResult epochCalculationResult = EpochCalculationResult .builder ().epoch (epoch ).build ();
3637
37- if (epoch < MAINNET_SHELLEY_START_EPOCH ) {
38+ if (epoch < networkConfig . getShelleyStartEpoch () ) {
3839 log .warn ("Epoch " + epoch + " is before the start of the Shelley era. No rewards were calculated in this epoch." );
3940 epochCalculationResult .setReserves (BigInteger .ZERO );
4041 epochCalculationResult .setTreasury (BigInteger .ZERO );
@@ -43,13 +44,13 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch,
4344 epochCalculationResult .setTotalPoolRewardsPot (BigInteger .ZERO );
4445 epochCalculationResult .setTotalAdaInCirculation (BigInteger .ZERO );
4546 return epochCalculationResult ;
46- } else if (epoch == MAINNET_SHELLEY_START_EPOCH ) {
47- epochCalculationResult .setReserves (MAINNET_SHELLEY_INITIAL_RESERVES );
48- epochCalculationResult .setTreasury (MAINNET_SHELLEY_INITIAL_TREASURY );
47+ } else if (epoch == networkConfig . getShelleyStartEpoch () ) {
48+ epochCalculationResult .setReserves (networkConfig . getShelleyInitialReserves () );
49+ epochCalculationResult .setTreasury (networkConfig . getShelleyInitialTreasury () );
4950 epochCalculationResult .setTotalDistributedRewards (BigInteger .ZERO );
5051 epochCalculationResult .setTotalRewardsPot (BigInteger .ZERO );
5152 epochCalculationResult .setTotalPoolRewardsPot (BigInteger .ZERO );
52- epochCalculationResult .setTotalAdaInCirculation (MAINNET_SHELLEY_INITIAL_UTXO );
53+ epochCalculationResult .setTotalAdaInCirculation (networkConfig . getShelleyInitialUtxo () );
5354 return epochCalculationResult ;
5455 }
5556
@@ -72,7 +73,7 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch,
7273
7374 final int blocksInEpoch = totalBlocksInEpoch ;
7475 final BigInteger rewardPot = TreasuryCalculation .calculateTotalRewardPotWithEta (
75- monetaryExpandRate , totalBlocksInEpoch , decentralizationParameter , reserveInPreviousEpoch , totalFeesForCurrentEpoch );
76+ monetaryExpandRate , totalBlocksInEpoch , decentralizationParameter , reserveInPreviousEpoch , totalFeesForCurrentEpoch , networkConfig );
7677
7778 final BigInteger treasuryCut = multiplyAndFloor (rewardPot , treasuryGrowthRate );
7879 BigInteger treasuryForCurrentEpoch = treasuryInPreviousEpoch .add (treasuryCut );
@@ -95,8 +96,8 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch,
9596 !ownerAccountsRegisteredInThePast .contains (rewardAddress )) {
9697 // If the reward address has been unregistered, the deposit can not be returned
9798 // and will be added to the treasury instead (Pool Reap see: shelley-ledger.pdf p.53)
98- treasuryForCurrentEpoch = treasuryForCurrentEpoch .add (POOL_DEPOSIT_IN_LOVELACE );
99- unclaimedRefunds = unclaimedRefunds .add (POOL_DEPOSIT_IN_LOVELACE );
99+ treasuryForCurrentEpoch = treasuryForCurrentEpoch .add (networkConfig . getPoolDepositInLovelace () );
100+ unclaimedRefunds = unclaimedRefunds .add (networkConfig . getPoolDepositInLovelace () );
100101 }
101102 }
102103 }
@@ -114,7 +115,7 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch,
114115
115116 treasuryForCurrentEpoch = treasuryForCurrentEpoch .subtract (treasuryWithdrawals );
116117 BigInteger totalDistributedRewards = BigInteger .ZERO ;
117- final BigInteger adaInCirculation = TOTAL_LOVELACE .subtract (reserveInPreviousEpoch );
118+ final BigInteger adaInCirculation = networkConfig . getTotalLovelace () .subtract (reserveInPreviousEpoch );
118119 final List <PoolRewardCalculationResult > poolRewardCalculationResults = new ArrayList <>();
119120 BigInteger unspendableEarnedRewards = BigInteger .ZERO ;
120121
@@ -146,15 +147,15 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch,
146147 // This is not the case anymore and the stake account receives the reward for all pools
147148 // Until the Allegra hard fork, this method will be used to emulate the old behavior
148149 boolean ignoreLeaderReward = false ;
149- if (epoch - 2 < MAINNET_ALLEGRA_HARDFORK_EPOCH ) {
150+ if (epoch - 2 < networkConfig . getAllegraHardforkEpoch () ) {
150151 ignoreLeaderReward = sharedPoolRewardAddressesWithoutReward .contains (poolId );
151152 }
152153
153154 poolRewardCalculationResult = calculatePoolRewardInEpoch (poolId , poolState ,
154155 blocksInEpoch , protocolParameters ,
155156 adaInCirculation , activeStakeInEpoch , stakePoolRewardsPot ,
156157 poolState .getOwnerActiveStake (), poolState .getOwners (),
157- delegatorAccountDeregistrations , ignoreLeaderReward , lateDeregisteredDelegators , registeredAccountsSinceLastEpoch );
158+ delegatorAccountDeregistrations , ignoreLeaderReward , lateDeregisteredDelegators , registeredAccountsSinceLastEpoch , networkConfig );
158159 }
159160
160161 totalDistributedRewards = add (totalDistributedRewards , poolRewardCalculationResult .getDistributedPoolReward ());
@@ -167,15 +168,15 @@ public static EpochCalculationResult calculateEpochRewardPots(final int epoch,
167168 calculatedReserve = add (calculatedReserve , undistributedRewards );
168169 calculatedReserve = subtract (calculatedReserve , unspendableEarnedRewards );
169170
170- if (epoch == MAINNET_ALLEGRA_HARDFORK_EPOCH ) {
171+ if (epoch == networkConfig . getAllegraHardforkEpoch () ) {
171172 /*
172173 "The bootstrap addresses from Figure 6 were not intended to include the Byron era redeem
173174 addresses (those with addrtype 2, see the Byron CDDL spec). These addresses were, however,
174175 not spendable in the Shelley era. At the Allegra hard fork they were removed from the UTxO
175176 and the Ada contained in them was returned to the reserves."
176177 - shelley-spec-ledger.pdf 17.5 p.115
177178 */
178- calculatedReserve = calculatedReserve .add (MAINNET_BOOTSTRAP_ADDRESS_AMOUNT );
179+ calculatedReserve = calculatedReserve .add (networkConfig . getBootstrapAddressAmount () );
179180 }
180181
181182 log .debug ("Unspendable earned rewards: " + unspendableEarnedRewards .longValue () + " Lovelace" );
0 commit comments