1

I'm currently implementing 0xRouter into my app and encountered a hurdle.

How can I deduct the fee of a trade from sellToken and not receive it in the form of buyToken? The main use for this is, if a user is buying a token via ETH. It's very inconvenient to receive the fee in tokenXY instead of ETH.

Since I don't see any way how to pass a "receiverAddress" to the callData, I tried deducting the percentage of msg.value on my relay contract directly, which then calls 0xProxy with the following parameters for the quote API call:

feeRecipient: callingUser.address, buyTokenPercentageFee: 1

Deducting the percentage of ETH on my contract works fine, but the buyAmount becomes 50% in the calldata, which then results in 50% being sent to my relay contract and 50% being sent to my user.

I assume buyTokenPercentageFee = 1 translates to 50% which is supposed to be a safety mechanism. Looking at the tx flow I realized at _transformERC20Private() in TransformERC20Feature.sol the msg.sender becomes recipient.

In other words - there is no way of using a relay contract in front of the call to 0xProxy without having tokens sent to the relay contract?

Am I missing something? I also looked at the explicit order build etc., but also don't see a way how to achieve what I'm looking for, even if I'd go through the struggle of creating and hashing the orders myself.

I mean even uniV2 has a "to" argument for a regular swap that can be routed through a contract before being sent to the router. Looking at the highly sophisticated code of 0x it just can't be that this is not possible.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.