Skip to content

Latest commit

 

History

History
113 lines (81 loc) · 2.91 KB

File metadata and controls

113 lines (81 loc) · 2.91 KB

JavaScript / Node.js — DeFiLlama Yield Scanner

Use the official apify-client SDK to run the DeFiLlama Yield Scanner and pull results into your Node app. These are client-side usage examples.

Install

npm install apify-client

Set your token (from Apify → Integrations):

export APIFY_TOKEN=apify_api_xxxxxxxxxxxxxxxxxxxxx

Basic run

import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });

const run = await client.actor('logiover/defillama-yield-scanner').call({
  chains: ['Ethereum', 'Solana'],
  minApy: 8,
  minTvlUsd: 1_000_000,
  sort: 'apy',
  maxResults: 250,
});

const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(`Got ${items.length} pools`);

console.table(
  items.slice(0, 10).map((p) => ({
    project: p.project,
    symbol: p.symbol,
    chain: p.chain,
    apy: p.apy,
    tvlUsd: p.tvlUsd,
  })),
);

Best stablecoin yields

import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });

const run = await client.actor('logiover/defillama-yield-scanner').call({
  stablecoinOnly: true,
  minApy: 6,
  minTvlUsd: 1_000_000,
  sort: 'apy',
  maxResults: 200,
});

const { items } = await client.dataset(run.defaultDatasetId).listItems();

const top = items
  .filter((p) => p.ilRisk === 'no')
  .sort((a, b) => b.apy - a.apy)
  .slice(0, 15);

for (const p of top) {
  console.log(`${p.apy.toFixed(2)}%  ${p.symbol.padEnd(12)} ${p.project} (${p.chain})`);
}

Compare APY for one asset across protocols

import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });

const run = await client.actor('logiover/defillama-yield-scanner').call({
  projects: ['aave', 'compound', 'morpho', 'spark'],
  sort: 'apy',
  maxResults: 2000,
});

const { items } = await client.dataset(run.defaultDatasetId).listItems();

const usdc = items.filter((p) => p.symbol === 'USDC');
console.table(
  usdc.map((p) => ({ project: p.project, chain: p.chain, apy: p.apy, tvlUsd: p.tvlUsd })),
);

Save to a JSON file

import { ApifyClient } from 'apify-client';
import { writeFile } from 'node:fs/promises';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });

const run = await client.actor('logiover/defillama-yield-scanner').call({ sort: 'tvl', maxResults: 5000 });
const { items } = await client.dataset(run.defaultDatasetId).listItems();

await writeFile('yields.json', JSON.stringify(items, null, 2));
console.log(`Saved ${items.length} pools to yields.json`);

See the full input/output reference in the main README.


▶️ Run on Apify →