-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-ekubo-api.js
More file actions
63 lines (51 loc) · 2.48 KB
/
test-ekubo-api.js
File metadata and controls
63 lines (51 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Simple test script to verify Ekubo API integration
const EKUBO_API_BASE = 'https://starknet-mainnet-api.ekubo.org';
async function testEkuboApi() {
console.log('🧪 Testing Ekubo API Integration...\n');
try {
// Test overview endpoint
console.log('📊 Fetching protocol overview...');
const overviewResponse = await fetch(`${EKUBO_API_BASE}/overview`);
const overview = await overviewResponse.json();
console.log(`✅ Overview data received. Timestamp: ${overview.timestamp}`);
console.log(`📈 Number of tokens with TVL: ${overview.tvlByToken.length}\n`);
// Test defi spring incentives
console.log('🌱 Fetching DeFi Spring incentives...');
const incentivesResponse = await fetch(`${EKUBO_API_BASE}/defi-spring-incentives`);
const incentives = await incentivesResponse.json();
console.log(`✅ Incentives data received`);
console.log(`💰 STRK Price: $${incentives.strkPrice}`);
console.log(`🏊 Total pairs: ${incentives.pairs.length}`);
// Find BTC pairs
const btcPairs = incentives.pairs.filter(pair =>
pair.token0.symbol === 'WBTC' ||
pair.token1.symbol === 'WBTC' ||
pair.token0.name.toLowerCase().includes('btc') ||
pair.token1.name.toLowerCase().includes('btc')
);
console.log(`₿ BTC-related pairs found: ${btcPairs.length}`);
if (btcPairs.length > 0) {
console.log('\n🔍 BTC Pairs Details:');
btcPairs.forEach((pair, index) => {
console.log(` ${index + 1}. ${pair.token0.symbol}/${pair.token1.symbol}`);
console.log(` APR: ${(pair.currentApr * 100).toFixed(3)}%`);
console.log(` TVL: $${pair.consideredTvl.toLocaleString()}`);
});
// Calculate weighted average APY
const totalTvl = btcPairs.reduce((sum, pair) => sum + pair.consideredTvl, 0);
const weightedApy = btcPairs.reduce((sum, pair) =>
sum + (pair.currentApr * 100 * pair.consideredTvl), 0) / totalTvl;
console.log(`\n📊 Weighted Average BTC APY: ${weightedApy.toFixed(2)}%`);
}
// Test TVL endpoint
console.log('\n💎 Testing TVL endpoint...');
const tvlResponse = await fetch(`${EKUBO_API_BASE}/overview/tvl`);
const tvlData = await tvlResponse.json();
console.log(`✅ TVL data received with ${tvlData.length} entries`);
console.log('\n🎉 All API tests passed! Integration is working correctly.');
} catch (error) {
console.error('❌ API test failed:', error.message);
}
}
// Run the test
testEkuboApi();