How To: Forecast maximum lend earnings using LEND.MARKETS
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.
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
1. See a list of all supported lending markets
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.
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.
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
3. Extract the best market from the top of the list
LIST function is useful for processing lists.
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.
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
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.
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)
DECIMALfunction 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.
- News: Vektor launches Lend and Borrow functionality!
- Spotlight: LEND and BORROW function spotlight
- Explainer: What is VXL
- Explainer: VXL Common Syntax Patterns
- More How-To's