Skip to main content

Types and Utility Functions

This document covers all struct types used throughout the Pendle Router and utility functions for generating parameters on-chain.

Core Parameter Types

TokenInput

Defines input token configuration for functions that accept tokens.

struct TokenInput {
address tokenIn;
uint256 netTokenIn;
address tokenMintSy;
address pendleSwap;
SwapData swapData;
}

Fields

NameTypeDescription
tokenInaddressAddress of the input token (can be any ERC20 token supported by Pendle)
netTokenInuint256Amount of input tokens
tokenMintSyaddressToken used to mint SY (must be supported by target SY contract)
pendleSwapaddressSwap aggregator address (use address(0) for direct SY token input)
swapDataSwapDataSwap configuration data for external aggregation

Usage Patterns

Direct SY Token Input (Simple): When tokenIn is already a token supported by the target SY contract:

  • Set tokenIn = tokenMintSy (same token)
  • Set pendleSwap = address(0) (no external swap needed)
  • Set swapData to empty (no aggregation)

Any ERC20 Token Input (Zap In): When tokenIn is any ERC20 token that needs to be swapped to a supported SY token:

  • Set tokenIn to the user's input token (e.g., USDC, DAI, WETH)

  • Set tokenMintSy to a token supported by the target SY

  • Set pendleSwap to the swap aggregator address

  • Set swapData with proper aggregator configuration.

    E.g: When you had USDC token and want to mint SY-sUSDe:

    • Set tokenIn = USDC
    • Set tokenMintSy = SY-sUSDe
    • Set pendleSwap = 0xd4F480965D2347d421F1bEC7F545682E5Ec2151D
    • Set swapData to proper data configuration obtained from SDK

Benefits of Zap In:

  • Users can interact with any Pendle market using any ERC20 token they hold
  • No need to manually swap tokens before interacting with Pendle
  • Optimal routing through multiple DEXes for best price execution
  • Single transaction for swap + Pendle operation

SDK Integration: The Pendle Hosted SDK automatically handles all TokenInput configuration when you enable routing. When you set enableAggregator: true in SDK calls, it:

  • Automatically selects the best swap aggregator (KyberSwap, ODOS, 1inch, etc.)
  • Generates optimal swapData for the chosen route
  • Handles all token conversions transparently
  • Provides the best possible price execution across multiple DEXes

For direct contract interaction, you need to manually configure these fields or use utility functions like createTokenInputSimple() for basic operations.

TokenOutput

Defines output token configuration for functions that return tokens.

struct TokenOutput {
address tokenOut;
uint256 minTokenOut;
address tokenRedeemSy;
address pendleSwap;
SwapData swapData;
}

Fields

NameTypeDescription
tokenOutaddressAddress of the desired output token (can be any ERC20 token supported by Pendle)
minTokenOutuint256Minimum amount of output tokens to receive (slippage protection)
tokenRedeemSyaddressToken to redeem SY to (must be supported by target SY contract)
pendleSwapaddressSwap aggregator address (use address(0) for direct SY token output)
swapDataSwapDataSwap configuration data for external aggregation

Usage Patterns

Direct SY Token Output (Simple): When tokenOut is already a token supported by the target SY contract:

  • Set tokenOut = tokenRedeemSy (same token)
  • Set pendleSwap = address(0) (no external swap needed)
  • Set swapData to empty (no aggregation)

Any ERC20 Token Output (Zap Out): When tokenOut is any ERC20 token different from supported SY tokens:

  • Set tokenOut to the user's desired token (e.g., USDC, DAI, WETH)
  • Set tokenRedeemSy to a token supported by the target SY
  • Set pendleSwap to the swap aggregator address
  • Set swapData with proper aggregator configuration (KyberSwap, 1inch, etc.)

Benefits of Zap Out:

  • Users can receive any ERC20 token as output from Pendle operations
  • No need to manually swap tokens after exiting Pendle positions
  • Optimal routing through multiple DEXes for best price execution
  • Single transaction for Pendle operation + swap
  • Built-in slippage protection with minTokenOut

SDK Integration: The Pendle Hosted SDK automatically handles all TokenOutput configuration when you enable routing. When you set enableAggregator: true in SDK calls, it:

  • Automatically selects the best swap aggregator for output token conversion
  • Generates optimal swapData for the chosen route
  • Calculates appropriate slippage protection
  • Handles all token conversions transparently

For direct contract interaction, you need to manually configure these fields or use utility functions like createTokenOutputSimple() for basic operations.

ApproxParams

Parameters for approximation algorithms used when swapping exact tokens to PT or YT. ApproxParams is required when the exact output amount needs to be determined through iterative approximation because the Pendle AMM formula cannot be directly inverted.

struct ApproxParams {
uint256 guessMin;
uint256 guessMax;
uint256 guessOffchain;
uint256 maxIteration;
uint256 eps;
}

Fields

NameTypeDescription
guessMinuint256Minimum bound for binary search
guessMaxuint256Maximum bound for binary search (use type(uint256).max for auto)
guessOffchainuint256Initial guess from off-chain calculation (use 0 for on-chain)
maxIterationuint256Maximum iterations for binary search (recommended: 256)
epsuint256Precision tolerance (recommended: 1e14)

When ApproxParams is Needed:

ApproxParams is required for functions that swap an exact amount of tokens to PT or YT, such as:

Why Approximation is Required: The Pendle AMM natively supports functions like swapExactPtForSy and swapSyForExactPt, but does NOT have swapExactSyForPt. When you want to swap an exact amount of tokens/SY for PT/YT, the router must use binary search to determine how much PT/YT can be obtained, since the AMM can only calculate the reverse (exact PT amounts).

LimitOrderData

Configuration for limit order functionality that provides better prices and reduces slippage by filling user orders at predetermined rates before routing to the AMM.

struct LimitOrderData {
address limitRouter;
uint256 epsSkipMarket;
FillOrderParams[] normalFills;
FillOrderParams[] flashFills;
bytes optData;
}

Fields

NameTypeDescription
limitRouteraddressAddress of limit order router
epsSkipMarketuint256Threshold to skip market operations
normalFillsFillOrderParams[]Normal limit order fills
flashFillsFillOrderParams[]Flash loan limit order fills
optDatabytesAdditional optimization data

RedeemYtIncomeToTokenStruct

Configuration for YT income redemption with token conversion.

struct RedeemYtIncomeToTokenStruct {
IPYieldToken yt;
bool doRedeemInterest;
bool doRedeemRewards;
address tokenRedeemSy;
uint256 minTokenRedeemOut;
}

Fields

NameTypeDescription
ytIPYieldTokenYT token contract interface
doRedeemInterestboolWhether to redeem accrued interest
doRedeemRewardsboolWhether to redeem reward tokens
tokenRedeemSyaddressToken to convert SY interest to
minTokenRedeemOutuint256Minimum tokens to receive from conversion

SwapData

Configuration for external swap aggregation functionality.

struct SwapData {
SwapType swapType;
address extRouter;
bytes extCalldata;
bool needScale;
}

Fields

NameTypeDescription
swapTypeSwapTypeType of swap aggregator to use
extRouteraddressAddress of the external swap router
extCalldatabytesEncoded calldata for the external swap
needScaleboolWhether the swap amount needs scaling

Use Case Enables integration with external swap aggregators like KyberSwap, 1inch, Paraswap, etc. This allows Pendle to support zapping in/out with any ERC20 token by routing through external DEXes.

SwapType

Enumeration defining supported swap aggregator types. See the complete SwapType definition in the smart contract.

enum SwapType {
NONE,
KYBERSWAP,
ODOS,
ETH_WETH,
OKX,
ONE_INCH,
PARASWAP
}

Values

ValueDescription
NONENo external swap aggregation
KYBERSWAPKyberSwap aggregation
ODOSODOS aggregation
ETH_WETHETH/WETH conversion
OKXOKX DEX aggregation
ONE_INCH1inch aggregation
PARASWAPParaswap aggregation

Use Case Specifies which external aggregator to use for token swaps, enabling Pendle to leverage the best available liquidity across different DEXes. The Pendle Hosted SDK automatically selects the optimal SwapType based on available liquidity and routing efficiency.

ExitPreExpReturnParams

Detailed breakdown of returns from pre-expiry position exit operations.

struct ExitPreExpReturnParams {
uint256 netPtFromRemove;
uint256 netSyFromRemove;
uint256 netPyRedeem;
uint256 netSyFromRedeem;
uint256 netPtSwap;
uint256 netYtSwap;
uint256 netSyFromSwap;
uint256 netSyFee;
uint256 totalSyOut;
}

Fields

NameTypeDescription
netPtFromRemoveuint256PT tokens obtained from LP removal
netSyFromRemoveuint256SY tokens obtained from LP removal
netPyRedeemuint256PT+YT pairs redeemed to SY
netSyFromRedeemuint256SY tokens from PT+YT redemption
netPtSwapuint256PT tokens swapped to SY
netYtSwapuint256YT tokens swapped to SY
netSyFromSwapuint256SY tokens from PT/YT swaps
netSyFeeuint256Trading fees paid in SY
totalSyOutuint256Total SY tokens received

Use Case Provides detailed breakdown of complex exit operations before market expiry, helping users understand exactly how their positions were unwound and what fees were paid.

ExitPostExpReturnParams

Breakdown of returns from post-expiry position exit operations.

struct ExitPostExpReturnParams {
uint256 netPtFromRemove;
uint256 netSyFromRemove;
uint256 netPtRedeem;
uint256 netSyFromRedeem;
uint256 totalSyOut;
}

Fields

NameTypeDescription
netPtFromRemoveuint256PT tokens obtained from LP removal
netSyFromRemoveuint256SY tokens obtained from LP removal
netPtRedeemuint256PT tokens redeemed at maturity
netSyFromRedeemuint256SY tokens from PT redemption
totalSyOutuint256Total SY tokens received

Use Case Provides breakdown of exit operations after market expiry when PT tokens can be redeemed 1:1 for underlying assets. Simpler than pre-expiry exits since no swapping is required.

Utility Functions

These functions generate the parameters described above on-chain, offering an alternative for users who do not utilize the Pendle SDK.

createTokenInputSimple

Creates a simple TokenInput struct without external swapping.

function createTokenInputSimple(address tokenIn, uint256 netTokenIn) pure returns (TokenInput memory)

Input Parameters

NameTypeDescription
tokenInaddressInput token address (must be supported by target SY)
netTokenInuint256Amount of input tokens

Return Values

NameTypeDescription
-TokenInputConfigured TokenInput struct

Use Case Most common way to create TokenInput for standard operations. The tokenIn must be one of the tokens accepted by the target SY contract (check via IStandardizedYield.getTokensIn()).

createTokenOutputSimple

Creates a simple TokenOutput struct without external swapping.

function createTokenOutputSimple(address tokenOut, uint256 minTokenOut) pure returns (TokenOutput memory)

Input Parameters

NameTypeDescription
tokenOutaddressOutput token address (must be supported by target SY)
minTokenOutuint256Minimum amount of output tokens

Return Values

NameTypeDescription
-TokenOutputConfigured TokenOutput struct

Use Case Most common way to create TokenOutput for standard operations. The tokenOut must be one of the tokens that the target SY can redeem to (check via IStandardizedYield.getTokensOut()).

createDefaultApproxParams

Creates default approximation parameters suitable for most operations.

function createDefaultApproxParams() pure returns (ApproxParams memory)

Return Values

NameTypeDescription
-ApproxParamsConfigured ApproxParams with optimal defaults

Configuration

  • guessMin: 0
  • guessMax: type(uint256).max (auto-detection)
  • guessOffchain: 0 (pure on-chain calculation)
  • maxIteration: 256 (sufficient for most cases)
  • eps: 1e14 (0.01% precision)

Use Case Recommended for all operations requiring approximation. These parameters provide good balance between accuracy and gas costs.

createEmptyLimitOrderData

Creates an empty LimitOrderData struct for operations without limit orders.

function createEmptyLimitOrderData() pure returns (LimitOrderData memory)

Return Values

NameTypeDescription
-LimitOrderDataEmpty LimitOrderData struct

Use Case Use when you don't need limit order functionality. Required by many functions but can be empty for standard market operations.

Integration Examples

Basic Parameter Creation

// Create input parameters for 1000 USDC
TokenInput memory input = createTokenInputSimple(USDC_ADDRESS, 1000e6);

// Create output parameters expecting at least 950 USDC
TokenOutput memory output = createTokenOutputSimple(USDC_ADDRESS, 950e6);

// Create default approximation parameters
ApproxParams memory approx = createDefaultApproxParams();

// Create empty limit order data
LimitOrderData memory limit = createEmptyLimitOrderData();

Complete Function Call Example

// Add liquidity with properly configured parameters
router.addLiquiditySingleToken(
msg.sender, // receiver
MARKET_ADDRESS, // market
minLpOut, // minLpOut
createDefaultApproxParams(), // guessPtReceivedFromSy
createTokenInputSimple(USDC_ADDRESS, 1000e6), // input
createEmptyLimitOrderData() // limit
);

Custom ApproxParams for Advanced Use

// Create custom approximation parameters for high precision
ApproxParams memory customApprox = ApproxParams({
guessMin: 0,
guessMax: type(uint256).max,
guessOffchain: estimatedOutput, // Use off-chain calculation if available
maxIteration: 512, // Higher precision
eps: 1e15 // Tighter tolerance (0.001%)
});

Best Practices

For Standard Operations:

  • Always use createDefaultApproxParams() unless you have specific precision requirements
  • Use createEmptyLimitOrderData() for simple market operations
  • Ensure token addresses are supported by target SY contracts

For Performance:

  • Off-chain approximation (guessOffchain) can reduce gas costs significantly
  • Higher maxIteration values increase precision but cost more gas
  • Tighter eps values improve precision but may increase iterations