Staking DAI for the ETHGlobal HackMoney Hackathon

April 26, 2020 · Jeff Wentworth

It's a stakeout!

Engineers and interns from Curvegrid are participating in the ETHGlobal HackMoney hackathon, which runs from April 24 to May 24, 2020. Three hundred hackers in teams of up to five are prototyping the next generation of decentralized finance (DeFi) applications. Past ETHGlobal hackathon DeFi winners include Set Protocol, ZK Social Recovery, and Blazar.

Participants are required to stake 50 DAI which is returned at the end of the hackathon to all of those who actively participate. The organizers, sponsors, and mentors put a substantial amount of work into the organization and running of the hackathon, and the small hurdle of staking 50 DAI encourages only those serious about participating to sign up.

There are two ways to stake DAI for HackMoney: one-at-a-time via the HackMoney signup page, and in bulk by interacting directly with the smart contract. We'll demonstrate the second approach and illustrate how it can be used to snap together different DeFi "money LEGOs".

Introduction to staking

Staking in decentralized finance (DeFi) is the process of pledging tokens or cryptocurrency for a period of time, in order to receive something of value in return. For example, one can deposit DAI into the DAI Savings Rate smart contract to effectively receive interest for the period of time the DAI is locked up.

Simple illustration of the staking process

Staking DAI for HackMoney with Unlock

We have the following components in the HackMoney staking setup.

  • MakerDAO: DAI is a stablecoin whose price vs. US dollars is managed a decentralized collateralized debt position (CDP). 1 DAI ≈ 1 USD. DAI is an ERC20 and DSToken-compatible smart contract.

  • Unlock Protocol: this is the heart of the DAI-for-HackMoney participation setup. The ETHGlobal organizers deployed an Unlock PublicLock smart contract to receive DAI from participants and in turn issue a HackMoney KEY token. At the end of the hackathon, participants who gave it their best can return the KEY tokens for their 50 DAI, plus an even portion of the DAI from anyone who signed up, staked, but didn't participate. On top of the smart contract, a web-based DApp integrated into the HackMoney signup portal can be used to stake DAI and receive a KEY token, securing one's spot in the HackMoney hackathon.

The HackMoney staking process

The basic process for staking DAI for HackMoney is:

  1. Acquire some ETH to pay the Ethereum gas fees
  2. Purchase at least 50 DAI for staking
  3. Signup for the hackathon with a web3 browser (MetaMask, etc.), and send two transactions:
    • approve() the HackMoney PublicLock smart contract to withdraw 50 DAI from your wallet.
    • purchase() the KEY token in exchange for 50 DAI, staked in the PublicLock smart contract.

Alternatively, skip steps 1 & 2 and use a credit card as the first part of step 3.

Staking DAI for HackMoney directly to the smart contract

Since the HackMoney PublicLock smart contract is running on the public Ethereum blockchain, we can talk to it directly. We will use MultiBaas but one could write a script or use geth commands directly if you are comfortable with the command line. In our case, we wanted to put up the 50 DAI on behalf of our participating engineers and interns. The HackMoney signup page only supports using the active web3 browser wallet. Either each participant would need to share their private key with us, or we could have sent each participant 50 DAI and they could have in turn staked it themselves.

But each transaction on Ethereum costs about $0.05-$1.50 in transaction fees, and with shipping DAI around as well as calling approve() and purchase() for each participant, the costs start to add up. What if we could simply stake DAI from a central wallet?

First we need to call approve() once on the DAI smart contract for the 8x50 = 400 DAI that we're going to stake centrally. This will allow the DAI to be withdrawn from our wallet and staked in to the HackMoney PublicLock smart contract. We have the DAI contract setup in our MultiBaas instance already, so we just navigate to it, enter the appropriate values, and click Send Method.

PublicLock smart contract in MultiBaas

We sign the transaction using MetaMask, and we're ready to stake DAI. Note that would have been 8 separate transactions, instead of just 1, had we done this via the HackMoney signup UI.

Next, we upload the PublicLock smart contract to MultiBaas and link it to the existing HackMoney smart contract instance:

PublicLock smart contract in MultiBaas

This top part shows the public state variables, including the KEY price (50.000... DAI). We can also see the number of KEY tokens that have been issued thus far (Total Supply = 279).

We scroll down to the purchase() method and fill in the appropriate values. The Recipient is the public Ethereum address of the participant we're staking on behalf of. We again click Send Method, sign the transaction, and we've justed staked 50 DAI in exchange for a KEY token on behalf of a participant!

Calling purchase() on the PublicLock smart contract in MultiBaas

In summary, here's what we did:

  1. Acquired some ETH to pay the Ethereum gas fees
  2. Purchased 8x50 = 400 DAI for staking
  3. approve() the HackMoney PublicLock smart contract to withdraw 400 DAI from our wallet
  4. purchase() the KEY token in exchange for 50 DAI, staked in the PublicLock smart contract, x8 for each of the participants we are staking on behalf of
  5. Each participant then signs up for the hackathon with a web3 browser (MetaMask, etc.), which recognizes that their wallet has already had 50 DAI staked on its behalf

Once more, with video

We recorded our efforts and put together a quick demo video of us staking the DAI with MultiBaas.