Giter VIP home page Giter VIP logo

wrap-n-zap's Introduction

WrapNZap

A simple zap contract to wrap a native token and send it to a destination.

Overview & Motivation

Some contracts -- such as Moloch DAOs -- cannot receive or deal with native coins such as ETH (on mainnet) or xDAI (on xDAI network). To be sent to such contracts, native coins must first be wrapped into ERC20 tokens. This creates a UX challenge for users trying to get coins into those contracts from other networks.

For example, consider a user trying to send DAI to a Moloch DAO on the xDAI network. Currently, they must do the following:

Current Process (before WrapNZap)

  1. Bridge their DAI from mainnet to the xDAI network. They'll receive xDAI (remember, not an ERC20 token) at their wallet address on the xDAI network.
  2. Wrap the xDAI into Wrapped xDAI (wxDAI) -- e.g. using a tool like WrapETH
  3. Transfer the wxDAI to the DAO

With WrapNZap

WrapNZap simplifies this process into a single step.

  1. Use the xDAI bridge and specify the DAO's WrapNZap contract as the receipient. The WrapNZap contract handles the wrapping and the zapping to the DAO.

How it works

Each instance of a WrapNZap contract specifies two key items:

  • wrapper -- the address of the wrapped native token contract (e.g. wxDAI)
  • zappee -- the address where the wrapped tokens will be sent/zapped (e.g. a Moloch DAO's bank).

WrapNZap leverages solidity's receive() capability to trigger activity when the network's native coin is sent to it.

When this happens, the native coins are first sent to the wrapper to be wrapped into an ERC20 token, and then the resulting tokens are transferred to the zappee.

The need for poke

On the xDAI network, the xDAI bridge doesn't send an xDAI transaction when new DAI is bridged over from mainnet. Instead, it assigns the xDAI to the recipient via the coinbase/block reward, which does not trigger a contract's receive() or fallback function. Unfortunately, that breaks the end to end automation awesomeness of WrapNZap.

We can, however, get around this problem with a public poke function that triggers the contract's balance to be wrapped and zapped. It of course requires an additional transaction, but it need not be the original sender.

WrapNZap Factory

This repo also includes a factory contract that simplifies the process for DAOs to deploy a WrapNZap contract of their own. A DAO -- or anybody working on behalf of the DAO -- can create a new WrapNZap instance with the DAO as the zappee.

Note: they will also need to set the wrapper.

Current Deployments

Mainnet

xDAI Network

Rinkeby

Kovan

Polygon

Running Tests

WrapNZap uses Hardhat, Waffle, and ethers. Here's how to test:

  1. Clone this repo -- git clone https://github.com/slgraham/wrap-n-zap.git
  2. Install hardhat and dependencies -- yarn install
  3. Run tests -- yarn hardhat test

wrap-n-zap's People

Contributors

spengrah avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.