Replace isTransferable
with fillOrder
variant that uses delegatecall
#19
Labels
isTransferable
with fillOrder
variant that uses delegatecall
#19
Summary
The
Exchange
contract'sfillOrder
function currently takes an argumentshouldThrowOnInsufficientBalanceOrAllowance
. If set tofalse
, balances and allowances of themakerToken
,takerToken
, and ZRX will be checked before attempting any token transfers. If any balances or allowances are insufficient,fillOrder
will fail gracefully be returning 0 and logging an error. This is intended to be used with any functions that fill multiple orders in a single transaction. If a single fill fails, we do not necessarily want the entire transaction tothrow
orrevert
.This proposal would remove the
shouldThrowOnInsufficientBalanceOrAllowance
argument and add a function that replicates this functionality by calling thefillOrder
function withdelegatecall
. In this case, balances and allowances are not checked before attempting a token transfer. However, usingdelegatecall
ensures that the the subcall returns false on a failed transfer, rather than reverting the entire transaction.Motivation
The implementation of
isTransferable
contains many edge cases, is bug prone, and is a constant point of confusion in theExchange
contract. With the addition of theREVERT
opcode in the Byzantium hard fork, it no longer results in gas savings compared to the transaction reverting. In addition, it is extremely expensive to use (making 8 external calls and copying an extra 384 bytes to memory), and usingdelegatecall
is significantly cheaper most of the time (making 1 extra external call and copying 480 extra bytes to memory).Implementation
The text was updated successfully, but these errors were encountered: