Skip to content

Add Cardano native SPO staking adapter#18485

Closed
mauriciomagaldi wants to merge 2 commits intoDefiLlama:mainfrom
mauriciomagaldi:add-cardano-spo-staking
Closed

Add Cardano native SPO staking adapter#18485
mauriciomagaldi wants to merge 2 commits intoDefiLlama:mainfrom
mauriciomagaldi:add-cardano-spo-staking

Conversation

@mauriciomagaldi
Copy link
Copy Markdown

@mauriciomagaldi mauriciomagaldi commented Mar 19, 2026

NOTE

Please enable "Allow edits by maintainers" while putting up the PR.


  • If you would like to add a volume/fees/revenue adapter please submit the PR here.
  • If you would like to add a liquidations adapter, please refer to this readme document for details.
  1. Once your adapter has been merged, it takes time to show on the UI. If more than 24 hours have passed, please let us know in Discord.
  2. Sorry, We no longer accept fetch adapter for new projects, we prefer the tvl to computed from blockchain data, if you have trouble with creating a the adapter, please hop onto our discord, we are happy to assist you.
  3. Please fill the form below only if the PR is for listing a new protocol else it can be ignored/replaced with reason/details about the PR
  4. For updating listing info It is a different repo, you can find your listing in this file: https://github.com/DefiLlama/defillama-server/blob/master/defi/src/protocols/data2.ts, you can edit it there and put up a PR
  5. Do not edit/push package-lock.json file as part of your changes, we use lockfileVersion 2, and most use v1 and using that messes up our CI
  6. No need to go to our discord and announce that you've created a PR, we monitor all PRs and will review it asap

Name (to be shown on DefiLlama):

Cardano SPO Staking

Twitter Link:

https://x.com/Cardano

List of audit links if any:

N/A — This adapter queries Cardano's native Ouroboros PoS consensus layer, not a smart contract. The staking mechanism is part of the core protocol, peer-reviewed and formally verified by IOHK Research (https://iohk.io/en/research/library/).

Website Link:

https://cardano.org/stake-pool-operation

Logo (High resolution, preferably in .svg and .png, for application on both white and black backgrounds. Will be shown with rounded borders):

https://cryptologos.cc/logos/cardano-ada-logo.svg https://cryptologos.cc/logos/cardano-ada-logo.png

Current TVL:
--- cardano-staking ---
ADA         21.82 B (~$6.3B at $0.29/ADA)
Total:      ~$6.3B
Treasury Addresses (if the protocol has treasury):

N/A — Native protocol-level staking, not a contract with a treasury address.

Chain:

Cardano

Coingecko ID (so your TVL can appear on Coingecko, leave empty if not listed):

cardano

Coinmarketcap ID (so your TVL can appear on Coinmarketcap):

https://coinmarketcap.com/currencies/cardano/

Short Description (to be shown on DefiLlama):

Cardano's native proof-of-stake delegation to ~2,948 stake pool operators (SPOs) via the Ouroboros consensus protocol. ADA holders delegate to pools without locking — staked ADA remains liquid and spendable at all times with no unbonding period.

Token address and ticker if any:

ADA (native token, no contract address)

Category (Yield/Dexes/Lending/Minting/Assets/Insurance/Options/Indexes/Staking):

Staking

Methodology:

Counts the total ADA actively delegated to all Cardano stake pool operators (SPOs) via the Ouroboros proof-of-stake consensus mechanism. Data is sourced from the Koios decentralized API's /epoch_info endpoint, which reports the aggregate active_stake (in lovelace) snapshot across all registered stake pools for each epoch (~5 days). The adapter queries the most recently completed epoch to ensure the stake snapshot is finalized.

Github org/user (Optional, if your code is open source):

https://github.com/cardano-community/koios-artifacts (data source) https://github.com/IntersectMBO/cardano-node (protocol)


Additional Context

Why this adapter is needed: Over 63% of circulating ADA (~21.82B ADA, ~$6.3B) is delegated to SPOs, but this is currently invisible on DeFi Llama. The existing Cardano "Total Staked" page shows only ~$27.9M from DeFi protocol-level staking (governance token staking in protocols like SundaeSwap, Liqwid). This adapter surfaces the native chain-level PoS staking under the "Staking" toggle, not default TVL.

Data source: Koios (https://api.koios.rest) — a decentralized, community-maintained, open-source REST API for Cardano blockchain data, operated by multiple independent node providers globally. It reads directly from cardano-db-sync, which indexes on-chain ledger state. The active_stake value comes from the Cardano ledger's epoch boundary snapshot.

Cross-reference validation:

Source Total ADA Staked USD (~$0.29/ADA)
Cardanoscan.io 21.82B ADA ~$6.33B
Cexplorer.io ~21.8B ADA ~$6.3B
PoolTool.io ~21.8B ADA ~$6.3B

Key distinction: Cardano staking is natively liquid — delegated ADA is never locked, has no unbonding period, and can be spent/moved at any time while still earning rewards.

Summary by CodeRabbit

  • New Features
    • Added Cardano SPO staking TVL tracking: retrieves active stake from the blockchain, validates the data, converts values to ADA, and displays the total active stake as a staking metric. Includes user-facing methodology text describing the calculation and provides an explicit staking metric for Cardano.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8625da50-0fa7-44f3-b329-2d247f85c4ae

📥 Commits

Reviewing files that changed from the base of the PR and between 3a5a319 and 7bf5b59.

📒 Files selected for processing (1)
  • projects/cardano-spo-staking/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • projects/cardano-spo-staking/index.js

📝 Walkthrough

Walkthrough

A new Cardano SPO staking module was added that queries the Koios API for the chain tip and epoch info, reads active_stake (lovelace), converts it to ADA using BigInt, and exports a cardano.staking function plus metadata and a no-op tvl.

Changes

Cohort / File(s) Summary
Cardano SPO Staking Module
projects/cardano-spo-staking/index.js
New module implementing staking() which fetches /tip and /epoch_info?epoch={currentEpoch-1}&select=active_stake from Koios, validates active_stake, converts lovelace→ADA with BigInt, returns { cardano: <ADA> }, and exports timetravel, methodology, and cardano.tvl/cardano.staking adapter.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I dug a query hole beneath the chain,
Koios hummed the epoch's secret name,
Lovelace turned to ADA in my paw,
I counted stakes without a flaw,
Hopping home, the totals sing—hurrah! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add Cardano native SPO staking adapter' directly and clearly summarizes the main change: introducing a new adapter for Cardano stake pool operator staking functionality.
Description check ✅ Passed The PR description comprehensively fills the template with all required fields for a new listing including Name, Twitter, Website, Logo, TVL, Chain, Category, Methodology, and additional context with data source validation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@llamabutler
Copy link
Copy Markdown

The adapter at projects/cardano-spo-staking exports TVL:

cardano-staking           5.76 B
staking                   5.76 B
cardano                   0.00

total                    0.00 

@mauriciomagaldi mauriciomagaldi marked this pull request as ready for review March 24, 2026 16:21
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@projects/cardano-spo-staking/index.js`:
- Around line 16-18: The code assumes get(`${KOIOS_API}/tip`) returns a
non-empty array and directly destructures into tip then reads tip.epoch_no; add
a defensive check after awaiting get(...) to verify the response is an array
with at least one element and that the first element has epoch_no (e.g., ensure
response && response.length > 0 and response[0].epoch_no !== undefined), and if
not, log/throw a clear error (using existing logger or throw) so currentEpoch is
not read from undefined; update the variables where tip and currentEpoch are
assigned in index.js to use this validation.
- Around line 29-35: Validate that epochInfo is an array with at least one
element before accessing epochInfo[0], and replace Number(...) conversion with
BigInt parsing for epochInfo[0].active_stake (e.g., const activeStakeLovelace =
BigInt(epochInfo[0].active_stake)); compute ADA safely by dividing and
formatting the BigInt (use integer division and remainder to produce a decimal
string or return the ADA amount as a string) and return that string under the
cardano key instead of a Number; update references to activeStakeLovelace and
the return object accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9d37b87c-4c7c-4175-9f95-b7b6934ce21b

📥 Commits

Reviewing files that changed from the base of the PR and between 80e869e and 3a5a319.

📒 Files selected for processing (1)
  • projects/cardano-spo-staking/index.js

Comment on lines +29 to +35
// active_stake is returned in lovelace (1 ADA = 1,000,000 lovelace)
const activeStakeLovelace = Number(epochInfo[0].active_stake);

// Return as ADA using coingecko ID; DeFi Llama SDK handles USD conversion
return {
cardano: activeStakeLovelace / 1e6,
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Precision loss: active_stake exceeds Number.MAX_SAFE_INTEGER.

The PR states ~21.82B ADA staked, which equals ~21.82 × 10¹⁵ lovelace. JavaScript's Number.MAX_SAFE_INTEGER is ~9 × 10¹⁵, so Number(epochInfo[0].active_stake) will lose precision for current Cardano staking levels.

Additionally, there's no validation that epochInfo contains data before accessing epochInfo[0].

Proposed fix using BigInt for safe conversion
-  // active_stake is returned in lovelace (1 ADA = 1,000,000 lovelace)
-  const activeStakeLovelace = Number(epochInfo[0].active_stake);
-
-  // Return as ADA using coingecko ID; DeFi Llama SDK handles USD conversion
-  return {
-    cardano: activeStakeLovelace / 1e6,
-  };
+  // active_stake is returned in lovelace (1 ADA = 1,000,000 lovelace)
+  // Use BigInt to avoid precision loss for values exceeding Number.MAX_SAFE_INTEGER
+  if (!epochInfo || !epochInfo.length || !epochInfo[0].active_stake) {
+    throw new Error(`No active_stake data for epoch ${epochToQuery}`);
+  }
+  const activeStakeLovelace = BigInt(epochInfo[0].active_stake);
+  const activeStakeAda = Number(activeStakeLovelace / BigInt(1e6));
+
+  // Return as ADA using coingecko ID; DeFi Llama SDK handles USD conversion
+  return {
+    cardano: activeStakeAda,
+  };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// active_stake is returned in lovelace (1 ADA = 1,000,000 lovelace)
const activeStakeLovelace = Number(epochInfo[0].active_stake);
// Return as ADA using coingecko ID; DeFi Llama SDK handles USD conversion
return {
cardano: activeStakeLovelace / 1e6,
};
// active_stake is returned in lovelace (1 ADA = 1,000,000 lovelace)
// Use BigInt to avoid precision loss for values exceeding Number.MAX_SAFE_INTEGER
if (!epochInfo || !epochInfo.length || !epochInfo[0].active_stake) {
throw new Error(`No active_stake data for epoch ${epochToQuery}`);
}
const activeStakeLovelace = BigInt(epochInfo[0].active_stake);
const activeStakeAda = Number(activeStakeLovelace / BigInt(1e6));
// Return as ADA using coingecko ID; DeFi Llama SDK handles USD conversion
return {
cardano: activeStakeAda,
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@projects/cardano-spo-staking/index.js` around lines 29 - 35, Validate that
epochInfo is an array with at least one element before accessing epochInfo[0],
and replace Number(...) conversion with BigInt parsing for
epochInfo[0].active_stake (e.g., const activeStakeLovelace =
BigInt(epochInfo[0].active_stake)); compute ADA safely by dividing and
formatting the BigInt (use integer division and remainder to produce a decimal
string or return the ADA amount as a string) and return that string under the
cardano key instead of a Number; update references to activeStakeLovelace and
the return object accordingly.

@llamabutler
Copy link
Copy Markdown

The adapter at projects/cardano-spo-staking exports TVL:

cardano-staking           5.65 B
staking                   5.65 B
cardano                   0.00

total                    0.00 

@RohanNero RohanNero self-assigned this Mar 24, 2026
@g1nt0ki
Copy link
Copy Markdown
Member

g1nt0ki commented Mar 25, 2026

sorry, we are not tracking staking for chains atm

@g1nt0ki g1nt0ki closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants