1

can someone help to explain the small remainingFillableTakerAmount for the following order hash: 0x886618b8da6aa22193ddffc6cfc7d89782a16a7dea9cd698dacb82b8b7e430f9:

{"total":3,"page":1,"perPage":20,"records":[{"order":{"signature":{"signatureType":2,"r":"0x09f8e3298f92644bc7f855d7b6daad5e9908cf22f26f14dbca03e801f45ac698","s":"0x7b0a88e939f443c63d73cf168502246a412e8086f96e44253803119defcba29c","v":27},"sender":"0x0000000000000000000000000000000000000000","maker":"0x8836a16db8db1cba0890f0ee97a9926cb47b4101","taker":"0x0000000000000000000000000000000000000000","takerTokenFeeAmount":"900000000000000000","makerAmount":"429300000000000000000000","takerAmount":"90000000000000000000","makerToken":"0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355","takerToken":"0x03582cb41f2fd982e1b531d633b6de049d56f2a0","salt":"1657610336337","verifyingContract":"0xdef1c0ded9bec7f1a1670819833240f027b25eff","feeRecipient":"0xbb0f479895915f80f6feb5babcb0ad39a0d7ef4e","expiry":"1658215136","chainId":3,"pool":"0x0000000000000000000000000000000000000000000000000000000000000000"},"metaData":{"orderHash":"0x886618b8da6aa22193ddffc6cfc7d89782a16a7dea9cd698dacb82b8b7e430f9","remainingFillableTakerAmount":"176236897062360417","createdAt":"2022-07-12T07:19:13.028Z"}},{"order":{"signature":{"signatureType":2,"r":"0x623dd23a16b8fef784bbfafe6ed194be70bee3220106da0fa9c91b0095590c1f","s":"0x673678d92ace80dc8f22ad215bf9c03c22c9f14978daf82e2e8baa75292d2123","v":28},"sender":"0x0000000000000000000000000000000000000000","maker":"0x8836a16db8db1cba0890f0ee97a9926cb47b4101","taker":"0x0000000000000000000000000000000000000000","takerTokenFeeAmount":"100000000000000000","makerAmount":"46700000000000000000000","takerAmount":"10000000000000000000","makerToken":"0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355","takerToken":"0x03582cb41f2fd982e1b531d633b6de049d56f2a0","salt":"1657609823092","verifyingContract":"0xdef1c0ded9bec7f1a1670819833240f027b25eff","feeRecipient":"0xbb0f479895915f80f6feb5babcb0ad39a0d7ef4e","expiry":"1658214623","chainId":3,"pool":"0x0000000000000000000000000000000000000000000000000000000000000000"},"metaData":{"orderHash":"0x9b65e4a1c24908d5e30373e643a3bfd1950754f1d4f477b3204b894c78b564f2","remainingFillableTakerAmount":"180010706421297471","createdAt":"2022-07-12T07:11:46.504Z"}},{"order":{"signature":{"signatureType":2,"r":"0xbe508aa9893f73c2e95e7fe8d22d2424b003550f3c884a8d7c547be6935d4e1a","s":"0x5e1c28ec5341bde124c5f55197b4d2801fa469e56fa8b4dd116d5cc0e2cb6c88","v":27},"sender":"0x0000000000000000000000000000000000000000","maker":"0x8836a16db8db1cba0890f0ee97a9926cb47b4101","taker":"0x0000000000000000000000000000000000000000","takerTokenFeeAmount":"100000000000000000","makerAmount":"46700000000000000000000","takerAmount":"10000000000000000000","makerToken":"0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355","takerToken":"0x03582cb41f2fd982e1b531d633b6de049d56f2a0","salt":"1657609825510","verifyingContract":"0xdef1c0ded9bec7f1a1670819833240f027b25eff","feeRecipient":"0xbb0f479895915f80f6feb5babcb0ad39a0d7ef4e","expiry":"1658214625","chainId":3,"pool":"0x0000000000000000000000000000000000000000000000000000000000000000"},"metaData":{"orderHash":"0xeb2680de5b1d40f9ff0ef6e7ed41692d86f66150e877939508e161600e22d1f7","remainingFillableTakerAmount":"180010706421297471","createdAt":"2022-07-12T07:11:48.716Z"}}]}
  • There are not cross-market orders (i.e. where takerToken is different) as can be seen here: https://ropsten.api.0x.org/orderbook/v1/orders?maker=0x8836a16db8db1cba0890f0ee97a9926cb47b4101
  • Maker allowance: 462616904978989909186790 (462'616.90497898990918679 in decimal terms)
  • Filled taker amount: 1500000000000000003 (1.5000...03 in decimal terms)
  • Expected: Remaining takerAmount of 88499999999999999997 (c. 88.5 in decimal terms) based on my calculations assuming sufficient maker allowance whic is the case here in my opinion
  • Actual: remainingTakerFillableAmount returned from 0x api call: 176236897062360417 (0.176... in decimal terms)

The result is that I can only fill the first order but not the other two using batchFillLimitOrders.

Can someone explain why remainingTakerFillableAmount is so low? Typically, this happens when maker allowance is too low, but in that case, there is clearly sufficient maker allowance. Is there something I'm missing or is this a bug?

I also created an issue in the 0x api github repo for that: https://github.com/0xProject/0x-api/issues/885

1 Answer 1

0

Ok, I can answer the question myself. The reason remainingFillableTakerAmount was showing less than expected is because the user has spent some of the maker token after they have created the orders. That is, checking the maker allowance for the maker token is not enough. One also needs to check the maker's maker token balance.

When some of the readers is planning to use 0x's orderbook api endpoint to build an orderbook like we did for app.diva.finance, you have to take the following fact into account: If a user creates multiple orders and the maker token balance or allowance reduces after the orders have been created and posted to the api server, 0x will return all orders, but only a subset of them will be actually fillable. Or to put it differently, the returned orders won't be mutually fillable resulting in errors if you try to do so.

To overcome this issue, we've implemented additional logic on the frontend to filter out the non-fillable orders by comparing the remainingFillableMakerAmount (has to be derived from remainingFillableTakerAmount, takerAmount and makerAmount) with the minimum of the maker's maker token allowance/balance. The most efficient way to query the minimum allowance/balance for a given set of maker addresses is using BalanceChecker contract's getMinOfBalancesOrAllowances function. Note that the maximum number of addresses you can pass into that function is 400-500. To account for that fact, it's recommended to implement some batch logic in case you ned up having more maker addresses than that.

Hope this insight which took me a few days to figure out will be helpful for future readers.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.