forked from balancer/balancer-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
3,258 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3811528 | ||
3528278 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3567680 | ||
3315258 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
186763 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
196603 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
107618 | ||
81507 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
91166 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,3 @@ broadcast/*/*/* | |
|
||
# Out dir | ||
out | ||
|
||
# Smock dir | ||
test/smock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
test/smock/* | ||
test/smock/* | ||
test/manual-smock/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,57 @@ | ||
<p align=center> | ||
<img width="128px" src="https://balancer-labs.github.io/pebbles/images/pebbles-pad.256w.png" alt="balancer pebbles logo"/> | ||
</p> | ||
<h1 align=center><code>Balancer CoW AMM</code></h1> | ||
|
||
<p align="center"> | ||
<a href="https://circleci.com/gh/balancer-labs/balancer-core"> | ||
<img src="https://circleci.com/gh/balancer-labs/balancer-core.svg?style=svg&circle-token=2f432d0cf2690bec7f215a7738bd1142b97bd9b4" /> | ||
</a> | ||
<a href="https://coveralls.io/github/balancer-labs/balancer-core"> | ||
<img src="https://coveralls.io/repos/github/balancer-labs/balancer-core/badge.svg?t=7avwwt" /> | ||
</a> | ||
<a href="https://www.gnu.org/licenses/gpl-3.0"> | ||
<img src="https://img.shields.io/badge/License-GPLv3-green.svg" /> | ||
</a> | ||
</p> | ||
|
||
<h1 align=center><code>balancer</code></h1> | ||
|
||
**Balancer** is an automated **portfolio manager**, **liquidity provider**, and **price sensor**. | ||
|
||
Balancer turns the concept of an index fund on its head: instead of a paying fees | ||
to portfolio managers to rebalance your portfolio, you collect fees from traders, who rebalance | ||
your portfolio by following arbitrage opportunities. | ||
**Balancer CoW AMM** is an automated **portfolio manager**, **liquidity provider**, and **price sensor**, that allows swaps to be executed via the CoW Protocol. | ||
|
||
Balancer is based on an N-dimensional invariant surface which is a generalization of the constant product formula described by Vitalik Buterin and proven viable by the popular Uniswap dapp. | ||
|
||
## 🍂 Bronze Release 🍂 | ||
|
||
The *🍂Bronze Release🍂* is the first of 3 planned releases of the Balancer Protocol. Bronze emphasizes code clarity for audit and verification, and does not go to great lengths to optimize for gas. | ||
|
||
The *❄️Silver Release❄️* will bring many gas optimizations and architecture changes that will reduce transaction overhead and enable more flexibility for managed pools. | ||
|
||
The *☀️Golden Release☀️* will introduce a curious new liquidity mechanism to the market. | ||
|
||
## Documentation | ||
|
||
The full documentation can be found at [https://docs.balancer.finance](https://docs.balancer.finance) | ||
|
||
|
||
## Development | ||
|
||
Most users will want to consume the ABI definitions for BFactory and BPool. | ||
Most users will want to consume the ABI definitions for BPool, BCoWPool, BFactory and BCoWFactory. | ||
|
||
This project follows the standard Truffle project structure. | ||
This project follows the standard Foundry project structure. | ||
|
||
``` | ||
yarn compile # build artifacts to `build/contracts` | ||
yarn testrpc # run ganache | ||
yarn build # build artifacts to `out/` | ||
yarn test # run the tests | ||
``` | ||
|
||
Tests can be run verbosely to view approximation diffs: | ||
|
||
``` | ||
yarn test:verbose | ||
``` | ||
|
||
``` | ||
Contract: BPool | ||
With fees | ||
pAi | ||
expected: 10.891089108910892) | ||
actual : 10.891089106783580001) | ||
relDif : 1.9532588879656032e-10) | ||
Pool Balance | ||
expected: 98010000000000030000) | ||
actual : 98010000001320543977) | ||
relDif : 1.3473294888276702e-11) | ||
Dirt Balance | ||
expected: 3921200210105053000) | ||
actual : 3921200210099248361) | ||
relDif : 1.480428360949332e-12) | ||
Rock Balance | ||
expected: 11763600630315160000) | ||
actual : 11763600630334527239) | ||
relDif : 1.6464292361378058e-12) | ||
✓ exitswap_ExternAmountOut (537ms) | ||
``` | ||
|
||
Complete API docs are available at [https://docs.balancer.finance/smart-contracts/api](https://docs.balancer.finance/smart-contracts/api) | ||
|
||
|
||
<p align=center>⊙</p> | ||
## Changes on BPool from (Balancer V1)[https://github.com/balancer/balancer-core] | ||
- Migrated to Foundry project structure | ||
- Implementation of interfaces with Natspec documentation | ||
- Replaced `require(cond, 'STRING')` for `if(!cond) revert CustomError()` | ||
- Bumped Solidity version from `0.5.12` to `0.8.25` (required for transient storage) | ||
- Added explicit `unchecked` blocks to `BNum` operations (to avoid Solidity overflow checks) | ||
- Deprecated `Record.balance` storage (in favour of `ERC20.balanceOf(address(this))`) | ||
- Deprecated `gulp` method (not needed since reading ERC20 balances) | ||
- Deprecated manageable pools: | ||
- Deprecated `isPublicSwap` mechanism (for pools to be swapped before being finalized) | ||
- Deprecated `rebind` method (in favour of `bind + unbind + bind`) | ||
- Deprecated exit fee on `unbind` (since the pool is not supposed to have collected any fees) | ||
- Deprecated `BBaseToken` (in favour of OpenZeppelin `ERC20` implementation) | ||
- Deprecated `BColor` and `BBronze` (unused contracts) | ||
- Deprecated `Migrations` contract (not needed) | ||
- Added an `_afterFinalize` hook (to be called at the end of the finalize routine) | ||
- Implemented reentrancy locks using transient storage. | ||
|
||
## Features on BCoWPool (added via inheritance to BPool) | ||
- Immutably stores CoW Protocol's `SolutionSettler` and `VaultRelayer` addresses at deployment | ||
- Immutably stores Cow Protocol's a Domain Separator at deployment (to avoid replay attacks) | ||
- Immutably stores Cow Protocol's `GPv2Order.appData` to be allowed to swap | ||
- Gives infinite ERC20 approval to the CoW Protocol's `VaultRelayer` contract | ||
- Implements IERC1271 `isValidSignature` method to allow for validating intentions of swaps | ||
- Implements a `commit` method to avoid multiple swaps from conflicting with each other. | ||
- This is stored in the same transient storage slot as reentrancy locks in order to prevent calls to swap/join functions within a settlement execution or vice versa. | ||
- It's an error to override a commitment since that could be used to clear reentrancy locks. Commitments can only be cleared by ending a transaction. | ||
- Validates the `GPv2Order` requirements before allowing the swap | ||
|
||
## Features on BCoWFactory | ||
- Added a `logBCoWPool` to log the finalization of BCoWPool contracts, to be called by a child pool | ||
|
||
## Creating a Pool | ||
- Create a new pool by calling `IBFactory.newBPool()` | ||
- Give ERC20 allowance to the pool by calling `IERC20.approve(pool, amount)` | ||
- Bind tokens one by one by calling `IBPool.bind(token, amount, weight)` | ||
- The amount represents the initial balance of the token in the pool (pulled from the caller's balance) | ||
- The weight represents the intended distribution of value between the tokens in the pool | ||
- Modify the pool's swap fee by calling `IBPool.setSwapFee(fee)` | ||
- Finalize the pool by calling `IBPool.finalize()` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {BCoWFactory} from 'contracts/BCoWFactory.sol'; | ||
import {Script} from 'forge-std/Script.sol'; | ||
import {Params} from 'script/Params.s.sol'; | ||
|
||
contract DeployBCoWFactory is Script, Params { | ||
function run() public { | ||
BCoWFactoryDeploymentParams memory _params = _bCoWFactoryDeploymentParams[block.chainid]; | ||
|
||
vm.startBroadcast(); | ||
BCoWFactory bCoWFactory = new BCoWFactory(_params.settlement, _params.appData); | ||
bCoWFactory.setBLabs(_params.bLabs); | ||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.8.25; | ||
|
||
/** | ||
* @title BCoWConst | ||
* @notice Constants used in the scope of the BCoWPool contract. | ||
*/ | ||
contract BCoWConst { | ||
/** | ||
* @notice The value representing the absence of a commitment. | ||
* @return _emptyCommitment The commitment value representing no commitment. | ||
*/ | ||
bytes32 public constant EMPTY_COMMITMENT = bytes32(0); | ||
|
||
/** | ||
* @notice The largest possible duration of any AMM order, starting from the | ||
* current block timestamp. | ||
* @return _maxOrderDuration The maximum order duration. | ||
*/ | ||
uint32 public constant MAX_ORDER_DURATION = 5 * 60; | ||
} |
Oops, something went wrong.