Skip to content

Commit

Permalink
Add cancel limit order (#16)
Browse files Browse the repository at this point in the history
* Add cancel limit order

* Fix comment
  • Loading branch information
yahuy-pendle authored Dec 20, 2024
1 parent 9756727 commit 9b0407b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
41 changes: 41 additions & 0 deletions hosted-sdk-demo/src/cancel-limit-order.ts
Original file line number Diff line number Diff line change
@@ -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 <CHAIN_ID> made by <USER_ADDRESS>
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 <ORDER_ID>
const {
data: orderData
} = await axios.get<LimitOrderResponse>(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);
}
2 changes: 2 additions & 0 deletions hosted-sdk-demo/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export const YT_ADDRESS = '0x04b7fa1e727d7290d6e24fa9b426d0c940283a95';

export const CHAIN_ID = 1;
export const RECEIVER_ADDRESS = '<RECEVER_ADDRESS>';
export const ORDER_ID = '<ORDER_ID>'
export const USER_ADDRESS = '<USER_ADDRESS>'
1 change: 1 addition & 0 deletions hosted-sdk-demo/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data> = {
tx: {
Expand Down
35 changes: 34 additions & 1 deletion hosted-sdk-demo/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
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;
}

0 comments on commit 9b0407b

Please sign in to comment.