Why didn't support token to ETH trade?


#1

Hello, any one here? I saw 0x v2 added an forwarder contract address, but it can only support ETH to token, why didn’t you consider of supporting token to ETH trade?


#2

When you submit an Ethereum transaction, you can specify an amount of ETH to go with the transaction. That means in a single transaction you can send ETH along with the trade you want to execute, the contract can convert your ETH into WETH, and execute any trades you’ve provided it in a single transaction.

You can’t do the same thing with tokens. You have to set allowances to be able to trade tokens; within Ethereum there’s no way around this. So if you’re trading tokens, you have to have one transaction to set allowances for your tokens and another transaction to execute the trade. You could potentially have a contract that trades tokens based on your allowances then converts WETH back to ETH before it sends it to you, but you’d still have to have at least two transactions to set allowances before executing the trade.


#3

Thank you for your reply!

According to this, we wanna to design a proxy wrapper contract, the flow like this:

User(Maker)
Taker(MarketMaker)
PW(Our proxy wrapper contract)
0xEX(0x exchange contract)
0xPC(0x proxy contract)
0xET(0x etherToken contract)

TokenA
WETH

User set TokenA allowance to PW
PW set TokenA allowance to 0xPC

  1. User place a order
    makerToken is TokenA
    takerToken is WETH

  2. taker send a fillOrder tx to PW

  3. PW transfer User’s TokenA to PW

  4. PW generate a new order, almost same data with original order, only salt, signature, maker, taker(taker address specified as “taker”) is different

  5. PW send a fillOrder tx to 0xEX

  6. 0xEX notify that 0xPC to transfer PW’s TokenA to taker

  7. 0xEX notify that 0xPC to transfer taker’s WETH to PW

  8. PW send a withdraw tx to 0x 0xET, and get ETH back

  9. PW send a internal tx, transfer ETH to User

And the step 2-9, is within one transaction, Dose it could be be possible?


#4

Technically you could use a WETH contract which withdraws on transfer to the user receiving WETH, call it WETHWithdraw.

This means you can use this specialised WETHWithdraw contract with a modified Forwarder contract.

Maker creates an order trading ZRX for WETHWithdraw.
Taker fills order through modified Forwarder, sending in ETH (internally ETH -> WETHWithdraw deposit, fillOrder).
When the ERC20 Proxy calls transfer on WETHWithdraw it transfers the balances and performs the withdraw and sends ETH to the receiver and reduces totalSupply.

This allows both maker and taker to use and receive ETH and WETHWithdraw is only utilised in the transaction lifecycle.

The downside to this is the additional gas costs. This gas cost is not paid by the maker (but by the taker), so the taker is paying for the makers convenience. Frequent traders and market makers would prefer the gas savings over the convenience, but it is still totally possible.

Remember WETH is just a contract the community has decided to agree and standardise upon. We are also looking into alternative ways ETH can adhere to the ERC20 standard to improve this UX.