SoftDAO / contracts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SoftDAO Contracts

███████  ██████  ███████ ████████
██      ██    ██ ██         ██
███████ ██    ██ █████      ██
     ██ ██    ██ ██         ██
███████  ██████  ██         ██

Table of Contents

Developer Setup

Before you begin, you need to install the following tools and run the following commands:
Note: Feel free to skip this section if you don't plan on deploying, verifying or testing the contracts.
Note: XXXXXXXXXX needs to be replaced with your API key.

  • Node (v18) and yarn (v3)
  • Git
  • Foundry
  • Go to packages/hardhat and run:
    • Run npx hardhat vars set EVM_PRIVATE_KEY_1 XXXXXXXXXX
    • Run npx hardhat vars set EVM_PRIVATE_KEY_2 XXXXXXXXXX
    • Run npx hardhat vars set ALCHEMY_API_KEY XXXXXXXXXX
    • Run npx hardhat vars set ETHERSCAN_API_KEY XXXXXXXXXX

Note: Setting up multiple EVM_PRIVATE_KEY_ is optional, contracts and contract calls which require multiple addresses will require you to set up multiple like this.

Contracts

Key smart contracts are found in the packages/hardhat/contracts folder and cover several use cases:

  • claim: contracts to distribute tokens with lockup conditions like vesting (continuous, tranche-based, or price-based) and voting power
  • governance: contracts to create a DAO, governor, and timelock. Allowing DAO members to vote with tokens held in a vesting contract
  • sale: contracts to sell tokens to users, can include access restrictions, fair random queues, and multiple payment methods
  • utilities: contains other useful contracts (i.e. contract registry)

Related:

  • interfaces: are helpful when building third-party contracts relying on Soft DAO primitives
  • mocks: are stubbed out contracts for testing and development (not for use in production)
  • token: are commonly used token standards

These contracts are a WIP:

  • payment: contracts to receive arbitrary payments from users and track how much they have sent

Testing

Setup your repository and contracts for the tests:

yarn

Run Hardhat tests:
Note: This command also includes a compile command and may take some time to complete.

yarn test

Run Foundry tests:
Note: This will do some setup the first time you run it and may take some time to complete.

yarn forge-test

Deploying and Verifying

Deploying a contract (using Hardhat)

Here is a real example where you can deploy an ERC20. Feel free to go to ignition/modules/Deploy_GenericERC20.ts and modify it to meet your needs first.

npx hardhat ignition deploy ignition/modules/Deploy_GenericERC20.ts --network <your-network>

<your-network> can be localhost, sepolia, etc. You can customize network configurations in hardhat.config.ts.

For key storage we utilize the configuration variables (see Developer Setup for instructions). EVM_PRIVATE_KEY_1 will be the deployer of any contracts you end up deploying using the commands above. The deployer account will be used to execute any function calls that are part of your deployment script.

Verifying a contract (using Hardhat)

Simply add the --verify flag to the end of the deploy command.

npx hardhat ignition deploy ignition/modules/Deploy_GenericERC20.ts --network <your-network> --verify

Deploying FlatPriceSale and FlatPriceSaleFactory

npx hardhat ignition deploy ignition/modules/Deploy_FlatPriceSaleFactory.ts --network <your-network> --verify

Using Deployed Soft DAO Contracts

Launching a Sale

This uses the FlatPriceSaleFactory contract to create a new sale with the configuration you desire.

npx hardhat ignition deploy ignition/modules/Execute_NewSale.ts --network <your-network>

WIP: Reviewing the Registry

Use the registry contracts below to find other official Soft DAO contracts. The registry is used to mark specific addresses as authentic contracts supporting specific interfaces following the ERC-165 standard, and the easiest way to decode the Registry contracts is via a subgraph watching the registry, such as those deployed by Tokensoft.

Note: Lowercase contract addresses are used as subgraph entity IDs.

Subgraph Example

URL: https://thegraph.com/hosted-service/subgraph/tokensoft/sales-mainnet Query:

{
  registry(id: "0xc70573b924c92618e6143f6ac4c2b1ad7ba8785b") {
    addresses {
      id
      interfaceIds
      interfaceNames
    }
  }
}

Response:

{
  "data": {
    "registry": {
      "addresses": [
        {
          "id": "0xf266195e1b30b8f536834303c555bd6aaf063f04",
          "interfaceIds": [
            "0xab85ea0e",
            "0xfc57b782",
            "0x09e04257",
            "0x35ef410e"
          ],
          "interfaceNames": [
            "IDistributor",
            "IAdvancedDistributor",
            "IContinuousVesting",
            "IMerkleSet"
          ]
        }
      ]
    }
  }
}

This resonse means that the address 0xf266195e1b30b8f536834303c555bd6aaf063f04 is known to the Soft DAO as a Distributor and includes advanced features, a merkle root access list, and continuous vesting. See the two files below for more information on the interfaces.

./subgraph/abis/interfaces.json

This file includes the ERC-165 interface for each Solidity contract/interface as well as the source solidity file defining the interface.

Example results:

{
  "Registry": {
    "source": "contracts/utilities/Registry.sol",
    "id": "0xe711948a"
  },
  "FlatPriceSaleFactory": {
    "source": "contracts/sale/v2/FlatPriceSaleFactory.sol",
    "id": "0xfcb73502"
  },
  "FlatPriceSale": {
    "source": "contracts/sale/v2/FlatPriceSale.sol",
    "id": "0x7a6d298d"
  },
  "IERC20": {
    "source": "@openzeppelin/contracts/token/ERC20/IERC20.sol",
    "id": "0x36372b07"
  },
  "IVotes": {
    "source": "@openzeppelin/contracts/governance/utils/IVotes.sol",
    "id": "0xe90fb3f6"
  },
  ...
}

./subgraph/build/interfaces.ts

This file allows one to reference the interfaces when developing a subgraph.

import { TypedMap } from "@graphprotocol/graph-ts"

class knownInterfacesClass extends TypedMap<string, string>{
  constructor(){
	super()

	// map interface names to ids AND ids to names

    this.set("Sweepable", "0xac1d7eef")
    this.set("0xac1d7eef", "Sweepable")
    ...
  }

  // convenience getters to emulate an object in AssemblyScript
  get Sweepable(): string {
    let value = this.get("Sweepable")
    return value!.toString()
  }
  ...
}

export const knownInterfaces = new knownInterfacesClass

Example AssemblyScript mapping file exampleMapping.ts

import { knownInterfaces } from "../../generated/interfaces";

// do something based on interface ID
if (registeredAddress.interfaceIds.includes(knownInterfaces.IDistributor)) {
  log.info("Registered {} as a Distributor", [registeredAddress.id]);
  saveDistributor(distributor.id, block);
}

Deployed Smart Contracts

Base sepolia

Base mainnet

Avalanche

Avalanche Fuji

Ethereum Mainnet

Polygon

Polygon Amoy

Ethereum Goerli

Polygon Mumbai

Arbitrum Goerli

Celo Alfajores

Celo

Optimism

Arbitrum

Binance Smart Chain

WIP: Disabling type and linting error checks

Hint Typescript helps you catch errors at compile time, which can save time and improve code quality, but can be challenging for those who are new to the language or who are used to the more dynamic nature of JavaScript. Below are the steps to disable type & lint check at different levels

Disabling commit checks

We run pre-commit git hook which lints the staged files and don't let you commit if there is an linting error.

To disable this, go to .husky/pre-commit file and comment out yarn lint-staged --verbose

- yarn lint-staged --verbose
+ # yarn lint-staged --verbose

Deploying to Vercel without any checks

By default, Vercel runs types and lint checks before building your app. The deployment will fail if there are any types or lint errors.

To ignore these checks while deploying from the CLI, use:

yarn vercel:yolo

If your repo is connected to Vercel, you can set NEXT_PUBLIC_IGNORE_BUILD_ERROR to true in a environment variable.

Disabling Github Workflow

We have github workflow setup checkout .github/workflows/lint.yaml which runs types and lint error checks every time code is pushed to main branch or pull request is made to main branch

To disable it, delete .github directory

Using Soft DAO Source Code

The contracts are licensed under the MIT license. Use them however you like — we'd appreciate a note that your core primitives are based on the Soft DAO!

About

License:Other


Languages

Language:TypeScript 74.2%Language:Solidity 24.3%Language:JavaScript 1.4%Language:Shell 0.1%Language:CSS 0.0%