Skip to content

Commit 4578fd3

Browse files
update example for new endpoints version
1 parent 4353f3d commit 4578fd3

6 files changed

Lines changed: 501 additions & 127 deletions

File tree

Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
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+
}
Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
11
import axios from "axios";
22
import { CORE_DOMAIN } from "./const";
33

4-
interface Param {
5-
chainId: number;
6-
}
7-
84
interface Query {
9-
order_by?: string;
10-
skip?: number;
11-
limit?: number;
12-
is_expired?: boolean;
13-
zappable?: boolean;
14-
type?: string;
5+
chainId?: number;
6+
type?: string; // PT, YT, SY, LP
157
address?: string;
16-
q?: string;
8+
q?: string; // Search query
179
}
1810

1911
interface AssetInfo {
20-
name: string;
21-
decimals: number;
12+
chainId: number;
2213
address: string;
14+
name: string;
2315
symbol: string;
16+
decimals: number;
17+
expiry?: string;
2418
tags: string[];
25-
expiry: string;
19+
type: string;
20+
underlyingAsset?: string;
21+
protocol?: string;
22+
yieldBearingAsset?: string;
2623
}
2724

2825
interface Response {
2926
assets: AssetInfo[];
3027
}
3128

32-
export async function getAssets() {
33-
// This is an example of how to get list of Pendle assets on Ethereum
34-
35-
const param: Param = {
36-
chainId: 1, // Ethereum
29+
export async function getPendleAssets() {
30+
// This example shows how to get all Pendle assets across all chains
31+
// using the /v1/assets/all cross-chain endpoint
32+
33+
const query: Query = {
34+
// chainId: 1, // Optional: filter by specific chain
35+
// type: 'PT', // Optional: filter by asset type (PT, YT, SY, LP)
36+
};
37+
38+
const targetPath = `/v1/assets/all`;
39+
40+
const { data } = await axios.get<Response>(CORE_DOMAIN + targetPath, { params: query });
41+
42+
console.log('Total assets:', data.assets.length);
43+
44+
if (data.assets.length > 0) {
45+
const firstAsset = data.assets[0];
46+
console.log('\nFirst asset:');
47+
console.log(' Chain:', firstAsset.chainId);
48+
console.log(' Address:', firstAsset.address);
49+
console.log(' Name:', firstAsset.name);
50+
console.log(' Symbol:', firstAsset.symbol);
51+
console.log(' Type:', firstAsset.type);
52+
console.log(' Decimals:', firstAsset.decimals);
53+
if (firstAsset.expiry) {
54+
console.log(' Expiry:', new Date(firstAsset.expiry).toISOString());
55+
}
56+
console.log(' Tags:', firstAsset.tags.join(', '));
3757
}
38-
39-
const targetPath = `/v3/${param.chainId}/assets/all`;
40-
41-
const { data } = await axios.get<Response>(CORE_DOMAIN + targetPath);
42-
43-
const {assets} = data;
44-
45-
console.log('first asset', assets[0]);
46-
}
58+
}

0 commit comments

Comments
 (0)