Skip to content

aihedge-finance: add APY adapter for AIHedge vaults#2840

Open
aihedgefi wants to merge 1 commit into
DefiLlama:masterfrom
aihedgefi:add-aihedge-finance
Open

aihedge-finance: add APY adapter for AIHedge vaults#2840
aihedgefi wants to merge 1 commit into
DefiLlama:masterfrom
aihedgefi:add-aihedge-finance

Conversation

@aihedgefi

@aihedgefi aihedgefi commented Jul 22, 2026

Copy link
Copy Markdown

Protocol Details
Project Slug: aihedge-finance
Chain: Ethereum
Vault: 0x469201fA49DB171C0F95371533C2D3Ad5aE60400 (USDC Vault)
Website: AI Hedge Finance — Decentralized Yield Marketplace
App URL: AI Hedge Finance
Docs: Introduction | AIHedge Documentation
APY Methodology
The adapter queries the ERC-4626 convertToAssets share-to-asset rate between the current block and a block 24 hours prior (timestamp - 86400) to compute the 24-hour compounding base APY (apyBase) for AIHedge vaults.

Verification
Local test executed with npm test src/adaptors/test.js:

Returned 1 pool on Ethereum with correct TVL ($1,017 USD) and base APY (~9.0%).

Summary by CodeRabbit

  • New Features
    • Added support for tracking AIHedge Finance vaults on Ethereum.
    • Added vault TVL and underlying asset price reporting.
    • Added annualized base APY calculations based on historical vault performance.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an Ethereum adapter for one AI Hedge Finance vault. The adapter reads vault assets and share conversion rates at current and prior timestamps, fetches underlying prices, calculates TVL and annualized base APY, filters finite pools, and exports time-travel metadata.

Changes

AI Hedge Finance vault adapter

Layer / File(s) Summary
Vault APY calculation and adapter wiring
src/adaptors/aihedge-finance/index.js
Defines the vault configuration and reads token decimals, total assets, historical conversion rates, and underlying prices to calculate tvlUsd and annualized apyBase, then exports the adapter with timetravel: true, apy, and the project URL.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: 0xkr3p

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the change: it adds an APY adapter for AIHedge Finance vaults.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: one or more packages not found in the registry.


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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/adaptors/aihedge-finance/index.js`:
- Around line 65-67: Update the price handling in the vault TVL calculation to
stop defaulting missing prices to zero. Before calculating tvlUsd, validate the
resolved price is finite and greater than zero, and skip the current pool when
it is not; apply the same guard to the corresponding price lookup at the other
reported occurrence.
- Around line 20-25: Update apy() to accept and use the requested timetravel
timestamp instead of calling Date.now(), and derive both block lookups from that
same timestamp so historical backfills calculate the correct 24-hour window. If
this adaptor cannot support a supplied timestamp, explicitly configure it with
timetravel: false.
🪄 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: ac118636-bdc0-471a-a5c4-884000fee374

📥 Commits

Reviewing files that changed from the base of the PR and between 83ee686 and a596721.

📒 Files selected for processing (1)
  • src/adaptors/aihedge-finance/index.js

Comment on lines +20 to +25
async function apy() {
const timestamp = Math.floor(Date.now() / 1000);

const [{ height: blockNow }, { height: blockPrev }] = await Promise.all([
utils.getPriceApiData(`/block/${CHAIN}/${timestamp}`),
utils.getPriceApiData(`/block/${CHAIN}/${timestamp - DAY}`),

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline src/handlers/triggerAdaptor.js --items all
rg -n -C 3 -g '*.js' -g '*.ts' '\btimetravel\b|\bapy\s*\(' src

Repository: DefiLlama/yield-server

Length of output: 50379


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== triggerAdaptor outline ==\n'
ast-grep outline src/handlers/triggerAdaptor.js --items all

printf '\n== aihedge-finance outline ==\n'
ast-grep outline src/adaptors/aihedge-finance/index.js --items all

printf '\n== aihedge-finance file size ==\n'
wc -l src/adaptors/aihedge-finance/index.js

printf '\n== relevant snippets ==\n'
sed -n '1,220p' src/adaptors/aihedge-finance/index.js

Repository: DefiLlama/yield-server

Length of output: 3606


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== search for adaptor invocation signatures ==\n'
rg -n -C 2 'triggerAdaptor|timetravel|module\.exports|exports\.main|adapter.*timestamp|timestamp.*adaptor|ctx\.timestamp|runAdaptor|apy\s*\(' src/handlers src/adaptors | head -n 200

Repository: DefiLlama/yield-server

Length of output: 10317


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== triggerAdaptor.js =='
wc -l src/handlers/triggerAdaptor.js
sed -n '1,220p' src/handlers/triggerAdaptor.js

echo
echo '== aihedge-finance index.js =='
wc -l src/adaptors/aihedge-finance/index.js
sed -n '1,220p' src/adaptors/aihedge-finance/index.js

echo
echo '== timestamp plumbing search =='
rg -n -C 3 'timetravel|timestamp|Date\.now\(|blockNow|blockPrev|getPriceApiData|requestTimestamp|historical' src/handlers src/adaptors/aihedge-finance src | head -n 200

Repository: DefiLlama/yield-server

Length of output: 22054


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== aihedge-finance relevant lines =='
nl -ba src/adaptors/aihedge-finance/index.js | sed -n '1,220p'

echo
echo '== exact module export usage =='
rg -n -C 2 'timetravel|module\.exports|apy' src/adaptors/aihedge-finance/index.js

Repository: DefiLlama/yield-server

Length of output: 237


🏁 Script executed:

#!/bin/bash
set -euo pipefail

log=/tmp/coderabbit-shell-logs/shell-output-QGQAs0

echo '== aihedge-finance hits in prior log =='
rg -n -C 2 'aihedge-finance|src/handlers/triggerAdaptor\.js|timetravel|Date\.now\(' "$log" | head -n 200

echo
echo '== focused slice around any aihedge-finance mentions =='
first=$(rg -n 'aihedge-finance' "$log" | head -n 1 | cut -d: -f1 || true)
if [ -n "${first:-}" ]; then
  start=$((first-20)); [ "$start" -lt 1 ] && start=1
  end=$((first+120))
  sed -n "${start},${end}p" "$log"
fi

Repository: DefiLlama/yield-server

Length of output: 10698


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== body timestamp fields in triggerAdaptor.js =='
rg -n -C 3 'body\.(timestamp|date|time|block|from|to)|requestTimestamp|targetDate|timetravel|project\.apy\(' src/handlers/triggerAdaptor.js

echo
echo '== other adaptor runners and timestamp plumbing =='
rg -n -C 2 'body\.(timestamp|date|time|block)|requestTimestamp|targetDate|timetravel' src/handlers src/adaptors | head -n 200

Repository: DefiLlama/yield-server

Length of output: 10268


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== all body field reads in triggerAdaptor.js =='
rg -n 'body\.' src/handlers/triggerAdaptor.js

echo
echo '== aihedge-finance and similar timetravel adaptors that do not accept params =='
rg -n -C 1 'module\.exports = \{|timetravel: true|async function apy\(' src/adaptors/aihedge-finance/index.js src/adaptors | head -n 120

Repository: DefiLlama/yield-server

Length of output: 5587


Honor the timetravel contract
apy() reads Date.now(), so historical backfills still use the live 24h window. Thread the requested timestamp through this adaptor (and align the price lookups to the same time), or set timetravel: false.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/adaptors/aihedge-finance/index.js` around lines 20 - 25, Update apy() to
accept and use the requested timetravel timestamp instead of calling Date.now(),
and derive both block lookups from that same timestamp so historical backfills
calculate the correct 24-hour window. If this adaptor cannot support a supplied
timestamp, explicitly configure it with timetravel: false.

Comment on lines +65 to +67
const price = pricesByAddress[vault.underlying.toLowerCase()] || 0;

const tvlUsd = (total / 10 ** dec) * price;

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not report a missing price as zero TVL.

A missing price becomes 0, which passes keepFinite; a price-service failure therefore emits a false zero-TVL pool. Skip the pool unless its price is finite and positive.

Suggested guard
-    const price = pricesByAddress[vault.underlying.toLowerCase()] || 0;
+    const price = Number(pricesByAddress[vault.underlying.toLowerCase()]);
+    if (!Number.isFinite(price) || price <= 0) return null;
...
-  return pools.filter(utils.keepFinite);
+  return pools.filter(Boolean).filter(utils.keepFinite);

Also applies to: 86-86

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/adaptors/aihedge-finance/index.js` around lines 65 - 67, Update the price
handling in the vault TVL calculation to stop defaulting missing prices to zero.
Before calculating tvlUsd, validate the resolved price is finite and greater
than zero, and skip the current pool when it is not; apply the same guard to the
corresponding price lookup at the other reported occurrence.

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.

1 participant