       %{} = address ->
         new_balance = filter_balance(address.address, address.balance)
 
-        new_tx = Enum.map(
-          address.histories,
-          fn %{
-               :txid => txid,
-               :balance => balance,
-               :block_height => block_height
-             } ->
-            %{
-              :txid => txid,
-              :balance => filter_balance(balance),
-              :block_height => block_height
-            }
-          end
-        )
+        new_tx =
+          address.histories
+          |> Stream.with_index()
+          |> Enum.map(
+            fn {
+              %{
+                :txid => txid,
+                :balance => balance,
+                :block_height => block_height
+              },
+              index
+            } ->
+              prev_tx = Enum.at(address.histories, index + 1)
+              prev_balance = Map.fetch(prev_tx, :balance)
+              %{
+                :txid => txid,
+                :balance => modify_balance_output(balance, prev_balance),
+                :block_height => block_height
+              }
+            end
+          )
 
         Map.merge(
           address,
           %{
             :balance => new_balance,
-            :txids => new_tx,
-            :unclaimed => Unclaimed.calculate_bonus(address.id)
+            :txids => new_tx
           }
         )
         |> Map.delete(:inserted_at)

       )
  end

  defp filter_balance(balance) do
    Map.to_list(balance)
    |> Enum.map(
         fn {_as, %{"asset" => asset, "amount" => amount}} ->
           %{
             "asset" => ChainAssets.get_asset_name_by_hash(asset),
             "amount" => Helpers.round_or_not(amount)
           }
         end
       )
  end

  @doc """

      nil -> %{:address => "not found", :claimable => nil}

      %{} = address ->
        Map.merge(
          address,
          %{
            claimable: Unclaimed.calculate_vouts_bonus(address.id),
            unclaimed: Unclaimed.calculate_bonus(address.id)
          }
        )
        |> Map.delete(:id)
    end
