Skip to content

PCSX SDK

Build and sign Exclusive Dutch Order (EDO) trades for PancakeSwap X (PCSX). Dutch orders fill at a decaying price over a short window, guaranteeing MEV protection and price improvement for traders.

Installation

npm install @pancakeswap/pcsx-sdk

Quick start

import {
  createExclusiveDutchOrderTrade,
} from '@pancakeswap/pcsx-sdk'
import { parseQuoteResponse } from '@pancakeswap/price-api-sdk'
import { TradeType } from '@pancakeswap/swap-sdk-core'
import { ChainId } from '@pancakeswap/chains'
import { bscTokens } from '@pancakeswap/tokens'
 
// 1. Fetch a quote from the PCSX price API
const res = await fetch('/api/price-quote', { ... })
const quoteResponse = await res.json()
 
// 2. Parse the quote — encodedOrder and permitData come from the API
const result = parseQuoteResponse(quoteResponse, {
  chainId: ChainId.BSC,
  currencyIn: bscTokens.cake,
  currencyOut: bscTokens.usdt,
  tradeType: TradeType.EXACT_INPUT,
})
 
const trade = result.trade  // ExclusiveDutchOrderTrade
 
// 3. Sign with Permit2 using the permitData from the trade
const signature = await walletClient.signTypedData(trade.permitData)
 
// 4. Submit the encoded order + signature to the filler network
await submitOrder({ encodedOrder: trade.encodedOrder, signature })

createExclusiveDutchOrderTrade

createExclusiveDutchOrderTrade(options: {
  currencyIn: Currency
  currenciesOut: [Currency, ...Currency[]]
  orderInfo: ExclusiveDutchOrderInfo
  tradeType: TradeType
  encodedOrder: Hex
  permitData: PermitWitnessTransferFromData
}) → ExclusiveDutchOrderTrade

Constructs an ExclusiveDutchOrderTrade from a PCSX API quote response. encodedOrder and permitData are provided by the API (typically via parseQuoteResponse from @pancakeswap/price-api-sdk).

ExclusiveDutchOrderInfo

FieldTypeDescription
deadlinenumberUnix timestamp when the order expires
exclusiveFillerstringAddress of the exclusive filler; use address(0) for open fill
exclusivityOverrideBpsbigintBps premium allowed for non-exclusive fillers during the exclusivity window
noncebigintUnique nonce for Permit2

ExclusiveDutchOrderTrade

Plain object encapsulating an EDO trade returned by createExclusiveDutchOrderTrade or parseQuoteResponse.

Properties

PropertyTypeDescription
tradeTypeTradeTypeEXACT_INPUT or EXACT_OUTPUT
inputAmountCurrencyAmountInput amount
outputAmountCurrencyAmountBest-case output (start amount)
minimumAmountOutCurrencyAmountWorst-case output (end amount, at deadline)
maximumAmountInCurrencyAmountMaximum input (end amount)
executionPricePricePrice at fill time 0
worstExecutionPricePricePrice at deadline
priceImpactnullAlways null for EDO trades
orderInfoExclusiveDutchOrderInfoOrder parameters
encodedOrderHexABI-encoded order ready for on-chain submission
permitDataPermitWitnessTransferFromDataEIP-712 typed data for Permit2 signing
quoteQueryHashstring | undefinedQuote identifier from the API

ExclusiveDutchOrder

Low-level class for constructing and encoding the raw UniswapX ExclusiveDutchOrder struct.

MethodSignatureDescription
ExclusiveDutchOrder.parse(encoded: string, chainId: ChainId) → ExclusiveDutchOrderDecode an ABI-encoded order
serialize() → stringABI-encode the order
hash() → stringCompute the order hash
resolve(at: { timestamp: number }) → ResolvedOrderResolve the Dutch auction output at a given timestamp

Constants

ExportTypeDescription
REACTOR_ADDRESS_MAPPINGRecord<ChainId, string>Dutch order reactor addresses per chain

PCSX contract addresses

See PancakeSwap X addresses for deployed reactor addresses.