Skip to content

Add Yield AI (Aptos) adapter#18684

Open
ssadkov wants to merge 3 commits intoDefiLlama:mainfrom
ssadkov:add-yield-ai-aptos
Open

Add Yield AI (Aptos) adapter#18684
ssadkov wants to merge 3 commits intoDefiLlama:mainfrom
ssadkov:add-yield-ai-aptos

Conversation

@ssadkov
Copy link
Copy Markdown

@ssadkov ssadkov commented Apr 7, 2026

NOTE

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


  1. If you would like to add a volume/fees/revenue adapter please submit the PR here.

  2. 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.

  3. 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.

  4. For updating listing info It is a different repo, you can find your listing in this file, you can edit it there and put up a PR

  5. Please do not add new npm dependencies, do not edit/push pnpm-lock.yaml file as part of your changes


(Needs to be filled only for new listings)

Name (to be shown on DefiLlama):
Yield AI

Twitter Link:
https://x.com/yieldai_app

List of audit links if any:
N/A

Website Link:
https://yieldai.app/

Logo (High resolution, will be shown with rounded borders):
PR to DefiLlama/icons: yield-ai.png (pending/merged). Temporary logo path for listing: https://icons.llama.fi/yield-ai.png

Current TVL:
~$700–$1.5k on Aptos at time of testing (varies with on-chain balances).

Treasury Addresses (if the protocol has treasury)
N/A

Chain:
Aptos

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

Coinmarketcap ID (so your TVL can appear on Coinmarketcap, leave empty if not listed):
N/A

Short Description (to be shown on DefiLlama):
Yield AI is a DeFi dashboard for Aptos that integrates 10+ protocols and an AI Agent in one interface. Track balances and positions, compare APRs, and deposit, withdraw, swap, and claim rewards gaslessly — all to maximize your yield.

Token address and ticker if any:
N/A

Category (full list at https://defillama.com/categories) *Please choose only one:
AI Agents

Oracle Provider(s): Specify the oracle(s) used (e.g., Chainlink, Band, API3, TWAP, etc.):
N/A

Implementation Details: Briefly describe how the oracle is integrated into your project:
N/A

Documentation/Proof: Provide links to documentation or any other resources that verify the oracle's usage:
N/A

forkedFrom (Does your project originate from another project):
N/A

methodology (what is being counted as tvl, how is tvl being calculated):
TVL counts (1) fungible-asset balances held on Yield AI vault safe object addresses on Aptos (Aptos Labs indexer current_fungible_asset_balances, owner = safe), (2) native APT held in each safe’s CoinStore via 0x1::coin::balance<0x1::aptos_coin::AptosCoin> (native APT FA rows are skipped to avoid double counting), and (3) Moar Market supply positions attributed to each safe via 0xa3af...::pool::get_all_pools (paused pools excluded) and per (pool index, safe) 0xa3af...::lens::get_lp_shares_and_deposited_amount, adding the deposited underlying amount (response index 1) using each pool’s underlying_asset metadata (APT pool uses 0xa). Safes are enumerated using on-chain vault views get_total_safes / get_safes_range_info; only entries with exists == true are included (paused safes are included). Note: Moar is also listed separately on DefiLlama; maintainers may want to confirm how this overlap should be presented to avoid double counting in aggregate views.
No protocol backend/API is used; TVL is computed from Aptos on-chain views + Aptos Labs Indexer GraphQL for fungible balances.

Github org/user (Optional, if your code is open source, we can track activity):
N/A

Does this project have a referral program?
N/A

Summary by CodeRabbit

  • New Features
    • Added Yield AI TVL tracking for Aptos: aggregates vault safes, fungible-asset balances, native APT balances, and liquidity pool deposits to report total value locked across Yield AI.
  • Documentation
    • Includes a clear methodology describing how TVL is counted and attributed.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

📝 Walkthrough

Walkthrough

New Aptos TVL adapter module added at projects/yield-ai/index.js that enumerates Yield AI vault safes, aggregates fungible assets via GraphQL, collects native APT balances on-chain, and attributes Moar pool deposits to underlying tokens.

Changes

Cohort / File(s) Summary
Yield AI TVL Module
projects/yield-ai/index.js
New module (≈429 LOC) exporting aptos.tvl. Enumerates safes via on-chain views, batches GraphQL queries for fungible-asset balances (skips native APT), queries native APT balances per safe, fetches Moar pools and per-(safe,pool) deposited amounts, normalizes addresses/token IDs, uses controlled concurrency and optional debug tracing, and exports methodology and flags (timetravel: false, doublecounted: true).

Sequence Diagram

sequenceDiagram
    participant TVL as TVL Calculator
    participant OnChain as Aptos On-Chain
    participant Indexer as Aptos Labs Indexer

    TVL->>OnChain: call get_total_safes()
    OnChain-->>TVL: safe count
    TVL->>OnChain: call get_safes_range_info()
    OnChain-->>TVL: safe list/details

    TVL->>Indexer: query current_fungible_asset_balances (batched safe owners)
    Indexer-->>TVL: fungible balances per safe

    TVL->>OnChain: coin::balance<AptosCoin> per safe (concurrent)
    OnChain-->>TVL: native APT balances

    TVL->>OnChain: MOAR::pool::get_all_pools()
    OnChain-->>TVL: pool list
    TVL->>OnChain: MOAR::lens::get_lp_shares_and_deposited_amount(safe,pool) (concurrent)
    OnChain-->>TVL: deposited amounts

    TVL->>TVL: normalize & aggregate amounts
    TVL->>TVL: api.add(token, amount) per asset
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 I nibble on code, hops light and spry,
Counting safes beneath Aptos sky,
Coins, tokens, pools — I tally with cheer,
Batches and pools make the picture clear,
A rabbit's small hop brings Yield AI near.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% 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 clearly and specifically describes the main change: adding a TVL adapter for Yield AI on Aptos, matching the changeset which introduces a new adapter module.
Description check ✅ Passed The PR description comprehensively fills the required template sections for a new listing, including protocol name, website, Twitter, chain, category, TVL methodology, and other relevant details.

✏️ 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/yield-ai exports TVL:

aptos                     732.00

total                    731.51 

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/yield-ai/index.js`:
- Around line 424-429: The adapter exports currently omit the doublecounted
flag, causing higher-level aggregates to double-count Moar (already tracked
separately); update the exported object (module.exports) to include
doublecounted: true alongside timetravel and aptos (i.e., add the property
"doublecounted: true" within the module.exports object where timetravel, aptos,
and methodology are defined) so the adapter is marked as double-counted.
- Around line 352-365: The concurrent PromisePool call using
PromisePool.withConcurrency(...).for(safeAddresses).process(...) currently
ignores the returned result so any errors from function_view are swallowed;
update the call in projects/yield-ai/index.js to await the PromisePool.process()
return value, inspect the returned result.errors array (from the PromisePool
API) and handle non-empty errors by logging them (or rethrowing) so failures are
surfaced and stop/mark the run as partial; reference the
PromisePool.withConcurrency/.for/.process invocation and the async worker that
calls function_view/COIN_BALANCE_FN to locate where to capture and handle
result.errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb2ef651-6e93-4163-ab37-f395103d1e7f

📥 Commits

Reviewing files that changed from the base of the PR and between aa21b6d and 342d3e0.

📒 Files selected for processing (1)
  • projects/yield-ai/index.js

@llamabutler
Copy link
Copy Markdown

The adapter at projects/yield-ai exports TVL:

aptos                     732.00

total                    731.54 

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.

🧹 Nitpick comments (1)
projects/yield-ai/index.js (1)

110-122: Minor edge case: scientific notation strings return incorrect values.

If v is a string like "1e10", the function returns "1" instead of "10000000000". While Aptos chain responses typically return raw integer strings making this unlikely in practice, consider handling this case for defensive robustness.

♻️ Optional fix to handle scientific notation
 function toIntegerString(v) {
   if (v == null) return null;
   if (typeof v === "bigint") return v.toString();
   if (typeof v === "number") {
     if (!Number.isFinite(v)) return null;
     return BigInt(Math.trunc(v)).toString();
   }
   const s = String(v).trim();
   if (!s) return null;
+  // Handle scientific notation strings like "1e10"
+  if (/^-?\d+(\.\d+)?[eE][+-]?\d+$/.test(s)) {
+    const num = Number(s);
+    if (Number.isFinite(num)) return BigInt(Math.trunc(num)).toString();
+    return null;
+  }
   const intPart = s.split(".")[0].split("e")[0].split("E")[0];
   if (!/^-?\d+$/.test(intPart)) return null;
   return intPart;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@projects/yield-ai/index.js` around lines 110 - 122, The toIntegerString
function mishandles numeric strings in scientific notation (e.g. "1e10"); update
toIntegerString to detect when the trimmed input string s contains "e" or "E",
parse it with Number(s) (ensure it's finite), convert to an integer via
Math.trunc, then return BigInt(thatNumber).toString() (preserving sign); if that
conversion fails or loses precision, fall back to the existing intPart
validation logic using intPart and the /^\-?\d+$/ test. Locate this logic inside
toIntegerString where s and intPart are defined.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@projects/yield-ai/index.js`:
- Around line 110-122: The toIntegerString function mishandles numeric strings
in scientific notation (e.g. "1e10"); update toIntegerString to detect when the
trimmed input string s contains "e" or "E", parse it with Number(s) (ensure it's
finite), convert to an integer via Math.trunc, then return
BigInt(thatNumber).toString() (preserving sign); if that conversion fails or
loses precision, fall back to the existing intPart validation logic using
intPart and the /^\-?\d+$/ test. Locate this logic inside toIntegerString where
s and intPart are defined.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c3a5bc1a-461b-4c7f-8788-83aa965efd36

📥 Commits

Reviewing files that changed from the base of the PR and between 342d3e0 and 50f32e7.

📒 Files selected for processing (1)
  • projects/yield-ai/index.js

@ssadkov
Copy link
Copy Markdown
Author

ssadkov commented Apr 8, 2026

Implemented the requested changes: added doublecounted: true (Moar overlap) and now capture PromisePool.process() results for APT + Moar calls and throw if result.errors is non-empty to surface RPC/view failures. node test.js projects/yield-ai/index.js passes.

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.

2 participants