Spectra Developer Docs
  • Developers Documentation
  • Getting Started
  • Guides
    • Tokenizing Yield
    • Providing Liquidity
    • Deploy PT and Curve Pool
    • Routing
    • IBT Additional Rewards
    • Locking APW for veAPW
    • Voting and Earning Rewards
  • Technical Reference
    • Deployed Contracts
    • Contract Functions
      • Principal Token
      • Yield Token
      • Registry
      • RateOracle
      • Factory
      • Access Manager
      • RouterUtil
      • Router
      • GovernanceRegistry
      • Voter
      • VotingReward
        • BribeVotingReward
        • FeesVotingReward
      • FeeDistributor
      • Spectra4626Wrapper
    • Yield Calculations
    • Spectra's Automated Market Makers
      • Rate Adjusted StableSwap pools
  • Glossary
  • INTEGRATION REFERENCE
    • Spectra Oracles
      • TWAP Oracles
      • Deterministic Oracles
        • Linear APR model
        • Linear Discount Model
        • Zero Coupon Bond Model
        • Comparison
      • Oracle Deployment
        • Deterministic Oracles Deployment
        • TWAP Oracles Deployment
Powered by GitBook
On this page
  • StableSwap pools
  • Overview
  • Rate Adjusted StableSwap for PT/IBT market making
  • Rate Adjustment Oracles
  • Interest Bearing Token Oracle
  • Principal Tokens pricing
  • Adjusting liquidity concentration
  • Adjusting the fees
  1. Technical Reference
  2. Spectra's Automated Market Makers

Rate Adjusted StableSwap pools

PreviousSpectra's Automated Market MakersNextGlossary

Last updated 2 days ago

In the following, we consider an Interest Bearing Token integrated in Spectra. We assume all instruments start at t=0t=0t=0 and expire at t=Tt=Tt=T.

StableSwap pools

Overview

StableSwap pools, developed by Curve Finance, are an AMM (Automated Market Maker) designed for trading pegged assets. They elaborate on the constant sum invariant to support an infinite price range by interpolating it with the constant sum invariant, while maintaining price impact minimal on almost all of the pool's range. For further information, we refer to the .

Rate Adjusted StableSwap for PT/IBT market making

Using a raw StableSwap pool for exchanging Interest Bearing Tokens for Principal Tokens will not be efficient, since they are not necessarily pegged.

Indeed, we make take as an example Interest Bearing assets with external cash flows, such as rewards or points. The implied rate will take the external cash flows into account, while the value of the Interest Bearing token in underlying asset will not grow as quickly.

The oracle adjusts the internal prices of the AMM with rate oracles by converting the balances into underlying asset, both for the Principal Token and the Interest Bearing token, so that the pair behaves as a pegged pair inside of the AMM. This is achieved through the , as described below.

The AMM's bonding Curve is exclusively used to incorporate implied interest rate volatility, delegating the predictable market drift's accounting to the rate oracles. This drastically improves liquidity usage for trading such a pair, compared to a classical AMM.

Rate Adjustment Oracles

Interest Bearing Token Oracle

Interest Bearing Tokens are ERC4626 compliant vaults. These vaults consist of an underlying asset reserve and a rate at which this reserve evolves. One can convert between shares of the vault and the underlying asset using the convertToAssets() method.

In mathematical terms, if (rt)t∈[0,T](r_t)_{t \in [0,T]}(rt​)t∈[0,T]​ denotes the instantaneous rate process, then the price of an Interest Bearing Token since deployment is given by

B(t)=exp⁡(∫0trudu)B(t) = \exp(\int_0^t r_u du )B(t)=exp(∫0t​ru​du)

Hence, to virtualise the Interest Bearing Token balance of the pool to its underlying value, we have to multiply that balance by the above rate.

This is achieved in practice by flagging the token at index 0 as an asset of type 3, i.e as an ERC4626 token, so that the StableSwap AMM knows it has to adjust the balances with the vault's rate.

Principal Tokens pricing

Principal Tokens are time bound instruments corresponding to a unit of underlying discounted by the implied interest rate over the term it is deployed on. They are the equivalent of zero-coupon bonds. They are redeemable for a unit of underlying at maturity when no negative interest rate has been registered in the underlying Interest Bearing Token, or else for a unit of underlying adjusted by the cumulative loss incurred by the negative interest. In Spectra, the redemption value of the Principal Token is referred to as the ptRate . In mathematical terms, the ptRate can be expressed as

α(t)=exp⁡(∫0truχ{ru<0}du)\alpha(t) = \exp(\int_0^t r_u \chi_{\{r_u < 0\}}du )α(t)=exp(∫0t​ru​χ{ru​<0}​du)

Given an implied APY RRR, the fair value of the Principal Token in underlying asset is given by

P(t,T,R)=α(t)(1+R)T−tyearP(t,T,R) = \frac{\alpha(t)}{(1+R)^{\frac{T-t}{\text{year}}}}P(t,T,R)=(1+R)yearT−t​α(t)​

Let Rˉ\bar{R}Rˉ be the expected implied APY. The Principal Token oracle will report P(t,T,Rˉ)P(t,T,\bar{R})P(t,T,Rˉ). If X(t)X(t)X(t) denotes the internal price of the pool at time ttt, we have that

X(t)P(t,T,Rˉ)B(t)=P(t,T,R)B(t)X(t) \frac{P(t,T,\bar{R})}{B(t)} = \frac{P(t,T,R)}{B(t)}X(t)B(t)P(t,T,Rˉ)​=B(t)P(t,T,R)​

Rearranging, we get

X(t)=P(t,T,R)P(t,T,Rˉ)X(t) = \frac{P(t,T,R)}{P(t,T,\bar{R})}X(t)=P(t,T,Rˉ)P(t,T,R)​

or

X(t)=(1+R−Rˉ1+Rˉ)T−tyearX(t) = \left (1 + \frac{R - \bar{R}}{1+\bar{R}}\right )^{\frac{T-t}{\text{year}}}X(t)=(1+1+RˉR−Rˉ​)yearT−t​

Therefore, with such choice of oracle for the Principal Token, the AMM prices the deviation of the implied rate from the expected rate over the given term.

In practice, this is achieved by flagging the token at index 1 as asset of type 1, i.e an asset whose price with respect to an underlying asset depends on an oracle. The oracle contract is RateAdjustmentOracle.sol and its value is fetched by the StableSwap algorithm before every state change.

Adjusting liquidity concentration

Holding R−RˉR-\bar{R}R−Rˉ constant, if R−Rˉ>0R-\bar{R} > 0R−Rˉ>0, then XXX is strictly decreasing and if R−Rˉ<0R-\bar{R} < 0 R−Rˉ<0, then XXX is strictly increasing. That means that assuming a constant maximal deviation of the implied rate from the expected implied rate, the price range in which liquidity is concentrated should get smaller the closer we get to maturity, to achieve a constant liquidity concentration profile in the implied interest rate space.

Let (A(t))t∈[0,T](A(t))_{t \in [0,T]}(A(t))t∈[0,T]​ be the time-dependent amplification factor and Ft(x,y,A)F_t(x,y,A)Ft​(x,y,A) be the StableSwap invariant, where x,yx,yx,y represent the rate adjusted balances of Interest Bearing Token and Principal Token, respectively. Assume we want to support a maximal deviation of a factor β\betaβ of the implied APY, that is

Rmax=(1+β)RˉR_{\text{max}} = (1+\beta)\bar{R}Rmax​=(1+β)Rˉ

achievable at IBT/PT ratio of l<0.5l < 0.5 l<0.5. Assume that xy>l\frac{x}{y} > lyx​>l (the other case is analogue). Then A(t)A(t)A(t) is defined implicitly by

DyFt(x−Δx,y,A(t))DxFt(x,y+φ(Δx),A(t))−(1+βRˉ1+Rˉ)T−tyear=0\frac{D_yF_t(x-\Delta x,y,A(t))}{D_xF_t(x,y+\varphi(\Delta x),A(t))} - \left (1 + \frac{\beta \bar{R}}{1+\bar{R}}\right )^{\frac{T-t}{\text{year}}} = 0 Dx​Ft​(x,y+φ(Δx),A(t))Dy​Ft​(x−Δx,y,A(t))​−(1+1+RˉβRˉ​)yearT−t​=0

where φ\varphiφ is the trading function implicitly defined by the invariant and Δx\Delta xΔx is chosen such that

x−Δxy+φ(Δy))=l\frac{x - \Delta x}{y + \varphi(\Delta y))} = ly+φ(Δy))x−Δx​=l

Adjusting the fees

The fees are adjusted such that the base fee , taken on the implied APY, stays constant over the term.

StableSwap Whitepaper
rate adjustment mechanism inside of Curve StableSwap