- Free Compass API Key
- Wallet EOA or smart account guide
Introduction
Pendle lets you tokenize and trade future yield. With Compass Labs, you can interact with Pendle markets - including buying/selling PT, YT, and LP positions - in just a few lines of code. Normally this would require complex smart contract logic and allowance juggling. With Compass SDK, you abstract all of that away. This tutorial walks you through a full strategy lifecycle across fixed and variable yield.Setup
The full, uninterrupted code is available at the end of the tutorial.
Query Pendle Markets
First, we need a Pendle market on Arbitrum to perform transactions with. Let’s query the list of active markets and select one we’d like to interact with.Select a Market
For simplicity, we are selecting the first market returned of the list of
active markets with
markets[0]. Consider things like implied yield,
maturity date and the underlying token when deciding which Pendle market to
transact with.Fixed Yield
Buy Principal Token (PT) to Earn Fixed Yield
Now that we have decided on a Pendle market to transact with, let us take our first position in the market by buying fixed yield. Fixed yield positions are represented by PT tokens. The price difference between 1 PT and 1 Underlying Asset represents the fixed yield your entitled to claim after the maturity date of the market when PT tokens can be redeemed 1:1 for the Underlying Asset.Check and Set Allowance
Check the current allowance given for the Pendle Router on the
USDC contract. If that allowance is less than the amount of
USDC we intend to use to purchase PT, then set the
allowance to a sufficient level.
Sell Principal Token (PT) Before Maturity Date
Let’s say some time after we purchsed our PT, we notice the market offering a more favorable signal for going long on yield. This likely means the implied yield rate has come down since we first took the PT position. Before going long on yield, we may want to sell our PT position beforehand and use the proceeds to fund our YT position.Check User Position
Check our current position in the Pendle market by including a user address with the Pendle Market
function. This will allow us to obtain our current PT balance.
Check and Set Allowance
Check the current allowance given for the Pendle Router on the PT
contract. If that allowance is less than the amount of PT we intend to
sell, then set the allowance to a sufficient level.
Both Principal Tokens (PT) and Yield Tokens (YT) are ERC-20 compatible
and, just like the Underlying Asset, require sufficient spending
allowances to be set on them before a given contract can spend a user’s
balance.
Variable Yield
Buy Yield Token (YT) to Earn Variable Yield
We have decided a long yield position is now favorable. This is likely because the implied yield rate has lowered. We now think that the yield generated from the Underlying Asset will be greater than the current implied yield from now until the market’s maturity date.Check User Position
Check our current position in the Pendle market by including a user address with the Pendle Market
function. This will allow us to obtain our current Underlying Asset balance.
Check and Set Allowance
Check the current allowance given for the Pendle Router on the
Underlying Asset contract. If that allowance is less than the amount of
Underlying Asset we intend to use to purchase YT, then set the
allowance to a sufficient level.
Redeem Claimable Yield and Sell YT Position
Perhaps now the implied yield has increased again and we’d like to sell our Yield Tokens (YT) for a profit before the maturity date of the market.Redeem Claimable Yield
Redeem any outstanding claimable yield on our YT. This will land in our wallet in the form of the market’s Underlying Asset.
Check and Set Allowance
Check the current allowance given for the Pendle Router on the YT
contract. If that allowance is less than the amount of YT we intend to
sell, then set the allowance to a sufficient level.
Provide Liquidity
Add Liquidity (LP)
Let’s say we are uncertain whether to take fixed yield or go long yield in a particular Pendle market but we’d still like to earn yield. Another option is to provide liquidity to the market and earn yield in the form of fees accrued by the market from other users taking positions. The liquidity you provide to a given Pendle market is represented by LP tokens.Check and Set Allowance
Check the current allowance given for the Pendle Router on the
USDT contract. If that allowance is less than the amount of
USDT we intend to use to purchase LP, then set the
allowance to a sufficient level.