📊Long Term Traders

Incentives

Maximize: order fill, privacy

Minimize: gas, slippage, MEV

Neutral: time to fill

Long-term traders who are interested in taking opinionated long-term positions traditionally relied on CEX or OTC desks. Centralized venues attract large order flows because of the availability of novel trade execution schemes and privacy beyond the obvious reasons like MEV and gas fees.

However, given the recent turmoil with centralized parties (see FTX), the risks associated with trading on these platforms outweigh the advantages they used to offer.

TWAMMs automate the execution of large orders by breaking the order into smaller virtual orders and executing it over multiple blocks. Arbitrageurs pay gas fees to write virtual orders on-chain when they correct asset prices as they deviate. Liquidity providers earn swap fees plus MEV kickbacks, and the entire trade lifecycle stays on-chain.

Executing On-Chain

With new on-chain technologies like TWAMMs and future developments planned, trading volume will naturally flow to the most efficient and secure platforms. Here's the current flow to execute large trades on centralized trading venues:

  1. KYC/AML on the regulated trading venue

  2. Move on-chain assets to the trading venue

  3. Use Web UX or Telegram Chats to get quotes

  4. Execute trades

  5. Withdraw proceeds and move them back on-chain

The list doesn't take into account the myriad of risks (custodial, counter-party, etc), expenses (high swap fees, platform fees, etc), and time delay of all the steps listed above.

On-chain Trading Experience with TWAMM

With our periphery contract, you'll be able to interact with TWAMM directly from Etherscan or a multitude of our integration partners.

In essence, this is what a long-term trader does:

swap $100M of ETH for USDC over 10,000 blocks

The smart contract executes the most efficient TWAP order on behalf of the trader. All the trader has done is step #4 from the list above. There's no change of custody or delays from setup till trade execution.

TWAMM Order with Uniswap V3 Range Orders

Below is a great example of how much better TWAMMs could be versus atomic execution venues like DEXs and aggregators. The same trade netted roughly ~$2M! more for the trader by using arbitrageurs to fill the order over multiple blocks.

How to use

Code Example

/// @notice ltSwap function with additional checks in place to ensure users don't lose funds by interacting
///         with TWAMM pools improperly. This function is only for long-term swappers < SwapType.LongTermSwap > 
///         and will be more gas expensive due to the additional checks.
/// @param  _amountIn the amount of tokenIn sold to the pool
/// @param  _intervals number of intervals trade should be executed in
/// @param  _poolType the pool type of the pair can be (Stable, Liquid, or Volatile). This affects the fee
///         tier and gas used to interact with the pool due to the OBI of executeVirtualOrders
/// @param  _tokenIn the address of the token sold to the pool
/// @param  _tokenOut the address of the token purchased from the pool
/// @param  _to the address where the purchased tokens should be sent to
///
function longTermSwap(
  uint256 _amountIn,
  uint256 _intervals,
  uint256 _poolType,
  address _tokenIn,
  address _tokenOut,
  address _to
) external {
  // balancer vault
  address constant VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
  // mainnet factory
  address constant FACTORY = 0xD64c9CD98949C07F3C85730a37c13f4e78f35E77;
  // get pool from factory
  address pool = ICronV1PoolFactory(FACTORY).getPool(_tokenIn, _tokenOut, _poolType);
  // setup information for long term swap
  bytes memory userData = abi.encode(
    ICronV1PoolEnums.SwapType.LongTermSwap, // swap type
    _intervals
  );
  bytes32 poolId = ICronV1Pool(pool).POOL_ID();
  (IERC20[] memory tokens, , ) = IVault(VAULT).getPoolTokens(poolId);
  IAsset[] memory assets = _convertERC20sToAssets(tokens);
  // approve tokens to spend from this contract in the vault
  tokens[0].approve(VAULT, swapAmount);
  // send long term order request to the pool via vault
  IVault(VAULT).swap(
    // ensure correct ordering of assets, matches tokenIn & tokenOut
    // this assumes tokenIn == assets[0] and tokenOut == assets[1]
    IVault.SingleSwap(poolId, IVault.SwapKind.GIVEN_IN, assets[0], assets[1], _amountIn, userData),
    IVault.FundManagement(msg.sender, false, payable(_to), false),
    0,
    block.timestamp + 1000
  );
}

Periphery

Who needs this today?

On-chain advantages of custody, programmability, and composability of capital are too attractive to ignore. TWAMMs are the ideal on-chain complement for trades that are large and time-insensitive such as peg maintenance, liquidations, & asset diversification.

Here's a short list of use cases and personas that can leverage TWAMMs:

đŸ‘ĢpageDAOs💉pageOpen Market OperationsđŸ’ŧpageTreasury Managers🌊pageLiquid Funds⚖ī¸pageToken Monetary Policy

Last updated