Skip to main content

Create a Limit Order

Pendle Limit Order systems allows makers to create limit orders without using gas. To achieve this, makers's signed orders are stored off-chain and will be filled by the takers on-chain.

To be able to create a limit order and submit it to the Pendle Limit Order system, you can follow these steps:

  1. Generate the limit order data
  2. Sign the limit order data
  3. Post the limit order data and its signature to the Pendle Limit Order system

Pendle expose 2 APIs to support maker create order easier

  1. Generate limit order data
  2. Post limit order

Typescript example

Note:: The code examples in the guide below are taken from our demo GitHub repository, which demonstrates the complete end-to-end Limit Order processes in a TypeScript environment.

Repo

Step 1: Generate limit order data

Order data definition

To place a limit order, maker need to generate this Order struct, which requires several details. Pendle provides a backend API that helps generate this data more easily. By providing the necessary information (orderType, token, maker, impliedAPY), the API returns the full limit order data for the maker.

Maker can generate the complete data yourself, but the API simplifies the process by handling complex fields like salt, failSafeRate, nonce, etc.

const requestBody: GenerateLimitOrderDataRequest = {
chainId: ChainId.ARBITRUM,
YT: aUSDC_MARKET.yt,
maker: signerAddress,
orderType: LimitOrderType.TOKEN_FOR_PT,
token: aUSDC_MARKET.tokenIn.usdc, // Use USDC as token in to swap to PT
makingAmount: '10000000', // 10 USDC
impliedApy: 0.1, // 10% implied APY
expiry: String(Math.floor(Date.now() / 1000) + 20 * 60), // order will be expired in 20 minutes
};

Full details of all limit order data can be found via the GenerateLimitOrderDataResponse on our API specification

Note that you need to ensure you have sufficient balance and allowance to create the limit order; otherwise, the API will return a 400 error.

Step 2: Sign limit order data

const signature = await signer.signTypedData(limitOrderDomainArbitrum, typesLimitOrder, data);

You can find the full example of signing a limit order using ethersjs library on our API demo repository

Step 3: Post the limit order

After sign the limit order data, you can send the limit order data along with the signature to our Backend API

const requestBody: CreateLimitOrderRequest = {
...generatedLimitOrderData,
yt: generatedLimitOrderData.YT,
type: generatedLimitOrderData.orderType,
signature,
};

All the implementation details can be found in the API demo repository