Giter Site home page Giter Site logo

crypto-index-fund's Introduction

PortFolio

This repository contains the backend code for the PortFolio project, written in Solidity.

Motivation

A PortFolio is an ERC20 token representing a pre-defined 'basket of goods' (a portfolio) of crypto assets. These assets are themselves other ERC20 tokens on the Ethereum blockchain.

What are the benefits of PortFolio?

  1. Easily buy and hold a diversified set of crypto assets.
  2. Redeem for the underlying assets at any time.
  3. Sell the underlying assets for the open-market Eth value at any time.
  4. Create custom PortFolios according to your risk preferences.

Development

Hardhat

We use the Hardhat framework to compile and test the contracts.

When you clone the repo, you will need to run npm install to get all of the smart contract, Hardhat and testing dependencies.

You will also need to create a .env file and replace the following variables with your own:

INFURA_API="https://rinkeby.infura.io/v3/<rinkeby_infura_api>"
KOVAN_API="https://kovan.infura.io/v3/<kovan_infura_api>"
WALLET_PK="<wallet_private_key>"

Testing:

  1. scripts/integration_test_portfolio_factory.js
    • Verifies that the portfolio factory is functioning as expected. Deploys two portfolio instances and verifies that these are working.
  2. scripts/integration_test_portfolio.js
    • Monitors the minting, and burning of the portfolio ERC20 token, and ensures that assets are bought, sold, and transferred correctly.
    • Tests key functionality of the portfolio contract, including:
      • Initial dployment
      • function: initialisePortfolio()
      • function: buy()
      • function: redeemAssets()
      • function: sellAssets()

Smart contracts

The contracts folder contains three smart contracts:

  1. Portfolio.sol - an ERC20 token representing a portfolio of crypto assets/

    • Allows users to buy into the portfolio
    • Swaps WETH to allocated proportions of portfolio assets
    • Stores all assets held by the portfolio (e.g., 50 LINK, 1000 DAI)
    • Allows users to redeem their share of assets directly
    • Alternatively: allows users to sell their assets and receieve ETH
  2. PortfolioFactory.sol - a contract used to create new Portfolios and track existing Portfolios

Test Portfolios

Kovan

We have deployed an example Portfolio on Kovan at the following address:

0x6CB8336581f0B99B225b14F3AfE7E2AC3f876C4F

This PortFolio is made up of the following assets:

Asset Holding (%)
Wrapped Ether 20
Dai Stablecoin 40
ChainLink Token 40

Rinkeby

We have deployed an example Portfolio on Kovan at the following address:

0x7157Ea1F87Cc4CbeE63137D3CB5ecBd44eE1960a

ERC20 : NAME = "Portfolio", TICKER = "FOLO"

It's super simple, containing only Weth.

Core Functionality

1. Creating a portfolio

Use the constructor of PortfolioFactory.sol to create a portfolio containing k tokens:

2. Buy into an existing portfolio

First, you need the contract (portfolio) address.

Send a transaction to the buy function, with Ether in msg.value.

3. Sell position in existing portfolio

First, you need the contract (portfolio) address.

Send a transaction to the sell function, and pass as argument the number of PortFolio tokens to sell.

The function will sell the appropriate share of the underlying assets and transfer the Ether to your address.

3. Redeem assets from existing portfolio

First, you need the contract (portfolio) address.

Send a transaction to the redeem function, and pass as argument the number of PortFolio tokens to sell.

The function will transfer the appropriate share of the underlying assets to your address.

Contributors

Luke Kirwan

Alex Straw

crypto-index-fund's People

Contributors

alex-straw avatar thelk22 avatar cameronmcewan avatar

Stargazers

 avatar  avatar AI/ML Engineer avatar Sathiya avatar  avatar Pavon Dunbar avatar

Watchers

 avatar

crypto-index-fund's Issues

initialisePortfolio() function results in error code 0

Hello there,

My name is Pavon Dunbar. I am writing to you guys because first, I really like your Crypto Index Fund smart contracts. I was able to successfully compile and deploy your contracts on the Ropsten testnet.

During contract interaction, I was able to use the Factory contract to create the portfolio as specified in your instructions with no issues. However, when I tried to access the initialisePortfolio() function, the result comes back with an error code 0.

I even tried to pass the new Portfolio address as a parameter but with no success.

How can I use the initialisePortfolio() function after I create the portfolio in the Factory contract?

I am using truffle to compile and deploy and truffle console to interact with the newly deployed contracts.

Thanks in advance.

Pavon

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.