A Walkthrough of Contributing to the Compound Protocol | by Adam Bavosa | Compound Labs

A Walkthrough of Contributing to the Compound Protocol for Developers

The Compound Protocol is free and open monetary infrastructure working on the Ethereum blockchain. Anybody with a future imaginative and prescient of the protocol can suggest an enchancment by writing code.

Not all protocol modifications essentially require code, however probably the most concerned ones do. On this quick information, we’ll stroll via altering the supply code and proposing a proper change with Compound Governance.

Right here is an outline of the steps we’ll take, with the tip purpose of proposing a brand new cToken marketplace for the protocol:

  1. Take away legacy verification checks from the supply code for brand new cTokens that might be added sooner or later.
  2. Take away assessments for the legacy verification checks, so that every one assessments succeed. Observe that when including new code, the developer ought to write further unit assessments to make sure optimum code protection.
  3. Create a pull request into the Compound Protocol GitHub repository, so the group can evaluation the code modifications, and ultimately sync them (if authorised via governance).
  4. Deploy a model new cToken contract for an ERC-20 asset.
  5. Confirm the contract code on Etherscan.
  6. Create a Compound Governance Proposal so as to add the brand new asset to the protocol.

Stipulations

New to Ethereum improvement? Attempt beginning a bit smaller with a extra fundamental information: Establishing an Ethereum Growth Surroundings.

Compound Protocol modifications are ideated and mentioned publicly on the Compound Neighborhood Discussion board. Earlier than persevering with, please learn the total handbook within the discussion board for Contributing to the Compound Protocol.

We’ll must create a GitHub account, and set up git. We’ll use these instruments to publicly merge new code into the open supply repository.

Skim the repository readme to turn into conversant in the out there instruments and the event course of.

Be taught what Compound Governance is by studying the associated weblog posts on the Compound Weblog. The governance course of is required for incorporating new code modifications into the on-chain protocol.

First, we’ll fork the Compound Protocol supply code to our GitHub account. We’ll make modifications on the forked repository and create a pull request into the unique repository.

Code

To start out, we’ll go to the GitHub repository and click on the fork button on the fitting. This makes a private copy of the repository.

Forking a GitHub code repository

Subsequent we’ll go to the forked repository web page in our account’s repositories. We’ll click on the inexperienced code button, then the SSH tab, and eventually the ‘copy to clipboard’ button on the fitting.

Cloning a GitHub code repository

Subsequent we’ll copy the repository to our native machine. We’ll open the terminal and navigate to our programming initiatives folder. Sort “git clone” adopted by the ssh deal with of the forked repository.

git clone git@github.com:ajb413/compound-protocol.git

Subsequent, we’ll navigate into the repository and set up dependencies. Now is an efficient time to put in Node.js (LTS) and Yarn.

cd compound-protocol/
yarn set up

After every part has been put in, we will open the supply code with a textual content editor and start making modifications. The one contract file we’ll modify is /contracts/CToken.sol. We’ll take away the next traces.

We will see within the definitions in /contracts/Comptroller.sol that these strategies don’t make any modifications or conditionally revert. We’ll deal with them as lifeless code that must be eliminated. The present cToken contracts name them, so we received’t take away them from the Comptroller in the present day.

Assessments

After saving the modified contract file, we’ll change the check code so it succeeds with the latest modifications. If we had been including new contract code, we might add extra assessments to make sure thorough code protection.

To run the entire initiatives assessments, use this command on the command line:

yarn check

To run a person check file, attempt one thing like:

yarn check assessments/Tokens/borrowAndRepayTest.js

When working all assessments, we’ll see that 6 assessments fail because of our contract code modifications. These explicit assessments will be commented out or deleted. As soon as the check command yields 0 failed assessments, we will proceed with our protocol change.

Pull Request

As soon as the assessments go, we will create a pull request. When a pull request is open, the group can publicly analyze the code modifications to make sure integrity and that greatest practices are applied. If the group approves the modifications via governance with a passing proposal, the pull request might be merged into the grasp department.

Subsequent we’ll commit the contract and check code modifications to the forked repository utilizing Git on the command line.

git add contracts/ assessments/
git commit -m "ctoken modifications"
git push origin grasp

We’ll return to the forked repository web page on GitHub and refresh it. There ought to now be a pull request button above the file explorer on the fitting. We’ll click on it to see the merge comparability web page.

Subsequent we’ll click on the inexperienced “Create pull request” button to open the general public pull request.

Some, however not all protocol modifications require deploying of latest sensible contracts. When including a brand new asset to the protocol, deploying a brand new cToken contract is required.

Deploying a cToken contract will be completed utilizing Saddle. The Compound Labs staff created a command line instrument referred to as Saddle for Ethereum improvement. It’s already included within the dependencies of the protocol repository.

Native Surroundings Contract Deploy

Earlier than we deploy to a public Ethereum community, we’ll first attempt to deploy the contract on a localhost fork. We’ll want a JSON RPC supplier URL for this. One will be acquired at no cost from Infura or an analogous service.

We’ll return to our textual content editor and open saddle.config.js within the undertaking root folder. We’ll duplicate the improvement object inside the networks object. The duplicate needs to be named one thing like local_fork.

Within the suppliers array of local_fork, we’ll take away the second object that begins with ganache. As a substitute, we’ll substitute your entire second object with a localhost JSON RPC URL. The local_fork’s suppliers array ought to now seem like the next:

suppliers: [
{env: "PROVIDER"},
{http: "http://127.0.0.1:8545"}
],

Now is an efficient time to globally set up Ganache CLI (extra on this instrument within the major information).

In a separate terminal window, we’ll use the next command to make an area fork of the Kovan community blockchain. The mnemonic generates accounts which were utilized in earlier developer guides. Observe that there’s an surroundings variable (infuraProjectId) that accommodates the Infura undertaking ID.

ganache-cli 
-f https://kovan.infura.io/v3/$infuraProjectId
-m "clutch captain shoe salt awake harvest setup major inmate ugly amongst turn into"

Subsequent we’ll make a brand new community config file for local_fork. This may be completed by copying the Kovan configuration and naming it local_fork.json. From the foundation listing of the undertaking, run the next command.

cp networks/kovan.json networks/local_fork.json

We copied Kovan as a result of the entire addresses would be the identical in our Ganache CLI community fork.

Subsequent we’ll deploy the contract utilizing Saddle. The brand new cToken might be Kyber Community Crystal. The underlying token deal with will be discovered within the Kyber documentation.

In a terminal window that’s navigated to the undertaking listing, we’ll use the next command to deploy the cToken to the native fork.

npx saddle -n local_fork script token:deploy '{
"underlying": "0xad67cB4d63C9da94AcA37fDF2761AaDF780ff4a2",
"comptroller": "$Comptroller",
"interestRateModel": "$Base200bps_Slope3000bps",
"initialExchangeRateMantissa": "2.0e18",
"title": "Compound Kyber Community Crystal",
"image": "cKNC",
"decimals": "8",
"admin": "$Timelock"
}'

On success, Saddle will log the deal with of the brand new cToken contract.

Contract Deploy & Etherscan Code Verification

Now that we all know the deployment works within the native check surroundings, we will attempt it on the general public community.

Earlier than we try this, we’ll get an Etherscan API key so we will publicly confirm the supply code. We’ll join a free account at etherscan.io. As soon as we have now an account, we’ll create an API key by clicking the profile dropdown, API Keys, and the “Add” button on the high of the web page.

Now that we have now an API key, we will add it to our command line surroundings variables. On a Mac, that is in ~/.bash_profile or ~/.zshrc. We’ll add the important thing on a brand new line with export ETHERSCAN_API_KEY="JI4D..." and restart the terminal window.

Subsequent we’ll add a personal key for the Kovan check web, so Saddle will know who’s deploying the brand new contract. We’ll create a brand new listing utilizing mkdir ~/.ethereum/ after which a brand new file to include the personal key with contact ~/.ethereum/kovan.

We’ll paste a Kovan personal key on this file with out the “0x” at the start of the hexadecimal string.

Subsequent, we’ll run the identical deploy command that we ran earlier besides this time we’ll substitute local_fork with kovan. This transformation will deploy the contract to Kovan, for actual. We’ll run the command. Remember to save the contract deal with that’s logged.

Go to kovan.etherscan.io and seek for the newly created contract deal with. Within the contract tab, we’ll see that there at the moment isn’t any verified supply code.

Subsequent, we’ll return to the command line, and run a command to confirm the supply code with Etherscan. We’ll substitute 0x9aF1962Dadf179e2aAa66F994ef09c65360b958e with our newly created contract deal with.

npx saddle -n kovan script token:confirm 0x9aF1962Dadf179e2aAa66F994ef09c65360b958e '{
"underlying": "0xad67cB4d63C9da94AcA37fDF2761AaDF780ff4a2",
"comptroller": "$Comptroller",
"interestRateModel": "$Base200bps_Slope3000bps",
"initialExchangeRateMantissa": "2.0e18",
"title": "Compound Kyber Community Crystal",
"image": "cKNC",
"decimals": "8",
"admin": "$Timelock"
}'

As soon as the verification completes, we’ll see that the contract code is now explorable on the contract Etherscan web page.

This identical course of will be adopted to deploy a contract to the Ethereum Mainnet.

The ultimate main step of fixing the Compound Protocol is to create a Governance proposal that the group collectively agrees to go.

Observe that the brand new cToken on this information is already supported by the on-chain Open Value Feed. If we had been proposing a brand new asset that isn’t but reported within the Open Value Feed, we would want to create modifications for that element too.

Proposal or Autonomous Proposal

There are a number of choices to go about making a Compound Governance Proposal. We’ll evaluation them right here. In the event that they don’t make sense, take a while to learn up on Governance on the Compound Weblog and on the comp.xyz discussion board.

  1. Purchase no less than 100,000 COMP or the equal delegated voting weight and create a proposal utilizing app.compound.finance/suggest.
  2. Focus on concepts for change with the higher Compound group on the discussion board or within the #governance channel of the Compound Discord. Discover a person that agrees with the change, has the power, and ask them to create the proposal.
  3. Purchase no less than 100 COMP and create a Compound Autonomous Proposal.

Let’s stroll via utilizing the app interface to focus on the mandatory “calldatas” for a brand new cToken proposal. Once more, that is just for customers that management no less than 100,000 votes.

Go to app.compound.finance/suggest. Fill within the proposal Title and Overview sections. Be as thorough as potential. Markdown is supported. Remember to embody a hyperlink to the GitHub pull request created earlier. Evaluate a related previous proposal and use it as a information to put in writing the Overview. Add the next Actions within the specified order.

  1. Comptroller contract, _supportMarket operate, new cToken contract deal with.
  2. Comptroller contract, _addCompMarkets operate, new cToken contract deal with.
  3. Comptroller contract, _setCollateralFactor operate, new cToken contract deal with and 600000000000000000 for 60% collateral issue.
  4. Different contract (new cToken contract deal with and ABI from the Etherscan web page, code tab, towards the underside), _setReserveFactor, 200000000000000000 for 20% reserve issue.

This proposal provides the brand new cToken to the official Comptroller, permits it as a market that participates in COMP Distribution, units the collateral issue to 60%, and units the reserve issue to twenty%. As soon as the Actions are stuffed in, click on the Submit Proposal button and submit the transaction utilizing MetaMask.

Creating a Compound Governance Proposal

For a extra detailed walkthrough of making a proposal, try the Compound Governance information – How To Suggest.

Compound is a residing, on-chain protocol, not only a repository of code that may be pulled and run. Proposing modifications is a critical enterprise that requires your entire group’s consideration and scrutiny. Not all proposals go. For extra concepts about learn how to submit profitable proposals, see the Contributing to the Compound Protocol handbook.

Crucial a part of creating Compound Protocol enhancements is collaborating in open discourse. Please be a part of the dialogue within the Compound Neighborhood Discussion board and within the #governance channel of the Compound Discord.

Thanks for studying and you’ll want to subscribe to the Compound E-newsletter. Be happy to touch upon this submit, or get in contact with the staff on the Compound Twitter.


Leave a Reply

Your email address will not be published. Required fields are marked *