@balancer-labs/v2-pool-linear

1.1.0 • Public • Published

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 AaveLinearPool, a Linear Pool that integrates with the Aave Protocol and holds aTokens as their "Wrapped" token.

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).

Readme

Keywords

none

Package Sidebar

Install

npm i @balancer-labs/v2-pool-linear

Weekly Downloads

0

Version

1.1.0

License

GPL-3.0-only

Unpacked Size

70 kB

Total Files

6

Last publish

Collaborators

  • endymionjkb
  • jubeira-balancer
  • johngrantuk
  • brunoguerios
  • mikeraymcdonald
  • nventuro