auryn-macmillan / wrap-n-zap

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

xDAI Network

WrapNZap Factory: 0x8464135c8F25Da09e49BC8782676a84730C318bC

Raid Guild WrapNZap: 0x8398bCD4f633C72939F9043dB78c574A91C99c0A

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

About

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

License:MIT License


Languages

Language:JavaScript 85.3%Language:Solidity 14.4%Language:Shell 0.3%