Skip to content

Commit

Permalink
Add mint & redeem SY methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tientran3 committed Dec 19, 2024
1 parent c3f2e0b commit 68b2342
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hosted-sdk-demo/src/mint-sy.ts
Original file line number Diff line number Diff line change
@@ -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<MintSyData>(`/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);
}
22 changes: 22 additions & 0 deletions hosted-sdk-demo/src/redeem-sy.ts
Original file line number Diff line number Diff line change
@@ -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<RedeemSyData>(`/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()
2 changes: 2 additions & 0 deletions hosted-sdk-demo/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

0 comments on commit 68b2342

Please sign in to comment.