How to rank DeFi protocols by TVL with DefiLlama
Get a ranked table of DeFi protocols by current TVL, filtered by chain or category, so you can compare the market in one call
On this page
You need a ranked snapshot of 25 DeFi protocols on Arbitrum for a weekly treasury review, and you want the numbers in a table you can sort and annotate. One call to defillama.protocols.top returns that list, with current TVL per protocol plus 1-day and 7-day change fields
The worksheet below is the deliverable: one row per protocol, ordered by TVL, with the signals you used to decide what stays on the review list. No run has been executed for this article, so the table is a design and the values are placeholders showing the shape
Example input and the snapshot table
Example input, with the chain filter set to Arbitrum and 25 rows requested:
{"limit": 25, "chain": "Arbitrum"}The agent fills a table with nine columns. Values here are placeholders showing the shape
| rank | name | slug | category | chains | tvlUsd | change1d | change7d | url |
|---|---|---|---|---|---|---|---|---|
| 1 | (protocol name) | (slug) | (category or empty) | (chain list) | (number) | (percent or empty) | (percent or empty) | (link or empty) |
Rank is not an output field. You derive it from the order of the protocols array, with the first element as rank 1. Write it down as a column anyway, because a treasury review reads better when the row number matches the position
The inputs the endpoint takes
chain takes a string of 1 to 64 characters, and it is how you narrow the snapshot to Arbitrum. category takes a string of the same length, which suits a review about one kind of protocol rather than one network. Both are optional, and the input object in the contract lists no required properties
limit is an integer from 1 to 100 with a default of 25. Ask for 25 and the array holds at most 25 rows, which matches the weekly review
The limit maximum is 100, so matched may be larger than the returned protocols array. The array is capped at 100 items while matched reports the size of the set that passed the filter. If your chain carries more than 100 protocols, the snapshot is the top slice and you cannot read total chain TVL off it
Getting the chain string right
Chain names and category names come from your own DeFi watchlist. The contract gives chain and category as free strings with a length range and does not list accepted values, so a misspelled chain returns a filtered set that is not what you meant. Check the chains field on a returned row to confirm the filter landed where you expected
Reading the output fields that drive the decision
Each item in protocols carries name, slug, chains and tvlUsd as required fields. category, change1d, change7d, url and logo are present but can be null
tvlUsd sets the order and is the number you quote in the review. change1d and change7d decide monitoring: a protocol inside the top 25 with a large negative 7-day change is a candidate for the watch list, and a protocol that has held its TVL across the week is a candidate for the list you stop reviewing weekly. A null change field means there is no value to compare, and the row needs a manual look before it goes onto either list
slug is the stable identifier to store in your sheet. Names can repeat across chains or get renamed; the slug is what you join on next week. chains tells you whether the TVL figure is Arbitrum-only or spread across several networks, which matters when you compare a protocol against a chain-specific total. url and logo are display fields, and no decision depends on them
What one snapshot cannot tell you
The response is a single ranked list, not a time series. change1d and change7d are the only history in it, so a four-week trend line comes from storing four responses and comparing them yourself. The call also cannot hand you a chain total or a list of valid chain names; those live outside this contract
The agent prompt
Set up https://purrkey.app/SKILL.md, then use Purrkey to pull a ranked
DeFi protocol snapshot. Check the current inputs and price of
defillama.protocols.top before running anything. Call it once with
limit 25 and chain "Arbitrum". Return a table with rank, name, slug,
category, chains, tvlUsd, change1d, change7d and url, sorted by tvlUsd
descending, with rank 1 for the largest TVL. Write an empty cell when a
field is null. Do not invent rows and do not fill gaps with numbers
from another source. Also report the returned matched count next to the
number of rows in the table.Run it once, read the rows with null change fields, and adjust the chain string if chains comes back showing networks you did not ask for. To build the weekly series, keep the same prompt and file each response under its review date
Estimated tool cost
The rule text reads: "Fixed per-call price under the published tool contract; failed executions are not charged." The path is POST /v1/runs
| Step | Formula | Unit price | Planned quantity | Total |
|---|---|---|---|---|
| One ranked snapshot | calls x price | $0.0005 per call | 1 | $0.0005 |
| Four weekly snapshots | calls x price | $0.0005 per call | 4 | $0.002 |
| One quarter of weekly snapshots | calls x price | $0.0005 per call | 13 | $0.0065 |
The totals sit at the listed per-call price, and a failed execution is not charged, so a rejected call never appears in the bill. Model fees for the agent are not counted
Two chains per week for a quarter is 26 calls, at $0.013 at the listed price. A second filtered pass for one category on the same chain doubles the call count
Next action
Open https://purrkey.app/tools/defillama?q=top, check the current price revision on the card, and send the prompt above with your own chain string
Get started by giving this to your agent
- Claude Code
- Codex
- Gemini CLI
- Cursor
- GitHub Copilot
Set up https://purrkey.app/SKILL.md, then use Purrkey to show me what I can do with DefiLlama.FAQ
How do I rank DeFi protocols by TVL?
Call defillama.protocols.top and read the protocols array in the order it arrives. The largest tvlUsd sits first, so the array position gives you the rank and no rank field is returned.
What inputs does defillama.protocols.top take?
It takes limit, an integer from 1 to 100 with a default of 25, and the optional strings chain and category, each 1 to 64 characters. The input object lists no required properties.
Can I filter the protocol ranking by chain or category?
Yes. Pass a chain name such as Arbitrum in chain, or a category string from your own watchlist in category. Confirm the filter landed by reading the chains field on a returned row.
Why is matched larger than the number of protocols returned?
The limit maximum is 100 and the protocols array holds at most 100 items, while matched reports the size of the set that passed the filter. A chain with more than 100 protocols returns the top slice only.
Does the endpoint return a rank field?
No. Rank is derived from the order of the protocols array, with the first element as rank 1. Store it as a column in your own sheet.
How much does a weekly DeFi TVL snapshot cost?
The price is $0.0005 per call, so one snapshot is $0.0005 and four weekly snapshots are $0.002. Failed executions are not charged, and model fees for the agent are not counted.
What does a null change1d or change7d mean?
The contract allows both fields to be null, which means there is no value to compare for that protocol. Send the row for a manual look before it goes on a monitor or exclude list.
Next step
Try this with DefiLlama
The tool directory lists every endpoint with its current price. Inspect the inputs there, then let your agent run a small batch before scaling up.