Use web3-wrapper instead of 0x.js, update logDecoder
This commit is contained in:
parent
fdea260e41
commit
237ebb0716
@ -28,7 +28,8 @@ contract AssetProxyOwner is
|
|||||||
|
|
||||||
event AssetProxyRegistration(address assetProxyContract, bool isRegistered);
|
event AssetProxyRegistration(address assetProxyContract, bool isRegistered);
|
||||||
|
|
||||||
// Mapping of AssetProxy contract address => approved to execute removeAuthorizedAddress without time lock.
|
// Mapping of AssetProxy contract address =>
|
||||||
|
// if this contract is allowed to call the AssetProxy's removeAuthorizedAddress method without a time lock.
|
||||||
mapping (address => bool) public isAssetProxyRegistered;
|
mapping (address => bool) public isAssetProxyRegistered;
|
||||||
|
|
||||||
bytes4 constant REMOVE_AUTHORIZED_ADDRESS_SELECTOR = bytes4(keccak256("removeAuthorizedAddress(address)"));
|
bytes4 constant REMOVE_AUTHORIZED_ADDRESS_SELECTOR = bytes4(keccak256("removeAuthorizedAddress(address)"));
|
||||||
@ -95,7 +96,7 @@ contract AssetProxyOwner is
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev Compares first 4 bytes of byte array to removeAuthorizedAddress function signature.
|
/// @dev Compares first 4 bytes of byte array to removeAuthorizedAddress function selector.
|
||||||
/// @param data Transaction data.
|
/// @param data Transaction data.
|
||||||
/// @return Successful if data is a call to removeAuthorizedAddress.
|
/// @return Successful if data is a call to removeAuthorizedAddress.
|
||||||
function isFunctionRemoveAuthorizedAddress(bytes memory data)
|
function isFunctionRemoveAuthorizedAddress(bytes memory data)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Provider } from '@0xproject/types';
|
import { Provider } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { DummyERC20TokenContract } from '../contract_wrappers/generated/dummy_e_r_c20_token';
|
import { DummyERC20TokenContract } from '../contract_wrappers/generated/dummy_e_r_c20_token';
|
||||||
@ -13,10 +14,12 @@ import { txDefaults } from './web3_wrapper';
|
|||||||
export class ERC20Wrapper {
|
export class ERC20Wrapper {
|
||||||
private _tokenOwnerAddresses: string[];
|
private _tokenOwnerAddresses: string[];
|
||||||
private _contractOwnerAddress: string;
|
private _contractOwnerAddress: string;
|
||||||
|
private _web3Wrapper: Web3Wrapper;
|
||||||
private _provider: Provider;
|
private _provider: Provider;
|
||||||
private _dummyTokenContracts?: DummyERC20TokenContract[];
|
private _dummyTokenContracts?: DummyERC20TokenContract[];
|
||||||
private _proxyContract?: ERC20ProxyContract;
|
private _proxyContract?: ERC20ProxyContract;
|
||||||
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
||||||
|
this._web3Wrapper = new Web3Wrapper(provider);
|
||||||
this._provider = provider;
|
this._provider = provider;
|
||||||
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
||||||
this._contractOwnerAddress = contractOwnerAddress;
|
this._contractOwnerAddress = contractOwnerAddress;
|
||||||
@ -68,7 +71,8 @@ export class ERC20Wrapper {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await Promise.all([...setBalancePromises, ...setAllowancePromises]);
|
const txHashes = await Promise.all([...setBalancePromises, ...setAllowancePromises]);
|
||||||
|
await Promise.all(_.map(txHashes, async txHash => this._web3Wrapper.awaitTransactionSuccessAsync(txHash)));
|
||||||
}
|
}
|
||||||
public async getBalancesAsync(): Promise<ERC20BalancesByOwner> {
|
public async getBalancesAsync(): Promise<ERC20BalancesByOwner> {
|
||||||
this._validateDummyTokenContractsExistOrThrow();
|
this._validateDummyTokenContractsExistOrThrow();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { generatePseudoRandomSalt } from '@0xproject/order-utils';
|
import { generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||||
import { Provider } from '@0xproject/types';
|
import { Provider } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { DummyERC721TokenContract } from '../contract_wrappers/generated/dummy_e_r_c721_token';
|
import { DummyERC721TokenContract } from '../contract_wrappers/generated/dummy_e_r_c721_token';
|
||||||
@ -14,11 +15,13 @@ import { txDefaults } from './web3_wrapper';
|
|||||||
export class ERC721Wrapper {
|
export class ERC721Wrapper {
|
||||||
private _tokenOwnerAddresses: string[];
|
private _tokenOwnerAddresses: string[];
|
||||||
private _contractOwnerAddress: string;
|
private _contractOwnerAddress: string;
|
||||||
|
private _web3Wrapper: Web3Wrapper;
|
||||||
private _provider: Provider;
|
private _provider: Provider;
|
||||||
private _dummyTokenContracts?: DummyERC721TokenContract[];
|
private _dummyTokenContracts?: DummyERC721TokenContract[];
|
||||||
private _proxyContract?: ERC721ProxyContract;
|
private _proxyContract?: ERC721ProxyContract;
|
||||||
private _initialTokenIdsByOwner: ERC721TokenIdsByOwner = {};
|
private _initialTokenIdsByOwner: ERC721TokenIdsByOwner = {};
|
||||||
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
||||||
|
this._web3Wrapper = new Web3Wrapper(provider);
|
||||||
this._provider = provider;
|
this._provider = provider;
|
||||||
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
||||||
this._contractOwnerAddress = contractOwnerAddress;
|
this._contractOwnerAddress = contractOwnerAddress;
|
||||||
@ -80,7 +83,8 @@ export class ERC721Wrapper {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await Promise.all([...setBalancePromises, ...setAllowancePromises]);
|
const txHashes = await Promise.all([...setBalancePromises, ...setAllowancePromises]);
|
||||||
|
await Promise.all(_.map(txHashes, async txHash => this._web3Wrapper.awaitTransactionSuccessAsync(txHash)));
|
||||||
}
|
}
|
||||||
public async getBalancesAsync(): Promise<ERC721TokenIdsByOwner> {
|
public async getBalancesAsync(): Promise<ERC721TokenIdsByOwner> {
|
||||||
this._validateDummyTokenContractsExistOrThrow();
|
this._validateDummyTokenContractsExistOrThrow();
|
||||||
|
@ -2,20 +2,18 @@ import { Provider, TransactionReceiptWithDecodedLogs } from '@0xproject/types';
|
|||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as Web3 from 'web3';
|
|
||||||
|
|
||||||
import { ExchangeContract } from '../contract_wrappers/generated/exchange';
|
import { ExchangeContract } from '../contract_wrappers/generated/exchange';
|
||||||
|
|
||||||
import { constants } from './constants';
|
import { constants } from './constants';
|
||||||
import { formatters } from './formatters';
|
import { formatters } from './formatters';
|
||||||
import { LogDecoder } from './log_decoder';
|
import { logDecoder } from './log_decoder';
|
||||||
import { orderUtils } from './order_utils';
|
import { orderUtils } from './order_utils';
|
||||||
import { AssetProxyId, OrderInfo, SignedOrder, SignedTransaction } from './types';
|
import { AssetProxyId, OrderInfo, SignedOrder, SignedTransaction } from './types';
|
||||||
|
|
||||||
export class ExchangeWrapper {
|
export class ExchangeWrapper {
|
||||||
private _exchange: ExchangeContract;
|
private _exchange: ExchangeContract;
|
||||||
private _web3Wrapper: Web3Wrapper;
|
private _web3Wrapper: Web3Wrapper;
|
||||||
private _logDecoder: LogDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID);
|
|
||||||
constructor(exchangeContract: ExchangeContract, provider: Provider) {
|
constructor(exchangeContract: ExchangeContract, provider: Provider) {
|
||||||
this._exchange = exchangeContract;
|
this._exchange = exchangeContract;
|
||||||
this._web3Wrapper = new Web3Wrapper(provider);
|
this._web3Wrapper = new Web3Wrapper(provider);
|
||||||
@ -249,7 +247,7 @@ export class ExchangeWrapper {
|
|||||||
private async _getTxWithDecodedExchangeLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
|
private async _getTxWithDecodedExchangeLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const tx = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
|
const tx = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
|
||||||
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
|
tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address);
|
||||||
tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log));
|
tx.logs = _.map(tx.logs, log => logDecoder.decodeLogOrThrow(log));
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,30 +5,15 @@ import * as _ from 'lodash';
|
|||||||
|
|
||||||
import { artifacts } from './artifacts';
|
import { artifacts } from './artifacts';
|
||||||
|
|
||||||
export class LogDecoder {
|
const abiArrays: AbiDefinition[][] = [];
|
||||||
private _abiDecoder: AbiDecoder;
|
_.forEach(artifacts, (artifact: ContractArtifact) => {
|
||||||
constructor(networkIdIfExists?: number) {
|
|
||||||
if (_.isUndefined(networkIdIfExists)) {
|
|
||||||
throw new Error('networkId not specified');
|
|
||||||
}
|
|
||||||
const abiArrays: AbiDefinition[][] = [];
|
|
||||||
_.forEach(artifacts, (artifact: ContractArtifact) => {
|
|
||||||
const compilerOutput = artifact.compilerOutput;
|
const compilerOutput = artifact.compilerOutput;
|
||||||
abiArrays.push(compilerOutput.abi);
|
abiArrays.push(compilerOutput.abi);
|
||||||
});
|
});
|
||||||
this._abiDecoder = new AbiDecoder(abiArrays);
|
const abiDecoder = new AbiDecoder(abiArrays);
|
||||||
}
|
|
||||||
public decodeLogOrThrow<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
|
|
||||||
const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log);
|
|
||||||
if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs<ArgsType>).args)) {
|
|
||||||
throw new Error(`Unable to decode log: ${JSON.stringify(log)}`);
|
|
||||||
}
|
|
||||||
wrapLogBigNumbers(logWithDecodedArgsOrLog);
|
|
||||||
return logWithDecodedArgsOrLog;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function wrapLogBigNumbers(log: any): any {
|
export const logDecoder = {
|
||||||
|
wrapLogBigNumbers(log: any): any {
|
||||||
const argNames = _.keys(log.args);
|
const argNames = _.keys(log.args);
|
||||||
for (const argName of argNames) {
|
for (const argName of argNames) {
|
||||||
const isWeb3BigNumber = _.startsWith(log.args[argName].constructor.toString(), 'function BigNumber(');
|
const isWeb3BigNumber = _.startsWith(log.args[argName].constructor.toString(), 'function BigNumber(');
|
||||||
@ -36,4 +21,13 @@ function wrapLogBigNumbers(log: any): any {
|
|||||||
log.args[argName] = new BigNumber(log.args[argName]);
|
log.args[argName] = new BigNumber(log.args[argName]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
decodeLogOrThrow<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
|
||||||
|
const logWithDecodedArgsOrLog = abiDecoder.tryToDecodeLogOrNoop(log);
|
||||||
|
if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs<ArgsType>).args)) {
|
||||||
|
throw new Error(`Unable to decode log: ${JSON.stringify(log)}`);
|
||||||
|
}
|
||||||
|
logDecoder.wrapLogBigNumbers(logWithDecodedArgsOrLog);
|
||||||
|
return logWithDecodedArgsOrLog;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
import { TransactionReceiptWithDecodedLogs, ZeroEx } from '0x.js';
|
import { Provider, TransactionReceiptWithDecodedLogs } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
|
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as Web3 from 'web3';
|
|
||||||
|
|
||||||
import { AssetProxyOwnerContract } from '../contract_wrappers/generated/asset_proxy_owner';
|
import { AssetProxyOwnerContract } from '../contract_wrappers/generated/asset_proxy_owner';
|
||||||
import { MultiSigWalletContract } from '../contract_wrappers/generated/multi_sig_wallet';
|
import { MultiSigWalletContract } from '../contract_wrappers/generated/multi_sig_wallet';
|
||||||
|
|
||||||
import { constants } from './constants';
|
import { constants } from './constants';
|
||||||
import { LogDecoder } from './log_decoder';
|
import { logDecoder } from './log_decoder';
|
||||||
|
|
||||||
export class MultiSigWrapper {
|
export class MultiSigWrapper {
|
||||||
private _multiSig: MultiSigWalletContract;
|
private _multiSig: MultiSigWalletContract;
|
||||||
private _logDecoder: LogDecoder = new LogDecoder(constants.TESTRPC_NETWORK_ID);
|
private _web3Wrapper: Web3Wrapper;
|
||||||
private _zeroEx: ZeroEx;
|
constructor(multiSigContract: MultiSigWalletContract, provider: Provider) {
|
||||||
constructor(multiSigContract: MultiSigWalletContract, zeroEx: ZeroEx) {
|
|
||||||
this._multiSig = multiSigContract;
|
this._multiSig = multiSigContract;
|
||||||
this._zeroEx = zeroEx;
|
this._web3Wrapper = new Web3Wrapper(provider);
|
||||||
}
|
}
|
||||||
public async submitTransactionAsync(
|
public async submitTransactionAsync(
|
||||||
destination: string,
|
destination: string,
|
||||||
@ -50,9 +49,9 @@ export class MultiSigWrapper {
|
|||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
private async _getTxWithDecodedMultiSigLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
|
private async _getTxWithDecodedMultiSigLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
|
||||||
const tx = await this._zeroEx.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
|
const tx = await this._web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
|
||||||
tx.logs = _.filter(tx.logs, log => log.address === this._multiSig.address);
|
tx.logs = _.filter(tx.logs, log => log.address === this._multiSig.address);
|
||||||
tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log));
|
tx.logs = _.map(tx.logs, log => logDecoder.decodeLogOrThrow(log));
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { LogWithDecodedArgs, ZeroEx } from '0x.js';
|
|
||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
|
import { LogWithDecodedArgs } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
@ -23,7 +23,6 @@ import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper';
|
|||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||||
const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID });
|
|
||||||
|
|
||||||
describe('AssetProxyOwner', () => {
|
describe('AssetProxyOwner', () => {
|
||||||
let owners: string[];
|
let owners: string[];
|
||||||
@ -60,7 +59,7 @@ describe('AssetProxyOwner', () => {
|
|||||||
REQUIRED_APPROVALS,
|
REQUIRED_APPROVALS,
|
||||||
SECONDS_TIME_LOCKED,
|
SECONDS_TIME_LOCKED,
|
||||||
);
|
);
|
||||||
multiSigWrapper = new MultiSigWrapper(multiSig, zeroEx);
|
multiSigWrapper = new MultiSigWrapper(multiSig, provider);
|
||||||
await erc20Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner });
|
await erc20Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner });
|
||||||
await erc721Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner });
|
await erc721Proxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner });
|
||||||
});
|
});
|
||||||
@ -89,7 +88,7 @@ describe('AssetProxyOwner', () => {
|
|||||||
expect(isErc721ProxyRegistered).to.equal(true);
|
expect(isErc721ProxyRegistered).to.equal(true);
|
||||||
});
|
});
|
||||||
it('should throw if a null address is included in assetProxyContracts', async () => {
|
it('should throw if a null address is included in assetProxyContracts', async () => {
|
||||||
const assetProxyContractAddresses = [erc20Proxy.address, ZeroEx.NULL_ADDRESS];
|
const assetProxyContractAddresses = [erc20Proxy.address, constants.NULL_ADDRESS];
|
||||||
return expect(
|
return expect(
|
||||||
AssetProxyOwnerContract.deployFrom0xArtifactAsync(
|
AssetProxyOwnerContract.deployFrom0xArtifactAsync(
|
||||||
artifacts.AssetProxyOwner,
|
artifacts.AssetProxyOwner,
|
||||||
@ -161,7 +160,7 @@ describe('AssetProxyOwner', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fail if registering a null address', async () => {
|
it('should fail if registering a null address', async () => {
|
||||||
const addressToRegister = ZeroEx.NULL_ADDRESS;
|
const addressToRegister = constants.NULL_ADDRESS;
|
||||||
const isRegistered = true;
|
const isRegistered = true;
|
||||||
const registerAssetProxyData = multiSig.registerAssetProxy.getABIEncodedTransactionData(
|
const registerAssetProxyData = multiSig.registerAssetProxy.getABIEncodedTransactionData(
|
||||||
addressToRegister,
|
addressToRegister,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user