-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert backend-api-demo to core service
- Loading branch information
Manh Cao
authored and
Manh Cao
committed
Sep 5, 2024
1 parent
e5f2f27
commit 2181e8b
Showing
9 changed files
with
139 additions
and
110 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const EXTERNAL_DOMAIN = `https://api-v2.pendle.finance/api/external`; | ||
export const CORE_DOMAIN = `https://api-v2.pendle.finance/api/core`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,60 @@ | ||
import axios from "axios"; | ||
import { EXTERNAL_DOMAIN } from "./const"; | ||
import { CORE_DOMAIN } from "./const"; | ||
|
||
interface Param { | ||
chainId: number; | ||
} | ||
|
||
interface Query { | ||
order_by?: string; | ||
skip?: number; | ||
limit?: number; | ||
is_expired?: boolean; | ||
zappable?: boolean; | ||
type?: string; | ||
address?: string; | ||
q?: string; | ||
} | ||
|
||
interface AssetInfo { | ||
name: string; | ||
decimals: number; | ||
address: string; | ||
symbol: string; | ||
tags: string[]; | ||
types: string[]; | ||
expiry: string; | ||
} | ||
|
||
interface Response { | ||
assets: AssetInfo[]; | ||
results: AssetInfo[]; | ||
total: number; | ||
limit: number; | ||
skip: number; | ||
} | ||
|
||
export async function getAssetList() { | ||
export async function getAssets() { | ||
// This is an example of how to get list of Pendle assets on Ethereum | ||
|
||
const param: Param = { | ||
chainId: 1, // Ethereum | ||
} | ||
|
||
const targetPath = `/v1/${param.chainId}/assets/all`; | ||
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 { data } = await axios.get<Response>(EXTERNAL_DOMAIN + targetPath); | ||
const {total, limit, skip, results: assets} = data; | ||
|
||
const { assets } = data; | ||
console.log('result info', {limit, total, skip}); | ||
|
||
const {name, address, decimals, expiry, symbol, tags} = assets[0]; | ||
const {name, address, decimals, expiry, symbol, types} = assets[0]; | ||
|
||
console.log('first asset', {name, address, decimals, expiry, symbol, tags}); | ||
console.log('first asset', {name, address, decimals, expiry, symbol, types}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,73 @@ | ||
import axios from "axios"; | ||
import { EXTERNAL_DOMAIN } from "./const"; | ||
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: string; | ||
yt: string; | ||
sy: string; | ||
pt: { | ||
id: string; | ||
}; | ||
yt: { | ||
id: string; | ||
}; | ||
sy: { | ||
id: string; | ||
}; | ||
} | ||
|
||
interface Response { | ||
markets: MarketInfo[]; | ||
total: number; | ||
limit: number; | ||
skip: number; | ||
results: MarketInfo[]; | ||
} | ||
|
||
export async function getActiveMarkets() { | ||
export async function getMarkets() { | ||
// This is an example of how to get list of active Pendle markets on Ethereum | ||
|
||
const param: Param = { | ||
chainId: 1, // Ethereum | ||
} | ||
|
||
const targetPath = `/v1/${param.chainId}/markets/active`; | ||
|
||
const { data } = await axios.get<Response>(EXTERNAL_DOMAIN + targetPath); | ||
|
||
const { markets } = data; | ||
|
||
const {name, address, expiry, pt, sy, yt} = markets[0]; | ||
|
||
console.log('first active market', {name, address, expiry, pt, sy, yt}); | ||
} | ||
|
||
export async function getInactiveMarkets() { | ||
// This is an example of how to get list of inactive Pendle markets on Ethereum | ||
|
||
const param: Param = { | ||
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/inactive`; | ||
const targetPath = `/v1/${param.chainId}/markets`; | ||
|
||
const { data } = await axios.get<Response>(CORE_DOMAIN + targetPath, {params: query}); | ||
|
||
const { data } = await axios.get<Response>(EXTERNAL_DOMAIN + targetPath); | ||
const { results: markets, skip, limit, total } = data; | ||
|
||
const { markets } = data; | ||
console.log('result info', {limit, total, skip}); | ||
|
||
const {name, address, expiry, pt, sy, yt} = markets[0]; | ||
const {id: ptId} = pt; | ||
const {id: syId} = sy; | ||
const {id: ytId} = yt; | ||
|
||
console.log('first inactive market', {name, address, expiry, pt, sy, yt}); | ||
console.log('first active market', {name, address, expiry, ptId, syId, ytId}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.