This documentation outlines the process used to aggregate Language TVL (Total Value Locked) and Language Fees for blockchain protocols using public APIs and a structured method.
1. Data Sources
APIs Used:
DefiLlama Protocols API URL: https://api.llama.fi/protocols Purpose: Provides detailed information about protocols, including their TVL, contract addresses, and metadata like associated chains.
DefiLlama Fees API URL: https://api.llama.fi/overview/fees Purpose: Provides protocol fee data, including total fees and revenue.
Etherscan API URL: https://api.etherscan.io/apiPurpose: Retrieves contract details, including the compiler version (e.g., Solidity, Vyper), by querying smart contract addresses.
2. Process Overview
This process combines data from the DefiLlama Protocols API, DefiLlama Fees API, and Etherscan API to correlate protocols with their primary programming languages and calculate aggregated metrics like TVL and Fees for each language.
3. Step-by-Step Methodology
Step 1: Fetch Protocol Data (TVL and Metadata)
Query the DefiLlama Protocols API to fetch a list of all protocols along with their:
Name
Contract addresses
TVL (Total Value Locked)
Blockchain(s) supported.
Example request:
GET https://api.llama.fi/protocols
Step 2: Fetch Fee Data
Query the DefiLlama Fees API to fetch protocol fees:
Daily, monthly, and yearly fees.
Breakdown of fees across supported chains.
Example request:
GET https://api.llama.fi/overview/fees?excludeTotalDataChart=true&excludeTotalDataChartBreakdown=true&dataType=dailyFees
Step 3: Retrieve Compiler Language Using Etherscan API
Input: Contract addresses retrieved from the DefiLlama Protocols API.
Query the Etherscan API for each contract address to get the compiler version.
Example request:
GET https://api.etherscan.io/api
?module=contract
&action=getsourcecode
&address=0xContractAddress
&apikey=YourEtherscanAPIKey
Response Fields:
CompilerVersion: Indicates the programming language (e.g., Solidity v0.8.4).
ABI: Used to validate the contract type.
If no compiler version is returned, the protocol is classified under "Unidentified."
Step 4: Cross-Reference Data
Use the protocol name or contract address to match:
Fee data from the DefiLlama Fees API.
Compiler language from the Etherscan API.
Step 5: Aggregate Data by Programming Language
Group protocols by their primary compiler language (e.g., Solidity, Vyper, etc.).
Aggregate the following metrics for each language:
TVL: Sum of TVL across all protocols using the language.
Fees: Sum of yearly fees across all protocols using the language.
4. Output and Visualization
Data Outputs
Aggregated Language Metrics: A table with the following columns:
Language (e.g., Solidity, Vyper)
Total TVL
Total Fees
Detailed Protocol Data: A table linking protocol names to their:
TVL
Fees
Compiler Language.
5. Challenges and Notes
Etherscan Rate Limits: The Etherscan API has rate limits; an appropriate delay mechanism was implemented.
Matching Errors: Some protocol names or contract addresses may not directly match, requiring manual reconciliation.
Unidentified Contracts: Some contracts returned no compiler data from Etherscan and were grouped under "Unidentified."
By combining data from the DefiLlama Protocols API, DefiLlama Fees API, and Etherscan API, we created a comprehensive view of how programming languages correlate with TVL and Fees.
The final dataset provides insights into the dominance of languages like Solidity in the Ethereum ecosystem.
Comments