Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pkg/balancer-js/src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ const balancerErrorCodes: Record<string, string> = {
'525': 'NONZERO_TOKEN_BALANCE',
'526': 'BALANCE_TOTAL_OVERFLOW',
'527': 'POOL_NO_TOKENS',
'528': 'INSUFFICIENT_FLASH_LOAN_BALANCE',
'600': 'SWAP_FEE_PERCENTAGE_TOO_HIGH',
'601': 'FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH',
'602': 'INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT',
'603': 'AUM_FEE_PERCENTAGE_TOO_HIGH',
'700': 'SPLITTER_FEE_PERCENTAGE_TOO_HIGH',
'998': 'UNIMPLEMENTED',
Expand Down
31 changes: 0 additions & 31 deletions pkg/interfaces/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,6 @@ contract SimpleDepositor {
}
```

Sample contract that performs Flash Loans:

```solidity
pragma solidity ^0.7.0;

import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IFlashLoanRecipient.sol";

contract FlashLoanRecipient is IFlashLoanRecipient {
IVault private constant vault = "0xBA12222222228d8Ba445958a75a0704d566BF2C8";

function makeFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
bytes memory userData
) external {
vault.flashLoan(this, tokens, amounts, userData);
}

function receiveFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
uint256[] memory feeAmounts,
bytes memory userData
) external override {
require(msg.sender == vault);
...
}
}
```

### Notes

In addition to interfaces, it also includes a small number of libraries that encapsulate enum types for particular pools (e.g., [StablePoolUserData](contracts/pool-stable/StablePoolUserData.sol), and functions for working with encoding and decoding `userData`. (See the `balancer-js` package for TypeScript versions of these utilities.)
Expand Down
25 changes: 25 additions & 0 deletions pkg/interfaces/contracts/pool-range/RangePoolUserData.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.7.0 <0.9.0;

import "../pool-weighted/WeightedPoolUserData.sol";

library RangePoolUserData {
// Joins

function initialVirtualBalances(bytes memory self) internal pure returns (uint256[] memory virtualBalances) {
(, , virtualBalances) = abi.decode(self, (WeightedPoolUserData.JoinKind, uint256[], uint256[]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,9 @@ library Errors {
uint256 internal constant NONZERO_TOKEN_BALANCE = 525;
uint256 internal constant BALANCE_TOTAL_OVERFLOW = 526;
uint256 internal constant POOL_NO_TOKENS = 527;
uint256 internal constant INSUFFICIENT_FLASH_LOAN_BALANCE = 528;

// Fees
uint256 internal constant SWAP_FEE_PERCENTAGE_TOO_HIGH = 600;
uint256 internal constant FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH = 601;
uint256 internal constant INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT = 602;
uint256 internal constant AUM_FEE_PERCENTAGE_TOO_HIGH = 603;

// FeeSplitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface IProtocolFeePercentagesProvider {
event ProtocolFeeTypeRegistered(uint256 indexed feeType, string name, uint256 maximumPercentage);

// Emitted when the value of a fee type changes.
// IMPORTANT: it is possible for a third party to modify the SWAP and FLASH_LOAN fee type values directly in the
// IMPORTANT: it is possible for a third party to modify the SWAP fee type values directly in the
// ProtocolFeesCollector, which will result in this event not being emitted despite their value changing. Such usage
// of the ProtocolFeesCollector is however discouraged: all state-changing interactions with it should originate in
// this contract.
Expand Down Expand Up @@ -61,11 +61,10 @@ interface IProtocolFeePercentagesProvider {
/**
* @dev Sets the percentage value for `feeType` to `newValue`.
*
* IMPORTANT: it is possible for a third party to modify the SWAP and FLASH_LOAN fee type values directly in the
* IMPORTANT: it is possible for a third party to modify the SWAP fee type values directly in the
* ProtocolFeesCollector, without invoking this function. This will result in the `ProtocolFeePercentageChanged`
* event not being emitted despite their value changing. Such usage of the ProtocolFeesCollector is however
* discouraged: only this contract should be granted permission to call `setSwapFeePercentage` and
* `setFlashLoanFeePercentage`.
* discouraged: only this contract should be granted permission to call `setSwapFeePercentage`.
*/
function setFeeTypePercentage(uint256 feeType, uint256 newValue) external;

Expand Down Expand Up @@ -93,7 +92,6 @@ library ProtocolFeeType {

// solhint-disable private-vars-leading-underscore
uint256 internal constant SWAP = 0;
uint256 internal constant FLASH_LOAN = 1;
uint256 internal constant YIELD = 2;
uint256 internal constant AUM = 3;
// solhint-enable private-vars-leading-underscore
Expand Down
37 changes: 0 additions & 37 deletions pkg/interfaces/contracts/vault/IFlashLoanRecipient.sol

This file was deleted.

5 changes: 0 additions & 5 deletions pkg/interfaces/contracts/vault/IProtocolFeesCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import "./IAuthorizer.sol";

interface IProtocolFeesCollector {
event SwapFeePercentageChanged(uint256 newSwapFeePercentage);
event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage);

function withdrawCollectedFees(
IERC20[] calldata tokens,
Expand All @@ -32,12 +31,8 @@ interface IProtocolFeesCollector {

function setSwapFeePercentage(uint256 newSwapFeePercentage) external;

function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external;

function getSwapFeePercentage() external view returns (uint256);

function getFlashLoanFeePercentage() external view returns (uint256);

function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts);

function getAuthorizer() external view returns (IAuthorizer);
Expand Down
38 changes: 8 additions & 30 deletions pkg/interfaces/contracts/vault/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import "../solidity-utils/misc/IWETH.sol";

import "./IAsset.sol";
import "./IAuthorizer.sol";
import "./IFlashLoanRecipient.sol";
import "./IProtocolFeesCollector.sol";

pragma solidity >=0.7.0 <0.9.0;
Expand Down Expand Up @@ -448,6 +447,13 @@ interface IVault is ISignaturesValidator, ITemporarilyPausable, IAuthentication

enum PoolBalanceChangeKind { JOIN, EXIT }

/* Withdraws all pool token balances to caller. The caller should be authorized to call this function.
* The call doesn't burn pool tokens and doesn't change totalSupply.
*
* Emits a `PoolBalanceChanged` event.
*/
function exitPoolEmergency(bytes32 poolId) external;

// Swaps
//
// Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this,
Expand Down Expand Up @@ -649,32 +655,6 @@ interface IVault is ISignaturesValidator, ITemporarilyPausable, IAuthentication
FundManagement memory funds
) external returns (int256[] memory assetDeltas);

// Flash Loans

/**
* @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it,
* and then reverting unless the tokens plus a proportional protocol fee have been returned.
*
* The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount
* for each token contract. `tokens` must be sorted in ascending order.
*
* The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the
* `receiveFlashLoan` call.
*
* Emits `FlashLoan` events.
*/
function flashLoan(
IFlashLoanRecipient recipient,
IERC20[] memory tokens,
uint256[] memory amounts,
bytes memory userData
) external;

/**
* @dev Emitted for each individual flash loan performed by `flashLoan`.
*/
event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount);

// Asset Management
//
// Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's
Expand Down Expand Up @@ -732,9 +712,7 @@ interface IVault is ISignaturesValidator, ITemporarilyPausable, IAuthentication
// Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by
// permissioned accounts.
//
// There are two kinds of protocol fees:
//
// - flash loan fees: charged on all flash loans, as a percentage of the amounts lent.
// There is one kind of protocol fees:
//
// - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including
// swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather,
Expand Down
1 change: 1 addition & 0 deletions pkg/pool-range/.solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
contracts/test/
30 changes: 30 additions & 0 deletions pkg/pool-range/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# <img src="../../logo.svg" alt="Range" height="128px">

# Range Weighted Pools


This package contains the source code for Range Weighted Pools, that is, Pools that swap tokens by enforcing a Constant Weighted Product invariant.

The pool currently in existence is [`RangePool`](./contracts/RangePool.sol) (basic ten token version).

Another useful contract is [`RangeMath`](./contracts/RangeMath.sol), which implements the low level calculations required for swaps, joins, exits and price calculations.

## Overview

### Installation

```console
$ git clone --recurse-submodules https://github.com/puzzlenetwork/ranges-sol

```

### Usage

This package can be used in multiple ways, including interacting with already deployed Pools, performing local testing, or even creating new Pool types that also use the Constant Weighted Product invariant.

To get the address of deployed contracts in both mainnet and various test networks, see [`range-deployments` repository](https://github.com/puzzlenetwork/range-deployments.git).


## Licensing

[GNU General Public License Version 3 (GPL v3)](../../LICENSE).
Loading
Loading