|
| 1 | +import axios from "axios"; |
| 2 | +import { CORE_DOMAIN } from "./const"; |
| 3 | + |
| 4 | +interface Query { |
| 5 | + skip?: number; |
| 6 | + limit?: number; |
| 7 | + chainId?: number; |
| 8 | + isActive?: boolean; |
| 9 | + ids?: string; // Comma-separated market IDs (e.g., "1-0x...,42161-0x...") |
| 10 | +} |
| 11 | + |
| 12 | +interface PointMetadata { |
| 13 | + pointName: string; |
| 14 | + chainId: number; |
| 15 | + multiplier: number; |
| 16 | +} |
| 17 | + |
| 18 | +interface ApyItem { |
| 19 | + id: string; |
| 20 | + apy: number; |
| 21 | + tags: string[]; |
| 22 | + source?: string; |
| 23 | + campaignDetail?: { |
| 24 | + amount: number; |
| 25 | + startTimestamp: string; |
| 26 | + endTimestamp: string; |
| 27 | + }; |
| 28 | +} |
| 29 | + |
| 30 | +interface ApyCategory { |
| 31 | + label: string; |
| 32 | + apy: number; |
| 33 | + items: ApyItem[]; |
| 34 | +} |
| 35 | + |
| 36 | +interface ApyBreakdown { |
| 37 | + categories: ApyCategory[]; |
| 38 | +} |
| 39 | + |
| 40 | +interface YieldRange { |
| 41 | + min: number; |
| 42 | + max: number; |
| 43 | +} |
| 44 | + |
| 45 | +interface MarketDetails { |
| 46 | + liquidity: number; |
| 47 | + totalTvl: number; |
| 48 | + tradingVolume: number; |
| 49 | + underlyingApy: number; |
| 50 | + swapFeeApy: number; |
| 51 | + pendleApy: number; |
| 52 | + ytFloatingApy: number; |
| 53 | + impliedApy: number; |
| 54 | + feeRate: number; |
| 55 | + yieldRange: YieldRange; |
| 56 | + aggregatedApy: number; |
| 57 | + maxBoostedApy: number; |
| 58 | + totalPt: number; |
| 59 | + totalSy: number; |
| 60 | + totalSupply: number; |
| 61 | + totalActiveSupply: number; |
| 62 | + ytRoi?: number; |
| 63 | + ptRoi?: number; |
| 64 | +} |
| 65 | + |
| 66 | +interface ExternalProtocolInfo { |
| 67 | + id: string; |
| 68 | + name: string; |
| 69 | + iconUrl: string; |
| 70 | + category: string; |
| 71 | + url: string; |
| 72 | + description?: string; |
| 73 | +} |
| 74 | + |
| 75 | +interface ExternalProtocolMetadata { |
| 76 | + protocol: ExternalProtocolInfo; |
| 77 | + integrationUrl: string; |
| 78 | + description: string; |
| 79 | + curatorAddress?: string; |
| 80 | + subtitle?: string; |
| 81 | + liquidity?: number; |
| 82 | + borrowApy?: number; |
| 83 | + supplyApy?: number; |
| 84 | + totalSupply?: number; |
| 85 | + supplyCap?: number; |
| 86 | + maxLtv?: number; |
| 87 | + chainId: number; |
| 88 | + spokeAddress?: string; |
| 89 | +} |
| 90 | + |
| 91 | +interface MarketExternalProtocols { |
| 92 | + pt: ExternalProtocolMetadata[]; |
| 93 | + yt: ExternalProtocolMetadata[]; |
| 94 | + lp: ExternalProtocolMetadata[]; |
| 95 | + crossPt: ExternalProtocolMetadata[]; |
| 96 | +} |
| 97 | + |
| 98 | +interface IncentiveCampaign { |
| 99 | + campaignName: string; |
| 100 | + assetId: string; |
| 101 | + rewardToken: string; |
| 102 | + amount: number; |
| 103 | + epochTimestamp: Date; |
| 104 | + nextEpochTimestamp: Date; |
| 105 | +} |
| 106 | + |
| 107 | +interface LimitOrderIncentive { |
| 108 | + mode: string; |
| 109 | + amountPerSec: number; |
| 110 | + impliedApy: number; |
| 111 | + minApy: number; |
| 112 | + maxApy: number; |
| 113 | + estimatedYtApr?: number; |
| 114 | + estimatedPtApr?: number; |
| 115 | +} |
| 116 | + |
| 117 | +interface PendleEmission { |
| 118 | + totalIncentive: number; |
| 119 | + tvlIncentive: number; |
| 120 | + feeIncentive: number; |
| 121 | + discretionaryIncentive: number; |
| 122 | + cobribingIncentive: number; |
| 123 | +} |
| 124 | + |
| 125 | +interface RewardApyBreakdown { |
| 126 | + asset: string; |
| 127 | + absoluteApy: number; |
| 128 | + relativeApy: number; |
| 129 | + source?: string; |
| 130 | + ytExclusive?: boolean; |
| 131 | + lpExclusive?: boolean; |
| 132 | + portalExtData?: { |
| 133 | + amount: number; |
| 134 | + startTimestamp: string; |
| 135 | + endTimestamp: string; |
| 136 | + }; |
| 137 | +} |
| 138 | + |
| 139 | +interface MarketData { |
| 140 | + chainId: number; |
| 141 | + address: string; |
| 142 | + name: string; |
| 143 | + expiry: string; |
| 144 | + |
| 145 | + pt: string; |
| 146 | + yt: string; |
| 147 | + sy: string; |
| 148 | + underlyingAsset: string; |
| 149 | + accountingAsset: string; |
| 150 | + rewardTokens: string[]; |
| 151 | + inputTokens: string[]; |
| 152 | + outputTokens: string[]; |
| 153 | + details: MarketDetails; |
| 154 | + ytApyBreakdown?: ApyBreakdown; |
| 155 | + lpApyBreakdown?: ApyBreakdown; |
| 156 | + underlyingRewardApyBreakdown?: RewardApyBreakdown[]; |
| 157 | + lpRewardApyBreakdown?: RewardApyBreakdown[]; |
| 158 | + isNew: boolean; |
| 159 | + isPrime: boolean; |
| 160 | + timestamp: Date; |
| 161 | + lpWrapper?: string; |
| 162 | + categoryIds: string[]; |
| 163 | + isVolatile?: boolean; |
| 164 | + points?: PointMetadata[]; |
| 165 | + externalProtocols?: MarketExternalProtocols; |
| 166 | + incentiveCampaigns?: IncentiveCampaign[]; |
| 167 | + limitOrderIncentive?: LimitOrderIncentive; |
| 168 | + pendleEmission?: PendleEmission; |
| 169 | +} |
| 170 | + |
| 171 | +interface Response { |
| 172 | + results: MarketData[]; |
| 173 | + total: number; |
| 174 | + skip: number; |
| 175 | + limit: number; |
| 176 | +} |
| 177 | + |
| 178 | +export async function getAllMarkets() { |
| 179 | + // This example shows how to get all markets across all chains |
| 180 | + |
| 181 | + const query: Query = { |
| 182 | + skip: 0, |
| 183 | + limit: 10, // Max 100 |
| 184 | + isActive: true, // Only active markets |
| 185 | + // chainId: 1, // Optional: filter by specific chain (e.g., Ethereum) |
| 186 | + }; |
| 187 | + |
| 188 | + const targetPath = `/v2/markets/all`; |
| 189 | + |
| 190 | + const { data } = await axios.get<Response>(CORE_DOMAIN + targetPath, { params: query }); |
| 191 | + |
| 192 | + console.log('Pagination info:', { |
| 193 | + total: data.total, |
| 194 | + skip: data.skip, |
| 195 | + limit: data.limit, |
| 196 | + returned: data.results.length, |
| 197 | + }); |
| 198 | + |
| 199 | + const firstMarket = data.results[0]; |
| 200 | + if (firstMarket) { |
| 201 | + console.log('\nFirst market:'); |
| 202 | + console.log(' Name:', firstMarket.name); |
| 203 | + console.log(' Chain:', firstMarket.chainId); |
| 204 | + console.log(' Address:', firstMarket.address); |
| 205 | + console.log(' Expiry:', new Date(firstMarket.expiry).toISOString()); |
| 206 | + console.log(' Is New:', firstMarket.isNew); |
| 207 | + console.log(' Is Prime:', firstMarket.isPrime); |
| 208 | + |
| 209 | + console.log('\nAsset IDs:'); |
| 210 | + console.log(' PT:', firstMarket.pt); |
| 211 | + console.log(' YT:', firstMarket.yt); |
| 212 | + console.log(' SY:', firstMarket.sy); |
| 213 | + console.log(' Underlying:', firstMarket.underlyingAsset); |
| 214 | + |
| 215 | + console.log('\nMarket Details:'); |
| 216 | + console.log(' TVL:', firstMarket.details.totalTvl); |
| 217 | + console.log(' Liquidity:', firstMarket.details.liquidity); |
| 218 | + console.log(' Trading Volume (24h):', firstMarket.details.tradingVolume); |
| 219 | + console.log(' Implied APY:', firstMarket.details.impliedApy); |
| 220 | + console.log(' Underlying APY:', firstMarket.details.underlyingApy); |
| 221 | + console.log(' YT Floating APY:', firstMarket.details.ytFloatingApy); |
| 222 | + console.log(' Swap Fee APY:', firstMarket.details.swapFeeApy); |
| 223 | + console.log(' Pendle APY:', firstMarket.details.pendleApy); |
| 224 | + console.log(' Aggregated APY:', firstMarket.details.aggregatedApy); |
| 225 | + console.log(' Max Boosted APY:', firstMarket.details.maxBoostedApy); |
| 226 | + |
| 227 | + if (firstMarket.ytApyBreakdown) { |
| 228 | + console.log('\nYT APY Breakdown:'); |
| 229 | + firstMarket.ytApyBreakdown.categories.forEach((category: ApyCategory) => { |
| 230 | + console.log(`\n ${category.label}: ${category.apy}`); |
| 231 | + category.items.forEach((item: ApyItem) => { |
| 232 | + console.log(` - Asset ${item.id}: ${item.apy}`); |
| 233 | + console.log(` Tags: ${item.tags.join(', ')}`); |
| 234 | + if (item.source) console.log(` Source: ${item.source}`); |
| 235 | + }); |
| 236 | + }); |
| 237 | + } |
| 238 | + |
| 239 | + if (firstMarket.lpApyBreakdown) { |
| 240 | + console.log('\nLP APY Breakdown:'); |
| 241 | + firstMarket.lpApyBreakdown.categories.forEach((category: ApyCategory) => { |
| 242 | + console.log(`\n ${category.label}: ${category.apy}`); |
| 243 | + category.items.forEach((item: ApyItem) => { |
| 244 | + console.log(` - Asset ${item.id}: ${item.apy}`); |
| 245 | + console.log(` Tags: ${item.tags.join(', ')}`); |
| 246 | + if (item.source) console.log(` Source: ${item.source}`); |
| 247 | + }); |
| 248 | + }); |
| 249 | + } |
| 250 | + |
| 251 | + if (firstMarket.points && firstMarket.points.length > 0) { |
| 252 | + console.log('\nPoints:'); |
| 253 | + firstMarket.points.forEach((point: PointMetadata) => { |
| 254 | + console.log(` - ${point.pointName}: ${point.multiplier}x`); |
| 255 | + }); |
| 256 | + } |
| 257 | + |
| 258 | + if (firstMarket.pendleEmission) { |
| 259 | + console.log('\nPendle Emission (weekly):'); |
| 260 | + console.log(' Total:', firstMarket.pendleEmission.totalIncentive); |
| 261 | + console.log(' TVL-based:', firstMarket.pendleEmission.tvlIncentive); |
| 262 | + console.log(' Fee-based:', firstMarket.pendleEmission.feeIncentive); |
| 263 | + console.log(' Discretionary:', firstMarket.pendleEmission.discretionaryIncentive); |
| 264 | + console.log(' Co-bribing:', firstMarket.pendleEmission.cobribingIncentive); |
| 265 | + } |
| 266 | + |
| 267 | + if (firstMarket.externalProtocols) { |
| 268 | + const { pt, yt, lp } = firstMarket.externalProtocols; |
| 269 | + if (pt.length > 0 || yt.length > 0 || lp.length > 0) { |
| 270 | + console.log('\nExternal Protocol Integrations:'); |
| 271 | + if (pt.length > 0) console.log(` PT integrations: ${pt.length}`); |
| 272 | + if (yt.length > 0) console.log(` YT integrations: ${yt.length}`); |
| 273 | + if (lp.length > 0) console.log(` LP integrations: ${lp.length}`); |
| 274 | + } |
| 275 | + } |
| 276 | + } |
| 277 | + |
| 278 | + // Example: Fetch next page |
| 279 | + // const nextQuery: Query = { |
| 280 | + // skip: data.skip + data.limit, |
| 281 | + // limit: 10, |
| 282 | + // isActive: true, |
| 283 | + // }; |
| 284 | + // const { data: nextPage } = await axios.get<Response>(CORE_DOMAIN + targetPath, { params: nextQuery }); |
| 285 | +} |
0 commit comments