Coder Social home page Coder Social logo

blockchain-solana / contract Goto Github PK

View Code? Open in Web Editor NEW

This project forked from theloneronin/contract

0.0 0.0 0.0 350 KB

Community contract for SmartWeave.

Home Page: https://community.xyz

License: MIT License

JavaScript 0.38% TypeScript 99.62%

contract's Introduction

Community Contract Specs

Gitopia

Community is a frontend, library (in Javascript) and a SmartWeave contract, to create new communities completely decentralized.

These are the contract's specs.

Holders = Community token holders/participants.

The community state has the following default structure:

{
  name: string,
  ticker: string,
  balances: {
    [key: string]: number // Positive integer
  },
  vault: {
    [key: string]: [{
      balance: number, // Positive integer
      end: number, // At what block the lock ends.
      start: number // At what block the lock starts.
    }]
  },
  votes: VoteInterface[], 
  roles: {
      [key: string]: string
  },
  settings: [ // Array of a Map<string, any>
      ["quorum", number], // quorum is between 0.01 and 0.99
      ["support", number], // between 0.01-0.99, how much % yays for a proposal to be approved
      ["voteLength", number], // How many blocks to leave a proposal open
      ["lockMinLength", number], // Minimum lockLength allowed
      ["lockMaxLength", number] // Maximum lockLength allowed
  ]
}

Here's an example of what the state when creating the contract should look like:

{
  "name": "Community",
  "ticker": "COMM",
  "balances": {
    "BPr7vrFduuQqqVMu_tftxsScTKUq9ke0rx4q5C9ieQU": 10000000
  },
  "vault": {},
  "votes": [],
  "roles": {},
  "settings": [
      ["quorum", 0.5],
      ["voteLength", 2000],
      ["lockMinLength", 100],
      ["lockMaxLength", 10000]
  ]
}

VoteInterface is:

interface VoteInterface {
  status?: 'active' | 'quorumFailed' | 'passed' | 'failed';
  type?: 'mint' | 'mintLocked' | 'burnVault' | 'indicative' | 'set';
  id?: number;
  totalWeight?: number;
  recipient?: string;
  target?: string;
  qty?: number;
  key?: string;
  value?: any;
  note?: string;
  yays?: number;
  nays?: number;
  voted?: string[];
  start?: number;
  lockLength?: number;
}

Transfer

Holders are able to transfer them to someone else on Arweave, not only to other Community members but to anyone else.

Requires:

  • target: To whom the balance is going to be transfered.
  • qty: How many tokens to transfer.

Returns:

{ state }

TransferLocked

Holders are able to transfer tokens and lock them at the same time, to someone else on Arweave.

Requires:

  • target: To whom the balance is going to be transfered.
  • qty: How many tokens to transfer.
  • lockLength: How many blocks qty will be locked.

Returns:

{state}

Balance

Check the current total balance (unlocked and in vault) of an account.

Optional:

  • target: To whom check the balance. If not provided, caller is used.

Returns:

result: {
    target: address,
    balance: target's balance
}

UnlockedBalance

Check the current unlocked balance of an account.

Optional:

  • target: To whom check the balance. If not provided, caller is used.

Returns:

result: {
    target: address,
    balance: target's balance
}

Locking System

Lock

Lock a balance to increase it's vote weight on the Community. The voting weight is: lockedBalance * (end - start).

Requires:

  • qty: Balance amount to lock.
  • lockLength: How many blocks qty will be locked.

Returns:

{ state }

Unlock

Unlock all locked balances that are over the end set while locking.

Returns:

{ state }

IncreaseVault

Increase a locked balance lockedLength.

Requires:

  • id: The vault ID to be locked longer.
  • lockLength: How many more blocks this vault will be locked.

VaultBalance

Check the current locked balance of an account.

Optional:

  • target: To whom check the balance. If not provided, caller is used.

Returns:

result: {
    target: address,
    balance: target's total locked balance
}

Voting System

Propose

Holders are able to propose a new vote, this will create a new proposal.

Requires:

type: Vote type. One of the following:

  • Mint To mint tokens to an Arweave address. Requires:
    • recipient: Arweave address recipient
    • qty: Amount of tokens to mint
    • note: Proposal description
  • MintLocked To mint locked tokens to an Arweave address.
    • recipient: Arweave address recipient
    • qty: Amount of tokens to mint
    • note: Proposal description
    • lockLength: How many blocks qty will be locked.
  • BurnVault To burn a vault with it's tokens. Warning: This will completely remove all the tokens stored on the target's vault.
    • target: Arweave address target
  • Set To update the Community settings. Requires:
    • key: Setting key
    • value: Setting value
  • Indicative To send a general non-fixed proposal. A yes/no question. Requires:
    • note: Proposal description

Allowed keys for set are:

  • quorum
  • support
  • lockMinLength
  • lockMaxLength
  • role
    • role value must be: {target: address, role: 'name'}
  • Custom Key/Value pairs

Returns:

{ state }

Vote

Cast a vote on one of the proposals.

Requires:

  • id: Proposal ID.
  • cast: What vote are you casting 'yay' || 'nay'.

Returns:

{ state }

Finalize

After a vote is concluded, we should call finalize to make it in effect. It will update the vote status to passed, and execute if needed, or failed.

Requires:

  • id: Proposal ID.

Returns:

{ state }

contract's People

Contributors

cedriking avatar graemecode avatar jespern 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.