Skip to content

naszam/maker-badges

Repository files navigation

#ubuntu 20.04.3 #node 16.13.1 built-with openzeppelin #solc 0.8.9 #testnet sokol #license AGPLv3

Lint Slither Tests Echidna

#ETHGlobal HackMoney

Maker Badges

Non-transferable Badges for Maker Ecosystem Activity

An incentive protocol to enhance activity on MakerDAO Ecosystem

Mentors

Demo
HackMoney

Sections

Building Blocks

Smart Contracts Flow-Chart

Dai GraphQL to check for activities on MakerDAO ecosystem

To enable MakerBadges to check off-chain for activities on MakerDAO ecosystem we're using the following MakerDAO DSS Contracts:

  • Pot: to check if a user has accrued 1 or more Dai from DSR.
  • Dai: to check if a user has sent 10 or 20 Dai.
  • Chief: to check if a user has voted in Executive Spells or Governance Polls.
  • Flip: to check if a user has bidden or won Collateral Auctions.
  • Cat: to check if a user have bitten an unsafe vault.

BadgeRoles Access Management for Default Admin, Admin, Templater and Pauser Role

BadgeRoles inherits the OpenZeppelin AccessControl.sol, allowing the owner of the contract to be set as Default Admin, Admin, Pauser and also as Templater, to add an Admin via addAdmin and remove an Admin via removeAdmin functions as well as to add a Templater via addTemplater and remove a Templater via removeTemplater functions.

MakerBadges to manage Templates and activate Non-transferable Badges for redeemers

To enable MakerBadges to verify redeemers checked off-chain for activities on MakerDAO ecosystem, when they try to redeem their Badge, we query the Dai GraphQL, and we generate a Merkle Tree of off-chain checked redeemers for each Badge Template.

In particular, we'll use:

  • verify to verify redeemers checked off-chain, using a proof (generated from the Merkle Tree for each redeemer).

MakerBadges let the admin to set (via setRootHashes) an array of root hashes, called roots, ordered by template Id to allow redemeers checked off-chain for activities via TheGraph on the frontend, and stored into a Merkle Tree, to redeem Badges.

A Merkle Tree is generated for every Badge Template and the root hash is then updated by the admin of MakerBadges on a weekly/monthly basis to allow batches of redeemers to redeem Badges.

MakerBadges inherits BadgeRoles, allowing a Templater to create a new template via createTemplate specifying name, description and image. A Templater can also update the template info via updateTemplate.

Getter functions are implemented to get template metadata via templates and the current number of templates via getTemplateCount.

It also inherits ERC721, where the _transfer has been overridden to implement the non-transferable feature, allowing redeemers checked off-chain to redeem a Badge for a specific activity on MakerDAO ecosystem via activateBadge that will verify if the caller is a redeemer and then will allow the caller to mint a new Non-transferable Maker Badge with tokenURI stored on IPFS (eg. "ipfs-hash.json").

templateQuantities getter function is implemented to get the number of badges activated for each template.

To avoid that a redeemer could activate the same Badge twice, the tokenId is generated via _getTokenId" that concatenates the redeemer address and the templateId to get a unique hard-coded identifier. The _mint function will check then if the tokenId already exists (= already minted) and if not mint a new Badge.

getBadgeRedeemer and getBadgeTemplate getter functions are implemented to get the redeemer address and templateId hard-coded inside the specified tokenId.

Finally setBaseURI is added to allow the default admin to set a new baseURI.

During deployment the contract sets the following ERC721 metadata:

Setup

Clone this GitHub repository.

Steps to compile and test

  • Local dependencies:
    • HardHat
    • TypeChain
    • OpenZeppelin Contracts
    • Ethers
    • Waffle
    • Solhint
    • Solcover
    • Prettier
    $ yarn install
  • Global dependencies:
    • Slither (optional):
    $ git clone https://github.com/crytic/slither.git && cd slither
    $ sudo python3 setup.py install
    • MythX CLI (optional):
    $ git clone git://github.com/dmuhs/mythx-cli && cd mythx-cli
    $ sudo python setup.py install

Running the project with local test network

  • Compile the smart contracts using HardHat with the following command:
    $ yarn build
  • Deploy the smart contracts locally with the following commands:
    $ yarn dev
    in a separate terminal:
    $ yarn deploy:local
  • Test the smart contracts using Waffle & Ethers with Fixtures:
    $ yarn test
  • Analyze the smart contracts using Slither with the following command (optional):
    $ slither .
  • Analyze the smart contracts using MythX CLI with the following command (optional):
    $ mythx analyze
  • Analyze the smart contracts using Echidna with the following command (optional):
    $ echidna-test . --contract BadgeRolesEchidnaTest --config echidna.config.yml

Deploy

Deploy on Sokol Testnet

  • Get an Ethereum Account on Metamask.

  • On the landing page, click “Get Chrome Extension.”

  • Add mnemonic to MNEMONIC .env file.

  • Add deployer address to DEPLOYER_ADDRESS .env file.

  • Add Sokol as custom RPC via Chainlist.

  • Get some test ether from a Sokol's faucet.

  • Uncomment the following lines in hardhat.config.ts:

    //if (!process.env.MNEMONIC) throw new Error('Please set your MNEMONIC in a .env file');
    //const mnemonic = process.env.MNEMONIC as string;
    
    //if (!process.env.DEPLOYER_ADDRESS) throw new Error("Please set your DEPLOYER_ADDRESS in a .env file")
    
  • Replace the following with mnemonic: mnemonic:

    mnemonic: "test test test test test test test test test test test junk"
    
  • Deploy MakerBadges on Sokol via the following command:

    $ yarn deploy:sokol
  • Flatten MakerBadges to verify on Blockscout:

    yarn flatten
    

Development Deployments

Sokol

MinimalForwarder 0xB27bC0B1eCa340a4579642E8ab3D76F6A5815303

MakerBadges: 0xD0d0d3A2E1c574D8eFb7c902C6Adf788F684d3B5

Interface

Backend

About

Inspiration & References

CDIPs

Authors

Project created by Nazzareno Massari and Scott Herren.
MakerDAOx and UI by Josi
A special thanks for support to Gonzalo Balabasquer.
Security Check by Scott Bigelow
MakerDAO Badge Illustrations by Richard Rosa