Here I'm referring to https://compound.finance, which is quite an awesome product.

One thing inspires me most is that the interests accrued in Compound are updated per block. How's that even possible?

From its FAQ (https://medium.com/compound-finance/faq-1a2636713b69):

How often is interest calculated?

The interest rates you see in the Interface and Market Overview are quoted as annual interest rates. Interest accrues each Ethereum block; every ~15 seconds, your balance will increase by (1/2102400) of the quoted interest rate. Really!

I still couldn't figure out how to do that, as I'm seeing exactly it works even without frontend UI - by setting requestedAmount to be 0xff...ff.

Can someone please educate me on this? Thanks.


It seems daunting bordering on impossible if you imagine a balances database updated every fifteen seconds.

That isn't necessary. If one has a principle amount, a rate, and elapsed time periods, one can calculate interest and present balance.

Hope it helps.

  • Hi Rob, you're right. But the thing is that if someone deposit or withdrawal some assest, then the interest rate for that particular asset changes, and the changed interest rate would affect all ppl who supplied / borrowed. - It seems Compound still works for all who are affected, I'm wondering how's that handled – nrek Apr 16 at 7:26
  • Contract source code: etherscan.io/address/… There is a lot to wade through, but you might start around 921 function calculateInterestIndex(. From eyeballing it superficially, they are using the principle described. – Rob Hitchens - B9lab Apr 16 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.