Track interest in your dapp

Now its easy with @rtoken/utils

September 01, 2020

The rToken Project and rDAI is a 100% community supported open-source project. If you want an introduction or need a quick refresher, check out Victor Rortvedt’s intro blog post.

Calculate interest in your dapp

I just released a completely re-designed rDAI tool -@rtoken/utils

This tool and it’s early versions have been part of the core infrastructure for most of rDAI apps you’re familiar with, such as rTrees, High Priests, and the rDAI explorer. The updates mean you can now accurately calculate the exact amount of interest sent between any two entities.

Look we even have a badge! That means its totally legit.

πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡
npm
πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†πŸ‘†

Before this update the library was only able to get a β€œsnapshot” of the current state of interest streams. If you wanted to calculate interest, you could only get a rough estimate. But now its fully accurate, since it uses the change in value of cDAI itself. Stay tuned for another post which explains this a bit more.

You can use this library with your own rToken contracts, and your own rToken subgraph, if you desire. Please test it out, make issues, and give back! We need your help.

Getting started

The library is pretty straightforward:

npm i @rtoken/utils

After initialization, you can easily fetch user details:

const user = rutils.user('0xaaa...');
console.log(await user.interestSentTo('0xbbb...'));
// > 1.230495 DAI

And if you want all the entire history for a particular address:

console.log(await user.interestReceivedList());
// >
[
  {
    // Who sent the interest
    sender: '0x0efe994201e2b0136dd40d5033b5f437e4c5f958',
    // Amount of rDAI the sender is using to generate interest for this user
    amount: '100.000000000000000000',
    // Amount of rDAI this user has redeemed from the sender
    interestRedeemed: '0.07179777866578322382540442607287171',
    // Sum of interestRedeemd and all outstanding interest (unredeemed) from the sender
    interestSent: 2.683831612180583,
    // Internal Savings Asset for this loan
    sInternal: '10.000000012701007569669278674669046802622'
  }
];

See the code in the rToken monorepo @rtoken/utils.

Now you are prepared to use rDAI in your dapp - go forth and compute interest!

Stay tuned

Shortly I will be posting more about this library, why its so difficult to calculate Compound Protocol interest, and some history about the rToken Project and why I’m involved.