aihedge-finance: add APY adapter for AIHedge vaults#2840
Conversation
📝 WalkthroughWalkthroughAdds 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. ChangesAI Hedge Finance vault adapter
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/adaptors/aihedge-finance/index.js
| 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}`), |
There was a problem hiding this comment.
🎯 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*\(' srcRepository: 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.jsRepository: 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 200Repository: 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 200Repository: 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.jsRepository: 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"
fiRepository: 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 200Repository: 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 120Repository: 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.
| const price = pricesByAddress[vault.underlying.toLowerCase()] || 0; | ||
|
|
||
| const tvlUsd = (total / 10 ** dec) * price; |
There was a problem hiding this comment.
🗄️ 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.
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