Coder Social home page Coder Social logo

crytotech / apeswap-governance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apeswapfinance/apeswap-governance

0.0 0.0 0.0 4.59 MB

A collection of solidity smart contracts to help manage the ApeSwap DAO.

Shell 0.29% JavaScript 18.15% TypeScript 69.88% Solidity 11.68%

apeswap-governance's Introduction

ApeSwap Governance SDK

Useful SDK for encoding transactions sent to timelock contracts used in the ApeSwap protocol. These timelock contracts are Open Zeppelin's implementation which integrates very well with DAO governance mechanisms.

Install

Click "Use as Template" to create a repo on GitHub based on this repo. Otherwise:
git clone [email protected]:DeFiFoFum/truffle-typescript-template.git

yarn install

Setup

Create a .env file based off of .env.example to deploy contracts to bsc mainnet/testnet and to verify deployed contracts.


Package Install

This repo also provides a helper module for interacting with the ApeSwap Governance contracts with node via a front-end or back-end framework.

yarn add @ape.swap/governance-sdk
cd governance-sdk
yarn install

Usage

Provided below is an example of importing the and using the provided library to encode a batch timelock tx.

import { TimelockLib } from '@ape.swap/governance-sdk';
const timelockEncoder = new TimelockLib.TimelockEncoder();


async function encodeMessageTx(message: string, { address = ADDRESS_0 }): Promise<PopulatedTransaction> {
    const messageBoardContract = new Contract(address, MessageBoardBuild.abi) as MessageBoard;
    const populatedTx = await messageBoardContract.populateTransaction.addMessage(message);
    return populatedTx;
}

async function encodeBatchTimelockMessageTx(messages: string[], { timelockAddress = ADDRESS_0, messageBoardAddress = ADDRESS_0, predecessor = BYTES_32_0, salt = BYTES_32_0, delay = 20 }): Promise<BatchEncodeReturn> {
    const timelockEncoder = new TimelockEncoder(timelockAddress);

    const targets: string[] = [];
    const datas: string[] = [];
    const values: string[] = [];
    for (const message of messages) {
        const populatedTx = await encodeMessageTx(message, { address: messageBoardAddress });
        targets.push(populatedTx.to || '0x');
        datas.push(populatedTx.data || '0x');
        values.push('0');
    }

    return await timelockEncoder.encodeTxsForBatchOperation({ targets, values, datas, predecessor, salt }, delay);
};

Development

Start a local development blockchain by running the following command:
yarn ganache

Deploy contracts to the development blockchain:
yarn migrate:dev

Compile

yarn compile


Deploy

Mainnet

yarn migrate:bsc [--reset] // Use --reset to redeploy already deployed contracts
yarn verify:bsc

Testnet

yarn migrate:testnet [--reset]
yarn verify:testnet

* new contracts that are created must be added to the verification script in package.json by adding && to the end with the new contract verification.

Lint

Lint with solhint
yarn lint / yarn lint:fix


Test

Tests are run with @openzeppelin test environment. This allows tests to be run independently of an external development blockchain.

Test the project with yarn test

Tests are using
@openzeppelin/test-helpers
@openzeppelin/test-environment


Solidity Doc Gen

yarn gen:docs solidity-docgen can be used in this repo to scrape NatSpec comments into markdown files for easy document generation.

This module uses the solc package to generate the documents. If the compiler is changed, ensure that the correct solc version is installed: yarn add [email protected]


Solidity Coverage

solidity-coverage is used in this repo to provide an output of the test coverage after running tests.

Automated Tests

The OpenZeppelin test environment coupled with Github actions facilitates automated contract tests on pushes to GitHub!


Generate Types from Contracts

Use typechain to generate contract interfaces for UI integration.
yarn gen:types

Contract Size

Use the truffle-contract-size module to find the size of each contract in the contracts/ directory with:
yarn size

apeswap-governance's People

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.