A simple zap contract to wrap a native token and send it to a destination.
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:
- 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.
- Wrap the xDAI into Wrapped xDAI (wxDAI) -- e.g. using a tool like WrapETH
- Transfer the wxDAI to the DAO
WrapNZap simplifies this process into a single step.
- 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.
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
.
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.
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
.
WrapNZap Factory: 0x8464135c8F25Da09e49BC8782676a84730C318bC
Raid Guild WrapNZap: 0x8398bCD4f633C72939F9043dB78c574A91C99c0A
WrapNZap uses Hardhat, Waffle, and ethers. Here's how to test:
- Clone this repo --
git clone https://github.com/slgraham/wrap-n-zap.git
- Install hardhat and dependencies --
yarn install
- Run tests --
yarn hardhat test