All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cardanofoundation.rewards.calculation.DepositsCalculation Maven / Gradle / Ivy

Go to download

This project aims to be a cardano reward calculation, java formula implementation and edge case documentation

The newest version!
package org.cardanofoundation.rewards.calculation;

import org.cardanofoundation.rewards.calculation.domain.RetiredPool;

import java.math.BigInteger;
import java.util.Set;

public class DepositsCalculation {

    public static BigInteger calculateDepositsInEpoch(BigInteger depositsInPreviousEpoch,
                                                      BigInteger transactionDepositsInEpoch,
                                                      Set retiredPoolsInEpoch) {
        BigInteger deposits = BigInteger.ZERO;
        deposits = deposits.add(transactionDepositsInEpoch);

        //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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy