Skip to content

Latest commit

 

History

History

pool-linear

Balancer

Balancer V2 Linear Pools

NPM Package Docs

This package contains the source code of Balancer V2 Linear Pools. These are three-token pools which contain "Main" and "Wrapped" tokens, where the wrapped token is typically yield-bearing: e.g., USDC and aUSDC. The third token is the BPT itself, enabling "joins" and "exits" to be performed as part of a batch swap.

Linear Pools are not designed to be accessed directly by end users. Rather, they are typically components of other pools, mainly as constituents of a ComposableStablePool, which enables the "Boosted Pool" behavior.

Overview

Installation

$ npm install @balancer-labs/v2-pool-linear

Usage

This package includes the LinearPool base condtract. Derived Linear Pool that integrate with the Aave Protocol and hold aTokens as their "Wrapped" token can be found in the Orb Collective repo.

However, some users might want to develop their own kind of Linear Pool, potentially integrating with a different protocol. In order to do this, you must inherit the LinearPool contract and implement the _getWrappedTokenRate() function:

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;

import '@balancer-labs/v2-pool-linear/contracts/LinearPool.sol';

contract CustomLinearPool is LinearPool {
  /**
   * @dev Returns a 18-decimal fixed point value that represents the value of the wrapped token in terms of the main
   * token. The final wrapped token scaling factor is this value multiplied by the wrapped token's decimal scaling
   * factor.
   *
   * WARNING: care must be take if calling external contracts from here, even `view` or `pure` functions. If said
   * calls revert, any revert data must not be bubbled-up directly but instead passed to `bubbleUpNonMaliciousRevert`
   * from `ExternalCallLib` (located in the `v2-pool-utils` package). See the following example:
   *
   *  try externalContract.someCall() returns (uint256 value) {
   *    return value;
   *  } catch (bytes memory revertData) {
   *    // Don't automatically bubble-up revert data.
   *    ExternalCallLib.bubbleUpNonMaliciousRevert(revertData);
   *  }
   */
  function _getWrappedTokenRate() internal view override returns (uint256) {}
}

Note: this example is missing some details, like calling the constructor of LinearPool.

Additionally, users might want to also take advantage of the LinearPoolRebalancer contract to have a simple, permissionless and highly efficient way of rebalancing their Pools.

To do this, inherit from LinearPoolRebalancer and implement the _wrapTokens, _unwrapTokens and _getRequiredTokensToWrap functions. See AaveLinearPoolRebalancer for an example.

Licensing

GNU General Public License Version 3 (GPL v3).