Skip to main content

Swap Simulation Functions

These functions come from the IPActionMarketCoreStatic facet. Each function simulates the corresponding Router swap and returns expected outputs, fee, price impact, and the exchange rate after the trade.

Common return fields:

FieldDescription
netSyFeeFee deducted from the trade, expressed in SY (18 decimals)
priceImpactPrice impact as an 18-decimal fraction (e.g. 1e16 = 1%)
exchangeRateAfterPT/SY exchange rate after the trade (18 decimals)

PT Swaps (Exact In)

swapExactPtForSyStatic

Simulates selling an exact amount of PT for SY.

function swapExactPtForSyStatic(address market, uint256 exactPtIn)
external
view
returns (uint256 netSyOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)

Parameters

NameTypeDescription
marketaddressPendle market address
exactPtInuint256Exact PT amount to sell

Return Values

NameTypeDescription
netSyOutuint256SY received
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

swapExactPtForTokenStatic

Simulates selling an exact amount of PT for an arbitrary token.

function swapExactPtForTokenStatic(address market, uint256 exactPtIn, address tokenOut)
external
view
returns (
uint256 netTokenOut,
uint256 netSyToRedeem,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter
)

Parameters

NameTypeDescription
marketaddressPendle market address
exactPtInuint256Exact PT amount to sell
tokenOutaddressDesired output token address

Return Values

NameTypeDescription
netTokenOutuint256Token received
netSyToRedeemuint256SY redeemed to produce the token output
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

swapExactPtForYtStatic

Simulates swapping an exact amount of PT for YT (leverage/deleverage operation).

function swapExactPtForYtStatic(address market, uint256 exactPtIn)
external
view
returns (
uint256 netYtOut,
uint256 totalPtToSwap,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter
)

Parameters

NameTypeDescription
marketaddressPendle market address
exactPtInuint256Exact PT amount to swap

Return Values

NameTypeDescription
netYtOutuint256YT received
totalPtToSwapuint256Total PT routed through the market (including flash-swap leg)
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

SY / Token Swaps (Exact In, PT Out)

swapExactSyForPtStatic

Simulates buying PT with an exact amount of SY.

function swapExactSyForPtStatic(address market, uint256 exactSyIn)
external
view
returns (uint256 netPtOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)

Parameters

NameTypeDescription
marketaddressPendle market address
exactSyInuint256Exact SY amount to spend

Return Values

NameTypeDescription
netPtOutuint256PT received
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

For generating ApproxParams automatically, use swapExactSyForPtStaticAndGenerateApproxParams instead.


swapExactTokenForPtStatic

Simulates buying PT with an exact amount of an arbitrary token.

function swapExactTokenForPtStatic(address market, address tokenIn, uint256 amountTokenIn)
external
view
returns (
uint256 netPtOut,
uint256 netSyMinted,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter
)

Parameters

NameTypeDescription
marketaddressPendle market address
tokenInaddressInput token address
amountTokenInuint256Exact token amount to spend

Return Values

NameTypeDescription
netPtOutuint256PT received
netSyMinteduint256SY minted from the input token
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

For generating ApproxParams automatically, use swapExactTokenForPtStaticAndGenerateApproxParams instead.


YT Swaps (Exact In)

swapExactSyForYtStatic

Simulates buying YT with an exact amount of SY.

function swapExactSyForYtStatic(address market, uint256 exactSyIn)
external
view
returns (uint256 netYtOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)

Parameters

NameTypeDescription
marketaddressPendle market address
exactSyInuint256Exact SY amount to spend

Return Values

NameTypeDescription
netYtOutuint256YT received
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

swapExactTokenForYtStatic

Simulates buying YT with an exact amount of an arbitrary token.

function swapExactTokenForYtStatic(address market, address tokenIn, uint256 amountTokenIn)
external
view
returns (
uint256 netYtOut,
uint256 netSyMinted,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter
)

Parameters

NameTypeDescription
marketaddressPendle market address
tokenInaddressInput token address
amountTokenInuint256Exact token amount to spend

Return Values

NameTypeDescription
netYtOutuint256YT received
netSyMinteduint256SY minted from the input token
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

swapExactYtForSyStatic

Simulates selling an exact amount of YT for SY. YT selling involves flash-swapping PT to repay accrued interest.

function swapExactYtForSyStatic(address market, uint256 exactYtIn)
external
view
returns (
uint256 netSyOut,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter,
uint256 netSyOwedInt,
uint256 netPYToRepaySyOwedInt,
uint256 netPYToRedeemSyOutInt
)

Parameters

NameTypeDescription
marketaddressPendle market address
exactYtInuint256Exact YT amount to sell

Return Values

NameTypeDescription
netSyOutuint256SY received after repaying interest
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade
netSyOwedIntuint256SY owed as interest that must be repaid
netPYToRepaySyOwedIntuint256PY units used to repay the interest obligation
netPYToRedeemSyOutIntuint256PY units redeemed to produce final SY output

swapExactYtForTokenStatic

Simulates selling an exact amount of YT for an arbitrary token.

function swapExactYtForTokenStatic(address market, uint256 exactYtIn, address tokenOut)
external
view
returns (
uint256 netTokenOut,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter,
uint256 netSyOut,
uint256 netSyOwedInt,
uint256 netPYToRepaySyOwedInt,
uint256 netPYToRedeemSyOutInt
)

Parameters

NameTypeDescription
marketaddressPendle market address
exactYtInuint256Exact YT amount to sell
tokenOutaddressDesired output token address

Return Values

NameTypeDescription
netTokenOutuint256Token received
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade
netSyOutuint256Intermediate SY before token redemption
netSyOwedIntuint256SY owed as interest
netPYToRepaySyOwedIntuint256PY units used to repay the interest obligation
netPYToRedeemSyOutIntuint256PY units redeemed to produce final output

swapExactYtForPtStatic

Simulates swapping an exact amount of YT for PT (leverage/deleverage operation).

function swapExactYtForPtStatic(address market, uint256 exactYtIn)
external
view
returns (
uint256 netPtOut,
uint256 totalPtSwapped,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter
)

Parameters

NameTypeDescription
marketaddressPendle market address
exactYtInuint256Exact YT amount to swap

Return Values

NameTypeDescription
netPtOutuint256PT received
totalPtSwappeduint256Total PT routed through the market
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

Exact-Out Swaps (Inverse)

These functions let you specify the desired output amount and compute the required input.

swapPtForExactSyStatic

Simulates selling PT to receive an exact amount of SY.

function swapPtForExactSyStatic(address market, uint256 exactSyOut)
external
view
returns (uint256 netPtIn, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)

Parameters

NameTypeDescription
marketaddressPendle market address
exactSyOutuint256Exact SY amount desired

Return Values

NameTypeDescription
netPtInuint256PT required
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

swapSyForExactPtStatic

Simulates buying an exact amount of PT with SY.

function swapSyForExactPtStatic(address market, uint256 exactPtOut)
external
view
returns (uint256 netSyIn, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)

Parameters

NameTypeDescription
marketaddressPendle market address
exactPtOutuint256Exact PT amount desired

Return Values

NameTypeDescription
netSyInuint256SY required
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

swapSyForExactYtStatic

Simulates buying an exact amount of YT with SY. Includes the internal interest accounting fields.

function swapSyForExactYtStatic(address market, uint256 exactYtOut)
external
view
returns (
uint256 netSyIn,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter,
uint256 netSyReceivedInt,
uint256 totalSyNeedInt
)

Parameters

NameTypeDescription
marketaddressPendle market address
exactYtOutuint256Exact YT amount desired

Return Values

NameTypeDescription
netSyInuint256SY required from the user
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade
netSyReceivedIntuint256SY received from the internal flash-swap leg
totalSyNeedIntuint256Total SY needed for minting PT+YT in the flash-swap

swapYtForExactSyStatic

Simulates selling YT to receive an exact amount of SY.

function swapYtForExactSyStatic(address market, uint256 exactSyOut)
external
view
returns (uint256 netYtIn, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)

Parameters

NameTypeDescription
marketaddressPendle market address
exactSyOutuint256Exact SY amount desired

Return Values

NameTypeDescription
netYtInuint256YT required
netSyFeeuint256Fee in SY
priceImpactuint256Price impact
exchangeRateAfteruint256Exchange rate after trade

Market State

readMarketState

Returns the raw MarketState struct for a given market.

function readMarketState(address market) external view returns (MarketState memory)

Parameters

NameTypeDescription
marketaddressPendle market address

Return Values

TypeDescription
MarketStateFull AMM state (see PendleMarket for field details)

Use Case Use to pass a pre-fetched MarketState into getTradeExchangeRateExcludeFee or other functions that accept it as a parameter, avoiding redundant on-chain reads.


Examples

Recommended: Use the Pendle API

The examples below show direct RouterStatic usage. For most integrations, the Pendle Hosted SDK / API is the better choice — it handles approximation, limit-order filling, and zap routing automatically.

Sell PT — simulate then execute

const ptAmount = ethers.parseEther("100");

// 1. Simulate
const [netTokenOut, , , priceImpact, exchangeRateAfter] =
await routerStatic.swapExactPtForTokenStatic(MARKET_ADDRESS, ptAmount, WSTETH_ADDRESS);

console.log(`Receive: ${ethers.formatEther(netTokenOut)} wstETH`);
console.log(`Price impact: ${ethers.formatEther(priceImpact * 100n)}%`);
console.log(`Rate after: ${ethers.formatEther(exchangeRateAfter)}`);

// 2. Execute
await IERC20(PT_ADDRESS).approve(ROUTER_ADDRESS, ptAmount);
await router.swapExactPtForToken(
signer.address,
MARKET_ADDRESS,
ptAmount,
createTokenOutputStruct(WSTETH_ADDRESS, (netTokenOut * 995n) / 1000n), // 0.5% slippage
emptyLimitOrderData
);

Sell YT — simulate then execute

const ytAmount = ethers.parseEther("50");

// 1. Simulate (note: YT selling involves flash-swap interest repayment internals)
const [netTokenOut, , priceImpact, , , netSyOwedInt] =
await routerStatic.swapExactYtForTokenStatic(MARKET_ADDRESS, ytAmount, WSTETH_ADDRESS);

console.log(`Receive: ${ethers.formatEther(netTokenOut)} wstETH`);
console.log(`Interest repaid in swap: ${ethers.formatEther(netSyOwedInt)} SY`);

// 2. Execute
await IERC20(YT_ADDRESS).approve(ROUTER_ADDRESS, ytAmount);
await router.swapExactYtForToken(
signer.address,
MARKET_ADDRESS,
ytAmount,
createTokenOutputStruct(WSTETH_ADDRESS, (netTokenOut * 995n) / 1000n),
emptyLimitOrderData
);

PT↔YT swap — simulate then execute

Swapping PT for YT (or YT for PT) changes your yield exposure direction without unwinding to the underlying asset.

const ptAmount = ethers.parseEther("10");

// 1. Simulate PT → YT
const [netYtOut, totalPtToSwap, , priceImpact] =
await routerStatic.swapExactPtForYtStatic(MARKET_ADDRESS, ptAmount);

console.log(`YT out: ${ethers.formatEther(netYtOut)}`);
console.log(`Total PT routed (incl. flash leg): ${ethers.formatEther(totalPtToSwap)}`);

// 2. Execute
await IERC20(PT_ADDRESS).approve(ROUTER_ADDRESS, ptAmount);
await router.swapExactPtForYt(
signer.address,
MARKET_ADDRESS,
ptAmount,
(netYtOut * 995n) / 1000n, // minYtOut
defaultApproxParams
);

Exact-out: buy a precise SY amount

Use swapPtForExactSyStatic when you need a known SY amount (e.g. to meet a downstream obligation).

const exactSyNeeded = ethers.parseEther("1.5");

// 1. Simulate — how much PT to sell?
const [netPtIn, , priceImpact] =
await routerStatic.swapPtForExactSyStatic(MARKET_ADDRESS, exactSyNeeded);

console.log(`PT required: ${ethers.formatEther(netPtIn)}`);

// Apply slippage on the input side (accept up to 0.5% more PT in)
const maxPtIn = (netPtIn * 1005n) / 1000n;

// 2. Execute
await IERC20(PT_ADDRESS).approve(ROUTER_ADDRESS, maxPtIn);
await router.swapPtForExactSy(
signer.address,
MARKET_ADDRESS,
exactSyNeeded,
maxPtIn,
emptyLimitOrderData
);