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 adjustments essentially require code, however essentially 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 summary of the steps we are going to take, with the tip aim of proposing a brand new cToken marketplace for the protocol:
- Take away legacy verification checks from the supply code for brand spanking new cTokens that will probably be added sooner or later.
- Take away exams for the legacy verification checks, so that every one exams succeed. Word that when including new code, the developer ought to write further unit exams to make sure optimum code protection.
- Create a pull request into the Compound Protocol GitHub repository, so the group can evaluate the code adjustments, and finally sync them (if accepted via governance).
- Deploy a model new cToken contract for an ERC-20 asset.
- Confirm the contract code on Etherscan.
- Create a Compound Governance Proposal so as to add the brand new asset to the protocol.
Stipulations
New to Ethereum growth? Attempt beginning a bit smaller with a extra fundamental information: Organising an Ethereum Improvement Atmosphere.
Compound Protocol adjustments are ideated and mentioned publicly on the Compound Neighborhood Discussion board. Earlier than persevering with, please learn the complete handbook within the discussion board for Contributing to the Compound Protocol.
We’ll have to 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 acquainted with the accessible 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 adjustments into the on-chain protocol.
First, we’ll fork the Compound Protocol supply code to our GitHub account. We’ll make adjustments 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 appropriate. This makes a private copy of the 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 appropriate.
Subsequent we’ll copy the repository to our native machine. We’ll open the terminal and navigate to our programming tasks folder. Kind “git clone” adopted by the ssh handle 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 little thing has been put in, we are able to open the supply code with a textual content editor and start making adjustments. The one contract file we are going to modify is /contracts/CToken.sol
. We’ll take away the next traces.
We are able to see within the definitions in /contracts/Comptroller.sol
that these strategies don’t make any adjustments or conditionally revert. We’ll deal with them as useless 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.
Exams
After saving the modified contract file, we’ll change the check code so it succeeds with the most recent adjustments. If we had been including new contract code, we’d add extra exams to make sure thorough code protection.
To run all the tasks exams, use this command on the command line:
yarn check
To run a person check file, attempt one thing like:
yarn check exams/Tokens/borrowAndRepayTest.js
When working all exams, we’ll see that 6 exams fail because of our contract code adjustments. These specific exams might be commented out or deleted. As soon as the check command yields 0 failed exams, we are able to proceed with our protocol change.
Pull Request
As soon as the exams cross, we are able to create a pull request. When a pull request is open, the group can publicly analyze the code adjustments to make sure integrity and that greatest practices are carried out. If the group approves the adjustments via governance with a passing proposal, the pull request will probably be merged into the grasp department.
Subsequent we’ll commit the contract and check code adjustments to the forked repository utilizing Git on the command line.
git add contracts/ exams/
git commit -m "ctoken adjustments"
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 appropriate. 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 adjustments 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 might be finished utilizing Saddle. The Compound Labs workforce created a command line device known as Saddle for Ethereum growth. 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 might 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 growth object throughout the networks object. The duplicate must 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 an alternative, we’ll substitute the complete second object with a localhost JSON RPC URL. The local_fork’s suppliers array ought to now appear to be 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 device within the major information).
In a separate terminal window, we’ll use the next command to make a neighborhood fork of the Kovan community blockchain. The mnemonic generates accounts which have been utilized in earlier developer guides. Word that there’s an setting 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 major inmate ugly amongst turn into"
Subsequent we’ll make a brand new community config file for local_fork. This may be finished 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 all the addresses would be the similar in our Ganache CLI community fork.
Subsequent we’ll deploy the contract utilizing Saddle. The brand new cToken will probably be Kyber Community Crystal. The underlying token handle might 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 handle of the brand new cToken contract.
Contract Deploy & Etherscan Code Verification
Now that we all know the deployment works within the native check setting, we are able to attempt it on the general public community.
Earlier than we try this, we’ll get an Etherscan API key so we are able to 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 are able to add it to our command line setting 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 internet, 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” firstly of the hexadecimal string.
Subsequent, we’ll run the identical deploy command that we ran earlier besides this time we are going to substitute local_fork with kovan. This variation will deploy the contract to Kovan, for actual. We’ll run the command. Remember to save the contract handle that’s logged.
Go to kovan.etherscan.io and seek for the newly created contract handle. Within the contract tab, we’ll see that there presently 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 handle.
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 might 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.
Word 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’s not but reported within the Open Value Feed, we would wish to create adjustments for that element too.
Proposal or Autonomous Proposal
There are a number of choices to go about making a Compound Governance Proposal. We’ll evaluate 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.
- Purchase a minimum of 100,000 COMP or the equal delegated voting weight and create a proposal utilizing app.compound.finance/suggest.
- 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 power, and ask them to create the proposal.
- Purchase a minimum of 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 a minimum of 100,000 votes.
Go to app.compound.finance/suggest. Fill within the proposal Title and Overview sections. Be as thorough as doable. Markdown is supported. Remember to embrace a hyperlink to the GitHub pull request created earlier. Assessment a related previous proposal and use it as a information to jot down the Overview. Add the next Actions within the specified order.
- Comptroller contract, _supportMarket perform, new cToken contract handle.
- Comptroller contract, _addCompMarkets perform, new cToken contract handle.
- Comptroller contract, _setCollateralFactor perform, new cToken contract handle and 600000000000000000 for 60% collateral issue.
- Different contract (new cToken contract handle 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 crammed in, click on the Submit Proposal button and submit the transaction utilizing MetaMask.
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 adjustments is a severe enterprise that requires the complete group’s consideration and scrutiny. Not all proposals cross. For extra concepts about find out how to submit profitable proposals, see the Contributing to the Compound Protocol handbook.
An important 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 you should definitely subscribe to the Compound Publication. Be at liberty to touch upon this put up, or get in contact with the workforce on the Compound Twitter.