Decode log arguments in awaitTransactionSuccessAsync
, when ABI is recognized.
This commit is contained in:
parent
aa29526ae4
commit
df746c5ff4
@ -51,6 +51,8 @@ import {
|
||||
TestStaticCallReceiverContract,
|
||||
} from '../src';
|
||||
|
||||
import { dependencyArtifacts } from './utils/dependency_artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
@ -136,17 +138,20 @@ describe('Exchange core', () => {
|
||||
artifacts.Exchange,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||
);
|
||||
maliciousWallet = maliciousValidator = await TestStaticCallReceiverContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestStaticCallReceiver,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
);
|
||||
reentrantErc20Token = await ReentrantERC20TokenContract.deployFrom0xArtifactAsync(
|
||||
artifacts.ReentrantERC20Token,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
exchange.address,
|
||||
);
|
||||
|
||||
@ -379,7 +384,7 @@ describe('Exchange core', () => {
|
||||
const initialTakerZrxBalance = await zrxToken.balanceOf.callAsync(takerAddress);
|
||||
const initialFeeRecipientZrxBalance = await zrxToken.balanceOf.callAsync(feeRecipientAddress);
|
||||
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
const txReceipt = await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress);
|
||||
|
||||
const finalMakerBalanceA = await noReturnErc20Token.balanceOf.callAsync(makerAddress);
|
||||
const finalMakerBalanceB = await erc20TokenB.balanceOf.callAsync(makerAddress);
|
||||
|
@ -29,6 +29,8 @@ import {
|
||||
TestAssetProxyDispatcherContract,
|
||||
} from '../src';
|
||||
|
||||
import { dependencyArtifacts } from './utils/dependency_artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
@ -72,6 +74,7 @@ describe('AssetProxyDispatcher', () => {
|
||||
artifacts.TestAssetProxyDispatcher,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(assetProxyDispatcher.address, {
|
||||
|
@ -18,6 +18,8 @@ import * as _ from 'lodash';
|
||||
|
||||
import { artifacts, TestExchangeInternalsContract } from '../src';
|
||||
|
||||
import { dependencyArtifacts } from './utils/dependency_artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
@ -65,6 +67,7 @@ describe('Exchange core internal functions', () => {
|
||||
artifacts.TestExchangeInternals,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
);
|
||||
overflowErrorForSendTransaction = new Error(
|
||||
await getRevertReasonOrErrorMessageForSendTransactionAsync(RevertReason.Uint256Overflow),
|
||||
|
@ -29,6 +29,8 @@ import {
|
||||
TestExchangeInternalsContract,
|
||||
} from '../src';
|
||||
|
||||
import { dependencyArtifacts } from './utils/dependency_artifacts';
|
||||
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
@ -118,6 +120,7 @@ describe('matchOrders', () => {
|
||||
artifacts.Exchange,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||
);
|
||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||
@ -141,6 +144,7 @@ describe('matchOrders', () => {
|
||||
artifacts.ReentrantERC20Token,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
exchange.address,
|
||||
);
|
||||
|
||||
@ -175,6 +179,7 @@ describe('matchOrders', () => {
|
||||
artifacts.TestExchangeInternals,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
|
@ -25,6 +25,8 @@ import {
|
||||
WalletContract,
|
||||
} from '../src';
|
||||
|
||||
import { dependencyArtifacts } from './utils/dependency_artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
@ -59,23 +61,27 @@ describe('MixinSignatureValidator', () => {
|
||||
artifacts.TestSignatureValidator,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
);
|
||||
testWallet = await WalletContract.deployFrom0xArtifactAsync(
|
||||
artifacts.Wallet,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
signerAddress,
|
||||
);
|
||||
testValidator = await ValidatorContract.deployFrom0xArtifactAsync(
|
||||
artifacts.Validator,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
signerAddress,
|
||||
);
|
||||
maliciousWallet = maliciousValidator = await TestStaticCallReceiverContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestStaticCallReceiver,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
);
|
||||
signatureValidatorLogDecoder = new LogDecoder(web3Wrapper, artifacts);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
|
@ -21,6 +21,8 @@ import * as _ from 'lodash';
|
||||
|
||||
import { artifacts, ExchangeContract, ExchangeWrapper, ExchangeWrapperContract, WhitelistContract } from '../src/';
|
||||
|
||||
import { dependencyArtifacts } from './utils/dependency_artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
@ -87,6 +89,7 @@ describe('Exchange transactions', () => {
|
||||
artifacts.Exchange,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||
);
|
||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||
@ -219,6 +222,7 @@ describe('Exchange transactions', () => {
|
||||
artifacts.ExchangeWrapper,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
exchange.address,
|
||||
);
|
||||
});
|
||||
@ -333,6 +337,7 @@ describe('Exchange transactions', () => {
|
||||
artifacts.Whitelist,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
exchange.address,
|
||||
);
|
||||
const isApproved = true;
|
||||
|
9
contracts/exchange/test/utils/dependency_artifacts.ts
Normal file
9
contracts/exchange/test/utils/dependency_artifacts.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { artifacts as erc1155Artifacts } from '@0x/contracts-erc1155';
|
||||
import { artifacts as erc20Artifacts } from '@0x/contracts-erc20';
|
||||
import { artifacts as erc721Artifacts } from '@0x/contracts-erc721';
|
||||
|
||||
export const dependencyArtifacts = {
|
||||
...erc20Artifacts,
|
||||
...erc721Artifacts,
|
||||
...erc1155Artifacts,
|
||||
};
|
@ -4,7 +4,6 @@ import { artifacts as erc721Artifacts } from '@0x/contracts-erc721';
|
||||
import {
|
||||
FillResults,
|
||||
formatters,
|
||||
LogDecoder,
|
||||
OrderInfo,
|
||||
orderUtils,
|
||||
Web3ProviderEngine,
|
||||
@ -22,16 +21,9 @@ import { AbiDecodedFillOrderData } from './types';
|
||||
export class ExchangeWrapper {
|
||||
private readonly _exchange: ExchangeContract;
|
||||
private readonly _web3Wrapper: Web3Wrapper;
|
||||
private readonly _logDecoder: LogDecoder;
|
||||
constructor(exchangeContract: ExchangeContract, provider: Web3ProviderEngine | ZeroExProvider) {
|
||||
this._exchange = exchangeContract;
|
||||
this._web3Wrapper = new Web3Wrapper(provider);
|
||||
this._logDecoder = new LogDecoder(this._web3Wrapper, {
|
||||
...artifacts,
|
||||
...erc20Artifacts,
|
||||
...erc721Artifacts,
|
||||
...erc1155Artifacts,
|
||||
});
|
||||
}
|
||||
public async fillOrderAsync(
|
||||
signedOrder: SignedOrder,
|
||||
@ -39,20 +31,18 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmount?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
|
||||
const txHash = await this._exchange.fillOrder.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.fillOrder.awaitTransactionSuccessAsync(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
{ from },
|
||||
);
|
||||
const txReceipt = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return txReceipt;
|
||||
}
|
||||
public async cancelOrderAsync(signedOrder: SignedOrder, from: string): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createCancel(signedOrder);
|
||||
const txHash = await this._exchange.cancelOrder.sendTransactionAsync(params.order, { from });
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
const txReceipt = await this._exchange.cancelOrder.awaitTransactionSuccessAsync(params.order, { from });
|
||||
return txReceipt;
|
||||
}
|
||||
public async fillOrKillOrderAsync(
|
||||
signedOrder: SignedOrder,
|
||||
@ -60,14 +50,13 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmount?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
|
||||
const txHash = await this._exchange.fillOrKillOrder.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.fillOrKillOrder.awaitTransactionSuccessAsync(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
{ from },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async fillOrderNoThrowAsync(
|
||||
signedOrder: SignedOrder,
|
||||
@ -75,14 +64,13 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmount?: BigNumber; gas?: number } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
|
||||
const txHash = await this._exchange.fillOrderNoThrow.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.fillOrderNoThrow.awaitTransactionSuccessAsync(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
{ from, gas: opts.gas },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async batchFillOrdersAsync(
|
||||
orders: SignedOrder[],
|
||||
@ -90,14 +78,13 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmounts?: BigNumber[] } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = formatters.createBatchFill(orders, opts.takerAssetFillAmounts);
|
||||
const txHash = await this._exchange.batchFillOrders.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.batchFillOrders.awaitTransactionSuccessAsync(
|
||||
params.orders,
|
||||
params.takerAssetFillAmounts,
|
||||
params.signatures,
|
||||
{ from },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async batchFillOrKillOrdersAsync(
|
||||
orders: SignedOrder[],
|
||||
@ -105,14 +92,13 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmounts?: BigNumber[] } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = formatters.createBatchFill(orders, opts.takerAssetFillAmounts);
|
||||
const txHash = await this._exchange.batchFillOrKillOrders.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.batchFillOrKillOrders.awaitTransactionSuccessAsync(
|
||||
params.orders,
|
||||
params.takerAssetFillAmounts,
|
||||
params.signatures,
|
||||
{ from },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async batchFillOrdersNoThrowAsync(
|
||||
orders: SignedOrder[],
|
||||
@ -120,14 +106,13 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmounts?: BigNumber[]; gas?: number } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = formatters.createBatchFill(orders, opts.takerAssetFillAmounts);
|
||||
const txHash = await this._exchange.batchFillOrdersNoThrow.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.batchFillOrdersNoThrow.awaitTransactionSuccessAsync(
|
||||
params.orders,
|
||||
params.takerAssetFillAmounts,
|
||||
params.signatures,
|
||||
{ from, gas: opts.gas },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async marketSellOrdersAsync(
|
||||
orders: SignedOrder[],
|
||||
@ -135,14 +120,13 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmount: BigNumber },
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = formatters.createMarketSellOrders(orders, opts.takerAssetFillAmount);
|
||||
const txHash = await this._exchange.marketSellOrders.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.marketSellOrders.awaitTransactionSuccessAsync(
|
||||
params.orders,
|
||||
params.takerAssetFillAmount,
|
||||
params.signatures,
|
||||
{ from },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async marketSellOrdersNoThrowAsync(
|
||||
orders: SignedOrder[],
|
||||
@ -150,14 +134,13 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmount: BigNumber; gas?: number },
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = formatters.createMarketSellOrders(orders, opts.takerAssetFillAmount);
|
||||
const txHash = await this._exchange.marketSellOrdersNoThrow.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.marketSellOrdersNoThrow.awaitTransactionSuccessAsync(
|
||||
params.orders,
|
||||
params.takerAssetFillAmount,
|
||||
params.signatures,
|
||||
{ from, gas: opts.gas },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async marketBuyOrdersAsync(
|
||||
orders: SignedOrder[],
|
||||
@ -165,14 +148,13 @@ export class ExchangeWrapper {
|
||||
opts: { makerAssetFillAmount: BigNumber },
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = formatters.createMarketBuyOrders(orders, opts.makerAssetFillAmount);
|
||||
const txHash = await this._exchange.marketBuyOrders.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.marketBuyOrders.awaitTransactionSuccessAsync(
|
||||
params.orders,
|
||||
params.makerAssetFillAmount,
|
||||
params.signatures,
|
||||
{ from },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async marketBuyOrdersNoThrowAsync(
|
||||
orders: SignedOrder[],
|
||||
@ -180,50 +162,45 @@ export class ExchangeWrapper {
|
||||
opts: { makerAssetFillAmount: BigNumber; gas?: number },
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = formatters.createMarketBuyOrders(orders, opts.makerAssetFillAmount);
|
||||
const txHash = await this._exchange.marketBuyOrdersNoThrow.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.marketBuyOrdersNoThrow.awaitTransactionSuccessAsync(
|
||||
params.orders,
|
||||
params.makerAssetFillAmount,
|
||||
params.signatures,
|
||||
{ from, gas: opts.gas },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async batchCancelOrdersAsync(
|
||||
orders: SignedOrder[],
|
||||
from: string,
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = formatters.createBatchCancel(orders);
|
||||
const txHash = await this._exchange.batchCancelOrders.sendTransactionAsync(params.orders, { from });
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
const txReceipt = await this._exchange.batchCancelOrders.awaitTransactionSuccessAsync(params.orders, { from });
|
||||
return txReceipt;
|
||||
}
|
||||
public async cancelOrdersUpToAsync(salt: BigNumber, from: string): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const txHash = await this._exchange.cancelOrdersUpTo.sendTransactionAsync(salt, { from });
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
const txReceipt = await this._exchange.cancelOrdersUpTo.awaitTransactionSuccessAsync(salt, { from });
|
||||
return txReceipt;
|
||||
}
|
||||
public async registerAssetProxyAsync(
|
||||
assetProxyAddress: string,
|
||||
from: string,
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const txHash = await this._exchange.registerAssetProxy.sendTransactionAsync(assetProxyAddress, { from });
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
const txReceipt = await this._exchange.registerAssetProxy.awaitTransactionSuccessAsync(assetProxyAddress, { from });
|
||||
return txReceipt;
|
||||
}
|
||||
public async executeTransactionAsync(
|
||||
signedTx: SignedZeroExTransaction,
|
||||
from: string,
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const txHash = await this._exchange.executeTransaction.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.executeTransaction.awaitTransactionSuccessAsync(
|
||||
signedTx.salt,
|
||||
signedTx.signerAddress,
|
||||
signedTx.data,
|
||||
signedTx.signature,
|
||||
{ from },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async getTakerAssetFilledAmountAsync(orderHashHex: string): Promise<BigNumber> {
|
||||
const filledAmount = await this._exchange.filled.callAsync(orderHashHex);
|
||||
@ -251,15 +228,14 @@ export class ExchangeWrapper {
|
||||
from: string,
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createMatchOrders(signedOrderLeft, signedOrderRight);
|
||||
const txHash = await this._exchange.matchOrders.sendTransactionAsync(
|
||||
const txReceipt = await this._exchange.matchOrders.awaitTransactionSuccessAsync(
|
||||
params.left,
|
||||
params.right,
|
||||
params.leftSignature,
|
||||
params.rightSignature,
|
||||
{ from },
|
||||
);
|
||||
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);
|
||||
return tx;
|
||||
return txReceipt;
|
||||
}
|
||||
public async getFillOrderResultsAsync(
|
||||
signedOrder: SignedOrder,
|
||||
|
@ -37,6 +37,7 @@ import 'make-promises-safe';
|
||||
import { artifacts, ExchangeContract, ExchangeFillEventArgs } from '../../src';
|
||||
|
||||
import { AssetWrapper } from './asset_wrapper';
|
||||
import { dependencyArtifacts } from './dependency_artifacts';
|
||||
import { ExchangeWrapper } from './exchange_wrapper';
|
||||
import { OrderFactoryFromScenario } from './order_factory_from_scenario';
|
||||
import { SimpleAssetBalanceAndProxyAllowanceFetcher } from './simple_asset_balance_and_proxy_allowance_fetcher';
|
||||
@ -101,6 +102,7 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
|
||||
artifacts.Exchange,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
zrxAssetData,
|
||||
);
|
||||
const exchangeWrapper = new ExchangeWrapper(exchangeContract, provider);
|
||||
|
@ -24,6 +24,8 @@ import * as _ from 'lodash';
|
||||
|
||||
import { artifacts, ExchangeContract, ExchangeWrapper, ReentrantERC20TokenContract } from '../src';
|
||||
|
||||
import { dependencyArtifacts } from './utils/dependency_artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
@ -87,6 +89,7 @@ describe('Exchange wrappers', () => {
|
||||
artifacts.Exchange,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
assetDataUtils.encodeERC20AssetData(zrxToken.address),
|
||||
);
|
||||
exchangeWrapper = new ExchangeWrapper(exchange, provider);
|
||||
@ -110,6 +113,7 @@ describe('Exchange wrappers', () => {
|
||||
artifacts.ReentrantERC20Token,
|
||||
provider,
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
exchange.address,
|
||||
);
|
||||
|
||||
|
@ -26,6 +26,7 @@ import { SimpleContractArtifact } from '@0x/types';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import { assert } from '@0x/assert';
|
||||
import * as ethers from 'ethers';
|
||||
import * as _ from 'lodash';
|
||||
// tslint:enable:no-unused-variable
|
||||
|
||||
{{#if events}}
|
||||
@ -63,6 +64,7 @@ export class {{contractName}}Contract extends BaseContract {
|
||||
artifact: ContractArtifact | SimpleContractArtifact,
|
||||
supportedProvider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
artifactDependencies: { [contractName: string]: (ContractArtifact | SimpleContractArtifact) },
|
||||
{{> typed_params inputs=ctor.inputs}}
|
||||
): Promise<{{contractName}}Contract> {
|
||||
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
|
||||
@ -76,13 +78,15 @@ export class {{contractName}}Contract extends BaseContract {
|
||||
const provider = providerUtils.standardizeOrThrow(supportedProvider);
|
||||
const bytecode = artifact.compilerOutput.evm.bytecode.object;
|
||||
const abi = artifact.compilerOutput.abi;
|
||||
return {{contractName}}Contract.deployAsync(bytecode, abi, provider, txDefaults, {{> params inputs=ctor.inputs}});
|
||||
const abiDependencies = _.mapValues(artifactDependencies, (artifactDependency: ContractArtifact | SimpleContractArtifact) => {return artifactDependency.compilerOutput.abi});
|
||||
return {{contractName}}Contract.deployAsync(bytecode, abi, provider, txDefaults, abiDependencies, {{> params inputs=ctor.inputs}});
|
||||
}
|
||||
public static async deployAsync(
|
||||
bytecode: string,
|
||||
abi: ContractAbi,
|
||||
supportedProvider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
abiDependencies: { [contractName: string]: ContractAbi },
|
||||
{{> typed_params inputs=ctor.inputs}}
|
||||
): Promise<{{contractName}}Contract> {
|
||||
assert.isHexString('bytecode', bytecode);
|
||||
@ -111,7 +115,7 @@ export class {{contractName}}Contract extends BaseContract {
|
||||
logUtils.log(`transactionHash: ${txHash}`);
|
||||
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
|
||||
logUtils.log(`{{contractName}} successfully deployed at ${txReceipt.contractAddress}`);
|
||||
const contractInstance = new {{contractName}}Contract(txReceipt.contractAddress as string, provider, txDefaults);
|
||||
const contractInstance = new {{contractName}}Contract(txReceipt.contractAddress as string, provider, txDefaults, abiDependencies);
|
||||
contractInstance.constructorArgs = [{{> params inputs=ctor.inputs}}];
|
||||
return contractInstance;
|
||||
}
|
||||
@ -213,8 +217,8 @@ export class {{contractName}}Contract extends BaseContract {
|
||||
);
|
||||
return logs;
|
||||
}{{/if}}
|
||||
constructor(address: string, supportedProvider: SupportedProvider, txDefaults?: Partial<TxData>) {
|
||||
super('{{contractName}}', {{contractName}}Contract.ABI(), address, supportedProvider, txDefaults);
|
||||
constructor(address: string, supportedProvider: SupportedProvider, txDefaults?: Partial<TxData>, logDecodeDependencies?: { [contractName: string]: ContractAbi }) {
|
||||
super('{{contractName}}', {{contractName}}Contract.ABI(), address, supportedProvider, txDefaults, logDecodeDependencies);
|
||||
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);{{#if events}}
|
||||
this._subscriptionManager = new SubscriptionManager<{{contractName}}EventArgs, {{contractName}}Events>(
|
||||
{{contractName}}Contract.ABI(),
|
||||
|
@ -186,6 +186,7 @@ export class BaseContract {
|
||||
address: string,
|
||||
supportedProvider: SupportedProvider,
|
||||
callAndTxnDefaults?: Partial<CallData>,
|
||||
abiDependencies?: { [contractName: string]: ContractAbi },
|
||||
) {
|
||||
assert.isString('contractName', contractName);
|
||||
assert.isETHAddressHex('address', address);
|
||||
@ -209,6 +210,10 @@ export class BaseContract {
|
||||
const abiEncoder = new AbiEncoder.Method(methodAbi);
|
||||
const functionSignature = abiEncoder.getSignature();
|
||||
this._abiEncoderByFunctionSignature[functionSignature] = abiEncoder;
|
||||
this._web3Wrapper.abiDecoder.addABI(abi, contractName);
|
||||
});
|
||||
_.each(abiDependencies, (abi, name) => {
|
||||
this._web3Wrapper.abiDecoder.addABI(abi, name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user