Wednesday, December 6, 2023

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


A Walkthrough of Contributing to the Compound Protocol for Developers

The Compound Protocol is free and open monetary infrastructure operating 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 brief information, we’ll stroll by way of 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 objective of proposing a brand new cToken marketplace for the protocol:

  1. Take away checks for the legacy verification checks, so that every one checks succeed. Notice that when including new code, the developer ought to write extra unit checks to make sure optimum code protection.
  2. Create a pull request into the Compound Protocol GitHub repository, so the group can assessment the code modifications, and ultimately sync them (if accredited by way of governance).
  3. Deploy a model new cToken contract for an ERC-20 asset.
  4. Confirm the contract code on Etherscan.
  5. Create a Compound Governance Proposal so as to add the brand new asset to the protocol.

Conditions

New to Ethereum improvement? Strive beginning a bit smaller with a extra fundamental information: Organising an Ethereum Growth Atmosphere.

Compound Protocol modifications are ideated and mentioned publicly on the Compound Neighborhood Discussion board. Earlier than persevering with, please learn the total guide 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 out to be aware of the accessible instruments and the event course of.

Study 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 begin, we’ll go to the GitHub repository and click on the fork button on the best. 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 at last the ‘copy to clipboard’ button on the best.

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 tasks folder. Sort “git clone” adopted by the ssh tackle 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 all the things 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 strains.

We are able to 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 useless code that must be eliminated. The present cToken contracts name them, so we gained’t take away them from the Comptroller right now.

Assessments

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

To run the entire tasks checks, use this command on the command line:

yarn check

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

yarn check checks/Tokens/borrowAndRepayTest.js

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

Pull Request

As soon as the checks cross, 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 carried out. If the group approves the modifications by way of 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/ checks/
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 best. 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 good contracts. When including a brand new asset to the protocol, deploying a brand new cToken contract is required.

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

Native Atmosphere 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 may be acquired without spending a dime 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 complete 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 main 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 have been utilized in earlier developer guides. Notice that there’s an surroundings variable (infuraProjectId) that comprises the Infura undertaking ID.

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

Subsequent we’ll make a brand new community config file for local_fork. This may be accomplished 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 similar 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 tackle may 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",
"identify": "Compound Kyber Community Crystal",
"image": "cKNC",
"decimals": "8",
"admin": "$Timelock"
}'

On success, Saddle will log the tackle 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 strive it on the general public community.

Earlier than we do 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 now have an account, we’ll create an API key by clicking the profile dropdown, API Keys, and the “Add” button on the prime of the web page.

Now that we now have 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 non-public 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 non-public key with contact ~/.ethereum/kovan.

We’ll paste a Kovan non-public key on this file with out the “0x” at first 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 modification will deploy the contract to Kovan, for actual. We’ll run the command. Make sure you save the contract tackle that’s logged.

Go to kovan.etherscan.io and seek for the newly created contract tackle. 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 tackle.

npx saddle -n kovan script token:confirm 0x9aF1962Dadf179e2aAa66F994ef09c65360b958e '{
"underlying": "0xad67cB4d63C9da94AcA37fDF2761AaDF780ff4a2",
"comptroller": "$Comptroller",
"interestRateModel": "$Base200bps_Slope3000bps",
"initialExchangeRateMantissa": "2.0e18",
"identify": "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 similar course of may be adopted to deploy a contract to the Ethereum Mainnet.

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

Notice that the brand new cToken on this information is already supported by the on-chain Open Worth Feed. If we had been proposing a brand new asset that’s not but reported within the Open Worth Feed, we would wish 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 assessment 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. Focus on concepts for change with the better 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 flexibility, and ask them to create the proposal.
  2. Purchase at the very least 100 COMP and create a Compound Autonomous Proposal.

Let’s stroll by way of utilizing the app interface to spotlight the mandatory “calldatas” for a brand new cToken proposal. Once more, that is just for customers that management at the very least 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. Make sure you embrace a hyperlink to the GitHub pull request created earlier. Evaluation a comparable previous proposal and use it as a information to write down the Overview. Add the next Actions within the specified order.

  1. Comptroller contract, _addCompMarkets perform, new cToken contract tackle.
  2. Comptroller contract, _setCollateralFactor perform, new cToken contract tackle and 600000000000000000 for 60% collateral issue.
  3. Different contract (new cToken contract tackle 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, allows 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 crammed 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, take a look at the Compound Governance information – How To Suggest.

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

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

Thanks for studying and be sure you subscribe to the Compound E-newsletter. Be at liberty to touch upon this put up, or get in contact with the staff on the Compound Twitter.



Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles