0

I am experiencing issues filling orders using the batchFillLimitOrders function when the remainingFillableTakerAmount is small.

I am calling the following piece of code using the input parameters listed below:

const response = await exchange
      .batchFillLimitOrders(fillOrders, signatures, takerAssetFillAmounts, true)
      .awaitTransactionSuccessAsync({ from: orderData.maker })
      .catch((err) => console.error('Error logged ' + JSON.stringify(err)))

First input parameter: Order objects

[
{
  chainId: 3
  expiry: "1657831517"
  feeRecipient: "0x0000000000000000000000000000000000000000"
  maker: "0x4c12ab430e078c56010c46f9391c60be50781b07"
  makerAmount: "270000000000000000000"
  makerToken: "0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355"
  pool: "0x0000000000000000000000000000000000000000000000000000000000000000"
  remainingFillableTakerAmount: "9998758480790449"
  salt: "1655239517688"
  sender: "0x0000000000000000000000000000000000000000"
  taker: "0x0000000000000000000000000000000000000000"
  takerAmount: "10000000000000000"
  takerToken: "0x03582cb41f2fd982e1b531d633b6de049d56f2a0"
  takerTokenFeeAmount: "0"
  verifyingContract: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"
},
{
  chainId: 3
  expiry: "1656397720"
  feeRecipient: "0x0000000000000000000000000000000000000000"
  maker: "0x2db4625a9ece077cb432d1a84b85b03c15721be6"
  makerAmount: "225300000000000000000"
  makerToken: "0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355"
  pool: "0x0000000000000000000000000000000000000000000000000000000000000000"
  remainingFillableTakerAmount: "1"
  salt: "1655188120250"
  sender: "0x0000000000000000000000000000000000000000"
  taker: "0x0000000000000000000000000000000000000000"
  takerAmount: "100000000000000000"
  takerToken: "0x03582cb41f2fd982e1b531d633b6de049d56f2a0"
  takerTokenFeeAmount: "0"
  verifyingContract: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"
},
{
  chainId: 3
  expiry: "1655274128"
  feeRecipient: "0x0000000000000000000000000000000000000000"
  maker: "0x2a65ae527c6ff4665e048b0e0883c486a7ba4dbc"
  makerAmount: "67200000000000000000"
  makerToken: "0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355"
  pool: "0x0000000000000000000000000000000000000000000000000000000000000000"
  remainingFillableTakerAmount: "2922902068498283"
  salt: "1655230928557"
  sender: "0x0000000000000000000000000000000000000000"
  taker: "0x0000000000000000000000000000000000000000"
  takerAmount: "3000000000000000"
  takerToken: "0x03582cb41f2fd982e1b531d633b6de049d56f2a0"
  takerTokenFeeAmount: "0"
  verifyingContract: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"
}
]

Second input parameter: Signatures

[
{
  r: "0x30feaab607cbc25f0f672f42f91bfc9c2946d14ba46014808196aade6b9bf63d"
  s: "0x4e56d337898ac32854588023f1347ac0904e2bcc887598f9495b3b3b96ec6fd0"
  signatureType: 2
  v: 27
},
{
  r: "0x41bd89be774e218d88801f474d38344eeb76e2c6603e41869a0041d91aba21ec"
  s: "0x75e28c241a60f9b83ac88d696819218728998805615ab67843e7044acab33476"
  signatureType: 2
  v: 27
},
{
  r: "0x214b1450334bafa9b3e1c48c3e31f82916662e4b53045b8515655074edadfdbc"
  s: "0x7d1005a5473a886ba0b6aae64d88a9d30fe8e88a957332eb155e97b1e69ddacc"
  signatureType: 2
  v: 28
}
]

Third input parameter: TakerAssetFillAmounts

[
'9998758480790449',
'1',
'1241519209550'
]

Error message that I receive:

{"code":-32603,"message":"execution reverted","data":{"originalError":{"code":3,"data":"0x1d44aa5dc35b019348a46f24084407a1a39c446af5cfef56fe27d475d0285d3861f0fe0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002385d15f7143b1","message":"execution reverted"}}}

The weird thing is that it works if I deduct 1 from each TakerAssetFillAmount element, i.e. if I pass the following as the third parameter:

[
'9998758480790448',
'0',
'1241519209549'
]

This let's me assume that there might be some rounding issue in the 0x protocol itself or the 0x API.

I looked at the smart contract implementation of the batchFillLimitOrder function and I suspect that it ends up in the catch without throwing any meaningful error message.

enter image description here

The consequence of this problem is that I cannot get rid of the dust transactions in the following orderbook that we built on top of 0x protocol: https://app.diva.finance/91/long

Anyone here who could help?

Another example that is failing:

Order:

chainId: 3
expiry: "1656539073"
feeRecipient: "0xbb0f479895915f80f6feb5babcb0ad39a0d7ef4e"
maker: "0x9adefeb576dcf52f5220709c1b267d89d5208d78"
makerAmount: "10000000000000000000"
makerToken: "0x8218c91a4d06829de73200201db7f57f1f7e698e"
pool: "0x0000000000000000000000000000000000000000000000000000000000000000"
remainingFillableTakerAmount: "5000000000000000000"
salt: "1655934273929"
sender: "0x0000000000000000000000000000000000000000"
taker: "0x0000000000000000000000000000000000000000"
takerAmount: "5000000000000000000"
takerToken: "0x134e62bd2ee247d4186a1fdbaa9e076cb26c1355"
takerTokenFeeAmount: "50000000000000000"
verifyingContract: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"

Trying to fill 3500000000000000000 out of 5000000000000000000 (i.e. 3.5 out of 5.0 remaining) results in the same error. Reducing the fill amount to 3450000000000000000 works though.

I checked the allowance for the takerToken for the address that I am using (0x47566C6c8f70E4F16Aa3E7D8eED4a2bDb3f4925b) and it shows 3500000000000000000 so this can't be the reasons as suspected in one of the comments.

I'd like to understand why this keeps happening and what I can do to mitigate that problem.

Update

It looks that if the approved amount is equal to remainingFillableTakerAmount, then it fails. It seems that approving slightly more than the remainingFillableTakerAmount does the trick. But would be curious to understand why.

2
  • Can you provide the blockNumber you were attempting to fill these orders at? Additionally, the takerAddress in question would also be helpful. Using a tool like Tenderly, we should be able to track down the reason for the revert. Jun 15, 2022 at 14:21
  • takerAddress: 0x9AdEFeb576dcF52F5220709c1B267d89d5208D78 I cannot provide a blockNumber as the transaction isn't even initiated. Jun 16, 2022 at 10:09

3 Answers 3

0

I might be missing something but have you tried seeing whether there's anything specific to your second order (the one with remainingFillableTakerAmount: "1").

E.g. does this work?

[
'9998758480790449',
'1',
'1241519209550'
]
1
  • The reason for remainingFillableTakerAmount = '1' is because due to the issue that we are experiencing, we are deducting 1 from each takerAssetFillAmount. As a result, you end up with 1 being the remainingFillableTakerAmount which we end up filtering out from our orderbook. Jun 16, 2022 at 10:08
0

Also, can you double-check if the approval or a balance may have been insufficient for one of the tokens? A simulation of your order is throwing an error that ERC20: transfer amount exceeds balance.

1
0

I think I found out my issue. If takerTokenFeeAmount > 0, then it looks like the taker needs to approve the sum, i.e. takerAmount + takerTokenFee and not just takerAmount. Hope this helps anyone who is working with the 0x protocol.

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.