BullishAF / BancorCompoundPool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bancor Compound Pool

Description

This project aims to implement a new Bancor pool design that interacts with compound platform automatically, when deployed the pool will hold only compound tokens internally (other tokens can be added also), however, when the compound token is added, the underlying token has to be specified.

When funding the pool (converter), liquidity providers will be able to use either cToken or its underlying equivalent. The converter contract will automatically mint the cTokens, if the underlying token is deposited, otherwise the token is directly added to the pool.

The same goes for users converting tokens, even if the pool contains only cToken, they will be able to choose which token to receive or to deposit (cToken or its underlying token) just by changing the conversion path.

Other than the possibility of converting from/to any token, the liquidity providers will benefit from compound earnings since all deposited underlying token will be sent to Compound.

Setup

Dependencies

  • node v10.18.0
  • npm 6.13.4
  • truffle
  • ganache-cli

Installation

$ git clone https://github.com/ridesolo/BancorCompoundPool
$ cd BancorCompoundPool
$ git submodule update --init
$ npm install

Verification

$ npm run test 

Please note that the values generated by the eth-gas-reporter are not accurate since the cToken contract behavior was emulated using a mock contract (extra gas will be consumed by compound contract platform).

Deployment

Deployment can be performed automatically, the script can deploy only dual token pool (cToken/BNT), please note that the underlying token has also to be specified when creating the pool. Pool with multiple reserve tokens (>2) can also be created, however the deployment script does not handle it for now.

Options:

  • --bancorContractRegistry: The address of Bancor Contract Registry deployed in the chosen network.
  • --uToken: Underlying token address of the chosen deployment network.
  • --cToken: Compound token address of the chosen deployment network.
  • --bntReserveBalance: BNT token balance to be deposited as inital reserve (do not forget the decimals).
  • --bntReserveRatio: BNT token ratio (the cumulative value of both ratios should be less than 1000000).
  • --underlyingReserveBalance: Underlying token balance to be deposited as inital reserve (do not forget the decimals).
  • --underlyingReserveRatio: The ratio of the underlying asset (same as the compound token, since they represent a single asset internally).
  • --conversionFee: Pool conversion fee.
  • --initialSmarTokenBalance: Initial smart token balance (don't forget the decimals, set to 18 by default).
  • --privateKey: Wallet private key to the account holding the necessary balances for the deployment.
  • --httpProvider: Http provider URL.

The example below shows how to deploy the converter to the live ethreum network using DAI/cDAI and BNT. Please note that the provided addresses can be subject to change by Bancor or Compound.

truffle migrate --reset --network external  \
--bancorContractRegistry "0x52Ae12ABe5D8BD778BD5397F99cA900624CfADD4" \
--uToken "0x6b175474e89094c44da98b954eedeac495271d0f" \
--cToken "0x5d3a536e4d6dbd6114cc1ead35777bab948e3643" \
--bntReserveBalance "1000000000000000000" \
--bntReserveRatio "500000" \
--underlyingReserveBalance "1000000000000000000" \
--underlyingReserveRatio "500000" \
--conversionFee "30000" \
--initialSmarTokenBalance "2000000000000000000" \
--privateKey "Set the private key to the account holding the necessary balances" \
--httpProvider "https://cloudflare-eth.com"

Web Server

To run the web server locally follow the instructions below:

npm start

To generate deployment file, run:

npm run build:prod

Example

A test example was deployed in Ropsten network under the following addresses:

For this example DAI/cDAI was selected, but any onther token can be deployed using the steps described above.

Path allowed by the converter and successful transactions example:

Token addresses (ropsten network):

Funding and Liquidate tests on ropsten:

When funding, following the balance and the approval amount the smart contract automatically select between underlying token and compound token. When liquidate is used the user receive the underlying token and any other token used as reserve.

About

License:MIT License


Languages

Language:JavaScript 94.4%Language:CSS 4.4%Language:HTML 1.2%