Computing and Accumulating Interest On-Chain (common patterns and their properties)

Computing and Accumulating Interest On-Chain (common patterns and their properties)

Many DeFi projects need to compute interest on chain, and they often need to accumulate interest over several different user accounts at the same time.

In this presentation we look at the challenges of computing compound interest on-chain, and the two main approaches that DeFi projects use to overcome them. We discuss the pros and cons of each.

We also discuss the most common way we’re seeing projects accumulate compound interest over several accounts at once.

The video can be seen here:
Computing and Accumulating Interest On-Chain - Presentation video

And the slides can be seen here:

4 Likes

Fantastic video! Really digs into the math behind Maker DSR and Compound.

I was aware of the “IOU” pattern after reading Compound’s code, but I like your name for it. The only concern I have with it is that the exchange rate is constantly increasing: numbers being finite this means the contract will eventually hit a numerical limit.

Have you done any math around how long it would take for the exchange rate to hit a numerical limit? For example, an exchange rate of 10% APR would last for how many years before overflow starts to occur. I’m sure it’s infinitesimal, but I’d be curious to see. It’s probably as likely as a hash collision in the transparent proxy pattern :slight_smile:

I’ve gotten word from @nventuro that a fixed point library from OZ is incoming. I can’t wait to see it.

1 Like

@Austin-Williams

Has anyone used an approximation of compound interest rather than using the exponentiation by squaring algorithm?

Specifically, we could use the binomial series approximation:
(1 + r )^t ≈ 1 + rt

This is generally valid when |rt| << 1, which should hold when the interest is accrued frequently. It is also, O(1), so it should be very gas efficient. Considering that the gas spent computing all of the interest accruals over the course of the year, the additional loss of accuracy may be worth it.

2 Likes