YieldOptions

The YieldOptions class lets you access yield data for various protocols on multiple chains. Use it to compare farm yields for your assets or discover new opportunities. It covers supported protocols, assets, and expected yields across different networks.

We currently support the following networks and protocols, with more being added soon:

Ethereum
โ”œโ”€โ”€ Aave V2
โ”œโ”€โ”€ Aave V3
โ”œโ”€โ”€ Aura
โ”œโ”€โ”€ Balancer
โ”œโ”€โ”€ Beefy
โ”œโ”€โ”€ Compound V2
โ”œโ”€โ”€ Compound V3
โ”œโ”€โ”€ Convex
โ”œโ”€โ”€ Curve
โ”œโ”€โ”€ Flux
โ”œโ”€โ”€ Idle
โ”œโ”€โ”€ Origin
โ”œโ”€โ”€ Yearn

Initialization

To set it up, provide a yield data source and specify the cache duration (in seconds).

const ttl = 3600; // cache for 1 hour
const yieldOptions = new YieldOptions(provider, ttl);

Choose Provider

Cached Provider

The CachedProvider is the most efficient solution. It is a simple wrapper class for static yield data. You pass it a URL pointing to a JSON file on initialization and it stores the data in memory.

const provider = new CachedProvider();
await provider.initialize("<https://raw.githubusercontent.com/Popcorn-Limited/apy-data/main/apy-data.json>");

const ttl = 3600;
const yieldOptions = new YieldOptions(provider, 3600);

Protocol Provider

The LiveProvider utilizes real-time yield data obtained from on-chain contracts or the protocol's API. To access on-chain data, it requires a connection to a viem public client.

const ttl = 3600;
const clients = {
    1: createPublicClient({
        chain: mainnet,
        transport: http()
    }),
};
const provider = new LiveProvider(clients, ttl);
const yieldOptions = new YieldOptions(provider, ttl);

Check our GitHub for available methods.

Last updated