diff --git a/contracts/extensions/package.json b/contracts/extensions/package.json index 3e132dc8e3..0b30fc3968 100644 --- a/contracts/extensions/package.json +++ b/contracts/extensions/package.json @@ -48,7 +48,6 @@ "homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md", "devDependencies": { "@0x/abi-gen": "^4.1.0", - "@0x/contract-wrappers": "9.1.7", "@0x/contracts-gen": "^1.0.13", "@0x/contracts-test-utils": "^3.1.13", "@0x/dev-utils": "^2.3.0", diff --git a/contracts/extensions/test/dutch_auction.ts b/contracts/extensions/test/dutch_auction.ts index 01c8e4a25a..c2bcb1dc15 100644 --- a/contracts/extensions/test/dutch_auction.ts +++ b/contracts/extensions/test/dutch_auction.ts @@ -1,4 +1,3 @@ -import { DutchAuctionWrapper } from '@0x/contract-wrappers'; import { ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; import { DummyERC20TokenContract } from '@0x/contracts-erc20'; import { DummyERC721TokenContract } from '@0x/contracts-erc721'; @@ -151,7 +150,7 @@ describe(ContractName.DutchAuction, () => { feeRecipientAddress, // taker address or sender address should be set to the ducth auction contract takerAddress: dutchAuctionContract.address, - makerAssetData: DutchAuctionWrapper.encodeDutchAuctionAssetData( + makerAssetData: assetDataUtils.encodeDutchAuctionAssetData( assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress), auctionBeginTimeSeconds, auctionBeginAmount, @@ -193,7 +192,7 @@ describe(ContractName.DutchAuction, () => { describe('matchOrders', () => { it('should be worth the begin price at the begining of the auction', async () => { auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp + 2); - const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + const makerAssetData = assetDataUtils.encodeDutchAuctionAssetData( defaultERC20MakerAssetData, auctionBeginTimeSeconds, auctionBeginAmount, @@ -207,7 +206,7 @@ describe(ContractName.DutchAuction, () => { it('should be be worth the end price at the end of the auction', async () => { auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds * 2); auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); - const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + const makerAssetData = assetDataUtils.encodeDutchAuctionAssetData( defaultERC20MakerAssetData, auctionBeginTimeSeconds, auctionBeginAmount, @@ -273,7 +272,7 @@ describe(ContractName.DutchAuction, () => { it('should revert when auction expires', async () => { auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds * 2); auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); - const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + const makerAssetData = assetDataUtils.encodeDutchAuctionAssetData( defaultERC20MakerAssetData, auctionBeginTimeSeconds, auctionBeginAmount, @@ -307,7 +306,7 @@ describe(ContractName.DutchAuction, () => { }); it('begin time is less than end time', async () => { auctionBeginTimeSeconds = new BigNumber(auctionEndTimeSeconds).plus(tenMinutesInSeconds); - const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + const makerAssetData = assetDataUtils.encodeDutchAuctionAssetData( defaultERC20MakerAssetData, auctionBeginTimeSeconds, auctionBeginAmount, @@ -335,7 +334,7 @@ describe(ContractName.DutchAuction, () => { it('should match orders when ERC721', async () => { const makerAssetId = erc721MakerAssetIds[0]; const erc721MakerAssetData = assetDataUtils.encodeERC721AssetData(erc721Token.address, makerAssetId); - const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + const makerAssetData = assetDataUtils.encodeDutchAuctionAssetData( erc721MakerAssetData, auctionBeginTimeSeconds, auctionBeginAmount, diff --git a/packages/0x.js/CHANGELOG.json b/packages/0x.js/CHANGELOG.json index 862d91dd88..646d1d852f 100644 --- a/packages/0x.js/CHANGELOG.json +++ b/packages/0x.js/CHANGELOG.json @@ -4,6 +4,10 @@ "changes": [ { "note": "Removed @0x/order-watcher" + }, + { + "note": "Update to latest @0x/contract-wrappers v11", + "pr": 2068 } ] }, diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 83f44b0a8a..f9e8706e06 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -43,7 +43,6 @@ }, "license": "Apache-2.0", "devDependencies": { - "@0x/abi-gen-wrappers": "^5.2.0", "@0x/contract-addresses": "^3.0.3", "@0x/dev-utils": "^2.3.0", "@0x/migrations": "^4.2.0", @@ -76,7 +75,7 @@ "@0x/assert": "^2.1.3", "@0x/asset-swapper": "^1.0.1", "@0x/base-contract": "^5.3.1", - "@0x/contract-wrappers": "9.1.7", + "@0x/contract-wrappers": "^11.0.0", "@0x/order-utils": "^8.2.5", "@0x/subproviders": "^5.0.1", "@0x/types": "^2.4.1", diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index b79026f287..f088ec02b4 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -13,36 +13,19 @@ export { CoordinatorWrapper, CoordinatorServerCancellationResponse, CoordinatorServerError, - DutchAuctionWrapper, - ERC20TokenWrapper, - ERC721TokenWrapper, - EtherTokenWrapper, - ExchangeWrapper, - ERC20ProxyWrapper, - ERC721ProxyWrapper, - ForwarderWrapper, - OrderValidatorWrapper, IndexedFilterValues, - BlockRange, ContractWrappersConfig, - MethodOpts, OrderTransactionOpts, TransactionOpts, - OrderStatus, OrderInfo, EventCallback, DecodedLogEvent, - TransactionEncoder, - BalanceAndAllowance, - OrderAndTraderInfo, - TraderInfo, - ValidateOrderFillableOpts, -} from '@0x/contract-wrappers'; - -export { + OrderStatus, DutchAuctionContract, ERC20ProxyContract, + ERC20TokenContract, ERC721ProxyContract, + ERC721TokenContract, ExchangeContract, ForwarderContract, OrderValidatorContract, @@ -69,7 +52,7 @@ export { ExchangeCancelEventArgs, ExchangeEventArgs, ExchangeEvents, -} from '@0x/abi-gen-wrappers'; +} from '@0x/contract-wrappers'; export import Web3ProviderEngine = require('web3-provider-engine'); diff --git a/packages/abi-gen-templates/partials/tx.handlebars b/packages/abi-gen-templates/partials/tx.handlebars index 306dbbdd71..aa1d41bd08 100644 --- a/packages/abi-gen-templates/partials/tx.handlebars +++ b/packages/abi-gen-templates/partials/tx.handlebars @@ -100,4 +100,22 @@ public {{languageSpecificName}} = { return gas; }, {{> callAsync}} + async validateAndSendTransactionAsync( + {{> typed_params inputs=inputs}} + txData?: Partial | undefined, + ): Promise { + await (this as any).{{languageSpecificName}}.callAsync( + {{#each inputs~}} + {{name}}, + {{/each~}} + txData, + ); + const txHash = await (this as any).{{languageSpecificName}}.sendTransactionAsync( + {{#each inputs~}} + {{name}}, + {{/each~}} + txData, + ); + return txHash; + } }; diff --git a/packages/abi-gen/test-cli/expected-output/typescript/abi_gen_dummy.ts b/packages/abi-gen/test-cli/expected-output/typescript/abi_gen_dummy.ts index 96a438bd83..6e02229ffb 100644 --- a/packages/abi-gen/test-cli/expected-output/typescript/abi_gen_dummy.ts +++ b/packages/abi-gen/test-cli/expected-output/typescript/abi_gen_dummy.ts @@ -396,6 +396,11 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(wad: BigNumber, txData?: Partial | undefined): Promise { + await (this as any).withdraw.callAsync(wad, txData); + const txHash = await (this as any).withdraw.sendTransactionAsync(wad, txData); + return txHash; + }, }; /** * Tests decoding when the input and output are complex and have more than one argument. @@ -1353,6 +1358,11 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(txData?: Partial | undefined): Promise { + await (this as any).nonPureMethod.callAsync(txData); + const txHash = await (this as any).nonPureMethod.sendTransactionAsync(txData); + return txHash; + }, }; /** * Tests decoding when the input and output are complex. @@ -1716,6 +1726,11 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(txData?: Partial | undefined): Promise { + await (this as any).nonPureMethodThatReturnsNothing.callAsync(txData); + const txHash = await (this as any).nonPureMethodThatReturnsNothing.sendTransactionAsync(txData); + return txHash; + }, }; public simplePureFunction = { /** diff --git a/packages/abi-gen/test-cli/test_typescript/test/abi_gen_dummy_test.ts b/packages/abi-gen/test-cli/test_typescript/test/abi_gen_dummy_test.ts index d674b9033a..33fce30f72 100644 --- a/packages/abi-gen/test-cli/test_typescript/test/abi_gen_dummy_test.ts +++ b/packages/abi-gen/test-cli/test_typescript/test/abi_gen_dummy_test.ts @@ -125,6 +125,14 @@ describe('AbiGenDummy Contract', () => { }); }); + describe('validate and send transaction', () => { + it('should call validateAndSendTransactionAsync', async () => { + const txHash = await abiGenDummy.nonPureMethod.validateAndSendTransactionAsync(); + const hexRegex = /^0x[a-fA-F0-9]+$/; + expect(txHash.match(hexRegex)).to.deep.equal([txHash]); + }); + }); + describe('event subscription', () => { const indexFilterValues = {}; const emptyCallback = () => {}; // tslint:disable-line:no-empty diff --git a/packages/asset-buyer/package.json b/packages/asset-buyer/package.json index 7f4df06625..df12abe0e3 100644 --- a/packages/asset-buyer/package.json +++ b/packages/asset-buyer/package.json @@ -39,7 +39,7 @@ "dependencies": { "@0x/assert": "^2.1.3", "@0x/connect": "^5.0.16", - "@0x/contract-wrappers": "9.1.7", + "@0x/contract-wrappers": "^11.0.0", "@0x/json-schemas": "^3.1.13", "@0x/order-utils": "^8.2.5", "@0x/subproviders": "^5.0.1", diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts index eb9c1f2036..ca468c8085 100644 --- a/packages/asset-buyer/src/asset_buyer.ts +++ b/packages/asset-buyer/src/asset_buyer.ts @@ -1,6 +1,6 @@ -import { ContractWrappers, ContractWrappersError, ForwarderWrapperError } from '@0x/contract-wrappers'; +import { ContractError, ContractWrappers, ForwarderError } from '@0x/contract-wrappers'; import { schemas } from '@0x/json-schemas'; -import { SignedOrder } from '@0x/order-utils'; +import { assetDataUtils, SignedOrder } from '@0x/order-utils'; import { ObjectMap } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; @@ -21,11 +21,10 @@ import { OrderProvider, OrdersAndFillableAmounts, } from './types'; - import { assert } from './utils/assert'; -import { assetDataUtils } from './utils/asset_data_utils'; import { buyQuoteCalculator } from './utils/buy_quote_calculator'; import { calculateLiquidity } from './utils/calculate_liquidity'; +import { numberPercentageToEtherTokenAmountPercentage } from './utils/number_percentage_to_ethertoken_amount_percentage'; import { orderProviderResponseProcessor } from './utils/order_provider_response_processor'; interface OrdersEntry { @@ -263,26 +262,32 @@ export class AssetBuyer { } } try { + // format fee percentage + const formattedFeePercentage = numberPercentageToEtherTokenAmountPercentage(feePercentage || 0); // if no ethAmount is provided, default to the worst ethAmount from buyQuote - const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEthAsync( + const value = ethAmount || worstCaseQuoteInfo.totalEthAmount; + + const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEth.validateAndSendTransactionAsync( orders, assetBuyAmount, - finalTakerAddress, - ethAmount || worstCaseQuoteInfo.totalEthAmount, + orders.map(o => o.signature), feeOrders, - feePercentage, + feeOrders.map(o => o.signature), + formattedFeePercentage, feeRecipient, { - gasLimit, + value, + from: finalTakerAddress.toLowerCase(), + gas: gasLimit, gasPrice, - shouldValidate: true, }, ); + return txHash; } catch (err) { - if (_.includes(err.message, ContractWrappersError.SignatureRequestDenied)) { + if (_.includes(err.message, ContractError.SignatureRequestDenied)) { throw new Error(AssetBuyerError.SignatureRequestDenied); - } else if (_.includes(err.message, ForwarderWrapperError.CompleteFillFailed)) { + } else if (_.includes(err.message, ForwarderError.CompleteFillFailed)) { throw new Error(AssetBuyerError.TransactionValueTooLow); } else { throw err; @@ -357,13 +362,13 @@ export class AssetBuyer { * Will throw if WETH does not exist for the current network. */ private _getEtherTokenAssetDataOrThrow(): string { - return assetDataUtils.getEtherTokenAssetData(this._contractWrappers); + return assetDataUtils.encodeERC20AssetData(this._contractWrappers.contractAddresses.etherToken); } /** * Get the assetData that represents the ZRX token. * Will throw if ZRX does not exist for the current network. */ private _getZrxTokenAssetDataOrThrow(): string { - return this._contractWrappers.exchange.getZRXAssetData(); + return assetDataUtils.encodeERC20AssetData(this._contractWrappers.contractAddresses.zrxToken); } } diff --git a/packages/asset-buyer/src/utils/asset_data_utils.ts b/packages/asset-buyer/src/utils/asset_data_utils.ts deleted file mode 100644 index 70f6469020..0000000000 --- a/packages/asset-buyer/src/utils/asset_data_utils.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ContractWrappers } from '@0x/contract-wrappers'; -import { assetDataUtils as sharedAssetDataUtils } from '@0x/order-utils'; -import * as _ from 'lodash'; - -export const assetDataUtils = { - ...sharedAssetDataUtils, - getEtherTokenAssetData(contractWrappers: ContractWrappers): string { - const etherTokenAddress = contractWrappers.forwarder.etherTokenAddress; - const etherTokenAssetData = sharedAssetDataUtils.encodeERC20AssetData(etherTokenAddress); - return etherTokenAssetData; - }, -}; diff --git a/packages/asset-buyer/src/utils/number_percentage_to_ethertoken_amount_percentage.ts b/packages/asset-buyer/src/utils/number_percentage_to_ethertoken_amount_percentage.ts new file mode 100644 index 0000000000..05c3830a9d --- /dev/null +++ b/packages/asset-buyer/src/utils/number_percentage_to_ethertoken_amount_percentage.ts @@ -0,0 +1,9 @@ +import { BigNumber } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; + +// HACK (xianny): copied from asset-swapper, which will replace this package +const ONE_AMOUNT = new BigNumber(1); +const ETHER_TOKEN_DECIMALS = 18; +export const numberPercentageToEtherTokenAmountPercentage = (percentage: number): BigNumber => { + return Web3Wrapper.toBaseUnitAmount(ONE_AMOUNT, ETHER_TOKEN_DECIMALS).multipliedBy(percentage); +}; diff --git a/packages/asset-buyer/src/utils/order_provider_response_processor.ts b/packages/asset-buyer/src/utils/order_provider_response_processor.ts index cb25f98701..300cb14299 100644 --- a/packages/asset-buyer/src/utils/order_provider_response_processor.ts +++ b/packages/asset-buyer/src/utils/order_provider_response_processor.ts @@ -1,4 +1,4 @@ -import { OrderAndTraderInfo, OrderStatus, OrderValidatorWrapper } from '@0x/contract-wrappers'; +import { OrderAndTraderInfo, OrderStatus, OrderValidatorContract } from '@0x/contract-wrappers'; import { orderCalculationUtils, sortingUtils } from '@0x/order-utils'; import { RemainingFillableCalculator } from '@0x/order-utils/lib/src/remaining_fillable_calculator'; import { SignedOrder } from '@0x/types'; @@ -34,7 +34,7 @@ export const orderProviderResponseProcessor = { orderProviderResponse: OrderProviderResponse, isMakerAssetZrxToken: boolean, expiryBufferSeconds: number, - orderValidator?: OrderValidatorWrapper, + orderValidator?: OrderValidatorContract, ): Promise { // drop orders that are expired or not open const filteredOrders = filterOutExpiredAndNonOpenOrders(orderProviderResponse.orders, expiryBufferSeconds); @@ -44,10 +44,16 @@ export const orderProviderResponseProcessor = { if (orderValidator !== undefined) { const takerAddresses = _.map(filteredOrders, () => constants.NULL_ADDRESS); try { - const ordersAndTradersInfo = await orderValidator.getOrdersAndTradersInfoAsync( + const [ordersInfo, tradersInfo] = await orderValidator.getOrdersAndTradersInfo.callAsync( filteredOrders, takerAddresses, ); + const ordersAndTradersInfo = ordersInfo.map((orderInfo, index) => { + return { + orderInfo, + traderInfo: tradersInfo[index], + }; + }); // take orders + on chain information and find the valid orders and remaining fillable maker asset amounts unsortedOrders = getValidOrdersWithRemainingFillableMakerAssetAmountsFromOnChain( filteredOrders, diff --git a/packages/asset-swapper/package.json b/packages/asset-swapper/package.json index aef6a5d21d..1c9d003bea 100644 --- a/packages/asset-swapper/package.json +++ b/packages/asset-swapper/package.json @@ -40,7 +40,7 @@ "@0x/assert": "^2.1.3", "@0x/connect": "^5.0.16", "@0x/contract-addresses": "^3.0.3", - "@0x/contract-wrappers": "9.1.7", + "@0x/contract-wrappers": "^11.0.0", "@0x/dev-utils": "^2.3.0", "@0x/fill-scenarios": "^3.0.16", "@0x/json-schemas": "^3.1.13", diff --git a/packages/asset-swapper/src/quote_consumers/exchange_swap_quote_consumer.ts b/packages/asset-swapper/src/quote_consumers/exchange_swap_quote_consumer.ts index 9d4badd8cd..981513fcf3 100644 --- a/packages/asset-swapper/src/quote_consumers/exchange_swap_quote_consumer.ts +++ b/packages/asset-swapper/src/quote_consumers/exchange_swap_quote_consumer.ts @@ -1,4 +1,4 @@ -import { ContractWrappers, ContractWrappersError, ForwarderWrapperError } from '@0x/contract-wrappers'; +import { ContractError, ContractWrappers, ForwarderError } from '@0x/contract-wrappers'; import { MarketOperation } from '@0x/types'; import { AbiEncoder, providerUtils } from '@0x/utils'; import { SupportedProvider, ZeroExProvider } from '@0x/web3-wrapper'; @@ -144,34 +144,34 @@ export class ExchangeSwapQuoteConsumer implements SwapQuoteConsumerBase o.signature), { - gasLimit, + from: finalTakerAddress, + gas: gasLimit, gasPrice, - shouldValidate: true, }, ); } else { const { takerAssetFillAmount } = quote; - txHash = await this._contractWrappers.exchange.marketSellOrdersNoThrowAsync( + txHash = await this._contractWrappers.exchange.marketSellOrdersNoThrow.validateAndSendTransactionAsync( orders, takerAssetFillAmount, - finalTakerAddress, + orders.map(o => o.signature), { - gasLimit, + from: finalTakerAddress, + gas: gasLimit, gasPrice, - shouldValidate: true, }, ); } return txHash; } catch (err) { - if (_.includes(err.message, ContractWrappersError.SignatureRequestDenied)) { + if (_.includes(err.message, ContractError.SignatureRequestDenied)) { throw new Error(SwapQuoteConsumerError.SignatureRequestDenied); - } else if (_.includes(err.message, ForwarderWrapperError.CompleteFillFailed)) { + } else if (_.includes(err.message, ForwarderError.CompleteFillFailed)) { throw new Error(SwapQuoteConsumerError.TransactionValueTooLow); } else { throw err; diff --git a/packages/asset-swapper/src/quote_consumers/forwarder_swap_quote_consumer.ts b/packages/asset-swapper/src/quote_consumers/forwarder_swap_quote_consumer.ts index 00964c0c2b..afce2133a0 100644 --- a/packages/asset-swapper/src/quote_consumers/forwarder_swap_quote_consumer.ts +++ b/packages/asset-swapper/src/quote_consumers/forwarder_swap_quote_consumer.ts @@ -1,5 +1,5 @@ -import { ContractWrappers, ContractWrappersError, ForwarderWrapperError } from '@0x/contract-wrappers'; -import { calldataOptimizationUtils } from '@0x/contract-wrappers/lib/src/utils/calldata_optimization_utils'; +import { ContractError, ContractWrappers, ForwarderError } from '@0x/contract-wrappers'; +import { assetDataUtils } from '@0x/order-utils'; import { MarketOperation } from '@0x/types'; import { AbiEncoder, providerUtils } from '@0x/utils'; import { SupportedProvider, ZeroExProvider } from '@0x/web3-wrapper'; @@ -20,7 +20,6 @@ import { } from '../types'; import { affiliateFeeUtils } from '../utils/affiliate_fee_utils'; import { assert } from '../utils/assert'; -import { assetDataUtils } from '../utils/asset_data_utils'; import { swapQuoteConsumerUtils } from '../utils/swap_quote_consumer_utils'; import { utils } from '../utils/utils'; @@ -103,9 +102,6 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase o.signature); const feeSignatures = _.map(feeOrders, o => o.signature); @@ -119,10 +115,10 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase o.signature), feeOrders, - feePercentage, + feeOrders.map(o => o.signature), + formattedFeePercentage, feeRecipient, { - gasLimit, + value, + from: finalTakerAddress.toLowerCase(), + gas: gasLimit, gasPrice, - shouldValidate: true, }, ); } else { - txHash = await this._contractWrappers.forwarder.marketSellOrdersWithEthAsync( + txHash = await this._contractWrappers.forwarder.marketSellOrdersWithEth.validateAndSendTransactionAsync( orders, - finalTakerAddress, - ethAmount || worstCaseQuoteInfo.totalTakerTokenAmount, + orders.map(o => o.signature), feeOrders, - feePercentage, + feeOrders.map(o => o.signature), + formattedFeePercentage, feeRecipient, { - gasLimit, + value, + from: finalTakerAddress.toLowerCase(), + gas: gasLimit, gasPrice, - shouldValidate: true, }, ); } return txHash; } catch (err) { - if (_.includes(err.message, ContractWrappersError.SignatureRequestDenied)) { + if (_.includes(err.message, ContractError.SignatureRequestDenied)) { throw new Error(SwapQuoteConsumerError.SignatureRequestDenied); - } else if (_.includes(err.message, ForwarderWrapperError.CompleteFillFailed)) { + } else if (_.includes(err.message, ForwarderError.CompleteFillFailed)) { throw new Error(SwapQuoteConsumerError.TransactionValueTooLow); } else { throw err; @@ -239,6 +241,6 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase { - const orderValidatorWrapper = this._contractWrappers.orderValidator; - const balanceAndAllowance = await orderValidatorWrapper.getBalanceAndAllowanceAsync( + const orderValidator = this._contractWrappers.orderValidator; + const balanceAndAllowance = await orderValidator.getBalanceAndAllowance.callAsync( takerAddress, swapQuote.takerAssetData, ); + const allowance = balanceAndAllowance[1]; return [ - balanceAndAllowance.allowance.isGreaterThanOrEqualTo(swapQuote.bestCaseQuoteInfo.totalTakerTokenAmount), - balanceAndAllowance.allowance.isGreaterThanOrEqualTo(swapQuote.worstCaseQuoteInfo.totalTakerTokenAmount), + allowance.isGreaterThanOrEqualTo(swapQuote.bestCaseQuoteInfo.totalTakerTokenAmount), + allowance.isGreaterThanOrEqualTo(swapQuote.worstCaseQuoteInfo.totalTakerTokenAmount), ]; } @@ -398,7 +398,7 @@ export class SwapQuoter { * Will throw if ZRX does not exist for the current network. */ private _getZrxTokenAssetDataOrThrow(): string { - return this._contractWrappers.exchange.getZRXAssetData(); + return assetDataUtils.encodeERC20AssetData(this._contractWrappers.contractAddresses.zrxToken); } /** diff --git a/packages/asset-swapper/src/utils/asset_data_utils.ts b/packages/asset-swapper/src/utils/asset_data_utils.ts deleted file mode 100644 index 70f6469020..0000000000 --- a/packages/asset-swapper/src/utils/asset_data_utils.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ContractWrappers } from '@0x/contract-wrappers'; -import { assetDataUtils as sharedAssetDataUtils } from '@0x/order-utils'; -import * as _ from 'lodash'; - -export const assetDataUtils = { - ...sharedAssetDataUtils, - getEtherTokenAssetData(contractWrappers: ContractWrappers): string { - const etherTokenAddress = contractWrappers.forwarder.etherTokenAddress; - const etherTokenAssetData = sharedAssetDataUtils.encodeERC20AssetData(etherTokenAddress); - return etherTokenAssetData; - }, -}; diff --git a/packages/asset-swapper/src/utils/order_provider_response_processor.ts b/packages/asset-swapper/src/utils/order_provider_response_processor.ts index 16dfe4bc1f..42d2f36f57 100644 --- a/packages/asset-swapper/src/utils/order_provider_response_processor.ts +++ b/packages/asset-swapper/src/utils/order_provider_response_processor.ts @@ -1,4 +1,4 @@ -import { OrderAndTraderInfo, OrderStatus, OrderValidatorWrapper } from '@0x/contract-wrappers'; +import { OrderAndTraderInfo, OrderStatus, OrderValidatorContract } from '@0x/contract-wrappers'; import { orderCalculationUtils, sortingUtils } from '@0x/order-utils'; import { RemainingFillableCalculator } from '@0x/order-utils/lib/src/remaining_fillable_calculator'; import { SignedOrder } from '@0x/types'; @@ -34,7 +34,7 @@ export const orderProviderResponseProcessor = { orderProviderResponse: OrderProviderResponse, isMakerAssetZrxToken: boolean, expiryBufferMs: number, - orderValidator?: OrderValidatorWrapper, + orderValidator?: OrderValidatorContract, ): Promise { // drop orders that are expired or not open const filteredOrders = filterOutExpiredAndNonOpenOrders( @@ -47,10 +47,17 @@ export const orderProviderResponseProcessor = { if (orderValidator !== undefined) { const takerAddresses = _.map(filteredOrders, () => constants.NULL_ADDRESS); try { - const ordersAndTradersInfo = await orderValidator.getOrdersAndTradersInfoAsync( + const [ordersInfo, tradersInfo] = await orderValidator.getOrdersAndTradersInfo.callAsync( filteredOrders, takerAddresses, ); + const ordersAndTradersInfo: OrderAndTraderInfo[] = ordersInfo.map((orderInfo, index) => { + const singleOrderAndTraderInfo: OrderAndTraderInfo = { + orderInfo, + traderInfo: tradersInfo[index], + }; + return singleOrderAndTraderInfo; + }); // take orders + on chain information and find the valid orders and remaining fillable maker asset amounts unsortedOrders = getValidOrdersWithRemainingFillableMakerAssetAmountsFromOnChain( filteredOrders, diff --git a/packages/asset-swapper/src/utils/swap_quote_consumer_utils.ts b/packages/asset-swapper/src/utils/swap_quote_consumer_utils.ts index 543a992d51..8420f2ad93 100644 --- a/packages/asset-swapper/src/utils/swap_quote_consumer_utils.ts +++ b/packages/asset-swapper/src/utils/swap_quote_consumer_utils.ts @@ -1,4 +1,5 @@ import { ContractWrappers } from '@0x/contract-wrappers'; +import { assetDataUtils } from '@0x/order-utils'; import { MarketOperation, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { SupportedProvider, Web3Wrapper } from '@0x/web3-wrapper'; @@ -15,7 +16,6 @@ import { } from '../types'; import { assert } from './assert'; -import { assetDataUtils } from './asset_data_utils'; export const swapQuoteConsumerUtils = { async getTakerAddressOrThrowAsync( @@ -52,9 +52,8 @@ export const swapQuoteConsumerUtils = { takerAddress: string, ): Promise<[BigNumber, BigNumber]> { const web3Wrapper = new Web3Wrapper(provider); - const wethAddress = contractWrappers.forwarder.etherTokenAddress; const ethBalance = await web3Wrapper.getBalanceInWeiAsync(takerAddress); - const wethBalance = await contractWrappers.erc20Token.getBalanceAsync(wethAddress, takerAddress); + const wethBalance = await contractWrappers.weth9.balanceOf.callAsync(takerAddress); return [ethBalance, wethBalance]; }, isValidForwarderSwapQuote(swapQuote: SwapQuote, wethAssetData: string): boolean { @@ -86,7 +85,7 @@ export const swapQuoteConsumerUtils = { provider: Provider, opts: Partial, ): Promise { - const wethAssetData = assetDataUtils.getEtherTokenAssetData(contractWrappers); + const wethAssetData = assetDataUtils.encodeERC20AssetData(contractWrappers.contractAddresses.etherToken); if (swapQuoteConsumerUtils.isValidForwarderSwapQuote(quote, wethAssetData)) { if (opts.takerAddress !== undefined) { assert.isETHAddressHex('takerAddress', opts.takerAddress); diff --git a/packages/asset-swapper/test/exchange_swap_quote_consumer_test.ts b/packages/asset-swapper/test/exchange_swap_quote_consumer_test.ts index ae0a9e1efc..553c1990af 100644 --- a/packages/asset-swapper/test/exchange_swap_quote_consumer_test.ts +++ b/packages/asset-swapper/test/exchange_swap_quote_consumer_test.ts @@ -1,4 +1,4 @@ -import { ContractAddresses, ContractWrappers } from '@0x/contract-wrappers'; +import { ContractAddresses, ContractWrappers, ERC20TokenContract } from '@0x/contract-wrappers'; import { BlockchainLifecycle, tokenUtils } from '@0x/dev-utils'; import { FillScenarios } from '@0x/fill-scenarios'; import { assetDataUtils } from '@0x/order-utils'; @@ -35,6 +35,7 @@ const FILLABLE_AMOUNTS = [new BigNumber(3), new BigNumber(2), new BigNumber(5)]. describe('ExchangeSwapQuoteConsumer', () => { let contractWrappers: ContractWrappers; let userAddresses: string[]; + let erc20TokenContract: ERC20TokenContract; let coinbaseAddress: string; let makerAddress: string; let takerAddress: string; @@ -78,6 +79,7 @@ describe('ExchangeSwapQuoteConsumer', () => { assetDataUtils.encodeERC20AssetData(takerTokenAddress), assetDataUtils.encodeERC20AssetData(contractAddresses.etherToken), ]; + erc20TokenContract = new ERC20TokenContract(makerTokenAddress, provider); }); after(async () => { await blockchainLifecycle.revertAsync(); @@ -123,24 +125,24 @@ describe('ExchangeSwapQuoteConsumer', () => { * Does not test the validity of the state change performed by the forwarder smart contract */ it('should perform a marketSell execution when provided a MarketSell type swapQuote', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); await swapQuoteConsumer.executeSwapQuoteOrThrowAsync(marketSellSwapQuote, { takerAddress }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress); + takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress); expect(takerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(makerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); }); it('should perform a marketBuy execution when provided a MarketBuy type swapQuote', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); await swapQuoteConsumer.executeSwapQuoteOrThrowAsync(marketBuySwapQuote, { takerAddress }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress); + takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress); expect(takerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(makerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); }); @@ -183,8 +185,8 @@ describe('ExchangeSwapQuoteConsumer', () => { describe('getCalldataOrThrow', () => { describe('valid swap quote', async () => { it('provide correct and optimized calldata options with default options for a marketSell SwapQuote (no affiliate fees)', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); const { calldataHexString, toAddress } = await swapQuoteConsumer.getCalldataOrThrowAsync( @@ -198,14 +200,14 @@ describe('ExchangeSwapQuoteConsumer', () => { data: calldataHexString, gas: 4000000, }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress); + takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress); expect(takerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(makerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); }); it('provide correct and optimized calldata options with default options for a marketBuy SwapQuote (no affiliate fees)', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); const { calldataHexString, toAddress } = await swapQuoteConsumer.getCalldataOrThrowAsync( @@ -219,8 +221,8 @@ describe('ExchangeSwapQuoteConsumer', () => { data: calldataHexString, gas: 4000000, }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20TokenContract.balanceOf.callAsync(makerAddress); + takerBalance = await erc20TokenContract.balanceOf.callAsync(takerAddress); expect(takerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(makerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); }); diff --git a/packages/asset-swapper/test/forwarder_swap_quote_consumer_test.ts b/packages/asset-swapper/test/forwarder_swap_quote_consumer_test.ts index 9fef5a35b7..c4ed8f1bcd 100644 --- a/packages/asset-swapper/test/forwarder_swap_quote_consumer_test.ts +++ b/packages/asset-swapper/test/forwarder_swap_quote_consumer_test.ts @@ -1,4 +1,4 @@ -import { ContractAddresses, ContractWrappers } from '@0x/contract-wrappers'; +import { ContractAddresses, ContractWrappers, ERC20TokenContract } from '@0x/contract-wrappers'; import { BlockchainLifecycle, tokenUtils } from '@0x/dev-utils'; import { assetDataUtils } from '@0x/order-utils'; import { MarketOperation, SignedOrder } from '@0x/types'; @@ -30,9 +30,11 @@ const MARKET_OPERATION = MarketOperation.Sell; const FILLABLE_AMOUNTS = [new BigNumber(2), new BigNumber(3), new BigNumber(5)].map(value => value.multipliedBy(ONE_ETH_IN_WEI), ); +const UNLIMITED_ALLOWANCE_IN_BASE_UNITS = new BigNumber(2).pow(256).minus(1); // tslint:disable-line:custom-no-magic-numbers describe('ForwarderSwapQuoteConsumer', () => { let contractWrappers: ContractWrappers; + let erc20Token: ERC20TokenContract; let userAddresses: string[]; let coinbaseAddress: string; let makerAddress: string; @@ -63,6 +65,7 @@ describe('ForwarderSwapQuoteConsumer', () => { contractWrappers = new ContractWrappers(provider, config); [coinbaseAddress, takerAddress, makerAddress, feeRecipient] = userAddresses; [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); + erc20Token = new ERC20TokenContract(makerTokenAddress, provider); [makerAssetData, takerAssetData, wethAssetData] = [ assetDataUtils.encodeERC20AssetData(makerTokenAddress), assetDataUtils.encodeERC20AssetData(takerTokenAddress), @@ -74,7 +77,7 @@ describe('ForwarderSwapQuoteConsumer', () => { }); beforeEach(async () => { await blockchainLifecycle.startAsync(); - const UNLIMITED_ALLOWANCE = contractWrappers.erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; + const UNLIMITED_ALLOWANCE = UNLIMITED_ALLOWANCE_IN_BASE_UNITS; erc20ProxyAddress = contractWrappers.erc20Proxy.address; const totalFillableAmount = FILLABLE_AMOUNTS.reduce( @@ -82,19 +85,13 @@ describe('ForwarderSwapQuoteConsumer', () => { new BigNumber(0), ); - await contractWrappers.erc20Token.transferAsync( - makerTokenAddress, - coinbaseAddress, - makerAddress, - totalFillableAmount, - ); + await erc20Token.transfer.sendTransactionAsync(makerAddress, totalFillableAmount, { + from: coinbaseAddress, + }); - await contractWrappers.erc20Token.setAllowanceAsync( - makerTokenAddress, - makerAddress, - erc20ProxyAddress, - UNLIMITED_ALLOWANCE, - ); + await erc20Token.approve.sendTransactionAsync(erc20ProxyAddress, UNLIMITED_ALLOWANCE, { + from: makerAddress, + }); orders = await getSignedOrdersWithNoFeesAsync( provider, makerAssetData, @@ -158,32 +155,32 @@ describe('ForwarderSwapQuoteConsumer', () => { * Does not test the validity of the state change performed by the forwarder smart contract */ it('should perform a marketSell execution when provided a MarketSell type swapQuote', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); await swapQuoteConsumer.executeSwapQuoteOrThrowAsync(marketSellSwapQuote, { takerAddress }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(0.5).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(new BigNumber(9.5).multipliedBy(ONE_ETH_IN_WEI)); }); it('should perform a marketBuy execution when provided a MarketBuy type swapQuote', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); await swapQuoteConsumer.executeSwapQuoteOrThrowAsync(marketBuySwapQuote, { takerAddress }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); expect(takerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(makerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); }); it('should perform a marketBuy execution with affiliate fees', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); const feeRecipientEthBalanceBefore = await web3Wrapper.getBalanceInWeiAsync(feeRecipient); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); @@ -192,8 +189,8 @@ describe('ForwarderSwapQuoteConsumer', () => { feePercentage: 0.05, feeRecipient, }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); const feeRecipientEthBalanceAfter = await web3Wrapper.getBalanceInWeiAsync(feeRecipient); expect(makerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); expect(takerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); @@ -204,15 +201,15 @@ describe('ForwarderSwapQuoteConsumer', () => { // TODO(david) Finish marketSell affiliate fee excution testing // it('should perform a marketSell execution with affiliate fees', async () => { - // let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - // let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + // let makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + // let takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); // const feeRecipientEthBalanceBefore = await web3Wrapper.getBalanceInWeiAsync(feeRecipient); // expect(makerBalance).to.bignumber.equal((new BigNumber(10)).multipliedBy(ONE_ETH_IN_WEI)); // expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); // console.log(makerBalance, takerBalance, feeRecipientEthBalanceBefore); // await swapQuoteConsumer.executeSwapQuoteOrThrowAsync(marketSellSwapQuote, { takerAddress, feePercentage: 0.05, feeRecipient }); - // makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - // takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + // makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + // takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); // const feeRecipientEthBalanceAfter = await web3Wrapper.getBalanceInWeiAsync(feeRecipient); // console.log(makerBalance, takerBalance, feeRecipientEthBalanceAfter); // expect(makerBalance).to.bignumber.equal((new BigNumber(0.5)).multipliedBy(ONE_ETH_IN_WEI)); @@ -368,8 +365,8 @@ describe('ForwarderSwapQuoteConsumer', () => { describe('valid swap quote', async () => { it('provide correct and optimized calldata options with default options for a marketSell SwapQuote (no affiliate fees)', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); const { calldataHexString, toAddress } = await swapQuoteConsumer.getCalldataOrThrowAsync( @@ -384,14 +381,14 @@ describe('ForwarderSwapQuoteConsumer', () => { value: marketSellSwapQuote.worstCaseQuoteInfo.totalTakerTokenAmount, gas: 4000000, }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(0.5).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(new BigNumber(9.5).multipliedBy(ONE_ETH_IN_WEI)); }); it('provide correct and optimized calldata options with default options for a marketBuy SwapQuote (no affiliate fees)', async () => { - let makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - let takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + let makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + let takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); expect(makerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(takerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); const { calldataHexString, toAddress } = await swapQuoteConsumer.getCalldataOrThrowAsync( @@ -406,8 +403,8 @@ describe('ForwarderSwapQuoteConsumer', () => { value: marketBuySwapQuote.worstCaseQuoteInfo.totalTakerTokenAmount, gas: 4000000, }); - makerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, makerAddress); - takerBalance = await contractWrappers.erc20Token.getBalanceAsync(makerTokenAddress, takerAddress); + makerBalance = await erc20Token.balanceOf.callAsync(makerAddress); + takerBalance = await erc20Token.balanceOf.callAsync(takerAddress); expect(takerBalance).to.bignumber.equal(new BigNumber(10).multipliedBy(ONE_ETH_IN_WEI)); expect(makerBalance).to.bignumber.equal(constants.ZERO_AMOUNT); }); diff --git a/packages/asset-swapper/test/swap_quote_consumer_utils_test.ts b/packages/asset-swapper/test/swap_quote_consumer_utils_test.ts index 9ed535c7ce..821e318ba1 100644 --- a/packages/asset-swapper/test/swap_quote_consumer_utils_test.ts +++ b/packages/asset-swapper/test/swap_quote_consumer_utils_test.ts @@ -146,7 +146,7 @@ describe('swapQuoteConsumerUtils', () => { }); it('should return exchange consumer if takerAsset is wEth and taker has enough weth', async () => { const etherInWei = new BigNumber(20).multipliedBy(ONE_ETH_IN_WEI); - await contractWrappers.etherToken.depositAsync(contractAddresses.etherToken, etherInWei, takerAddress); + await contractWrappers.weth9.deposit.sendTransactionAsync({ value: etherInWei, from: takerAddress }); const consumerType = await swapQuoteConsumerUtils.getConsumerTypeForSwapQuoteAsync( forwarderSwapQuote, contractWrappers, @@ -157,7 +157,7 @@ describe('swapQuoteConsumerUtils', () => { }); it('should return forwarder consumer if takerAsset is wEth and takerAddress has no available balance in either weth or eth (defaulting behavior)', async () => { const etherInWei = new BigNumber(50).multipliedBy(ONE_ETH_IN_WEI); - await contractWrappers.etherToken.depositAsync(contractAddresses.etherToken, etherInWei, takerAddress); + await contractWrappers.weth9.deposit.sendTransactionAsync({ value: etherInWei, from: takerAddress }); const consumerType = await swapQuoteConsumerUtils.getConsumerTypeForSwapQuoteAsync( largeForwarderSwapQuote, contractWrappers, diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index 40a4751eaa..51d804ea59 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "11.1.0", + "changes": [ + { + "note": "Add `contractAddresses` to `ContractWrappers` class. Add `validateAndSendTransactionAsync` to all methods. Add interfaces ForwarderError, ContractError, TraderInfo, OrderAndTraderInfo.", + "pr": 2068 + } + ] + }, { "version": "11.0.0", "changes": [ diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index 6d0e55910b..7cb94410b2 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -51,11 +51,7 @@ "@0x/assert": "^2.1.3", "@0x/contracts-test-utils": "^3.1.12", "@0x/coordinator-server": "^0.1.3", - "@0x/dev-utils": "^2.2.6", - "@0x/fill-scenarios": "^3.0.15", "@0x/json-schemas": "^3.1.13", - "@0x/migrations": "^4.1.11", - "@0x/subproviders": "^5.0.0", "@0x/tslint-config": "^3.0.1", "@0x/types": "^2.4.1", "@0x/utils": "^4.5.0", @@ -73,12 +69,9 @@ "shx": "^0.2.2" }, "dependencies": { - "@0x/abi-gen-wrappers": "^5.2.0", "@0x/base-contract": "^5.3.1", "@0x/contract-addresses": "^3.0.3", "@0x/contract-artifacts": "^2.0.4", - "@0x/contracts-test-utils": "^3.1.13", - "@0x/coordinator-server": "^0.1.3", "@0x/dev-utils": "^2.3.0", "@0x/fill-scenarios": "^3.0.16", "@0x/migrations": "^4.2.0", diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts index 7eae2ef857..f216b773eb 100644 --- a/packages/contract-wrappers/src/contract_wrappers.ts +++ b/packages/contract-wrappers/src/contract_wrappers.ts @@ -1,3 +1,4 @@ +import { ContractAddresses } from '@0x/contract-addresses'; import { Coordinator, DutchAuction, @@ -22,7 +23,6 @@ import { ERC721ProxyContract } from './generated-wrappers/erc721_proxy'; import { ExchangeContract } from './generated-wrappers/exchange'; import { ForwarderContract } from './generated-wrappers/forwarder'; import { OrderValidatorContract } from './generated-wrappers/order_validator'; - import { WETH9Contract } from './generated-wrappers/weth9'; import { ContractWrappersConfigSchema } from './schemas/contract_wrappers_config_schema'; import { ContractWrappersConfig } from './types'; @@ -33,6 +33,10 @@ import { _getDefaultContractAddresses } from './utils/contract_addresses'; * The ContractWrappers class contains smart contract wrappers helpful when building on 0x protocol. */ export class ContractWrappers { + /** + * An index of the default contract addresses for this network. + */ + public contractAddresses: ContractAddresses; /** * An instance of the ExchangeContract class containing methods for interacting with the 0x Exchange smart contract. */ @@ -116,6 +120,7 @@ export class ContractWrappers { contractAddresses.exchange, contractAddresses.coordinatorRegistry, ); + this.contractAddresses = contractAddresses; } /** * Unsubscribes from all subscriptions for all contracts. diff --git a/packages/contract-wrappers/src/generated-wrappers/asset_proxy_owner.ts b/packages/contract-wrappers/src/generated-wrappers/asset_proxy_owner.ts index 4255ed3678..503097b573 100644 --- a/packages/contract-wrappers/src/generated-wrappers/asset_proxy_owner.ts +++ b/packages/contract-wrappers/src/generated-wrappers/asset_proxy_owner.ts @@ -336,6 +336,11 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(owner: string, txData?: Partial | undefined): Promise { + await (this as any).removeOwner.callAsync(owner, txData); + const txHash = await (this as any).removeOwner.sendTransactionAsync(owner, txData); + return txHash; + }, }; /** * Allows an owner to revoke a confirmation for a transaction. @@ -492,6 +497,14 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + transactionId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).revokeConfirmation.callAsync(transactionId, txData); + const txHash = await (this as any).revokeConfirmation.sendTransactionAsync(transactionId, txData); + return txHash; + }, }; public isOwner = { /** @@ -803,6 +816,17 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + transactionId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).executeRemoveAuthorizedAddressAtIndex.callAsync(transactionId, txData); + const txHash = await (this as any).executeRemoveAuthorizedAddressAtIndex.sendTransactionAsync( + transactionId, + txData, + ); + return txHash; + }, }; public secondsTimeLocked = { /** @@ -1138,6 +1162,19 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + assetProxyContract: string, + isRegistered: boolean, + txData?: Partial | undefined, + ): Promise { + await (this as any).registerAssetProxy.callAsync(assetProxyContract, isRegistered, txData); + const txHash = await (this as any).registerAssetProxy.sendTransactionAsync( + assetProxyContract, + isRegistered, + txData, + ); + return txHash; + }, }; /** * Allows to add a new owner. Transaction has to be sent by wallet. @@ -1288,6 +1325,11 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(owner: string, txData?: Partial | undefined): Promise { + await (this as any).addOwner.callAsync(owner, txData); + const txHash = await (this as any).addOwner.sendTransactionAsync(owner, txData); + return txHash; + }, }; /** * Returns the confirmation status of a transaction. @@ -1526,6 +1568,14 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _secondsTimeLocked: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).changeTimeLock.callAsync(_secondsTimeLocked, txData); + const txHash = await (this as any).changeTimeLock.sendTransactionAsync(_secondsTimeLocked, txData); + return txHash; + }, }; public isAssetProxyRegistered = { /** @@ -2195,6 +2245,14 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _required: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).changeRequirement.callAsync(_required, txData); + const txHash = await (this as any).changeRequirement.sendTransactionAsync(_required, txData); + return txHash; + }, }; /** * Allows an owner to confirm a transaction. @@ -2351,6 +2409,14 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + transactionId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).confirmTransaction.callAsync(transactionId, txData); + const txHash = await (this as any).confirmTransaction.sendTransactionAsync(transactionId, txData); + return txHash; + }, }; /** * Allows an owner to submit and confirm a transaction. @@ -2561,6 +2627,16 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + destination: string, + value: BigNumber, + data: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).submitTransaction.callAsync(destination, value, data, txData); + const txHash = await (this as any).submitTransaction.sendTransactionAsync(destination, value, data, txData); + return txHash; + }, }; public confirmationTimes = { /** @@ -2939,6 +3015,15 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + owner: string, + newOwner: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).replaceOwner.callAsync(owner, newOwner, txData); + const txHash = await (this as any).replaceOwner.sendTransactionAsync(owner, newOwner, txData); + return txHash; + }, }; /** * Allows anyone to execute a confirmed transaction. @@ -3095,6 +3180,14 @@ export class AssetProxyOwnerContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + transactionId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).executeTransaction.callAsync(transactionId, txData); + const txHash = await (this as any).executeTransaction.sendTransactionAsync(transactionId, txData); + return txHash; + }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/coordinator.ts b/packages/contract-wrappers/src/generated-wrappers/coordinator.ts index 13d6bcff1d..bc74cf6cf7 100644 --- a/packages/contract-wrappers/src/generated-wrappers/coordinator.ts +++ b/packages/contract-wrappers/src/generated-wrappers/coordinator.ts @@ -567,6 +567,32 @@ export class CoordinatorContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + transaction: { salt: BigNumber; signerAddress: string; data: string }, + txOrigin: string, + transactionSignature: string, + approvalExpirationTimeSeconds: BigNumber[], + approvalSignatures: string[], + txData?: Partial | undefined, + ): Promise { + await (this as any).executeTransaction.callAsync( + transaction, + txOrigin, + transactionSignature, + approvalExpirationTimeSeconds, + approvalSignatures, + txData, + ); + const txHash = await (this as any).executeTransaction.sendTransactionAsync( + transaction, + txOrigin, + transactionSignature, + approvalExpirationTimeSeconds, + approvalSignatures, + txData, + ); + return txHash; + }, }; public EIP712_EXCHANGE_DOMAIN_HASH = { /** diff --git a/packages/contract-wrappers/src/generated-wrappers/coordinator_registry.ts b/packages/contract-wrappers/src/generated-wrappers/coordinator_registry.ts index 373136ce51..26a74b5ed4 100644 --- a/packages/contract-wrappers/src/generated-wrappers/coordinator_registry.ts +++ b/packages/contract-wrappers/src/generated-wrappers/coordinator_registry.ts @@ -201,6 +201,14 @@ export class CoordinatorRegistryContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + coordinatorEndpoint: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).setCoordinatorEndpoint.callAsync(coordinatorEndpoint, txData); + const txHash = await (this as any).setCoordinatorEndpoint.sendTransactionAsync(coordinatorEndpoint, txData); + return txHash; + }, }; /** * Gets the endpoint for a Coordinator. diff --git a/packages/contract-wrappers/src/generated-wrappers/dummy_erc20_token.ts b/packages/contract-wrappers/src/generated-wrappers/dummy_erc20_token.ts index 6dbf9f4b02..78a1056f5a 100644 --- a/packages/contract-wrappers/src/generated-wrappers/dummy_erc20_token.ts +++ b/packages/contract-wrappers/src/generated-wrappers/dummy_erc20_token.ts @@ -302,6 +302,15 @@ export class DummyERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _spender: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).approve.callAsync(_spender, _value, txData); + const txHash = await (this as any).approve.sendTransactionAsync(_spender, _value, txData); + return txHash; + }, }; /** * Query total supply of token @@ -578,6 +587,16 @@ export class DummyERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transferFrom.callAsync(_from, _to, _value, txData); + const txHash = await (this as any).transferFrom.sendTransactionAsync(_from, _to, _value, txData); + return txHash; + }, }; public decimals = { /** @@ -988,6 +1007,14 @@ export class DummyERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).mint.callAsync(_value, txData); + const txHash = await (this as any).mint.sendTransactionAsync(_value, txData); + return txHash; + }, }; /** * send `value` token to `to` from `msg.sender` @@ -1162,6 +1189,15 @@ export class DummyERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _to: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transfer.callAsync(_to, _value, txData); + const txHash = await (this as any).transfer.sendTransactionAsync(_to, _value, txData); + return txHash; + }, }; public allowance = { /** @@ -1430,6 +1466,15 @@ export class DummyERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _target: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).setBalance.callAsync(_target, _value, txData); + const txHash = await (this as any).setBalance.sendTransactionAsync(_target, _value, txData); + return txHash; + }, }; public transferOwnership = { /** @@ -1574,6 +1619,11 @@ export class DummyERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + await (this as any).transferOwnership.callAsync(newOwner, txData); + const txHash = await (this as any).transferOwnership.sendTransactionAsync(newOwner, txData); + return txHash; + }, }; public MAX_MINT_AMOUNT = { /** diff --git a/packages/contract-wrappers/src/generated-wrappers/dummy_erc721_token.ts b/packages/contract-wrappers/src/generated-wrappers/dummy_erc721_token.ts index 0d5780f909..2068a03154 100644 --- a/packages/contract-wrappers/src/generated-wrappers/dummy_erc721_token.ts +++ b/packages/contract-wrappers/src/generated-wrappers/dummy_erc721_token.ts @@ -387,6 +387,15 @@ export class DummyERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _approved: string, + _tokenId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).approve.callAsync(_approved, _tokenId, txData); + const txHash = await (this as any).approve.sendTransactionAsync(_approved, _tokenId, txData); + return txHash; + }, }; /** * Throws unless `msg.sender` is the current owner, an authorized @@ -599,6 +608,16 @@ export class DummyERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _tokenId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transferFrom.callAsync(_from, _to, _tokenId, txData); + const txHash = await (this as any).transferFrom.sendTransactionAsync(_from, _to, _tokenId, txData); + return txHash; + }, }; /** * Function to mint a new token @@ -777,6 +796,15 @@ export class DummyERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _to: string, + _tokenId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).mint.callAsync(_to, _tokenId, txData); + const txHash = await (this as any).mint.sendTransactionAsync(_to, _tokenId, txData); + return txHash; + }, }; /** * This works identically to the other function with an extra data parameter, @@ -987,6 +1015,16 @@ export class DummyERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _tokenId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).safeTransferFrom1.callAsync(_from, _to, _tokenId, txData); + const txHash = await (this as any).safeTransferFrom1.sendTransactionAsync(_from, _to, _tokenId, txData); + return txHash; + }, }; /** * NFTs assigned to zero address are considered invalid, and queries @@ -1439,6 +1477,15 @@ export class DummyERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _owner: string, + _tokenId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).burn.callAsync(_owner, _tokenId, txData); + const txHash = await (this as any).burn.sendTransactionAsync(_owner, _tokenId, txData); + return txHash; + }, }; /** * Emits the ApprovalForAll event. The contract MUST allow @@ -1630,6 +1677,15 @@ export class DummyERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _operator: string, + _approved: boolean, + txData?: Partial | undefined, + ): Promise { + await (this as any).setApprovalForAll.callAsync(_operator, _approved, txData); + const txHash = await (this as any).setApprovalForAll.sendTransactionAsync(_operator, _approved, txData); + return txHash; + }, }; /** * Throws unless `msg.sender` is the current owner, an authorized @@ -1868,6 +1924,23 @@ export class DummyERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _tokenId: BigNumber, + _data: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).safeTransferFrom2.callAsync(_from, _to, _tokenId, _data, txData); + const txHash = await (this as any).safeTransferFrom2.sendTransactionAsync( + _from, + _to, + _tokenId, + _data, + txData, + ); + return txHash; + }, }; public isApprovedForAll = { /** @@ -2094,6 +2167,11 @@ export class DummyERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + await (this as any).transferOwnership.callAsync(newOwner, txData); + const txHash = await (this as any).transferOwnership.sendTransactionAsync(newOwner, txData); + return txHash; + }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/dutch_auction.ts b/packages/contract-wrappers/src/generated-wrappers/dutch_auction.ts index b4ab61b8de..50cd951647 100644 --- a/packages/contract-wrappers/src/generated-wrappers/dutch_auction.ts +++ b/packages/contract-wrappers/src/generated-wrappers/dutch_auction.ts @@ -311,6 +311,27 @@ export class DutchAuctionContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + order: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + txData?: Partial | undefined, + ): Promise { + await (this as any).getAuctionDetails.callAsync(order, txData); + const txHash = await (this as any).getAuctionDetails.sendTransactionAsync(order, txData); + return txHash; + }, }; /** * Matches the buy and sell orders at an amount given the following: the current block time, the auction @@ -775,6 +796,49 @@ export class DutchAuctionContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + buyOrder: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + sellOrder: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + buySignature: string, + sellSignature: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).matchOrders.callAsync(buyOrder, sellOrder, buySignature, sellSignature, txData); + const txHash = await (this as any).matchOrders.sendTransactionAsync( + buyOrder, + sellOrder, + buySignature, + sellSignature, + txData, + ); + return txHash; + }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/contract-wrappers/src/generated-wrappers/erc20_proxy.ts b/packages/contract-wrappers/src/generated-wrappers/erc20_proxy.ts index 0b9f9752cd..192facec79 100644 --- a/packages/contract-wrappers/src/generated-wrappers/erc20_proxy.ts +++ b/packages/contract-wrappers/src/generated-wrappers/erc20_proxy.ts @@ -205,6 +205,11 @@ export class ERC20ProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + await (this as any).addAuthorizedAddress.callAsync(target, txData); + const txHash = await (this as any).addAuthorizedAddress.sendTransactionAsync(target, txData); + return txHash; + }, }; public authorities = { /** @@ -425,6 +430,11 @@ export class ERC20ProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + await (this as any).removeAuthorizedAddress.callAsync(target, txData); + const txHash = await (this as any).removeAuthorizedAddress.sendTransactionAsync(target, txData); + return txHash; + }, }; public owner = { /** @@ -677,6 +687,19 @@ export class ERC20ProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + target: string, + index: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).removeAuthorizedAddressAtIndex.callAsync(target, index, txData); + const txHash = await (this as any).removeAuthorizedAddressAtIndex.sendTransactionAsync( + target, + index, + txData, + ); + return txHash; + }, }; /** * Gets the proxy id associated with the proxy address. @@ -1023,6 +1046,11 @@ export class ERC20ProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + await (this as any).transferOwnership.callAsync(newOwner, txData); + const txHash = await (this as any).transferOwnership.sendTransactionAsync(newOwner, txData); + return txHash; + }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/erc20_token.ts b/packages/contract-wrappers/src/generated-wrappers/erc20_token.ts index e910137065..cb734f6ffd 100644 --- a/packages/contract-wrappers/src/generated-wrappers/erc20_token.ts +++ b/packages/contract-wrappers/src/generated-wrappers/erc20_token.ts @@ -240,6 +240,15 @@ export class ERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _spender: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).approve.callAsync(_spender, _value, txData); + const txHash = await (this as any).approve.sendTransactionAsync(_spender, _value, txData); + return txHash; + }, }; /** * Query total supply of token @@ -516,6 +525,16 @@ export class ERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transferFrom.callAsync(_from, _to, _value, txData); + const txHash = await (this as any).transferFrom.sendTransactionAsync(_from, _to, _value, txData); + return txHash; + }, }; /** * Query the balance of owner @@ -764,6 +783,15 @@ export class ERC20TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _to: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transfer.callAsync(_to, _value, txData); + const txHash = await (this as any).transfer.sendTransactionAsync(_to, _value, txData); + return txHash; + }, }; public allowance = { /** diff --git a/packages/contract-wrappers/src/generated-wrappers/erc721_proxy.ts b/packages/contract-wrappers/src/generated-wrappers/erc721_proxy.ts index 63af02b710..b49f64cf62 100644 --- a/packages/contract-wrappers/src/generated-wrappers/erc721_proxy.ts +++ b/packages/contract-wrappers/src/generated-wrappers/erc721_proxy.ts @@ -205,6 +205,11 @@ export class ERC721ProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + await (this as any).addAuthorizedAddress.callAsync(target, txData); + const txHash = await (this as any).addAuthorizedAddress.sendTransactionAsync(target, txData); + return txHash; + }, }; public authorities = { /** @@ -425,6 +430,11 @@ export class ERC721ProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + await (this as any).removeAuthorizedAddress.callAsync(target, txData); + const txHash = await (this as any).removeAuthorizedAddress.sendTransactionAsync(target, txData); + return txHash; + }, }; public owner = { /** @@ -677,6 +687,19 @@ export class ERC721ProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + target: string, + index: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).removeAuthorizedAddressAtIndex.callAsync(target, index, txData); + const txHash = await (this as any).removeAuthorizedAddressAtIndex.sendTransactionAsync( + target, + index, + txData, + ); + return txHash; + }, }; /** * Gets the proxy id associated with the proxy address. @@ -1023,6 +1046,11 @@ export class ERC721ProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + await (this as any).transferOwnership.callAsync(newOwner, txData); + const txHash = await (this as any).transferOwnership.sendTransactionAsync(newOwner, txData); + return txHash; + }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/erc721_token.ts b/packages/contract-wrappers/src/generated-wrappers/erc721_token.ts index 422f748c94..cae997baac 100644 --- a/packages/contract-wrappers/src/generated-wrappers/erc721_token.ts +++ b/packages/contract-wrappers/src/generated-wrappers/erc721_token.ts @@ -325,6 +325,15 @@ export class ERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _approved: string, + _tokenId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).approve.callAsync(_approved, _tokenId, txData); + const txHash = await (this as any).approve.sendTransactionAsync(_approved, _tokenId, txData); + return txHash; + }, }; /** * Throws unless `msg.sender` is the current owner, an authorized @@ -537,6 +546,16 @@ export class ERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _tokenId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transferFrom.callAsync(_from, _to, _tokenId, txData); + const txHash = await (this as any).transferFrom.sendTransactionAsync(_from, _to, _tokenId, txData); + return txHash; + }, }; /** * This works identically to the other function with an extra data parameter, @@ -747,6 +766,16 @@ export class ERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _tokenId: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).safeTransferFrom1.callAsync(_from, _to, _tokenId, txData); + const txHash = await (this as any).safeTransferFrom1.sendTransactionAsync(_from, _to, _tokenId, txData); + return txHash; + }, }; /** * NFTs assigned to zero address are considered invalid, and queries @@ -1088,6 +1117,15 @@ export class ERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _operator: string, + _approved: boolean, + txData?: Partial | undefined, + ): Promise { + await (this as any).setApprovalForAll.callAsync(_operator, _approved, txData); + const txHash = await (this as any).setApprovalForAll.sendTransactionAsync(_operator, _approved, txData); + return txHash; + }, }; /** * Throws unless `msg.sender` is the current owner, an authorized @@ -1326,6 +1364,23 @@ export class ERC721TokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _tokenId: BigNumber, + _data: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).safeTransferFrom2.callAsync(_from, _to, _tokenId, _data, txData); + const txHash = await (this as any).safeTransferFrom2.sendTransactionAsync( + _from, + _to, + _tokenId, + _data, + txData, + ); + return txHash; + }, }; public isApprovedForAll = { /** diff --git a/packages/contract-wrappers/src/generated-wrappers/exchange.ts b/packages/contract-wrappers/src/generated-wrappers/exchange.ts index 2df6b7ae3b..482c5c3efd 100644 --- a/packages/contract-wrappers/src/generated-wrappers/exchange.ts +++ b/packages/contract-wrappers/src/generated-wrappers/exchange.ts @@ -477,6 +477,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + takerAssetFillAmounts: BigNumber[], + signatures: string[], + txData?: Partial | undefined, + ): Promise { + await (this as any).batchFillOrders.callAsync(orders, takerAssetFillAmounts, signatures, txData); + const txHash = await (this as any).batchFillOrders.sendTransactionAsync( + orders, + takerAssetFillAmounts, + signatures, + txData, + ); + return txHash; + }, }; public cancelled = { /** @@ -750,6 +778,16 @@ export class ExchangeContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + hash: string, + signerAddress: string, + signature: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).preSign.callAsync(hash, signerAddress, signature, txData); + const txHash = await (this as any).preSign.sendTransactionAsync(hash, signerAddress, signature, txData); + return txHash; + }, }; /** * Match two complementary orders that have a profitable spread. @@ -1193,6 +1231,49 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + leftOrder: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + rightOrder: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + leftSignature: string, + rightSignature: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).matchOrders.callAsync(leftOrder, rightOrder, leftSignature, rightSignature, txData); + const txHash = await (this as any).matchOrders.sendTransactionAsync( + leftOrder, + rightOrder, + leftSignature, + rightSignature, + txData, + ); + return txHash; + }, }; /** * Fills the input order. @@ -1504,6 +1585,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + order: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + takerAssetFillAmount: BigNumber, + signature: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).fillOrderNoThrow.callAsync(order, takerAssetFillAmount, signature, txData); + const txHash = await (this as any).fillOrderNoThrow.sendTransactionAsync( + order, + takerAssetFillAmount, + signature, + txData, + ); + return txHash; + }, }; public assetProxies = { /** @@ -1813,6 +1922,27 @@ export class ExchangeContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + txData?: Partial | undefined, + ): Promise { + await (this as any).batchCancelOrders.callAsync(orders, txData); + const txHash = await (this as any).batchCancelOrders.sendTransactionAsync(orders, txData); + return txHash; + }, }; /** * Synchronously executes multiple calls of fillOrKill. @@ -2133,6 +2263,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + takerAssetFillAmounts: BigNumber[], + signatures: string[], + txData?: Partial | undefined, + ): Promise { + await (this as any).batchFillOrKillOrders.callAsync(orders, takerAssetFillAmounts, signatures, txData); + const txHash = await (this as any).batchFillOrKillOrders.sendTransactionAsync( + orders, + takerAssetFillAmounts, + signatures, + txData, + ); + return txHash; + }, }; /** * Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch @@ -2295,6 +2453,14 @@ export class ExchangeContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + targetOrderEpoch: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).cancelOrdersUpTo.callAsync(targetOrderEpoch, txData); + const txHash = await (this as any).cancelOrdersUpTo.sendTransactionAsync(targetOrderEpoch, txData); + return txHash; + }, }; /** * Fills an order with specified parameters and ECDSA signature. @@ -2616,6 +2782,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + takerAssetFillAmounts: BigNumber[], + signatures: string[], + txData?: Partial | undefined, + ): Promise { + await (this as any).batchFillOrdersNoThrow.callAsync(orders, takerAssetFillAmounts, signatures, txData); + const txHash = await (this as any).batchFillOrdersNoThrow.sendTransactionAsync( + orders, + takerAssetFillAmounts, + signatures, + txData, + ); + return txHash; + }, }; /** * Gets an asset proxy. @@ -3067,6 +3261,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + order: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + takerAssetFillAmount: BigNumber, + signature: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).fillOrKillOrder.callAsync(order, takerAssetFillAmount, signature, txData); + const txHash = await (this as any).fillOrKillOrder.sendTransactionAsync( + order, + takerAssetFillAmount, + signature, + txData, + ); + return txHash; + }, }; /** * Approves/unnapproves a Validator contract to verify signatures on signer's behalf. @@ -3261,6 +3483,19 @@ export class ExchangeContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + validatorAddress: string, + approval: boolean, + txData?: Partial | undefined, + ): Promise { + await (this as any).setSignatureValidatorApproval.callAsync(validatorAddress, approval, txData); + const txHash = await (this as any).setSignatureValidatorApproval.sendTransactionAsync( + validatorAddress, + approval, + txData, + ); + return txHash; + }, }; public allowedValidators = { /** @@ -3653,6 +3888,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + takerAssetFillAmount: BigNumber, + signatures: string[], + txData?: Partial | undefined, + ): Promise { + await (this as any).marketSellOrders.callAsync(orders, takerAssetFillAmount, signatures, txData); + const txHash = await (this as any).marketSellOrders.sendTransactionAsync( + orders, + takerAssetFillAmount, + signatures, + txData, + ); + return txHash; + }, }; /** * Fetches information for all passed in orders. @@ -4324,6 +4587,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + makerAssetFillAmount: BigNumber, + signatures: string[], + txData?: Partial | undefined, + ): Promise { + await (this as any).marketBuyOrdersNoThrow.callAsync(orders, makerAssetFillAmount, signatures, txData); + const txHash = await (this as any).marketBuyOrdersNoThrow.sendTransactionAsync( + orders, + makerAssetFillAmount, + signatures, + txData, + ); + return txHash; + }, }; /** * Fills the input order. @@ -4629,6 +4920,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + order: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + takerAssetFillAmount: BigNumber, + signature: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).fillOrder.callAsync(order, takerAssetFillAmount, signature, txData); + const txHash = await (this as any).fillOrder.sendTransactionAsync( + order, + takerAssetFillAmount, + signature, + txData, + ); + return txHash; + }, }; /** * Executes an exchange method call in the context of signer. @@ -4855,6 +5174,23 @@ export class ExchangeContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + salt: BigNumber, + signerAddress: string, + data: string, + signature: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).executeTransaction.callAsync(salt, signerAddress, data, signature, txData); + const txHash = await (this as any).executeTransaction.sendTransactionAsync( + salt, + signerAddress, + data, + signature, + txData, + ); + return txHash; + }, }; /** * Registers an asset proxy to its asset proxy id. @@ -5012,6 +5348,14 @@ export class ExchangeContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + assetProxy: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).registerAssetProxy.callAsync(assetProxy, txData); + const txHash = await (this as any).registerAssetProxy.sendTransactionAsync(assetProxy, txData); + return txHash; + }, }; /** * Gets information about an order: status, hash, and amount filled. @@ -5377,6 +5721,27 @@ export class ExchangeContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + order: { + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }, + txData?: Partial | undefined, + ): Promise { + await (this as any).cancelOrder.callAsync(order, txData); + const txHash = await (this as any).cancelOrder.sendTransactionAsync(order, txData); + return txHash; + }, }; public orderEpoch = { /** @@ -5832,6 +6197,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + takerAssetFillAmount: BigNumber, + signatures: string[], + txData?: Partial | undefined, + ): Promise { + await (this as any).marketSellOrdersNoThrow.callAsync(orders, takerAssetFillAmount, signatures, txData); + const txHash = await (this as any).marketSellOrdersNoThrow.sendTransactionAsync( + orders, + takerAssetFillAmount, + signatures, + txData, + ); + return txHash; + }, }; public EIP712_DOMAIN_HASH = { /** @@ -6209,6 +6602,34 @@ export class ExchangeContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + makerAssetFillAmount: BigNumber, + signatures: string[], + txData?: Partial | undefined, + ): Promise { + await (this as any).marketBuyOrders.callAsync(orders, makerAssetFillAmount, signatures, txData); + const txHash = await (this as any).marketBuyOrders.sendTransactionAsync( + orders, + makerAssetFillAmount, + signatures, + txData, + ); + return txHash; + }, }; public currentContextAddress = { /** @@ -6415,6 +6836,11 @@ export class ExchangeContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + await (this as any).transferOwnership.callAsync(newOwner, txData); + const txHash = await (this as any).transferOwnership.sendTransactionAsync(newOwner, txData); + return txHash; + }, }; public VERSION = { /** diff --git a/packages/contract-wrappers/src/generated-wrappers/forwarder.ts b/packages/contract-wrappers/src/generated-wrappers/forwarder.ts index d7d643b2ac..e76c4c014f 100644 --- a/packages/contract-wrappers/src/generated-wrappers/forwarder.ts +++ b/packages/contract-wrappers/src/generated-wrappers/forwarder.ts @@ -584,6 +584,64 @@ export class ForwarderContract extends BaseContract { >(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + makerAssetFillAmount: BigNumber, + signatures: string[], + feeOrders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + feeSignatures: string[], + feePercentage: BigNumber, + feeRecipient: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).marketBuyOrdersWithEth.callAsync( + orders, + makerAssetFillAmount, + signatures, + feeOrders, + feeSignatures, + feePercentage, + feeRecipient, + txData, + ); + const txHash = await (this as any).marketBuyOrdersWithEth.sendTransactionAsync( + orders, + makerAssetFillAmount, + signatures, + feeOrders, + feeSignatures, + feePercentage, + feeRecipient, + txData, + ); + return txHash; + }, }; /** * Withdraws assets from this contract. The contract requires a ZRX balance in order to @@ -763,6 +821,15 @@ export class ForwarderContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + assetData: string, + amount: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).withdrawAsset.callAsync(assetData, amount, txData); + const txHash = await (this as any).withdrawAsset.sendTransactionAsync(assetData, amount, txData); + return txHash; + }, }; public owner = { /** @@ -1335,6 +1402,61 @@ export class ForwarderContract extends BaseContract { >(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + orders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + signatures: string[], + feeOrders: Array<{ + makerAddress: string; + takerAddress: string; + feeRecipientAddress: string; + senderAddress: string; + makerAssetAmount: BigNumber; + takerAssetAmount: BigNumber; + makerFee: BigNumber; + takerFee: BigNumber; + expirationTimeSeconds: BigNumber; + salt: BigNumber; + makerAssetData: string; + takerAssetData: string; + }>, + feeSignatures: string[], + feePercentage: BigNumber, + feeRecipient: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).marketSellOrdersWithEth.callAsync( + orders, + signatures, + feeOrders, + feeSignatures, + feePercentage, + feeRecipient, + txData, + ); + const txHash = await (this as any).marketSellOrdersWithEth.sendTransactionAsync( + orders, + signatures, + feeOrders, + feeSignatures, + feePercentage, + feeRecipient, + txData, + ); + return txHash; + }, }; public transferOwnership = { /** @@ -1479,6 +1601,11 @@ export class ForwarderContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + await (this as any).transferOwnership.callAsync(newOwner, txData); + const txHash = await (this as any).transferOwnership.sendTransactionAsync(newOwner, txData); + return txHash; + }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/contract-wrappers/src/generated-wrappers/i_asset_proxy.ts b/packages/contract-wrappers/src/generated-wrappers/i_asset_proxy.ts index 00b079a261..ffa9c8e7e6 100644 --- a/packages/contract-wrappers/src/generated-wrappers/i_asset_proxy.ts +++ b/packages/contract-wrappers/src/generated-wrappers/i_asset_proxy.ts @@ -178,6 +178,11 @@ export class IAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + await (this as any).addAuthorizedAddress.callAsync(target, txData); + const txHash = await (this as any).addAuthorizedAddress.sendTransactionAsync(target, txData); + return txHash; + }, }; /** * Removes authorizion of an address. @@ -330,6 +335,11 @@ export class IAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + await (this as any).removeAuthorizedAddress.callAsync(target, txData); + const txHash = await (this as any).removeAuthorizedAddress.sendTransactionAsync(target, txData); + return txHash; + }, }; /** * Removes authorizion of an address. @@ -520,6 +530,19 @@ export class IAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + target: string, + index: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).removeAuthorizedAddressAtIndex.callAsync(target, index, txData); + const txHash = await (this as any).removeAuthorizedAddressAtIndex.sendTransactionAsync( + target, + index, + txData, + ); + return txHash; + }, }; /** * Transfers assets. Either succeeds or throws. @@ -746,6 +769,17 @@ export class IAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + assetData: string, + from: string, + to: string, + amount: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transferFrom.callAsync(assetData, from, to, amount, txData); + const txHash = await (this as any).transferFrom.sendTransactionAsync(assetData, from, to, amount, txData); + return txHash; + }, }; /** * Gets the proxy id associated with the proxy address. @@ -1022,6 +1056,11 @@ export class IAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + await (this as any).transferOwnership.callAsync(newOwner, txData); + const txHash = await (this as any).transferOwnership.sendTransactionAsync(newOwner, txData); + return txHash; + }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/contract-wrappers/src/generated-wrappers/multi_asset_proxy.ts b/packages/contract-wrappers/src/generated-wrappers/multi_asset_proxy.ts index 676dab94b4..f1df53a9d2 100644 --- a/packages/contract-wrappers/src/generated-wrappers/multi_asset_proxy.ts +++ b/packages/contract-wrappers/src/generated-wrappers/multi_asset_proxy.ts @@ -276,6 +276,11 @@ export class MultiAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + await (this as any).addAuthorizedAddress.callAsync(target, txData); + const txHash = await (this as any).addAuthorizedAddress.sendTransactionAsync(target, txData); + return txHash; + }, }; public authorities = { /** @@ -570,6 +575,11 @@ export class MultiAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + await (this as any).removeAuthorizedAddress.callAsync(target, txData); + const txHash = await (this as any).removeAuthorizedAddress.sendTransactionAsync(target, txData); + return txHash; + }, }; public owner = { /** @@ -822,6 +832,19 @@ export class MultiAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + target: string, + index: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).removeAuthorizedAddressAtIndex.callAsync(target, index, txData); + const txHash = await (this as any).removeAuthorizedAddressAtIndex.sendTransactionAsync( + target, + index, + txData, + ); + return txHash; + }, }; /** * Gets the proxy id associated with the proxy address. @@ -1115,6 +1138,14 @@ export class MultiAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + assetProxy: string, + txData?: Partial | undefined, + ): Promise { + await (this as any).registerAssetProxy.callAsync(assetProxy, txData); + const txHash = await (this as any).registerAssetProxy.sendTransactionAsync(assetProxy, txData); + return txHash; + }, }; /** * Gets all authorized addresses. @@ -1325,6 +1356,11 @@ export class MultiAssetProxyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + await (this as any).transferOwnership.callAsync(newOwner, txData); + const txHash = await (this as any).transferOwnership.sendTransactionAsync(newOwner, txData); + return txHash; + }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/contract-wrappers/src/generated-wrappers/weth9.ts b/packages/contract-wrappers/src/generated-wrappers/weth9.ts index 208683f64b..1de423d9ea 100644 --- a/packages/contract-wrappers/src/generated-wrappers/weth9.ts +++ b/packages/contract-wrappers/src/generated-wrappers/weth9.ts @@ -287,6 +287,15 @@ export class WETH9Contract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + guy: string, + wad: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).approve.callAsync(guy, wad, txData); + const txHash = await (this as any).approve.sendTransactionAsync(guy, wad, txData); + return txHash; + }, }; public totalSupply = { /** @@ -540,6 +549,16 @@ export class WETH9Contract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + src: string, + dst: string, + wad: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transferFrom.callAsync(src, dst, wad, txData); + const txHash = await (this as any).transferFrom.sendTransactionAsync(src, dst, wad, txData); + return txHash; + }, }; public withdraw = { /** @@ -682,6 +701,11 @@ export class WETH9Contract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(wad: BigNumber, txData?: Partial | undefined): Promise { + await (this as any).withdraw.callAsync(wad, txData); + const txHash = await (this as any).withdraw.sendTransactionAsync(wad, txData); + return txHash; + }, }; public decimals = { /** @@ -1032,6 +1056,15 @@ export class WETH9Contract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + dst: string, + wad: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transfer.callAsync(dst, wad, txData); + const txHash = await (this as any).transfer.sendTransactionAsync(dst, wad, txData); + return txHash; + }, }; public deposit = { /** @@ -1168,6 +1201,11 @@ export class WETH9Contract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync(txData?: Partial | undefined): Promise { + await (this as any).deposit.callAsync(txData); + const txHash = await (this as any).deposit.sendTransactionAsync(txData); + return txHash; + }, }; public allowance = { /** diff --git a/packages/contract-wrappers/src/generated-wrappers/zrx_token.ts b/packages/contract-wrappers/src/generated-wrappers/zrx_token.ts index 1ff3150abe..0a8a027f27 100644 --- a/packages/contract-wrappers/src/generated-wrappers/zrx_token.ts +++ b/packages/contract-wrappers/src/generated-wrappers/zrx_token.ts @@ -288,6 +288,15 @@ export class ZRXTokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _spender: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).approve.callAsync(_spender, _value, txData); + const txHash = await (this as any).approve.sendTransactionAsync(_spender, _value, txData); + return txHash; + }, }; public totalSupply = { /** @@ -560,6 +569,16 @@ export class ZRXTokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _from: string, + _to: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transferFrom.callAsync(_from, _to, _value, txData); + const txHash = await (this as any).transferFrom.sendTransactionAsync(_from, _to, _value, txData); + return txHash; + }, }; public decimals = { /** @@ -912,6 +931,15 @@ export class ZRXTokenContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + async validateAndSendTransactionAsync( + _to: string, + _value: BigNumber, + txData?: Partial | undefined, + ): Promise { + await (this as any).transfer.callAsync(_to, _value, txData); + const txHash = await (this as any).transfer.sendTransactionAsync(_to, _value, txData); + return txHash; + }, }; public allowance = { /** diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index 9fbb8d0f59..0cdaefd19b 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -24,4 +24,21 @@ export * from '@0x/contract-addresses'; export { ContractWrappers } from './contract_wrappers'; export { CoordinatorWrapper } from './coordinator_wrapper'; -export { OrderStatus } from './types'; + +export { BlockRange } from '@0x/base-contract'; +export { + OrderStatus, + ContractError, + ForwarderError, + OrderAndTraderInfo, + CoordinatorServerCancellationResponse, + CoordinatorServerError, + IndexedFilterValues, + ContractWrappersConfig, + OrderTransactionOpts, + TransactionOpts, + OrderInfo, + EventCallback, + DecodedLogEvent, + TraderInfo, +} from './types'; diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index 55f2d9ea29..46f189790f 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -24,6 +24,25 @@ export interface IndexedFilterValues { [index: string]: ContractEventArg; } +export enum ForwarderError { + CompleteFillFailed = 'COMPLETE_FILL_FAILED', +} + +export enum ContractError { + ContractNotDeployedOnNetwork = 'CONTRACT_NOT_DEPLOYED_ON_NETWORK', + InsufficientAllowanceForTransfer = 'INSUFFICIENT_ALLOWANCE_FOR_TRANSFER', + InsufficientBalanceForTransfer = 'INSUFFICIENT_BALANCE_FOR_TRANSFER', + InsufficientEthBalanceForDeposit = 'INSUFFICIENT_ETH_BALANCE_FOR_DEPOSIT', + InsufficientWEthBalanceForWithdrawal = 'INSUFFICIENT_WETH_BALANCE_FOR_WITHDRAWAL', + InvalidJump = 'INVALID_JUMP', + OutOfGas = 'OUT_OF_GAS', + SubscriptionNotFound = 'SUBSCRIPTION_NOT_FOUND', + SubscriptionAlreadyPresent = 'SUBSCRIPTION_ALREADY_PRESENT', + ERC721OwnerNotFound = 'ERC_721_OWNER_NOT_FOUND', + ERC721NoApproval = 'ERC_721_NO_APPROVAL', + SignatureRequestDenied = 'SIGNATURE_REQUEST_DENIED', +} + /** * networkId: The id of the underlying ethereum network your provider is connected to. (1-mainnet, 3-ropsten, 4-rinkeby, 42-kovan, 50-testrpc) * gasPrice: Gas price to use with every transaction @@ -72,6 +91,22 @@ export enum OrderStatus { Cancelled, } +export interface TraderInfo { + makerBalance: BigNumber; + makerAllowance: BigNumber; + takerBalance: BigNumber; + takerAllowance: BigNumber; + makerZrxBalance: BigNumber; + makerZrxAllowance: BigNumber; + takerZrxBalance: BigNumber; + takerZrxAllowance: BigNumber; +} + +export interface OrderAndTraderInfo { + orderInfo: OrderInfo; + traderInfo: TraderInfo; +} + export { CoordinatorServerCancellationResponse, CoordinatorServerError } from './utils/coordinator_server_types'; export interface CoordinatorTransaction { diff --git a/packages/contract-wrappers/src/utils/decorators.ts b/packages/contract-wrappers/src/utils/decorators.ts index b1cad0a235..5862f5017f 100644 --- a/packages/contract-wrappers/src/utils/decorators.ts +++ b/packages/contract-wrappers/src/utils/decorators.ts @@ -1,6 +1,6 @@ import * as _ from 'lodash'; -export enum ContractWrappersError { +export enum ContractError { ContractNotDeployedOnNetwork = 'CONTRACT_NOT_DEPLOYED_ON_NETWORK', InsufficientAllowanceForTransfer = 'INSUFFICIENT_ALLOWANCE_FOR_TRANSFER', InsufficientBalanceForTransfer = 'INSUFFICIENT_BALANCE_FOR_TRANSFER', @@ -31,10 +31,10 @@ type ErrorTransformer = (err: Error) => Error; const contractCallErrorTransformer = (error: Error) => { if (_.includes(error.message, constants.INVALID_JUMP_PATTERN)) { - return new Error(ContractWrappersError.InvalidJump); + return new Error(ContractError.InvalidJump); } if (_.includes(error.message, constants.OUT_OF_GAS_PATTERN)) { - return new Error(ContractWrappersError.OutOfGas); + return new Error(ContractError.OutOfGas); } if (_.includes(error.message, constants.REVERT)) { const revertReason = error.message.split(constants.REVERT)[1].trim(); @@ -57,7 +57,7 @@ const signatureRequestErrorTransformer = (error: Error) => { _.includes(error.message, constants.METAMASK_USER_DENIED_SIGNATURE_PATTERN) || _.includes(error.message, constants.TRUST_WALLET_USER_DENIED_SIGNATURE_PATTERN) ) { - const errMsg = ContractWrappersError.SignatureRequestDenied; + const errMsg = ContractError.SignatureRequestDenied; return new Error(errMsg); } return error; diff --git a/packages/contract-wrappers/test/coordinator_wrapper_test.ts b/packages/contract-wrappers/test/coordinator_wrapper_test.ts index 8735088a97..573b943b3e 100644 --- a/packages/contract-wrappers/test/coordinator_wrapper_test.ts +++ b/packages/contract-wrappers/test/coordinator_wrapper_test.ts @@ -1,4 +1,3 @@ -import { CoordinatorRegistryContract } from '@0x/abi-gen-wrappers'; import { constants } from '@0x/contracts-test-utils'; import { defaultOrmConfig, getAppAsync } from '@0x/coordinator-server'; import { BlockchainLifecycle, tokenUtils } from '@0x/dev-utils'; @@ -12,6 +11,7 @@ import 'mocha'; import * as nock from 'nock'; import { ContractWrappers } from '../src'; +import { CoordinatorRegistryContract } from '../src/index'; import { CoordinatorServerErrorMsg } from '../src/utils/coordinator_server_types'; import { chaiSetup } from './utils/chai_setup'; diff --git a/packages/contract-wrappers/test/utils/token_utils.ts b/packages/contract-wrappers/test/utils/token_utils.ts index 187a935b1b..903fa5b09d 100644 --- a/packages/contract-wrappers/test/utils/token_utils.ts +++ b/packages/contract-wrappers/test/utils/token_utils.ts @@ -1,7 +1,8 @@ -import { DummyERC721TokenContract } from '@0x/abi-gen-wrappers'; import { generatePseudoRandomSalt } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; +import { DummyERC721TokenContract } from '../../src/index'; + import { provider, txDefaults, web3Wrapper } from './web3_wrapper'; // Those addresses come from migrations. They're deterministic so it's relatively safe to hard-code them here. diff --git a/packages/monorepo-scripts/src/doc_gen_configs.ts b/packages/monorepo-scripts/src/doc_gen_configs.ts index b7e23fb289..d3e1fd25d6 100644 --- a/packages/monorepo-scripts/src/doc_gen_configs.ts +++ b/packages/monorepo-scripts/src/doc_gen_configs.ts @@ -60,12 +60,12 @@ export const docGenConfigs: DocGenConfigs = { 'NonceSubproviderErrors', 'Web3WrapperErrors', 'AssetBuyerError', - 'ContractWrappersError', + 'ContractError', 'TypedDataError', 'SwapQuoterError', 'SwapQuoteGetOutputOpts', 'SwapQuoteExecutionOpts', - 'ForwarderWrapperError', + 'ForwarderError', 'CoordinatorServerError', 'CoordinatorServerCancellationResponse', 'EventCallback', diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index 9be4b43b55..a5cec6ee4b 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -20,6 +20,7 @@ "license": "Apache-2.0", "dependencies": { "0x.js": "^6.0.15", + "@0x/contract-wrappers": "^11.0.0", "@0x/subproviders": "^5.0.1", "@0x/typescript-typings": "^4.2.4", "@0x/utils": "^4.5.0", diff --git a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts index 23dfc0db99..e66e51fe74 100644 --- a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts +++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts @@ -1,4 +1,4 @@ -import { ERC20TokenWrapper } from '0x.js'; +import { ERC20TokenContract, SupportedProvider } from '0x.js'; import { BigNumber, logUtils } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import * as _ from 'lodash'; @@ -37,7 +37,7 @@ export const dispenseAssetTasks = { recipientAddress: string, tokenSymbol: string, networkId: number, - erc20TokenWrapper: ERC20TokenWrapper, + provider: SupportedProvider, ): AsyncTask { return async () => { logUtils.log(`Processing ${tokenSymbol} ${recipientAddress}`); @@ -47,10 +47,8 @@ export const dispenseAssetTasks = { throw new Error(`Unsupported asset type: ${tokenSymbol}`); } const baseUnitAmount = Web3Wrapper.toBaseUnitAmount(amountToDispense, tokenIfExists.decimals); - const userBalanceBaseUnits = await erc20TokenWrapper.getBalanceAsync( - tokenIfExists.address, - recipientAddress, - ); + const erc20Token = new ERC20TokenContract(tokenIfExists.address, provider); + const userBalanceBaseUnits = await erc20Token.balanceOf.callAsync(recipientAddress); const maxAmountBaseUnits = Web3Wrapper.toBaseUnitAmount( new BigNumber(DISPENSE_MAX_AMOUNT_TOKEN), tokenIfExists.decimals, @@ -61,12 +59,9 @@ export const dispenseAssetTasks = { ); return; } - const txHash = await erc20TokenWrapper.transferAsync( - tokenIfExists.address, - configs.DISPENSER_ADDRESS, - recipientAddress, - baseUnitAmount, - ); + const txHash = await erc20Token.transfer.sendTransactionAsync(recipientAddress, baseUnitAmount, { + from: configs.DISPENSER_ADDRESS, + }); logUtils.log(`Sent ${amountToDispense} ${tokenSymbol} to ${recipientAddress} tx: ${txHash}`); }; }, diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index 08f3270d22..fafc1dad1c 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -124,7 +124,7 @@ export class Handler { recipient, requestedAssetType, networkConfig.networkId, - networkConfig.contractWrappers.erc20Token, + networkConfig.contractWrappers.getProvider(), ); break; default: diff --git a/packages/website/package.json b/packages/website/package.json index 7a51d9b484..3fbc9815b7 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -23,7 +23,7 @@ "dependencies": { "@0x/asset-buyer": "^6.1.11", "@0x/contract-addresses": "^3.0.3", - "@0x/contract-wrappers": "^9.1.7", + "@0x/contract-wrappers": "^11.0.0", "@0x/json-schemas": "^3.1.13", "@0x/order-utils": "^8.2.5", "@0x/subproviders": "^5.0.1", diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 1767384703..d458327be9 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -2,11 +2,13 @@ import { BlockRange, ContractWrappers, DecodedLogEvent, + ERC20TokenContract, ExchangeCancelEventArgs, ExchangeEventArgs, ExchangeEvents, ExchangeFillEventArgs, IndexedFilterValues, + WETH9Contract, } from '@0x/contract-wrappers'; import { assetDataUtils, orderHashUtils, signatureUtils } from '@0x/order-utils'; import { @@ -237,11 +239,12 @@ export class Blockchain { utils.assert(this._contractWrappers !== undefined, 'Contract Wrappers must be instantiated.'); this._showFlashMessageIfLedger(); - const txHash = await this._contractWrappers.erc20Token.setProxyAllowanceAsync( - token.address, - this._userAddressIfExists, + const erc20Token = new ERC20TokenContract(token.address, this._contractWrappers.getProvider()); + const txHash = await erc20Token.approve.sendTransactionAsync( + this._contractWrappers.contractAddresses.erc20Proxy, amountInBaseUnits, { + from: this._userAddressIfExists, gasPrice: this._defaultGasPrice, }, ); @@ -274,15 +277,11 @@ export class Blockchain { utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); this._showFlashMessageIfLedger(); - const txHash = await this._contractWrappers.erc20Token.transferAsync( - token.address, - this._userAddressIfExists, - toAddress, - amountInBaseUnits, - { - gasPrice: this._defaultGasPrice, - }, - ); + const erc20Token = new ERC20TokenContract(token.address, this._contractWrappers.getProvider()); + const txHash = await erc20Token.transfer.validateAndSendTransactionAsync(toAddress, amountInBaseUnits, { + from: this._userAddressIfExists, + gasPrice: this._defaultGasPrice, + }); await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash); const etherScanLinkIfExists = utils.getEtherScanLinkIfExists(txHash, this.networkId, EtherscanLinkSuffixes.Tx); this._dispatcher.showFlashMessage( @@ -299,11 +298,12 @@ export class Blockchain { utils.assert(this._contractWrappers !== undefined, 'ContractWrappers must be instantiated.'); utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); this._showFlashMessageIfLedger(); - const txHash = await this._contractWrappers.exchange.fillOrderAsync( + const txHash = await this._contractWrappers.exchange.fillOrder.validateAndSendTransactionAsync( signedOrder, fillTakerTokenAmount, - this._userAddressIfExists, + signedOrder.signature, { + from: this._userAddressIfExists, gasPrice: this._defaultGasPrice, }, ); @@ -316,7 +316,8 @@ export class Blockchain { } public async cancelOrderAsync(signedOrder: SignedOrder): Promise { this._showFlashMessageIfLedger(); - const txHash = await this._contractWrappers.exchange.cancelOrderAsync(signedOrder, { + const txHash = await this._contractWrappers.exchange.cancelOrder.validateAndSendTransactionAsync(signedOrder, { + from: signedOrder.makerAddress, gasPrice: this._defaultGasPrice, }); const receipt = await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash); @@ -329,7 +330,7 @@ export class Blockchain { public async getUnavailableTakerAmountAsync(orderHash: string): Promise { utils.assert(orderHashUtils.isValidOrderHash(orderHash), 'Must be valid orderHash'); utils.assert(this._contractWrappers !== undefined, 'ContractWrappers must be instantiated.'); - const unavailableTakerAmount = await this._contractWrappers.exchange.getFilledTakerAssetAmountAsync(orderHash); + const unavailableTakerAmount = await this._contractWrappers.exchange.filled.callAsync(orderHash); return unavailableTakerAmount; } public getExchangeContractAddressIfExists(): string | undefined { @@ -340,10 +341,13 @@ export class Blockchain { fillTakerTokenAmount: BigNumber, takerAddress: string, ): Promise { - await this._contractWrappers.exchange.validateFillOrderThrowIfInvalidAsync( + await this._contractWrappers.exchange.fillOrder.callAsync( signedOrder, fillTakerTokenAmount, - takerAddress, + signedOrder.signature, + { + from: takerAddress, + }, ); } public isValidAddress(address: string): boolean { @@ -420,14 +424,12 @@ export class Blockchain { utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); this._showFlashMessageIfLedger(); - const txHash = await this._contractWrappers.etherToken.depositAsync( - etherTokenAddress, - amount, - this._userAddressIfExists, - { - gasPrice: this._defaultGasPrice, - }, - ); + const etherToken = new WETH9Contract(etherTokenAddress, this._contractWrappers.getProvider()); + const txHash = await etherToken.deposit.validateAndSendTransactionAsync({ + value: amount, + from: this._userAddressIfExists, + gasPrice: this._defaultGasPrice, + }); await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash); } public async convertWrappedEthTokensToEthAsync(etherTokenAddress: string, amount: BigNumber): Promise { @@ -435,14 +437,11 @@ export class Blockchain { utils.assert(this._doesUserAddressExist(), BlockchainCallErrs.UserHasNoAssociatedAddresses); this._showFlashMessageIfLedger(); - const txHash = await this._contractWrappers.etherToken.withdrawAsync( - etherTokenAddress, - amount, - this._userAddressIfExists, - { - gasPrice: this._defaultGasPrice, - }, - ); + const etherToken = new WETH9Contract(etherTokenAddress, this._contractWrappers.getProvider()); + const txHash = await etherToken.withdraw.validateAndSendTransactionAsync(amount, { + from: this._userAddressIfExists, + gasPrice: this._defaultGasPrice, + }); await this._showEtherScanLinkAndAwaitTransactionMinedAsync(txHash); } public async doesContractExistAtAddressAsync(address: string): Promise { @@ -471,9 +470,13 @@ export class Blockchain { let balance = new BigNumber(0); let allowance = new BigNumber(0); if (this._doesUserAddressExist()) { + const erc20Token = new ERC20TokenContract(tokenAddress, this._contractWrappers.getProvider()); [balance, allowance] = await Promise.all([ - this._contractWrappers.erc20Token.getBalanceAsync(tokenAddress, ownerAddressIfExists), - this._contractWrappers.erc20Token.getProxyAllowanceAsync(tokenAddress, ownerAddressIfExists), + erc20Token.balanceOf.callAsync(ownerAddressIfExists), + erc20Token.allowance.callAsync( + ownerAddressIfExists, + this._contractWrappers.contractAddresses.erc20Proxy, + ), ]); } return [balance, allowance]; diff --git a/packages/website/ts/pages/governance/connect_form.tsx b/packages/website/ts/pages/governance/connect_form.tsx index ac056a75ee..63653d9870 100644 --- a/packages/website/ts/pages/governance/connect_form.tsx +++ b/packages/website/ts/pages/governance/connect_form.tsx @@ -1,5 +1,5 @@ import { getContractAddressesForNetworkOrThrow } from '@0x/contract-addresses'; -import { ContractWrappers } from '@0x/contract-wrappers'; +import { ContractWrappers, ERC20TokenContract } from '@0x/contract-wrappers'; import { ledgerEthereumBrowserClientFactoryAsync, LedgerSubprovider, @@ -221,8 +221,9 @@ export class ConnectForm extends React.Component { utils.assert(this._contractWrappers !== undefined, 'ContractWrappers must be instantiated.'); const contractAddresses = getContractAddressesForNetworkOrThrow(this.networkId); const tokenAddress: string = contractAddresses.zrxToken; + const erc20Token = new ERC20TokenContract(tokenAddress, this._contractWrappers.getProvider()); try { - const amount = await this._contractWrappers.erc20Token.getBalanceAsync(tokenAddress, owner); + const amount = await erc20Token.balanceOf.callAsync(owner); return amount; } catch (error) { return ZERO; diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 86e5b1fe78..eac022bd0b 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -1,4 +1,4 @@ -import { ContractWrappersError } from '@0x/contract-wrappers'; +import { ContractError } from '@0x/contract-wrappers'; import { assetDataUtils, TypedDataError } from '@0x/order-utils'; import { ExchangeContractErrs } from '@0x/types'; import { BigNumber } from '@0x/utils'; @@ -233,13 +233,13 @@ export const utils = { const isUniqueSymbol = tokenWithSameSymbolIfExists === undefined; return isUniqueName && isUniqueSymbol; }, - zeroExErrToHumanReadableErrMsg(error: ContractWrappersError | ExchangeContractErrs, takerAddress: string): string { - const ContractWrappersErrorToHumanReadableError: { [error: string]: string } = { + zeroExErrToHumanReadableErrMsg(error: ContractError | ExchangeContractErrs, takerAddress: string): string { + const ContractErrorToHumanReadableError: { [error: string]: string } = { [BlockchainCallErrs.UserHasNoAssociatedAddresses]: 'User has no addresses available', [TypedDataError.InvalidSignature]: 'Order signature is not valid', - [ContractWrappersError.ContractNotDeployedOnNetwork]: 'Contract is not deployed on the detected network', - [ContractWrappersError.InvalidJump]: 'Invalid jump occured while executing the transaction', - [ContractWrappersError.OutOfGas]: 'Transaction ran out of gas', + [ContractError.ContractNotDeployedOnNetwork]: 'Contract is not deployed on the detected network', + [ContractError.InvalidJump]: 'Invalid jump occured while executing the transaction', + [ContractError.OutOfGas]: 'Transaction ran out of gas', }; const exchangeContractErrorToHumanReadableError: { [error: string]: string; @@ -269,7 +269,7 @@ export const utils = { [ExchangeContractErrs.InsufficientRemainingFillAmount]: 'Insufficient remaining fill amount', }; const humanReadableErrorMsg = - exchangeContractErrorToHumanReadableError[error] || ContractWrappersErrorToHumanReadableError[error]; + exchangeContractErrorToHumanReadableError[error] || ContractErrorToHumanReadableError[error]; return humanReadableErrorMsg; }, isParityNode(nodeVersion: string): boolean {