diff --git a/hosted-sdk-demo/src/cancel-limit-order.ts b/hosted-sdk-demo/src/cancel-limit-order.ts new file mode 100644 index 0000000..6a45b3e --- /dev/null +++ b/hosted-sdk-demo/src/cancel-limit-order.ts @@ -0,0 +1,41 @@ +import axios from "axios"; +import { CHAIN_ID, ORDER_ID, USER_ADDRESS } from "./constants"; +import { callSDK, getSigner, LIMIT_ORDER_URL } from "./helper"; +import { LimitOrderResponse } from "./types"; + +export async function cancelAll() { + // Cancel all limit orders on made by + const res = await callSDK(`v1/sdk/${CHAIN_ID}/limit-order/cancel-all`, { + userAddress: USER_ADDRESS, + }); + + // Send tx + getSigner().sendTransaction(res.tx); +} + +export async function cancelSingle() { + // Get order with + const { + data: orderData + } = await axios.get(LIMIT_ORDER_URL + `/v1/limit-order/${ORDER_ID}`, {}); + + // Cancel the order + const res = await callSDK(`v1/sdk/${CHAIN_ID}/limit-order/cancel-single`, { + userAddress: USER_ADDRESS, + salt: orderData.salt, + expiry: orderData.expiry, + nonce: orderData.nonce, + orderType: orderData.type, + token: orderData.token, + YT: orderData.yt, + maker: orderData.maker, + receiver: orderData.receiver, + makingAmount: orderData.makingAmount, + lnImpliedRate: orderData.lnImpliedRate, + failSafeRate: orderData.failSafeRate, + permit: orderData.permit, + }); + + // Send tx + getSigner().sendTransaction(res.tx); +} \ No newline at end of file diff --git a/hosted-sdk-demo/src/constants.ts b/hosted-sdk-demo/src/constants.ts index f70a541..1ea3fba 100644 --- a/hosted-sdk-demo/src/constants.ts +++ b/hosted-sdk-demo/src/constants.ts @@ -8,3 +8,5 @@ export const YT_ADDRESS = '0x04b7fa1e727d7290d6e24fa9b426d0c940283a95'; export const CHAIN_ID = 1; export const RECEIVER_ADDRESS = ''; +export const ORDER_ID = '' +export const USER_ADDRESS = '' diff --git a/hosted-sdk-demo/src/helper.ts b/hosted-sdk-demo/src/helper.ts index 4e0b0e9..8fc277b 100644 --- a/hosted-sdk-demo/src/helper.ts +++ b/hosted-sdk-demo/src/helper.ts @@ -2,6 +2,7 @@ import axios from 'axios'; import { ethers } from 'ethers'; const HOSTED_SDK_URL = 'https://api-v2.pendle.finance/core/'; +export const LIMIT_ORDER_URL = 'https://api-v2.pendle.finance/limit-order/' type MethodReturnType = { tx: { diff --git a/hosted-sdk-demo/src/types.ts b/hosted-sdk-demo/src/types.ts index d9ed65d..9c57354 100644 --- a/hosted-sdk-demo/src/types.ts +++ b/hosted-sdk-demo/src/types.ts @@ -8,4 +8,37 @@ 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 +export type RollOverPtData = { amountPtOut: string, priceImpact: number }; + +export interface LimitOrderResponse { + /** Hash of the order */ + id: string; + /** Signature of order, signed by maker */ + signature: string; + /** Chain id */ + chainId: number; + /** BigInt string of salt */ + salt: string; + /** BigInt string of expiry, in second */ + expiry: string; + /** BigInt string of nonce */ + nonce: string; + /** LimitOrderType { 0 : TOKEN_FOR_PT, 1 : PT_FOR_TOKEN, 2 : TOKEN_FOR_YT, 3 : YT_FOR_TOKEN } */ + type: 0 | 1 | 2 | 3; + /** Token used by user to make order */ + token: string; + /** YT address */ + yt: string; + /** Maker address */ + maker: string; + /** Receiver address */ + receiver: string; + /** BigInt string of making amount, the amount of token if the order is TOKEN_FOR_PT or TOKEN_FOR_YT, otherwise the amount of PT or YT */ + makingAmount: string; + /** BigInt string of remaining making amount, the unit is the same as makingAmount */ + lnImpliedRate: string; + /** BigInt string of failSafeRate */ + failSafeRate: string; + /** Bytes string for permit */ + permit: string; +} \ No newline at end of file