Giter VIP home page Giter VIP logo

submoloch's Introduction

SubMoloch

The Polkadot version of MolochDao. Developed for the purpose of learning, please use it at your own risk

Setup

Installing Node.js

We require node >=12.0, if not, you can go to the nodejs website and find out how to install or upgrade. Or we recommend that you install Node using nvm. Windows users can use nvm-windows instead.

Substrate Prerequisites

Follow the official installation steps from the Substrate Developer Hub Knowledge Base.

rustup component add rust-src --toolchain nightly
rustup target add wasm32-unknown-unknown --toolchain nightly

Installing The Patract Node

We use Patract Node as our contract test chain. It has some very convenient optimizations for contracts, such as reducing out-of-block time. To install Patract Node:

$ cargo install patract-prep --git https://github.com/patractlabs/patract --locked --force

Run a local node

patract-prep --dev --execution=Native --tmp

Compile

npx redspot compile

Test

npx redspot test --no-compile

Deploy

npx redspot run scripts/submoloch.deploy.ts --no-compile

submoloch's People

Contributors

hychen avatar

Watchers

 avatar  avatar

submoloch's Issues

test: constructor

  • verify deployment parameters.
  • require fail - summoner can not be zero address.
  • require fail - period duration can not be zero.
  • require fail - voting period can not be zero.
  • require fail - voting period exceeds limit.
  • require fail - grace period exceeds limit.
  • require fail - dilution bound can not be zero.
  • require fail - dilution bound exceeds limit.
  • require fail - need at least one approved token.
  • require fail - too many tokens.
  • require fail - deposit cannot be smaller than processing reward.
  • require fail - approved token cannot be zero.
  • require fail - duplicate approved token.

test: submit_proposal

  • happy case.
  • require fail - insufficient tribute tokens.
  • require fail - tribute token is not whitelisted.
  • require fail - payment token is not whitelisted.
  • require fail - applicant can not be zero.
  • require fail - applicant address can not be reserved.
  • failure - too many shares requested.
  • failure - too many shares (just loot) requested.
  • failure - too many shares (& loot) requested.
  • happy case - second submitted proposal returns incremented proposalId.

test: submit_vote

  • happy case - yes vote.
  • happy case - no vote.
  • require fail - proposal does not exist.
  • require fail - vote must be less than 3.
  • require fail - voting period has not started.
  • voting period boundary.
    • require fail - voting period has expired.
    • success - vote 1 period before voting period expires.
  • require fail - member has already voted.
  • require fail - vote must be yes or no.
  • modifier - delegate.
  • submitVote modifying member.highestIndexYesVote.
    • require fail - voting period not starting yet.
    • happy case - yes vote, highestIndexYesVote is updated.
    • happy case - no vote, highestIndexYesVote not updated.

Reduce the contract size : split submoloch contract to smaller contracts.

The size of submoloch is exceeded the limitation.

Possible Solutions

1 split submoloch to three small contracts,

  1. guild :: to manage memberships;
  2. grant :: to process proposals.
  3. pool :: to transfer the funds

2 shrinking wasm size

  1. Experiment wasm-opt optimization options suggested in (paritytech/cargo-contract#110)
  2. Experiment methodologies suggested in https://github.com/johnthagen/min-sized-rust

3 Remove erc20 contract from submoloch build dependency. Use erc20-trait instead.

4 Convert error strings to custom Error types.

Leave client side decide which error strings should be printed.

5. Use types that take smaller spaces. (e.x.: u128 -> u8)

test: submit_whitelist_proposal

  • happy case.
  • require fail - applicant can not be zero.
  • require fail - cannot add already have whitelisted the token.
  • happy case - second submitted proposal returns incremented proposalId.

test: cancel_proposal

  • happy case.
  • failure - already sponsored.
  • failure - already cancelled.
  • failure - solely the proposer can cancel.

test: process_proposal

  • happy path - pass - yes win.
  • happy path - fail - no wins (proposer gets funds back).
  • happy path - shares added to existing member.
  • happy path - applicant is used as a delegate key so delegate key is reset.
  • happy path - auto-fail if shares exceed limit.
  • happy path - auto-fail if loot & shares exceed limit.
  • happy path - token whitelist.
  • happy path - guild kick member.
  • edge case - paymentRequested more than funds in the bank.
  • edge case - dilution bound is exceeded.
  • require fail - proposal does not exist.
  • require fail - proposal is not ready to be processed.
  • require fail - proposal has already been processed.
  • require fail - previous proposal must be processed.
  • require fail - must be a whitelist proposal.
  • require fail - must be a guild kick proposal.
  • require fail - must be a standard process not a whitelist proposal.
  • require fail - must be a standard process not a guild kick proposal.

test: update_delegate_key

  • happy case.
  • failure - can not be zero address.
  • failure - cant overwrite existing members.
  • failure - cant overwrite existing delegate keys.

test: ragequit + withdrawbalance

  • full ragequit -
    • happy path
  • partial shares
    • happy path
  • require fail -
    • not a member.
    • requesting more shares than you own.
    • requesting more loot than you own.
    • when a proposal is in flight
      • unable to quit when proposal in flight.
  • withdraw balance
    • withdraw full balance (applicant, sponsor, processor.
    • withdraw some balance (applicant.
    • withdraw 0 balance (applicant).
    • require fail - insufficient balance.

test: as a member with solely loot and no shares...

  • can still ragequit (justMember modifier.
  • can still partial ragequit (justMember modifier.
  • unable to update delegateKey (justShareholder modifier).
  • unable to use delegate key to sponsor (justShareholder modifier).
  • unable to use delegate key to vote (justDelegate modifier)'.

test: sponsor_proposal

  • happy path - sponsor add token to whitelist.
  • with a second member besides the summoner.
  • happy path - sponsor proposal.
  • failure - proposal has already been sponsored.
  • failure - proposal has been cancelled.
  • failure - sponsor whitelist token proposal already proposed.
  • require fail - insufficient deposit token.
  • require fail - sponsor non-existant proposal fails.

Implement error handling helper crate

The following is the quick note of my roughly idea, gonna be changed later.

#+begin_src rust
#[ink_error::ink_error_definition]
pub enum SubmitProposalError {
/// too many tribute tokens
TooManyTributeTokensError
}
#+end_src

will derive to

#+begin_src rust
#[derive(displaydoc::Display, Debug, scale::Encode, scale::Decode)]
pub enum Error {
/// too many tribute tokens
ProposalNotFound,
TransferFail(erc20::Erc20::error)
}
#+end_src

#+begin_src rust

fn sponsor_proposal(&mut self, args: bool) -> Result<(), Error> {
// exit early if input args are not good,
ink_error::ensure!(true, Error::ProposalNotFound);

// panic to revert the state on chain.
ink_error::assert!(true, Error::TransferFail(erc20::Erc20::error:InsuffienceBalances));

// real business logic

Ok(());

}
#+end_src

test: submit_guildkick_proposal

  • happy case.
  • require fail - member must have at least one share.
  • happy case - second submitted proposal returns incremented proposalId.

test: jail effects

  • cant process proposals for a jailed applicant.
  • cant sponsor proposals for a jailed applicant.
  • cant sponsor proposals for a jailed applicant.
  • cant sponsor guild kick proposals for a jailed applicant.
  • cant submit proposals for a jailed applicant.
  • cant submit guild kick proposals for a jailed applicant.

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.