From 68b234241491b41043f148af0a24ec2e3aa44775 Mon Sep 17 00:00:00 2001 From: Tien Tran Date: Thu, 19 Dec 2024 10:55:05 +0700 Subject: [PATCH] Add mint & redeem SY methods --- hosted-sdk-demo/src/mint-sy.ts | 20 ++++++++++++++++++++ hosted-sdk-demo/src/redeem-sy.ts | 22 ++++++++++++++++++++++ hosted-sdk-demo/src/types.ts | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 hosted-sdk-demo/src/mint-sy.ts create mode 100644 hosted-sdk-demo/src/redeem-sy.ts diff --git a/hosted-sdk-demo/src/mint-sy.ts b/hosted-sdk-demo/src/mint-sy.ts new file mode 100644 index 0000000..0439cfc --- /dev/null +++ b/hosted-sdk-demo/src/mint-sy.ts @@ -0,0 +1,20 @@ +import { CHAIN_ID, RECEIVER_ADDRESS, SY_ADDRESS, wstETH } from "./constants"; +import { callSDK, getSigner } from "./helper"; +import { MintSyData } from "./types"; + +export async function mintSyFromToken() { + // Use 1 wstETH to mint SY with 1% slippage + const res = await callSDK(`/v1/sdk/${CHAIN_ID}/mint-sy`, { + receiver: RECEIVER_ADDRESS, + sy: SY_ADDRESS, + slippage: 0.01, + tokenIn: wstETH, + amountIn: '1000000000000000000', + }); + + console.log('Amount SY Out: ', res.data.amountOut); + console.log('Price impact: ', res.data.priceImpact); + + // Send tx + getSigner().sendTransaction(res.tx); +} \ No newline at end of file diff --git a/hosted-sdk-demo/src/redeem-sy.ts b/hosted-sdk-demo/src/redeem-sy.ts new file mode 100644 index 0000000..3337df6 --- /dev/null +++ b/hosted-sdk-demo/src/redeem-sy.ts @@ -0,0 +1,22 @@ +import { CHAIN_ID, RECEIVER_ADDRESS, SY_ADDRESS, wstETH } from "./constants"; +import { callSDK, getSigner } from "./helper"; +import { RedeemSyData } from "./types"; + +export async function redeemSyToToken() { + // Redeem 1 SY to wstETH with 1% slippage + const res = await callSDK(`/v1/sdk/${CHAIN_ID}/redeem-sy`, { + receiver: RECEIVER_ADDRESS, + slippage: 0.01, + sy: SY_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); +} + +redeemSyToToken() \ No newline at end of file diff --git a/hosted-sdk-demo/src/types.ts b/hosted-sdk-demo/src/types.ts index 427bbad..d9ed65d 100644 --- a/hosted-sdk-demo/src/types.ts +++ b/hosted-sdk-demo/src/types.ts @@ -4,6 +4,8 @@ export type AddLiquidityDualData = { amountOut: string, priceImpact: number }; export type RemoveLiquidityData = { amountOut: string, priceImpact: number }; export type RemoveLiquidityDualData = { amountTokenOut: string; amountPtOut: string, priceImpact: number }; export type MintPyData = { amountOut: string, priceImpact: number }; +export type MintSyData = { amountOut: string, priceImpact: number }; export type RedeemPyData = { amountOut: string, priceImpact: number }; +export type RedeemSyData = { amountOut: string, priceImpact: number }; export type TransferLiquidityData = { amountLpOut: string; amountYtOut: string, priceImpact: number }; export type RollOverPtData = { amountPtOut: string, priceImpact: number }; \ No newline at end of file