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.
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.
blockNumber
you were attempting to fill these orders at? Additionally, thetakerAddress
in question would also be helpful. Using a tool like Tenderly, we should be able to track down the reason for the revert.takerAddress
: 0x9AdEFeb576dcF52F5220709c1B267d89d5208D78 I cannot provide ablockNumber
as the transaction isn't even initiated.