Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Mutate ERC20 ABI to handle WETH Deposit and Withdrawl
Browse files Browse the repository at this point in the history
  • Loading branch information
dekz committed May 10, 2019
1 parent f944b95 commit c5f6ebe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ export class CollisionResistanceAbiDecoder {
this._restAbiDecoder = new AbiDecoder(abis);
}
public tryToDecodeLogOrNoop<ArgsType extends DecodedLogArgs>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
let maybeDecodedLog = log;
if (this._knownERC20Tokens.has(log.address)) {
maybeDecodedLog = this._erc20AbiDecoder.tryToDecodeLogOrNoop(log);
const maybeDecodedERC20Log = this._erc20AbiDecoder.tryToDecodeLogOrNoop(log);
return maybeDecodedERC20Log;
} else if (this._knownERC721Tokens.has(log.address)) {
maybeDecodedLog = this._erc721AbiDecoder.tryToDecodeLogOrNoop(log);
const maybeDecodedERC721Log = this._erc721AbiDecoder.tryToDecodeLogOrNoop(log);
return maybeDecodedERC721Log;
} else {
const maybeDecodedLog = this._restAbiDecoder.tryToDecodeLogOrNoop(log);
return maybeDecodedLog;
}
// 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<DecodedLogArgs>).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 {
Expand Down
15 changes: 13 additions & 2 deletions packages/order-watcher/src/order_watcher/order_watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,20 @@ 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(
artifacts.ERC20Token.compilerOutput.abi,
combinedWETHERC20Abi,
artifacts.ERC721Token.compilerOutput.abi,
[artifacts.WETH9.compilerOutput.abi, artifacts.Exchange.compilerOutput.abi],
[artifacts.Exchange.compilerOutput.abi],
);
const contractWrappers = new ContractWrappers(provider, {
networkId,
Expand Down Expand Up @@ -150,6 +160,7 @@ export class OrderWatcher {
this._cleanupJobInterval = config.cleanupJobIntervalMs;
const zrxTokenAddress = assetDataUtils.decodeERC20AssetData(orderFilledCancelledFetcher.getZRXAssetData())
.tokenAddress;
this._collisionResistantAbiDecoder.addERC20Token(zrxTokenAddress);
this._dependentOrderHashesTracker = new DependentOrderHashesTracker(zrxTokenAddress);
}
/**
Expand Down

0 comments on commit c5f6ebe

Please sign in to comment.