Skip to content

Commit

Permalink
changed demo APIs to simple APIs for get assets and markets
Browse files Browse the repository at this point in the history
  • Loading branch information
tungtranpendle committed Oct 3, 2024
1 parent bd2abfa commit fc6fc27
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 96 deletions.
36 changes: 21 additions & 15 deletions backend-api-demo/src/get-asset-prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import { CORE_DOMAIN } from "./const";
import axios from "axios";
import { parse } from "csv-string";

interface GetSpotPriceParam {
interface GetAssetPricesParam {
chainId: number;
}

interface GetSpotPriceQuery {
address?: string[];
interface GetAssetPricesQuery {
addresses?: string; // separated by commas, return all asset prices if empty
}

interface GetSpotPriceResponse {
total: number;
addresses: string[];
pricesUsd: (number | null)[];
interface GetAssetPricesResponse {
prices: Record<string, number>;
}

interface GetHistoricalPricesParam {
Expand Down Expand Up @@ -45,23 +43,31 @@ interface GetHistoricalPricesResponse {
}

export async function getAssetPrices() {
// This is an example of how to get all spot prices of assets on Ethereum
// This is an example of how to get all spot prices of pendle assets on Ethereum

const param: GetSpotPriceParam = {
const param: GetAssetPricesParam = {
chainId: 1, // Ethereum
};

const targetPath = `/v1/${param.chainId}/prices/assets/all`;
const addressPt_USDe = '0xa8778dd6b7f1f61f2cfda5d3cb18be8f99a8db30'; // address of PT-USDe-26DEC2024
const addressPt_weETH = '0x6ee2b5e19ecba773a352e5b21415dc419a700d1d'; // address of PT-weETH-26DEC2024

const addresses = `${addressPt_USDe},${addressPt_weETH}`;

const { data } = await axios.get<GetSpotPriceResponse>(CORE_DOMAIN + targetPath);
const query: GetAssetPricesQuery = {
addresses: addresses
}

const {total, pricesUsd, addresses} = data;
const targetPath = `/v1/${param.chainId}/assets/prices`;

console.log('result info', {total});
const { data } = await axios.get<GetAssetPricesResponse>(CORE_DOMAIN + targetPath, {
params: query
});

const address = addresses[0];
const {prices: priceUsdMap} = data;

console.log(`prices of ${address} is ${pricesUsd[0] ?? 0} USD`);
console.log(`price of Pt USDe is ${priceUsdMap[addressPt_USDe] ?? 0} USD`);
console.log(`price of Pt weETH is ${priceUsdMap[addressPt_weETH] ?? 0} USD`);
}

export async function getHistoricalAssetPrices() {
Expand Down
26 changes: 6 additions & 20 deletions backend-api-demo/src/get-list-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ interface AssetInfo {
decimals: number;
address: string;
symbol: string;
types: string[];
tags: string[];
expiry: string;
}

interface Response {
results: AssetInfo[];
total: number;
limit: number;
skip: number;
assets: AssetInfo[];
}

export async function getAssets() {
Expand All @@ -39,22 +36,11 @@ export async function getAssets() {
chainId: 1, // Ethereum
}

const query: Query = {
order_by: 'name:1',
skip: 0,
limit: 10,
is_expired: false,
}

const targetPath = `/v1/${param.chainId}/assets`;

const { data } = await axios.get<Response>(CORE_DOMAIN + targetPath, {params: query});

const {total, limit, skip, results: assets} = data;
const targetPath = `/v3/${param.chainId}/assets/all`;

console.log('result info', {limit, total, skip});
const { data } = await axios.get<Response>(CORE_DOMAIN + targetPath);

const {name, address, decimals, expiry, symbol, types} = assets[0];
const {assets} = data;

console.log('first asset', {name, address, decimals, expiry, symbol, types});
console.log('first asset', assets[0]);
}
70 changes: 9 additions & 61 deletions backend-api-demo/src/get-list-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,18 @@ import { CORE_DOMAIN } from "./const";
interface Param {
chainId: number;
}

interface Query {
order_by?: string;
skip?: number;
limit?: number;
is_expired?: boolean;
select?: string;
pt?: string;
yt?: string;
sy?: string;
q?: string;
is_active?: boolean;
categoryId?: string;
}

interface MarketInfo {
name: string;
address: string;
expiry: string;
pt: {
id: string;
};
yt: {
id: string;
};
sy: {
id: string;
};
liquidity: {
usd: number;
acc: number;
};
underlyingInterestApy: number;
underlyingRewardApy: number,
underlyingApy: number;
impliedApy: number;
ytFloatingApy: number;
aggregatedApy: number;
maxBoostedApy: number;
lpRewardApy: number;
voterApy: number;
pt: string;
yt: string;
sy: string;
underlyingAsset: string;
}

interface Response {
total: number;
limit: number;
skip: number;
results: MarketInfo[];
markets: MarketInfo[];
}

export async function getMarkets() {
Expand All @@ -61,27 +25,11 @@ export async function getMarkets() {
chainId: 1, // Ethereum
}

const query: Query = {
order_by: 'name:1',
skip: 0,
limit: 10,
is_expired: false,
select: 'pro',
}

const targetPath = `/v1/${param.chainId}/markets`;

const { data } = await axios.get<Response>(CORE_DOMAIN + targetPath, {params: query});

const { results: markets, skip, limit, total } = data;
const targetPath = `/v1/${param.chainId}/markets/active`;

console.log('result info', {limit, total, skip});
const { data } = await axios.get<Response>(CORE_DOMAIN + targetPath);

const {name, address, expiry, pt, sy, yt, liquidity, impliedApy, aggregatedApy, underlyingApy, lpRewardApy, underlyingInterestApy, underlyingRewardApy, maxBoostedApy, voterApy, ytFloatingApy} = markets[0];
const {id: ptId} = pt;
const {id: syId} = sy;
const {id: ytId} = yt;
const {usd: liquidityUSD } = liquidity;
const { markets } = data;

console.log('first active market', {name, address, expiry, ptId, syId, ytId, liquidityUSD, impliedApy, aggregatedApy, underlyingApy, lpRewardApy, underlyingInterestApy, underlyingRewardApy, maxBoostedApy, voterApy, ytFloatingApy });
console.log('first active market', markets[0]);
}

0 comments on commit fc6fc27

Please sign in to comment.