KyberSwap Docs
  • Introduction to KyberSwap
  • Getting Started
    • Quickstart
      • FAQ
    • Supported Exchanges And Networks
    • Foundational Topics
      • Decentralized Finance
        • Tokens
        • Stablecoins
        • DEX/DeFi Aggregator
        • Slippage
        • Price Impact
        • Zap
        • Maximal Extractable Value (MEV)
      • Decentralized Technologies
        • Wallets
        • Dapps
        • RPC
        • Oracles
        • On-Chain vs Off-Chain Data
      • Other Valuable Resources
  • KyberSwap Solutions
    • KyberSwap Interface
      • User Guides
        • Connect Your Wallet
        • Switching Networks
        • Instantly Swap At Superior Rates
        • Swap At Your Preferred Rates
        • Cross-chain Swap
        • Add Your Favourite Tokens
        • Get Crypto With Fiat
        • Bridge Your Assets Across Multiple Chains
      • Profiles
        • Profile Creation
        • Profile Customization
        • Sync Profile Across Devices
      • Notifications
        • Notification Center
    • KyberSwap Aggregator
      • Concepts
        • Dynamic Trade Routing
      • User Guides
        • Instantly Swap At Superior Rates
      • Developer Guides
        • Execute A Swap With The Aggregator API
        • Upgrading To APIv1
      • Aggregator API Specification
        • EVM Swaps
        • Permit
      • Contracts
        • Aggregator Contract Addresses
      • DEX IDs
      • Subgraphs
      • FAQ
    • KyberSwap Zap as a Service
      • KyberSwap Zap as a Service (ZaaS) API
        • ZaaS HTTP API
        • ZaaS GRPC API
      • KyberSwap Zap Liquidity Widget
      • Zap Fee Model
      • Zap's Supported Chains/Dexes
      • Zap's Deployed Contract Addresses
      • Zap's DEX IDs
    • KyberSwap Widget
      • Developer Guides
        • Integrating The KyberSwap Widget
        • Customizing The KyberSwap Widget
      • iFrame Alternative
      • Widget/iFrame Fee
    • KyberSwap Liquidity Widget
      • Integrating The KyberSwap Liquidity Widget
    • Limit Order
      • Concepts
        • Off-Chain Relay, On-Chain Settlement
        • Gasless Cancellation
      • User Guides
        • Swap At Your Preferred Rates
        • Update Limit Orders
        • Cancel Limit Orders
      • Developer Guides
        • Create Limit Order
        • Gasless Cancel
        • Hard Cancel
        • Fill Limit Order
      • Contracts
        • Limit Order Contract Addresses
      • Limit Order API Specification
        • General APIs
        • Maker APIs
        • Taker APIs
      • FAQ
    • KyberSwap OnChain Price Service
    • Fee Schedule
  • Governance
    • KyberDAO
      • User Guides
        • Participating in KyberDAO
        • Staking
        • Voting
        • Stake KNC And Enjoy Gas Savings
      • Fees to KyberDAO
      • KyberDAO Operator MultiSig
      • Contracts
        • KyberDAO Contract Repo
        • KyberDAO Contract Addresses
      • FAQ - Others
    • KNC Token
      • KNC Tokenomics & Utility
      • Gas Refund Program
      • KNC Contract Addresses
  • Security
    • Audits
  • Reference
    • Legacy
      • KyberSwap Classic
        • Concepts
          • Programmable Pricing Curves
          • Dynamic Auto-Adjusting Fees
          • Virtual Balances
          • Protocol Fees
        • Contracts
          • Classic Contract Repo
          • Classic Contract Addresses
          • Classic Contract Farming Addresses
      • KyberSwap Elastic
        • Concepts
          • Concentrated Liquidity
          • Reinvestment Curve
          • Tick-Range Mechanism
          • Pool Process Flows
          • Anti-Sniping Mechanism
          • Tick-Based Farming
          • Elastic Zap
          • TWAP Oracle
          • Elastic APR Calculations
        • Contracts
          • Elastic Contract Repo
          • Elastic Contract Addresses
          • Elastic Farming Contract Addresses
          • Elastic Zap Contract Addresses
          • Elastic Core Contracts
          • Elastic Core Libraries
          • Elastic Periphery Core Contracts
          • Elastic Peripheral Library Contracts
          • Elastic Peripheral Base Contracts
        • Subgraphs
      • Whitepapers
      • Audits
      • KyberAI
        • KyberScore
        • Concepts
        • On-Chain Indicators
          • Number Of Trades
          • Trading Volume
          • Netflow To Whale Wallets
          • Netflow To CEX
          • Number Of Transfers
          • Volume Of Transfers
          • Number Of Holders
          • Top Holders
        • Technical Indicators
          • Live Charts
          • Support & Resistance Levels
          • Live Trades
          • Funding Rate On CEX
          • Liquidations On CEX
        • Liquidity Analysis
      • Elastic Legacy
        • Elastic Legacy Contract Repo
        • Elastic Legacy Contract Addresses
        • Elastic Legacy Farming Contract Addresses
        • Remove Elastic Legacy Liquidity
      • Protocol
        • Overview
        • Smart Contract Architecture
        • Trust and Security Model
      • Integrations
        • Getting Started
        • Use Cases
        • Integration Types
        • Smart Contracts
        • Ethers JS
        • RESTful API
        • Slippage Rate Protection
        • Price Feed Security
        • Contract Events
        • Platform Fees
      • Reserves
        • Getting Started
          • Overview
          • Why Develop On Kyber
          • Create New Reserve
          • Existing Reserves
          • Customising Existing Reserves
        • Development Guides
          • Fed Price Reserve
          • Automated Price Reserve
          • Reserves with Ganache
          • Orderbook Reserve
        • Operations
          • Listing Policies
          • Reserve IDs
          • Reserve Rebates
          • Sanity Rates
      • Addresses
        • Introduction
        • Mainnet
        • Kovan
        • Rinkeby
        • Ropsten
      • API/ABI
        • Introduction
        • RESTful API
          • RESTful API Overview
          • RESTful API
        • Core Smart Contracts
          • IKyberNetworkProxy
          • KyberNetworkProxy
          • IKyberNetwork
          • ISimpleKyberProxy
          • IKyberMatchingEngine
          • KyberMatchingEngine
          • IKyberHint
          • KyberHintHandler
          • IKyberHintHandler
          • IKyberFeeHandler
          • IKyberStaking
          • KyberStaking
          • IKyberDao
          • KyberDao
          • IKyberStorage
          • KyberStorage
          • IKyberHistory
          • KyberHistory
          • IKyberReserve
          • KyberReserve
          • ConversionRates
          • LiquidityConversionRates
          • EpochUtils
          • IEpochUtils
          • KyberFeeHandler
        • Contract ABIs
          • ABIs
        • Code Snippets
          • Token Quantity Conversion
        • Misc Contracts
          • KyberNetwork
          • ConversionRatesInterface
          • PermissionGroups
          • SanityRates
          • Withdrawable
          • OrderbookReserveInterface
          • OrderbookReserveLister
    • KyberSwap Operator MultiSig
    • Permitable Tokens
    • Third-Party Integrations
    • KyberSwap Analytics
    • KyberSwap App
    • GitHub
    • KyberSwap Analytics
    • KyberSwap Blog
    • Kyber Network Press Kit
  • Socials
    • X
    • Discord
    • Telegram
    • LinkedIn
    • Reddit
    • Instagram
    • Tik Tok
  • Support
    • KyberSwap Help Center
    • Complaints Handling Process
Powered by GitBook
On this page
  • Introduction
  • Implementation overview
  • Technical explanation
  • Compounding fee​
  • Reinvestment curve​
  • Approximation condition​
  • Reinvestment token​

Was this helpful?

  1. Reference
  2. Legacy
  3. KyberSwap Elastic
  4. Concepts

Reinvestment Curve

Auto-Compounding LP Fees

PreviousConcentrated LiquidityNextTick-Range Mechanism

Last updated 2 years ago

Was this helpful?

Introduction

As AMMs grew in popularity with the explosion of DeFi summer, its key limitation became increasingly apparent: LP fees sat in the contract unutilized and required significant gas fees to be collected and reinvested. For most, the opportunity cost of idle LP fees was a price which they were willing to pay given the significantly better yields which concentrated liquidity positions offered (as there were limited alternatives). Nevertheless, the gas costs required to constantly reinvest LP fees could quickly become prohibitively expensive for all except the largest LPs. This is also not taking into account the administrative overhead required to manually reinvest LP fees.

The reinvestment curve was a novel solution that was launched with KyberSwap Elastic. The reinvestment curve was designed with the sole purpose of natively reinvesting otherwise unutilized LP fees in the concentrated liquidity model. This meant LP fees for concentrated liquidity positions were automatically compounded without the gas nor the manual management overhead. Moreover, LPs still have the option to collect their auto-compounded fee earnings separately at any point in time.

Crucially, the auto-compounding of yields meant that any LP fees were immediately reinvested therefore ensuring even greater capital efficiency. As such, the reinvestment curve enables otherwise idle capital (i.e. earned interest) to earn an incremental amount of the fees.

Implementation overview

To achieve this feat of auto-compounding yields for non-fungible liquidity positions, KyberSwap Elastic introduced the reinvestment curve which is an additional AMM pool where fees received from the original pool would accrue to. As LP fees are added to the pool, new reinvestment curve liquidity tokens are minted for the original liquidity position. Through aggregating the reinvestment curve with the original price curve, KyberSwap Elastic enables LP fees to be compounded even when a position goes out of range. Put more formally, LP fees are reinvested into the pool at an infinite range.

Technical explanation

Compounding fee

In Uniswap v3, the fees are taken in the form of token0 & token1 separately, which do not contribute to the pool's liquidity. This limit makes Uniswap v3 not directly compoundable within the protocol. The KyberSwap Elastic protocol inherits the liquidity concentration of KyberSwap Classic and achieves customizability of Uniswap v3 while preserving the compounding feature. This is achieved by placing collected fees into a reinvestment curve, which is aggregated with the pool.

The reinvestment curve is a compoundable constant product curve that supports the price range from 0 to infinity. The reinvestment curve is aggregated with the pool so that both pools maintain a common price while behaving differently. Price ranges of the pool have different amounts of liquidity, which are not affected by exchange activities. Meanwhile, the reinvestment curve's liquidity remains the same on all ticks and increases based on the accumulating fee after each swap.

Reinvestment curve

Assume that:

  • x,yx,yx,y: reserve of token in/out

  • Δx,ΔyΔx,ΔyΔx,Δy: amount in/out

  • LLL: liquidity

Base formula:

(1.1) x∗y=L2x*y=L^2x∗y=L2

Currently, the trade fee will be calculated as a proportion of amountIn = (Δx∗fee\Delta x * feeΔx∗fee). This amount will be reinvested into the pool as an addition of liquidity:

(1.2) (x+Δx∗fee)∗y=(L+ΔL)2(x + \Delta x * fee) * y = (L + \Delta L)^2(x+Δx∗fee)∗y=(L+ΔL)2

This can be approximated to

(1.3) ΔL=L∗fee∗Δx2∗x\Delta L =\Large \frac{L * fee * \Delta x}{2 * x}ΔL=2∗xL∗fee∗Δx​

with the assumption that

(1.4) Δx∗fee<<x\Delta x * fee << xΔx∗fee<<x

the equation after swap:

(1.5) (x+Δx)∗(y−Δy)=(L+ΔL)2(x + \Delta x) * (y - \Delta y) = (L + \Delta L)^2(x+Δx)∗(y−Δy)=(L+ΔL)2

By (1.3), we calculate the incremental liquidity based on the amount in and fee; and then by (1.5) we calculate the amount out based on the amount in and incremental liquidity.

After the swap, the constant product curve in 1.1 remains unchanged except that a small proportion of liquidity is added into the curve in the form of reinvestment liquidity. The pool contract will needs to keep track of 2 variables: baseL is the liquidity from LP and reinvestL is the liquidity from the fee. The liquidity L is the sum of these 2 variables. After each swap, the fee will be added into reinvestL.

Assume that fee = 1% and the swap results in less than a 5% change in price, we have:

Δx∗feex<0.0005{\Large \frac{\Delta x * fee}{x} } < 0.0005xΔx∗fee​<0.0005

Alternatively, it is also possible to approximate based on tick calculation for swaps that have less than 5% price impact whereby a 5% change in price is equivalent to 487 ticks.

For swaps which result in price changes greater than 5%, we can dived it into multiple steps whereby each step is limited to a 5% price change.

  • The reinvestment token represents the proportional share of the fee liquidity, reinvestL, that each user is entitled to.

  • Reinvestment tokens are minted each time a user adds/removes liquidity or if a user's position crosses a tick. The amount of reinvestment tokens minted is equivalent to the additional fee liquidity, reinvestL, brought about by the changes in LP liquidity, baseL.

Approximation condition

Reinvestment token

Following the London Hardfork, warming up another contract became increasingly . In order to reduce gas overheads, we have merged the reinvestment token and pool contract. Consequently, the pool contract inherits the ERC20 contract.

concentrated liquidity
​
​
​
​
costly