How To: Forecast maximum lend earnings using LEND.MARKETS

🧠
This is part of our How To series: A selection of use-cases that have high educational value, and/or best showcases Vektor's capabilities. We will continue to add new How To articles over time, and they should not be considered exhaustive! Vektor is a powerful tool and VXL is a very flexible language with many different use-cases; this is just a taster.

🏁 Skip to the "answer"

Objective & Benefit

When it comes to lending your assets in DeFi, there is a lot of choice. For any single asset, many markets exist, across many different venues and chains. Mostly supply APYs are variable and change regularly, and so it can be difficult to understand which venue to lend your assets to, and how much you can expect to earn if you do.

We're going to use this example to show how Vektor can very easily search for and summarise all the different lending opportunities existing for a certain asset (USDC), and then process that information to calculate the actual expected earnings if you lent your USDC to the maximum yielding opportunity.

Functions used

LEND.MARKETS - get the current market rates for lending an asset
LIST.FIRST - get the first item of a list
GET - gets the value for a specific field if present in an object
DECIMAL - convert a percentage/string/integer into a decimal
BALANCE - get the balance of an asset on a blockchain for a label
* - multiplication arithmetic operator

Step-by-step

1. See a list of all supported lending markets

Use the LEND.MARKETS function to instantly see all the supply APYs on all supported assets, venues, and blockchains, all in one list and live updating every few seconds.

A list of all lending markets supported by Vektor

As it stands, we can see here many different lending markets encompassing different assets. But for this use case we're only interested in USDC.

2. Filter to show only USDC lending markets

You can use the INCLUDE_ASSETS= filter option, common across many functions, to restrict the search to just lending markets for USDC, while still searching all venues and chains.

A list of lending markets, filtered to only show USDC markets

We're interested in the maximum earnings potential, so we're going to drill down deeper on the lending market that's at the top of this list (the list is automatically sorted by SUPPLY_APY.

3. Extract the best market from the top of the list

Vektor's LIST function is useful for processing lists.

Vektor's LIST function and it's sub-functions

We're going to use the LIST.FIRST sub-function and wrap it around our LEND.MARKETS function to take the first item from the markets list.

LEND.MARKETS function nested inside LIST.FIRST function

The result is a single market object that has been extracted from the top of the (sorted) markets list.

To forecast our potential earnings, we need to access the SUPPLY_APY from this market object.

4. Get the SUPPLY_APY data point from the market object

Vektor's data model allows us to access invidual data points from any object. In this example the available data points from the lend market object are

  • ASSET (here, USDC)
  • VENUE (here, RADIANT)
  • BLOCKCHAIN (here, ARBITRUM)
  • TOTAL_SUPPLY (here, 37,684,919)
  • SUPPLY_APY (here, 2.06%)

There are two ways to access data points; you can either use the GET function, or you can use dot . suffix notation. They both do the same thing. You can read more on a separate post here. We're going to use the GET function to get the SUPPLY_APY data point.

The SUPPLY_APY datapoint has been pulled from the market object using the GET function

5. Calculate expected earnings using this APY

In the final step we will simply multiply this supply APY with our balance of USDC. By doing so we can answer the question:

If I lent all of my USDC at this rate, what earnings could I expect?

You can achieve this using the BALANCES function and some simple multiplication arithmetic on the previous statement.

Expected annual earnings = (total USDC balance) * (USDC supply APY)
The maximum annual lend earnings expected if we lent all of our USDC to the current best USDC market
⚠️
NB currently we have to use the DECIMAL function to conver the SUPPLY_APY (percentage) to a decimal format for multiplication. This may change in future. 

Success! We now have our earnings potential forecast, fully dynamic and constantly updating to reflect changes in our USDC balances (wherever they are) and to reflect the current best lending market (whichever venue or chain it occurs).

We could easily now use the LEND function to actually deploy our USDC into this market, making an on-chain transaction using Vektor. That's out of scope for this How-To article.


Hope you liked this How-To use-case! You can find more here.

💎
Do you have an excellent Vektor use-case that you'd like to have featured? We'd love to hear from you!

Read more: