-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feat: add orrai quant terminal #2624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GNaD13
wants to merge
3
commits into
DefiLlama:master
Choose a base branch
from
oraichain:feat/quant-terminal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| const utils = require('../utils'); | ||
|
|
||
| const LCD_ENDPOINT = 'https://lcd.orai.io'; | ||
| const CHAIN = 'arbitrum'; | ||
| const PROJECT = 'orai-quant-terminal'; | ||
| const APP_URL = 'https://quant.orai.io/vault'; | ||
|
|
||
| // Each entry maps a vault to its stats contract. | ||
| // Data is read from statsContract, while pool identity uses vaultAddress. | ||
| const POOLS_CONFIG = [ | ||
| { | ||
| statsContract: 'orai1rzfk6fd6d5zhm77cshdtr0vsuyu0qe0dg36evysklx8n6q8h38psxywppw', | ||
| vaultAddress: '0xd3A1C2Bd6E1d163A7380D701c946aDCd82DD95b1', | ||
| symbol: 'USDC', | ||
| poolMeta: 'Golden Rhythm Vault', | ||
| underlyingTokens: [], | ||
| url: "https://quant.orai.io/vault-v3/0xd3a1c2bd6e1d163a7380d701c946adcd82dd95b1", | ||
| }, | ||
| { | ||
| statsContract: 'orai1rzfk6fd6d5zhm77cshdtr0vsuyu0qe0dg36evysklx8n6q8h38psxywppw', | ||
| vaultAddress: '0xf90E1b849bFB17D57abDb07438d68ac787B5C587', | ||
| symbol: 'USDC', | ||
| poolMeta: 'Polymarket Vault', | ||
| underlyingTokens: [], | ||
| url: "https://quant.orai.io/vault-v2/0xf90e1b849bfb17d57abdb07438d68ac787b5c587", | ||
| }, | ||
| { | ||
| statsContract: 'orai1rzfk6fd6d5zhm77cshdtr0vsuyu0qe0dg36evysklx8n6q8h38psxywppw', | ||
| vaultAddress: '0x5424293637Cc59ad7580aD1caC46e28D4801a587', | ||
| symbol: 'USDC', | ||
| poolMeta: 'XAU Alpha Vault', | ||
| underlyingTokens: [], | ||
| url: "https://quant.orai.io/vault-v2/0x5424293637cc59ad7580ad1cac46e28d4801a587", | ||
| } | ||
| ]; | ||
|
|
||
| function toQueryPath(queryMsg) { | ||
| return encodeURIComponent( | ||
| Buffer.from(JSON.stringify(queryMsg)).toString('base64') | ||
| ); | ||
| } | ||
|
|
||
| async function queryContract({ contract, queryMsg }) { | ||
| const queryPath = toQueryPath(queryMsg); | ||
| const url = `${LCD_ENDPOINT}/cosmwasm/wasm/v1/contract/${contract}/smart/${queryPath}`; | ||
| const response = await utils.getData(url); | ||
| return response?.data ?? response; | ||
| } | ||
|
|
||
| async function queryVaultStats(contract, vaultAddress) { | ||
| const queryMsg = | ||
| { get_vault_stats: { vault_address: vaultAddress.toLowerCase() } }; | ||
| return queryContract({ contract, queryMsg }); | ||
| } | ||
|
|
||
| function extractFirstNumber(payload, depth = 0) { | ||
| if (depth > 8 || payload === null || payload === undefined) return null; | ||
| if (typeof payload === 'number' && Number.isFinite(payload)) return payload; | ||
| if (typeof payload === 'string') { | ||
| const value = Number(payload); | ||
| return Number.isFinite(value) ? value : null; | ||
| } | ||
| if (Array.isArray(payload)) { | ||
| for (const item of payload) { | ||
| const value = extractFirstNumber(item, depth + 1); | ||
| if (value !== null) return value; | ||
| } | ||
| return null; | ||
| } | ||
| if (typeof payload !== 'object') return null; | ||
|
|
||
| for (const value of Object.values(payload)) { | ||
| const number = extractFirstNumber(value, depth + 1); | ||
| if (number !== null) return number; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| function extractNumericByKeys(payload, keys) { | ||
| if (!payload || typeof payload !== 'object') return null; | ||
| for (const key of keys) { | ||
| if (!(key in payload)) continue; | ||
| const value = extractFirstNumber(payload[key]); | ||
| if (value !== null) return value; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| function normalizeApyPercent(value) { | ||
| if (!Number.isFinite(value)) return null; | ||
| if (value < 0) return null; | ||
| // Assume APY is already percent; only tiny values are treated as ratio inputs. | ||
| return value < 0.01 ? value * 100 : value; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| async function buildPoolData(config) { | ||
| const vaultStatsData = await queryVaultStats( | ||
| config.statsContract, | ||
| config.vaultAddress | ||
| ); | ||
|
|
||
| const tvlSource = vaultStatsData?.tvl ?? vaultStatsData; | ||
| const apySource = vaultStatsData?.apy ?? vaultStatsData; | ||
|
|
||
| const tvlRaw = extractNumericByKeys(tvlSource, ['tvl']) ?? extractFirstNumber(tvlSource); | ||
| const tvlUsd = tvlRaw / 1e6; | ||
|
|
||
| const apyRaw = extractNumericByKeys(apySource, ['apy']) ?? extractFirstNumber(apySource); | ||
|
|
||
| const apy = normalizeApyPercent(apyRaw); | ||
|
|
||
| if (!Number.isFinite(tvlUsd) || tvlUsd <= 0 || apy === null) return null; | ||
|
|
||
| return { | ||
| pool: `${config.vaultAddress}-${CHAIN}`, | ||
| chain: utils.formatChain(CHAIN), | ||
| project: PROJECT, | ||
| symbol: utils.formatSymbol(config.symbol), | ||
| tvlUsd, | ||
| apy, | ||
| underlyingTokens: config.underlyingTokens, | ||
| poolMeta: config.poolMeta, | ||
| url: config.url, | ||
| token: config.vaultAddress, | ||
| }; | ||
| } | ||
|
|
||
| async function apy() { | ||
| const settledPools = await Promise.allSettled(POOLS_CONFIG.map(buildPoolData)); | ||
| return settledPools | ||
| .filter((result) => result.status === 'fulfilled' && result.value) | ||
| .map((result) => result.value); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| module.exports = { | ||
| timetravel: false, | ||
| apy, | ||
| url: APP_URL, | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: DefiLlama/yield-server
Length of output: 112
🏁 Script executed:
Repository: DefiLlama/yield-server
Length of output: 3214
🏁 Script executed:
Repository: DefiLlama/yield-server
Length of output: 108
🏁 Script executed:
grep -r "get_vault_stats" src/adaptors/orai-quant-terminal/ -A 5 -B 5Repository: DefiLlama/yield-server
Length of output: 892
🏁 Script executed:
Repository: DefiLlama/yield-server
Length of output: 1847
🏁 Script executed:
Repository: DefiLlama/yield-server
Length of output: 108
🏁 Script executed:
Repository: DefiLlama/yield-server
Length of output: 1692
Lock extraction to known response schema keys instead of relying on generic fallback.
When
vaultStatsDatalacks top-leveltvlorapykeys, the code falls back to searching the entire response object withextractFirstNumber(). This recursively returns the first finite number found (viaObject.values()iteration), which could silently pick any numeric field likedecimals,block_height, orfee_bps, producing valid-looking but completely wrongtvlUsdorapyvalues. Downstream validation at line 120 only checksisFinite()and> 0, insufficient to catch this.Instead, restrict
extractNumericByKeysto an explicit whitelist of valid keys (e.g.['tvl', 'apy', 'apr', 'total_value_locked']) and returnnullif none match, rather than falling back to the generic DFS search.🤖 Prompt for AI Agents