OpenFi => DeFi in 10 min with Aragon Agent

Burrrata
The Eagle’s Nest 🦅
7 min readFeb 28, 2020

Why do we build dApps and protocols in the first place? Because we want trustless collaboration across borders, censorship resistance, and all the other blockchain things. For simple contracts that will never need upgrading this is easy. You deploy your code to mainnet and there it lives, autonomously, forever. However, if your contracts require upgradeability or parameter adjustments, you run into the problem of governance.

Aragon is a modular platform focused on optimizing governance of decentralized organizations. Aragon does a lot of things, but the goal of this article is to demonstrate how you can go from owner == msg.sender to Aragon DAO in less than 30 min.

The way we’re going to do this is via Aragon Agent. Agent is an Aragon app that allows a DAO to interact with any Ethereum dapp just like a regular account does. This means with Aragon and Agent, you get upgradable governance of your dapp or protocol without changing one line of your code. Keep reading to see how this works.

Gameplan

  1. Deploy a protocol with a single owner
  2. Deploy a DAO
  3. Transfer ownership of the protocol to the DAO
  4. Use the DAO to change the parameters of the protocol

Our Smart contract

pragma solidity ^0.5.16;contract AwesomeProtocolProxy {

address public owner;
address public code;
address public revenue;
uint256 public fee;

constructor () public {
owner = msg.sender;
fee = 1;
revenue = msg.sender;
code = 0xBe19dBee25F447133d0FA3cA05b88D8Ff2a9CB8f;
}
//////////////////////////////////////////
// Awesome Protocol Code Goes Here !! //
//////////////////////////////////////////
// ------------------------ Admin Functions ------------------------------------- /**
* @notice Transfers ownership of the contract to a new account.
*/
function transferOwnership(address newOwner) external onlyOwner {
owner = newOwner;
}
/**
* @notice Sets the Fee for Protocol
*/
function setProtocolFee(uint256 _fee) external onlyOwner {
fee = _fee;
}

/*
* @notice Sets the Fee for Protocol
*/
function setRevenue(address _revenue) external onlyOwner {
revenue = _revenue;
}
/**
* @notice Update the Protocol logic contract codeowner to `newCode`
*/
function updateCode(address newCode) external onlyOwner {
code = newCode;
}
modifier onlyOwner() {
require (owner == msg.sender, "NOT_OWNER");
_;
}
}

This is the proxy for our awesome DeFi protocol. Notice that the deploying account will be set as the owner and our protocol needs an admin to adjust three state variables:

  • fee: the fee our protocol charges
  • revenue: the address that collects fees
  • code: the implementation of our protocol

Lets deploy this contract to Rinkeby:

  • Go to https://remix.ethereum.org
  • Create a new file called AwesomeProtocolProxy.sol
  • Copy & paste contract
  • Unlock your frame account
  • Switch to injected web3
  • Deploy contract

You’ll notice that we have unilateral power to change the fee, address, and functionality of the protocol. This is a centralised protocol running on decentralised architecture. We can do better.

Our Aragon DAO

Aragon DAOs are incredibly flexible. All the core functionalities of a DAO (token management, Finances, etc) are modular smart contracts called apps. Apps have permission to perform specific actions on other apps.

Templates are pre-configured patterns for different types of organisational types. In part 2 of this series we will install a new app into our DAO and introduce a new tool, aragonCLI.

But for the purposes of this exercise, we will stick with the membership template.

Select Membership Template

A “Membership” organization that uses a non-transferable token to represent membership in the DAO. Decisions are made via “one-member-one-vote”. This fits well for our current stage of the project where we have three core devs and a relatively small community.

Claim An ENS Domain

Aragon uses the Ethereum Name Service (ENS) to assign names to organizations. Choose your DAO name wisely. Once chosen, The organization’s ENS name cannot be changed.

Set Voting Parameters

“Support” is the percentage of votes on a proposal that the total “Yes” votes must be greater than for the proposal to be passed. This voting app will have the authority to sign transactions on behalf of agent, and agent owns our protocol, so for this example we want decisions to be unanimous.

“Minimum Approval %” is the percentage of the total token supply that support for a proposal must be greater than for the proposal to be considered valid. we will set this to one third, since every member has an effective veto.

“Vote Duration” is the length of time that the vote will be open for participation. we will leave this as the default.

Create Token

Choose a token name, Ticker and bootstrap the DAO with its founding members. Note: Do not add more than a few tokenholders to your organization on this screen or the transaction to create your organization may fail; you can add more tokenholders after the organization has been created.

Review

Success! 🎉

Guided tour of our DAO

Now that we’ve created a DAO, let’s explore the apps and features that we’re going to use in this tutorial.

Tokens

The Tokens app allows you to mint new tokens and assign them to yourself or other entities. Tokens minted by the Tokens app confer voting abilities to holders of the tokens such that one token equals one vote. Tokens in a Membership organization are non-transferable, and each tokenholder can only hold a maximum of one token minted by the organization at a time

Voting

Taking actions in an Aragon Membership DAO requires approval by members. This is made possible via the Voting app. Any time an action is taken, it is sent through the Voting app before it can be executed. For example, assigning tokens and signing transactions with Agent requires a vote by members (token holders) of the DAO.

Organisation

Before we go back to our smart contract, we need to get the address of our DAO’s Agent. Every component of an Aragon DAO is it’s own contract. All the info for all the components your DAO uses can be found in the SYSTEM/Organization page. All you need to do here is click on the Agent address and then copy it.

Transferring Ownership

Back in remix, we are going to transfer ownership to our DAOs Agent. Here’s how:

  • on the DEPLOY & RUN TRANSACTIONS tab and open the deployed instance of our contract
  • open the drop down for the changeOwner function, paste the Agents address, send transaction
  • call getter for owner check it is set to agent
  • Success🎉

Our DeFi protocol is now owned by our DAO. Only our DAOs Agent can call the three admin functions. Any of the three token holders can open a vote for Agent to call the functions, and thats what we are going to do next

Interacting with Agent

Let’s explore how to use Agent with the Aragon Client console:

  • In the Aragon client, click on the gear icon in the top right of the page
  • Select ‘Help & Feedback’
  • Enable the console toggle
  • Open the console

Change parameters

The console exposes two aragonCLI commands:

  • Exec: enables you to directly call a function in a Aragon app
  • Act: enables you to call functions on other smartcontracts using Agent

We are only going to use Act. Currently, the DAO is the owner of our protocol, however, the address where the revenue is still sent to the previous account. We want to call the setRevenue() and change the address to Agent.

the syntax of the act command is

act/agentProxyAddress/targetAddress/methodName(type: arg)

agentProxyAddress : is the Address of our agent

targetAddress : is the address of the smartcontract

methodName(type: arg) : is the function we are calling

Putting it all together we get:

act/0x5a43dbb51bae8f571d54f8d1b42b691a531503be/0x8BBAa8C008e438f1Ed3ECb2fce47365f140D1e54/setRevenue(address: 0x5a43dbb51bae8f571d54f8d1b42b691a531503be)

Finally, press send and sign the transaction. since we don’t have unilateral permission to call functions using agent, the action is forwarded to a vote.

Vote in Your DAO!

Head back to your DAO. We now have a new vote in the Voting app! Vote, it is your destiny. After the vote passes head back to remix. If all goes well, you should see that the fee has been updated!

Wrap up

We have gone from 0 to DAO in less than an hour. Congratulations! While this is cool, we have only scratched the surface of what’s possible. In future tutorials we will show you how to install apps into your DAO, modify permissions, and explore new workflows for Agent

Need Help?

If you have any questions or would like expert help implementing a governance solution for your dapp or protocol please reach out to us!

Reach Out!

You can also find us here:

Recommended Readings

Aragon OS Motivations

Aragon Agent Page

Riding the EVM with Aragon Agent and EVM scripts

How to use Aragon Agent · Aragon Developer Portal

This post was a collaboration between Burrrata and Python Pete.

--

--