Giter VIP home page Giter VIP logo

balancerbot's Introduction

## Intro

A bot that does arbitrage between Uniswap and other exchanges. The idea is to do all the intelligence (decision of when to trade and what trade) off chain with some simple information about the state of prices, etc called from on chain via Infura. A proxy contract atomizes two transactions in one (so that they either both execute or none do).

Decided to develop using Truffle as it's easy to write, test and deploy contracts, etc.

Kyber/UniSwap Implementation

As Balancer contract interfaces aren't ready yet decided to interface to Kyber Network, an on-chain liquidity protocol. This demonstrates swapping between two protocols using the Arb proxy contract. The contract and bot is written in a way that make it easy to swap out the Kyber function for Balancer.

Main contract is found in /contracts/KyberUniArbContract.sol.

  • By default the address that deploys the contract is the owner.
  • UniSwap requires approval to trade tokens on behalf of owner. approveToken function is called for this. Only the contract owner can approve tokens. (Has to be an ERC20 token!)
  • trade function executes a trade. At the moment this does Eth->ERC20 via Kyber then ERC20->Eth via UniSwap which also sends the Eth to the msg.sender.
  • Should be easy to drop in Balancer functions.

Testing

Two approaches to testing.

Javascript unit tests, see 'test/kyberUniArbContract.js' folder. These cover:

  • Confirm fail if not enough Eth sent for trade
  • Confirm atomic trade
  • Only owner can approve tokens

Testing full function on-chain with Rinkeby using Kyber/UniSwap functions. See testScriptsKyber.js for example of full trade, possible to run on Rinkeby or Mainet (when Contract is deployed). See 'Kyber Swaps' below for Rinkeby transaction and script output.

testScriptsUniswap and RinkebyArbContract were initial tests that still have some potentially useful examples for future.

To Do

UniSwap rate issue - waiting for feedback on Discord (can explain further).

Slippage - Not a trader (yet :)) not sure best way to handle this.

Add some events/log processing to Bot. Quite a bit that can be added here but holding off until contract, etc is finalised. Also decide if need more permanent logs?

Meta-transaction type method for contract? Easier use? Bot script would have more control and flexibility. Arb contract just functions as relayer. Would still need some kind of approval so no-one takes advantage of contract? Or make it so caller still spends gas, etc.

Gas Costs

KyberUni Contract Deploy

Rinkeby: 0xbaA1f8d938c064322C0D9c2DC68f0e516AE35678, 0.02210208 ETH Total for deploy via Truffle.

Trade Transaction Fee

0.00246379 Ether, Gas Used: 246,379, Gas Price: 10 Gwei

Rinkeby Kyber/UniSwap Trade:

Tx Hash

$ node testScriptsKyber.js RINKEBY Bot Account Balance: 18.423841957836522602 Arb Contract Balance: 0 The Uniswap exchange address for OMG token is:0x160190Ff19176ab27E0c59C8282bdB8078f1AE59 Approving token... Total supply: 21000000 Tx Count: 82 Signed... Sending... Sent... Allowance: 21000000000000000000000000 Token Approved. Uniswap Eth Reserve: 0.460680160083065078 Uniswap Token Reserve: 0.526373310586151677

Uniswap (OMG -> Eth): 0.875196653816028574 (1.142600346607593195) Kyber (Eth -> OMG): 61.0794391069944

Trading - Kyber: 0.001Eth swapped for: 0.0610794391069944OMG Trading - Uniswap: Sell: 0.0610794391069944 for Eth: 0.046814277882848405 Tx Count: 83 Signed... Sending... Sent... Bot Account Balance: 18.466553715719371007

balancerbot's People

Contributors

johngrantuk 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

Watchers

 avatar  avatar  avatar

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.