Code Monkey home page Code Monkey logo

balancer-core's Introduction

balancer pebbles logo

balancer

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

Development

Most users will want to consume the ABI definitions for BFactory and BPool.

This project follows the standard Truffle project structure.

yarn compile   # build artifacts to `build/contracts`
yarn testrpc # run ganache
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

balancer-core's People

Contributors

camelwater avatar dependabot-preview[bot] avatar fernandomartinelli avatar mikemcdonald avatar montyly avatar nmushegian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

balancer-core's Issues

swap_exactprice

We might want to have a function that trades until exactly target SER. This is very useful for arbitrage.

how to LOG_SWAP for join/exit

it would be VERY NICE if we could emit an individual SWAP event for each token, exchanging it for the correct weighted quantity of poolcoin

In other words, make it very simple to generate exchange events (ie tax events) from event history

swap...LimitPrice

try/view/do
cross
ExactInLimitPrice
LimitPriceExactOut
MaxInMinOutLimitPrice

API coverage

Trader

swap variants

viewSwap, trySwap, and doSwap for each variant

Function Release Tests? Docs?
*_ExactInAnyOut
*_ExactInMinOut Bronze🥉
*_AnyInExactOut
*_MaxInExactOut Bronze🥉
*_ExactInLimitPrice Silver🥈
*_LimitPriceExactOut Silver🥈
*_MaxInMinOutLimitPrice Silver🥈
getSpotPrice Bronze🥉

Pooling

Function Release Tests? Docs?
isPoolOpen Bronze🥉
pool Bronze🥉
unpool Bronze🥉
getRefPrice Bronze🥉
getAmountsForRefValue Bronze🥉

Manager

Function Release Tests? Docs?
bind Bronze🥉
unbind Bronze🥉
start Bronze🥉
pause Bronze🥉
sweep Bronze🥉
setFee Bronze🥉
setParams Bronze🥉
setWeightAdjustBalance Silver🥈
setBalanceAdjustWeight Silver🥈
getBalance Bronze🥉
getPercent Bronze🥉
getWeight Bronze🥉

starter issue

mutex for xfers

there's no correct way to mutate balances and make 2 calls

should lock around both xfers

swapOmath tests

you can tell there's a bug from just reading

make a test to catch it

alternate API

swap_ExactAmountIn((Ti), Ai, (To), Lo, Lp) returns (Ao, Mp)
swap_ExactAmountOut((Ti), Li, (To), Ao, Lp) returns (Ai, Mp)
swap_ExactMarginalPrice((Ti), Li, (To), Lo, MP) returns (Ai, Ao)
swap_ThreeLimitMaximize((Ti), Li, (To), Lo, Lp) returns (Ai, Ao, Mp)

determine limits for pow approximations

we need to set a limit for base for pow approximation in testing and contract code. the approximation converges for base < 2, but we don't know whether that's the best limit to advertise to users since the error always favors balancer

random test points

characterize valid points

  • 0 < Bi, Wi, Bo, Wo < MAXINT
  • Ai < Bi
  • Ao < Bo
  • 0 <= fee < 1

generate a lot of them and test swapImathExact against solidity implementation

improve coverage for tests

We'd like to have full code coverage. For example, our MaxInMinOut test cases don't error at all. Fine to have separate test ranges for errors to start, but in the end it might be good to have our current ranges to include errors.

bronze Min and Max weights

if we want our weight range to be 1.0 - 100.0 then a lot of our tests would fail

most tests should pass with simply scaling up the test points weights

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.