1"use strict";(self.webpackChunkpendle_documentation=self.webpackChunkpendle_documentation||[]).push([[1499],{8438:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>x,frontMatter:()=>i,metadata:()=>r,toc:()=>l});const r=JSON.parse('{"id":"Contracts/RouterStatic/ApiReference/RateFunctions","title":"Market Rates & State Functions","description":"These functions come from the IPActionMarketAuxStatic facet. They cover spot prices, market state, price impact calculations, and ApproxParams generation helpers.","source":"@site/docs/pendle-dev-docs/Contracts/RouterStatic/ApiReference/RateFunctions.md","sourceDirName":"Contracts/RouterStatic/ApiReference","slug":"/Contracts/RouterStatic/ApiReference/RateFunctions","permalink":"/pendle-v2-dev/Contracts/RouterStatic/ApiReference/RateFunctions","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"hide_table_of_contents":true},"sidebar":"pendleDevSidebar","previous":{"title":"Info Functions","permalink":"/pendle-v2-dev/Contracts/RouterStatic/ApiReference/InfoFunctions"},"next":{"title":"Swap Functions","permalink":"/pendle-v2-dev/Contracts/RouterStatic/ApiReference/SwapFunctions"}}');var s=n(4848),d=n(8453);const i={hide_table_of_contents:!0},c="Market Rates & State Functions",a={},l=[{value:"Spot Rates",id:"spot-rates",level:2},{value:"getLpToSyRate",id:"getlptosyrate",level:3},{value:"getLpToAssetRate",id:"getlptoassetrate",level:3},{value:"getPtToSyRate",id:"getpttosyrate",level:3},{value:"getPtToAssetRate",id:"getpttoassetrate",level:3},{value:"getYtToSyRate",id:"getyttosyrate",level:3},{value:"getYtToAssetRate",id:"getyttoassetrate",level:3},{value:"Market State",id:"market-state",level:2},{value:"getMarketState",id:"getmarketstate",level:3},{value:"getTradeExchangeRateExcludeFee",id:"gettradeexchangerateexcludefee",level:3},{value:"getTradeExchangeRateIncludeFee",id:"gettradeexchangerateincludefee",level:3},{value:"Price Impact",id:"price-impact",level:2},{value:"calcPriceImpactPt",id:"calcpriceimpactpt",level:3},{value:"calcPriceImpactYt",id:"calcpriceimpactyt",level:3},{value:"calcPriceImpactPY",id:"calcpriceimpactpy",level:3},{value:"Yield Token / PT / YT Conversion Rates",id:"yield-token--pt--yt-conversion-rates",level:2},{value:"getYieldTokenAndPtRate",id:"getyieldtokenandptrate",level:3},{value:"getYieldTokenAndYtRate",id:"getyieldtokenandytrate",level:3},{value:"ApproxParams Helpers",id:"approxparams-helpers",level:2},{value:"swapExactSyForPtStaticAndGenerateApproxParams",id:"swapexactsyforptstaticandgenerateapproxparams",level:3},{value:"swapExactTokenForPtStaticAndGenerateApproxParams",id:"swapexacttokenforptstaticandgenerateapproxparams",level:3},{value:"Examples",id:"examples",level:2},{value:"Display LP / PT / YT spot prices",id:"display-lp--pt--yt-spot-prices",level:3},{value:"Read market state and implied yield",id:"read-market-state-and-implied-yield",level:3},{value:"Gate a trade on price impact",id:"gate-a-trade-on-price-impact",level:3},{value:"Buy PT with token using generated ApproxParams",id:"buy-pt-with-token-using-generated-approxparams",level:3}];function h(e){const t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",hr:"hr",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,d.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.header,{children:(0,s.jsx)(t.h1,{id:"market-rates--state-functions",children:"Market Rates & State Functions"})}),"\n",(0,s.jsxs)(t.p,{children:["These functions come from the ",(0,s.jsx)(t.code,{children:"IPActionMarketAuxStatic"})," facet. They cover spot prices, market state, price impact calculations, and ",(0,s.jsx)(t.code,{children:"ApproxParams"})," generation helpers."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h2,{id:"spot-rates",children:"Spot Rates"}),"\n",(0,s.jsx)(t.p,{children:"All spot rates are returned as 18-decimal fixed-point numbers."}),"\n",(0,s.jsx)(t.h3,{id:"getlptosyrate",children:"getLpToSyRate"}),"\n",(0,s.jsxs)(t.p,{children:["Returns the ",(0,s.jsx)(t.strong,{children:"spot"})," price of 1 LP token denominated in the market's SY token."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getLpToSyRate(address market) external view returns (uint256)\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]})})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Spot LP price in SY units (18 decimals)"})]})})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"getlptoassetrate",children:"getLpToAssetRate"}),"\n",(0,s.jsxs)(t.p,{children:["Returns the ",(0,s.jsx)(t.strong,{children:"spot"})," price of 1 LP token denominated in the SY's underlying asset."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getLpToAssetRate(address market) external view returns (uint256)\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]})})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Spot LP price in underlying asset units (18 decimals)"})]})})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"getpttosyrate",children:"getPtToSyRate"}),"\n",(0,s.jsxs)(t.p,{children:["Returns the ",(0,s.jsx)(t.strong,{children:"spot"})," price of 1 PT token denominated in SY."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getPtToSyRate(address market) external view returns (uint256)\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]})})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Spot PT price in SY units (18 decimals)"})]})})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"getpttoassetrate",children:"getPtToAssetRate"}),"\n",(0,s.jsxs)(t.p,{children:["Returns the ",(0,s.jsx)(t.strong,{children:"spot"})," price of 1 PT token denominated in the SY's underlying asset."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getPtToAssetRate(address market) external view returns (uint256)\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"getyttosyrate",children:"getYtToSyRate"}),"\n",(0,s.jsxs)(t.p,{children:["Returns the ",(0,s.jsx)(t.strong,{children:"spot"})," price of 1 YT token denominated in SY."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getYtToSyRate(address market) external view returns (uint256)\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"getyttoassetrate",children:"getYtToAssetRate"}),"\n",(0,s.jsxs)(t.p,{children:["Returns the ",(0,s.jsx)(t.strong,{children:"spot"})," price of 1 YT token denominated in the SY's underlying asset."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getYtToAssetRate(address market) external view returns (uint256)\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h2,{id:"market-state",children:"Market State"}),"\n",(0,s.jsx)(t.h3,{id:"getmarketstate",children:"getMarketState"}),"\n",(0,s.jsx)(t.p,{children:"Returns the full market state along with derived metrics."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getMarketState(address market)\n external\n view\n returns (\n address pt,\n address yt,\n address sy,\n int256 impliedYield,\n uint256 marketExchangeRateExcludeFee,\n MarketState memory state\n )\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]})})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"pt"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Principal Token address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"yt"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Yield Token address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"sy"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"SY token address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"impliedYield"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"int256"})}),(0,s.jsx)(t.td,{children:"Current implied yield rate (18 decimals)"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"marketExchangeRateExcludeFee"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Current PT/SY exchange rate (fees excluded)"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"state"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"MarketState"})}),(0,s.jsx)(t.td,{children:"Full low-level AMM state struct"})]})]})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"gettradeexchangerateexcludefee",children:"getTradeExchangeRateExcludeFee"}),"\n",(0,s.jsx)(t.p,{children:"Returns the current trade exchange rate from a given market state, excluding fees."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getTradeExchangeRateExcludeFee(address market, MarketState memory state)\n external\n view\n returns (uint256)\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"state"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"MarketState"})}),(0,s.jsxs)(t.td,{children:["Market state (e.g. from ",(0,s.jsx)(t.code,{children:"getMarketState"}),")"]})]})]})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Exchange rate excluding fees (18 decimals)"})]})})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"gettradeexchangerateincludefee",children:"getTradeExchangeRateIncludeFee"}),"\n",(0,s.jsx)(t.p,{children:"Returns the effective exchange rate for a specific trade size, including fees."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getTradeExchangeRateIncludeFee(address market, int256 netPtOut)\n external\n view\n returns (uint256)\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netPtOut"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"int256"})}),(0,s.jsx)(t.td,{children:"Signed PT delta for the trade (positive = PT leaving pool, negative = PT entering pool)"})]})]})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Effective exchange rate including fees (18 decimals)"})]})})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h2,{id:"price-impact",children:"Price Impact"}),"\n",(0,s.jsxs)(t.p,{children:["All price impact values are returned as 18-decimal fixed-point numbers (e.g. ",(0,s.jsx)(t.code,{children:"1e16"})," = 1%)."]}),"\n",(0,s.jsx)(t.h3,{id:"calcpriceimpactpt",children:"calcPriceImpactPt"}),"\n",(0,s.jsx)(t.p,{children:"Calculates the price impact of a PT trade."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function calcPriceImpactPt(address market, int256 netPtOut)\n external\n view\n returns (uint256)\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netPtOut"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"int256"})}),(0,s.jsx)(t.td,{children:"Signed PT amount (posi
1tive = buy PT, negative = sell PT)"})]})]})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Price impact as a fraction (18 decimals)"})]})})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"calcpriceimpactyt",children:"calcPriceImpactYt"}),"\n",(0,s.jsx)(t.p,{children:"Calculates the price impact of a YT trade, expressed in PT terms."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function calcPriceImpactYt(address market, int256 netPtOut)\n external\n view\n returns (uint256)\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"calcpriceimpactpy",children:"calcPriceImpactPY"}),"\n",(0,s.jsx)(t.p,{children:"Calculates the combined price impact of a simultaneous PT+YT trade."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function calcPriceImpactPY(address market, int256 netPtOut)\n external\n view\n returns (uint256)\n"})}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h2,{id:"yield-token--pt--yt-conversion-rates",children:"Yield Token / PT / YT Conversion Rates"}),"\n",(0,s.jsx)(t.h3,{id:"getyieldtokenandptrate",children:"getYieldTokenAndPtRate"}),"\n",(0,s.jsx)(t.p,{children:"Returns how many yield tokens are equivalent to 1 PT at current rates."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getYieldTokenAndPtRate(address market)\n external\n view\n returns (address yieldToken, uint256 netPtOut, uint256 netYieldTokenOut)\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]})})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"yieldToken"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"The market's underlying yield-bearing token"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netPtOut"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Normalised PT amount used as the basis (typically 1e18)"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netYieldTokenOut"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Equivalent yield token amount"})]})]})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"getyieldtokenandytrate",children:"getYieldTokenAndYtRate"}),"\n",(0,s.jsx)(t.p,{children:"Returns how many yield tokens are equivalent to 1 YT at current rates."}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function getYieldTokenAndYtRate(address market)\n external\n view\n returns (address yieldToken, uint256 netYtOut, uint256 netYieldTokenOut)\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"yieldToken"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"The market's underlying yield-bearing token"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netYtOut"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Normalised YT amount used as the basis (typically 1e18)"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netYieldTokenOut"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Equivalent yield token amount"})]})]})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h2,{id:"approxparams-helpers",children:"ApproxParams Helpers"}),"\n",(0,s.jsxs)(t.p,{children:["These functions combine a swap simulation with automatic ",(0,s.jsx)(t.code,{children:"ApproxParams"})," generation. Pass the returned ",(0,s.jsx)(t.code,{children:"approxParams"})," directly to the corresponding Router function."]}),"\n",(0,s.jsx)(t.h3,{id:"swapexactsyforptstaticandgenerateapproxparams",children:"swapExactSyForPtStaticAndGenerateApproxParams"}),"\n",(0,s.jsxs)(t.p,{children:["Simulates swapping exact SY for PT and returns a ready-to-use ",(0,s.jsx)(t.code,{children:"ApproxParams"}),"."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function swapExactSyForPtStaticAndGenerateApproxParams(\n address market,\n uint256 exactSyIn,\n uint256 slippage\n)\n external\n view\n returns (\n uint256 netPtOut,\n uint256 netSyFee,\n uint256 priceImpact,\n uint256 exchangeRateAfter,\n ApproxParams memory approxParams\n )\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"exactSyIn"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Exact SY amount to swap in"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"slippage"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsxs)(t.td,{children:["Maximum acceptable slippage (18-decimal fraction, e.g. ",(0,s.jsx)(t.code,{children:"5e15"})," = 0.5%)"]})]})]})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netPtOut"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Expected PT output"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netSyFee"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Fee paid in SY"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"priceImpact"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Price impact of the trade (18 decimals)"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"exchangeRateAfter"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Exchange rate after the trade (18 decimals)"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"approxParams"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"../../PendleRouter/ApiReference/Types#approxparams",children:(0,s.jsx)(t.code,{children:"ApproxParams"})})}),(0,s.jsx)(t.td,{children:"Pre-filled approximation parameters for the Router call"})]})]})]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h3,{id:"swapexacttokenforptstaticandgenerateapproxparams",children:"swapExactTokenForPtStaticAndGenerateApproxParams"}),"\n",(0,s.jsxs)(t.p,{children:["Simulates swapping exact tokens for PT and returns a ready-to-use ",(0,s.jsx)(t.code,{children:"ApproxParams"}),"."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-solidity",children:"function swapExactTokenForPtStaticAndGenerateApproxParams(\n address market,\n address tokenIn,\n uint256 amountTokenIn,\n uint256 slippage\n)\n external\n view\n returns (\n uint256 netPtOut,\n uint256 netSyMinted,\n uint256 netSyFee,\n uint256 priceImpact,\n uint256 exchangeRateAfter,\n ApproxParams memory approxParams\n )\n"})}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Parameters"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"market"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Pendle market address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"tokenIn"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"address"})}),(0,s.jsx)(t.td,{children:"Input token address"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"amountTokenIn"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Exact token amount to swap in"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"slippage"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Maximum acceptable slippage (18-decimal fraction)"})]})]})]}),"\n",(0,s.jsx)(t.p,{children:(0,s.jsx)(t.strong,{children:"Return Values"})}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Name"}),(0,s.jsx)(t.th,{children:"Type"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netPtOut"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Expected PT output"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netSyMinted"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"SY minted from the input token"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"netSyFee"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Fee paid in SY"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"priceImpact"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Price impact of the trade (18 decimals)"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"exchangeRateAfter"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"uint256"})}),(0,s.jsx)(t.td,{children:"Exchange rate after the trade (18 decimals)"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:"approxParams"}),(0,s.jsx)(t.td,{children:(0,s.jsx)(t.a,{href:"../../PendleRouter/ApiReference/Types#approxparams",children:(0,s.jsx)(t.code,{children:"ApproxParams"})})}),(0,s.jsx)(t.td,{children:"Pre-filled approximation parameters for the Router call"})]})]})]}),"\n",(0,s.jsxs)(t.p,{children:[(0,s.jsx)(t.strong,{children:"Use Case"}),"\nThis is the recommended way to populate ",(0,s.jsx)(t.code,{children:"ApproxParams"})," for ",(0,s.jsx)(t.code,{children:"swapExactTokenForPt"}),". It avoids the need to tune approximation parameters manually."]}),"\n",(0,s.jsx)(t.hr,{}),"\n",(0,s.jsx)(t.h2,{id:"examples",children:"Examples"}),"\n",(0,s.jsx)(t.admonition,{title:"Recommended: Use the Pendle API",type:"tip",children:(0,s.jsxs)(t.p,{children:["The examples below show direct RouterStatic usage. For most integrations, the ",(0,s.jsx)(t.a,{href:"../../../Backen
1d/HostedSdk",children:"Pendle Hosted SDK / API"})," is the better choice \u2014 it handles approximation, limit-order filling, and zap routing automatically."]})}),"\n",(0,s.jsx)(t.h3,{id:"display-lp--pt--yt-spot-prices",children:"Display LP / PT / YT spot prices"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",children:"const [lpToAsset, ptToAsset, ytToAsset] = await Promise.all([\n routerStatic.getLpToAssetRate(MARKET_ADDRESS),\n routerStatic.getPtToAssetRate(MARKET_ADDRESS),\n routerStatic.getYtToAssetRate(MARKET_ADDRESS),\n]);\n\n// All values are 18-decimal fractions of the underlying asset\nconsole.log(`1 LP = ${ethers.formatEther(lpToAsset)} underlying`);\nconsole.log(`1 PT = ${ethers.formatEther(ptToAsset)} underlying`);\nconsole.log(`1 YT = ${ethers.formatEther(ytToAsset)} underlying`);\n"})}),"\n",(0,s.jsx)(t.h3,{id:"read-market-state-and-implied-yield",children:"Read market state and implied yield"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",children:"const [pt, yt, sy, impliedYield, exchangeRateExcludeFee, state] =\n await routerStatic.getMarketState(MARKET_ADDRESS);\n\n// impliedYield is a signed 18-decimal annualised rate\nconst impliedYieldPct = Number(ethers.formatEther(impliedYield)) * 100;\nconsole.log(`Implied yield: ${impliedYieldPct.toFixed(2)}%`);\nconsole.log(`PT: ${pt}, YT: ${yt}, SY: ${sy}`);\n"})}),"\n",(0,s.jsx)(t.h3,{id:"gate-a-trade-on-price-impact",children:"Gate a trade on price impact"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",children:'const netPtOut_amount = ethers.parseEther("500");\n\nconst priceImpact = await routerStatic.calcPriceImpactPt(MARKET_ADDRESS, netPtOut_amount);\nconst impactPct = Number(ethers.formatEther(priceImpact)) * 100;\n\nif (impactPct > 1.0) {\n throw new Error(`Price impact ${impactPct.toFixed(2)}% exceeds 1% threshold \u2014 reduce size`);\n}\n'})}),"\n",(0,s.jsx)(t.h3,{id:"buy-pt-with-token-using-generated-approxparams",children:"Buy PT with token using generated ApproxParams"}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",children:'const tokenIn = WSTETH_ADDRESS;\nconst amountIn = ethers.parseEther("1");\nconst SLIPPAGE = ethers.parseEther("0.005"); // 0.5%\n\n// 1. Get simulation + ready-to-use ApproxParams in a single call\nconst [netPtOut, netSyMinted, netSyFee, priceImpact, exchangeRateAfter, approxParams] =\n await routerStatic.swapExactTokenForPtStaticAndGenerateApproxParams(\n MARKET_ADDRESS,\n tokenIn,\n amountIn,\n SLIPPAGE\n );\n\nconsole.log(`PT out: ${ethers.formatEther(netPtOut)}`);\nconsole.log(`Fee: ${ethers.formatEther(netSyFee)} SY`);\nconsole.log(`Impact: ${ethers.formatEther(priceImpact * 100n)}%`);\n\n// 2. Execute \u2014 pass approxParams directly, no manual tuning needed\nawait IERC20(tokenIn).approve(ROUTER_ADDRESS, amountIn);\nawait router.swapExactTokenForPt(\n signer.address,\n MARKET_ADDRESS,\n (netPtOut * 995n) / 1000n, // minPtOut\n approxParams, // generated by RouterStatic\n createTokenInputStruct(tokenIn, amountIn),\n emptyLimitOrderData\n);\n'})})]})}function x(e={}){const{wrapper:t}={...(0,d.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>c});var r=n(6540);const s={},d=r.createContext(s);function i(e){const t=r.useContext(d);return r.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:i(e.components),r.createElement(d.Provider,{value:t},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.