-
-
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.
* Add hosted SDK docs * remove `enableAggregator` since it is enabled by default * Add `/api` to endpoints
- Loading branch information
Showing
15 changed files
with
1,258 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "hosted-sdk-demo", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^1.7.4", | ||
"ethers": "5", | ||
"typescript": "^5.5.4" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.2.0", | ||
"ts-node": "^10.9.2" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { CHAIN_ID, MARKET_ADDRESS, RECEIVER_ADDRESS, SY_ADDRESS, wstETH } from "./constants"; | ||
import { callSDK, getSigner } from "./helper"; | ||
import { AddLiquidityDualData } from "./types"; | ||
|
||
export async function addLiquidityDualSyAndPt() { | ||
// Use 1 SY and 1 PT to add liquidity to wstETH pool with 1% slippage | ||
const res = await callSDK<AddLiquidityDualData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/add-liquidity-dual`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: SY_ADDRESS, | ||
amountTokenIn: '1000000000000000000', | ||
amountPtIn: '1000000000000000000', | ||
}); | ||
|
||
console.log('Amount LP Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function addLiquidityDualTokenAndPt() { | ||
// USe 1 wstETH and 1 PT to add liquidity to wstETH pool with 1% slippage | ||
const res = await callSDK<AddLiquidityDualData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/add-liquidity-dual`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: wstETH, | ||
amountTokenIn: '1000000000000000000', | ||
amountPtIn: '1000000000000000000', | ||
}); | ||
|
||
console.log('Amount LP Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { CHAIN_ID, MARKET_ADDRESS, PT_ADDRESS, RECEIVER_ADDRESS, SY_ADDRESS, wstETH } from "./constants"; | ||
import { callSDK, getSigner } from "./helper"; | ||
import { AddLiquidityData } from "./types"; | ||
|
||
export async function addLiquiditySinglePt() { | ||
// Use 1 PT to add liquidity to wstETH pool with 1% slippage | ||
const res = await callSDK<AddLiquidityData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/add-liquidity`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: PT_ADDRESS, | ||
amountIn: '1000000000000000000' | ||
}); | ||
|
||
console.log('Amount LP Out: ', res.data.amountLpOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function addLiquiditySingleSy() { | ||
// Use 1 SY to add liquidity to wstETH pool with 1% slippage | ||
const res = await callSDK<AddLiquidityData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/add-liquidity`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: SY_ADDRESS, | ||
amountIn: '1000000000000000000', | ||
}); | ||
|
||
console.log('Amount LP Out: ', res.data.amountLpOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function addLiquiditySingleSyKeepYt() { | ||
// Use 1 SY to add liquidity to wstETH pool (zero price impact mode) with 1% slippage | ||
const res = await callSDK<AddLiquidityData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/add-liquidity`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: SY_ADDRESS, | ||
amountIn: '1000000000000000000', | ||
zpi: true, | ||
}); | ||
|
||
console.log('Amount LP Out: ', res.data.amountLpOut); | ||
console.log('Amount YT Out: ', res.data.amountYtOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function addLiquiditySingleToken() { | ||
// Use 1 wstETH to add liquidity to wstETH pool with 1% slippage | ||
const res = await callSDK<AddLiquidityData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/add-liquidity`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: wstETH, | ||
amountIn: '1000000000000000000' | ||
}); | ||
|
||
console.log('Amount LP Out: ', res.data.amountLpOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function addLiquiditySingleTokenKeepYt() { | ||
// Use 1 wstETH to add liquidity to wstETH pool (zero price impact mode) with 1% slippage | ||
const res = await callSDK<AddLiquidityData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/add-liquidity`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: wstETH, | ||
amountIn: '1000000000000000000', | ||
zpi: true, | ||
}); | ||
|
||
console.log('Amount LP Out: ', res.data.amountLpOut); | ||
console.log('Amount YT Out: ', res.data.amountYtOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Tokens | ||
export const wstETH = '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'; | ||
export const MARKET_ADDRESS = '0x34280882267ffa6383b363e278b027be083bbe3b'; | ||
export const SY_ADDRESS = '0xcbc72d92b2dc8187414f6734718563898740c0bc'; | ||
export const PT_ADDRESS = '0xb253eff1104802b97ac7e3ac9fdd73aece295a2c'; | ||
export const YT_ADDRESS = '0x04b7fa1e727d7290d6e24fa9b426d0c940283a95'; | ||
|
||
export const CHAIN_ID = 1; | ||
export const RECEIVER_ADDRESS = '<RECEVER_ADDRESS>'; |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import axios from 'axios'; | ||
import { ethers } from 'ethers'; | ||
|
||
const HOSTED_SDK_URL = 'https://api-v2.pendle.finance/api/external/'; | ||
|
||
type MethodReturnType<Data> = { | ||
tx: { | ||
data: string; | ||
to: string; | ||
value: string; | ||
}; | ||
data: Data; | ||
}; | ||
|
||
export async function callSDK<Data>(path: string, params: Record<string, any> = {}) { | ||
const response = await axios.get<MethodReturnType<Data>>(HOSTED_SDK_URL + path, { | ||
params | ||
}); | ||
|
||
return response.data; | ||
} | ||
|
||
export function getSigner() { | ||
const provider = new ethers.providers.JsonRpcProvider('https://rpc.ankr.com/eth'); | ||
const signer = new ethers.Wallet(process.env.PRIVATE_KEY!, provider); | ||
return signer; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { CHAIN_ID, RECEIVER_ADDRESS, SY_ADDRESS, wstETH, YT_ADDRESS } from "./constants"; | ||
import { callSDK, getSigner } from "./helper"; | ||
import { MintPyData } from "./types"; | ||
|
||
export async function mintPyFromSy() { | ||
// Use 1 SY to mint PT and YT with 1% slippage | ||
const res = await callSDK<MintPyData>(`/v1/sdk/${CHAIN_ID}/mint`, { | ||
receiver: RECEIVER_ADDRESS, | ||
yt: YT_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: SY_ADDRESS, | ||
amountIn: '1000000000000000000', | ||
}); | ||
|
||
console.log('Amount PT & YT Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function mintPyFromToken() { | ||
// Use 1 wstETH to mint PT and YT with 1% slippage | ||
const res = await callSDK<MintPyData>(`/v1/sdk/${CHAIN_ID}/mint`, { | ||
receiver: RECEIVER_ADDRESS, | ||
yt: YT_ADDRESS, | ||
slippage: 0.01, | ||
tokenIn: wstETH, | ||
amountIn: '1000000000000000000', | ||
}); | ||
|
||
console.log('Amount PT & YT Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { CHAIN_ID, RECEIVER_ADDRESS, SY_ADDRESS, wstETH, YT_ADDRESS } from "./constants"; | ||
import { callSDK, getSigner } from "./helper"; | ||
import { RedeemPyData } from "./types"; | ||
|
||
export async function redeemPyToSy() { | ||
// Redeem 1 PT and 1 YT to SY with 1% slippage | ||
const res = await callSDK<RedeemPyData>(`/v1/sdk/${CHAIN_ID}/redeem`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
yt: YT_ADDRESS, | ||
amountIn: '1000000000000000000', | ||
tokenOut: SY_ADDRESS, | ||
}); | ||
|
||
console.log('Amount SY Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function redeemPyToToken() { | ||
// Redeem 1 PT and 1 YT to wstETH with 1% slippage | ||
const res = await callSDK<RedeemPyData>(`/v1/sdk/${CHAIN_ID}/redeem`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
yt: YT_ADDRESS, | ||
amountIn: '1000000000000000000', | ||
tokenOut: wstETH, | ||
}); | ||
|
||
console.log('Amount wstETH Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { CHAIN_ID, MARKET_ADDRESS, RECEIVER_ADDRESS, SY_ADDRESS, wstETH } from "./constants"; | ||
import { callSDK, getSigner } from "./helper"; | ||
import { RemoveLiquidityDualData } from "./types"; | ||
|
||
export async function removeLiquidityDualSyAndPt() { | ||
// Remove 1 LP from wstETH pool to SY and PT with 1% slippage | ||
const res = await callSDK<RemoveLiquidityDualData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/remove-liquidity-dual`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenOut: SY_ADDRESS, | ||
amountIn: '1000000000000000000', | ||
}); | ||
|
||
console.log('Amount SY Out: ', res.data.amountTokenOut); | ||
console.log('Amount PT Out: ', res.data.amountPtOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function removeLiquidityDualTokenAndPt() { | ||
// Remove 1 LP from wstETH pool to wstETH and PT with 1% slippage | ||
const res = await callSDK<RemoveLiquidityDualData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/remove-liquidity-dual`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenOut: wstETH, | ||
amountIn: '1000000000000000000', | ||
}); | ||
|
||
console.log('Amount wstETH Out: ', res.data.amountTokenOut); | ||
console.log('Amount PT Out: ', res.data.amountPtOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { CHAIN_ID, MARKET_ADDRESS, PT_ADDRESS, RECEIVER_ADDRESS, SY_ADDRESS, wstETH } from "./constants"; | ||
import { callSDK, getSigner } from "./helper"; | ||
import { RemoveLiquidityData } from "./types"; | ||
|
||
export async function removeLiquiditySinglePt() { | ||
// Remove 1 LP from wstETH pool to PT with 1% slippage | ||
const res = await callSDK<RemoveLiquidityData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/remove-liquidity`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenOut: PT_ADDRESS, | ||
amountIn: '1000000000000000000' | ||
}); | ||
|
||
console.log('Amount PT Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function removeLiquiditySingleSy() { | ||
// Remove 1 LP from wstETH pool to SY with 1% slippage | ||
const res = await callSDK<RemoveLiquidityData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/remove-liquidity`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenOut: SY_ADDRESS, | ||
amountIn: '1000000000000000000' | ||
}); | ||
|
||
console.log('Amount SY Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} | ||
|
||
export async function removeLiquiditySingleToken() { | ||
// Remove 1 LP from wstETH pool to wstETH with 1% slippage | ||
const res = await callSDK<RemoveLiquidityData>(`/v1/sdk/${CHAIN_ID}/markets/${MARKET_ADDRESS}/remove-liquidity`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
tokenOut: wstETH, | ||
amountIn: '1000000000000000000' | ||
}); | ||
|
||
console.log('Amount wstETH Out: ', res.data.amountOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CHAIN_ID, MARKET_ADDRESS, RECEIVER_ADDRESS } from "./constants"; | ||
import { callSDK, getSigner } from "./helper"; | ||
import { RollOverPtData } from "./types"; | ||
|
||
const eETH_MARKET_ADDRESS = '0xe1f19cbda26b6418b0c8e1ee978a533184496066'; | ||
|
||
export async function rollOverPt() { | ||
// Transfer 1 PT eETH to wstETH PT with 1% slippage | ||
const res = await callSDK<RollOverPtData>(`/v1/sdk/${CHAIN_ID}/markets/${eETH_MARKET_ADDRESS}/roll-over-pt`, { | ||
receiver: RECEIVER_ADDRESS, | ||
slippage: 0.01, | ||
dstMarket: MARKET_ADDRESS, | ||
ptAmount: '1000000000000000000', | ||
}); | ||
|
||
console.log('Amount PT Out: ', res.data.amountPtOut); | ||
console.log('Price impact: ', res.data.priceImpact); | ||
|
||
// Send tx | ||
getSigner().sendTransaction(res.tx); | ||
} |
Oops, something went wrong.