RiskProtocol / core-protocol

1 stars 0 forks source link

Research: 0x fees #116

Open mz7mz7mz7 opened 1 year ago

mz7mz7mz7 commented 1 year ago

Research how 0x fees work. Can we set them to an arbitrary value? Who is being paid the fee? Is there a way for other trading participants to overwrite it?

Review the docs/code but maybe also build simple PoC (even in the form of unit tests) showing how the fees can be used.

Tunji17 commented 1 year ago

https://docs.0xprotocol.org/en/latest/basics/protocol_fees.html

Tunji17 commented 1 year ago

https://www.loom.com/share/5290b74a92a64e1a8e364ace4c82c424?sid=1c4338cf-7cca-4dd1-afb5-33df932d41d1

Tunji17 commented 1 year ago
{
    "makerToken": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    "takerToken": "0xe41d2489571d322189246dafa5ebde1f4699f498",
    "makerAmount": "100000000000000",
    "takerAmount": "2000000000000000000000",
    "maker": "0x56EB0aD2dC746540Fab5C02478B31e2AA9DdC38C",
    "taker": "0x0000000000000000000000000000000000000000",
    "pool": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "expiry": "1614956256",
    "salt": "2752094376750492926844965905320507011598275560670346196138937898764349624882",
    "chainId": 1,
    "verifyingContract": "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
    "takerTokenFeeAmount": "0",
    "sender": "0x0000000000000000000000000000000000000000",
    "feeRecipient": "0x0000000000000000000000000000000000000000",
    "signature": {
        "v": 27,
        "r": "0x983a8a8dad663124a52609fe9aa82737f7f02d12ed951785f36b50906041794d",
        "s": "0x5f18ae837be4732bcb3dd019104cf775f92b8740b275be510462a7aa62cdf252",
        "signatureType": 3
    }
}

This is a sample of the limit order object containing feeRecipient and takerTokenFeeAmount gotten from https://0x.org/docs/0x-orderbook-api/api-references/post-orderbook-v1-order

mz7mz7mz7 commented 1 year ago

This is a sample of the limit order object containing feeRecipient and takerTokenFeeAmount gotten from https://0x.org/docs/0x-orderbook-api/api-references/post-orderbook-v1-order

So the values both for the fee and the recipient are 0x0 here. Can we find an example with non-zero fees, ideally with the tx hash (i.e., the order that was settled and the fees paid)?

Tunji17 commented 1 year ago

Yes, I showed this in the loom video i attached to the ticket, if you check here, https://polygonscan.com/token/0xAcBFc51186a5104BEA8DDc98c9C45569e86d2e0E?a=0x4274e6eedd682721d938ea6d63b294a92abe949f all the transactions to this address are fees

mz7mz7mz7 commented 1 year ago
  1. So I understand this transaction https://polygonscan.com/tx/0xecdfa5a877201867f10af88f317bfc408213f98163b940adfd71e3bcd51e5dfc as 0x6 trades with himself tokenX and Y, pays .5 X to himself for .1 for Y, and again pay .5 of X as a trading fee. It's a highly unusual trade... Can we please simulate one that is more realistic to make sure we do not have unexpected side effects? Ie there are actually 2 accounts trading, and the fee is not consuming 100% of the taker token?
mz7mz7mz7 commented 1 year ago
  1. Also, setting the fee as a fixed price implies that we can not set the fees as a % of the trade amount. Some more questions:
    • What happens with the fee for partially filled orders? How much is paid?
mz7mz7mz7 commented 1 year ago
  1. Is the 'protocol fee' (https://docs.0xprotocol.org/en/latest/basics/protocol_fees.html) and 'taker fee' the same? I am a bit confused by this article; it mentions v3 and v4, v4 being the latest 0x version, so it implies there are some protocol fees (in ETH) in the recent protocol version. But we did not really observe them @Tunji17 in your tests. Not sure how to interpret it.
Tunji17 commented 1 year ago

It’s not the same, the protocol fee was the fee 0x was charging i think

mz7mz7mz7 commented 1 year ago

But they say they distribute that fee to makers as a liquidity reward. And again: I did not see that fee being paid, in ETH, on your video/examples.

Tunji17 commented 1 year ago

I will verify this and revert to you with answers

Tunji17 commented 11 months ago

Hello @mz7mz7mz7 i have been able to test and answer this question

What happens with the fee for partially filled orders? How much is paid?

I created an order to sell 2 token A for 8 token B and set the fee amount to be 8 token B, I partially filled 1 token A for 4 of token B and ended up also paying 4 token B as the fee amount, this means i paid 8 token B in total for 1 token A. I expected it to work this way and i think it's fine