Giter Club home page Giter Club logo

contracts's Introduction

Icons made by Eucalyp from www.flaticon.com

HQ20 contracts

HQ20/contracts is a Solidity project with contracts, libraries and examples to help you build fully-featured distributed applications for the real world.

Disclaimer: The contracts are expected to be used as smart contract patterns for you to draw inspiration from, and for them to be easy to understand they have been kept deliberately simple. If you decide to reuse the contracts, or to copy and paste code in them, make sure that you look for and close the vulnerabilities. If you plan to go to the mainnet, please get a third party audit done.

In a Nutshell

At the time of this writing (May 2020), this are the contents of this repository:

contracts ──┬─── access        - Access Control Contracts, some of them built on top of `AccessControl.sol`
            ├─── classifieds   - Example of a decentralized classifieds market for ERC721
            ├─── dao           - Example of building a decentralized venture capital fund
            ├─── energy        - Example of building a decentralized market for energy distribution
            ├─── exchange      - The Uniswap decentralized market contracts, with solidity tests
            ├─── introspection - Example of using ERC165 to verify contract types before casting
            ├─── issuance      - Example of an ICO, can be used as well for share issuances
            ├─── lists         - Reusable implementations of different types of linked lists
            ├─── math          - Reusable implementation of a lightweight fixed point math library
            ├─── state         - Reusable implementation of a fully-featured state machine
            ├─── token         - Token implementations, including a reusable dividend-bearing ERC20
            ├─── utils         - Reusable library to cast between `uint` and `int`.
            └─── voting        - Example implementations of token-based and address-based votings

Installation

Use the package manager yarn to install dependencies.

$ yarn add @hq20/contracts

Usage

pragma solidity ^0.6.0;
import "@hq20/contracts/contracts/access/Roles.sol"


contract MyContract is Roles {
	constructor() public Roles(msg.sender) {
		// do something
	}
}

Directories

Contracts go in contracts, test files go in test.

Inside the contracts folder the files are organized by topic and by type.

At the root of contracts are directories for each one of the topics, containing the simplest implementations that are in a mature state.

For contracts that are under development there is a contracts/drafts directory with the appropriate topic folders inside.

For contracts that are used for testing of libraries or internal methods there is a contracts/test directory with the appropriate topic folders inside.

The test directory replicates the structure of the contracts directory.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

As well as bug fixes, we will welcome updates to the basic contracts that make them even easier to understand, examples of contracts implementing a particular feature, or advanced contracts that put together a number of features into a complete use case.

Please make sure to update tests as appropriate.

License

Apache-2.0

contracts's People

Contributors

alcueca avatar dependabot-preview[bot] avatar obernardovieira avatar uivlis 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

contracts's Issues

ERC1820 Example

The latest evolution of ERC165, in that it includes a global registry of contracts and the interfaces they implement. A bit mind-bending. Obviously needs an example.

Create classifieds market

Start by using a fixed price buy/sell market as for AB. Please write it from scratch instead of reusing their contract and name everything as for a craigslist classifieds board.

The mechanics are:

  1. The market works with a currency token, like Issuance.sol.
  2. Someone puts a buy or sell advert. There is no description or anything for the advert, just an address as a payload.
  3. The payload address conforms for an ERC721 contract interface.
  4. The buy part puts in escrow an amount of the currency token, for the sell part the ownership of the ERC721 payload is what is put in escrow.

Silence warnings for ClassifiedsAdvanced.sol

,/home/alberto/Code/hq20-contracts/contracts/drafts/classifieds/ClassifiedsAdvanced.sol:35:9: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
        address operator,
        ^--------------^

Create Whitelist contract inside access

Branch new/whitelist

This is a stripped down version of RBAC.sol, with just one Role.

An Ownable contract that keeps a mapping of address => bool

Methods:
isMember: returns mapping(address)
addMember: sets mapping(address) = true
removeMember: delete mapping(address)

There is no listing of members, that will be done in a separate issue and contract.

Release Classifieds.sol

  • Rename Classifieds.sol as ClassifiedsAdvanced.sol.

  • Rename ClassifiedsV2.sol as Classifieds.sol and get it out of drafts.

  • Increase test coverage of the Classifieds.sol outside drafts until tests pass (90%?)

ERC1404 Example

I think this is the earliest try for a security token. There are more recent ones. It would be nice to show we know how to implement things with them.

Example of RBAC.sol usage

This could be something like an ERC20 factory, where the ERC20s created get the RBAC.sol contract and user defined roles for minters and recipients.

It might need a bit of a frontend to make sense.

Voting and Staking

Consider how a voting library could be built for DAO.sol.

The idea is that there are several actions that can be voted. The actions are known at coding time (for example, investing in a new venture, distributing dividends and raising funds).

Voting is the same for all actions. There is a staking token and each token is one vote. Each token cannot be used for more than one voting simultaneously.

I would like the logic to be reused between voting actions, only changing the resulting action if the vote is successful.

We might have to mess with function signatures and things like that, no idea really.

Add method for Owner to withdraw contract funds

This is a method for the owner to retrieve the currency stored in the issuance contract. Please come up with a suitable name.

It should be possible only on "LIVE" state.

Please merge #26 first and make this issue a PR of its own.

ERC777 example

ERC777 is supposed to supersede ERC20. OpenZeppelin has an implementation. I would like to have an example of how to use it.

Comment out gas tests

Either comment out the gas tests for LinkedList and friends, or move them somewhere where they don't run with yarn test.

Link repo and soldoc

When opening the soldoc page there is no link to go to the repo. When opening the repo in github there is no link to go to the soldoc page.

Parallel tests?

Our tests are getting longer to run as the package grows. Would it be a good idea to parallelize them?

Escrow Example

OpenZeppelin has Escrow contracts, but I see no examples. I like examples. Maybe even a simple use case.

Use fixed point math in Issuance.sol

There is an issue with the current formula for token issuance, which is

amount(issuanceToken) = amount(currencyToken)/issuePrice

because you cannot set a subunitary issuePrice. It should be:

amount(issuanceToken) = amount(currencyToken).fixedDiv(issuePrice, 10**18)

or something similar using fixed point math. See ABDK or Fixidity.

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.