Beispiel #1
0
    def calculate(self, reward_data3, total_amount):

        new_rewards = []

        # move skipped records to next phase
        for rl3 in self.iterateskipped(reward_data3):
            new_rewards.append(rl3)

        for rl3 in self.filterskipped(reward_data3):
            if rl3.type == TYPE_FOUNDERS_PARENT:
                for addr, ratio in self.founders_map.items():
                    rl4 = RewardLog(addr, TYPE_FOUNDER, 0, 0)
                    # new ratio is parent ratio * ratio of the founder
                    rl4.ratio = ratio * rl3.ratio
                    rl4.ratio4 = rl4.ratio
                    rl4.service_fee_ratio = 0
                    rl4.service_fee_rate = 0
                    rl4.parent = rl3
                    new_rewards.append(rl4)

                # if no founders, add parent object to rewards list
                if not self.founders_map.items():
                    new_rewards.append(rl3)

            elif rl3.type == TYPE_OWNERS_PARENT:
                for addr, ratio in self.owners_map.items():
                    rl4 = RewardLog(addr, TYPE_OWNER,
                                    ratio * rl3.staking_balance, 0)
                    # new ratio is parent ratio * ratio of the owner
                    rl4.ratio = ratio * rl3.ratio
                    rl4.ratio4 = rl4.ratio
                    rl4.service_fee_ratio = 0
                    rl4.service_fee_rate = 0
                    rl4.parent = rl3
                    new_rewards.append(rl4)

                # if no owners, add parent object to rewards list
                if not self.owners_map.items():
                    new_rewards.append(rl3)
            else:
                rl3.ratio4 = rl3.ratio
                new_rewards.append(rl3)

        return new_rewards, total_amount
Beispiel #2
0
    def calculate(self, reward_data2, total_amount):

        new_rewards = []
        total_excluded_ratio = 0.0

        for rl2 in self.iterateskipped(reward_data2):
            # move skipped records to next phase
            new_rewards.append(rl2)

        # exclude requested items
        for rl2 in self.filterskipped(reward_data2):
            if rl2.address in self.excluded_set:
                rl2.skip(desc=BY_CONFIGURATION, phase=self.phase)
                new_rewards.append(rl2)
                total_excluded_ratio += rl2.ratio
            elif (
                MIN_DELEGATION_KEY in self.excluded_set
                and rl2.staking_balance < self.min_delegation_amount
            ):
                rl2.skip(desc=BY_MIN_DELEGATION, phase=self.phase)
                new_rewards.append(rl2)
                total_excluded_ratio += rl2.ratio
            else:
                new_rewards.append(rl2)

        total_service_fee_ratio = total_excluded_ratio

        # set fee rates and ratios
        for rl in self.filterskipped(new_rewards):
            rl.service_fee_rate = self.fee_calc.calculate(rl.originaladdress)
            rl.service_fee_ratio = rl.service_fee_rate * rl.ratio
            rl.ratio = rl.ratio - rl.service_fee_ratio
            rl.ratio3 = rl.ratio

            total_service_fee_ratio += rl.service_fee_ratio

        # create founders parent record
        if total_service_fee_ratio > ALMOST_ZERO:
            rl = RewardLog(
                address=TYPE_FOUNDERS_PARENT,
                type=TYPE_FOUNDERS_PARENT,
                staking_balance=0,
                current_balance=0,
            )
            rl.service_fee_rate = 0
            rl.service_fee_ratio = 0
            rl.ratio = total_service_fee_ratio
            rl.ratio3 = rl.ratio

            new_rewards.append(rl)

        return new_rewards, int(total_amount)
    def calculate(self, reward_logs):
        # if address is in address destination dictionary;
        # then set payment address to mapped address value
        for rl in self.filterskipped(reward_logs):
            rl.ratio6 = rl.ratio

        address_set = set(rl.paymentaddress
                          for rl in self.filterskipped(reward_logs))
        payment_address_list_dict = {addr: [] for addr in address_set}

        # group payments by paymentaddress
        for rl in self.filterskipped(reward_logs):
            payment_address_list_dict[rl.paymentaddress].append(rl)

        reward_data6 = []
        for rl in self.iterateskipped(reward_logs):
            reward_data6.append(rl)

        for addr, rl_list in payment_address_list_dict.items():
            if len(rl_list) > 1:
                total_staking_balance = sum(
                    [rl.staking_balance for rl in rl_list])
                total_current_balance = sum(
                    [rl.current_balance for rl in rl_list])
                total_ratio = sum([rl.ratio for rl in rl_list])
                total_payment_amount = sum([rl.amount for rl in rl_list])
                total_adjusted_payment_amount = sum(
                    [rl.adjusted_amount for rl in rl_list])
                total_adjustment = sum([rl.adjustment for rl in rl_list])
                total_service_fee_amount = sum(
                    [rl.service_fee_amount for rl in rl_list])
                total_service_fee_ratio = sum(
                    [rl.service_fee_ratio for rl in rl_list])

                merged = RewardLog(addr, TYPE_MERGED, total_staking_balance,
                                   total_current_balance)
                merged.ratio = total_ratio
                merged.amount = total_payment_amount
                merged.adjusted_amount = total_adjusted_payment_amount
                merged.adjustment = total_adjustment
                merged.service_fee_amount = total_service_fee_amount
                merged.service_fee_ratio = total_service_fee_ratio
                merged.service_fee_rate = 0
                merged.parents = rl_list

                reward_data6.append(merged)
            else:
                reward_data6.append(rl_list[0])

        return reward_data6