def calc_supply_age(
    prev_cs, cs, transferred_value, prev_age_ms, ms_since_prev_block
) -> int:
    """
    Calculate mean supply height in ms from given args.

    Definitions:
     - h: height
     - s(h): circulating supply at h
     - a(h): mean supply age at h
     - e(h): coinbase emission for block h
     - x(h): transferred ERG in block h, excluding r(h)
     - t(h): time between current and previous block

    At h = 1
    --------
    s(1) = e(1)
    a(1) = 0
    x(1) = 0

    At h = 2
    --------
    x(2) <= s(1)
    s(2) = s(1) + e(2)
    a(2) = [ (s(1) - x(2)) * (a(1) + t(h)) ] / s(2)

    At h = n
    --------
    x(n) <= s(n-1)
    s(n) = s(n-1) + e(n)
    a(n) = [ (s(n-1) - x(n)) * (a(n-1) + t(n)) ] / s(n)
    """
    return ((prev_cs - transferred_value) * (prev_age_ms + ms_since_prev_block)) / cs