summary: Fraxswap
  
  Fraxswap is the first constant product automated market maker with an embedded time-weighted average market maker.
content: Fraxswap is the first constant product automated market maker with an embedded time-weighted average market maker (TWAMM) designed by Frax Finance. Fraxswap is mainly used for conducting large trades over long periods of time trustlessly. In June 2022, the Frax Finance team announced the launch of Fraxswap. !Screen Shot 2022-10-05 at 11.39.39 PM.png Overview Fraxswap is fully permissionless and its core automated market maker is based on Uniswap V2. Fraxswap’s automated market maker aims to help traders execute large orders efficiently. It assists the Frax protocol in increasing the stability of the pegs for the FRAX & FPI stablecoins as well as returning protocol excess profits to FXS holders through TWAMM purchases. The motivation for Fraxswap was to create a unique AMM with specialized features for algorithmic stablecoin monetary policy, forward guidance, and large sustained market orders to stabilize the price of one asset by contracting its supply or acquiring specific collateral over a prolonged period. !FraxSwap.png Diagram of order flow on a Fraxswap pair with a TWAMM order active Core Automated Market Maker Fraxswap’s core automated market maker is Uniswap V2 and based on the full range xy=k constant product design. Fraxswap adhered to many of the design decisions of Uniswap V2 as it extended the codebase to support TWAMMs. Time-weighted Average Market Maker (TWAMM) Fraxswap is the first live TWAMM implementation. The embedded TWAMM adheres to Paradigm’s original whitepaper specifications. The features mentioned in the whitepaper are used to optimize the execution of long-term orders which include the following: Order pooling and aligning order expiries (hourly) Long-term orders are executed prior to any interaction with Fraxswap. The long-term orders are executed first before the automated, interaction and once per block. Fraxswap implemented an approximation formula of Paradigm’s original formula and allows for a simplified, more gas-efficient TWAMM. The TWAMM whitepaper describes the fundamental mechanics: "Each TWAMM instance facilitates trading between a particular pair of assets, such as ETH and [FRAX]. The TWAMM contains an embedded AMM, a standard constant-product market maker for [...] two assets. Anyone may trade with this embedded AMM at any time, just as if it were a normal AMM. Traders can submit long-term orders to the TWAMM, which are orders to sell a fixed amount of one of the assets over a fixed number of blocks — say, an order to sell 100 ETH over the next 2,000 blocks. The TWAMM breaks these long-term orders into infinitely many infinitely small virtual sub-orders, which trade against the embedded AMM at an even rate over time. Processing transactions for each of these virtual sub-orders individually would cost infinite gas, but a closed-form mathematical formula allows us to calculate their cumulative effect only when needed. The execution of long-term orders will push the embedded AMM's price away from prices on other markets over time. When this happens, arbitrageurs will trade against the embedded AMM's price to bring it back in line, ensuring good execution for long-term orders. For example, if long-term sells have made ETH cheaper on the embedded AMM than it is on a particular centralized exchange, arbitrageurs will buy ETH from the embedded AMM, bringing its price back up, and sell it on the centralized exchange for a profit." The interactive comparison of Paradigm’s TWAMM formula and Fraxswap’s TWAMM formula can be found on desmos. Protocol Use Cases & DAO to DAO Swaps The Frax Protocol uses the Fraxswap’s design for its critical system function through TWAMM orders. The core team’s motivation for building Fraxswap was to create a unique AMM with specialized features for algorithmic stablecoin monetary policy, forward guidance, and large sustained market orders to stabilize the price of one asset by contracting its supply or acquiring specific collateral over a prolonged period. Frax Protocol uses Fraxswap for the following: Buying back and burning FXS with AMO profits Minting new FXS to buy back and burn FRAX stablecoins to stabilize the price peg Minting FRAX to purchase hard assets through seigniorage, and many more market operations in development Use cases for other protocols, stablecoin issuers, & DAOs: Fraxswap is a fully permissionless automated market maker that offer other protocols the option to create LP pairs in any token and use Fraxswap for the same (or other novel) use cases. Fraxswap offers use cases for other protocols, stablecoin issuers and DAOs such as: Accumulation of a treasury asset (such as stablecoins) over time by slowly selling governance tokens. Buying back governance tokens slowly over time with DAO revenues & reserves. Acquire another protocol's governance tokens slowly over time with the DAO's own governance tokens. Defending "risk free value" (RFV) for treasury based DAOs such as Olympus, Temple, and various projects where the backing of the governance token is socially or programmatically guaranteed. Fraxswap V2 The core team teased the launch of Fraxswap V2 a few months after the launch of Fraxswap. Fraxswap v2 plans to support concentrated liquidity & correlated asset liquidity in a unique & novel way to allow TWAMM functionality across such pairs. In August 2022, Frax Finance launched Fraxswap V2 which offers new dynamic fee pool creation with the option for governance changes regarding fee tiers. Additionally, Fraxswap V2 offers improved gas optimization for swaps and TWAMMs.