From d1203f90da01b05d9c6d1ca1860da86b6fb8d325 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Fri, 10 May 2019 16:32:17 +0200 Subject: [PATCH] Revert "Mutate ERC20 ABI to handle WETH Deposit and Withdrawl" This reverts commit c5f6ebee188e35a4e7fc8b9363d04ca90e4f31ee. --- .../collision_resistant_abi_decoder.ts | 17 ++++++++++------- .../src/order_watcher/order_watcher.ts | 15 ++------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/packages/order-watcher/src/order_watcher/collision_resistant_abi_decoder.ts b/packages/order-watcher/src/order_watcher/collision_resistant_abi_decoder.ts index 2ea7969470..52f28cd4a3 100644 --- a/packages/order-watcher/src/order_watcher/collision_resistant_abi_decoder.ts +++ b/packages/order-watcher/src/order_watcher/collision_resistant_abi_decoder.ts @@ -26,16 +26,19 @@ export class CollisionResistanceAbiDecoder { this._restAbiDecoder = new AbiDecoder(abis); } public tryToDecodeLogOrNoop(log: LogEntry): LogWithDecodedArgs | RawLog { + let maybeDecodedLog = log; if (this._knownERC20Tokens.has(log.address)) { - const maybeDecodedERC20Log = this._erc20AbiDecoder.tryToDecodeLogOrNoop(log); - return maybeDecodedERC20Log; + maybeDecodedLog = this._erc20AbiDecoder.tryToDecodeLogOrNoop(log); } else if (this._knownERC721Tokens.has(log.address)) { - const maybeDecodedERC721Log = this._erc721AbiDecoder.tryToDecodeLogOrNoop(log); - return maybeDecodedERC721Log; - } else { - const maybeDecodedLog = this._restAbiDecoder.tryToDecodeLogOrNoop(log); - return maybeDecodedLog; + maybeDecodedLog = this._erc721AbiDecoder.tryToDecodeLogOrNoop(log); } + // Fall back to the supplied ABIs for decoding if the ERC20/ERC721 decoding fails + // This ensures we hit events like Deposit and Withdraw given WETH can be a known ERC20Token + const isLogDecoded = ((maybeDecodedLog as any) as LogWithDecodedArgs).event !== undefined; + if (!isLogDecoded) { + maybeDecodedLog = this._restAbiDecoder.tryToDecodeLogOrNoop(log); + } + return maybeDecodedLog; } // Hints the ABI decoder that a particular token address is ERC20 and events from it should be decoded as ERC20 events public addERC20Token(address: string): void { diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index c298cbcac4..78c619859f 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -119,20 +119,10 @@ export class OrderWatcher { }; this._provider = provider; - const wethDepositEvent = _.find( - artifacts.WETH9.compilerOutput.abi, - item => item.type === 'event' && item.name === 'Deposit', - ); - const wethWithdrawEvent = _.find( - artifacts.WETH9.compilerOutput.abi, - item => item.type === 'event' && item.name === 'Withdrawal', - ); - // Combine ERC20 and WETH events into a single ABI. This is used as the default ERC20 ABI when decoding - const combinedWETHERC20Abi = [...artifacts.ERC20Token.compilerOutput.abi, wethDepositEvent, wethWithdrawEvent]; this._collisionResistantAbiDecoder = new CollisionResistanceAbiDecoder( - combinedWETHERC20Abi, + artifacts.ERC20Token.compilerOutput.abi, artifacts.ERC721Token.compilerOutput.abi, - [artifacts.Exchange.compilerOutput.abi], + [artifacts.WETH9.compilerOutput.abi, artifacts.Exchange.compilerOutput.abi], ); const contractWrappers = new ContractWrappers(provider, { networkId, @@ -160,7 +150,6 @@ export class OrderWatcher { this._cleanupJobInterval = config.cleanupJobIntervalMs; const zrxTokenAddress = assetDataUtils.decodeERC20AssetData(orderFilledCancelledFetcher.getZRXAssetData()) .tokenAddress; - this._collisionResistantAbiDecoder.addERC20Token(zrxTokenAddress); this._dependentOrderHashesTracker = new DependentOrderHashesTracker(zrxTokenAddress); } /**