|
| 1 | +const API_BASE = process.env.XOXNO_LENDING_API_BASE || 'https://api.xoxno.com'; |
| 2 | +const HEADERS = { 'User-Agent': 'dune-analytics' }; |
| 3 | +const REQUEST_TIMEOUT_MS = 5_000; |
| 4 | + |
| 5 | +const CHAIN_CONFIGS = { |
| 6 | + stellar: { |
| 7 | + chain: 'Stellar', |
| 8 | + exportPath: '/integrations/lending/stellar', |
| 9 | + }, |
| 10 | + |
| 11 | + // Add MultiversX later with the same API response shape: |
| 12 | + // multiversx: { |
| 13 | + // chain: 'MultiversX', |
| 14 | + // exportPath: '/integrations/lending/multiversx', |
| 15 | + // }, |
| 16 | +}; |
| 17 | + |
| 18 | +function getApiUrl(path) { |
| 19 | + return `${API_BASE.replace(/\/$/, '')}${path}`; |
| 20 | +} |
| 21 | + |
| 22 | +async function getMarkets(config) { |
| 23 | + const response = await fetch(getApiUrl(config.exportPath), { |
| 24 | + headers: HEADERS, |
| 25 | + signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), |
| 26 | + }); |
| 27 | + |
| 28 | + if (!response.ok) { |
| 29 | + throw new Error(`XOXNO ${config.chain} lending export failed: ${response.status}`); |
| 30 | + } |
| 31 | + |
| 32 | + const data = await response.json(); |
| 33 | + return Array.isArray(data.markets) ? data.markets : []; |
| 34 | +} |
| 35 | + |
| 36 | +function keepFinite(pool) { |
| 37 | + return [ |
| 38 | + pool.tvlUsd, |
| 39 | + pool.apyBase, |
| 40 | + pool.apyBaseBorrow, |
| 41 | + pool.totalSupplyUsd, |
| 42 | + pool.totalBorrowUsd, |
| 43 | + ].every(Number.isFinite); |
| 44 | +} |
| 45 | + |
| 46 | +function decimalToPercent(value) { |
| 47 | + return Number(value ?? 0) * 100; |
| 48 | +} |
| 49 | + |
| 50 | +async function apy() { |
| 51 | + const pools = []; |
| 52 | + |
| 53 | + for (const config of Object.values(CHAIN_CONFIGS)) { |
| 54 | + const markets = await getMarkets(config); |
| 55 | + |
| 56 | + for (const market of markets) { |
| 57 | + pools.push({ |
| 58 | + pool: `xoxno-lending-${config.chain.toLowerCase()}-${market.token}`, |
| 59 | + chain: config.chain, |
| 60 | + project: 'xoxno-lending', |
| 61 | + symbol: market.symbol, |
| 62 | + tvlUsd: Number(market.tvlUsd ?? 0), |
| 63 | + apyBase: decimalToPercent(market.supplyApy), |
| 64 | + apyBaseBorrow: decimalToPercent(market.borrowApy), |
| 65 | + totalSupplyUsd: Number(market.suppliedUsd ?? 0), |
| 66 | + totalBorrowUsd: Number(market.borrowedUsd ?? 0), |
| 67 | + underlyingTokens: [market.token], |
| 68 | + url: 'https://xoxno.com/defi/lending', |
| 69 | + }); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + return pools.filter(keepFinite); |
| 74 | +} |
| 75 | + |
| 76 | +module.exports = { |
| 77 | + protocolId: '8049', |
| 78 | + timetravel: false, |
| 79 | + apy, |
| 80 | + url: 'https://xoxno.com/defi/lending', |
| 81 | +}; |
0 commit comments