diff --git a/.circleci/config.yml b/.circleci/config.yml index 43e2947822..54b86c86ee 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,7 +47,7 @@ jobs: - restore_cache: keys: - repo-{{ .Environment.CIRCLE_SHA1 }} - - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils @0x/contracts-staking + - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-tests @0x/contracts-staking test-exchange-ganache-3.0: resource_class: medium+ docker: @@ -67,7 +67,7 @@ jobs: - restore_cache: keys: - repo-{{ .Environment.CIRCLE_SHA1 }} - - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-asset-proxy @0x/contracts-exchange-forwarder @0x/contracts-dev-utils @0x/contracts-staking @0x/contracts-coordinator + - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-asset-proxy @0x/contracts-exchange-forwarder @0x/contracts-tests @0x/contracts-staking @0x/contracts-coordinator # TODO(dorothy-zbornak): Re-enable after updating this package for 3.0. # - run: yarn wsrun test:circleci @0x/contracts-extensions test-publish: diff --git a/contracts/asset-proxy/CHANGELOG.json b/contracts/asset-proxy/CHANGELOG.json index e51f943a2b..c601dcce07 100644 --- a/contracts/asset-proxy/CHANGELOG.json +++ b/contracts/asset-proxy/CHANGELOG.json @@ -29,6 +29,10 @@ { "note": "Add `UniswapBridge`", "pr": 2233 + }, + { + "note": "Replaced `SafeMath` with `LibSafeMath`", + "pr": 2254 } ], "timestamp": 1570135330 diff --git a/contracts/asset-proxy/contracts/src/ERC1155Proxy.sol b/contracts/asset-proxy/contracts/src/ERC1155Proxy.sol index 2e43635325..9ae6e5bc88 100644 --- a/contracts/asset-proxy/contracts/src/ERC1155Proxy.sol +++ b/contracts/asset-proxy/contracts/src/ERC1155Proxy.sol @@ -19,7 +19,7 @@ pragma solidity ^0.5.9; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "@0x/contracts-erc1155/contracts/src/interfaces/IERC1155.sol"; import "../archive/MixinAuthorizable.sol"; import "./interfaces/IAssetProxy.sol"; @@ -27,10 +27,10 @@ import "./interfaces/IAssetProxy.sol"; contract ERC1155Proxy is MixinAuthorizable, - SafeMath, IAssetProxy { using LibBytes for bytes; + using LibSafeMath for uint256; // Id of this proxy. bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC1155Assets(address,uint256[],uint256[],bytes)")); @@ -71,7 +71,7 @@ contract ERC1155Proxy is // to avoid copying over `ids` or `data`. This is possible if they are // identical to `values` and the offsets for each are pointing to the // same location in the ABI encoded calldata. - scaledValues[i] = _safeMul(values[i], amount); + scaledValues[i] = values[i].safeMul(amount); } // Execute `safeBatchTransferFrom` call diff --git a/contracts/asset-proxy/package.json b/contracts/asset-proxy/package.json index a39c3c18b5..4bd866af5b 100644 --- a/contracts/asset-proxy/package.json +++ b/contracts/asset-proxy/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", diff --git a/contracts/asset-proxy/test/authorizable.ts b/contracts/asset-proxy/test/authorizable.ts index 37b8cbaee1..4a7794734c 100644 --- a/contracts/asset-proxy/test/authorizable.ts +++ b/contracts/asset-proxy/test/authorizable.ts @@ -1,11 +1,4 @@ -import { - chaiSetup, - constants, - expectTransactionFailedAsync, - provider, - txDefaults, - web3Wrapper, -} from '@0x/contracts-test-utils'; +import { chaiSetup, expectTransactionFailedAsync, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { RevertReason } from '@0x/types'; import { BigNumber } from '@0x/utils'; @@ -60,21 +53,13 @@ describe('Authorizable', () => { }); it('should allow owner to add an authorized address', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const isAuthorized = await authorizable.authorized.callAsync(address); expect(isAuthorized).to.be.true(); }); it('should revert if owner attempts to authorize a duplicate address', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); return expectTransactionFailedAsync( authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }), RevertReason.TargetAlreadyAuthorized, @@ -84,11 +69,7 @@ describe('Authorizable', () => { describe('removeAuthorizedAddress', () => { it('should revert if not called by owner', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); await expectTransactionFailedAsync( authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: notOwner }), RevertReason.OnlyContractOwner, @@ -96,16 +77,8 @@ describe('Authorizable', () => { }); it('should allow owner to remove an authorized address', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); + await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const isAuthorized = await authorizable.authorized.callAsync(address); expect(isAuthorized).to.be.false(); }); @@ -122,11 +95,7 @@ describe('Authorizable', () => { describe('removeAuthorizedAddressAtIndex', () => { it('should revert if not called by owner', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const index = new BigNumber(0); await expectTransactionFailedAsync( authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, { @@ -137,11 +106,7 @@ describe('Authorizable', () => { }); it('should revert if index is >= authorities.length', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const index = new BigNumber(1); return expectTransactionFailedAsync( authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, { @@ -164,16 +129,8 @@ describe('Authorizable', () => { it('should revert if address at index does not match target', async () => { const address1 = address; const address2 = notOwner; - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address1, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address2, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address1, { from: owner }); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address2, { from: owner }); const address1Index = new BigNumber(0); return expectTransactionFailedAsync( authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address2, address1Index, { @@ -184,18 +141,11 @@ describe('Authorizable', () => { }); it('should allow owner to remove an authorized address', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const index = new BigNumber(0); - await authorizable.removeAuthorizedAddressAtIndex.awaitTransactionSuccessAsync( - address, - index, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.removeAuthorizedAddressAtIndex.awaitTransactionSuccessAsync(address, index, { + from: owner, + }); const isAuthorized = await authorizable.authorized.callAsync(address); expect(isAuthorized).to.be.false(); }); @@ -205,19 +155,11 @@ describe('Authorizable', () => { it('should return all authorized addresses', async () => { const initial = await authorizable.getAuthorizedAddresses.callAsync(); expect(initial).to.have.length(0); - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const afterAdd = await authorizable.getAuthorizedAddresses.callAsync(); expect(afterAdd).to.have.length(1); expect(afterAdd).to.include(address); - await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const afterRemove = await authorizable.getAuthorizedAddresses.callAsync(); expect(afterRemove).to.have.length(0); }); diff --git a/contracts/asset-proxy/test/erc1155_proxy.ts b/contracts/asset-proxy/test/erc1155_proxy.ts index 64783ba085..c06f351e23 100644 --- a/contracts/asset-proxy/test/erc1155_proxy.ts +++ b/contracts/asset-proxy/test/erc1155_proxy.ts @@ -72,16 +72,8 @@ describe('ERC1155Proxy', () => { const usedAddresses = ([owner, notAuthorized, authorized, spender, receiver] = _.slice(accounts, 0, 5)); erc1155ProxyWrapper = new ERC1155ProxyWrapper(provider, usedAddresses, owner); erc1155Proxy = await erc1155ProxyWrapper.deployProxyAsync(); - await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - authorized, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - erc1155Proxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(authorized, { from: owner }); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(erc1155Proxy.address, { from: owner }); // deploy & configure ERC1155 tokens and receiver [erc1155Wrapper] = await erc1155ProxyWrapper.deployDummyContractsAsync(); erc1155Contract = erc1155Wrapper.getContract(); @@ -696,25 +688,18 @@ describe('ERC1155Proxy', () => { const tokenUri = ''; for (const tokenToCreate of tokensToCreate) { // create token - await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync( - tokenToCreate, - tokenUri, - { + await erc1155Wrapper + .getContract() + .createWithType.awaitTransactionSuccessAsync(tokenToCreate, tokenUri, { from: owner, - }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + }); // mint balance for spender - await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync( - tokenToCreate, - [spender], - [spenderInitialBalance], - { + await erc1155Wrapper + .getContract() + .mintFungible.awaitTransactionSuccessAsync(tokenToCreate, [spender], [spenderInitialBalance], { from: owner, - }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + }); } ///// Step 2/5 ///// // Check balances before transfer @@ -805,25 +790,18 @@ describe('ERC1155Proxy', () => { const tokenUri = ''; for (const tokenToCreate of tokensToCreate) { // create token - await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync( - tokenToCreate, - tokenUri, - { + await erc1155Wrapper + .getContract() + .createWithType.awaitTransactionSuccessAsync(tokenToCreate, tokenUri, { from: owner, - }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + }); // mint balance for spender - await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync( - tokenToCreate, - [spender], - [spenderInitialBalance], - { + await erc1155Wrapper + .getContract() + .mintFungible.awaitTransactionSuccessAsync(tokenToCreate, [spender], [spenderInitialBalance], { from: owner, - }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + }); } ///// Step 2/5 ///// // Check balances before transfer @@ -937,25 +915,18 @@ describe('ERC1155Proxy', () => { const tokenUri = ''; for (const tokenToCreate of tokensToCreate) { // create token - await erc1155Wrapper.getContract().createWithType.awaitTransactionSuccessAsync( - tokenToCreate, - tokenUri, - { + await erc1155Wrapper + .getContract() + .createWithType.awaitTransactionSuccessAsync(tokenToCreate, tokenUri, { from: owner, - }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + }); // mint balance for spender - await erc1155Wrapper.getContract().mintFungible.awaitTransactionSuccessAsync( - tokenToCreate, - [spender], - [spenderInitialBalance], - { + await erc1155Wrapper + .getContract() + .mintFungible.awaitTransactionSuccessAsync(tokenToCreate, [spender], [spenderInitialBalance], { from: owner, - }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + }); } ///// Step 2/5 ///// // Check balances before transfer @@ -1667,13 +1638,9 @@ describe('ERC1155Proxy', () => { it('should propagate revert reason from erc1155 contract failure', async () => { // disable transfers const shouldRejectTransfer = true; - await erc1155Receiver.setRejectTransferFlag.awaitTransactionSuccessAsync( - shouldRejectTransfer, - { - from: owner, - }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc1155Receiver.setRejectTransferFlag.awaitTransactionSuccessAsync(shouldRejectTransfer, { + from: owner, + }); // setup test parameters const tokenHolders = [spender, receiverContract]; const tokensToTransfer = fungibleTokens.slice(0, 1); diff --git a/contracts/asset-proxy/test/proxies.ts b/contracts/asset-proxy/test/proxies.ts index 2d7d01aa9f..20a00b98e3 100644 --- a/contracts/asset-proxy/test/proxies.ts +++ b/contracts/asset-proxy/test/proxies.ts @@ -105,64 +105,24 @@ describe('Asset Transfer Proxies', () => { ); // Configure ERC20Proxy - await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - authorized, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(authorized, { from: owner }); + await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { from: owner }); // Configure ERC721Proxy - await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - authorized, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(authorized, { from: owner }); + await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { from: owner }); // Configure ERC115Proxy erc1155ProxyWrapper = new ERC1155ProxyWrapper(provider, usedAddresses, owner); erc1155Proxy = await erc1155ProxyWrapper.deployProxyAsync(); - await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - authorized, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(authorized, { from: owner }); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { from: owner }); // Configure MultiAssetProxy - await multiAssetProxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - authorized, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync( - erc20Proxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync( - erc721Proxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync( - erc1155Proxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await multiAssetProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(authorized, { from: owner }); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, { from: owner }); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, { from: owner }); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc1155Proxy.address, { from: owner }); // Deploy and configure ERC20 tokens const numDummyErc20ToDeploy = 2; @@ -192,19 +152,13 @@ describe('Asset Transfer Proxies', () => { ); await erc20Wrapper.setBalancesAndAllowancesAsync(); - await noReturnErc20Token.setBalance.awaitTransactionSuccessAsync( - fromAddress, - constants.INITIAL_ERC20_BALANCE, - { - from: owner, - }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await noReturnErc20Token.setBalance.awaitTransactionSuccessAsync(fromAddress, constants.INITIAL_ERC20_BALANCE, { + from: owner, + }); await noReturnErc20Token.approve.awaitTransactionSuccessAsync( erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { from: fromAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, ); await multipleReturnErc20Token.setBalance.awaitTransactionSuccessAsync( fromAddress, @@ -212,13 +166,11 @@ describe('Asset Transfer Proxies', () => { { from: owner, }, - constants.AWAIT_TRANSACTION_MINED_MS, ); await multipleReturnErc20Token.approve.awaitTransactionSuccessAsync( erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE, { from: fromAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, ); // Deploy and configure ERC721 tokens and receiver @@ -407,12 +359,9 @@ describe('Asset Transfer Proxies', () => { toAddress, amount, ); - await erc20TokenA.approve.awaitTransactionSuccessAsync( - erc20Proxy.address, - allowance, - { from: fromAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc20TokenA.approve.awaitTransactionSuccessAsync(erc20Proxy.address, allowance, { + from: fromAddress, + }); const erc20Balances = await erc20Wrapper.getBalancesAsync(); // Perform a transfer; expect this to fail. await expectTransactionFailedAsync( @@ -439,12 +388,9 @@ describe('Asset Transfer Proxies', () => { toAddress, amount, ); - await noReturnErc20Token.approve.awaitTransactionSuccessAsync( - erc20Proxy.address, - allowance, - { from: fromAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await noReturnErc20Token.approve.awaitTransactionSuccessAsync(erc20Proxy.address, allowance, { + from: fromAddress, + }); const initialFromBalance = await noReturnErc20Token.balanceOf.callAsync(fromAddress); const initialToBalance = await noReturnErc20Token.balanceOf.callAsync(toAddress); // Perform a transfer; expect this to fail. @@ -680,19 +626,13 @@ describe('Asset Transfer Proxies', () => { const ownerFromAsset = await erc721TokenA.ownerOf.callAsync(erc721AFromTokenId); expect(ownerFromAsset).to.be.equal(fromAddress); // Remove blanket transfer approval for fromAddress. - await erc721TokenA.setApprovalForAll.awaitTransactionSuccessAsync( - erc721Proxy.address, - false, - { from: fromAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc721TokenA.setApprovalForAll.awaitTransactionSuccessAsync(erc721Proxy.address, false, { + from: fromAddress, + }); // Remove token transfer approval for fromAddress. - await erc721TokenA.approve.awaitTransactionSuccessAsync( - constants.NULL_ADDRESS, - erc721AFromTokenId, - { from: fromAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc721TokenA.approve.awaitTransactionSuccessAsync(constants.NULL_ADDRESS, erc721AFromTokenId, { + from: fromAddress, + }); // Perform a transfer; expect this to fail. const amount = new BigNumber(1); const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData( diff --git a/contracts/asset-proxy/test/utils/erc20_wrapper.ts b/contracts/asset-proxy/test/utils/erc20_wrapper.ts index 8fdd210b24..2076040bd8 100644 --- a/contracts/asset-proxy/test/utils/erc20_wrapper.ts +++ b/contracts/asset-proxy/test/utils/erc20_wrapper.ts @@ -70,13 +70,11 @@ export class ERC20Wrapper { tokenOwnerAddress, constants.INITIAL_ERC20_BALANCE, { from: this._contractOwnerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, ); await dummyTokenContract.approve.awaitTransactionSuccessAsync( (this._proxyContract as ERC20ProxyContract).address, constants.INITIAL_ERC20_ALLOWANCE, { from: tokenOwnerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, ); } } @@ -88,12 +86,9 @@ export class ERC20Wrapper { } public async setBalanceAsync(userAddress: string, assetData: string, amount: BigNumber): Promise { const tokenContract = this._getTokenContractFromAssetData(assetData); - await tokenContract.setBalance.awaitTransactionSuccessAsync( - userAddress, - amount, - { from: this._contractOwnerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await tokenContract.setBalance.awaitTransactionSuccessAsync(userAddress, amount, { + from: this._contractOwnerAddress, + }); } public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise { const tokenContract = this._getTokenContractFromAssetData(assetData); @@ -104,12 +99,7 @@ export class ERC20Wrapper { public async setAllowanceAsync(userAddress: string, assetData: string, amount: BigNumber): Promise { const tokenContract = this._getTokenContractFromAssetData(assetData); const proxyAddress = (this._proxyContract as ERC20ProxyContract).address; - await tokenContract.approve.awaitTransactionSuccessAsync( - proxyAddress, - amount, - { from: userAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await tokenContract.approve.awaitTransactionSuccessAsync(proxyAddress, amount, { from: userAddress }); } public async getBalancesAsync(): Promise { this._validateDummyTokenContractsExistOrThrow(); diff --git a/contracts/asset-proxy/test/utils/erc721_wrapper.ts b/contracts/asset-proxy/test/utils/erc721_wrapper.ts index 3ff03f3d19..e2ae988930 100644 --- a/contracts/asset-proxy/test/utils/erc721_wrapper.ts +++ b/contracts/asset-proxy/test/utils/erc721_wrapper.ts @@ -93,22 +93,14 @@ export class ERC721Wrapper { ): Promise { const tokenContract = this._getTokenContractFromAssetData(tokenAddress); const proxyAddress = (this._proxyContract as ERC721ProxyContract).address; - await tokenContract.setApprovalForAll.awaitTransactionSuccessAsync( - proxyAddress, - isApproved, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await tokenContract.setApprovalForAll.awaitTransactionSuccessAsync(proxyAddress, isApproved, { + from: ownerAddress, + }); } public async approveAsync(to: string, tokenAddress: string, tokenId: BigNumber): Promise { const tokenContract = this._getTokenContractFromAssetData(tokenAddress); const tokenOwner = await this.ownerOfAsync(tokenAddress, tokenId); - await tokenContract.approve.awaitTransactionSuccessAsync( - to, - tokenId, - { from: tokenOwner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await tokenContract.approve.awaitTransactionSuccessAsync(to, tokenId, { from: tokenOwner }); } public async transferFromAsync( tokenAddress: string, @@ -117,31 +109,19 @@ export class ERC721Wrapper { userAddress: string, ): Promise { const tokenContract = this._getTokenContractFromAssetData(tokenAddress); - await tokenContract.transferFrom.awaitTransactionSuccessAsync( - currentOwner, - userAddress, - tokenId, - { from: currentOwner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await tokenContract.transferFrom.awaitTransactionSuccessAsync(currentOwner, userAddress, tokenId, { + from: currentOwner, + }); } public async mintAsync(tokenAddress: string, tokenId: BigNumber, userAddress: string): Promise { const tokenContract = this._getTokenContractFromAssetData(tokenAddress); - await tokenContract.mint.awaitTransactionSuccessAsync( - userAddress, - tokenId, - { from: this._contractOwnerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await tokenContract.mint.awaitTransactionSuccessAsync(userAddress, tokenId, { + from: this._contractOwnerAddress, + }); } public async burnAsync(tokenAddress: string, tokenId: BigNumber, owner: string): Promise { const tokenContract = this._getTokenContractFromAssetData(tokenAddress); - await tokenContract.burn.awaitTransactionSuccessAsync( - owner, - tokenId, - { from: this._contractOwnerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await tokenContract.burn.awaitTransactionSuccessAsync(owner, tokenId, { from: this._contractOwnerAddress }); } public async ownerOfAsync(tokenAddress: string, tokenId: BigNumber): Promise { const tokenContract = this._getTokenContractFromAssetData(tokenAddress); diff --git a/contracts/coordinator/package.json b/contracts/coordinator/package.json index 16de8c364c..037ea6909f 100644 --- a/contracts/coordinator/package.json +++ b/contracts/coordinator/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", diff --git a/contracts/coordinator/test/coordinator_registry.ts b/contracts/coordinator/test/coordinator_registry.ts index ef20a0eaf8..743132fa7e 100644 --- a/contracts/coordinator/test/coordinator_registry.ts +++ b/contracts/coordinator/test/coordinator_registry.ts @@ -1,11 +1,6 @@ -import { blockchainTests, expect } from '@0x/contracts-test-utils'; +import { blockchainTests, expect, verifyEvents } from '@0x/contracts-test-utils'; -import { - artifacts, - CoordinatorRegistryContract, - CoordinatorRegistryCoordinatorEndpointSetEventArgs, - CoordinatorTestFactory, -} from '../src'; +import { artifacts, CoordinatorRegistryContract, CoordinatorRegistryCoordinatorEndpointSetEventArgs } from '../src'; // tslint:disable:no-unnecessary-type-assertion blockchainTests.resets('Coordinator Registry tests', env => { @@ -71,7 +66,7 @@ blockchainTests.resets('Coordinator Registry tests', env => { coordinatorOperator, coordinatorEndpoint, }; - CoordinatorTestFactory.verifyEvents(txReceipt, [expectedEvent], 'CoordinatorEndpointSet'); + verifyEvents(txReceipt, [expectedEvent], 'CoordinatorEndpointSet'); }); }); }); diff --git a/contracts/coordinator/test/utils/index.ts b/contracts/coordinator/test/utils/index.ts index a724673f47..bd5bd79dae 100644 --- a/contracts/coordinator/test/utils/index.ts +++ b/contracts/coordinator/test/utils/index.ts @@ -1,4 +1,3 @@ export { hashUtils } from './hash_utils'; export { ApprovalFactory } from './approval_factory'; -export { CoordinatorTestFactory } from './coordinator_test_factory'; export * from './types'; diff --git a/contracts/dev-utils/package.json b/contracts/dev-utils/package.json index b88780e996..659f18ce0b 100644 --- a/contracts/dev-utils/package.json +++ b/contracts/dev-utils/package.json @@ -6,30 +6,17 @@ }, "description": "0x protocol specific utility contracts", "main": "lib/src/index.js", - "directories": { - "test": "test" - }, "scripts": { "build": "yarn pre_build && tsc -b", + "test": "echo !!! Run tests in @0x/contracts-tests instead !!!", "build:ci": "yarn build", "pre_build": "run-s compile quantify_bytecode contracts:gen generate_contract_wrappers", - "test": "yarn run_mocha", - "rebuild_and_test": "run-s build test", - "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", - "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", - "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", - "run_mocha": "UNLIMITED_CONTRACT_SIZE=true mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", - "coverage:report:text": "istanbul report text", - "coverage:report:html": "istanbul report html && open coverage/index.html", - "profiler:report:html": "istanbul report html && open coverage/index.html", - "coverage:report:lcov": "istanbul report lcov", - "test:circleci": "yarn test", "contracts:gen": "contracts-gen", "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol", "quantify_bytecode": "echo EVM bytecode object lengths:;for i in ./generated-artifacts/*.json; do node -e \"console.log('$i\t' + (require('$i').compilerOutput.evm.bytecode.object.length - 2) / 2)\"; done", @@ -51,19 +38,9 @@ "devDependencies": { "@0x/abi-gen": "^4.3.0-beta.0", "@0x/contracts-gen": "^1.1.0-beta.0", - "@0x/contracts-test-utils": "^3.2.0-beta.0", - "@0x/dev-utils": "^2.4.0-beta.0", "@0x/sol-compiler": "^3.2.0-beta.0", "@0x/tslint-config": "^3.0.1", - "@types/lodash": "4.14.104", - "@types/mocha": "^5.2.7", "@types/node": "*", - "chai": "^4.0.1", - "chai-as-promised": "^7.1.0", - "chai-bignumber": "^3.0.0", - "dirty-chai": "^2.0.1", - "make-promises-safe": "^1.1.0", - "mocha": "^6.2.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "solhint": "^1.4.1", @@ -72,21 +49,15 @@ "typescript": "3.0.1" }, "dependencies": { + "@0x/assert": "^2.2.0-beta.0", "@0x/base-contract": "^5.5.0-beta.0", - "@0x/contracts-asset-proxy": "^2.3.0-beta.0", - "@0x/contracts-erc1155": "^1.2.0-beta.0", - "@0x/contracts-erc20": "^2.3.0-beta.0", - "@0x/contracts-erc721": "^2.2.0-beta.0", - "@0x/contracts-exchange": "^2.2.0-beta.0", - "@0x/contracts-exchange-libs": "^3.1.0-beta.0", - "@0x/contracts-utils": "^3.3.0-beta.0", - "@0x/order-utils": "^8.5.0-beta.0", + "@0x/contract-addresses": "^3.3.0-beta.0", + "@0x/json-schemas": "^4.1.0-beta.0", "@0x/types": "^2.5.0-beta.0", - "@0x/typescript-typings": "^4.4.0-beta.0", "@0x/utils": "^4.6.0-beta.0", "@0x/web3-wrapper": "^6.1.0-beta.0", "ethereum-types": "^2.2.0-beta.0", - "ethereumjs-util": "^5.1.1" + "ethers": "~4.0.4" }, "publishConfig": { "access": "public" diff --git a/contracts/erc1155/CHANGELOG.json b/contracts/erc1155/CHANGELOG.json index b2d85d92cc..f42944b3be 100644 --- a/contracts/erc1155/CHANGELOG.json +++ b/contracts/erc1155/CHANGELOG.json @@ -5,6 +5,10 @@ { "note": "Add `mintKnownFungibleTokensAsync()`, `isNonFungibleItemAsync()`, `isFungibleItemAsync()`, `getOwnerOfAsync()`, `getBalanceAsync()` to `Erc1155Wrapper`.", "pr": 1819 + }, + { + "note": "Replaced `SafeMath` with `LibSafeMath`", + "pr": 2254 } ], "timestamp": 1570135330 diff --git a/contracts/erc1155/contracts/src/ERC1155.sol b/contracts/erc1155/contracts/src/ERC1155.sol index afebfbc634..ab81c61aec 100644 --- a/contracts/erc1155/contracts/src/ERC1155.sol +++ b/contracts/erc1155/contracts/src/ERC1155.sol @@ -18,7 +18,7 @@ pragma solidity ^0.5.9; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "@0x/contracts-utils/contracts/src/LibAddress.sol"; import "./interfaces/IERC1155.sol"; import "./interfaces/IERC1155Receiver.sol"; @@ -26,11 +26,11 @@ import "./MixinNonFungibleToken.sol"; contract ERC1155 is - SafeMath, IERC1155, MixinNonFungibleToken { using LibAddress for address; + using LibSafeMath for uint256; // selectors for receiver callbacks bytes4 constant public ERC1155_RECEIVED = 0xf23a6e61; @@ -88,11 +88,11 @@ contract ERC1155 is nfOwners[id] = to; // You could keep balance of NF type in base type id like so: // uint256 baseType = getNonFungibleBaseType(_id); - // balances[baseType][_from] = balances[baseType][_from]._safeSub(_value); - // balances[baseType][_to] = balances[baseType][_to]._safeAdd(_value); + // balances[baseType][_from] = balances[baseType][_from].safeSub(_value); + // balances[baseType][_to] = balances[baseType][_to].safeAdd(_value); } else { - balances[id][from] = _safeSub(balances[id][from], value); - balances[id][to] = _safeAdd(balances[id][to], value); + balances[id][from] = balances[id][from].safeSub(value); + balances[id][to] = balances[id][to].safeAdd(value); } emit TransferSingle(msg.sender, from, to, id, value); @@ -170,8 +170,8 @@ contract ERC1155 is ); nfOwners[id] = to; } else { - balances[id][from] = _safeSub(balances[id][from], value); - balances[id][to] = _safeAdd(balances[id][to], value); + balances[id][from] = balances[id][from].safeSub(value); + balances[id][to] = balances[id][to].safeAdd(value); } } emit TransferBatch(msg.sender, from, to, ids, values); diff --git a/contracts/erc1155/contracts/src/ERC1155Mintable.sol b/contracts/erc1155/contracts/src/ERC1155Mintable.sol index 5057f956c7..5d99a535cf 100644 --- a/contracts/erc1155/contracts/src/ERC1155Mintable.sol +++ b/contracts/erc1155/contracts/src/ERC1155Mintable.sol @@ -1,6 +1,6 @@ pragma solidity ^0.5.9; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "./ERC1155.sol"; import "./interfaces/IERC1155Mintable.sol"; @@ -11,6 +11,7 @@ contract ERC1155Mintable is IERC1155Mintable, ERC1155 { + using LibSafeMath for uint256; /// token nonce uint256 internal nonce; @@ -37,7 +38,7 @@ contract ERC1155Mintable is ) external returns (uint256 type_) - { + { // Store the type in the upper 128 bits type_ = (++nonce << 128); @@ -114,7 +115,7 @@ contract ERC1155Mintable is uint256 quantity = quantities[i]; // Grant the items to the caller - balances[id][dst] = _safeAdd(quantity, balances[id][dst]); + balances[id][dst] = quantity.safeAdd(balances[id][dst]); // Emit the Transfer/Mint event. // the 0x0 source address implies a mint @@ -172,7 +173,7 @@ contract ERC1155Mintable is nfOwners[id] = dst; // You could use base-type id to store NF type balances if you wish. - // balances[_type][dst] = quantity._safeAdd(balances[_type][dst]); + // balances[_type][dst] = quantity.safeAdd(balances[_type][dst]); emit TransferSingle(msg.sender, address(0x0), dst, id, 1); @@ -194,6 +195,6 @@ contract ERC1155Mintable is // record the `maxIndex` of this nft type // this allows us to mint more nft's of this type in a subsequent call. - maxIndex[type_] = _safeAdd(to.length, maxIndex[type_]); + maxIndex[type_] = to.length.safeAdd(maxIndex[type_]); } } diff --git a/contracts/erc1155/package.json b/contracts/erc1155/package.json index f931f4ec11..f3111ac48c 100644 --- a/contracts/erc1155/package.json +++ b/contracts/erc1155/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", diff --git a/contracts/erc1155/test/utils/erc1155_wrapper.ts b/contracts/erc1155/test/utils/erc1155_wrapper.ts index 5f2ea1483f..984935db17 100644 --- a/contracts/erc1155/test/utils/erc1155_wrapper.ts +++ b/contracts/erc1155/test/utils/erc1155_wrapper.ts @@ -1,4 +1,4 @@ -import { constants, LogDecoder } from '@0x/contracts-test-utils'; +import { LogDecoder } from '@0x/contracts-test-utils'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import * as chai from 'chai'; @@ -100,7 +100,6 @@ export class Erc1155Wrapper { beneficiaries, tokenAmountsAsArray, { from: this._contractOwner }, - constants.AWAIT_TRANSACTION_MINED_MS, ); } public async mintNonFungibleTokensAsync(beneficiaries: string[]): Promise<[BigNumber, BigNumber[]]> { @@ -114,12 +113,9 @@ export class Erc1155Wrapper { // tslint:disable-next-line no-unnecessary-type-assertion const createFungibleTokenLog = tx.logs[0] as LogWithDecodedArgs; const token = createFungibleTokenLog.args.id; - await this._erc1155Contract.mintNonFungible.awaitTransactionSuccessAsync( - token, - beneficiaries, - { from: this._contractOwner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await this._erc1155Contract.mintNonFungible.awaitTransactionSuccessAsync(token, beneficiaries, { + from: this._contractOwner, + }); const encodedNftIds: BigNumber[] = []; const nftIdBegin = 1; const nftIdEnd = beneficiaries.length + 1; diff --git a/contracts/erc20/CHANGELOG.json b/contracts/erc20/CHANGELOG.json index 4c349e24df..74e072b7b5 100644 --- a/contracts/erc20/CHANGELOG.json +++ b/contracts/erc20/CHANGELOG.json @@ -4,6 +4,10 @@ "changes": [ { "note": "Dependencies updated" + }, + { + "note": "Replaced `SafeMath` with `LibSafeMath`", + "pr": 2254 } ], "timestamp": 1570135330 diff --git a/contracts/erc20/contracts/src/MintableERC20Token.sol b/contracts/erc20/contracts/src/MintableERC20Token.sol index 65e102135b..fab2aac164 100644 --- a/contracts/erc20/contracts/src/MintableERC20Token.sol +++ b/contracts/erc20/contracts/src/MintableERC20Token.sol @@ -18,22 +18,23 @@ pragma solidity ^0.5.9; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "./UnlimitedAllowanceERC20Token.sol"; -contract MintableERC20Token is - SafeMath, +contract MintableERC20Token is UnlimitedAllowanceERC20Token { + using LibSafeMath for uint256; + /// @dev Mints new tokens /// @param _to Address of the beneficiary that will own the minted token /// @param _value Amount of tokens to mint function _mint(address _to, uint256 _value) internal { - balances[_to] = _safeAdd(_value, balances[_to]); - _totalSupply = _safeAdd(_totalSupply, _value); + balances[_to] = _value.safeAdd(balances[_to]); + _totalSupply = _totalSupply.safeAdd(_value); emit Transfer( address(0), @@ -48,8 +49,8 @@ contract MintableERC20Token is function _burn(address _owner, uint256 _value) internal { - balances[_owner] = _safeSub(balances[_owner], _value); - _totalSupply = _safeSub(_totalSupply, _value); + balances[_owner] = balances[_owner].safeSub(_value); + _totalSupply = _totalSupply.safeSub(_value); emit Transfer( _owner, diff --git a/contracts/erc20/contracts/test/DummyERC20Token.sol b/contracts/erc20/contracts/test/DummyERC20Token.sol index 2a74d21237..be39ac3048 100644 --- a/contracts/erc20/contracts/test/DummyERC20Token.sol +++ b/contracts/erc20/contracts/test/DummyERC20Token.sol @@ -18,14 +18,17 @@ pragma solidity ^0.5.5; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "@0x/contracts-utils/contracts/src/Ownable.sol"; import "../src/MintableERC20Token.sol"; -contract DummyERC20Token is +contract DummyERC20Token is Ownable, MintableERC20Token { + using LibSafeMath for uint256; + string public name; string public symbol; uint256 public decimals; @@ -55,9 +58,9 @@ contract DummyERC20Token is { uint256 currBalance = balances[_target]; if (_value < currBalance) { - _totalSupply = _safeSub(_totalSupply, _safeSub(currBalance, _value)); + _totalSupply = _totalSupply.safeSub(currBalance.safeSub(_value)); } else { - _totalSupply = _safeAdd(_totalSupply, _safeSub(_value, currBalance)); + _totalSupply = _totalSupply.safeAdd(_value.safeSub(currBalance)); } balances[_target] = _value; } diff --git a/contracts/erc20/package.json b/contracts/erc20/package.json index 6e2d280cfc..bd851a7056 100644 --- a/contracts/erc20/package.json +++ b/contracts/erc20/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", diff --git a/contracts/erc721/CHANGELOG.json b/contracts/erc721/CHANGELOG.json index 7b77e700de..4ad739fabc 100644 --- a/contracts/erc721/CHANGELOG.json +++ b/contracts/erc721/CHANGELOG.json @@ -4,6 +4,10 @@ "changes": [ { "note": "Dependencies updated" + }, + { + "note": "Replaced `SafeMath` with `LibSafeMath`", + "pr": 2254 } ], "timestamp": 1570135330 diff --git a/contracts/erc721/contracts/src/ERC721Token.sol b/contracts/erc721/contracts/src/ERC721Token.sol index aa2ba3cca0..810016d195 100644 --- a/contracts/erc721/contracts/src/ERC721Token.sol +++ b/contracts/erc721/contracts/src/ERC721Token.sol @@ -20,13 +20,14 @@ pragma solidity ^0.5.9; import "./interfaces/IERC721Token.sol"; import "./interfaces/IERC721Receiver.sol"; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; contract ERC721Token is - IERC721Token, - SafeMath + IERC721Token { + using LibSafeMath for uint256; + // Function selector for ERC721Receiver.onERC721Received // 0x150b7a02 bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")); @@ -163,7 +164,7 @@ contract ERC721Token is _approved ); } - + /// @notice Count all NFTs assigned to an owner /// @dev NFTs assigned to the zero address are considered invalid, and this /// function throws for queries about the zero address. @@ -223,9 +224,9 @@ contract ERC721Token is } owners[_tokenId] = _to; - balances[_from] = _safeSub(balances[_from], 1); - balances[_to] = _safeAdd(balances[_to], 1); - + balances[_from] = balances[_from].safeSub(1); + balances[_to] = balances[_to].safeAdd(1); + emit Transfer( _from, _to, diff --git a/contracts/erc721/contracts/src/MintableERC721Token.sol b/contracts/erc721/contracts/src/MintableERC721Token.sol index c3e0a6dca9..667b5994a9 100644 --- a/contracts/erc721/contracts/src/MintableERC721Token.sol +++ b/contracts/erc721/contracts/src/MintableERC721Token.sol @@ -18,16 +18,19 @@ pragma solidity ^0.5.9; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "./ERC721Token.sol"; contract MintableERC721Token is ERC721Token { + using LibSafeMath for uint256; + /// @dev Function to mint a new token /// Reverts if the given token ID already exists /// @param _to Address of the beneficiary that will own the minted token - /// @param _tokenId ID of the token to be minted by the msg.sender + /// @param _tokenId ID of the token to be minted by the msg.sender function _mint(address _to, uint256 _tokenId) internal { @@ -43,7 +46,7 @@ contract MintableERC721Token is ); owners[_tokenId] = _to; - balances[_to] = _safeAdd(balances[_to], 1); + balances[_to] = balances[_to].safeAdd(1); emit Transfer( address(0), @@ -71,7 +74,7 @@ contract MintableERC721Token is ); owners[_tokenId] = address(0); - balances[_owner] = _safeSub(balances[_owner], 1); + balances[_owner] = balances[_owner].safeSub(1); emit Transfer( _owner, diff --git a/contracts/erc721/package.json b/contracts/erc721/package.json index cc3c04f2a1..2bbebbba84 100644 --- a/contracts/erc721/package.json +++ b/contracts/erc721/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", diff --git a/contracts/exchange-forwarder/package.json b/contracts/exchange-forwarder/package.json index a14a5a8cd1..7a517399ea 100644 --- a/contracts/exchange-forwarder/package.json +++ b/contracts/exchange-forwarder/package.json @@ -23,7 +23,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", "coverage:report:html": "istanbul report html && open coverage/index.html", diff --git a/contracts/exchange-libs/contracts/src/LibMath.sol b/contracts/exchange-libs/contracts/src/LibMath.sol index 29d61afdd7..e18c746bf1 100644 --- a/contracts/exchange-libs/contracts/src/LibMath.sol +++ b/contracts/exchange-libs/contracts/src/LibMath.sol @@ -85,9 +85,9 @@ library LibMath { )); } - // _safeDiv computes `floor(a / b)`. We use the identity (a, b integer): + // safeDiv computes `floor(a / b)`. We use the identity (a, b integer): // ceil(a / b) = floor((a + b - 1) / b) - // To implement `ceil(a / b)` using _safeDiv. + // To implement `ceil(a / b)` using safeDiv. partialAmount = numerator.safeMul(target) .safeAdd(denominator.safeSub(1)) .safeDiv(denominator); @@ -127,9 +127,9 @@ library LibMath { pure returns (uint256 partialAmount) { - // _safeDiv computes `floor(a / b)`. We use the identity (a, b integer): + // safeDiv computes `floor(a / b)`. We use the identity (a, b integer): // ceil(a / b) = floor((a + b - 1) / b) - // To implement `ceil(a / b)` using _safeDiv. + // To implement `ceil(a / b)` using safeDiv. partialAmount = numerator.safeMul(target) .safeAdd(denominator.safeSub(1)) .safeDiv(denominator); diff --git a/contracts/exchange-libs/package.json b/contracts/exchange-libs/package.json index e21a07ead7..0e88be8bd4 100644 --- a/contracts/exchange-libs/package.json +++ b/contracts/exchange-libs/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", diff --git a/contracts/exchange/package.json b/contracts/exchange/package.json index 6f09054ea8..0c2d9b033c 100644 --- a/contracts/exchange/package.json +++ b/contracts/exchange/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", @@ -63,6 +63,7 @@ "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", + "js-combinatorics": "^0.5.3", "make-promises-safe": "^1.1.0", "mocha": "^6.2.0", "npm-run-all": "^4.1.2", diff --git a/contracts/exchange/src/index.ts b/contracts/exchange/src/index.ts index ea1294353f..4b64e3df2b 100644 --- a/contracts/exchange/src/index.ts +++ b/contracts/exchange/src/index.ts @@ -1,4 +1,5 @@ export * from './artifacts'; export * from './wrappers'; +export * from '../test/balance_stores'; export * from '../test/utils'; export * from './wrapper_interfaces'; diff --git a/contracts/exchange/src/wrapper_interfaces.ts b/contracts/exchange/src/wrapper_interfaces.ts index 88ed09502b..2c8fe219b1 100644 --- a/contracts/exchange/src/wrapper_interfaces.ts +++ b/contracts/exchange/src/wrapper_interfaces.ts @@ -1,4 +1,5 @@ import { PromiseWithTransactionHash } from '@0x/base-contract'; +import { AwaitTransactionSuccessOpts } from '@0x/types'; import { BlockParam, CallData, TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types'; // Generated Wrapper Interfaces @@ -7,8 +8,7 @@ export interface AssetProxyDispatcher { awaitTransactionSuccessAsync: ( assetProxy: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + txOpts?: AwaitTransactionSuccessOpts, ) => PromiseWithTransactionHash; }; getAssetProxy: { @@ -21,16 +21,14 @@ export interface Authorizable extends Ownable { awaitTransactionSuccessAsync: ( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + txOpts?: AwaitTransactionSuccessOpts, ) => PromiseWithTransactionHash; }; removeAuthorizedAddress: { awaitTransactionSuccessAsync: ( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + txOpts?: AwaitTransactionSuccessOpts, ) => PromiseWithTransactionHash; }; authorized: { @@ -46,8 +44,7 @@ export interface Ownable { awaitTransactionSuccessAsync: ( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + txOpts?: AwaitTransactionSuccessOpts, ) => PromiseWithTransactionHash; }; owner: { diff --git a/contracts/exchange/test/assertion_wrappers/fill_order_wrapper.ts b/contracts/exchange/test/assertion_wrappers/fill_order_wrapper.ts index e675019145..242a0ab8e7 100644 --- a/contracts/exchange/test/assertion_wrappers/fill_order_wrapper.ts +++ b/contracts/exchange/test/assertion_wrappers/fill_order_wrapper.ts @@ -1,53 +1,47 @@ -import { - artifacts as proxyArtifacts, - ERC1155ProxyWrapper, - ERC20Wrapper, - ERC721Wrapper, -} from '@0x/contracts-asset-proxy'; -import { artifacts as erc20Artifacts } from '@0x/contracts-erc20'; -import { artifacts as erc721Artifacts } from '@0x/contracts-erc721'; import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs'; import { constants, expect, FillEventArgs, filterLogsToArguments, - LogDecoder, OrderStatus, orderUtils, - Web3ProviderEngine, } from '@0x/contracts-test-utils'; import { orderHashUtils } from '@0x/order-utils'; import { FillResults, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; -import { Web3Wrapper } from '@0x/web3-wrapper'; -import { TransactionReceiptWithDecodedLogs, ZeroExProvider } from 'ethereum-types'; +import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts, ExchangeContract } from '../../src'; -import { BalanceStore } from '../balance_stores/balance_store'; -import { BlockchainBalanceStore } from '../balance_stores/blockchain_balance_store'; -import { LocalBalanceStore } from '../balance_stores/local_balance_store'; +import { + BalanceStore, + BlockchainBalanceStore, + ExchangeContract, + LocalBalanceStore, + TokenContractsByName, + TokenIds, + TokenOwnersByName, +} from '../../src'; export class FillOrderWrapper { private readonly _exchange: ExchangeContract; private readonly _blockchainBalanceStore: BlockchainBalanceStore; - private readonly _web3Wrapper: Web3Wrapper; /** - * Simulates matching two orders by transferring amounts defined in - * `transferAmounts` and returns the results. - * @param orders The orders being matched and their filled states. + * Locally simulates filling an order. + * @param txReceipt Transaction receipt from the actual fill, needed to update eth balance + * @param signedOrder The order being filled. * @param takerAddress Address of taker (the address who matched the two orders) - * @param tokenBalances Current token balances. - * @param transferAmounts Amounts to transfer during the simulation. - * @return The new account balances and fill events that occurred during the match. + * @param opts Optionally specifies the amount to fill. + * @param initBalanceStore Account balances prior to the fill. + * @return The expected account balances, fill results, and fill events. */ public static simulateFillOrder( + txReceipt: TransactionReceiptWithDecodedLogs, signedOrder: SignedOrder, takerAddress: string, - opts: { takerAssetFillAmount?: BigNumber } = {}, initBalanceStore: BalanceStore, + opts: { takerAssetFillAmount?: BigNumber } = {}, ): [FillResults, FillEventArgs, BalanceStore] { const balanceStore = LocalBalanceStore.create(initBalanceStore); const takerAssetFillAmount = @@ -88,6 +82,7 @@ export class FillOrderWrapper { fillResults.makerFeePaid, signedOrder.makerFeeAssetData, ); + balanceStore.burnGas(txReceipt.from, constants.DEFAULT_GAS_PRICE * txReceipt.gasUsed); return [fillResults, fillEvent, balanceStore]; } @@ -126,22 +121,19 @@ export class FillOrderWrapper { /** * Constructor. - * @param exchangeContract Insstance of the deployed exchange contract - * @param erc20Wrapper The ERC20 Wrapper used to interface with deployed erc20 tokens. - * @param erc721Wrapper The ERC721 Wrapper used to interface with deployed erc20 tokens. - * @param erc1155ProxyWrapper The ERC1155 Proxy Wrapper used to interface with deployed erc20 tokens. - * @param provider Web3 provider to be used by a `Web3Wrapper` instance + * @param exchangeContract Instance of the deployed exchange contract. + * @param tokenOwnersByName The addresses of token owners to assert the balances of. + * @param tokenContractsByName The contracts of tokens to assert the balances of. + * @param tokenIds The tokenIds of ERC721 and ERC1155 assets to assert the balances of. */ public constructor( exchangeContract: ExchangeContract, - erc20Wrapper: ERC20Wrapper, - erc721Wrapper: ERC721Wrapper, - erc1155ProxyWrapper: ERC1155ProxyWrapper, - provider: Web3ProviderEngine | ZeroExProvider, + tokenOwnersByName: TokenOwnersByName, + tokenContractsByName: Partial, + tokenIds: Partial, ) { this._exchange = exchangeContract; - this._blockchainBalanceStore = new BlockchainBalanceStore(erc20Wrapper, erc721Wrapper, erc1155ProxyWrapper); - this._web3Wrapper = new Web3Wrapper(provider); + this._blockchainBalanceStore = new BlockchainBalanceStore(tokenOwnersByName, tokenContractsByName, tokenIds); } /** @@ -171,31 +163,32 @@ export class FillOrderWrapper { // Assert init state of exchange await this._assertOrderStateAsync(signedOrder, initTakerAssetFilledAmount); // Simulate and execute fill then assert outputs + const [fillResults, fillEvent, txReceipt] = await this._fillOrderAsync(signedOrder, from, opts); const [ simulatedFillResults, simulatedFillEvent, simulatedFinalBalanceStore, - ] = FillOrderWrapper.simulateFillOrder(signedOrder, from, opts, this._blockchainBalanceStore); - const [fillResults, fillEvent] = await this._fillOrderAsync(signedOrder, from, opts); + ] = FillOrderWrapper.simulateFillOrder(txReceipt, signedOrder, from, this._blockchainBalanceStore, opts); // Assert state transition expect(simulatedFillResults, 'Fill Results').to.be.deep.equal(fillResults); expect(simulatedFillEvent, 'Fill Events').to.be.deep.equal(fillEvent); - const areBalancesEqual = BalanceStore.isEqual(simulatedFinalBalanceStore, this._blockchainBalanceStore); - expect(areBalancesEqual, 'Balances After Fill').to.be.true(); + + await this._blockchainBalanceStore.updateBalancesAsync(); + this._blockchainBalanceStore.assertEquals(simulatedFinalBalanceStore); + // Assert end state of exchange const finalTakerAssetFilledAmount = initTakerAssetFilledAmount.plus(fillResults.takerAssetFilledAmount); await this._assertOrderStateAsync(signedOrder, finalTakerAssetFilledAmount); } /** - * Fills an order on-chain. As an optimization this function auto-updates the blockchain balance store - * used by this contract. + * Fills an order on-chain. */ protected async _fillOrderAsync( signedOrder: SignedOrder, from: string, opts: { takerAssetFillAmount?: BigNumber } = {}, - ): Promise<[FillResults, FillEventArgs]> { + ): Promise<[FillResults, FillEventArgs, TransactionReceiptWithDecodedLogs]> { const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount); const fillResults = await this._exchange.fillOrder.callAsync( params.order, @@ -203,33 +196,21 @@ export class FillOrderWrapper { params.signature, { from }, ); - // @TODO: Replace with `awaitTransactionAsync` once `development` is merged into `3.0` branch - const txHash = await this._exchange.fillOrder.sendTransactionAsync( + const txReceipt = await this._exchange.fillOrder.awaitTransactionSuccessAsync( params.order, params.takerAssetFillAmount, params.signature, { from }, ); - const logDecoder = new LogDecoder(this._web3Wrapper, { - ...artifacts, - ...proxyArtifacts, - ...erc20Artifacts, - ...erc721Artifacts, - }); - const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(txHash); const fillEvent = FillOrderWrapper._extractFillEventsfromReceipt(txReceipt)[0]; - await this._blockchainBalanceStore.updateBalancesAsync(); - return [fillResults, fillEvent]; + return [fillResults, fillEvent, txReceipt]; } /** * Asserts that the provided order's fill amount and order status * are the expected values. * @param order The order to verify for a correct state. - * @param expectedFilledAmount The amount that the order should - * have been filled. - * @param side The side that the provided order should be matched on. - * @param exchangeWrapper The ExchangeWrapper instance. + * @param expectedFilledAmount The amount that the order should have been filled. */ private async _assertOrderStateAsync( order: SignedOrder, diff --git a/contracts/exchange/test/balance_stores/balance_store.ts b/contracts/exchange/test/balance_stores/balance_store.ts index 1e518b2d10..a9a1b56941 100644 --- a/contracts/exchange/test/balance_stores/balance_store.ts +++ b/contracts/exchange/test/balance_stores/balance_store.ts @@ -1,92 +1,133 @@ -import { ERC1155Holdings, ERC1155HoldingsByOwner, TokenBalances } from '@0x/contracts-test-utils'; +import { BaseContract } from '@0x/base-contract'; +import { expect, TokenBalances } from '@0x/contracts-test-utils'; import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; -/** - * Note - this should live in `@0x/contracts-test-utils` but that would create a circular - * dependency in `BlockchainBlanceStore`. We should be able to mvoe this once we can rely - * solely on auto-generated wrappers opposed to the existing ERC20Wrapper, ERC721Wrapper, - * and ERC1155Wrapper. - */ +import { TokenAddresses, TokenContractsByName, TokenOwnersByName } from './types'; + export class BalanceStore { protected _balances: TokenBalances; + protected _tokenAddresses: TokenAddresses; + protected _ownerAddresses: string[]; + private _addressNames: { + [address: string]: string; + }; /** - * Returns true iff balance stores do have the same entries. - * @param lhs First balance store to compare - * @param rhs Second balance store to compare + * Constructor. + * @param tokenOwnersByName Addresses of token owners to track balances of. + * @param tokenContractsByName Contracts of tokens to track balances of. */ - public static isEqual(lhs: BalanceStore, rhs: BalanceStore): boolean { - return _.isEqual(lhs.getRawBalances(), rhs.getRawBalances()); + public constructor(tokenOwnersByName: TokenOwnersByName, tokenContractsByName: Partial) { + this._balances = { erc20: {}, erc721: {}, erc1155: {}, eth: {} }; + this._ownerAddresses = Object.values(tokenOwnersByName); + + _.defaults(tokenContractsByName, { erc20: {}, erc721: {}, erc1155: {} }); + const tokenAddressesByName = _.mapValues( + { ...tokenContractsByName.erc20, ...tokenContractsByName.erc721, ...tokenContractsByName.erc1155 }, + contract => (contract as BaseContract).address, + ); + this._addressNames = _.invert({ ...tokenOwnersByName, ...tokenAddressesByName }); + + this._tokenAddresses = { + erc20: Object.values(tokenContractsByName.erc20 || {}).map(contract => contract.address), + erc721: Object.values(tokenContractsByName.erc721 || {}).map(contract => contract.address), + erc1155: Object.values(tokenContractsByName.erc1155 || {}).map(contract => contract.address), + }; } /** * Throws iff balance stores do not have the same entries. - * @param lhs First balance store to compare - * @param rhs Second balance store to compare + * @param rhs Balance store to compare to */ - public static assertEqual(lhs: BalanceStore, rhs: BalanceStore): void { - if (!BalanceStore.isEqual(lhs, rhs)) { - throw new Error(`Balance stores are not equal:\n\nLeft:\n${lhs}\n\nRight:\n${rhs}`); - } + public assertEquals(rhs: BalanceStore): void { + this._assertEthBalancesEqual(rhs); + this._assertErc20BalancesEqual(rhs); + this._assertErc721BalancesEqual(rhs); + this._assertErc1155BalancesEqual(rhs); } /** - * Restructures `ERC1155HoldingsByOwner` to be compatible with `TokenBalances.erc1155`. - * @param erc1155HoldingsByOwner Holdings returned by `ERC1155ProxyWrapper.getBalancesAsync()`. + * Copies from an existing balance store. + * @param balanceStore to copy from. */ - protected static _transformERC1155Holdings(erc1155HoldingsByOwner: ERC1155HoldingsByOwner): ERC1155Holdings { - const result = {}; - for (const owner of _.keys(erc1155HoldingsByOwner.fungible)) { - for (const contract of _.keys(erc1155HoldingsByOwner.fungible[owner])) { - _.set(result as any, [owner, contract, 'fungible'], erc1155HoldingsByOwner.fungible[owner][contract]); - } - } - for (const owner of _.keys(erc1155HoldingsByOwner.nonFungible)) { - for (const contract of _.keys(erc1155HoldingsByOwner.nonFungible[owner])) { - const tokenIds = _.flatten(_.values(erc1155HoldingsByOwner.nonFungible[owner][contract])); - _.set(result as any, [owner, contract, 'nonFungible'], _.uniqBy(tokenIds, v => v.toString(10))); - } - } - return result; + public cloneFrom(balanceStore: BalanceStore): void { + this._balances = _.cloneDeep(balanceStore._balances); + this._tokenAddresses = _.cloneDeep(balanceStore._tokenAddresses); + this._ownerAddresses = _.cloneDeep(balanceStore._ownerAddresses); + this._addressNames = _.cloneDeep(balanceStore._addressNames); } /** - * Encodes token balances in a way that they can be compared by lodash. + * Returns the human-readable name for the given address, if it exists. + * @param address The address to get the name for. */ - protected static _encodeTokenBalances(obj: any): any { - if (!_.isPlainObject(obj)) { - if (BigNumber.isBigNumber(obj)) { - return obj.toString(10); - } - if (_.isArray(obj)) { - return _.sortBy(obj, v => BalanceStore._encodeTokenBalances(v)); - } - return obj; + private _readableAddressName(address: string): string { + return this._addressNames[address] || address; + } + + /** + * Throws iff balance stores do not have the same ETH balances. + * @param rhs Balance store to compare to + */ + private _assertEthBalancesEqual(rhs: BalanceStore): void { + for (const ownerAddress of [...this._ownerAddresses, ...rhs._ownerAddresses]) { + const thisBalance = _.get(this._balances.eth, [ownerAddress], new BigNumber(0)); + const rhsBalance = _.get(rhs._balances.eth, [ownerAddress], new BigNumber(0)); + expect(thisBalance, `${this._readableAddressName(ownerAddress)} ETH balance`).to.bignumber.equal( + rhsBalance, + ); } - const keys = _.keys(obj).sort(); - return _.zip(keys, keys.map(k => BalanceStore._encodeTokenBalances(obj[k]))); } /** - * Constructor. + * Throws iff balance stores do not have the same ERC20 balances. + * @param rhs Balance store to compare to */ - public constructor() { - this._balances = { erc20: {}, erc721: {}, erc1155: {}, eth: {} }; + private _assertErc20BalancesEqual(rhs: BalanceStore): void { + for (const ownerAddress of [...this._ownerAddresses, ...rhs._ownerAddresses]) { + for (const tokenAddress of [...this._tokenAddresses.erc20, ...rhs._tokenAddresses.erc20]) { + const thisBalance = _.get(this._balances.erc20, [ownerAddress, tokenAddress], new BigNumber(0)); + const rhsBalance = _.get(rhs._balances.erc20, [ownerAddress, tokenAddress], new BigNumber(0)); + expect( + thisBalance, + `${this._readableAddressName(ownerAddress)} ${this._readableAddressName(tokenAddress)} balance`, + ).to.bignumber.equal(rhsBalance); + } + } } /** - * Copies the balance from an existing balance store. - * @param balanceStore to copy balances from. + * Throws iff balance stores do not have the same ERC721 balances. + * @param rhs Balance store to compare to */ - public copyBalancesFrom(balanceStore: BalanceStore): void { - this._balances = _.cloneDeep(balanceStore._balances); + private _assertErc721BalancesEqual(rhs: BalanceStore): void { + for (const ownerAddress of [...this._ownerAddresses, ...rhs._ownerAddresses]) { + for (const tokenAddress of [...this._tokenAddresses.erc721, ...rhs._tokenAddresses.erc721]) { + const thisBalance = _.get(this._balances.erc721, [ownerAddress, tokenAddress], []); + const rhsBalance = _.get(rhs._balances.erc721, [ownerAddress, tokenAddress], []); + expect( + thisBalance, + `${this._readableAddressName(ownerAddress)} ${this._readableAddressName(tokenAddress)} balance`, + ).to.deep.equal(rhsBalance); + } + } } /** - * Returns the raw `TokenBalances` that this class encapsulates. + * Throws iff balance stores do not have the same ERC1155 balances. + * @param rhs Balance store to compare to */ - public getRawBalances(): TokenBalances { - return _.cloneDeep(this._balances); + private _assertErc1155BalancesEqual(rhs: BalanceStore): void { + for (const ownerAddress of [...this._ownerAddresses, ...rhs._ownerAddresses]) { + for (const tokenAddress of [...this._tokenAddresses.erc1155, ...rhs._tokenAddresses.erc1155]) { + const thisBalance = _.get(this._balances.erc1155, [ownerAddress, tokenAddress], {}); + const rhsBalance = _.get(rhs._balances.erc1155, [ownerAddress, tokenAddress], {}); + expect( + thisBalance, + `${this._readableAddressName(ownerAddress)} ${this._readableAddressName(tokenAddress)} balance`, + ).to.deep.equal(rhsBalance); + } + } } } diff --git a/contracts/exchange/test/balance_stores/blockchain_balance_store.ts b/contracts/exchange/test/balance_stores/blockchain_balance_store.ts index ce994d2f0c..64952296b2 100644 --- a/contracts/exchange/test/balance_stores/blockchain_balance_store.ts +++ b/contracts/exchange/test/balance_stores/blockchain_balance_store.ts @@ -1,40 +1,140 @@ -import { ERC1155ProxyWrapper, ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; +import { web3Wrapper } from '@0x/contracts-test-utils'; +import { BigNumber } from '@0x/utils'; +import * as combinatorics from 'js-combinatorics'; +import * as _ from 'lodash'; import { BalanceStore } from './balance_store'; +import { TokenContracts, TokenContractsByName, TokenIds, TokenOwnersByName } from './types'; export class BlockchainBalanceStore extends BalanceStore { - private readonly _erc20Wrapper: ERC20Wrapper; - private readonly _erc721Wrapper: ERC721Wrapper; - private readonly _erc1155ProxyWrapper: ERC1155ProxyWrapper; + private readonly _tokenContracts: TokenContracts; + private readonly _tokenIds: TokenIds; /** * Constructor. - * @param erc20Wrapper The ERC20 Wrapper used to interface with deployed erc20 tokens. - * @param erc721Wrapper The ERC721 Wrapper used to interface with deployed erc20 tokens. - * @param erc1155ProxyWrapper The ERC1155 Proxy Wrapper used to interface with deployed erc20 tokens. + * @param tokenOwnersByName The addresses of token owners whose balances will be tracked. + * @param tokenContractsByName The contracts of tokens to track. + * @param tokenIds The tokenIds of ERC721 and ERC1155 assets to track. */ public constructor( - erc20Wrapper: ERC20Wrapper, - erc721Wrapper: ERC721Wrapper, - erc1155ProxyWrapper: ERC1155ProxyWrapper, + tokenOwnersByName: TokenOwnersByName, + tokenContractsByName: Partial, + tokenIds: Partial, ) { - super(); - this._erc20Wrapper = erc20Wrapper; - this._erc721Wrapper = erc721Wrapper; - this._erc1155ProxyWrapper = erc1155ProxyWrapper; + super(tokenOwnersByName, tokenContractsByName); + this._tokenContracts = { + erc20: Object.values(tokenContractsByName.erc20 || {}), + erc721: Object.values(tokenContractsByName.erc721 || {}), + erc1155: Object.values(tokenContractsByName.erc1155 || {}), + }; + this._tokenIds = { + erc721: tokenIds.erc721 || {}, + erc1155: tokenIds.erc1155 || {}, + }; } /** - * Updates balances by querying on-chain values managed by the erc20, erc721, and erc1155 wrappers. + * Updates balances by querying on-chain values. */ public async updateBalancesAsync(): Promise { - const [erc20, erc721, erc1155] = await Promise.all([ - this._erc20Wrapper.getBalancesAsync(), - this._erc721Wrapper.getBalancesAsync(), - this._erc1155ProxyWrapper.getBalancesAsync(), + await Promise.all([ + this.updateEthBalancesAsync(), + this.updateErc20BalancesAsync(), + this.updateErc721BalancesAsync(), + this.updateErc1155BalancesAsync(), ]); - this._balances.erc20 = erc20; - this._balances.erc721 = erc721; - this._balances.erc1155 = BalanceStore._transformERC1155Holdings(erc1155); + } + + /** + * Updates ETH balances. + */ + public async updateEthBalancesAsync(): Promise { + const ethBalances = _.zipObject( + this._ownerAddresses, + await Promise.all(this._ownerAddresses.map(address => web3Wrapper.getBalanceInWeiAsync(address))), + ); + this._balances.eth = ethBalances; + } + + /** + * Updates ERC20 balances. + */ + public async updateErc20BalancesAsync(): Promise { + const balances = await Promise.all( + this._ownerAddresses.map(async account => + _.zipObject( + this._tokenContracts.erc20.map(token => token.address), + await Promise.all(this._tokenContracts.erc20.map(token => token.balanceOf.callAsync(account))), + ), + ), + ); + this._balances.erc20 = _.zipObject(this._ownerAddresses, balances); + } + + /** + * Updates ERC721 balances. + */ + public async updateErc721BalancesAsync(): Promise { + const erc721ContractsByAddress = _.zipObject( + this._tokenContracts.erc721.map(contract => contract.address), + this._tokenContracts.erc721, + ); + + this._balances.erc721 = {}; + for (const [tokenAddress, tokenIds] of Object.entries(this._tokenIds.erc721)) { + for (const tokenId of tokenIds) { + const tokenOwner = await erc721ContractsByAddress[tokenAddress].ownerOf.callAsync(tokenId); + _.update(this._balances.erc721, [tokenOwner, tokenAddress], nfts => _.union([tokenId], nfts).sort()); + } + } + } + + /** + * Updates ERC1155 balances. + */ + public async updateErc1155BalancesAsync(): Promise { + const erc1155ContractsByAddress = _.zipObject( + this._tokenContracts.erc1155.map(contract => contract.address), + this._tokenContracts.erc1155, + ); + + for (const [tokenAddress, { fungible, nonFungible }] of Object.entries(this._tokenIds.erc1155)) { + const contract = erc1155ContractsByAddress[tokenAddress]; + const tokenIds = [...fungible, ...nonFungible]; + if (this._ownerAddresses.length === 0 || tokenIds.length === 0) { + continue; + } + + const [_tokenIds, _tokenOwners] = _.unzip( + combinatorics.cartesianProduct(tokenIds, this._ownerAddresses).toArray(), + ); + const balances = await contract.balanceOfBatch.callAsync( + _tokenOwners as string[], + _tokenIds as BigNumber[], + ); + + let i = 0; + for (const tokenOwner of this._ownerAddresses) { + // Fungible tokens + _.set(this._balances.erc1155, [tokenOwner, tokenAddress, 'fungible'], {}); + for (const tokenId of fungible) { + _.set( + this._balances.erc1155, + [tokenOwner, tokenAddress, 'fungible', tokenId.toString()], + balances[i++], + ); + } + // Non-fungible tokens + _.set(this._balances.erc1155, [tokenOwner, tokenAddress, 'nonFungible'], []); + for (const tokenId of nonFungible) { + const isOwner = balances[i++]; + if (isOwner.isEqualTo(1)) { + _.update(this._balances.erc1155, [tokenOwner, tokenAddress, 'nonFungible'], nfts => + _.union([tokenId], nfts).sort(), + ); + } + } + } + } } } diff --git a/contracts/exchange/test/balance_stores/index.ts b/contracts/exchange/test/balance_stores/index.ts new file mode 100644 index 0000000000..cb0e290bca --- /dev/null +++ b/contracts/exchange/test/balance_stores/index.ts @@ -0,0 +1,4 @@ +export { BalanceStore } from './balance_store'; +export { LocalBalanceStore } from './local_balance_store'; +export { BlockchainBalanceStore } from './blockchain_balance_store'; +export * from './types'; diff --git a/contracts/exchange/test/balance_stores/local_balance_store.ts b/contracts/exchange/test/balance_stores/local_balance_store.ts index 7d339c4182..6f2a65806d 100644 --- a/contracts/exchange/test/balance_stores/local_balance_store.ts +++ b/contracts/exchange/test/balance_stores/local_balance_store.ts @@ -1,28 +1,42 @@ +import { constants } from '@0x/contracts-test-utils'; import { assetDataUtils } from '@0x/order-utils'; import { AssetProxyId } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import { BalanceStore } from './balance_store'; +import { TokenContractsByName, TokenOwnersByName } from './types'; export class LocalBalanceStore extends BalanceStore { /** * Creates a new balance store based on an existing one. - * @param balanceStore Existing balance store whose values should be copied. + * @param sourceBalanceStore Existing balance store whose values should be copied. */ public static create(sourceBalanceStore?: BalanceStore): LocalBalanceStore { const localBalanceStore = new LocalBalanceStore(); if (sourceBalanceStore !== undefined) { - localBalanceStore.copyBalancesFrom(sourceBalanceStore); + localBalanceStore.cloneFrom(sourceBalanceStore); } return localBalanceStore; } /** * Constructor. + * Note that parameters are given {} defaults because `LocalBalanceStore`s will typically + * be initialized via `create`. */ - public constructor() { - super(); + public constructor( + tokenOwnersByName: TokenOwnersByName = {}, + tokenContractsByName: Partial = {}, + ) { + super(tokenOwnersByName, tokenContractsByName); + } + + /** + * Decreases the ETH balance of an address to simulate gas usage. + */ + public burnGas(senderAddress: string, amount: BigNumber | number): void { + this._balances.eth[senderAddress] = this._balances.eth[senderAddress].minus(amount); } /** @@ -41,52 +55,66 @@ export class LocalBalanceStore extends BalanceStore { case AssetProxyId.ERC20: { const erc20AssetData = assetDataUtils.decodeERC20AssetData(assetData); const assetAddress = erc20AssetData.tokenAddress; - const fromBalances = this._balances.erc20[fromAddress]; - const toBalances = this._balances.erc20[toAddress]; - fromBalances[assetAddress] = fromBalances[assetAddress].minus(amount); - toBalances[assetAddress] = toBalances[assetAddress].plus(amount); + _.update(this._balances.erc20, [fromAddress, assetAddress], balance => balance.minus(amount)); + _.update(this._balances.erc20, [toAddress, assetAddress], balance => + (balance || constants.ZERO_AMOUNT).plus(amount), + ); break; } case AssetProxyId.ERC721: { const erc721AssetData = assetDataUtils.decodeERC721AssetData(assetData); const assetAddress = erc721AssetData.tokenAddress; const tokenId = erc721AssetData.tokenId; - const fromTokens = this._balances.erc721[fromAddress][assetAddress]; - const toTokens = this._balances.erc721[toAddress][assetAddress]; + const fromTokens = _.get(this._balances.erc721, [fromAddress, assetAddress], []); + const toTokens = _.get(this._balances.erc721, [toAddress, assetAddress], []); if (amount.gte(1)) { - const tokenIndex = _.findIndex(fromTokens, t => t.eq(tokenId)); + const tokenIndex = _.findIndex(fromTokens as BigNumber[], t => t.eq(tokenId)); if (tokenIndex !== -1) { fromTokens.splice(tokenIndex, 1); toTokens.push(tokenId); + toTokens.sort(); } } + _.set(this._balances.erc721, [fromAddress, assetAddress], fromTokens); + _.set(this._balances.erc721, [toAddress, assetAddress], toTokens); break; } case AssetProxyId.ERC1155: { const erc1155AssetData = assetDataUtils.decodeERC1155AssetData(assetData); const assetAddress = erc1155AssetData.tokenAddress; - const fromBalances = this._balances.erc1155[fromAddress][assetAddress]; - const toBalances = this._balances.erc1155[toAddress][assetAddress]; - for (const i of _.times(erc1155AssetData.tokenIds.length)) { - const tokenId = erc1155AssetData.tokenIds[i]; + const fromBalances = { + // tslint:disable-next-line:no-inferred-empty-object-type + fungible: _.get(this._balances.erc1155, [fromAddress, assetAddress, 'fungible'], {}), + nonFungible: _.get(this._balances.erc1155, [fromAddress, assetAddress, 'nonFungible'], []), + }; + const toBalances = { + // tslint:disable-next-line:no-inferred-empty-object-type + fungible: _.get(this._balances.erc1155, [toAddress, assetAddress, 'fungible'], {}), + nonFungible: _.get(this._balances.erc1155, [toAddress, assetAddress, 'nonFungible'], []), + }; + for (const [i, tokenId] of erc1155AssetData.tokenIds.entries()) { const tokenValue = erc1155AssetData.tokenValues[i]; const tokenAmount = amount.times(tokenValue); if (tokenAmount.gt(0)) { - const tokenIndex = _.findIndex(fromBalances.nonFungible, t => t.eq(tokenId)); + const tokenIndex = _.findIndex(fromBalances.nonFungible as BigNumber[], t => t.eq(tokenId)); if (tokenIndex !== -1) { // Transfer a non-fungible. fromBalances.nonFungible.splice(tokenIndex, 1); toBalances.nonFungible.push(tokenId); + // sort NFT's by name + toBalances.nonFungible.sort(); } else { // Transfer a fungible. - const _tokenId = tokenId.toString(10); - fromBalances.fungible[_tokenId] = fromBalances.fungible[_tokenId].minus(tokenAmount); - toBalances.fungible[_tokenId] = toBalances.fungible[_tokenId].plus(tokenAmount); + const _tokenId = tokenId.toString(); + _.update(fromBalances.fungible, [_tokenId], balance => balance.minus(tokenAmount)); + _.update(toBalances.fungible, [_tokenId], balance => + (balance || constants.ZERO_AMOUNT).plus(tokenAmount), + ); } } } - // sort NFT's by name - toBalances.nonFungible.sort(); + _.set(this._balances.erc1155, [fromAddress, assetAddress], fromBalances); + _.set(this._balances.erc1155, [toAddress, assetAddress], toBalances); break; } case AssetProxyId.MultiAsset: { diff --git a/contracts/exchange/test/balance_stores/types.ts b/contracts/exchange/test/balance_stores/types.ts new file mode 100644 index 0000000000..c8090f0e39 --- /dev/null +++ b/contracts/exchange/test/balance_stores/types.ts @@ -0,0 +1,51 @@ +import { ERC1155MintableContract } from '@0x/contracts-erc1155'; +import { DummyERC20TokenContract, DummyNoReturnERC20TokenContract } from '@0x/contracts-erc20'; +import { DummyERC721TokenContract } from '@0x/contracts-erc721'; +import { BigNumber } from '@0x/utils'; + +// alias for clarity +type address = string; + +interface TokenData { + erc20: TERC20; + erc721: TERC721; + erc1155: TERC1155; +} + +export type TokenAddresses = TokenData; + +export type TokenContracts = TokenData< + Array, + DummyERC721TokenContract[], + ERC1155MintableContract[] +>; + +interface Named { + [readableName: string]: T; +} + +export type TokenOwnersByName = Named
; + +export type TokenAddressesByName = TokenData, Named
, Named
>; + +export type TokenContractsByName = TokenData< + Named, + Named, + Named +>; + +interface ERC721TokenIds { + [tokenAddress: string]: BigNumber[]; +} + +interface ERC1155TokenIds { + [tokenAddress: string]: { + fungible: BigNumber[]; + nonFungible: BigNumber[]; + }; +} + +export interface TokenIds { + erc721: ERC721TokenIds; + erc1155: ERC1155TokenIds; +} diff --git a/contracts/exchange/test/core.ts b/contracts/exchange/test/core.ts index 8951bb2627..2ee5a2b5e5 100644 --- a/contracts/exchange/test/core.ts +++ b/contracts/exchange/test/core.ts @@ -222,7 +222,27 @@ blockchainTests.resets('Exchange core', () => { }; const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)]; orderFactory = new OrderFactory(privateKey, defaultOrderParams); - fillOrderWrapper = new FillOrderWrapper(exchange, erc20Wrapper, erc721Wrapper, erc1155ProxyWrapper, provider); + + const tokenContracts = { + erc20: { erc20TokenA, erc20TokenB, feeToken, noReturnErc20Token }, + erc721: { erc721Token }, + erc1155: { erc1155Contract }, + }; + const tokenIds = { + erc721: { [erc721Token.address]: [...erc721MakerAssetIds, ...erc721TakerAssetIds] }, + erc1155: { + [erc1155Contract.address]: { + fungible: erc1155FungibleTokens, + nonFungible: [...erc1155NonFungibleTokensOwnedByMaker, ...erc1155NonFungibleTokensOwnedByTaker], + }, + }, + }; + fillOrderWrapper = new FillOrderWrapper( + exchange, + { makerAddress, takerAddress, feeRecipientAddress }, + tokenContracts, + tokenIds, + ); }); describe('fillOrder', () => { beforeEach(async () => { diff --git a/contracts/exchange/test/match_orders.ts b/contracts/exchange/test/match_orders.ts index 3c74932c8c..c2d1a09bb3 100644 --- a/contracts/exchange/test/match_orders.ts +++ b/contracts/exchange/test/match_orders.ts @@ -141,56 +141,30 @@ describe('matchOrders', () => { await exchangeWrapper.registerAssetProxyAsync(erc1155Proxy.address, owner); await exchangeWrapper.registerAssetProxyAsync(multiAssetProxyContract.address, owner); // Authorize proxies. - await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - exchange.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - exchange.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - exchange.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await multiAssetProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync( - exchange.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxyContract.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxyContract.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxyContract.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync( - erc20Proxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync( - erc721Proxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync( - erc1155Proxy.address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner }); + await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner }); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner }); + await multiAssetProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { + from: owner, + }); + await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxyContract.address, { + from: owner, + }); + await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxyContract.address, { + from: owner, + }); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxyContract.address, { + from: owner, + }); + await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, { + from: owner, + }); + await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, { + from: owner, + }); + await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync(erc1155Proxy.address, { + from: owner, + }); // Set default addresses defaultERC20MakerAssetAddress = erc20Tokens[0].address; diff --git a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts index 89cf4e801e..bee9116bc4 100644 --- a/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts +++ b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts @@ -123,65 +123,37 @@ export async function fillOrderCombinatorialUtilsFactoryAsync( await exchangeWrapper.registerAssetProxyAsync(erc1155Proxy.address, ownerAddress); await exchangeWrapper.registerAssetProxyAsync(multiAssetProxy.address, ownerAddress); - await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - exchangeContract.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeContract.address, { + from: ownerAddress, + }); - await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - exchangeContract.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeContract.address, { + from: ownerAddress, + }); - await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - exchangeContract.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeContract.address, { + from: ownerAddress, + }); - await multiAssetProxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - exchangeContract.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await multiAssetProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeContract.address, { + from: ownerAddress, + }); - await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxy.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { from: ownerAddress }); - await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxy.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { + from: ownerAddress, + }); - await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync( - multiAssetProxy.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { + from: ownerAddress, + }); - await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync( - erc20Proxy.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, { from: ownerAddress }); - await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync( - erc721Proxy.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, { from: ownerAddress }); - await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync( - erc1155Proxy.address, - { from: ownerAddress }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc1155Proxy.address, { from: ownerAddress }); const orderFactory = new OrderFactoryFromScenario( userAddresses, diff --git a/contracts/extensions/CHANGELOG.json b/contracts/extensions/CHANGELOG.json index e357e80602..5f12dbaa04 100644 --- a/contracts/extensions/CHANGELOG.json +++ b/contracts/extensions/CHANGELOG.json @@ -4,6 +4,10 @@ "changes": [ { "note": "Dependencies updated" + }, + { + "note": "Replaced the use of `SafeMath` with `LibSafeMath`", + "pr": 2254 } ], "timestamp": 1570135330 diff --git a/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol b/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol index 78f69fa4c3..e8ddfaca64 100644 --- a/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol +++ b/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol @@ -23,13 +23,13 @@ import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; -import "@0x/contracts-utils/contracts/src/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; -contract DutchAuction is - SafeMath -{ +contract DutchAuction { + using LibBytes for bytes; + using LibSafeMath for uint256; // solhint-disable var-name-mixedcase IExchange internal EXCHANGE; @@ -120,8 +120,8 @@ contract DutchAuction is address token = assetData.readAddress(16); // Calculate the excess from the buy order. This can occur if the buyer sends in a higher // amount than the calculated current amount - uint256 buyerExcessAmount = _safeSub(buyOrder.makerAssetAmount, auctionDetails.currentAmount); - uint256 sellerExcessAmount = _safeSub(leftMakerAssetSpreadAmount, buyerExcessAmount); + uint256 buyerExcessAmount = buyOrder.makerAssetAmount.safeSub(auctionDetails.currentAmount); + uint256 sellerExcessAmount = leftMakerAssetSpreadAmount.safeSub(buyerExcessAmount); // Return the difference between auctionDetails.currentAmount and sellOrder.takerAssetAmount // to the seller if (sellerExcessAmount > 0) { @@ -190,12 +190,8 @@ contract DutchAuction is // Auction end time is guaranteed by 0x Exchange due to the order expiration auctionDetails.currentAmount = minAmount; } else { - auctionDetails.currentAmount = _safeAdd( - minAmount, - _safeDiv( - _safeMul(remainingDurationSeconds, amountDelta), - auctionDurationSeconds - ) + auctionDetails.currentAmount = minAmount.safeAdd( + remainingDurationSeconds.safeMul(amountDelta).safeDiv(auctionDurationSeconds) ); } return auctionDetails; diff --git a/contracts/extensions/package.json b/contracts/extensions/package.json index 982f4edf5e..6d7716c0a3 100644 --- a/contracts/extensions/package.json +++ b/contracts/extensions/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", diff --git a/contracts/integrations/src/index.ts b/contracts/integrations/src/index.ts index a51a51959b..d55f08ea2d 100644 --- a/contracts/integrations/src/index.ts +++ b/contracts/integrations/src/index.ts @@ -1,3 +1,2 @@ export * from './artifacts'; export * from './wrappers'; -export * from './deployment_mananger'; diff --git a/contracts/integrations/test/actors/base.ts b/contracts/integrations/test/actors/base.ts new file mode 100644 index 0000000000..c3638c817d --- /dev/null +++ b/contracts/integrations/test/actors/base.ts @@ -0,0 +1,54 @@ +import { DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20'; +import { constants } from '@0x/contracts-test-utils'; +import { BigNumber } from '@0x/utils'; + +import { DeploymentManager } from '../deployment/deployment_mananger'; + +export type Constructor = new (...args: any[]) => T; + +export interface ActorConfig { + address: string; + name?: string; + deployment: DeploymentManager; + [mixinProperty: string]: any; +} + +export class Actor { + public readonly address: string; + public readonly name: string; + public readonly deployment: DeploymentManager; + + constructor(config: ActorConfig) { + this.address = config.address; + this.name = config.name || config.address; + this.deployment = config.deployment; + } + + /** + * Sets a balance for an ERC20 token and approves a spender (defaults to the ERC20 asset proxy) + * to transfer the token. + */ + public async configureERC20TokenAsync( + token: DummyERC20TokenContract | WETH9Contract, + spender?: string, + amount?: BigNumber, + ): Promise { + if (token instanceof DummyERC20TokenContract) { + await token.setBalance.awaitTransactionSuccessAsync( + this.address, + amount || constants.INITIAL_ERC20_BALANCE, + ); + } else { + await token.deposit.awaitTransactionSuccessAsync({ + from: this.address, + value: amount || constants.ONE_ETHER, + }); + } + + await token.approve.awaitTransactionSuccessAsync( + spender || this.deployment.assetProxies.erc20Proxy.address, + constants.MAX_UINT256, + { from: this.address }, + ); + } +} diff --git a/contracts/integrations/test/actors/hybrids.ts b/contracts/integrations/test/actors/hybrids.ts new file mode 100644 index 0000000000..bd55763de8 --- /dev/null +++ b/contracts/integrations/test/actors/hybrids.ts @@ -0,0 +1,5 @@ +import { Actor } from './base'; +import { MakerMixin } from './maker'; +import { PoolOperatorMixin } from './pool_operator'; + +export class OperatorMaker extends PoolOperatorMixin(MakerMixin(Actor)) {} diff --git a/contracts/integrations/test/actors/index.ts b/contracts/integrations/test/actors/index.ts new file mode 100644 index 0000000000..ab525a5a70 --- /dev/null +++ b/contracts/integrations/test/actors/index.ts @@ -0,0 +1,3 @@ +export { Maker } from './maker'; +export { PoolOperator } from './pool_operator'; +export * from './hybrids'; diff --git a/contracts/integrations/test/actors/maker.ts b/contracts/integrations/test/actors/maker.ts new file mode 100644 index 0000000000..870716c7d2 --- /dev/null +++ b/contracts/integrations/test/actors/maker.ts @@ -0,0 +1,59 @@ +import { constants, OrderFactory } from '@0x/contracts-test-utils'; +import { Order, SignedOrder } from '@0x/types'; +import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; + +import { Actor, ActorConfig, Constructor } from './base'; + +export interface MakerConfig extends ActorConfig { + orderConfig: Partial; +} + +export function MakerMixin(Base: TBase) { + return class extends Base { + public poolId?: string; + public readonly actor: Actor; + public readonly orderFactory: OrderFactory; + + /** + * The mixin pattern requires that this constructor uses `...args: any[]`, but this class + * really expects a single `MakerConfig` parameter (assuming `Actor` is used as the base + * class). + */ + constructor(...args: any[]) { + super(...args); + this.actor = (this as any) as Actor; + + const { orderConfig } = args[0] as MakerConfig; + const defaultOrderParams = { + ...constants.STATIC_ORDER_PARAMS, + makerAddress: this.actor.address, + exchangeAddress: this.actor.deployment.exchange.address, + chainId: this.actor.deployment.chainId, + ...orderConfig, + }; + const privateKey = + constants.TESTRPC_PRIVATE_KEYS[this.actor.deployment.accounts.indexOf(this.actor.address)]; + this.orderFactory = new OrderFactory(privateKey, defaultOrderParams); + } + + /** + * Signs an order (optionally, with custom parameters) as the maker. + */ + public async signOrderAsync(customOrderParams: Partial = {}): Promise { + return this.orderFactory.newSignedOrderAsync(customOrderParams); + } + + /** + * Joins the staking pool specified by the given ID. + */ + public async joinStakingPoolAsync(poolId: string): Promise { + const stakingContract = this.actor.deployment.staking.stakingWrapper; + this.poolId = poolId; + return stakingContract.joinStakingPoolAsMaker.awaitTransactionSuccessAsync(poolId, { + from: this.actor.address, + }); + } + }; +} + +export class Maker extends MakerMixin(Actor) {} diff --git a/contracts/integrations/test/actors/pool_operator.ts b/contracts/integrations/test/actors/pool_operator.ts new file mode 100644 index 0000000000..3f15b8a002 --- /dev/null +++ b/contracts/integrations/test/actors/pool_operator.ts @@ -0,0 +1,66 @@ +import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; + +import { Actor, ActorConfig, Constructor } from './base'; + +export interface PoolOperatorConfig extends ActorConfig { + operatorShare: number; +} + +export function PoolOperatorMixin(Base: TBase) { + return class extends Base { + public operatorShare: number; + public readonly poolIds: string[] = []; + public readonly actor: Actor; + + /** + * The mixin pattern requires that this constructor uses `...args: any[]`, but this class + * really expects a single `PoolOperatorConfig` parameter (assuming `Actor` is used as the + * base class). + */ + constructor(...args: any[]) { + super(...args); + this.actor = (this as any) as Actor; + + const { operatorShare } = args[0] as PoolOperatorConfig; + this.operatorShare = operatorShare; + } + + /** + * Creates a staking pool and returns the ID of the new pool. + */ + public async createStakingPoolAsync( + operatorShare: number, + addOperatorAsMaker: boolean = false, + ): Promise { + const stakingContract = this.actor.deployment.staking.stakingWrapper; + const txReceipt = await stakingContract.createStakingPool.awaitTransactionSuccessAsync( + operatorShare, + addOperatorAsMaker, + { from: this.actor.address }, + ); + + const createStakingPoolLog = txReceipt.logs[0]; + const poolId = (createStakingPoolLog as any).args.poolId; + this.poolIds.push(poolId); + return poolId; + } + + /** + * Decreases the operator share of a specified staking pool. + */ + public async decreaseOperatorShareAsync( + poolId: string, + newOperatorShare: number, + ): Promise { + const stakingContract = this.actor.deployment.staking.stakingWrapper; + this.operatorShare = newOperatorShare; + return stakingContract.decreaseStakingPoolOperatorShare.awaitTransactionSuccessAsync( + poolId, + newOperatorShare, + { from: this.actor.address }, + ); + } + }; +} + +export class PoolOperator extends PoolOperatorMixin(Actor) {} diff --git a/contracts/coordinator/test/coordinator.ts b/contracts/integrations/test/coordinator/coordinator.ts similarity index 99% rename from contracts/coordinator/test/coordinator.ts rename to contracts/integrations/test/coordinator/coordinator.ts index 02db8841e3..c4671a7994 100644 --- a/contracts/coordinator/test/coordinator.ts +++ b/contracts/integrations/test/coordinator/coordinator.ts @@ -1,4 +1,5 @@ import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy'; +import { ApprovalFactory, artifacts, CoordinatorContract } from '@0x/contracts-coordinator'; import { artifacts as erc20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20'; import { artifacts as exchangeArtifacts, @@ -19,7 +20,7 @@ import { import { assetDataUtils, CoordinatorRevertErrors, transactionHashUtils } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; -import { ApprovalFactory, artifacts, CoordinatorContract, CoordinatorTestFactory } from '../src'; +import { CoordinatorTestFactory } from './coordinator_test_factory'; // tslint:disable:no-unnecessary-type-assertion blockchainTests.resets('Coordinator tests', env => { diff --git a/contracts/coordinator/test/utils/coordinator_test_factory.ts b/contracts/integrations/test/coordinator/coordinator_test_factory.ts similarity index 91% rename from contracts/coordinator/test/utils/coordinator_test_factory.ts rename to contracts/integrations/test/coordinator/coordinator_test_factory.ts index caca5877da..bd3ba81f2d 100644 --- a/contracts/coordinator/test/utils/coordinator_test_factory.ts +++ b/contracts/integrations/test/coordinator/coordinator_test_factory.ts @@ -1,4 +1,5 @@ import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; +import { CoordinatorContract } from '@0x/contracts-coordinator'; import { ExchangeCancelEventArgs, ExchangeCancelUpToEventArgs, @@ -6,31 +7,17 @@ import { ExchangeFillEventArgs, ExchangeFunctionName, } from '@0x/contracts-exchange'; -import { expect, filterLogsToArguments, Numberish, TokenBalances, web3Wrapper } from '@0x/contracts-test-utils'; +import { expect, Numberish, TokenBalances, verifyEvents, web3Wrapper } from '@0x/contracts-test-utils'; import { assetDataUtils, orderHashUtils } from '@0x/order-utils'; import { SignedOrder, SignedZeroExTransaction } from '@0x/types'; import { BigNumber, RevertError } from '@0x/utils'; import { TransactionReceiptWithDecodedLogs, TxData } from 'ethereum-types'; import * as _ from 'lodash'; -import { CoordinatorContract } from '../../src'; - export class CoordinatorTestFactory { private readonly _addresses: string[]; private readonly _protocolFee: BigNumber; - public static verifyEvents( - txReceipt: TransactionReceiptWithDecodedLogs, - expectedEvents: TEventArgs[], - eventName: string, - ): void { - const logs = filterLogsToArguments(txReceipt.logs, eventName); - expect(logs.length).to.eq(expectedEvents.length); - logs.forEach((log, index) => { - expect(log).to.deep.equal(expectedEvents[index]); - }); - } - private static _expectedCancelEvent(order: SignedOrder): ExchangeCancelEventArgs { return { makerAddress: order.makerAddress, @@ -89,11 +76,7 @@ export class CoordinatorTestFactory { } const transactionReceipt = await tx; - CoordinatorTestFactory.verifyEvents( - transactionReceipt, - orders.map(order => this._expectedFillEvent(order)), - ExchangeEvents.Fill, - ); + verifyEvents(transactionReceipt, orders.map(order => this._expectedFillEvent(order)), ExchangeEvents.Fill); const expectedBalances = this._getExpectedBalances(initBalances, orders, transactionReceipt, txData.value); await this._verifyBalancesAsync(expectedBalances); @@ -121,9 +104,9 @@ export class CoordinatorTestFactory { orderSenderAddress: this._coordinatorContract.address, orderEpoch: new BigNumber(1), }; - CoordinatorTestFactory.verifyEvents(transactionReceipt, [expectedEvent], ExchangeEvents.CancelUpTo); + verifyEvents(transactionReceipt, [expectedEvent], ExchangeEvents.CancelUpTo); } else { - CoordinatorTestFactory.verifyEvents( + verifyEvents( transactionReceipt, orders.map(order => CoordinatorTestFactory._expectedCancelEvent(order)), ExchangeEvents.Cancel, diff --git a/contracts/integrations/test/deployment_manager_test.ts b/contracts/integrations/test/deployment/deployment_manager_test.ts similarity index 92% rename from contracts/integrations/test/deployment_manager_test.ts rename to contracts/integrations/test/deployment/deployment_manager_test.ts index 26591a3b5c..359f165922 100644 --- a/contracts/integrations/test/deployment_manager_test.ts +++ b/contracts/integrations/test/deployment/deployment_manager_test.ts @@ -1,9 +1,8 @@ import { Authorizable, Ownable } from '@0x/contracts-exchange'; import { constants as stakingConstants } from '@0x/contracts-staking'; -import { blockchainTests, constants, expect } from '@0x/contracts-test-utils'; -import { BigNumber } from '@0x/utils'; +import { blockchainTests, expect } from '@0x/contracts-test-utils'; -import { DeploymentManager } from '../src'; +import { DeploymentManager } from './deployment_mananger'; blockchainTests('Deployment Manager', env => { let owner: string; @@ -11,7 +10,6 @@ blockchainTests('Deployment Manager', env => { before(async () => { [owner] = await env.getAccountAddressesAsync(); - deploymentManager = await DeploymentManager.deployAsync(env); }); @@ -42,14 +40,14 @@ blockchainTests('Deployment Manager', env => { describe('asset proxy owner', () => { it('should be owned by `owner`', async () => { // Ensure that the owners of the asset proxy only contain the owner. - const owners = await deploymentManager.assetProxyOwner.getOwners.callAsync(); + const owners = await deploymentManager.governor.getOwners.callAsync(); expect(owners).to.be.deep.eq([owner]); }); }); describe('asset proxies', () => { it('should be owned be the asset proxy owner', async () => { - await batchAssertOwnerAsync(deploymentManager.assetProxyOwner.address, [ + await batchAssertOwnerAsync(deploymentManager.governor.address, [ deploymentManager.assetProxies.erc1155Proxy, deploymentManager.assetProxies.erc20Proxy, deploymentManager.assetProxies.erc721Proxy, @@ -95,7 +93,7 @@ blockchainTests('Deployment Manager', env => { describe('exchange', () => { it('should be owned by the asset proxy owner', async () => { const exchangeOwner = await deploymentManager.exchange.owner.callAsync(); - expect(exchangeOwner).to.be.eq(deploymentManager.assetProxyOwner.address); + expect(exchangeOwner).to.be.eq(deploymentManager.governor.address); }); /* @@ -103,7 +101,7 @@ blockchainTests('Deployment Manager', env => { made an Authorizable contract. it('should have authorized the asset proxy owner', async () => { const isAuthorized = await deploymentManager.exchange.owner.callAsync( - deploymentManager.assetProxyOwner.address, + deploymentManager.governor.address, ); expect(isAuthorized).to.be.true(); }); @@ -123,12 +121,12 @@ blockchainTests('Deployment Manager', env => { describe('staking', () => { it('should be owned by the asset proxy owner', async () => { const stakingOwner = await deploymentManager.staking.stakingProxy.owner.callAsync(); - expect(stakingOwner).to.be.eq(deploymentManager.assetProxyOwner.address); + expect(stakingOwner).to.be.eq(deploymentManager.governor.address); }); it('should have authorized the asset proxy owner in the staking proxy', async () => { const isAuthorized = await deploymentManager.staking.stakingProxy.authorized.callAsync( - deploymentManager.assetProxyOwner.address, + deploymentManager.governor.address, ); expect(isAuthorized).to.be.true(); }); diff --git a/contracts/integrations/src/deployment_mananger.ts b/contracts/integrations/test/deployment/deployment_mananger.ts similarity index 75% rename from contracts/integrations/src/deployment_mananger.ts rename to contracts/integrations/test/deployment/deployment_mananger.ts index f763c3f609..3a8002ce39 100644 --- a/contracts/integrations/src/deployment_mananger.ts +++ b/contracts/integrations/test/deployment/deployment_mananger.ts @@ -6,9 +6,14 @@ import { MultiAssetProxyContract, StaticCallProxyContract, } from '@0x/contracts-asset-proxy'; -import { artifacts as ERC1155Artifacts, ERC1155Contract } from '@0x/contracts-erc1155'; -import { artifacts as ERC20Artifacts, ERC20TokenContract, ZRXTokenContract, WETH9Contract } from '@0x/contracts-erc20'; -import { artifacts as ERC721Artifacts, ERC721TokenContract } from '@0x/contracts-erc721'; +import { artifacts as ERC1155Artifacts, ERC1155MintableContract } from '@0x/contracts-erc1155'; +import { + DummyERC20TokenContract, + artifacts as ERC20Artifacts, + ZRXTokenContract, + WETH9Contract, +} from '@0x/contracts-erc20'; +import { artifacts as ERC721Artifacts, DummyERC721TokenContract } from '@0x/contracts-erc721'; import { artifacts as exchangeArtifacts, AssetProxyDispatcher, @@ -16,22 +21,19 @@ import { ExchangeContract, Ownable, } from '@0x/contracts-exchange'; -import { artifacts as multisigArtifacts, AssetProxyOwnerContract } from '@0x/contracts-multisig'; +import { artifacts as multisigArtifacts, ZeroExGovernorContract } from '@0x/contracts-multisig'; import { artifacts as stakingArtifacts, ReadOnlyProxyContract, - StakingContract, StakingProxyContract, + TestStakingContract, ZrxVaultContract, } from '@0x/contracts-staking'; import { BlockchainTestsEnvironment, constants } from '@0x/contracts-test-utils'; -import { Web3ProviderEngine } from '@0x/subproviders'; import { BigNumber } from '@0x/utils'; import { TxData } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts, TestStakingPlaceholderContract } from './'; - /** * Adds a batch of authorities to a list of authorizable contracts. * @param owner The owner of the authorizable contracts. @@ -76,7 +78,7 @@ async function batchRegisterAssetProxyAsync( */ async function batchTransferOwnershipAsync( owner: string, - newOwner: AssetProxyOwnerContract, + newOwner: ZeroExGovernorContract, ownedContracts: Ownable[], ): Promise { for (const ownedContract of ownedContracts) { @@ -96,45 +98,53 @@ interface AssetProxyContracts { // Contract wrappers for all of the staking contracts interface StakingContracts { readOnlyProxy: ReadOnlyProxyContract; - stakingLogic: TestStakingPlaceholderContract; + stakingLogic: TestStakingContract; stakingProxy: StakingProxyContract; - stakingWrapper: TestStakingPlaceholderContract; + stakingWrapper: TestStakingContract; zrxVault: ZrxVaultContract; } // Contract wrappers for tokens. interface TokenContracts { - erc1155: ERC1155Contract; - erc20: ERC20TokenContract; - erc721: ERC721TokenContract; + erc20: DummyERC20TokenContract[]; + erc721: DummyERC721TokenContract[]; + erc1155: ERC1155MintableContract[]; weth: WETH9Contract; zrx: ZRXTokenContract; } +// Options to be passed to `deployAsync` +export interface DeploymentOptions { + owner: string; + numErc1155TokensToDeploy: number; + numErc20TokensToDeploy: number; + numErc721TokensToDeploy: number; +} + export class DeploymentManager { public static protocolFeeMultiplier = new BigNumber(150000); - public assetProxies: AssetProxyContracts; - public assetProxyOwner: AssetProxyOwnerContract; - public exchange: ExchangeContract; - public staking: StakingContracts; - public tokens: TokenContracts; - /** * Fully deploy the 0x exchange and staking contracts and configure the system with the * asset proxy owner multisig. * @param environment A blockchain test environment to use for contracts deployment. + * @param options Specifies the owner address and number of tokens to deploy. */ - public static async deployAsync(environment: BlockchainTestsEnvironment): Promise { + public static async deployAsync( + environment: BlockchainTestsEnvironment, + options: Partial = {}, + ): Promise { const chainId = await environment.getChainIdAsync(); - const [owner] = await environment.getAccountAddressesAsync(); + const accounts = await environment.getAccountAddressesAsync(); + + const owner = options.owner || (await environment.getAccountAddressesAsync())[0]; const txDefaults = { ...environment.txDefaults, from: owner, }; // Deploy the contracts using the same owner and environment. - const assetProxies = await DeploymentManager._deployAssetProxyContractsAsync(environment, owner, txDefaults); + const assetProxies = await DeploymentManager._deployAssetProxyContractsAsync(environment, txDefaults); const exchange = await ExchangeContract.deployFrom0xArtifactAsync( exchangeArtifacts.Exchange, environment.provider, @@ -142,8 +152,8 @@ export class DeploymentManager { exchangeArtifacts, new BigNumber(chainId), ); - const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync( - multisigArtifacts.AssetProxyOwner, + const governor = await ZeroExGovernorContract.deployFrom0xArtifactAsync( + multisigArtifacts.ZeroExGovernor, environment.provider, txDefaults, multisigArtifacts, @@ -154,7 +164,7 @@ export class DeploymentManager { new BigNumber(1), constants.ZERO_AMOUNT, ); - const tokens = await DeploymentManager._deployTokenContractsAsync(environment, txDefaults); + const tokens = await DeploymentManager._deployTokenContractsAsync(environment, txDefaults, options); const staking = await DeploymentManager._deployStakingContractsAsync( environment, owner, @@ -168,10 +178,10 @@ export class DeploymentManager { await DeploymentManager._configureExchangeWithStakingAsync(exchange, staking, owner); // Authorize the asset-proxy owner in the staking proxy and in the zrx vault. - await staking.stakingProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(assetProxyOwner.address, { + await staking.stakingProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(governor.address, { from: owner, }); - await staking.zrxVault.addAuthorizedAddress.awaitTransactionSuccessAsync(assetProxyOwner.address, { + await staking.zrxVault.addAuthorizedAddress.awaitTransactionSuccessAsync(governor.address, { from: owner, }); @@ -180,7 +190,7 @@ export class DeploymentManager { await staking.zrxVault.removeAuthorizedAddress.awaitTransactionSuccessAsync(owner, { from: owner }); // Transfer complete ownership of the system to the asset proxy owner. - await batchTransferOwnershipAsync(owner, assetProxyOwner, [ + await batchTransferOwnershipAsync(owner, governor, [ assetProxies.erc20Proxy, assetProxies.erc721Proxy, assetProxies.erc1155Proxy, @@ -190,7 +200,7 @@ export class DeploymentManager { staking.stakingProxy, ]); - return new DeploymentManager(assetProxies, assetProxyOwner, exchange, staking, tokens); + return new DeploymentManager(assetProxies, governor, exchange, staking, tokens, chainId, accounts); } /** @@ -273,12 +283,10 @@ export class DeploymentManager { /** * Deploy a set of asset proxy contracts. * @param environment The blockchain environment to use. - * @param owner An owner address to use when configuring the asset proxies. * @param txDefaults Defaults to use when deploying the asset proxies. */ protected static async _deployAssetProxyContractsAsync( environment: BlockchainTestsEnvironment, - owner: string, txDefaults: Partial, ): Promise { const erc20Proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync( @@ -349,8 +357,8 @@ export class DeploymentManager { txDefaults, stakingArtifacts, ); - const stakingLogic = await TestStakingPlaceholderContract.deployFrom0xArtifactAsync( - artifacts.TestStakingPlaceholder, + const stakingLogic = await TestStakingContract.deployFrom0xArtifactAsync( + stakingArtifacts.TestStaking, environment.provider, txDefaults, stakingArtifacts, @@ -365,7 +373,7 @@ export class DeploymentManager { stakingLogic.address, readOnlyProxy.address, ); - const stakingWrapper = new TestStakingPlaceholderContract(stakingProxy.address, environment.provider); + const stakingWrapper = new TestStakingContract(stakingProxy.address, environment.provider); // Add the zrx vault and the weth contract to the staking proxy. await stakingWrapper.setWethContract.awaitTransactionSuccessAsync(tokens.weth.address, { from: owner }); @@ -392,30 +400,67 @@ export class DeploymentManager { * Deploy a set of token contracts. * @param environment The blockchain environment to use. * @param txDefaults Defaults to use when deploying the asset proxies. + * @param options Specifies how many tokens of each standard to deploy. */ protected static async _deployTokenContractsAsync( environment: BlockchainTestsEnvironment, txDefaults: Partial, + options: Partial, ): Promise { - const erc20 = await ERC20TokenContract.deployFrom0xArtifactAsync( - ERC20Artifacts.ERC20Token, - environment.provider, - txDefaults, - ERC20Artifacts, + const numErc20TokensToDeploy = + options.numErc20TokensToDeploy !== undefined + ? options.numErc20TokensToDeploy + : constants.NUM_DUMMY_ERC20_TO_DEPLOY; + const numErc721TokensToDeploy = + options.numErc721TokensToDeploy !== undefined + ? options.numErc721TokensToDeploy + : constants.NUM_DUMMY_ERC721_TO_DEPLOY; + const numErc1155TokensToDeploy = + options.numErc1155TokensToDeploy !== undefined + ? options.numErc1155TokensToDeploy + : constants.NUM_DUMMY_ERC1155_CONTRACTS_TO_DEPLOY; + + const erc20 = await Promise.all( + _.times( + numErc20TokensToDeploy, + async () => + await DummyERC20TokenContract.deployFrom0xArtifactAsync( + ERC20Artifacts.DummyERC20Token, + environment.provider, + txDefaults, + ERC20Artifacts, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + ), ); - - const erc721 = await ERC721TokenContract.deployFrom0xArtifactAsync( - ERC721Artifacts.ERC721Token, - environment.provider, - txDefaults, - ERC721Artifacts, + const erc721 = await Promise.all( + _.times( + numErc721TokensToDeploy, + async () => + await DummyERC721TokenContract.deployFrom0xArtifactAsync( + ERC721Artifacts.DummyERC721Token, + environment.provider, + txDefaults, + ERC721Artifacts, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + ), + ), ); - - const erc1155 = await ERC1155Contract.deployFrom0xArtifactAsync( - ERC1155Artifacts.ERC1155, - environment.provider, - txDefaults, - ERC1155Artifacts, + const erc1155 = await Promise.all( + _.times( + numErc1155TokensToDeploy, + async () => + await ERC1155MintableContract.deployFrom0xArtifactAsync( + ERC1155Artifacts.ERC1155Mintable, + environment.provider, + txDefaults, + ERC1155Artifacts, + ), + ), ); const weth = await WETH9Contract.deployFrom0xArtifactAsync( @@ -424,7 +469,6 @@ export class DeploymentManager { txDefaults, ERC20Artifacts, ); - const zrx = await ZRXTokenContract.deployFrom0xArtifactAsync( ERC20Artifacts.ZRXToken, environment.provider, @@ -433,25 +477,21 @@ export class DeploymentManager { ); return { - erc1155, erc20, erc721, + erc1155, weth, zrx, }; } - private constructor( - assetProxies: AssetProxyContracts, - assetProxyOwner: AssetProxyOwnerContract, - exchange: ExchangeContract, - staking: StakingContracts, - tokens: TokenContracts, - ) { - this.assetProxies = assetProxies; - this.assetProxyOwner = assetProxyOwner; - this.exchange = exchange; - this.staking = staking; - this.tokens = tokens; - } + protected constructor( + public assetProxies: AssetProxyContracts, + public governor: ZeroExGovernorContract, + public exchange: ExchangeContract, + public staking: StakingContracts, + public tokens: TokenContracts, + public chainId: number, + public accounts: string[], + ) {} } diff --git a/contracts/integrations/test/deployment_test.ts b/contracts/integrations/test/deployment/deployment_test.ts similarity index 95% rename from contracts/integrations/test/deployment_test.ts rename to contracts/integrations/test/deployment/deployment_test.ts index fd88c20cc5..a273e633fb 100644 --- a/contracts/integrations/test/deployment_test.ts +++ b/contracts/integrations/test/deployment/deployment_test.ts @@ -17,7 +17,7 @@ import { ExchangeProtocolFeeMultiplierEventArgs, Ownable, } from '@0x/contracts-exchange'; -import { artifacts as multisigArtifacts, AssetProxyOwnerContract } from '@0x/contracts-multisig'; +import { artifacts as multisigArtifacts, ZeroExGovernorContract } from '@0x/contracts-multisig'; import { artifacts as stakingArtifacts, constants as stakingConstants, @@ -43,7 +43,7 @@ blockchainTests('Deployment and Configuration End to End Tests', env => { let owner: string; // Contract Instances - let assetProxyOwner: AssetProxyOwnerContract; + let governor: ZeroExGovernorContract; let erc20Proxy: ERC20ProxyContract; let erc721Proxy: ERC721ProxyContract; let erc1155Proxy: ERC1155ProxyContract; @@ -75,11 +75,11 @@ blockchainTests('Deployment and Configuration End to End Tests', env => { from: owner, }; - // Deploy AssetProxyOwner. For the purposes of this test, we will assume that - // the AssetProxyOwner does not know what destinations will be needed during + // Deploy ZeroExGovernor. For the purposes of this test, we will assume that + // the ZeroExGovernor does not know what destinations will be needed during // construction. - assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync( - multisigArtifacts.AssetProxyOwner, + governor = await ZeroExGovernorContract.deployFrom0xArtifactAsync( + multisigArtifacts.ZeroExGovernor, env.provider, txDefaults, multisigArtifacts, @@ -387,7 +387,7 @@ blockchainTests('Deployment and Configuration End to End Tests', env => { expect(isAuthorized).to.be.false(); // Authorize the asset-proxy owner. - receipt = await contract.addAuthorizedAddress.awaitTransactionSuccessAsync(assetProxyOwner.address, { + receipt = await contract.addAuthorizedAddress.awaitTransactionSuccessAsync(governor.address, { from: owner, }); @@ -396,21 +396,21 @@ blockchainTests('Deployment and Configuration End to End Tests', env => { receipt.logs, AuthorizableEvents.AuthorizedAddressAdded, ); - expect(logs).to.be.deep.eq([{ target: assetProxyOwner.address, caller: owner }]); + expect(logs).to.be.deep.eq([{ target: governor.address, caller: owner }]); // Ensure that the asset-proxy owner was actually authorized. - isAuthorized = await contract.authorized.callAsync(assetProxyOwner.address); + isAuthorized = await contract.authorized.callAsync(governor.address); expect(isAuthorized).to.be.true(); } // Transfers ownership of a contract to the asset-proxy owner, and ensures that the change was actually made. async function transferOwnershipAndAssertSuccessAsync(contract: Ownable): Promise { // Transfer ownership to the new owner. - await contract.transferOwnership.awaitTransactionSuccessAsync(assetProxyOwner.address, { from: owner }); + await contract.transferOwnership.awaitTransactionSuccessAsync(governor.address, { from: owner }); // Ensure that the owner address has been updated. const ownerAddress = await contract.owner.callAsync(); - expect(ownerAddress).to.be.eq(assetProxyOwner.address); + expect(ownerAddress).to.be.eq(governor.address); } it('should transfer authorization of the owner to the asset-proxy owner in the staking contracts', async () => { diff --git a/contracts/multisig/contracts/src/MultiSigWalletWithTimeLock.sol b/contracts/multisig/contracts/src/MultiSigWalletWithTimeLock.sol index aab693e44a..0fa163180e 100644 --- a/contracts/multisig/contracts/src/MultiSigWalletWithTimeLock.sol +++ b/contracts/multisig/contracts/src/MultiSigWalletWithTimeLock.sol @@ -18,6 +18,7 @@ pragma solidity ^0.5.9; +import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "./MultiSigWallet.sol"; @@ -27,6 +28,8 @@ import "./MultiSigWallet.sol"; contract MultiSigWalletWithTimeLock is MultiSigWallet { + using LibSafeMath for uint256; + event ConfirmationTimeSet(uint256 indexed transactionId, uint256 confirmationTime); event TimeLockChange(uint256 secondsTimeLocked); @@ -52,7 +55,7 @@ contract MultiSigWalletWithTimeLock is modifier pastTimeLock(uint256 transactionId) { require( - block.timestamp >= confirmationTimes[transactionId] + secondsTimeLocked, + block.timestamp >= confirmationTimes[transactionId].safeAdd(secondsTimeLocked), "TIME_LOCK_INCOMPLETE" ); _; diff --git a/contracts/multisig/contracts/src/AssetProxyOwner.sol b/contracts/multisig/contracts/src/ZeroExGovernor.sol similarity index 99% rename from contracts/multisig/contracts/src/AssetProxyOwner.sol rename to contracts/multisig/contracts/src/ZeroExGovernor.sol index 9e424e9c7d..b4f1d137bc 100644 --- a/contracts/multisig/contracts/src/AssetProxyOwner.sol +++ b/contracts/multisig/contracts/src/ZeroExGovernor.sol @@ -24,7 +24,7 @@ import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; -contract AssetProxyOwner is +contract ZeroExGovernor is MultiSigWalletWithTimeLock { using LibBytes for bytes; diff --git a/contracts/multisig/contracts/test/TestAssetProxyOwner.sol b/contracts/multisig/contracts/test/TestZeroExGovernor.sol similarity index 94% rename from contracts/multisig/contracts/test/TestAssetProxyOwner.sol rename to contracts/multisig/contracts/test/TestZeroExGovernor.sol index 224b92edf2..4504098fde 100644 --- a/contracts/multisig/contracts/test/TestAssetProxyOwner.sol +++ b/contracts/multisig/contracts/test/TestZeroExGovernor.sol @@ -19,12 +19,12 @@ pragma solidity ^0.5.9; pragma experimental ABIEncoderV2; -import "../src/AssetProxyOwner.sol"; +import "../src/ZeroExGovernor.sol"; // solhint-disable no-empty-blocks -contract TestAssetProxyOwner is - AssetProxyOwner +contract TestZeroExGovernor is + ZeroExGovernor { constructor ( bytes4[] memory _functionSelectors, @@ -35,7 +35,7 @@ contract TestAssetProxyOwner is uint256 _defaultSecondsTimeLocked ) public - AssetProxyOwner( + ZeroExGovernor( _functionSelectors, _destinations, _functionCallTimeLockSeconds, diff --git a/contracts/multisig/package.json b/contracts/multisig/package.json index 1e4d940868..a97a278696 100644 --- a/contracts/multisig/package.json +++ b/contracts/multisig/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", @@ -34,7 +34,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "./generated-artifacts/@(AssetProxyOwner|ContractCallReceiver|MultiSigWallet|MultiSigWalletWithTimeLock|TestAssetProxyOwner|TestRejectEther).json", + "abis": "./generated-artifacts/@(ContractCallReceiver|MultiSigWallet|MultiSigWalletWithTimeLock|TestRejectEther|TestZeroExGovernor|ZeroExGovernor).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/multisig/src/artifacts.ts b/contracts/multisig/src/artifacts.ts index f2a986632b..8a0baca5d1 100644 --- a/contracts/multisig/src/artifacts.ts +++ b/contracts/multisig/src/artifacts.ts @@ -5,17 +5,17 @@ */ import { ContractArtifact } from 'ethereum-types'; -import * as AssetProxyOwner from '../generated-artifacts/AssetProxyOwner.json'; import * as ContractCallReceiver from '../generated-artifacts/ContractCallReceiver.json'; import * as MultiSigWallet from '../generated-artifacts/MultiSigWallet.json'; import * as MultiSigWalletWithTimeLock from '../generated-artifacts/MultiSigWalletWithTimeLock.json'; -import * as TestAssetProxyOwner from '../generated-artifacts/TestAssetProxyOwner.json'; import * as TestRejectEther from '../generated-artifacts/TestRejectEther.json'; +import * as TestZeroExGovernor from '../generated-artifacts/TestZeroExGovernor.json'; +import * as ZeroExGovernor from '../generated-artifacts/ZeroExGovernor.json'; export const artifacts = { - AssetProxyOwner: AssetProxyOwner as ContractArtifact, MultiSigWallet: MultiSigWallet as ContractArtifact, MultiSigWalletWithTimeLock: MultiSigWalletWithTimeLock as ContractArtifact, + ZeroExGovernor: ZeroExGovernor as ContractArtifact, ContractCallReceiver: ContractCallReceiver as ContractArtifact, - TestAssetProxyOwner: TestAssetProxyOwner as ContractArtifact, TestRejectEther: TestRejectEther as ContractArtifact, + TestZeroExGovernor: TestZeroExGovernor as ContractArtifact, }; diff --git a/contracts/multisig/src/wrappers.ts b/contracts/multisig/src/wrappers.ts index 0e54c14150..2bd971f5d3 100644 --- a/contracts/multisig/src/wrappers.ts +++ b/contracts/multisig/src/wrappers.ts @@ -3,9 +3,9 @@ * Warning: This file is auto-generated by contracts-gen. Don't edit manually. * ----------------------------------------------------------------------------- */ -export * from '../generated-wrappers/asset_proxy_owner'; export * from '../generated-wrappers/contract_call_receiver'; export * from '../generated-wrappers/multi_sig_wallet'; export * from '../generated-wrappers/multi_sig_wallet_with_time_lock'; -export * from '../generated-wrappers/test_asset_proxy_owner'; export * from '../generated-wrappers/test_reject_ether'; +export * from '../generated-wrappers/test_zero_ex_governor'; +export * from '../generated-wrappers/zero_ex_governor'; diff --git a/contracts/multisig/test/utils/index.ts b/contracts/multisig/test/utils/index.ts index c6cc6e30d2..7ecfd79e74 100644 --- a/contracts/multisig/test/utils/index.ts +++ b/contracts/multisig/test/utils/index.ts @@ -1,2 +1,2 @@ export * from './multi_sig_wrapper'; -export * from './asset_proxy_owner_wrapper'; +export * from './zero_ex_governor_wrapper'; diff --git a/contracts/multisig/test/utils/asset_proxy_owner_wrapper.ts b/contracts/multisig/test/utils/zero_ex_governor_wrapper.ts similarity index 71% rename from contracts/multisig/test/utils/asset_proxy_owner_wrapper.ts rename to contracts/multisig/test/utils/zero_ex_governor_wrapper.ts index e0bfeb7af2..19a0688fd9 100644 --- a/contracts/multisig/test/utils/asset_proxy_owner_wrapper.ts +++ b/contracts/multisig/test/utils/zero_ex_governor_wrapper.ts @@ -3,13 +3,13 @@ import { AbiEncoder, BigNumber } from '@0x/utils'; import { LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; -import { AssetProxyOwnerContract, AssetProxyOwnerSubmissionEventArgs, TestAssetProxyOwnerContract } from '../../src'; +import { TestZeroExGovernorContract, ZeroExGovernorContract, ZeroExGovernorSubmissionEventArgs } from '../../src'; // tslint:disable: no-unnecessary-type-assertion -export class AssetProxyOwnerWrapper { - private readonly _assetProxyOwner: AssetProxyOwnerContract | TestAssetProxyOwnerContract; - constructor(assetproxyOwnerContract: AssetProxyOwnerContract | TestAssetProxyOwnerContract) { - this._assetProxyOwner = assetproxyOwnerContract; +export class ZeroExGovernorWrapper { + private readonly _governor: ZeroExGovernorContract | TestZeroExGovernorContract; + constructor(assetproxyOwnerContract: ZeroExGovernorContract | TestZeroExGovernorContract) { + this._governor = assetproxyOwnerContract; } public async submitTransactionAsync( data: string[], @@ -20,13 +20,13 @@ export class AssetProxyOwnerWrapper { const values = opts.values === undefined ? data.map(() => constants.ZERO_AMOUNT) : opts.values; const batchTransactionEncoder = AbiEncoder.create('(bytes[],address[],uint256[])'); const batchTransactionData = batchTransactionEncoder.encode([data, destinations, values]); - const txReceipt = await this._assetProxyOwner.submitTransaction.awaitTransactionSuccessAsync( + const txReceipt = await this._governor.submitTransaction.awaitTransactionSuccessAsync( hexRandom(20), // submitTransaction will fail if this is a null address constants.ZERO_AMOUNT, batchTransactionData, { from }, ); - const txId = (txReceipt.logs[0] as LogWithDecodedArgs).args.transactionId; + const txId = (txReceipt.logs[0] as LogWithDecodedArgs).args.transactionId; return { txReceipt, txId }; } public async submitConfirmAndExecuteTransactionAsync( @@ -39,12 +39,12 @@ export class AssetProxyOwnerWrapper { const submitResults = await this.submitTransactionAsync(data, destinations, signerAddresses[0], opts); const requiredSignatures = opts.requiredSignatures === undefined ? 2 : opts.requiredSignatures; for (const index of _.range(1, requiredSignatures)) { - await this._assetProxyOwner.confirmTransaction.awaitTransactionSuccessAsync(submitResults.txId, { + await this._governor.confirmTransaction.awaitTransactionSuccessAsync(submitResults.txId, { from: signerAddresses[index], }); } await increaseTimeAndMineBlockAsync(increaseTimeSeconds); - const executionTxReceipt = await this._assetProxyOwner.executeTransaction.awaitTransactionSuccessAsync( + const executionTxReceipt = await this._governor.executeTransaction.awaitTransactionSuccessAsync( submitResults.txId, { from: opts.executeFromAddress === undefined ? signerAddresses[0] : opts.executeFromAddress }, ); diff --git a/contracts/multisig/test/asset_proxy_owner.ts b/contracts/multisig/test/zero_ex_governor.ts similarity index 80% rename from contracts/multisig/test/asset_proxy_owner.ts rename to contracts/multisig/test/zero_ex_governor.ts index 166e16a554..9615070613 100644 --- a/contracts/multisig/test/asset_proxy_owner.ts +++ b/contracts/multisig/test/zero_ex_governor.ts @@ -6,18 +6,18 @@ import * as _ from 'lodash'; import { artifacts, - AssetProxyOwnerExecutionEventArgs, - AssetProxyOwnerFunctionCallTimeLockRegistrationEventArgs, - AssetProxyOwnerWrapper, ContractCallReceiverContract, ContractCallReceiverEventArgs, - TestAssetProxyOwnerContract, + TestZeroExGovernorContract, + ZeroExGovernorExecutionEventArgs, + ZeroExGovernorFunctionCallTimeLockRegistrationEventArgs, + ZeroExGovernorWrapper, } from '../src'; // tslint:disable: no-unnecessary-type-assertion -blockchainTests.resets('AssetProxyOwner', env => { - let assetProxyOwner: TestAssetProxyOwnerContract; - let assetProxyOwnerWrapper: AssetProxyOwnerWrapper; +blockchainTests.resets('ZeroExGovernor', env => { + let governor: TestZeroExGovernorContract; + let governorWrapper: ZeroExGovernorWrapper; let receiver: ContractCallReceiverContract; let signerAddresses: string[]; let notSignerAddress: string; @@ -31,8 +31,8 @@ blockchainTests.resets('AssetProxyOwner', env => { const accounts = await env.web3Wrapper.getAvailableAddressesAsync(); signerAddresses = accounts.slice(0, TOTAL_SIGNERS); notSignerAddress = accounts[TOTAL_SIGNERS]; - assetProxyOwner = await TestAssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.TestAssetProxyOwner, + governor = await TestZeroExGovernorContract.deployFrom0xArtifactAsync( + artifacts.TestZeroExGovernor, env.provider, env.txDefaults, artifacts, @@ -46,11 +46,11 @@ blockchainTests.resets('AssetProxyOwner', env => { await env.web3Wrapper.awaitTransactionMinedAsync( await env.web3Wrapper.sendTransactionAsync({ from: signerAddresses[0], - to: assetProxyOwner.address, + to: governor.address, value: INITIAL_BALANCE, }), ); - assetProxyOwnerWrapper = new AssetProxyOwnerWrapper(assetProxyOwner); + governorWrapper = new ZeroExGovernorWrapper(governor); receiver = await ContractCallReceiverContract.deployFrom0xArtifactAsync( artifacts.ContractCallReceiver, env.provider, @@ -82,8 +82,8 @@ blockchainTests.resets('AssetProxyOwner', env => { blockchainTests.resets('constructor', () => { it('should fail if destinations.length != functionSelectors.length', async () => { const reg = createFunctionRegistration(1, 2, 1); - const tx = TestAssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.TestAssetProxyOwner, + const tx = TestZeroExGovernorContract.deployFrom0xArtifactAsync( + artifacts.TestZeroExGovernor, env.provider, env.txDefaults, artifacts, @@ -98,8 +98,8 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should fail if functionCallTimeLockSeconds.length != functionSelectors.length', async () => { const reg = createFunctionRegistration(1, 1, 2); - const tx = TestAssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.TestAssetProxyOwner, + const tx = TestZeroExGovernorContract.deployFrom0xArtifactAsync( + artifacts.TestZeroExGovernor, env.provider, env.txDefaults, artifacts, @@ -114,8 +114,8 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should fail if functionCallTimeLockSeconds.length != destinations.length', async () => { const reg = createFunctionRegistration(2, 1, 1); - const tx = TestAssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.TestAssetProxyOwner, + const tx = TestZeroExGovernorContract.deployFrom0xArtifactAsync( + artifacts.TestZeroExGovernor, env.provider, env.txDefaults, artifacts, @@ -129,8 +129,8 @@ blockchainTests.resets('AssetProxyOwner', env => { await expect(tx).to.revertWith(RevertReason.EqualLengthsRequired); }); it('should allow no function calls to be registered', async () => { - const tx = TestAssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.TestAssetProxyOwner, + const tx = TestZeroExGovernorContract.deployFrom0xArtifactAsync( + artifacts.TestZeroExGovernor, env.provider, env.txDefaults, artifacts, @@ -145,8 +145,8 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should register a single functon call', async () => { const reg = createFunctionRegistration(1, 1, 1); - const apOwner = await TestAssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.TestAssetProxyOwner, + const governorContract = await TestZeroExGovernorContract.deployFrom0xArtifactAsync( + artifacts.TestZeroExGovernor, env.provider, env.txDefaults, artifacts, @@ -157,7 +157,7 @@ blockchainTests.resets('AssetProxyOwner', env => { new BigNumber(REQUIRED_SIGNERS), new BigNumber(DEFAULT_TIME_LOCK), ); - const timelock = await apOwner.functionCallTimeLocks.callAsync( + const timelock = await governorContract.functionCallTimeLocks.callAsync( reg.functionSelectors[0], reg.destinations[0], ); @@ -166,8 +166,8 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should register multiple function calls', async () => { const reg = createFunctionRegistration(2, 2, 2); - const apOwner = await TestAssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.TestAssetProxyOwner, + const governorContract = await TestZeroExGovernorContract.deployFrom0xArtifactAsync( + artifacts.TestZeroExGovernor, env.provider, env.txDefaults, artifacts, @@ -179,7 +179,10 @@ blockchainTests.resets('AssetProxyOwner', env => { new BigNumber(DEFAULT_TIME_LOCK), ); for (const [index, selector] of reg.functionSelectors.entries()) { - const timelock = await apOwner.functionCallTimeLocks.callAsync(selector, reg.destinations[index]); + const timelock = await governorContract.functionCallTimeLocks.callAsync( + selector, + reg.destinations[index], + ); expect(timelock[0]).to.equal(true); expect(timelock[1]).to.bignumber.equal(reg.functionCallTimeLockSeconds[index]); } @@ -189,7 +192,7 @@ blockchainTests.resets('AssetProxyOwner', env => { blockchainTests.resets('registerFunctionCall', () => { it('should revert if not called by wallet', async () => { const reg = createFunctionRegistration(1, 1, 1); - const tx = assetProxyOwner.registerFunctionCall.awaitTransactionSuccessAsync( + const tx = governor.registerFunctionCall.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], @@ -200,7 +203,7 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should register a function call', async () => { const reg = createFunctionRegistration(1, 1, 1); - const txReceipt = await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + const txReceipt = await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], @@ -208,13 +211,13 @@ blockchainTests.resets('AssetProxyOwner', env => { ); expect(txReceipt.logs.length).to.eq(1); const logArgs = (txReceipt.logs[0] as LogWithDecodedArgs< - AssetProxyOwnerFunctionCallTimeLockRegistrationEventArgs + ZeroExGovernorFunctionCallTimeLockRegistrationEventArgs >).args; expect(logArgs.functionSelector).to.eq(reg.functionSelectors[0]); expect(logArgs.destination).to.eq(reg.destinations[0]); expect(logArgs.hasCustomTimeLock).to.eq(true); expect(logArgs.newSecondsTimeLocked).to.bignumber.eq(reg.functionCallTimeLockSeconds[0]); - const timelock = await assetProxyOwner.functionCallTimeLocks.callAsync( + const timelock = await governor.functionCallTimeLocks.callAsync( reg.functionSelectors[0], reg.destinations[0], ); @@ -223,20 +226,20 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should be able to overwrite existing function calls', async () => { const reg = createFunctionRegistration(1, 1, 1); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], reg.functionCallTimeLockSeconds[0], ); const newTimeLock = reg.functionCallTimeLockSeconds[0].plus(1000); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], newTimeLock, ); - const timelock = await assetProxyOwner.functionCallTimeLocks.callAsync( + const timelock = await governor.functionCallTimeLocks.callAsync( reg.functionSelectors[0], reg.destinations[0], ); @@ -245,19 +248,19 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should clear the function timelock if hasCustomTimeLock is set to false', async () => { const reg = createFunctionRegistration(1, 1, 1); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], reg.functionCallTimeLockSeconds[0], ); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( false, reg.functionSelectors[0], reg.destinations[0], reg.functionCallTimeLockSeconds[0], ); - const timelock = await assetProxyOwner.functionCallTimeLocks.callAsync( + const timelock = await governor.functionCallTimeLocks.callAsync( reg.functionSelectors[0], reg.destinations[0], ); @@ -268,7 +271,7 @@ blockchainTests.resets('AssetProxyOwner', env => { describe('assertValidFunctionCall', () => { it('should revert if the data is less than 4 bytes long', async () => { - const result = assetProxyOwner.assertValidFunctionCall.callAsync( + const result = governor.assertValidFunctionCall.callAsync( constants.ZERO_AMOUNT, constants.NULL_BYTES, constants.NULL_ADDRESS, @@ -284,7 +287,7 @@ blockchainTests.resets('AssetProxyOwner', env => { const latestTimestamp = await getLatestBlockTimestampAsync(); const transactionConfirmationTime = new BigNumber(latestTimestamp); const reg = createFunctionRegistration(1, 1, 1); - const result = assetProxyOwner.assertValidFunctionCall.callAsync( + const result = governor.assertValidFunctionCall.callAsync( transactionConfirmationTime, reg.functionSelectors[0], reg.destinations[0], @@ -293,7 +296,7 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should revert if a registered function is called before the custom timelock', async () => { const reg = createFunctionRegistration(1, 1, 1); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], @@ -301,7 +304,7 @@ blockchainTests.resets('AssetProxyOwner', env => { ); const latestTimestamp = await getLatestBlockTimestampAsync(); const transactionConfirmationTime = new BigNumber(latestTimestamp); - const result = assetProxyOwner.assertValidFunctionCall.callAsync( + const result = governor.assertValidFunctionCall.callAsync( transactionConfirmationTime, reg.functionSelectors[0], reg.destinations[0], @@ -310,7 +313,7 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should revert if a registered function is called before the custom timelock and after the default timelock', async () => { const reg = createFunctionRegistration(1, 1, 1); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], @@ -318,7 +321,7 @@ blockchainTests.resets('AssetProxyOwner', env => { ); const latestTimestamp = await getLatestBlockTimestampAsync(); const transactionConfirmationTime = new BigNumber(latestTimestamp).minus(DEFAULT_TIME_LOCK); - const result = assetProxyOwner.assertValidFunctionCall.callAsync( + const result = governor.assertValidFunctionCall.callAsync( transactionConfirmationTime, reg.functionSelectors[0], reg.destinations[0], @@ -329,7 +332,7 @@ blockchainTests.resets('AssetProxyOwner', env => { const latestTimestamp = await getLatestBlockTimestampAsync(); const transactionConfirmationTime = new BigNumber(latestTimestamp).minus(DEFAULT_TIME_LOCK); const reg = createFunctionRegistration(1, 1, 1); - const result = assetProxyOwner.assertValidFunctionCall.callAsync( + const result = governor.assertValidFunctionCall.callAsync( transactionConfirmationTime, reg.functionSelectors[0], reg.destinations[0], @@ -338,7 +341,7 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should be successful if a registered function is called after the custom timelock', async () => { const reg = createFunctionRegistration(1, 1, 1); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], @@ -348,7 +351,7 @@ blockchainTests.resets('AssetProxyOwner', env => { const transactionConfirmationTime = new BigNumber(latestTimestamp).minus( reg.functionCallTimeLockSeconds[0], ); - const result = assetProxyOwner.assertValidFunctionCall.callAsync( + const result = governor.assertValidFunctionCall.callAsync( transactionConfirmationTime, reg.functionSelectors[0], reg.destinations[0], @@ -357,14 +360,14 @@ blockchainTests.resets('AssetProxyOwner', env => { }); it('should allow a custom timelock to be set to 0', async () => { const reg = createFunctionRegistration(1, 1, 1); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, reg.functionSelectors[0], reg.destinations[0], constants.ZERO_AMOUNT, ); const latestTimestamp = await getLatestBlockTimestampAsync(); - const result = assetProxyOwner.assertValidFunctionCall.callAsync( + const result = governor.assertValidFunctionCall.callAsync( new BigNumber(latestTimestamp), reg.functionSelectors[0], reg.destinations[0], @@ -390,15 +393,15 @@ blockchainTests.resets('AssetProxyOwner', env => { const value = values === undefined ? constants.ZERO_AMOUNT : values[i]; expect(contractCallLogArgs.value).to.bignumber.eq(value); }); - const executionLog = logs[data.length] as LogWithDecodedArgs; + const executionLog = logs[data.length] as LogWithDecodedArgs; expect(executionLog.event).to.eq('Execution'); expect(executionLog.args.transactionId).to.bignumber.eq(txId); } it('should revert if the transaction is not confirmed by the required amount of signers', async () => { const data = [hexRandom()]; const destinations = [receiver.address]; - const results = await assetProxyOwnerWrapper.submitTransactionAsync(data, destinations, signerAddresses[0]); - const tx = assetProxyOwner.executeTransaction.awaitTransactionSuccessAsync(results.txId, { + const results = await governorWrapper.submitTransactionAsync(data, destinations, signerAddresses[0]); + const tx = governor.executeTransaction.awaitTransactionSuccessAsync(results.txId, { from: signerAddresses[1], }); expect(tx).to.revertWith(RevertReason.TxNotFullyConfirmed); @@ -406,8 +409,8 @@ blockchainTests.resets('AssetProxyOwner', env => { it('should revert if the transaction is not confirmed by the required amount of signers and called by the submitter', async () => { const data = [hexRandom()]; const destinations = [receiver.address]; - const results = await assetProxyOwnerWrapper.submitTransactionAsync(data, destinations, signerAddresses[0]); - const tx = assetProxyOwner.executeTransaction.awaitTransactionSuccessAsync(results.txId, { + const results = await governorWrapper.submitTransactionAsync(data, destinations, signerAddresses[0]); + const tx = governor.executeTransaction.awaitTransactionSuccessAsync(results.txId, { from: signerAddresses[0], }); expect(tx).to.revertWith(RevertReason.TxNotFullyConfirmed); @@ -415,7 +418,7 @@ blockchainTests.resets('AssetProxyOwner', env => { it('should be able to execute an unregistered function after the default timelock with no value', async () => { const data = [hexRandom()]; const destinations = [receiver.address]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -427,7 +430,7 @@ blockchainTests.resets('AssetProxyOwner', env => { const data = [hexRandom()]; const destinations = [receiver.address]; const values = [INITIAL_BALANCE]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -440,13 +443,13 @@ blockchainTests.resets('AssetProxyOwner', env => { const data = [hexRandom()]; const destinations = [receiver.address]; const newTimeLock = new BigNumber(DEFAULT_TIME_LOCK).dividedToIntegerBy(2); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, data[0].slice(0, 10), receiver.address, newTimeLock, ); - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -458,13 +461,13 @@ blockchainTests.resets('AssetProxyOwner', env => { const data = [hexRandom()]; const destinations = [receiver.address]; const newTimeLock = constants.ZERO_AMOUNT; - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, data[0].slice(0, 10), receiver.address, newTimeLock, ); - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -476,14 +479,14 @@ blockchainTests.resets('AssetProxyOwner', env => { const data = [hexRandom()]; const destinations = [receiver.address]; const newTimeLock = new BigNumber(DEFAULT_TIME_LOCK).dividedToIntegerBy(2); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, data[0].slice(0, 10), receiver.address, newTimeLock, ); const values = [INITIAL_BALANCE]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -495,7 +498,7 @@ blockchainTests.resets('AssetProxyOwner', env => { it('should be able to call multiple functions with a single destination and no values', async () => { const data = [hexRandom(), hexRandom()]; const destinations = [receiver.address, receiver.address]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -513,7 +516,7 @@ blockchainTests.resets('AssetProxyOwner', env => { const data = [hexRandom(), hexRandom()]; const destinations = [receiver.address, receiver2.address]; const values = [INITIAL_BALANCE.dividedToIntegerBy(4), INITIAL_BALANCE.dividedToIntegerBy(3)]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -526,13 +529,13 @@ blockchainTests.resets('AssetProxyOwner', env => { const data = [hexRandom(), hexRandom()]; const destinations = [receiver.address, receiver.address]; const newTimeLock = new BigNumber(DEFAULT_TIME_LOCK).dividedToIntegerBy(2); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, data[0].slice(0, 10), receiver.address, newTimeLock, ); - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -544,13 +547,13 @@ blockchainTests.resets('AssetProxyOwner', env => { const data = [hexRandom(), hexRandom()]; const destinations = [receiver.address, receiver.address]; const newTimeLock = new BigNumber(DEFAULT_TIME_LOCK).dividedToIntegerBy(2); - await assetProxyOwner.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( + await governor.registerFunctionCallBypassWallet.awaitTransactionSuccessAsync( true, data[0].slice(0, 10), receiver.address, newTimeLock, ); - const tx = assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const tx = governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -561,7 +564,7 @@ blockchainTests.resets('AssetProxyOwner', env => { it('should be able to execute a transaction if called by any address', async () => { const data = [hexRandom()]; const destinations = [receiver.address]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -574,7 +577,7 @@ blockchainTests.resets('AssetProxyOwner', env => { // NOTE: elements of `data` must be at least 4 bytes long const data = [constants.NULL_BYTES4]; const destinations = [receiver.address]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -585,7 +588,7 @@ blockchainTests.resets('AssetProxyOwner', env => { it('should not call a function if the input array lengths are 0', async () => { const data: string[] = []; const destinations: string[] = []; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -596,7 +599,7 @@ blockchainTests.resets('AssetProxyOwner', env => { it('should revert if destinations.length != data.length', async () => { const data = [hexRandom(), hexRandom()]; const destinations = [receiver.address]; - const tx = assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const tx = governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -608,7 +611,7 @@ blockchainTests.resets('AssetProxyOwner', env => { const data = [hexRandom()]; const destinations = [receiver.address]; const values = [constants.ZERO_AMOUNT, constants.ZERO_AMOUNT]; - const tx = assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const tx = governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -620,20 +623,20 @@ blockchainTests.resets('AssetProxyOwner', env => { it('should revert if the transaction is already executed', async () => { const data = [hexRandom()]; const destinations = [receiver.address]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, DEFAULT_TIME_LOCK, ); - const tx = assetProxyOwner.executeTransaction.awaitTransactionSuccessAsync(results.txId); + const tx = governor.executeTransaction.awaitTransactionSuccessAsync(results.txId); expect(tx).to.revertWith(RevertReason.TxAlreadyExecuted); }); it('should revert if the only call is unsuccessful', async () => { const alwaysRevertSelector = '0xF1F2F3F4'; const data = [alwaysRevertSelector]; const destinations = [receiver.address]; - const tx = assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const tx = governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -645,7 +648,7 @@ blockchainTests.resets('AssetProxyOwner', env => { const alwaysRevertSelector = '0xF1F2F3F4'; const data = [hexRandom(), alwaysRevertSelector]; const destinations = [receiver.address, receiver.address]; - const tx = assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const tx = governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -656,15 +659,15 @@ blockchainTests.resets('AssetProxyOwner', env => { it('should be able to call registerFunctionCall after the default timelock', async () => { const reg = createFunctionRegistration(1, 1, 1); const data = [ - assetProxyOwner.registerFunctionCall.getABIEncodedTransactionData( + governor.registerFunctionCall.getABIEncodedTransactionData( true, reg.functionSelectors[0], reg.destinations[0], reg.functionCallTimeLockSeconds[0], ), ]; - const destinations = [assetProxyOwner.address]; - const results = await assetProxyOwnerWrapper.submitConfirmAndExecuteTransactionAsync( + const destinations = [governor.address]; + const results = await governorWrapper.submitConfirmAndExecuteTransactionAsync( data, destinations, signerAddresses, @@ -672,7 +675,7 @@ blockchainTests.resets('AssetProxyOwner', env => { ); expect(results.executionTxReceipt.logs.length).to.eq(2); const registrationLogArgs = (results.executionTxReceipt.logs[0] as LogWithDecodedArgs< - AssetProxyOwnerFunctionCallTimeLockRegistrationEventArgs + ZeroExGovernorFunctionCallTimeLockRegistrationEventArgs >).args; expect(registrationLogArgs.destination).to.eq(reg.destinations[0]); expect(registrationLogArgs.functionSelector).to.eq(reg.functionSelectors[0]); diff --git a/contracts/multisig/tsconfig.json b/contracts/multisig/tsconfig.json index cbcd1aaf31..643ad217e9 100644 --- a/contracts/multisig/tsconfig.json +++ b/contracts/multisig/tsconfig.json @@ -3,12 +3,12 @@ "compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true }, "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], "files": [ - "generated-artifacts/AssetProxyOwner.json", "generated-artifacts/ContractCallReceiver.json", "generated-artifacts/MultiSigWallet.json", "generated-artifacts/MultiSigWalletWithTimeLock.json", - "generated-artifacts/TestAssetProxyOwner.json", - "generated-artifacts/TestRejectEther.json" + "generated-artifacts/TestRejectEther.json", + "generated-artifacts/TestZeroExGovernor.json", + "generated-artifacts/ZeroExGovernor.json" ], "exclude": ["./deploy/solc/solc_bin"] } diff --git a/contracts/staking/contracts/src/Staking.sol b/contracts/staking/contracts/src/Staking.sol index 082db5f1c4..0cae856329 100644 --- a/contracts/staking/contracts/src/Staking.sol +++ b/contracts/staking/contracts/src/Staking.sol @@ -31,13 +31,6 @@ contract Staking is MixinStake, MixinExchangeFees { - // this contract can receive ETH - // solhint-disable no-empty-blocks - function () - external - payable - {} - /// @dev Initialize storage owned by this contract. /// This function should not be called directly. /// The StakingProxy contract will call it in `attachStakingContract()`. diff --git a/contracts/staking/contracts/src/fees/MixinExchangeFees.sol b/contracts/staking/contracts/src/fees/MixinExchangeFees.sol index 239145da75..576fbe22db 100644 --- a/contracts/staking/contracts/src/fees/MixinExchangeFees.sol +++ b/contracts/staking/contracts/src/fees/MixinExchangeFees.sol @@ -81,49 +81,46 @@ contract MixinExchangeFees is return; } - // Look up the pool for this epoch. - uint256 currentEpoch_ = currentEpoch; - mapping (bytes32 => IStructs.ActivePool) storage activePoolsThisEpoch = - _getActivePoolsFromEpoch(currentEpoch_); + // Look up the pool stats and aggregated stats for this epoch. - IStructs.ActivePool memory pool = activePoolsThisEpoch[poolId]; + uint256 currentEpoch_ = currentEpoch; + IStructs.PoolStats storage poolStatsPtr = poolStatsByEpoch[poolId][currentEpoch_]; + IStructs.AggregatedStats storage aggregatedStatsPtr = aggregatedStatsByEpoch[currentEpoch_]; - // If the pool was previously inactive in this epoch, initialize it. - if (pool.feesCollected == 0) { + // Perform some initialization if this is the pool's first protocol fee in this epoch. + uint256 feesCollectedByPool = poolStatsPtr.feesCollected; + if (feesCollectedByPool == 0) { // Compute member and total weighted stake. - (pool.membersStake, pool.weightedStake) = _computeMembersAndWeightedStake(poolId, poolStake); + (uint256 membersStakeInPool, uint256 weightedStakeInPool) = _computeMembersAndWeightedStake(poolId, poolStake); + poolStatsPtr.membersStake = membersStakeInPool; + poolStatsPtr.weightedStake = weightedStakeInPool; // Increase the total weighted stake. - totalWeightedStakeThisEpoch = totalWeightedStakeThisEpoch.safeAdd(pool.weightedStake); + aggregatedStatsPtr.totalWeightedStake = aggregatedStatsPtr.totalWeightedStake.safeAdd(weightedStakeInPool); - // Increase the number of active pools. - numActivePoolsThisEpoch += 1; + // Increase the number of pools to finalize. + aggregatedStatsPtr.numPoolsToFinalize = aggregatedStatsPtr.numPoolsToFinalize.safeAdd(1); - // Emit an event so keepers know what pools to pass into - // `finalize()`. - emit StakingPoolActivated(currentEpoch_, poolId); + // Emit an event so keepers know what pools earned rewards this epoch. + emit StakingPoolEarnedRewardsInEpoch(currentEpoch_, poolId); } // Credit the fees to the pool. - pool.feesCollected = pool.feesCollected.safeAdd(protocolFeePaid); + poolStatsPtr.feesCollected = feesCollectedByPool.safeAdd(protocolFeePaid); // Increase the total fees collected this epoch. - totalFeesCollectedThisEpoch = totalFeesCollectedThisEpoch.safeAdd(protocolFeePaid); - - // Store the pool. - activePoolsThisEpoch[poolId] = pool; + aggregatedStatsPtr.totalFeesCollected = aggregatedStatsPtr.totalFeesCollected.safeAdd(protocolFeePaid); } - /// @dev Get information on an active staking pool in this epoch. + /// @dev Get stats on a staking pool in this epoch. /// @param poolId Pool Id to query. - /// @return pool ActivePool struct. - function getActiveStakingPoolThisEpoch(bytes32 poolId) + /// @return PoolStats struct for pool id. + function getStakingPoolStatsThisEpoch(bytes32 poolId) external view - returns (IStructs.ActivePool memory pool) + returns (IStructs.PoolStats memory) { - pool = _getActivePoolFromEpoch(currentEpoch, poolId); - return pool; + return poolStatsByEpoch[poolId][currentEpoch]; } /// @dev Computes the members and weighted stake for a pool at the current diff --git a/contracts/staking/contracts/src/immutable/MixinDeploymentConstants.sol b/contracts/staking/contracts/src/immutable/MixinDeploymentConstants.sol index 6aa23444b3..70735152c7 100644 --- a/contracts/staking/contracts/src/immutable/MixinDeploymentConstants.sol +++ b/contracts/staking/contracts/src/immutable/MixinDeploymentConstants.sol @@ -28,16 +28,24 @@ contract MixinDeploymentConstants { // @TODO SET THESE VALUES FOR DEPLOYMENT // Mainnet WETH9 Address - address constant private WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); + // address constant private WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); // Kovan WETH9 Address - // address constant private WETH_ADDRESS = address(0xd0a1e359811322d97991e03f863a0c30c2cf029c); + // address constant private WETH_ADDRESS = address(0xd0A1E359811322d97991E03f863a0C30C2cF029C); // Ropsten & Rinkeby WETH9 Address - // address constant private WETH_ADDRESS = address(0xc778417e063141139fce010982780140aa0cd5ab); + address constant private WETH_ADDRESS = address(0xc778417E063141139Fce010982780140Aa0cD5Ab); // @TODO SET THESE VALUES FOR DEPLOYMENT - address constant private ZRX_VAULT_ADDRESS = address(1); + + // Kovan ZrxVault address + // address constant private ZRX_VAULT_ADDRESS = address(0xf36eabdFE986B35b62c8FD5a98A7f2aEBB79B291); + + // Ropsten ZrxVault address + address constant private ZRX_VAULT_ADDRESS = address(0xffD161026865Ad8B4aB28a76840474935eEc4DfA); + + // Rinkeby ZrxVault address + // address constant private ZRX_VAULT_ADDRESS = address(0xA5Bf6aC73bC40790FC6Ffc9DBbbCE76c9176e224); /// @dev An overridable way to access the deployed WETH contract. /// Must be view to allow overrides to access state. diff --git a/contracts/staking/contracts/src/immutable/MixinStorage.sol b/contracts/staking/contracts/src/immutable/MixinStorage.sol index a8ee6ac7f9..341c694020 100644 --- a/contracts/staking/contracts/src/immutable/MixinStorage.sol +++ b/contracts/staking/contracts/src/immutable/MixinStorage.sol @@ -101,25 +101,15 @@ contract MixinStorage is // Denominator for cobb douglas alpha factor. uint32 public cobbDouglasAlphaDenominator; - /* Finalization states */ + /* State for finalization */ - /// @dev The total fees collected in the current epoch, built up iteratively - /// in `payProtocolFee()`. - uint256 public totalFeesCollectedThisEpoch; + /// @dev Stats for each pool that generated fees with sufficient stake to earn rewards. + /// See `_minimumPoolStake` in MixinParams. + mapping (bytes32 => mapping (uint256 => IStructs.PoolStats)) public poolStatsByEpoch; - /// @dev The total weighted stake in the current epoch, built up iteratively - /// in `payProtocolFee()`. - uint256 public totalWeightedStakeThisEpoch; - - /// @dev State information for each active pool in an epoch. - /// In practice, we only store state for `currentEpoch % 2`. - mapping (uint256 => mapping (bytes32 => IStructs.ActivePool)) internal _activePoolsByEpoch; - - /// @dev Number of pools activated in the current epoch. - uint256 public numActivePoolsThisEpoch; - - /// @dev State for unfinalized rewards. - IStructs.UnfinalizedState public unfinalizedState; + /// @dev Aggregated stats across all pools that generated fees with sufficient stake to earn rewards. + /// See `_minimumPoolStake` in MixinParams. + mapping (uint256 => IStructs.AggregatedStats) public aggregatedStatsByEpoch; /// @dev The WETH balance of this contract that is reserved for pool reward payouts. uint256 public wethReservedForPoolRewards; diff --git a/contracts/staking/contracts/src/interfaces/IStakingEvents.sol b/contracts/staking/contracts/src/interfaces/IStakingEvents.sol index 353f5dda4d..c8f07ed663 100644 --- a/contracts/staking/contracts/src/interfaces/IStakingEvents.sol +++ b/contracts/staking/contracts/src/interfaces/IStakingEvents.sol @@ -43,24 +43,23 @@ interface IStakingEvents { address exchangeAddress ); - /// @dev Emitted by MixinExchangeFees when a pool pays protocol fees - /// for the first time in an epoch. - /// @param epoch The epoch in which the pool was activated. + /// @dev Emitted by MixinExchangeFees when a pool starts earning rewards in an epoch. + /// @param epoch The epoch in which the pool earned rewards. /// @param poolId The ID of the pool. - event StakingPoolActivated( + event StakingPoolEarnedRewardsInEpoch( uint256 indexed epoch, bytes32 indexed poolId ); /// @dev Emitted by MixinFinalizer when an epoch has ended. - /// @param epoch The closing epoch. - /// @param numActivePools Number of active pools in the closing epoch. - /// @param rewardsAvailable Rewards available to all active pools. - /// @param totalWeightedStake Total weighted stake across all active pools. - /// @param totalFeesCollected Total fees collected across all active pools. + /// @param epoch The epoch that ended. + /// @param numPoolsToFinalize Number of pools that earned rewards during `epoch` and must be finalized. + /// @param rewardsAvailable Rewards available to all pools that earned rewards during `epoch`. + /// @param totalWeightedStake Total weighted stake across all pools that earned rewards during `epoch`. + /// @param totalFeesCollected Total fees collected across all pools that earned rewards during `epoch`. event EpochEnded( uint256 indexed epoch, - uint256 numActivePools, + uint256 numPoolsToFinalize, uint256 rewardsAvailable, uint256 totalFeesCollected, uint256 totalWeightedStake diff --git a/contracts/staking/contracts/src/interfaces/IStorage.sol b/contracts/staking/contracts/src/interfaces/IStorage.sol index a1d9d6ecee..797f5d111e 100644 --- a/contracts/staking/contracts/src/interfaces/IStorage.sol +++ b/contracts/staking/contracts/src/interfaces/IStorage.sol @@ -65,11 +65,6 @@ interface IStorage { view returns (uint256); - function activePoolsThisEpoch() - external - view - returns (bytes32[] memory); - function validExchanges(address exchangeAddress) external view diff --git a/contracts/staking/contracts/src/interfaces/IStructs.sol b/contracts/staking/contracts/src/interfaces/IStructs.sol index 3b889f2f7b..d4d3ff533f 100644 --- a/contracts/staking/contracts/src/interfaces/IStructs.sol +++ b/contracts/staking/contracts/src/interfaces/IStructs.sol @@ -29,29 +29,27 @@ interface IStructs { uint96 lastSetTimestamp; } - /// @dev Status for a pool that actively traded during the current epoch. - /// (see MixinExchangeFees). + /// @dev Stats for a pool that earned rewards. /// @param feesCollected Fees collected in ETH by this pool. /// @param weightedStake Amount of weighted stake in the pool. /// @param membersStake Amount of non-operator stake in the pool. - struct ActivePool { + struct PoolStats { uint256 feesCollected; uint256 weightedStake; uint256 membersStake; } - /// @dev Holds state for unfinalized epoch rewards. + /// @dev Holds stats aggregated across a set of pools. /// @param rewardsAvailable Rewards (ETH) available to the epoch /// being finalized (the previous epoch). This is simply the balance /// of the contract at the end of the epoch. - /// @param poolsRemaining The number of active pools in the last - /// epoch that have yet to be finalized through `finalizePools()`. + /// @param numPoolsToFinalize The number of pools that have yet to be finalized through `finalizePools()`. /// @param totalFeesCollected The total fees collected for the epoch being finalized. /// @param totalWeightedStake The total fees collected for the epoch being finalized. /// @param totalRewardsFinalized Amount of rewards that have been paid during finalization. - struct UnfinalizedState { + struct AggregatedStats { uint256 rewardsAvailable; - uint256 poolsRemaining; + uint256 numPoolsToFinalize; uint256 totalFeesCollected; uint256 totalWeightedStake; uint256 totalRewardsFinalized; diff --git a/contracts/staking/contracts/src/libs/LibCobbDouglas.sol b/contracts/staking/contracts/src/libs/LibCobbDouglas.sol index 347758bde2..b956cab0b0 100644 --- a/contracts/staking/contracts/src/libs/LibCobbDouglas.sol +++ b/contracts/staking/contracts/src/libs/LibCobbDouglas.sol @@ -33,11 +33,9 @@ library LibCobbDouglas { /// 0 <= alphaNumerator / alphaDenominator <= 1 /// @param totalRewards collected over an epoch. /// @param fees Fees attributed to the the staking pool. - /// @param totalFees Total fees collected across all active staking pools in - /// the epoch. + /// @param totalFees Total fees collected across all pools that earned rewards. /// @param stake Stake attributed to the staking pool. - /// @param totalStake Total stake across all active staking pools in the - /// epoch. + /// @param totalStake Total stake across all pools that earned rewards. /// @param alphaNumerator Numerator of `alpha` in the cobb-douglas function. /// @param alphaDenominator Denominator of `alpha` in the cobb-douglas /// function. diff --git a/contracts/staking/contracts/src/libs/LibStakingRichErrors.sol b/contracts/staking/contracts/src/libs/LibStakingRichErrors.sol index ad8ceec25a..30117d9ce8 100644 --- a/contracts/staking/contracts/src/libs/LibStakingRichErrors.sol +++ b/contracts/staking/contracts/src/libs/LibStakingRichErrors.sol @@ -112,6 +112,10 @@ library LibStakingRichErrors { bytes4 internal constant PREVIOUS_EPOCH_NOT_FINALIZED_ERROR_SELECTOR = 0x614b800a; + // bytes4(keccak256("PoolNotFinalizedError(bytes32,uint256)")) + bytes4 internal constant POOL_NOT_FINALIZED_ERROR_SELECTOR = + 0x5caa0b05; + // solhint-disable func-name-mixedcase function OnlyCallableByExchangeError( address senderAddress @@ -308,4 +312,19 @@ library LibStakingRichErrors { unfinalizedPoolsRemaining ); } + + function PoolNotFinalizedError( + bytes32 poolId, + uint256 epoch + ) + internal + pure + returns (bytes memory) + { + return abi.encodeWithSelector( + POOL_NOT_FINALIZED_ERROR_SELECTOR, + poolId, + epoch + ); + } } diff --git a/contracts/staking/contracts/src/stake/MixinStakeBalances.sol b/contracts/staking/contracts/src/stake/MixinStakeBalances.sol index bc089d9651..70a6fe515f 100644 --- a/contracts/staking/contracts/src/stake/MixinStakeBalances.sol +++ b/contracts/staking/contracts/src/stake/MixinStakeBalances.sol @@ -72,7 +72,7 @@ contract MixinStakeBalances is /// @dev Returns the total stake for a given staker. /// @param staker of stake. - /// @return Total active stake for staker. + /// @return Total ZRX staked by `staker`. function getTotalStake(address staker) public view diff --git a/contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol b/contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol index 3b78364784..478113b9fb 100644 --- a/contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol +++ b/contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol @@ -31,25 +31,13 @@ contract MixinStakingPoolRewards is { using LibSafeMath for uint256; - /// @dev Syncs rewards for a delegator. This includes transferring WETH - /// rewards to the delegator, and adding/removing - /// dependencies on cumulative rewards. - /// This is used by a delegator when they want to sync their rewards - /// without delegating/undelegating. It's effectively the same as - /// delegating zero stake. + /// @dev Withdraws the caller's WETH rewards that have accumulated + /// until the last epoch. /// @param poolId Unique id of pool. function withdrawDelegatorRewards(bytes32 poolId) external { - address member = msg.sender; - - _withdrawAndSyncDelegatorRewards( - poolId, - member - ); - - _delegatedStakeToPoolByOwner[member][poolId] = - _loadCurrentBalance(_delegatedStakeToPoolByOwner[member][poolId]); + _withdrawAndSyncDelegatorRewards(poolId, msg.sender); } /// @dev Computes the reward balance in ETH of the operator of a pool. @@ -105,8 +93,8 @@ contract MixinStakingPoolRewards is ); } - /// @dev Syncs rewards for a delegator. This includes transferring rewards - /// withdrawing rewards and adding/removing dependencies on cumulative rewards. + /// @dev Syncs rewards for a delegator. This includes withdrawing rewards + /// rewards and adding/removing dependencies on cumulative rewards. /// @param poolId Unique id of pool. /// @param member of the pool. function _withdrawAndSyncDelegatorRewards( @@ -116,7 +104,7 @@ contract MixinStakingPoolRewards is internal { // Ensure the pool is finalized. - finalizePool(poolId); + _assertPoolFinalizedLastEpoch(poolId); // Compute balance owed to delegator uint256 balance = _computeDelegatorReward( @@ -128,6 +116,12 @@ contract MixinStakingPoolRewards is 0 ); + // Sync the delegated stake balance. This will ensure future calls of + // `_computeDelegatorReward` during this epoch will return 0, + // preventing a delegator from withdrawing more than once an epoch. + _delegatedStakeToPoolByOwner[member][poolId] = + _loadCurrentBalance(_delegatedStakeToPoolByOwner[member][poolId]); + // Withdraw non-0 balance if (balance != 0) { // Decrease the balance of the pool @@ -211,7 +205,7 @@ contract MixinStakingPoolRewards is PPM_DENOMINATOR, totalReward ); - membersReward = totalReward - operatorReward; + membersReward = totalReward.safeSub(operatorReward); } return (operatorReward, membersReward); } @@ -232,19 +226,13 @@ contract MixinStakingPoolRewards is view returns (uint256 reward) { - // There can be no rewards in epoch 0 because there is no delegated - // stake. - uint256 _currentEpoch = currentEpoch; - if (_currentEpoch == 0) { - return 0; - } - + uint256 currentEpoch_ = currentEpoch; IStructs.StoredBalance memory delegatedStake = _delegatedStakeToPoolByOwner[member][poolId]; // There can be no rewards if the last epoch when stake was stored is // equal to the current epoch, because all prior rewards, including // rewards finalized this epoch have been claimed. - if (delegatedStake.currentEpoch == _currentEpoch) { + if (delegatedStake.currentEpoch == currentEpoch_) { return 0; } @@ -253,7 +241,7 @@ contract MixinStakingPoolRewards is // 1/3 Unfinalized rewards earned in `currentEpoch - 1`. reward = _computeUnfinalizedDelegatorReward( delegatedStake, - _currentEpoch, + currentEpoch_, unfinalizedMembersReward, unfinalizedMembersStake ); @@ -275,7 +263,7 @@ contract MixinStakingPoolRewards is poolId, delegatedStake.nextEpochBalance, delegatedStakeNextEpoch, - _currentEpoch + currentEpoch_ ) ); diff --git a/contracts/staking/contracts/src/sys/MixinAbstract.sol b/contracts/staking/contracts/src/sys/MixinAbstract.sol index 2ca468b689..9d2ad630eb 100644 --- a/contracts/staking/contracts/src/sys/MixinAbstract.sol +++ b/contracts/staking/contracts/src/sys/MixinAbstract.sol @@ -24,19 +24,6 @@ pragma experimental ABIEncoderV2; /// cyclical dependencies. contract MixinAbstract { - /// @dev Instantly finalizes a single pool that was active in the previous - /// epoch, crediting it rewards for members and withdrawing operator's - /// rewards as WETH. This can be called by internal functions that need - /// to finalize a pool immediately. Does nothing if the pool is already - /// finalized or was not active in the previous epoch. - /// @param poolId The pool ID to finalize. - /// @return operatorReward The reward credited to the pool operator. - /// @return membersReward The reward credited to the pool members. - /// @return membersStake The total stake for all non-operator members in - /// this pool. - function finalizePool(bytes32 poolId) - public; - /// @dev Computes the reward owed to a pool during finalization. /// Does nothing if the pool is already finalized. /// @param poolId The pool's ID. @@ -50,4 +37,10 @@ contract MixinAbstract { uint256 totalReward, uint256 membersStake ); + + /// @dev Asserts that a pool has been finalized last epoch. + /// @param poolId The id of the pool that should have been finalized. + function _assertPoolFinalizedLastEpoch(bytes32 poolId) + internal + view; } diff --git a/contracts/staking/contracts/src/sys/MixinFinalizer.sol b/contracts/staking/contracts/src/sys/MixinFinalizer.sol index 72c9907d9c..8626b0d151 100644 --- a/contracts/staking/contracts/src/sys/MixinFinalizer.sol +++ b/contracts/staking/contracts/src/sys/MixinFinalizer.sol @@ -35,98 +35,83 @@ contract MixinFinalizer is /// @dev Begins a new epoch, preparing the prior one for finalization. /// Throws if not enough time has passed between epochs or if the /// previous epoch was not fully finalized. - /// If there were no active pools in the closing epoch, the epoch - /// will be instantly finalized here. Otherwise, `finalizePool()` - /// should be called on each active pool afterwards. - /// @return poolsRemaining The number of unfinalized pools. + /// @return numPoolsToFinalize The number of unfinalized pools. function endEpoch() external - returns (uint256 poolsRemaining) + returns (uint256) { - uint256 closingEpoch = currentEpoch; - IStructs.UnfinalizedState memory state = unfinalizedState; + uint256 currentEpoch_ = currentEpoch; + uint256 prevEpoch = currentEpoch_.safeSub(1); // Make sure the previous epoch has been fully finalized. - if (state.poolsRemaining != 0) { + uint256 numPoolsToFinalizeFromPrevEpoch = aggregatedStatsByEpoch[prevEpoch].numPoolsToFinalize; + if (numPoolsToFinalizeFromPrevEpoch != 0) { LibRichErrors.rrevert( LibStakingRichErrors.PreviousEpochNotFinalizedError( - closingEpoch - 1, - state.poolsRemaining + prevEpoch, + numPoolsToFinalizeFromPrevEpoch ) ); } - // Convert all ETH to WETH + // Convert all ETH to WETH; the WETH balance of this contract is the total rewards. _wrapEth(); - // Set up unfinalized state. - state.rewardsAvailable = _getAvailableWethBalance(); - state.poolsRemaining = poolsRemaining = numActivePoolsThisEpoch; - state.totalFeesCollected = totalFeesCollectedThisEpoch; - state.totalWeightedStake = totalWeightedStakeThisEpoch; - state.totalRewardsFinalized = 0; - unfinalizedState = state; + // Load aggregated stats for the epoch we're ending. + aggregatedStatsByEpoch[currentEpoch_].rewardsAvailable = _getAvailableWethBalance(); + IStructs.AggregatedStats memory aggregatedStats = aggregatedStatsByEpoch[currentEpoch_]; // Emit an event. emit EpochEnded( - closingEpoch, - state.poolsRemaining, - state.rewardsAvailable, - state.totalFeesCollected, - state.totalWeightedStake + currentEpoch_, + aggregatedStats.numPoolsToFinalize, + aggregatedStats.rewardsAvailable, + aggregatedStats.totalFeesCollected, + aggregatedStats.totalWeightedStake ); - // Reset current epoch state. - totalFeesCollectedThisEpoch = 0; - totalWeightedStakeThisEpoch = 0; - numActivePoolsThisEpoch = 0; - // Advance the epoch. This will revert if not enough time has passed. _goToNextEpoch(); - // If there were no active pools, the epoch is already finalized. - if (poolsRemaining == 0) { - emit EpochFinalized(closingEpoch, 0, state.rewardsAvailable); + // If there are no pools to finalize then the epoch is finalized. + if (aggregatedStats.numPoolsToFinalize == 0) { + emit EpochFinalized(currentEpoch_, 0, aggregatedStats.rewardsAvailable); } + + return aggregatedStats.numPoolsToFinalize; } - /// @dev Instantly finalizes a single pool that was active in the previous + /// @dev Instantly finalizes a single pool that earned rewards in the previous /// epoch, crediting it rewards for members and withdrawing operator's /// rewards as WETH. This can be called by internal functions that need /// to finalize a pool immediately. Does nothing if the pool is already - /// finalized or was not active in the previous epoch. + /// finalized or did not earn rewards in the previous epoch. /// @param poolId The pool ID to finalize. function finalizePool(bytes32 poolId) - public + external { - // Noop on epoch 0 + // Compute relevant epochs uint256 currentEpoch_ = currentEpoch; - if (currentEpoch_ == 0) { - return; - } - - // Load the finalization and pool state into memory. - IStructs.UnfinalizedState memory state = unfinalizedState; + uint256 prevEpoch = currentEpoch_.safeSub(1); - // Noop if all active pools have been finalized. - if (state.poolsRemaining == 0) { + // Load the aggregated stats into memory; noop if no pools to finalize. + IStructs.AggregatedStats memory aggregatedStats = aggregatedStatsByEpoch[prevEpoch]; + if (aggregatedStats.numPoolsToFinalize == 0) { return; } - uint256 prevEpoch = currentEpoch_.safeSub(1); - IStructs.ActivePool memory pool = _getActivePoolFromEpoch(prevEpoch, poolId); - - // Noop if the pool was not active or already finalized (has no fees). - if (pool.feesCollected == 0) { + // Noop if the pool did not earn rewards or already finalized (has no fees). + IStructs.PoolStats memory poolStats = poolStatsByEpoch[poolId][prevEpoch]; + if (poolStats.feesCollected == 0) { return; } - // Clear the pool state so we don't finalize it again, and to recoup + // Clear the pool stats so we don't finalize it again, and to recoup // some gas. - delete _getActivePoolsFromEpoch(prevEpoch)[poolId]; + delete poolStatsByEpoch[poolId][prevEpoch]; // Compute the rewards. - uint256 rewards = _getUnfinalizedPoolRewardsFromState(pool, state); + uint256 rewards = _getUnfinalizedPoolRewardsFromPoolStats(poolStats, aggregatedStats); // Pay the operator and update rewards for the pool. // Note that we credit at the CURRENT epoch even though these rewards @@ -134,7 +119,7 @@ contract MixinFinalizer is (uint256 operatorReward, uint256 membersReward) = _syncPoolRewards( poolId, rewards, - pool.membersStake + poolStats.membersStake ); // Emit an event. @@ -148,22 +133,22 @@ contract MixinFinalizer is uint256 totalReward = operatorReward.safeAdd(membersReward); // Increase `totalRewardsFinalized`. - unfinalizedState.totalRewardsFinalized = - state.totalRewardsFinalized = - state.totalRewardsFinalized.safeAdd(totalReward); + aggregatedStatsByEpoch[prevEpoch].totalRewardsFinalized = + aggregatedStats.totalRewardsFinalized = + aggregatedStats.totalRewardsFinalized.safeAdd(totalReward); // Decrease the number of unfinalized pools left. - unfinalizedState.poolsRemaining = - state.poolsRemaining = - state.poolsRemaining.safeSub(1); + aggregatedStatsByEpoch[prevEpoch].numPoolsToFinalize = + aggregatedStats.numPoolsToFinalize = + aggregatedStats.numPoolsToFinalize.safeSub(1); // If there are no more unfinalized pools remaining, the epoch is // finalized. - if (state.poolsRemaining == 0) { + if (aggregatedStats.numPoolsToFinalize == 0) { emit EpochFinalized( prevEpoch, - state.totalRewardsFinalized, - state.rewardsAvailable.safeSub(state.totalRewardsFinalized) + aggregatedStats.totalRewardsFinalized, + aggregatedStats.rewardsAvailable.safeSub(aggregatedStats.totalRewardsFinalized) ); } } @@ -182,46 +167,10 @@ contract MixinFinalizer is uint256 membersStake ) { - uint256 epoch = currentEpoch; - // There are no pools to finalize at epoch 0. - if (epoch == 0) { - return (0, 0); - } - IStructs.ActivePool memory pool = _getActivePoolFromEpoch(epoch - 1, poolId); - reward = _getUnfinalizedPoolRewardsFromState(pool, unfinalizedState); - membersStake = pool.membersStake; - } - - /// @dev Get an active pool from an epoch by its ID. - /// @param epoch The epoch the pool was/will be active in. - /// @param poolId The ID of the pool. - /// @return pool The pool with ID `poolId` that was active in `epoch`. - function _getActivePoolFromEpoch( - uint256 epoch, - bytes32 poolId - ) - internal - view - returns (IStructs.ActivePool memory pool) - { - pool = _getActivePoolsFromEpoch(epoch)[poolId]; - return pool; - } - - /// @dev Get a mapping of active pools from an epoch. - /// This uses the formula `epoch % 2` as the epoch index in order - /// to reuse state, because we only need to remember, at most, two - /// epochs at once. - /// @return activePools The pools that were active in `epoch`. - function _getActivePoolsFromEpoch( - uint256 epoch - ) - internal - view - returns (mapping (bytes32 => IStructs.ActivePool) storage activePools) - { - activePools = _activePoolsByEpoch[epoch % 2]; - return activePools; + uint256 prevEpoch = currentEpoch.safeSub(1); + IStructs.PoolStats memory poolStats = poolStatsByEpoch[poolId][prevEpoch]; + reward = _getUnfinalizedPoolRewardsFromPoolStats(poolStats, aggregatedStatsByEpoch[prevEpoch]); + membersStake = poolStats.membersStake; } /// @dev Converts the entire ETH balance of this contract into WETH. @@ -247,31 +196,50 @@ contract MixinFinalizer is return wethBalance; } + /// @dev Asserts that a pool has been finalized last epoch. + /// @param poolId The id of the pool that should have been finalized. + function _assertPoolFinalizedLastEpoch(bytes32 poolId) + internal + view + { + uint256 prevEpoch = currentEpoch.safeSub(1); + IStructs.PoolStats memory poolStats = poolStatsByEpoch[poolId][prevEpoch]; + + // A pool that has any fees remaining has not been finalized + if (poolStats.feesCollected != 0) { + LibRichErrors.rrevert( + LibStakingRichErrors.PoolNotFinalizedError( + poolId, + prevEpoch + ) + ); + } + } + /// @dev Computes the reward owed to a pool during finalization. - /// @param pool The active pool. - /// @param state The current state of finalization. - /// @return rewards Unfinalized rewards for this pool. - function _getUnfinalizedPoolRewardsFromState( - IStructs.ActivePool memory pool, - IStructs.UnfinalizedState memory state + /// @param poolStats Stats for a specific pool. + /// @param aggregatedStats Stats aggregated across all pools. + /// @return rewards Unfinalized rewards for the input pool. + function _getUnfinalizedPoolRewardsFromPoolStats( + IStructs.PoolStats memory poolStats, + IStructs.AggregatedStats memory aggregatedStats ) private view returns (uint256 rewards) { - // There can't be any rewards if the pool was active or if it has - // no stake. - if (pool.feesCollected == 0) { + // There can't be any rewards if the pool did not collect any fees. + if (poolStats.feesCollected == 0) { return rewards; } // Use the cobb-douglas function to compute the total reward. rewards = LibCobbDouglas.cobbDouglas( - state.rewardsAvailable, - pool.feesCollected, - state.totalFeesCollected, - pool.weightedStake, - state.totalWeightedStake, + aggregatedStats.rewardsAvailable, + poolStats.feesCollected, + aggregatedStats.totalFeesCollected, + poolStats.weightedStake, + aggregatedStats.totalWeightedStake, cobbDouglasAlphaNumerator, cobbDouglasAlphaDenominator ); @@ -279,7 +247,7 @@ contract MixinFinalizer is // Clip the reward to always be under // `rewardsAvailable - totalRewardsPaid`, // in case cobb-douglas overflows, which should be unlikely. - uint256 rewardsRemaining = state.rewardsAvailable.safeSub(state.totalRewardsFinalized); + uint256 rewardsRemaining = aggregatedStats.rewardsAvailable.safeSub(aggregatedStats.totalRewardsFinalized); if (rewardsRemaining < rewards) { rewards = rewardsRemaining; } diff --git a/contracts/staking/contracts/src/sys/MixinScheduler.sol b/contracts/staking/contracts/src/sys/MixinScheduler.sol index 90f76c22f9..0c52978c03 100644 --- a/contracts/staking/contracts/src/sys/MixinScheduler.sol +++ b/contracts/staking/contracts/src/sys/MixinScheduler.sol @@ -53,6 +53,7 @@ contract MixinScheduler is // solhint-disable-next-line currentEpochStartTimeInSeconds = block.timestamp; + currentEpoch = 1; } /// @dev Moves to the next epoch, given the current epoch period has ended. diff --git a/contracts/staking/contracts/test/TestDelegatorRewards.sol b/contracts/staking/contracts/test/TestDelegatorRewards.sol index f88cd9c0a6..814b054808 100644 --- a/contracts/staking/contracts/test/TestDelegatorRewards.sol +++ b/contracts/staking/contracts/test/TestDelegatorRewards.sol @@ -48,11 +48,6 @@ contract TestDelegatorRewards is mapping (uint256 => mapping (bytes32 => UnfinalizedPoolReward)) private unfinalizedPoolRewardsByEpoch; - /// @dev Expose the original finalizePool - function originalFinalizePool(bytes32 poolId) external { - MixinFinalizer.finalizePool(poolId); - } - /// @dev Set unfinalized rewards for a pool in the current epoch. function setUnfinalizedPoolReward( bytes32 poolId, @@ -99,7 +94,7 @@ contract TestDelegatorRewards is currentEpoch += 1; } - /// @dev Create and delegate stake that is active in the current epoch. + /// @dev Create and delegate stake to the current epoch. /// Only used to test purportedly unreachable states. /// Also withdraws pending rewards. function delegateStakeNow( @@ -171,7 +166,7 @@ contract TestDelegatorRewards is /// @dev Overridden to realize `unfinalizedPoolRewardsByEpoch` in /// the current epoch and emit a event, function finalizePool(bytes32 poolId) - public + external { UnfinalizedPoolReward memory reward = unfinalizedPoolRewardsByEpoch[currentEpoch][poolId]; delete unfinalizedPoolRewardsByEpoch[currentEpoch][poolId]; diff --git a/contracts/staking/contracts/test/TestFinalizer.sol b/contracts/staking/contracts/test/TestFinalizer.sol index 1284360cb1..23dbfc342b 100644 --- a/contracts/staking/contracts/test/TestFinalizer.sol +++ b/contracts/staking/contracts/test/TestFinalizer.sol @@ -63,6 +63,13 @@ contract TestFinalizer is _removeAuthorizedAddressAtIndex(msg.sender, 0); } + // this contract can receive ETH + // solhint-disable no-empty-blocks + function () + external + payable + {} + /// @dev Activate a pool in the current epoch. function addActivePool( bytes32 poolId, @@ -74,20 +81,19 @@ contract TestFinalizer is external { require(feesCollected > 0, "FEES_MUST_BE_NONZERO"); - mapping (bytes32 => IStructs.ActivePool) storage activePools = _getActivePoolsFromEpoch( - currentEpoch - ); - IStructs.ActivePool memory pool = activePools[poolId]; - require(pool.feesCollected == 0, "POOL_ALREADY_ADDED"); + uint256 currentEpoch_ = currentEpoch; + IStructs.PoolStats memory poolStats = poolStatsByEpoch[poolId][currentEpoch_]; + require(poolStats.feesCollected == 0, "POOL_ALREADY_ADDED"); _operatorSharesByPool[poolId] = operatorShare; - activePools[poolId] = IStructs.ActivePool({ + poolStatsByEpoch[poolId][currentEpoch_] = IStructs.PoolStats({ feesCollected: feesCollected, membersStake: membersStake, weightedStake: weightedStake }); - totalFeesCollectedThisEpoch += feesCollected; - totalWeightedStakeThisEpoch += weightedStake; - numActivePoolsThisEpoch += 1; + + aggregatedStatsByEpoch[currentEpoch_].totalFeesCollected += feesCollected; + aggregatedStatsByEpoch[currentEpoch_].totalWeightedStake += weightedStake; + aggregatedStatsByEpoch[currentEpoch_].numPoolsToFinalize += 1; } /// @dev Drain the balance of this contract. @@ -131,13 +137,21 @@ contract TestFinalizer is ); } - /// @dev Expose `_getActivePoolFromEpoch`. - function getActivePoolFromEpoch(uint256 epoch, bytes32 poolId) + /// @dev Expose pool stats for the input epoch. + function getPoolStatsFromEpoch(uint256 epoch, bytes32 poolId) + external + view + returns (IStructs.PoolStats memory) + { + return poolStatsByEpoch[poolId][epoch]; + } + + function getAggregatedStatsForPreviousEpoch() external view - returns (IStructs.ActivePool memory pool) + returns (IStructs.AggregatedStats memory) { - pool = _getActivePoolFromEpoch(epoch, poolId); + return aggregatedStatsByEpoch[currentEpoch - 1]; } /// @dev Overridden to log and transfer to receivers. diff --git a/contracts/staking/contracts/test/TestMixinStake.sol b/contracts/staking/contracts/test/TestMixinStake.sol new file mode 100644 index 0000000000..382f17f8e9 --- /dev/null +++ b/contracts/staking/contracts/test/TestMixinStake.sol @@ -0,0 +1,241 @@ +/* + + Copyright 2019 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.5.9; +pragma experimental ABIEncoderV2; + +import "../src/interfaces/IStructs.sol"; +import "./TestStakingNoWETH.sol"; + + +contract TestMixinStake is + TestStakingNoWETH +{ + event ZrxVaultDepositFrom( + address staker, + uint256 amount + ); + + event ZrxVaultWithdrawFrom( + address staker, + uint256 amount + ); + + event MoveStakeStorage( + bytes32 fromBalanceSlot, + bytes32 toBalanceSlot, + uint256 amount + ); + + event IncreaseCurrentAndNextBalance( + bytes32 balanceSlot, + uint256 amount + ); + + event DecreaseCurrentAndNextBalance( + bytes32 balanceSlot, + uint256 amount + ); + + event IncreaseNextBalance( + bytes32 balanceSlot, + uint256 amount + ); + + event DecreaseNextBalance( + bytes32 balanceSlot, + uint256 amount + ); + + event WithdrawAndSyncDelegatorRewards( + bytes32 poolId, + address delegator + ); + + /// @dev Advance the epoch counter. + function advanceEpoch() external { + currentEpoch += 1; + } + + /// @dev `IZrxVault.depositFrom` + function depositFrom(address staker, uint256 amount) external { + emit ZrxVaultDepositFrom(staker, amount); + } + + /// @dev `IZrxVault.withdrawFrom` + function withdrawFrom(address staker, uint256 amount) external { + emit ZrxVaultWithdrawFrom(staker, amount); + } + + function getDelegatedStakeByPoolIdSlot(bytes32 poolId) + external + view + returns (bytes32 slot) + { + return _getPtrSlot(_delegatedStakeByPoolId[poolId]); + } + + function getDelegatedStakeToPoolByOwnerSlot(bytes32 poolId, address staker) + external + view + returns (bytes32 slot) + { + return _getPtrSlot(_delegatedStakeToPoolByOwner[staker][poolId]); + } + + function getGlobalStakeByStatusSlot(IStructs.StakeStatus status) + external + view + returns (bytes32 slot) + { + return _getPtrSlot(_globalStakeByStatus[uint8(status)]); + } + + function getOwnerStakeByStatusSlot(address owner, IStructs.StakeStatus status) + external + view + returns (bytes32 slot) + { + return _getPtrSlot(_ownerStakeByStatus[uint8(status)][owner]); + } + + /// @dev Set `_ownerStakeByStatus` + function setOwnerStakeByStatus( + address owner, + IStructs.StakeStatus status, + IStructs.StoredBalance memory stake + ) + public + { + _ownerStakeByStatus[uint8(status)][owner] = stake; + } + + /// @dev Overridden to use this contract as the ZRX vault. + function getZrxVault() + public + view + returns (IZrxVault zrxVault) + { + return IZrxVault(address(this)); + } + + /// @dev Overridden to only emit an event. + function _withdrawAndSyncDelegatorRewards( + bytes32 poolId, + address member + ) + internal + { + emit WithdrawAndSyncDelegatorRewards(poolId, member); + } + + /// @dev Overridden to only emit an event. + function _moveStake( + IStructs.StoredBalance storage fromPtr, + IStructs.StoredBalance storage toPtr, + uint256 amount + ) + internal + { + emit MoveStakeStorage( + _getPtrSlot(fromPtr), + _getPtrSlot(toPtr), + amount + ); + } + + /// @dev Overridden to only emit an event. + function _increaseCurrentAndNextBalance( + IStructs.StoredBalance storage balancePtr, + uint256 amount + ) + internal + { + emit IncreaseCurrentAndNextBalance( + _getPtrSlot(balancePtr), + amount + ); + } + + /// @dev Overridden to only emit an event. + function _decreaseCurrentAndNextBalance( + IStructs.StoredBalance storage balancePtr, + uint256 amount + ) + internal + { + emit DecreaseCurrentAndNextBalance( + _getPtrSlot(balancePtr), + amount + ); + } + + /// @dev Overridden to only emit an event. + function _increaseNextBalance( + IStructs.StoredBalance storage balancePtr, + uint256 amount + ) + internal + { + emit IncreaseNextBalance( + _getPtrSlot(balancePtr), + amount + ); + } + + /// @dev Overridden to only emit an event. + function _decreaseNextBalance( + IStructs.StoredBalance storage balancePtr, + uint256 amount + ) + internal + { + emit DecreaseNextBalance( + _getPtrSlot(balancePtr), + amount + ); + } + + /// @dev Overridden to just return the input. + function _loadCurrentBalance(IStructs.StoredBalance storage balancePtr) + internal + view + returns (IStructs.StoredBalance memory balance) + { + balance = balancePtr; + } + + /// @dev Throws if poolId == 0x0 + function _assertStakingPoolExists(bytes32 poolId) + internal + view + { + require(poolId != bytes32(0), "INVALID_POOL"); + } + + // solhint-disable-next-line + function _getPtrSlot(IStructs.StoredBalance storage ptr) + private + pure + returns (bytes32 offset) + { + assembly { + offset := ptr_slot + } + } +} diff --git a/contracts/staking/contracts/test/TestProtocolFees.sol b/contracts/staking/contracts/test/TestProtocolFees.sol index a6091e19a8..b9b93944e6 100644 --- a/contracts/staking/contracts/test/TestProtocolFees.sol +++ b/contracts/staking/contracts/test/TestProtocolFees.sol @@ -86,6 +86,14 @@ contract TestProtocolFees is return true; } + function getAggregatedStatsForCurrentEpoch() + external + view + returns (IStructs.AggregatedStats memory) + { + return aggregatedStatsByEpoch[currentEpoch]; + } + /// @dev Overridden to use test pools. function getStakingPoolIdOfMaker(address makerAddress) public diff --git a/contracts/staking/contracts/test/TestStorageLayoutAndConstants.sol b/contracts/staking/contracts/test/TestStorageLayoutAndConstants.sol index 7c9a5f1f85..05cd4f9721 100644 --- a/contracts/staking/contracts/test/TestStorageLayoutAndConstants.sol +++ b/contracts/staking/contracts/test/TestStorageLayoutAndConstants.sol @@ -275,45 +275,21 @@ contract TestStorageLayoutAndConstants is offset := 0x0 assertSlotAndOffset( - totalFeesCollectedThisEpoch_slot, - totalFeesCollectedThisEpoch_offset, + poolStatsByEpoch_slot, + poolStatsByEpoch_offset, slot, offset ) slot := add(slot, 0x1) assertSlotAndOffset( - totalWeightedStakeThisEpoch_slot, - totalWeightedStakeThisEpoch_offset, + aggregatedStatsByEpoch_slot, + aggregatedStatsByEpoch_offset, slot, offset ) slot := add(slot, 0x1) - assertSlotAndOffset( - _activePoolsByEpoch_slot, - _activePoolsByEpoch_offset, - slot, - offset - ) - slot := add(slot, 0x1) - - assertSlotAndOffset( - numActivePoolsThisEpoch_slot, - numActivePoolsThisEpoch_offset, - slot, - offset - ) - slot := add(slot, 0x1) - - assertSlotAndOffset( - unfinalizedState_slot, - unfinalizedState_offset, - slot, - offset - ) - slot := add(slot, 0x5) - assertSlotAndOffset( wethReservedForPoolRewards_slot, wethReservedForPoolRewards_offset, diff --git a/contracts/staking/package.json b/contracts/staking/package.json index 884892949b..0052b78911 100644 --- a/contracts/staking/package.json +++ b/contracts/staking/package.json @@ -23,7 +23,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", @@ -37,7 +37,7 @@ }, "config": { "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", - "abis": "./generated-artifacts/@(IStaking|IStakingEvents|IStakingProxy|IStorage|IStorageInit|IStructs|IZrxVault|LibCobbDouglas|LibFixedMath|LibFixedMathRichErrors|LibProxy|LibSafeDowncast|LibStakingRichErrors|MixinAbstract|MixinConstants|MixinCumulativeRewards|MixinDeploymentConstants|MixinExchangeFees|MixinExchangeManager|MixinFinalizer|MixinParams|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakeStorage|MixinStakingPool|MixinStakingPoolRewards|MixinStorage|ReadOnlyProxy|Staking|StakingProxy|TestAssertStorageParams|TestCobbDouglas|TestCumulativeRewardTracking|TestDelegatorRewards|TestExchangeManager|TestFinalizer|TestInitTarget|TestLibFixedMath|TestLibProxy|TestLibProxyReceiver|TestLibSafeDowncast|TestMixinStakeStorage|TestProtocolFees|TestStaking|TestStakingNoWETH|TestStakingProxy|TestStorageLayoutAndConstants|ZrxVault|ZrxVaultBackstop).json" + "abis": "./generated-artifacts/@(IStaking|IStakingEvents|IStakingProxy|IStorage|IStorageInit|IStructs|IZrxVault|LibCobbDouglas|LibFixedMath|LibFixedMathRichErrors|LibProxy|LibSafeDowncast|LibStakingRichErrors|MixinAbstract|MixinConstants|MixinCumulativeRewards|MixinDeploymentConstants|MixinExchangeFees|MixinExchangeManager|MixinFinalizer|MixinParams|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakeStorage|MixinStakingPool|MixinStakingPoolRewards|MixinStorage|ReadOnlyProxy|Staking|StakingProxy|TestAssertStorageParams|TestCobbDouglas|TestCumulativeRewardTracking|TestDelegatorRewards|TestExchangeManager|TestFinalizer|TestInitTarget|TestLibFixedMath|TestLibProxy|TestLibProxyReceiver|TestLibSafeDowncast|TestMixinStake|TestMixinStakeStorage|TestProtocolFees|TestStaking|TestStakingNoWETH|TestStakingProxy|TestStorageLayoutAndConstants|ZrxVault|ZrxVaultBackstop).json" }, "repository": { "type": "git", diff --git a/contracts/staking/src/artifacts.ts b/contracts/staking/src/artifacts.ts index 5cd2b8ff12..9e31c1564e 100644 --- a/contracts/staking/src/artifacts.ts +++ b/contracts/staking/src/artifacts.ts @@ -47,6 +47,7 @@ import * as TestLibFixedMath from '../generated-artifacts/TestLibFixedMath.json' import * as TestLibProxy from '../generated-artifacts/TestLibProxy.json'; import * as TestLibProxyReceiver from '../generated-artifacts/TestLibProxyReceiver.json'; import * as TestLibSafeDowncast from '../generated-artifacts/TestLibSafeDowncast.json'; +import * as TestMixinStake from '../generated-artifacts/TestMixinStake.json'; import * as TestMixinStakeStorage from '../generated-artifacts/TestMixinStakeStorage.json'; import * as TestProtocolFees from '../generated-artifacts/TestProtocolFees.json'; import * as TestStaking from '../generated-artifacts/TestStaking.json'; @@ -100,6 +101,7 @@ export const artifacts = { TestLibProxy: TestLibProxy as ContractArtifact, TestLibProxyReceiver: TestLibProxyReceiver as ContractArtifact, TestLibSafeDowncast: TestLibSafeDowncast as ContractArtifact, + TestMixinStake: TestMixinStake as ContractArtifact, TestMixinStakeStorage: TestMixinStakeStorage as ContractArtifact, TestProtocolFees: TestProtocolFees as ContractArtifact, TestStaking: TestStaking as ContractArtifact, diff --git a/contracts/staking/src/wrappers.ts b/contracts/staking/src/wrappers.ts index 149d989f78..0ce6576d60 100644 --- a/contracts/staking/src/wrappers.ts +++ b/contracts/staking/src/wrappers.ts @@ -45,6 +45,7 @@ export * from '../generated-wrappers/test_lib_fixed_math'; export * from '../generated-wrappers/test_lib_proxy'; export * from '../generated-wrappers/test_lib_proxy_receiver'; export * from '../generated-wrappers/test_lib_safe_downcast'; +export * from '../generated-wrappers/test_mixin_stake'; export * from '../generated-wrappers/test_mixin_stake_storage'; export * from '../generated-wrappers/test_protocol_fees'; export * from '../generated-wrappers/test_staking'; diff --git a/contracts/staking/test/actors/finalizer_actor.ts b/contracts/staking/test/actors/finalizer_actor.ts index 36dcd237f5..2d2e099b3c 100644 --- a/contracts/staking/test/actors/finalizer_actor.ts +++ b/contracts/staking/test/actors/finalizer_actor.ts @@ -238,7 +238,7 @@ export class FinalizerActor extends BaseActor { private async _getRewardByPoolIdAsync(poolIds: string[]): Promise { const activePools = await Promise.all( poolIds.map(async poolId => - this._stakingApiWrapper.stakingContract.getActiveStakingPoolThisEpoch.callAsync(poolId), + this._stakingApiWrapper.stakingContract.getStakingPoolStatsThisEpoch.callAsync(poolId), ), ); const totalRewards = await this._stakingApiWrapper.utils.getAvailableRewardsBalanceAsync(); diff --git a/contracts/staking/test/cumulative_reward_tracking_test.ts b/contracts/staking/test/cumulative_reward_tracking_test.ts index 7693903d08..3930dee05b 100644 --- a/contracts/staking/test/cumulative_reward_tracking_test.ts +++ b/contracts/staking/test/cumulative_reward_tracking_test.ts @@ -32,396 +32,396 @@ blockchainTests.resets('Cumulative Reward Tracking', env => { }); describe('Tracking Cumulative Rewards (CR)', () => { - it('pool created at epoch 0', async () => { + it('pool created at epoch 1', async () => { await simulation.runTestAsync([], [TestAction.CreatePool], []); }); - it('pool created in epoch >0', async () => { + it('pool created in epoch >1', async () => { await simulation.runTestAsync([TestAction.Finalize], [TestAction.CreatePool], []); }); it('delegating in the same epoch pool is created', async () => { await simulation.runTestAsync( [ - // Creates CR for epoch 0 + // Creates CR for epoch 1 TestAction.CreatePool, ], [ - // Updates CR for epoch 0 - // Creates CR for epoch 1 + // Updates CR for epoch 1 + // Creates CR for epoch 2 TestAction.Delegate, ], - [], + [{ event: 'SetCumulativeReward', epoch: 1 }], ); }); it('re-delegating in the same epoch', async () => { await simulation.runTestAsync( [ - // Creates CR for epoch 0 + // Creates CR for epoch 1 TestAction.CreatePool, ], [ - // Updates CR for epoch 0 + // Updates CR for epoch 1 TestAction.Delegate, - // Updates CR for epoch 0 + // Updates CR for epoch 1 TestAction.Delegate, ], - [], + [{ event: 'SetCumulativeReward', epoch: 1 }], ); }); it('delegating in new epoch', async () => { - // since there was no delegation in epoch 0 there is no longer a dependency on the CR for epoch 0 + // since there was no delegation in epoch 1 there is no longer a dependency on the CR for epoch 1 await simulation.runTestAsync( [ - // Creates CR for epoch 0 + // Creates CR for epoch 1 TestAction.CreatePool, - // Moves to epoch 1 + // Moves to epoch 2 TestAction.Finalize, ], [ - // Creates a CR for epoch 1 - // Sets MRCR to epoch 1 - // Unsets the CR for epoch 0 + // Creates a CR for epoch 2 + // Sets MRCR to epoch 2 + // Unsets the CR for epoch 1 TestAction.Delegate, ], - [{ event: 'SetCumulativeReward', epoch: 1 }], + [{ event: 'SetCumulativeReward', epoch: 2 }], ); }); it('re-delegating in a new epoch', async () => { await simulation.runTestAsync( [ - // Creates CR in epoch 0 + // Creates CR in epoch 1 TestAction.CreatePool, - // Updates CR for epoch 0 - // Creates CR for epoch 1 + // Updates CR for epoch 1 + // Creates CR for epoch 2 TestAction.Delegate, - // Moves to epoch 1 + // Moves to epoch 2 TestAction.Finalize, ], [ - // Updates CR for epoch 1 - // Sets MRCR to epoch 1 + // Updates CR for epoch 2 + // Sets MRCR to epoch 2 TestAction.Delegate, ], - [{ event: 'SetCumulativeReward', epoch: 1 }], + [{ event: 'SetCumulativeReward', epoch: 2 }], ); }); - it('delegating in epoch 1 then again in epoch 2', async () => { + it('delegating in epoch 2 then again in epoch 3', async () => { await simulation.runTestAsync( [ - // Creates CR for epoch 0 + // Creates CR for epoch 1 TestAction.CreatePool, - // Moves to epoch 1 + // Moves to epoch 2 TestAction.Finalize, - // Creates CR for epoch 1 - // Sets MRCR to epoch 1 + // Creates CR for epoch 2 + // Sets MRCR to epoch 2 TestAction.Delegate, - // Move to epoch 2 + // Move to epoch 3 TestAction.Finalize, ], [ - // Updates CR for epoch 2 - // Sets MRCR to epoch 2 - // Creates CR for epoch 3 - // Clears CR for epoch 1 + // Updates CR for epoch 3 + // Sets MRCR to epoch 3 + // Creates CR for epoch 4 + // Clears CR for epoch 2 TestAction.Delegate, ], - [{ event: 'SetCumulativeReward', epoch: 2 }], + [{ event: 'SetCumulativeReward', epoch: 3 }], ); }); - it('delegate in epoch 1 then undelegate in epoch 2', async () => { + it('delegate in epoch 2 then undelegate in epoch 3', async () => { await simulation.runTestAsync( [ - // Creates CR for epoch 0 + // Creates CR for epoch 1 TestAction.CreatePool, - // Moves to epoch 1 + // Moves to epoch 2 TestAction.Finalize, - // Creates CR for epoch 1 - // Sets MRCR to epoch 0 - // Clears CR for epoch 0 // Creates CR for epoch 2 + // Sets MRCR to epoch 1 + // Clears CR for epoch 1 + // Creates CR for epoch 3 TestAction.Delegate, - // Moves to epoch 2 + // Moves to epoch 3 TestAction.Finalize, ], [ - // Update CR for epoch 2 - // Set MRCR to epoch 2 - // Clear CR for epoch 1 + // Update CR for epoch 3 + // Set MRCR to epoch 3 + // Clear CR for epoch 2 TestAction.Undelegate, ], - [{ event: 'SetCumulativeReward', epoch: 2 }], + [{ event: 'SetCumulativeReward', epoch: 3 }], ); }); - it('delegate in epoch 0 and epoch 1, then undelegate half in epoch 2', async () => { + it('delegate in epoch 1 and epoch 2, then undelegate half in epoch 3', async () => { await simulation.runTestAsync( [ - // Create CR for epoch 0 + // Create CR for epoch 1 TestAction.CreatePool, - // Updates CR for epoch 0 - // Sets MRCR to epoch 0 - // Creates CR for epoch 1 - TestAction.Delegate, - // Moves to epoch 1 - TestAction.Finalize, // Updates CR for epoch 1 // Sets MRCR to epoch 1 // Creates CR for epoch 2 - // Clears CR for epoch 0 TestAction.Delegate, // Moves to epoch 2 TestAction.Finalize, - ], - [ // Updates CR for epoch 2 // Sets MRCR to epoch 2 - // Creates CR for epoch 3 (because there will still be stake) + // Creates CR for epoch 3 // Clears CR for epoch 1 + TestAction.Delegate, + // Moves to epoch 3 + TestAction.Finalize, + ], + [ + // Updates CR for epoch 3 + // Sets MRCR to epoch 3 + // Creates CR for epoch 4 (because there will still be stake) + // Clears CR for epoch 2 TestAction.Undelegate, ], - [{ event: 'SetCumulativeReward', epoch: 2 }], + [{ event: 'SetCumulativeReward', epoch: 3 }], ); }); - it('delegate in epoch 1 and 2 then again in 3', async () => { + it('delegate in epoch 2 and 3 then again in 3', async () => { await simulation.runTestAsync( [ - // Creates CR for epoch 0 - TestAction.CreatePool, - // Updates CR for epoch 0 - // Sets MRCR to epoch 0 // Creates CR for epoch 1 - TestAction.Delegate, - // Moves to epoch 1 - TestAction.Finalize, + TestAction.CreatePool, // Updates CR for epoch 1 // Sets MRCR to epoch 1 // Creates CR for epoch 2 - // Clears CR for epoch 0 TestAction.Delegate, // Moves to epoch 2 TestAction.Finalize, - ], - [ // Updates CR for epoch 2 // Sets MRCR to epoch 2 // Creates CR for epoch 3 // Clears CR for epoch 1 TestAction.Delegate, + // Moves to epoch 3 + TestAction.Finalize, ], - [{ event: 'SetCumulativeReward', epoch: 2 }], + [ + // Updates CR for epoch 3 + // Sets MRCR to epoch 3 + // Creates CR for epoch 4 + // Clears CR for epoch 2 + TestAction.Delegate, + ], + [{ event: 'SetCumulativeReward', epoch: 3 }], ); }); - it('delegate in epoch 0, earn reward in epoch 1', async () => { + it('delegate in epoch 1, earn reward in epoch 2', async () => { await simulation.runTestAsync( [ - // Create CR for epoch 0 + // Create CR for epoch 1 TestAction.CreatePool, - // Updates CR for epoch 0 - // Sets MRCR to epoch 0 - // Creates CR for epoch 1 + // Updates CR for epoch 1 + // Sets MRCR to epoch 1 + // Creates CR for epoch 2 TestAction.Delegate, - // Moves to epoch 1 + // Moves to epoch 2 TestAction.Finalize, // Credits pool with rewards TestAction.PayProtocolFee, ], [ - // Moves to epoch 2 - // Creates CR for epoch 2 - // Sets MRCR to epoch 2 + // Moves to epoch 3 + // Creates CR for epoch 3 + // Sets MRCR to epoch 3 TestAction.Finalize, ], - [{ event: 'SetCumulativeReward', epoch: 2 }], + [{ event: 'SetCumulativeReward', epoch: 3 }], ); }); - it('delegate in epoch 0, epoch 2, earn reward in epoch 3, then delegate', async () => { + it('delegate in epoch 1, epoch 3, earn reward in epoch 4, then delegate', async () => { await simulation.runTestAsync( [ - // Create CR for epoch 0 + // Create CR for epoch 1 TestAction.CreatePool, - // Updates CR for epoch 0 - // Sets MRCR to epoch 0 - // Creates CR for epoch 1 - TestAction.Delegate, - // Moves to epoch 1 - TestAction.Finalize, // Updates CR for epoch 1 // Sets MRCR to epoch 1 // Creates CR for epoch 2 - // Clears CR for epoch 0 TestAction.Delegate, // Moves to epoch 2 TestAction.Finalize, + // Updates CR for epoch 2 + // Sets MRCR to epoch 2 + // Creates CR for epoch 3 + // Clears CR for epoch 1 + TestAction.Delegate, + // Moves to epoch 3 + TestAction.Finalize, // Credits pool with rewards TestAction.PayProtocolFee, - // Moves to epoch 3 - // Creates CR for epoch 3 - // Sets MRCR to epoch 3 + // Moves to epoch 4 + // Creates CR for epoch 4 + // Sets MRCR to epoch 4 TestAction.Finalize, ], [ - // Updates CR for epoch 3 - // Creates CR for epoch 4 - // Clears CR for epoch 1 + // Updates CR for epoch 4 + // Creates CR for epoch 5 // Clears CR for epoch 2 + // Clears CR for epoch 3 TestAction.Delegate, ], [], ); }); - it('delegate in epoch 0 and 1, earn reward in epoch 3, then undelegate half', async () => { + it('delegate in epoch 1 and 2, earn reward in epoch 4, then undelegate half', async () => { await simulation.runTestAsync( [ - // Create CR for epoch 0 + // Create CR for epoch 1 TestAction.CreatePool, - // Updates CR for epoch 0 - // Sets MRCR to epoch 0 - // Creates CR for epoch 1 - TestAction.Delegate, - // Moves to epoch 1 - TestAction.Finalize, // Updates CR for epoch 1 // Sets MRCR to epoch 1 // Creates CR for epoch 2 - // Clears CR for epoch 0 TestAction.Delegate, // Moves to epoch 2 TestAction.Finalize, + // Updates CR for epoch 2 + // Sets MRCR to epoch 2 + // Creates CR for epoch 3 + // Clears CR for epoch 1 + TestAction.Delegate, + // Moves to epoch 3 + TestAction.Finalize, // Credits pool with rewards TestAction.PayProtocolFee, - // Moves to epoch 3 - // Creates CR for epoch 3 - // Sets MRCR to epoch 3 + // Moves to epoch 4 + // Creates CR for epoch 4 + // Sets MRCR to epoch 4 TestAction.Finalize, ], [ - // Updates CR for epoch 3 - // Creates CR for epoch 4 (because there is still stake remaming) - // Clears CR for epoch 1 + // Updates CR for epoch 4 + // Creates CR for epoch 5 (because there is still stake remaming) // Clears CR for epoch 2 + // Clears CR for epoch 3 TestAction.Undelegate, ], [], ); }); - it('delegate in epoch 1, 2, earn rewards in epoch 3, skip to epoch 4, then delegate', async () => { + it('delegate in epoch 2, 3, earn rewards in epoch 4, skip to epoch 5, then delegate', async () => { await simulation.runTestAsync( [ - // Create CR for epoch 0 + // Create CR for epoch 1 TestAction.CreatePool, - // Updates CR for epoch 0 - // Sets MRCR to epoch 0 - // Creates CR for epoch 1 - TestAction.Delegate, - // Moves to epoch 1 - TestAction.Finalize, // Updates CR for epoch 1 // Sets MRCR to epoch 1 // Creates CR for epoch 2 - // Clears CR for epoch 0 TestAction.Delegate, // Moves to epoch 2 TestAction.Finalize, - // Credits pool with rewards - TestAction.PayProtocolFee, - // Moves to epoch 3 + // Updates CR for epoch 2 + // Sets MRCR to epoch 2 // Creates CR for epoch 3 - // Sets MRCR to epoch 3 + // Clears CR for epoch 1 + TestAction.Delegate, + // Moves to epoch 3 TestAction.Finalize, + // Credits pool with rewards + TestAction.PayProtocolFee, // Moves to epoch 4 + // Creates CR for epoch 4 + // Sets MRCR to epoch 4 + TestAction.Finalize, + // Moves to epoch 5 TestAction.Finalize, ], [ - // Creates CR for epoch 4 - // Sets MRCR to epoch 4 - // Clears CR for epoch 3 // Creates CR for epoch 5 - // Clears CR for epoch 1 + // Sets MRCR to epoch 5 + // Clears CR for epoch 4 + // Creates CR for epoch 6 + // Clears CR for epoch 2 TestAction.Delegate, ], - [{ event: 'SetCumulativeReward', epoch: 4 }], + [{ event: 'SetCumulativeReward', epoch: 5 }], ); }); - it('earn reward in epoch 1 with no stake, then delegate', async () => { + it('earn reward in epoch 2 with no stake, then delegate', async () => { await simulation.runTestAsync( [ - // Creates CR for epoch 0 + // Creates CR for epoch 1 TestAction.CreatePool, // Credit pool with rewards TestAction.PayProtocolFee, - // Moves to epoch 1 + // Moves to epoch 2 // That's it, because there's no active pools. TestAction.Finalize, ], [ - // Updates CR to epoch 1 - // Sets MRCR to epoch 1 - // Clears CR for epoch 0 - // Creates CR for epoch 2 + // Updates CR to epoch 2 + // Sets MRCR to epoch 2 + // Clears CR for epoch 1 + // Creates CR for epoch 3 TestAction.Delegate, ], - [{ event: 'SetCumulativeReward', epoch: 1 }], + [{ event: 'SetCumulativeReward', epoch: 2 }], ); }); - it('delegate in epoch 1, 3, then delegate in epoch 4', async () => { + it('delegate in epoch 2, 4, then delegate in epoch 5', async () => { await simulation.runTestAsync( [ - // Creates CR for epoch 0 + // Creates CR for epoch 1 TestAction.CreatePool, - // Moves to epoch 1 + // Moves to epoch 2 TestAction.Finalize, - // Creates CR for epoch 1 - // Sets MRCR to epoch 0 - // Clears CR for epoch 0 // Creates CR for epoch 2 + // Sets MRCR to epoch 1 + // Clears CR for epoch 1 + // Creates CR for epoch 3 TestAction.Delegate, - // Moves to epoch 2 - TestAction.Finalize, // Moves to epoch 3 TestAction.Finalize, - // Creates CR for epoch 3 - // Sets MRCR to epoch 3 - // Clears CR for epoch 1 + // Moves to epoch 4 + TestAction.Finalize, // Creates CR for epoch 4 + // Sets MRCR to epoch 4 // Clears CR for epoch 2 + // Creates CR for epoch 5 + // Clears CR for epoch 3 TestAction.Delegate, - // Moves to epoch 4 + // Moves to epoch 5 TestAction.Finalize, ], [ - // Updates CR for epoch 4 - // Sets MRCR to epoch 4 - // Clears CR for epoch 3 - // Creates CR for epoch 5 + // Updates CR for epoch 5 + // Sets MRCR to epoch 5 + // Clears CR for epoch 4 + // Creates CR for epoch 6 TestAction.Delegate, ], - [{ event: 'SetCumulativeReward', epoch: 4 }], + [{ event: 'SetCumulativeReward', epoch: 5 }], ); }); - it('delegate in epoch 1, then epoch 3', async () => { + it('delegate in epoch 2, then epoch 4', async () => { await simulation.runTestAsync( [ - // Creates CR for epoch 0 + // Creates CR for epoch 1 TestAction.CreatePool, - // Moves to epoch 1 + // Moves to epoch 2 TestAction.Finalize, - // Creates CR for epoch 1 - // Sets MRCR to epoch 0 - // Clears CR for epoch 0 // Creates CR for epoch 2 + // Sets MRCR to epoch 1 + // Clears CR for epoch 1 + // Creates CR for epoch 3 TestAction.Delegate, - // Moves to epoch 2 - TestAction.Finalize, // Moves to epoch 3 TestAction.Finalize, + // Moves to epoch 4 + TestAction.Finalize, ], [ - // Creates CR for epoch 3 - // Sets MRCR to epoch 3 - // Clears CR for epoch 1 // Creates CR for epoch 4 + // Sets MRCR to epoch 4 // Clears CR for epoch 2 + // Creates CR for epoch 5 + // Clears CR for epoch 3 TestAction.Delegate, ], - [{ event: 'SetCumulativeReward', epoch: 3 }], + [{ event: 'SetCumulativeReward', epoch: 4 }], ); }); }); diff --git a/contracts/staking/test/rewards_test.ts b/contracts/staking/test/rewards_test.ts index 1fdc68ff90..0f0c4f5172 100644 --- a/contracts/staking/test/rewards_test.ts +++ b/contracts/staking/test/rewards_test.ts @@ -1,5 +1,6 @@ import { ERC20Wrapper } from '@0x/contracts-asset-proxy'; import { blockchainTests, constants, describe, expect, shortZip } from '@0x/contracts-test-utils'; +import { StakingRevertErrors } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; @@ -242,7 +243,7 @@ blockchainTests.resets('Testing Rewards', env => { }); }); it('Should split pool reward between delegators, when they join in different epochs', async () => { - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) const stakeAmounts = [toBaseUnitAmount(4), toBaseUnitAmount(6)]; const totalStakeAmount = toBaseUnitAmount(10); @@ -256,7 +257,7 @@ blockchainTests.resets('Testing Rewards', env => { // skip epoch, so staker can start earning rewards await payProtocolFeeAndFinalize(); - // second staker delegates (epoch 1) + // second staker delegates (epoch 2) await stakers[1].stakeAsync(stakeAmounts[1]); await stakers[1].moveStakeAsync( new StakeInfo(StakeStatus.Undelegated), @@ -281,11 +282,11 @@ blockchainTests.resets('Testing Rewards', env => { it('Should give pool reward to delegators only for the epoch during which they delegated', async () => { const stakeAmounts = [toBaseUnitAmount(4), toBaseUnitAmount(6)]; const totalStakeAmount = toBaseUnitAmount(10); - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) await stakers[0].stakeWithPoolAsync(poolId, stakeAmounts[0]); // skip epoch, so first staker can start earning rewards await payProtocolFeeAndFinalize(); - // second staker delegates (epoch 1) + // second staker delegates (epoch 2) await stakers[1].stakeWithPoolAsync(poolId, stakeAmounts[1]); // only the first staker will get this reward const rewardForOnlyFirstDelegator = toBaseUnitAmount(10); @@ -321,11 +322,11 @@ blockchainTests.resets('Testing Rewards', env => { const totalSharedRewards = new BigNumber(totalSharedRewardsAsNumber); const stakeAmounts = [toBaseUnitAmount(4), toBaseUnitAmount(6)]; const totalStakeAmount = toBaseUnitAmount(10); - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) await stakers[0].stakeWithPoolAsync(poolId, stakeAmounts[0]); // skip epoch, so first staker can start earning rewards await payProtocolFeeAndFinalize(); - // second staker delegates (epoch 1) + // second staker delegates (epoch 2) await stakers[1].stakeWithPoolAsync(poolId, stakeAmounts[1]); // only the first staker will get this reward await payProtocolFeeAndFinalize(rewardForOnlyFirstDelegator); @@ -345,7 +346,7 @@ blockchainTests.resets('Testing Rewards', env => { }); it('Should withdraw existing rewards when undelegating stake', async () => { const stakeAmount = toBaseUnitAmount(4); - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) await stakers[0].stakeWithPoolAsync(poolId, stakeAmount); // skip epoch, so first staker can start earning rewards await payProtocolFeeAndFinalize(); @@ -366,7 +367,7 @@ blockchainTests.resets('Testing Rewards', env => { }); it('Should withdraw existing rewards correctly when delegating more stake', async () => { const stakeAmount = toBaseUnitAmount(4); - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) await stakers[0].stakeWithPoolAsync(poolId, stakeAmount); // skip epoch, so first staker can start earning rewards await payProtocolFeeAndFinalize(); @@ -394,11 +395,11 @@ blockchainTests.resets('Testing Rewards', env => { const totalRewardsAfterAddingMoreStake = BigNumber.sum(...rewardsAfterAddingMoreStake); const stakeAmounts = [toBaseUnitAmount(4), toBaseUnitAmount(6)]; const totalStake = BigNumber.sum(...stakeAmounts); - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) await stakers[0].stakeWithPoolAsync(poolId, stakeAmounts[0]); // skip epoch, so first staker can start earning rewards await payProtocolFeeAndFinalize(); - // second staker delegates (epoch 1) + // second staker delegates (epoch 2) await stakers[1].stakeWithPoolAsync(poolId, stakeAmounts[1]); // only the first staker will get this reward await payProtocolFeeAndFinalize(rewardBeforeAddingMoreStake); @@ -423,7 +424,7 @@ blockchainTests.resets('Testing Rewards', env => { }); }); it('Should stop collecting rewards after undelegating', async () => { - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) const rewardForDelegator = toBaseUnitAmount(10); const rewardNotForDelegator = toBaseUnitAmount(7); const stakeAmount = toBaseUnitAmount(4); @@ -452,7 +453,7 @@ blockchainTests.resets('Testing Rewards', env => { }); }); it('Should stop collecting rewards after undelegating, after several epochs', async () => { - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) const rewardForDelegator = toBaseUnitAmount(10); const rewardsNotForDelegator = [ toBaseUnitAmount(20), @@ -487,7 +488,7 @@ blockchainTests.resets('Testing Rewards', env => { }); }); it('Should collect fees correctly when leaving and returning to a pool', async () => { - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) const rewardsForDelegator = [toBaseUnitAmount(10), toBaseUnitAmount(15)]; const rewardNotForDelegator = toBaseUnitAmount(7); const stakeAmount = toBaseUnitAmount(4); @@ -525,7 +526,7 @@ blockchainTests.resets('Testing Rewards', env => { it('Should collect fees correctly when re-delegating after un-delegating', async () => { // Note - there are two ranges over which payouts are computed (see _computeRewardBalanceOfDelegator). // This triggers the first range (rewards for `delegatedStake.currentEpoch`), but not the second. - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) const rewardForDelegator = toBaseUnitAmount(10); const stakeAmount = toBaseUnitAmount(4); await stakers[0].stakeAsync(stakeAmount); @@ -560,7 +561,7 @@ blockchainTests.resets('Testing Rewards', env => { }); }); it('Should withdraw delegator rewards when calling `withdrawDelegatorRewards`', async () => { - // first staker delegates (epoch 0) + // first staker delegates (epoch 1) const rewardForDelegator = toBaseUnitAmount(10); const stakeAmount = toBaseUnitAmount(4); await stakers[0].stakeAsync(stakeAmount); @@ -584,6 +585,31 @@ blockchainTests.resets('Testing Rewards', env => { poolRewardBalance: constants.ZERO_AMOUNT, }); }); + it('should fail to withdraw delegator rewards if the pool has not been finalized for the previous epoch', async () => { + const rewardForDelegator = toBaseUnitAmount(10); + const stakeAmount = toBaseUnitAmount(4); + await stakers[0].stakeAsync(stakeAmount); + await stakers[0].moveStakeAsync( + new StakeInfo(StakeStatus.Undelegated), + new StakeInfo(StakeStatus.Delegated, poolId), + stakeAmount, + ); + await stakingApiWrapper.stakingContract.payProtocolFee.awaitTransactionSuccessAsync( + poolOperator.getOwner(), + takerAddress, + rewardForDelegator, + { from: exchangeAddress, value: rewardForDelegator }, + ); + const currentEpoch = await stakingApiWrapper.stakingContract.currentEpoch.callAsync(); + await stakingApiWrapper.utils.fastForwardToNextEpochAsync(); + await stakingApiWrapper.utils.endEpochAsync(); + const expectedError = new StakingRevertErrors.PoolNotFinalizedError(poolId, currentEpoch); + expect( + stakingApiWrapper.stakingContract.withdrawDelegatorRewards.awaitTransactionSuccessAsync(poolId, { + from: stakers[0].getOwner(), + }), + ).to.revertWith(expectedError); + }); it(`payout should be based on stake at the time of rewards`, async () => { const staker = stakers[0]; const stakeAmount = toBaseUnitAmount(5); diff --git a/contracts/staking/test/stake_test.ts b/contracts/staking/test/stake_test.ts index bc98b41690..065178d80a 100644 --- a/contracts/staking/test/stake_test.ts +++ b/contracts/staking/test/stake_test.ts @@ -73,7 +73,7 @@ blockchainTests.resets('Stake Statuses', env => { }); describe('Move Stake', () => { it("should be able to rebalance next epoch's stake", async () => { - // epoch 1 + // epoch 2 const amount = toBaseUnitAmount(10); await staker.stakeAsync(amount); await staker.moveStakeAsync( @@ -81,7 +81,7 @@ blockchainTests.resets('Stake Statuses', env => { new StakeInfo(StakeStatus.Delegated, poolIds[0]), amount, ); - // still epoch 1 ~ should be able to move stake again + // still epoch 2 ~ should be able to move stake again await staker.moveStakeAsync( new StakeInfo(StakeStatus.Delegated, poolIds[0]), new StakeInfo(StakeStatus.Undelegated), @@ -89,7 +89,7 @@ blockchainTests.resets('Stake Statuses', env => { ); }); it("should be able to reassign next epoch's stake", async () => { - // epoch 1 + // epoch 2 const amount = toBaseUnitAmount(10); await staker.stakeAsync(amount); await staker.moveStakeAsync( @@ -97,7 +97,7 @@ blockchainTests.resets('Stake Statuses', env => { new StakeInfo(StakeStatus.Delegated, poolIds[0]), amount, ); - // still epoch 1 ~ should be able to move stake again + // still epoch 2 ~ should be able to move stake again await staker.moveStakeAsync( new StakeInfo(StakeStatus.Delegated, poolIds[0]), new StakeInfo(StakeStatus.Delegated, poolIds[1]), @@ -105,7 +105,7 @@ blockchainTests.resets('Stake Statuses', env => { ); }); it('should fail to move the same stake more than once', async () => { - // epoch 1 + // epoch 2 const amount = toBaseUnitAmount(10); await staker.stakeAsync(amount); await staker.moveStakeAsync( @@ -124,14 +124,14 @@ blockchainTests.resets('Stake Statuses', env => { }); describe('Stake and Move', () => { it("should be able to rebalance next epoch's stake", async () => { - // epoch 1 + // epoch 2 const amount = toBaseUnitAmount(10); await staker.stakeAndMoveAsync( new StakeInfo(StakeStatus.Undelegated), new StakeInfo(StakeStatus.Delegated, poolIds[0]), amount, ); - // still epoch 1 ~ should be able to move stake again + // still epoch 2 ~ should be able to move stake again await staker.moveStakeAsync( new StakeInfo(StakeStatus.Delegated, poolIds[0]), new StakeInfo(StakeStatus.Undelegated), @@ -139,7 +139,7 @@ blockchainTests.resets('Stake Statuses', env => { ); }); it('should fail to move the same stake more than once', async () => { - // epoch 1 + // epoch 2 const amount = toBaseUnitAmount(10); await staker.stakeAndMoveAsync( new StakeInfo(StakeStatus.Undelegated), diff --git a/contracts/staking/test/unit_tests/delegator_reward_test.ts b/contracts/staking/test/unit_tests/delegator_reward_test.ts index 0113edc223..58e4855e20 100644 --- a/contracts/staking/test/unit_tests/delegator_reward_test.ts +++ b/contracts/staking/test/unit_tests/delegator_reward_test.ts @@ -207,7 +207,7 @@ blockchainTests.resets('Delegator rewards unit tests', env => { } async function finalizePoolAsync(poolId: string): Promise> { - const receipt = await testContract.originalFinalizePool.awaitTransactionSuccessAsync(poolId); + const receipt = await testContract.finalizePool.awaitTransactionSuccessAsync(poolId); const delegatorTransfers = getTransfersFromLogs(receipt.logs, poolId); return { delegatorTransfers, @@ -226,13 +226,13 @@ blockchainTests.resets('Delegator rewards unit tests', env => { } describe('computeRewardBalanceOfOperator()', () => { - it('nothing in epoch 0', async () => { + it('nothing in epoch 1', async () => { const { poolId } = await rewardPoolAsync(); const operatorReward = await getOperatorRewardBalanceAsync(poolId); expect(operatorReward).to.bignumber.eq(0); }); - it('nothing in epoch 1', async () => { + it('nothing in epoch 2', async () => { await advanceEpochAsync(); const { poolId } = await rewardPoolAsync(); const operatorReward = await getOperatorRewardBalanceAsync(poolId); @@ -273,8 +273,7 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('nothing once rewards are finalized', async () => { const { poolId } = await setUnfinalizedPoolRewardAsync(); - // Delegate some stake to trigger finalization. - await delegateStakeAsync(poolId); + await finalizePoolAsync(poolId); const operatorReward = await getOperatorRewardBalanceAsync(poolId); expect(operatorReward).to.bignumber.eq(0); }); @@ -282,77 +281,77 @@ blockchainTests.resets('Delegator rewards unit tests', env => { }); describe('computeRewardBalanceOfDelegator()', () => { - it('nothing in epoch 0 for delegator with no stake', async () => { + it('nothing in epoch 1 for delegator with no stake', async () => { const { poolId } = await rewardPoolAsync(); const delegator = randomAddress(); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(delegatorReward).to.bignumber.eq(0); }); - it('nothing in epoch 1 for delegator with no stake', async () => { - await advanceEpochAsync(); // epoch 1 + it('nothing in epoch 2 for delegator with no stake', async () => { + await advanceEpochAsync(); // epoch 2 const { poolId } = await rewardPoolAsync(); const delegator = randomAddress(); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(delegatorReward).to.bignumber.eq(0); }); - it('nothing in epoch 0 for delegator staked in epoch 0', async () => { + it('nothing in epoch 1 for delegator staked in epoch 1', async () => { const { poolId } = await rewardPoolAsync(); - // Assign active stake to pool in epoch 0, which is usuaslly not + // Assign active stake to pool in epoch 1, which is usuaslly not // possible due to delegating delays. const { delegator } = await delegateStakeNowAsync(poolId); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(delegatorReward).to.bignumber.eq(0); }); - it('nothing in epoch 1 for delegator delegating in epoch 1', async () => { - await advanceEpochAsync(); // epoch 1 + it('nothing in epoch 2 for delegator delegating in epoch 2', async () => { + await advanceEpochAsync(); // epoch 2 const { poolId } = await rewardPoolAsync(); const { delegator } = await delegateStakeAsync(poolId); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(delegatorReward).to.bignumber.eq(0); }); - it('nothing in epoch 1 for delegator delegating in epoch 0', async () => { + it('nothing in epoch 2 for delegator delegating in epoch 1', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - // rewards paid for stake in epoch 0. + await advanceEpochAsync(); // epoch 2 (stake now active) + // rewards paid for stake in epoch 1. await rewardPoolAsync({ poolId, membersStake: stake }); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(delegatorReward).to.bignumber.eq(0); }); - it('all rewards from epoch 2 for delegator delegating in epoch 0', async () => { + it('all rewards from epoch 3 for delegator delegating in epoch 1', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1. + await advanceEpochAsync(); // epoch 2 (stake now active) + await advanceEpochAsync(); // epoch 3 + // rewards paid for stake in epoch 2. const { membersReward: reward } = await rewardPoolAsync({ poolId, membersStake: stake }); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(delegatorReward).to.bignumber.eq(reward); }); - it('all rewards from epoch 2 and 3 for delegator delegating in epoch 0', async () => { + it('all rewards from epoch 3 and 3 for delegator delegating in epoch 1', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - await advanceEpochAsync(); // epoch 2 - const { membersReward: reward1 } = await rewardPoolAsync({ poolId, membersStake: stake }); + await advanceEpochAsync(); // epoch 2 (stake now active) await advanceEpochAsync(); // epoch 3 + const { membersReward: reward1 } = await rewardPoolAsync({ poolId, membersStake: stake }); + await advanceEpochAsync(); // epoch 4 const { membersReward: reward2 } = await rewardPoolAsync({ poolId, membersStake: stake }); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); assertRoughlyEquals(delegatorReward, BigNumber.sum(reward1, reward2)); }); - it('partial rewards from epoch 2 and 3 for delegator partially delegating in epoch 0', async () => { + it('partial rewards from epoch 3 and 3 for delegator partially delegating in epoch 1', async () => { const poolId = hexRandom(); const { delegator, stake: delegatorStake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1. + await advanceEpochAsync(); // epoch 2 (stake now active) + await advanceEpochAsync(); // epoch 3 + // rewards paid for stake in epoch 2. const { membersReward: reward, membersStake: rewardStake } = await rewardPoolAsync({ poolId, membersStake: new BigNumber(delegatorStake).times(2), @@ -365,9 +364,9 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('has correct reward immediately after undelegating', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1. + await advanceEpochAsync(); // epoch 2 (stake now active) + await advanceEpochAsync(); // epoch 3 + // rewards paid for stake in epoch 2. const { membersReward: reward } = await rewardPoolAsync({ poolId, membersStake: stake }); const { delegatorTransfers: withdrawal } = await undelegateStakeAsync(poolId, delegator); assertRoughlyEquals(withdrawal, reward); @@ -378,9 +377,9 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('has correct reward immediately after undelegating and redelegating', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1. + await advanceEpochAsync(); // epoch 2 (stake now active) + await advanceEpochAsync(); // epoch 3 + // rewards paid for stake in epoch 2. const { membersReward: reward } = await rewardPoolAsync({ poolId, membersStake: stake }); const { delegatorTransfers: withdrawal } = await undelegateStakeAsync(poolId, delegator); assertRoughlyEquals(withdrawal, reward); @@ -392,15 +391,15 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('has correct reward immediately after undelegating, redelegating, and rewarding fees', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1. + await advanceEpochAsync(); // epoch 2 (stake now active) + await advanceEpochAsync(); // epoch 3 + // rewards paid for stake in epoch 2. await rewardPoolAsync({ poolId, membersStake: stake }); await undelegateStakeAsync(poolId, delegator); await delegateStakeAsync(poolId, { delegator, stake }); - await advanceEpochAsync(); // epoch 3 await advanceEpochAsync(); // epoch 4 - // rewards paid for stake in epoch 3. + await advanceEpochAsync(); // epoch 5 + // rewards paid for stake in epoch 4. const { membersReward: reward } = await rewardPoolAsync({ poolId, membersStake: stake }); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); assertRoughlyEquals(delegatorReward, reward); @@ -410,10 +409,10 @@ blockchainTests.resets('Delegator rewards unit tests', env => { const poolId = hexRandom(); // stake at 0 const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - // Pay rewards for epoch 0. - await advanceEpochAsync(); // epoch 2 + await advanceEpochAsync(); // epoch 2 (stake now active) // Pay rewards for epoch 1. + await advanceEpochAsync(); // epoch 3 + // Pay rewards for epoch 2. const { membersReward: reward } = await rewardPoolAsync({ poolId, membersStake: stake }); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(delegatorReward).to.bignumber.eq(reward); @@ -423,21 +422,21 @@ blockchainTests.resets('Delegator rewards unit tests', env => { const poolId = hexRandom(); // stake at 0 const { delegator, stake: stake1 } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake1 now active) - await advanceEpochAsync(); // epoch 2 + await advanceEpochAsync(); // epoch 2 (stake1 now active) + await advanceEpochAsync(); // epoch 3 const stake2 = getRandomInteger(0, stake1); const totalStake = BigNumber.sum(stake1, stake2); // Make the total stake in rewards > totalStake so delegator never // receives 100% of rewards. const rewardStake = totalStake.times(2); - // Pay rewards for epoch 1. + // Pay rewards for epoch 2. const { membersReward: reward1 } = await rewardPoolAsync({ poolId, membersStake: rewardStake }); // add extra stake const { delegatorTransfers: withdrawal } = await delegateStakeAsync(poolId, { delegator, stake: stake2 }); - await advanceEpochAsync(); // epoch 3 (stake2 now active) - // Pay rewards for epoch 2. - await advanceEpochAsync(); // epoch 4 + await advanceEpochAsync(); // epoch 4 (stake2 now active) // Pay rewards for epoch 3. + await advanceEpochAsync(); // epoch 5 + // Pay rewards for epoch 4. const { membersReward: reward2 } = await rewardPoolAsync({ poolId, membersStake: rewardStake }); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); const expectedDelegatorReward = BigNumber.sum( @@ -451,18 +450,18 @@ blockchainTests.resets('Delegator rewards unit tests', env => { const poolId = hexRandom(); // stake at 0 const { delegator, stake: stake1 } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake1 now active) + await advanceEpochAsync(); // epoch 2 (stake1 now active) // add extra stake const { stake: stake2 } = await delegateStakeAsync(poolId, { delegator }); const totalStake = BigNumber.sum(stake1, stake2); - await advanceEpochAsync(); // epoch 2 (stake2 now active) + await advanceEpochAsync(); // epoch 3 (stake2 now active) // Make the total stake in rewards > totalStake so delegator never // receives 100% of rewards. const rewardStake = totalStake.times(2); - // Pay rewards for epoch 1. - const { membersReward: reward1 } = await rewardPoolAsync({ poolId, membersStake: rewardStake }); - await advanceEpochAsync(); // epoch 3 // Pay rewards for epoch 2. + const { membersReward: reward1 } = await rewardPoolAsync({ poolId, membersStake: rewardStake }); + await advanceEpochAsync(); // epoch 4 + // Pay rewards for epoch 3. const { membersReward: reward2 } = await rewardPoolAsync({ poolId, membersStake: rewardStake }); const delegatorReward = await getDelegatorRewardBalanceAsync(poolId, delegator); const expectedDelegatorReward = BigNumber.sum( @@ -475,14 +474,14 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('computes correct rewards for 2 staggered delegators', async () => { const poolId = hexRandom(); const { delegator: delegatorA, stake: stakeA } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake A now active) + await advanceEpochAsync(); // epoch 2 (stake A now active) const { delegator: delegatorB, stake: stakeB } = await delegateStakeAsync(poolId); const totalStake = BigNumber.sum(stakeA, stakeB); - await advanceEpochAsync(); // epoch 2 (stake B now active) - // rewards paid for stake in epoch 1 (delegator A only) + await advanceEpochAsync(); // epoch 3 (stake B now active) + // rewards paid for stake in epoch 2 (delegator A only) const { membersReward: reward1 } = await rewardPoolAsync({ poolId, membersStake: stakeA }); - await advanceEpochAsync(); // epoch 3 - // rewards paid for stake in epoch 2 (delegator A and B) + await advanceEpochAsync(); // epoch 4 + // rewards paid for stake in epoch 3 (delegator A and B) const { membersReward: reward2 } = await rewardPoolAsync({ poolId, membersStake: totalStake }); const delegatorRewardA = await getDelegatorRewardBalanceAsync(poolId, delegatorA); const expectedDelegatorRewardA = BigNumber.sum( @@ -498,15 +497,15 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('computes correct rewards for 2 staggered delegators with a 2 epoch gap between payments', async () => { const poolId = hexRandom(); const { delegator: delegatorA, stake: stakeA } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake A now active) + await advanceEpochAsync(); // epoch 2 (stake A now active) const { delegator: delegatorB, stake: stakeB } = await delegateStakeAsync(poolId); const totalStake = BigNumber.sum(stakeA, stakeB); - await advanceEpochAsync(); // epoch 2 (stake B now active) - // rewards paid for stake in epoch 1 (delegator A only) + await advanceEpochAsync(); // epoch 3 (stake B now active) + // rewards paid for stake in epoch 2 (delegator A only) const { membersReward: reward1 } = await rewardPoolAsync({ poolId, membersStake: stakeA }); - await advanceEpochAsync(); // epoch 3 await advanceEpochAsync(); // epoch 4 - // rewards paid for stake in epoch 3 (delegator A and B) + await advanceEpochAsync(); // epoch 5 + // rewards paid for stake in epoch 4 (delegator A and B) const { membersReward: reward2 } = await rewardPoolAsync({ poolId, membersStake: totalStake }); const delegatorRewardA = await getDelegatorRewardBalanceAsync(poolId, delegatorA); const expectedDelegatorRewardA = BigNumber.sum( @@ -522,15 +521,15 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('correct rewards for rewards with different stakes', async () => { const poolId = hexRandom(); const { delegator, stake: delegatorStake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1. + await advanceEpochAsync(); // epoch 2 (stake now active) + await advanceEpochAsync(); // epoch 3 + // rewards paid for stake in epoch 2. const { membersReward: reward1, membersStake: rewardStake1 } = await rewardPoolAsync({ poolId, membersStake: new BigNumber(delegatorStake).times(2), }); - await advanceEpochAsync(); // epoch 3 - // rewards paid for stake in epoch 2 + await advanceEpochAsync(); // epoch 4 + // rewards paid for stake in epoch 3 const { membersReward: reward2, membersStake: rewardStake2 } = await rewardPoolAsync({ poolId, membersStake: new BigNumber(delegatorStake).times(3), @@ -544,29 +543,29 @@ blockchainTests.resets('Delegator rewards unit tests', env => { }); describe('with unfinalized rewards', async () => { - it('nothing with only unfinalized rewards from epoch 1 for delegator with nothing delegated', async () => { + it('nothing with only unfinalized rewards from epoch 2 for delegator with nothing delegated', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId, { stake: 0 }); - await advanceEpochAsync(); // epoch 1 + await advanceEpochAsync(); // epoch 2 await setUnfinalizedPoolRewardAsync({ poolId, membersStake: stake }); const reward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(reward).to.bignumber.eq(0); }); - it('nothing with only unfinalized rewards from epoch 1 for delegator delegating in epoch 0', async () => { + it('nothing with only unfinalized rewards from epoch 2 for delegator delegating in epoch 1', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 + await advanceEpochAsync(); // epoch 2 await setUnfinalizedPoolRewardAsync({ poolId, membersStake: stake }); const reward = await getDelegatorRewardBalanceAsync(poolId, delegator); expect(reward).to.bignumber.eq(0); }); - it('returns unfinalized rewards from epoch 2 for delegator delegating in epoch 0', async () => { + it('returns unfinalized rewards from epoch 3 for delegator delegating in epoch 1', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 await advanceEpochAsync(); // epoch 2 + await advanceEpochAsync(); // epoch 3 const { membersReward: unfinalizedReward } = await setUnfinalizedPoolRewardAsync({ poolId, membersStake: stake, @@ -575,12 +574,12 @@ blockchainTests.resets('Delegator rewards unit tests', env => { assertRoughlyEquals(reward, unfinalizedReward); }); - it('returns unfinalized rewards from epoch 3 for delegator delegating in epoch 0', async () => { + it('returns unfinalized rewards from epoch 4 for delegator delegating in epoch 1', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 await advanceEpochAsync(); // epoch 2 await advanceEpochAsync(); // epoch 3 + await advanceEpochAsync(); // epoch 4 const { membersReward: unfinalizedReward } = await setUnfinalizedPoolRewardAsync({ poolId, membersStake: stake, @@ -589,13 +588,13 @@ blockchainTests.resets('Delegator rewards unit tests', env => { assertRoughlyEquals(reward, unfinalizedReward); }); - it('returns unfinalized rewards from epoch 3 + rewards from epoch 2 for delegator delegating in epoch 0', async () => { + it('returns unfinalized rewards from epoch 4 + rewards from epoch 3 for delegator delegating in epoch 1', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 await advanceEpochAsync(); // epoch 2 - const { membersReward: prevReward } = await rewardPoolAsync({ poolId, membersStake: stake }); await advanceEpochAsync(); // epoch 3 + const { membersReward: prevReward } = await rewardPoolAsync({ poolId, membersStake: stake }); + await advanceEpochAsync(); // epoch 4 const { membersReward: unfinalizedReward } = await setUnfinalizedPoolRewardAsync({ poolId, membersStake: stake, @@ -605,14 +604,14 @@ blockchainTests.resets('Delegator rewards unit tests', env => { assertRoughlyEquals(reward, expectedReward); }); - it('returns unfinalized rewards from epoch 4 + rewards from epoch 2 for delegator delegating in epoch 1', async () => { + it('returns unfinalized rewards from epoch 5 + rewards from epoch 3 for delegator delegating in epoch 2', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 await advanceEpochAsync(); // epoch 2 - const { membersReward: prevReward } = await rewardPoolAsync({ poolId, membersStake: stake }); await advanceEpochAsync(); // epoch 3 + const { membersReward: prevReward } = await rewardPoolAsync({ poolId, membersStake: stake }); await advanceEpochAsync(); // epoch 4 + await advanceEpochAsync(); // epoch 5 const { membersReward: unfinalizedReward } = await setUnfinalizedPoolRewardAsync({ poolId, membersStake: stake, @@ -625,14 +624,14 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('returns correct rewards if unfinalized stake is different from previous rewards', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 await advanceEpochAsync(); // epoch 2 + await advanceEpochAsync(); // epoch 3 const { membersReward: prevReward, membersStake: prevStake } = await rewardPoolAsync({ poolId, membersStake: new BigNumber(stake).times(2), }); - await advanceEpochAsync(); // epoch 3 await advanceEpochAsync(); // epoch 4 + await advanceEpochAsync(); // epoch 5 const { membersReward: unfinalizedReward, membersStake: unfinalizedStake, @@ -654,9 +653,9 @@ blockchainTests.resets('Delegator rewards unit tests', env => { it('transfers all rewards to delegator when touching stake', async () => { const poolId = hexRandom(); const { delegator, stake } = await delegateStakeAsync(poolId); - await advanceEpochAsync(); // epoch 1 (stake now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1 + await advanceEpochAsync(); // epoch 2 (stake now active) + await advanceEpochAsync(); // epoch 3 + // rewards paid for stake in epoch 2 const { membersReward: reward } = await rewardPoolAsync({ poolId, membersStake: stake }); const { delegatorTransfers: withdrawal } = await touchStakeAsync(poolId, delegator); const finalRewardBalance = await getDelegatorRewardBalanceAsync(poolId, delegator); @@ -671,17 +670,17 @@ blockchainTests.resets('Delegator rewards unit tests', env => { stakeResults.push(await delegateStakeAsync(poolId)); const { delegator, stake } = stakeResults[0]; const rewardStake = new BigNumber(stake).times(2); - await advanceEpochAsync(); // epoch 1 (stake now active) + await advanceEpochAsync(); // epoch 2 (stake now active) // add more stake. stakeResults.push(await delegateStakeAsync(poolId, { delegator, stake })); - await advanceEpochAsync(); // epoch 1 (2 * stake now active) - // reward for epoch 1, using 2 * stake so delegator should + await advanceEpochAsync(); // epoch 2 (2 * stake now active) + // reward for epoch 2, using 2 * stake so delegator should // only be entitled to a fraction of the rewards. const { membersReward: reward } = await rewardPoolAsync({ poolId, membersStake: rewardStake }); - await advanceEpochAsync(); // epoch 2 + await advanceEpochAsync(); // epoch 3 // touch the stake one last time stakeResults.push(await touchStakeAsync(poolId, delegator)); - // Should only see deposits for epoch 2. + // Should only see deposits for epoch 3. const allDeposits = stakeResults.map(r => r.delegatorTransfers); const expectedReward = computeDelegatorRewards(reward, stake, rewardStake); assertRoughlyEquals(BigNumber.sum(...allDeposits), expectedReward); @@ -694,19 +693,19 @@ blockchainTests.resets('Delegator rewards unit tests', env => { stakeResults.push(await delegateStakeAsync(poolId)); const { delegator, stake } = stakeResults[0]; const rewardStake = new BigNumber(stake).times(2); - await advanceEpochAsync(); // epoch 1 (full stake now active) - // reward for epoch 0 + await advanceEpochAsync(); // epoch 2 (full stake now active) + // reward for epoch 1 await rewardPoolAsync({ poolId, membersStake: rewardStake }); // unstake some const unstake = new BigNumber(stake).dividedToIntegerBy(2); stakeResults.push(await undelegateStakeAsync(poolId, delegator, unstake)); - await advanceEpochAsync(); // epoch 2 (half active stake) - // reward for epoch 1 + await advanceEpochAsync(); // epoch 3 (half active stake) + // reward for epoch 2 const { membersReward: reward1 } = await rewardPoolAsync({ poolId, membersStake: rewardStake }); // re-stake stakeResults.push(await delegateStakeAsync(poolId, { delegator, stake: unstake })); - await advanceEpochAsync(); // epoch 3 (full stake now active) - // reward for epoch 2 + await advanceEpochAsync(); // epoch 4 (full stake now active) + // reward for epoch 3 const { membersReward: reward2 } = await rewardPoolAsync({ poolId, membersStake: rewardStake }); // touch the stake to claim rewards stakeResults.push(await touchStakeAsync(poolId, delegator)); @@ -723,9 +722,9 @@ blockchainTests.resets('Delegator rewards unit tests', env => { const { delegator: delegatorA, stake: stakeA } = await delegateStakeAsync(poolId); const { delegator: delegatorB, stake: stakeB } = await delegateStakeAsync(poolId); const totalStake = BigNumber.sum(stakeA, stakeB); - await advanceEpochAsync(); // epoch 1 (stakes now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1 + await advanceEpochAsync(); // epoch 2 (stakes now active) + await advanceEpochAsync(); // epoch 3 + // rewards paid for stake in epoch 2 const { membersReward: reward } = await rewardPoolAsync({ poolId, membersStake: totalStake }); // delegator A will finalize and collect rewards by touching stake. const { delegatorTransfers: withdrawalA } = await touchStakeAsync(poolId, delegatorA); @@ -740,18 +739,18 @@ blockchainTests.resets('Delegator rewards unit tests', env => { const { delegator: delegatorA, stake: stakeA } = await delegateStakeAsync(poolId); const { delegator: delegatorB, stake: stakeB } = await delegateStakeAsync(poolId); const totalStake = BigNumber.sum(stakeA, stakeB); - await advanceEpochAsync(); // epoch 1 (stakes now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1 - const { membersReward: prevReward } = await rewardPoolAsync({ poolId, membersStake: totalStake }); + await advanceEpochAsync(); // epoch 2 (stakes now active) await advanceEpochAsync(); // epoch 3 - // unfinalized rewards for stake in epoch 2 + // rewards paid for stake in epoch 2 + const { membersReward: prevReward } = await rewardPoolAsync({ poolId, membersStake: totalStake }); + await advanceEpochAsync(); // epoch 4 + // unfinalized rewards for stake in epoch 3 const { membersReward: unfinalizedReward } = await setUnfinalizedPoolRewardAsync({ poolId, membersStake: totalStake, }); const totalRewards = BigNumber.sum(prevReward, unfinalizedReward); - // delegator A will finalize and collect rewards by touching stake. + await finalizePoolAsync(poolId); const { delegatorTransfers: withdrawalA } = await touchStakeAsync(poolId, delegatorA); assertRoughlyEquals(withdrawalA, computeDelegatorRewards(totalRewards, stakeA, totalStake)); // delegator B will collect rewards by touching stake @@ -764,12 +763,12 @@ blockchainTests.resets('Delegator rewards unit tests', env => { const { delegator: delegatorA, stake: stakeA } = await delegateStakeAsync(poolId); const { delegator: delegatorB, stake: stakeB } = await delegateStakeAsync(poolId); const totalStake = BigNumber.sum(stakeA, stakeB); - await advanceEpochAsync(); // epoch 1 (stakes now active) - await advanceEpochAsync(); // epoch 2 - // rewards paid for stake in epoch 1 - const { membersReward: prevReward } = await rewardPoolAsync({ poolId, membersStake: totalStake }); + await advanceEpochAsync(); // epoch 2 (stakes now active) await advanceEpochAsync(); // epoch 3 - // unfinalized rewards for stake in epoch 2 + // rewards paid for stake in epoch 2 + const { membersReward: prevReward } = await rewardPoolAsync({ poolId, membersStake: totalStake }); + await advanceEpochAsync(); // epoch 4 + // unfinalized rewards for stake in epoch 3 const { membersReward: unfinalizedReward } = await setUnfinalizedPoolRewardAsync({ poolId, membersStake: totalStake, diff --git a/contracts/staking/test/unit_tests/finalizer_test.ts b/contracts/staking/test/unit_tests/finalizer_test.ts index 50448f5063..8143917b34 100644 --- a/contracts/staking/test/unit_tests/finalizer_test.ts +++ b/contracts/staking/test/unit_tests/finalizer_test.ts @@ -22,11 +22,11 @@ import { TestFinalizerDepositStakingPoolRewardsEventArgs as DepositStakingPoolRewardsEventArgs, TestFinalizerEvents, } from '../../src'; +import { constants as stakingConstants } from '../utils/constants'; import { assertIntegerRoughlyEquals, getRandomInteger, toBaseUnitAmount } from '../utils/number_utils'; blockchainTests.resets('Finalizer unit tests', env => { const { ZERO_AMOUNT } = constants; - const INITIAL_EPOCH = 0; const INITIAL_BALANCE = toBaseUnitAmount(32); let operatorRewardsReceiver: string; let membersRewardsReceiver: string; @@ -87,21 +87,14 @@ blockchainTests.resets('Finalizer unit tests', env => { interface UnfinalizedState { rewardsAvailable: Numberish; - poolsRemaining: number; + numPoolsToFinalize: Numberish; totalFeesCollected: Numberish; totalWeightedStake: Numberish; totalRewardsFinalized: Numberish; } async function getUnfinalizedStateAsync(): Promise { - const r = await testContract.unfinalizedState.callAsync(); - return { - rewardsAvailable: r[0], - poolsRemaining: r[1].toNumber(), - totalFeesCollected: r[2], - totalWeightedStake: r[3], - totalRewardsFinalized: r[4], - }; + return testContract.getAggregatedStatsForPreviousEpoch.callAsync(); } async function finalizePoolsAsync(poolIds: string[]): Promise { @@ -142,16 +135,16 @@ blockchainTests.resets('Finalizer unit tests', env => { async function assertFinalizationLogsAndBalancesAsync( rewardsAvailable: Numberish, - activePools: ActivePoolOpts[], + poolsToFinalize: ActivePoolOpts[], finalizationLogs: LogEntry[], ): Promise { const currentEpoch = await getCurrentEpochAsync(); // Compute the expected rewards for each pool. - const poolsWithStake = activePools.filter(p => !new BigNumber(p.weightedStake).isZero()); + const poolsWithStake = poolsToFinalize.filter(p => !new BigNumber(p.weightedStake).isZero()); const poolRewards = await calculatePoolRewardsAsync(rewardsAvailable, poolsWithStake); const totalRewards = BigNumber.sum(...poolRewards); const rewardsRemaining = new BigNumber(rewardsAvailable).minus(totalRewards); - const [totalOperatorRewards, totalMembersRewards] = getTotalSplitRewards(activePools, poolRewards); + const [totalOperatorRewards, totalMembersRewards] = getTotalSplitRewards(poolsToFinalize, poolRewards); // Assert the `RewardsPaid` logs. const rewardsPaidEvents = getRewardsPaidEvents(finalizationLogs); @@ -186,7 +179,7 @@ blockchainTests.resets('Finalizer unit tests', env => { // Assert the `EpochFinalized` logs. const epochFinalizedEvents = getEpochFinalizedEvents(finalizationLogs); expect(epochFinalizedEvents.length).to.eq(1); - expect(epochFinalizedEvents[0].epoch).to.bignumber.eq(currentEpoch - 1); + expect(epochFinalizedEvents[0].epoch).to.bignumber.eq(currentEpoch.minus(1)); assertIntegerRoughlyEquals(epochFinalizedEvents[0].rewardsPaid, totalRewards); assertIntegerRoughlyEquals(epochFinalizedEvents[0].rewardsRemaining, rewardsRemaining); @@ -203,13 +196,13 @@ blockchainTests.resets('Finalizer unit tests', env => { async function calculatePoolRewardsAsync( rewardsAvailable: Numberish, - activePools: ActivePoolOpts[], + poolsToFinalize: ActivePoolOpts[], ): Promise { - const totalFees = BigNumber.sum(...activePools.map(p => p.feesCollected)); - const totalStake = BigNumber.sum(...activePools.map(p => p.weightedStake)); - const poolRewards = _.times(activePools.length, () => constants.ZERO_AMOUNT); - for (const i of _.times(activePools.length)) { - const pool = activePools[i]; + const totalFees = BigNumber.sum(...poolsToFinalize.map(p => p.feesCollected)); + const totalStake = BigNumber.sum(...poolsToFinalize.map(p => p.weightedStake)); + const poolRewards = _.times(poolsToFinalize.length, () => constants.ZERO_AMOUNT); + for (const i of _.times(poolsToFinalize.length)) { + const pool = poolsToFinalize[i]; const feesCollected = new BigNumber(pool.feesCollected); if (feesCollected.isZero()) { continue; @@ -262,8 +255,8 @@ blockchainTests.resets('Finalizer unit tests', env => { return filterLogsToArguments(logs, IStakingEventsEvents.RewardsPaid); } - async function getCurrentEpochAsync(): Promise { - return (await testContract.currentEpoch.callAsync()).toNumber(); + async function getCurrentEpochAsync(): Promise { + return testContract.currentEpoch.callAsync(); } async function getBalanceOfAsync(whom: string): Promise { @@ -274,13 +267,13 @@ blockchainTests.resets('Finalizer unit tests', env => { it('advances the epoch', async () => { await testContract.endEpoch.awaitTransactionSuccessAsync(); const currentEpoch = await testContract.currentEpoch.callAsync(); - expect(currentEpoch).to.bignumber.eq(INITIAL_EPOCH + 1); + expect(currentEpoch).to.bignumber.eq(stakingConstants.INITIAL_EPOCH.plus(1)); }); it('emits an `EpochEnded` event', async () => { const receipt = await testContract.endEpoch.awaitTransactionSuccessAsync(); assertEpochEndedEvent(receipt.logs, { - epoch: new BigNumber(INITIAL_EPOCH), + epoch: stakingConstants.INITIAL_EPOCH, numActivePools: ZERO_AMOUNT, rewardsAvailable: INITIAL_BALANCE, totalFeesCollected: ZERO_AMOUNT, @@ -288,16 +281,16 @@ blockchainTests.resets('Finalizer unit tests', env => { }); }); - it('immediately finalizes if there are no active pools', async () => { + it('immediately finalizes if there are no pools to finalize', async () => { const receipt = await testContract.endEpoch.awaitTransactionSuccessAsync(); assertEpochFinalizedEvent(receipt.logs, { - epoch: new BigNumber(INITIAL_EPOCH), + epoch: stakingConstants.INITIAL_EPOCH, rewardsPaid: ZERO_AMOUNT, rewardsRemaining: INITIAL_BALANCE, }); }); - it('does not immediately finalize if there is an active pool', async () => { + it('does not immediately finalize if there is a pool to finalize', async () => { await addActivePoolAsync(); const receipt = await testContract.endEpoch.awaitTransactionSuccessAsync(); const events = filterLogsToArguments( @@ -307,43 +300,46 @@ blockchainTests.resets('Finalizer unit tests', env => { expect(events).to.deep.eq([]); }); - it("clears the next epoch's finalization state", async () => { - // Add a pool so there is state to clear. - await addActivePoolAsync(); - await testContract.endEpoch.awaitTransactionSuccessAsync(); - const epoch = await testContract.currentEpoch.callAsync(); - expect(epoch).to.bignumber.eq(INITIAL_EPOCH + 1); - const numActivePools = await testContract.numActivePoolsThisEpoch.callAsync(); - const totalFees = await testContract.totalFeesCollectedThisEpoch.callAsync(); - const totalStake = await testContract.totalWeightedStakeThisEpoch.callAsync(); - expect(numActivePools).to.bignumber.eq(0); - expect(totalFees).to.bignumber.eq(0); - expect(totalStake).to.bignumber.eq(0); - }); - it('prepares unfinalized state', async () => { // Add a pool so there is state to clear. const pool = await addActivePoolAsync(); await testContract.endEpoch.awaitTransactionSuccessAsync(); return assertUnfinalizedStateAsync({ - poolsRemaining: 1, + numPoolsToFinalize: 1, rewardsAvailable: INITIAL_BALANCE, totalFeesCollected: pool.feesCollected, totalWeightedStake: pool.weightedStake, }); }); + it("correctly stores the epoch's aggregated stats after ending the epoch", async () => { + const pool = await addActivePoolAsync(); + const epoch = await testContract.currentEpoch.callAsync(); + await testContract.endEpoch.awaitTransactionSuccessAsync(); + const aggregatedStats = await testContract.aggregatedStatsByEpoch.callAsync(epoch); + expect(aggregatedStats).to.be.deep.equal([ + INITIAL_BALANCE, + new BigNumber(1), // pools to finalize + pool.feesCollected, + pool.weightedStake, + new BigNumber(0), // rewards finalized + ]); + }); + it('reverts if the prior epoch is unfinalized', async () => { await addActivePoolAsync(); await testContract.endEpoch.awaitTransactionSuccessAsync(); const tx = testContract.endEpoch.awaitTransactionSuccessAsync(); - const expectedError = new StakingRevertErrors.PreviousEpochNotFinalizedError(INITIAL_EPOCH, 1); + const expectedError = new StakingRevertErrors.PreviousEpochNotFinalizedError( + stakingConstants.INITIAL_EPOCH, + 1, + ); return expect(tx).to.revertWith(expectedError); }); }); describe('_finalizePool()', () => { - it('does nothing if there were no active pools', async () => { + it('does nothing if there were no pools to finalize', async () => { await testContract.endEpoch.awaitTransactionSuccessAsync(); const poolId = hexRandom(); const logs = await finalizePoolsAsync([poolId]); @@ -379,8 +375,8 @@ blockchainTests.resets('Finalizer unit tests', env => { const pool = _.sample(pools) as ActivePoolOpts; await testContract.endEpoch.awaitTransactionSuccessAsync(); await finalizePoolsAsync([pool.poolId]); - const poolState = await testContract.getActivePoolFromEpoch.callAsync( - new BigNumber(INITIAL_EPOCH), + const poolState = await testContract.getPoolStatsFromEpoch.callAsync( + stakingConstants.INITIAL_EPOCH, pool.poolId, ); expect(poolState.feesCollected).to.bignumber.eq(0); @@ -430,35 +426,35 @@ blockchainTests.resets('Finalizer unit tests', env => { await testContract.endEpoch.awaitTransactionSuccessAsync(); await finalizePoolsAsync([pool.poolId]); await testContract.endEpoch.awaitTransactionSuccessAsync(); - return expect(getCurrentEpochAsync()).to.become(INITIAL_EPOCH + 2); + return expect(getCurrentEpochAsync()).to.become(stakingConstants.INITIAL_EPOCH.plus(2)); }); - it('does not reward a pool that was only active 2 epochs ago', async () => { + it('does not reward a pool that only earned rewards 2 epochs ago', async () => { const pool1 = await addActivePoolAsync(); await testContract.endEpoch.awaitTransactionSuccessAsync(); await finalizePoolsAsync([pool1.poolId]); await addActivePoolAsync(); await testContract.endEpoch.awaitTransactionSuccessAsync(); - expect(getCurrentEpochAsync()).to.become(INITIAL_EPOCH + 2); + expect(getCurrentEpochAsync()).to.become(stakingConstants.INITIAL_EPOCH.plus(2)); const logs = await finalizePoolsAsync([pool1.poolId]); const rewardsPaidEvents = getRewardsPaidEvents(logs); expect(rewardsPaidEvents).to.deep.eq([]); }); - it('does not reward a pool that was only active 3 epochs ago', async () => { + it('does not reward a pool that only earned rewards 3 epochs ago', async () => { const pool1 = await addActivePoolAsync(); await testContract.endEpoch.awaitTransactionSuccessAsync(); await finalizePoolsAsync([pool1.poolId]); await testContract.endEpoch.awaitTransactionSuccessAsync(); await addActivePoolAsync(); await testContract.endEpoch.awaitTransactionSuccessAsync(); - expect(getCurrentEpochAsync()).to.become(INITIAL_EPOCH + 3); + expect(getCurrentEpochAsync()).to.become(stakingConstants.INITIAL_EPOCH.plus(3)); const logs = await finalizePoolsAsync([pool1.poolId]); const rewardsPaidEvents = getRewardsPaidEvents(logs); expect(rewardsPaidEvents).to.deep.eq([]); }); - it('rolls over leftover rewards into th next epoch', async () => { + it('rolls over leftover rewards into the next epoch', async () => { const poolIds = _.times(3, () => hexRandom()); await Promise.all(poolIds.map(async id => addActivePoolAsync({ poolId: id }))); await testContract.endEpoch.awaitTransactionSuccessAsync(); @@ -495,23 +491,23 @@ blockchainTests.resets('Finalizer unit tests', env => { membersStake: 0, }; - it('returns empty if epoch is 0', async () => { + it('returns empty if epoch is 1', async () => { const poolId = hexRandom(); return assertUnfinalizedPoolRewardsAsync(poolId, ZERO_REWARDS); }); - it('returns empty if pool was not active', async () => { + it('returns empty if pool did not earn rewards', async () => { await testContract.endEpoch.awaitTransactionSuccessAsync(); const poolId = hexRandom(); return assertUnfinalizedPoolRewardsAsync(poolId, ZERO_REWARDS); }); - it('returns empty if pool is active only in the current epoch', async () => { + it('returns empty if pool is earned rewards only in the current epoch', async () => { const pool = await addActivePoolAsync(); return assertUnfinalizedPoolRewardsAsync(pool.poolId, ZERO_REWARDS); }); - it('returns empty if pool was only active in the 2 epochs ago', async () => { + it('returns empty if pool only earned rewards in the 2 epochs ago', async () => { const pool = await addActivePoolAsync(); await testContract.endEpoch.awaitTransactionSuccessAsync(); await finalizePoolsAsync([pool.poolId]); diff --git a/contracts/staking/test/unit_tests/protocol_fees_test.ts b/contracts/staking/test/unit_tests/protocol_fees_test.ts index 4da63f00a1..d5b5dcd53d 100644 --- a/contracts/staking/test/unit_tests/protocol_fees_test.ts +++ b/contracts/staking/test/unit_tests/protocol_fees_test.ts @@ -15,7 +15,7 @@ import * as _ from 'lodash'; import { artifacts, IStakingEventsEvents, - IStakingEventsStakingPoolActivatedEventArgs, + IStakingEventsStakingPoolEarnedRewardsInEpochEventArgs, TestProtocolFeesContract, TestProtocolFeesERC20ProxyTransferFromEventArgs, TestProtocolFeesEvents, @@ -152,7 +152,7 @@ blockchainTests('Protocol Fees unit tests', env => { }); async function getProtocolFeesAsync(poolId: string): Promise { - return (await testContract.getActiveStakingPoolThisEpoch.callAsync(poolId)).feesCollected; + return (await testContract.getStakingPoolStatsThisEpoch.callAsync(poolId)).feesCollected; } describe('ETH fees', () => { @@ -369,21 +369,22 @@ blockchainTests('Protocol Fees unit tests', env => { }); interface FinalizationState { - numActivePools: BigNumber; + numPoolsToFinalize: BigNumber; totalFeesCollected: BigNumber; totalWeightedStake: BigNumber; } async function getFinalizationStateAsync(): Promise { + const aggregatedStats = await testContract.getAggregatedStatsForCurrentEpoch.callAsync(); return { - numActivePools: await testContract.numActivePoolsThisEpoch.callAsync(), - totalFeesCollected: await testContract.totalFeesCollectedThisEpoch.callAsync(), - totalWeightedStake: await testContract.totalWeightedStakeThisEpoch.callAsync(), + numPoolsToFinalize: aggregatedStats.numPoolsToFinalize, + totalFeesCollected: aggregatedStats.totalFeesCollected, + totalWeightedStake: aggregatedStats.totalWeightedStake, }; } interface PayToMakerResult { - poolActivatedEvents: IStakingEventsStakingPoolActivatedEventArgs[]; + poolEarnedRewardsEvents: IStakingEventsStakingPoolEarnedRewardsInEpochEventArgs[]; fee: BigNumber; } @@ -395,13 +396,13 @@ blockchainTests('Protocol Fees unit tests', env => { new BigNumber(_fee), { from: exchangeAddress, value: _fee }, ); - const events = filterLogsToArguments( + const events = filterLogsToArguments( receipt.logs, - IStakingEventsEvents.StakingPoolActivated, + IStakingEventsEvents.StakingPoolEarnedRewardsInEpoch, ); return { fee: new BigNumber(_fee), - poolActivatedEvents: events, + poolEarnedRewardsEvents: events, }; } @@ -412,37 +413,37 @@ blockchainTests('Protocol Fees unit tests', env => { .plus(operatorStake); } - it('no active pools to start', async () => { + it('no pools to finalize to start', async () => { const state = await getFinalizationStateAsync(); - expect(state.numActivePools).to.bignumber.eq(0); + expect(state.numPoolsToFinalize).to.bignumber.eq(0); expect(state.totalFeesCollected).to.bignumber.eq(0); expect(state.totalWeightedStake).to.bignumber.eq(0); }); it('pool is not registered to start', async () => { const { poolId } = await createTestPoolAsync(); - const pool = await testContract.getActiveStakingPoolThisEpoch.callAsync(poolId); + const pool = await testContract.getStakingPoolStatsThisEpoch.callAsync(poolId); expect(pool.feesCollected).to.bignumber.eq(0); expect(pool.membersStake).to.bignumber.eq(0); expect(pool.weightedStake).to.bignumber.eq(0); }); - it('activates a active pool the first time it earns a fee', async () => { + it('correctly emits event for pool the first time it earns a fee', async () => { const pool = await createTestPoolAsync(); const { poolId, makers: [poolMaker], } = pool; - const { fee, poolActivatedEvents } = await payToMakerAsync(poolMaker); - expect(poolActivatedEvents.length).to.eq(1); - expect(poolActivatedEvents[0].poolId).to.eq(poolId); - const actualPool = await testContract.getActiveStakingPoolThisEpoch.callAsync(poolId); + const { fee, poolEarnedRewardsEvents } = await payToMakerAsync(poolMaker); + expect(poolEarnedRewardsEvents.length).to.eq(1); + expect(poolEarnedRewardsEvents[0].poolId).to.eq(poolId); + const actualPoolStats = await testContract.getStakingPoolStatsThisEpoch.callAsync(poolId); const expectedWeightedStake = toWeightedStake(pool.operatorStake, pool.membersStake); - expect(actualPool.feesCollected).to.bignumber.eq(fee); - expect(actualPool.membersStake).to.bignumber.eq(pool.membersStake); - expect(actualPool.weightedStake).to.bignumber.eq(expectedWeightedStake); + expect(actualPoolStats.feesCollected).to.bignumber.eq(fee); + expect(actualPoolStats.membersStake).to.bignumber.eq(pool.membersStake); + expect(actualPoolStats.weightedStake).to.bignumber.eq(expectedWeightedStake); const state = await getFinalizationStateAsync(); - expect(state.numActivePools).to.bignumber.eq(1); + expect(state.numPoolsToFinalize).to.bignumber.eq(1); expect(state.totalFeesCollected).to.bignumber.eq(fee); expect(state.totalWeightedStake).to.bignumber.eq(expectedWeightedStake); }); @@ -454,16 +455,16 @@ blockchainTests('Protocol Fees unit tests', env => { makers: [poolMaker], } = pool; const { fee: fee1 } = await payToMakerAsync(poolMaker); - const { fee: fee2, poolActivatedEvents } = await payToMakerAsync(poolMaker); - expect(poolActivatedEvents).to.deep.eq([]); - const actualPool = await testContract.getActiveStakingPoolThisEpoch.callAsync(poolId); + const { fee: fee2, poolEarnedRewardsEvents } = await payToMakerAsync(poolMaker); + expect(poolEarnedRewardsEvents).to.deep.eq([]); + const actualPoolStats = await testContract.getStakingPoolStatsThisEpoch.callAsync(poolId); const expectedWeightedStake = toWeightedStake(pool.operatorStake, pool.membersStake); const fees = BigNumber.sum(fee1, fee2); - expect(actualPool.feesCollected).to.bignumber.eq(fees); - expect(actualPool.membersStake).to.bignumber.eq(pool.membersStake); - expect(actualPool.weightedStake).to.bignumber.eq(expectedWeightedStake); + expect(actualPoolStats.feesCollected).to.bignumber.eq(fees); + expect(actualPoolStats.membersStake).to.bignumber.eq(pool.membersStake); + expect(actualPoolStats.weightedStake).to.bignumber.eq(expectedWeightedStake); const state = await getFinalizationStateAsync(); - expect(state.numActivePools).to.bignumber.eq(1); + expect(state.numPoolsToFinalize).to.bignumber.eq(1); expect(state.totalFeesCollected).to.bignumber.eq(fees); expect(state.totalWeightedStake).to.bignumber.eq(expectedWeightedStake); }); @@ -477,19 +478,19 @@ blockchainTests('Protocol Fees unit tests', env => { poolId, makers: [poolMaker], } = pool; - const { fee, poolActivatedEvents } = await payToMakerAsync(poolMaker); - expect(poolActivatedEvents.length).to.eq(1); - expect(poolActivatedEvents[0].poolId).to.eq(poolId); - const actualPool = await testContract.getActiveStakingPoolThisEpoch.callAsync(poolId); + const { fee, poolEarnedRewardsEvents } = await payToMakerAsync(poolMaker); + expect(poolEarnedRewardsEvents.length).to.eq(1); + expect(poolEarnedRewardsEvents[0].poolId).to.eq(poolId); + const actualPoolStats = await testContract.getStakingPoolStatsThisEpoch.callAsync(poolId); const expectedWeightedStake = toWeightedStake(pool.operatorStake, pool.membersStake); - expect(actualPool.feesCollected).to.bignumber.eq(fee); - expect(actualPool.membersStake).to.bignumber.eq(pool.membersStake); - expect(actualPool.weightedStake).to.bignumber.eq(expectedWeightedStake); + expect(actualPoolStats.feesCollected).to.bignumber.eq(fee); + expect(actualPoolStats.membersStake).to.bignumber.eq(pool.membersStake); + expect(actualPoolStats.weightedStake).to.bignumber.eq(expectedWeightedStake); totalFees = totalFees.plus(fee); totalWeightedStake = totalWeightedStake.plus(expectedWeightedStake); } const state = await getFinalizationStateAsync(); - expect(state.numActivePools).to.bignumber.eq(pools.length); + expect(state.numPoolsToFinalize).to.bignumber.eq(pools.length); expect(state.totalFeesCollected).to.bignumber.eq(totalFees); expect(state.totalWeightedStake).to.bignumber.eq(totalWeightedStake); }); @@ -502,10 +503,10 @@ blockchainTests('Protocol Fees unit tests', env => { } = pool; await payToMakerAsync(poolMaker); await testContract.advanceEpoch.awaitTransactionSuccessAsync(); - const actualPool = await testContract.getActiveStakingPoolThisEpoch.callAsync(poolId); - expect(actualPool.feesCollected).to.bignumber.eq(0); - expect(actualPool.membersStake).to.bignumber.eq(0); - expect(actualPool.weightedStake).to.bignumber.eq(0); + const actualPoolStats = await testContract.getStakingPoolStatsThisEpoch.callAsync(poolId); + expect(actualPoolStats.feesCollected).to.bignumber.eq(0); + expect(actualPoolStats.membersStake).to.bignumber.eq(0); + expect(actualPoolStats.weightedStake).to.bignumber.eq(0); }); describe('Multiple makers', () => { diff --git a/contracts/staking/test/unit_tests/stake_test.ts b/contracts/staking/test/unit_tests/stake_test.ts new file mode 100644 index 0000000000..a4b84fd251 --- /dev/null +++ b/contracts/staking/test/unit_tests/stake_test.ts @@ -0,0 +1,450 @@ +import { + blockchainTests, + expect, + filterLogs, + filterLogsToArguments, + getRandomInteger, + hexLeftPad, + hexRandom, + Numberish, + shortZip, +} from '@0x/contracts-test-utils'; +import { StakingRevertErrors } from '@0x/order-utils'; +import { BigNumber } from '@0x/utils'; +import * as _ from 'lodash'; + +import { StakeStatus } from '../utils/types'; + +import { + artifacts, + TestMixinStakeContract, + TestMixinStakeDecreaseCurrentAndNextBalanceEventArgs as DecreaseCurrentAndNextBalanceEventArgs, + TestMixinStakeDecreaseNextBalanceEventArgs as DecreaseNextBalanceEventArgs, + TestMixinStakeEvents as StakeEvents, + TestMixinStakeIncreaseCurrentAndNextBalanceEventArgs as IncreaseCurrentAndNextBalanceEventArgs, + TestMixinStakeIncreaseNextBalanceEventArgs as IncreaseNextBalanceEventArgs, + TestMixinStakeMoveStakeEventArgs as MoveStakeEventArgs, + TestMixinStakeMoveStakeStorageEventArgs as MoveStakeStorageEventArgs, + TestMixinStakeStakeEventArgs as StakeEventArgs, + TestMixinStakeUnstakeEventArgs as UnstakeEventArgs, + TestMixinStakeWithdrawAndSyncDelegatorRewardsEventArgs as WithdrawAndSyncDelegatorRewardsEventArgs, + TestMixinStakeZrxVaultDepositFromEventArgs as ZrxVaultDepositFromEventArgs, + TestMixinStakeZrxVaultWithdrawFromEventArgs as ZrxVaultWithdrawFromEventArgs, +} from '../../src'; + +blockchainTests.resets('MixinStake unit tests', env => { + let testContract: TestMixinStakeContract; + let staker: string; + let stakerUndelegatedStakeSlot: string; + let currentEpoch: BigNumber; + + before(async () => { + [staker] = await env.getAccountAddressesAsync(); + testContract = await TestMixinStakeContract.deployFrom0xArtifactAsync( + artifacts.TestMixinStake, + env.provider, + env.txDefaults, + artifacts, + ); + currentEpoch = await testContract.currentEpoch.callAsync(); + stakerUndelegatedStakeSlot = await testContract.getOwnerStakeByStatusSlot.callAsync( + staker, + StakeStatus.Undelegated, + ); + }); + + describe('stake()', () => { + it('deposits funds into the ZRX vault', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.stake.awaitTransactionSuccessAsync(amount); + const events = filterLogsToArguments(logs, StakeEvents.ZrxVaultDepositFrom); + expect(events).to.be.length(1); + expect(events[0].staker).to.eq(staker); + expect(events[0].amount).to.bignumber.eq(amount); + }); + + it('increases current and next undelegated stake balance', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.stake.awaitTransactionSuccessAsync(amount); + const events = filterLogsToArguments( + logs, + StakeEvents.IncreaseCurrentAndNextBalance, + ); + expect(events).to.be.length(1); + expect(events[0].balanceSlot).to.eq(stakerUndelegatedStakeSlot); + expect(events[0].amount).to.bignumber.eq(amount); + }); + + it('raises a `Stake` event', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.stake.awaitTransactionSuccessAsync(amount); + const events = filterLogsToArguments(logs, StakeEvents.Stake); + expect(events).to.be.length(1); + expect(events[0].staker).to.eq(staker); + expect(events[0].amount).to.bignumber.eq(amount); + }); + }); + + describe('unstake()', () => { + async function setUndelegatedStakeAsync( + currentEpochBalance: Numberish, + nextEpochBalance: Numberish, + ): Promise { + await testContract.setOwnerStakeByStatus.awaitTransactionSuccessAsync(staker, StakeStatus.Undelegated, { + currentEpoch, + currentEpochBalance: new BigNumber(currentEpochBalance), + nextEpochBalance: new BigNumber(nextEpochBalance), + }); + } + + it('throws if not enough undelegated stake in the current epoch', async () => { + const amount = getRandomInteger(0, 100e18); + await setUndelegatedStakeAsync(amount.minus(1), amount); + const tx = testContract.unstake.awaitTransactionSuccessAsync(amount); + const expectedError = new StakingRevertErrors.InsufficientBalanceError(amount, amount.minus(1)); + return expect(tx).to.revertWith(expectedError); + }); + + it('throws if not enough undelegated stake in the next epoch', async () => { + const amount = getRandomInteger(0, 100e18); + await setUndelegatedStakeAsync(amount, amount.minus(1)); + const tx = testContract.unstake.awaitTransactionSuccessAsync(amount); + const expectedError = new StakingRevertErrors.InsufficientBalanceError(amount, amount.minus(1)); + return expect(tx).to.revertWith(expectedError); + }); + + it('throws if not enough undelegated stake in both epochs', async () => { + const amount = getRandomInteger(0, 100e18); + await setUndelegatedStakeAsync(amount.minus(1), amount.minus(1)); + const tx = testContract.unstake.awaitTransactionSuccessAsync(amount); + const expectedError = new StakingRevertErrors.InsufficientBalanceError(amount, amount.minus(1)); + return expect(tx).to.revertWith(expectedError); + }); + + it('decreases current and next undelegated stake balance', async () => { + const amount = getRandomInteger(0, 100e18); + await setUndelegatedStakeAsync(amount, amount); + const { logs } = await testContract.unstake.awaitTransactionSuccessAsync(amount); + const events = filterLogsToArguments( + logs, + StakeEvents.DecreaseCurrentAndNextBalance, + ); + expect(events).to.be.length(1); + expect(events[0].balanceSlot).to.eq(stakerUndelegatedStakeSlot); + expect(events[0].amount).to.bignumber.eq(amount); + }); + + it('withdraws funds from the ZRX vault', async () => { + const amount = getRandomInteger(0, 100e18); + await setUndelegatedStakeAsync(amount, amount); + const { logs } = await testContract.unstake.awaitTransactionSuccessAsync(amount); + const events = filterLogsToArguments(logs, StakeEvents.ZrxVaultWithdrawFrom); + expect(events).to.be.length(1); + expect(events[0].staker).to.eq(staker); + expect(events[0].amount).to.bignumber.eq(amount); + }); + + it('emits an `Unstake` event', async () => { + const amount = getRandomInteger(0, 100e18); + await setUndelegatedStakeAsync(amount, amount); + const { logs } = await testContract.unstake.awaitTransactionSuccessAsync(amount); + const events = filterLogsToArguments(logs, StakeEvents.Unstake); + expect(events).to.be.length(1); + expect(events[0].staker).to.eq(staker); + expect(events[0].amount).to.bignumber.eq(amount); + }); + }); + + describe('moveStake()', () => { + const INVALID_POOL_ERROR = 'INVALID_POOL'; + const INVALID_POOL_ID = hexLeftPad(0); + const VALID_POOL_IDS = [hexRandom(), hexRandom()]; + let delegatedStakeToPoolByOwnerSlots: string[]; + let delegatedStakeByPoolIdSlots: string[]; + let globalDelegatedStakeSlot: string; + let stakerDelegatedStakeSlot: string; + + before(async () => { + delegatedStakeToPoolByOwnerSlots = await Promise.all( + VALID_POOL_IDS.map(async poolId => + testContract.getDelegatedStakeToPoolByOwnerSlot.callAsync(poolId, staker), + ), + ); + delegatedStakeByPoolIdSlots = await Promise.all( + VALID_POOL_IDS.map(async poolId => testContract.getDelegatedStakeByPoolIdSlot.callAsync(poolId)), + ); + globalDelegatedStakeSlot = await testContract.getGlobalStakeByStatusSlot.callAsync(StakeStatus.Delegated); + stakerDelegatedStakeSlot = await testContract.getOwnerStakeByStatusSlot.callAsync( + staker, + StakeStatus.Delegated, + ); + }); + + it('throws if the "from" pool is invalid', async () => { + const tx = testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: INVALID_POOL_ID }, + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] }, + getRandomInteger(0, 100e18), + ); + return expect(tx).to.revertWith(INVALID_POOL_ERROR); + }); + + it('throws if the "to" pool is invalid', async () => { + const tx = testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Delegated, poolId: INVALID_POOL_ID }, + getRandomInteger(0, 100e18), + ); + return expect(tx).to.revertWith(INVALID_POOL_ERROR); + }); + + it('throws if the "from" and "to" pools are invalid', async () => { + const tx = testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: INVALID_POOL_ID }, + { status: StakeStatus.Delegated, poolId: INVALID_POOL_ID }, + getRandomInteger(0, 100e18), + ); + return expect(tx).to.revertWith(INVALID_POOL_ERROR); + }); + + it('withdraws delegator rewards when "from" stake is delegated', async () => { + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[1] }, + getRandomInteger(0, 100e18), + ); + const events = filterLogsToArguments( + logs, + StakeEvents.WithdrawAndSyncDelegatorRewards, + ); + expect(events).to.be.length(1); + expect(events[0].poolId).to.eq(VALID_POOL_IDS[0]); + expect(events[0].delegator).to.eq(staker); + }); + + it('withdraws delegator rewards when "to" stake is delegated', async () => { + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[1] }, + getRandomInteger(0, 100e18), + ); + const events = filterLogsToArguments( + logs, + StakeEvents.WithdrawAndSyncDelegatorRewards, + ); + expect(events).to.be.length(1); + expect(events[0].poolId).to.eq(VALID_POOL_IDS[1]); + expect(events[0].delegator).to.eq(staker); + }); + + it('withdraws delegator rewards when both stakes are both delegated', async () => { + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[1] }, + getRandomInteger(0, 100e18), + ); + const events = filterLogsToArguments( + logs, + StakeEvents.WithdrawAndSyncDelegatorRewards, + ); + expect(events).to.be.length(2); + for (const [event, poolId] of shortZip(events, VALID_POOL_IDS)) { + expect(event.poolId).to.eq(poolId); + expect(event.delegator).to.eq(staker); + } + }); + + it('does not withdraw delegator rewards when both stakes are both undelegated', async () => { + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[1] }, + getRandomInteger(0, 100e18), + ); + const events = filterLogsToArguments( + logs, + StakeEvents.WithdrawAndSyncDelegatorRewards, + ); + expect(events).to.be.length(0); + }); + + it('decreases pool and global delegated stake counters when "from" stake is delegated', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const decreaseNextBalanceEvents = filterLogsToArguments( + logs, + StakeEvents.DecreaseNextBalance, + ); + const counters = [ + delegatedStakeToPoolByOwnerSlots[0], + delegatedStakeByPoolIdSlots[0], + globalDelegatedStakeSlot, + ]; + expect(decreaseNextBalanceEvents).to.be.length(3); + for (const [event, slot] of shortZip(decreaseNextBalanceEvents, counters)) { + expect(event.balanceSlot).to.eq(slot); + expect(event.amount).to.bignumber.eq(amount); + } + }); + + it('increases pool and global delegated stake counters when "to" stake is delegated', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const increaseNextBalanceEvents = filterLogsToArguments( + logs, + StakeEvents.IncreaseNextBalance, + ); + const counters = [ + delegatedStakeToPoolByOwnerSlots[1], + delegatedStakeByPoolIdSlots[1], + globalDelegatedStakeSlot, + ]; + expect(increaseNextBalanceEvents).to.be.length(3); + for (const [event, slot] of shortZip(increaseNextBalanceEvents, counters)) { + expect(event.balanceSlot).to.eq(slot); + expect(event.amount).to.bignumber.eq(amount); + } + }); + + it('decreases then increases pool and global delegated stake counters when both stakes are delegated', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const decreaseNextBalanceEvents = filterLogs( + logs, + StakeEvents.DecreaseNextBalance, + ); + const increaseNextBalanceEvents = filterLogs( + logs, + StakeEvents.IncreaseNextBalance, + ); + const decreaseCounters = [ + delegatedStakeToPoolByOwnerSlots[0], + delegatedStakeByPoolIdSlots[0], + globalDelegatedStakeSlot, + ]; + expect(decreaseNextBalanceEvents).to.be.length(3); + for (const [event, slot] of shortZip(decreaseNextBalanceEvents, decreaseCounters)) { + expect(event.args.balanceSlot).to.eq(slot); + expect(event.args.amount).to.bignumber.eq(amount); + } + const increaseCounters = [ + delegatedStakeToPoolByOwnerSlots[1], + delegatedStakeByPoolIdSlots[1], + globalDelegatedStakeSlot, + ]; + expect(increaseNextBalanceEvents).to.be.length(3); + for (const [event, slot] of shortZip(increaseNextBalanceEvents, increaseCounters)) { + expect(event.args.balanceSlot).to.eq(slot); + expect(event.args.amount).to.bignumber.eq(amount); + } + // Check that all decreases occur before the increases. + const maxDecreaseIndex = _.max(decreaseNextBalanceEvents.map(e => e.logIndex)) as number; + const maxIncreaseIndex = _.max(increaseNextBalanceEvents.map(e => e.logIndex)) as number; + expect(maxDecreaseIndex).to.be.lt(maxIncreaseIndex); + }); + + it('does not change pool and global delegated stake counters when both stakes are undelegated', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const decreaseNextBalanceEvents = filterLogsToArguments( + logs, + StakeEvents.DecreaseNextBalance, + ); + const increaseNextBalanceEvents = filterLogsToArguments( + logs, + StakeEvents.IncreaseNextBalance, + ); + expect(decreaseNextBalanceEvents).to.be.length(0); + expect(increaseNextBalanceEvents).to.be.length(0); + }); + + it('moves the owner stake between the same pointer when both are undelegated', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const events = filterLogsToArguments(logs, StakeEvents.MoveStakeStorage); + expect(events).to.be.length(1); + expect(events[0].fromBalanceSlot).to.eq(stakerUndelegatedStakeSlot); + expect(events[0].toBalanceSlot).to.eq(stakerUndelegatedStakeSlot); + expect(events[0].amount).to.bignumber.eq(amount); + }); + + it('moves the owner stake between the same pointer when both are delegated', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const events = filterLogsToArguments(logs, StakeEvents.MoveStakeStorage); + expect(events).to.be.length(1); + expect(events[0].fromBalanceSlot).to.eq(stakerDelegatedStakeSlot); + expect(events[0].toBalanceSlot).to.eq(stakerDelegatedStakeSlot); + expect(events[0].amount).to.bignumber.eq(amount); + }); + + it('moves the owner stake between different pointers when "from" is undelegated and "to" is delegated', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const events = filterLogsToArguments(logs, StakeEvents.MoveStakeStorage); + expect(events).to.be.length(1); + expect(events[0].fromBalanceSlot).to.eq(stakerUndelegatedStakeSlot); + expect(events[0].toBalanceSlot).to.eq(stakerDelegatedStakeSlot); + expect(events[0].amount).to.bignumber.eq(amount); + }); + + it('moves the owner stake between different pointers when "from" is delegated and "to" is undelegated', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const events = filterLogsToArguments(logs, StakeEvents.MoveStakeStorage); + expect(events).to.be.length(1); + expect(events[0].fromBalanceSlot).to.eq(stakerDelegatedStakeSlot); + expect(events[0].toBalanceSlot).to.eq(stakerUndelegatedStakeSlot); + expect(events[0].amount).to.bignumber.eq(amount); + }); + + it('emits a `MoveStake` event', async () => { + const amount = getRandomInteger(0, 100e18); + const { logs } = await testContract.moveStake.awaitTransactionSuccessAsync( + { status: StakeStatus.Undelegated, poolId: VALID_POOL_IDS[0] }, + { status: StakeStatus.Delegated, poolId: VALID_POOL_IDS[1] }, + amount, + ); + const events = filterLogsToArguments(logs, StakeEvents.MoveStake); + expect(events).to.be.length(1); + expect(events[0].staker).to.eq(staker); + expect(events[0].amount).to.bignumber.eq(amount); + expect(events[0].fromStatus).to.eq(StakeStatus.Undelegated); + expect(events[0].toStatus).to.eq(StakeStatus.Delegated); + expect(events[0].fromPool).to.eq(VALID_POOL_IDS[0]); + expect(events[0].toPool).to.eq(VALID_POOL_IDS[1]); + }); + }); +}); +// tslint:disable: max-file-line-count diff --git a/contracts/staking/test/utils/api_wrapper.ts b/contracts/staking/test/utils/api_wrapper.ts index b2a9726275..62974b51db 100644 --- a/contracts/staking/test/utils/api_wrapper.ts +++ b/contracts/staking/test/utils/api_wrapper.ts @@ -9,7 +9,7 @@ import * as _ from 'lodash'; import { artifacts, IStakingEventsEpochEndedEventArgs, - IStakingEventsStakingPoolActivatedEventArgs, + IStakingEventsStakingPoolEarnedRewardsInEpochEventArgs, ReadOnlyProxyContract, StakingProxyContract, TestCobbDouglasContract, @@ -76,13 +76,13 @@ export class StakingApiWrapper { findActivePoolIdsAsync: async (epoch?: number): Promise => { const _epoch = epoch !== undefined ? epoch : await this.stakingContract.currentEpoch.callAsync(); - const events = filterLogsToArguments( + const events = filterLogsToArguments( await this.stakingContract.getLogsAsync( - TestStakingEvents.StakingPoolActivated, + TestStakingEvents.StakingPoolEarnedRewardsInEpoch, { fromBlock: BlockParamLiteral.Earliest, toBlock: BlockParamLiteral.Latest }, { epoch: new BigNumber(_epoch) }, ), - TestStakingEvents.StakingPoolActivated, + TestStakingEvents.StakingPoolEarnedRewardsInEpoch, ); return events.map(e => e.poolId); }, diff --git a/contracts/staking/test/utils/constants.ts b/contracts/staking/test/utils/constants.ts index de50d7cb21..c0528e8fce 100644 --- a/contracts/staking/test/utils/constants.ts +++ b/contracts/staking/test/utils/constants.ts @@ -9,7 +9,7 @@ export const constants = { SECOND_POOL_ID: '0x0000000000000000000000000000000000000000000000000000000000000002', NIL_POOL_ID: '0x0000000000000000000000000000000000000000000000000000000000000000', NIL_ADDRESS: '0x0000000000000000000000000000000000000000', - INITIAL_EPOCH: new BigNumber(0), + INITIAL_EPOCH: new BigNumber(1), DEFAULT_PARAMS: { epochDurationInSeconds: new BigNumber(TEN_DAYS), rewardDelegatedStakeWeight: new BigNumber(PPM * 0.9), diff --git a/contracts/staking/tsconfig.json b/contracts/staking/tsconfig.json index 69497c153e..b8371bcb1b 100644 --- a/contracts/staking/tsconfig.json +++ b/contracts/staking/tsconfig.json @@ -45,6 +45,7 @@ "generated-artifacts/TestLibProxy.json", "generated-artifacts/TestLibProxyReceiver.json", "generated-artifacts/TestLibSafeDowncast.json", + "generated-artifacts/TestMixinStake.json", "generated-artifacts/TestMixinStakeStorage.json", "generated-artifacts/TestProtocolFees.json", "generated-artifacts/TestStaking.json", diff --git a/contracts/test-utils/src/index.ts b/contracts/test-utils/src/index.ts index 68bc19c5b5..48121d3870 100644 --- a/contracts/test-utils/src/index.ts +++ b/contracts/test-utils/src/index.ts @@ -15,7 +15,7 @@ export { export { getLatestBlockTimestampAsync, increaseTimeAndMineBlockAsync } from './block_timestamp'; export { provider, txDefaults, web3Wrapper } from './web3_wrapper'; export { LogDecoder } from './log_decoder'; -export { filterLogs, filterLogsToArguments } from './log_utils'; +export { filterLogs, filterLogsToArguments, verifyEvents } from './log_utils'; export { signingUtils } from './signing_utils'; export { orderUtils } from './order_utils'; export { typeEncodingUtils } from './type_encoding_utils'; @@ -48,6 +48,7 @@ export { ERC1155Holdings, ERC1155NonFungibleHoldingsByOwner, ERC721TokenIdsByOwner, + EthBalancesByOwner, FillEventArgs, MarketBuyOrders, MarketSellOrders, diff --git a/contracts/test-utils/src/log_utils.ts b/contracts/test-utils/src/log_utils.ts index ae95ace2f8..8c09add427 100644 --- a/contracts/test-utils/src/log_utils.ts +++ b/contracts/test-utils/src/log_utils.ts @@ -1,4 +1,6 @@ -import { LogEntry, LogWithDecodedArgs } from 'ethereum-types'; +import { LogEntry, LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; + +import { expect } from './chai_setup'; // tslint:disable no-unnecessary-type-assertion @@ -15,3 +17,18 @@ export function filterLogs(logs: LogEntry[], event: string): Array(logs: LogEntry[], event: string): TEventArgs[] { return filterLogs(logs, event).map(log => log.args); } + +/** + * Verifies that a transaction emitted the expected events of a particular type. + */ +export function verifyEvents( + txReceipt: TransactionReceiptWithDecodedLogs, + expectedEvents: TEventArgs[], + eventName: string, +): void { + const logs = filterLogsToArguments(txReceipt.logs, eventName); + expect(logs.length).to.eq(expectedEvents.length); + logs.forEach((log, index) => { + expect(log).to.deep.equal(expectedEvents[index]); + }); +} diff --git a/contracts/test-utils/src/types.ts b/contracts/test-utils/src/types.ts index 98388eb60c..01b445f184 100644 --- a/contracts/test-utils/src/types.ts +++ b/contracts/test-utils/src/types.ts @@ -37,6 +37,10 @@ export interface ERC1155HoldingsByOwner { nonFungible: ERC1155NonFungibleHoldingsByOwner; } +export interface EthBalancesByOwner { + [owner: string]: BigNumber; +} + export interface SubmissionContractEventArgs { transactionId: BigNumber; } @@ -99,7 +103,7 @@ export enum ContractName { DummyERC20Token = 'DummyERC20Token', EtherToken = 'WETH9', DutchAuction = 'DutchAuction', - AssetProxyOwner = 'AssetProxyOwner', + ZeroExGovernor = 'ZeroExGovernor', AccountLevels = 'AccountLevels', EtherDelta = 'EtherDelta', Arbitrage = 'Arbitrage', @@ -150,20 +154,10 @@ export interface ERC1155Holdings { } export interface TokenBalances { - erc20: { - [owner: string]: { - [contract: string]: BigNumber; - }; - }; - erc721: { - [owner: string]: { - [contract: string]: BigNumber[]; - }; - }; + erc20: ERC20BalancesByOwner; + erc721: ERC721TokenIdsByOwner; erc1155: ERC1155Holdings; - eth: { - [owner: string]: BigNumber; - }; + eth: EthBalancesByOwner; } export interface FillEventArgs { diff --git a/contracts/tests/CHANGELOG.json b/contracts/tests/CHANGELOG.json new file mode 100644 index 0000000000..b4dd63c035 --- /dev/null +++ b/contracts/tests/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "0.0.1", + "changes": [ + { + "note": "Created package", + "pr": 2261 + } + ] + } +] diff --git a/contracts/tests/README.md b/contracts/tests/README.md new file mode 100644 index 0000000000..f55bf39be6 --- /dev/null +++ b/contracts/tests/README.md @@ -0,0 +1,75 @@ +## Tests + +This package implements unit tests against 0x's smart contracts. Its primary purpose is to help avoid circular dependencies between the contract packages. + +## Contributing + +We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository. + +For proposals regarding the 0x protocol's smart contract architecture, message format, or additional functionality, go to the [0x Improvement Proposals (ZEIPs)](https://github.com/0xProject/ZEIPs) repository and follow the contribution guidelines provided therein. + +Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. + +### Install Dependencies + +If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: + +```bash +yarn config set workspaces-experimental true +``` + +Then install dependencies + +```bash +yarn install +``` + +### Build + +To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: + +```bash +PKG=@0x/contracts-tests yarn build +``` + +Or continuously rebuild on change: + +```bash +PKG=@0x/contracts-tests yarn watch +``` + +If imports are rebuilt in their source packages, they do not need to be rebuilt here. + +Example: + +``` +// contracts/tests/test/some-new/some_new_test.ts +import { SomeNewContract } from '@0x/contracts-some-new'; + +describe('should do its thing', () => { + const contractInstance = new SomeNewContract(); + expect(contractInstance.someTruthyFunction.callAsync()).to.be.true(); +}) +``` + +Run `yarn watch` from `contracts/some-new`, and then running `yarn test` from this package should test the new changes. + +### Clean + +```bash +yarn clean +``` + +Since the purpose of this package is to test other packages, make sure you are running `yarn clean` as necessary in the imported packages as well. + +### Lint + +```bash +yarn lint +``` + +### Run Tests + +```bash +yarn test +``` diff --git a/contracts/tests/compiler.json b/contracts/tests/compiler.json new file mode 100644 index 0000000000..6b74c612c2 --- /dev/null +++ b/contracts/tests/compiler.json @@ -0,0 +1,26 @@ +{ + "artifactsDir": "./generated-artifacts", + "contractsDir": "./contracts", + "useDockerisedSolc": false, + "isOfflineMode": false, + "compilerSettings": { + "evmVersion": "constantinople", + "optimizer": { + "enabled": true, + "runs": 1000000, + "details": { "yul": true, "deduplicate": true, "cse": true, "constantOptimizer": true } + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "devdoc", + "evm.bytecode.object", + "evm.bytecode.sourceMap", + "evm.deployedBytecode.object", + "evm.deployedBytecode.sourceMap" + ] + } + } + } +} diff --git a/contracts/tests/package.json b/contracts/tests/package.json new file mode 100644 index 0000000000..061c3b5d13 --- /dev/null +++ b/contracts/tests/package.json @@ -0,0 +1,86 @@ +{ + "name": "@0x/contracts-tests", + "version": "0.0.1", + "engines": { + "node": ">=6.12" + }, + "description": "Unit tests for 0x contracts", + "main": "lib/src/index.js", + "directories": { + "test": "test" + }, + "scripts": { + "build": "tsc -b", + "build:ci": "yarn build", + "pre_build": "run-s compile contracts:gen generate_contract_wrappers", + "test": "yarn run_mocha", + "rebuild_and_test": "run-s build test", + "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", + "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", + "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", + "run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", + "compile": "sol-compiler", + "watch": "sol-compiler -w", + "clean": "shx rm -rf lib generated-artifacts generated-wrappers", + "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "coverage:report:text": "istanbul report text", + "coverage:report:html": "istanbul report html && open coverage/index.html", + "profiler:report:html": "istanbul report html && open coverage/index.html", + "coverage:report:lcov": "istanbul report lcov", + "test:circleci": "yarn test", + "contracts:gen": "contracts-gen", + "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol", + "compile:truffle": "truffle compile" + }, + "config": { + "abis": "./generated-artifacts/@().json", + "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." + }, + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x-monorepo.git" + }, + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/0xProject/0x-monorepo/issues" + }, + "homepage": "https://github.com/0xProject/0x-monorepo/contracts/tests/README.md", + "devDependencies": { + "@0x/abi-gen": "^4.3.0-beta.0", + "@0x/contracts-asset-proxy": "^2.3.0-beta.0", + "@0x/base-contract": "^5.5.0-beta.0", + "@0x/contracts-dev-utils": "^0.1.0-beta.0", + "@0x/contracts-erc1155": "^1.2.0-beta.0", + "@0x/contracts-erc20": "^2.3.0-beta.0", + "@0x/contracts-erc721": "^2.2.0-beta.0", + "@0x/contracts-exchange": "^2.2.0-beta.0", + "@0x/contracts-gen": "^1.1.0-beta.0", + "@0x/contracts-test-utils": "^3.2.0-beta.0", + "@0x/sol-compiler": "^3.2.0-beta.0", + "@0x/tslint-config": "^3.0.1", + "@0x/types": "^2.5.0-beta.0", + "@0x/typescript-typings": "^4.4.0-beta.0", + "@0x/utils": "^4.6.0-beta.0", + "@0x/web3-wrapper": "^6.1.0-beta.0", + "@types/mocha": "^5.2.7", + "@types/node": "*", + "chai": "^4.0.1", + "chai-as-promised": "^7.1.0", + "chai-bignumber": "^3.0.0", + "dirty-chai": "^2.0.1", + "ethereum-types": "^2.2.0-beta.0", + "make-promises-safe": "^1.1.0", + "mocha": "^6.2.0", + "npm-run-all": "^4.1.2", + "shx": "^0.2.2", + "solhint": "^1.4.1", + "truffle": "^5.0.32", + "tslint": "5.11.0", + "typescript": "3.0.1" + }, + "publishConfig": { + "access": "private" + } +} diff --git a/contracts/tests/src/artifacts.ts b/contracts/tests/src/artifacts.ts new file mode 100644 index 0000000000..ee78e80403 --- /dev/null +++ b/contracts/tests/src/artifacts.ts @@ -0,0 +1,8 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +import { ContractArtifact } from 'ethereum-types'; + +export const artifacts = {}; diff --git a/contracts/tests/src/index.ts b/contracts/tests/src/index.ts new file mode 100644 index 0000000000..01206c99a9 --- /dev/null +++ b/contracts/tests/src/index.ts @@ -0,0 +1 @@ +export * from './artifacts'; diff --git a/contracts/tests/src/wrappers.ts b/contracts/tests/src/wrappers.ts new file mode 100644 index 0000000000..74ff63e906 --- /dev/null +++ b/contracts/tests/src/wrappers.ts @@ -0,0 +1,5 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ diff --git a/contracts/dev-utils/test/global_hooks.ts b/contracts/tests/test/dev-utils/global_hooks.ts similarity index 100% rename from contracts/dev-utils/test/global_hooks.ts rename to contracts/tests/test/dev-utils/global_hooks.ts diff --git a/contracts/dev-utils/test/lib_asset_data.ts b/contracts/tests/test/dev-utils/lib_asset_data.ts similarity index 99% rename from contracts/dev-utils/test/lib_asset_data.ts rename to contracts/tests/test/dev-utils/lib_asset_data.ts index 3707b34280..1b1d9b6dda 100644 --- a/contracts/dev-utils/test/lib_asset_data.ts +++ b/contracts/tests/test/dev-utils/lib_asset_data.ts @@ -25,7 +25,7 @@ import { AssetProxyId } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import * as ethUtil from 'ethereumjs-util'; -import { artifacts, LibAssetDataContract } from '../src'; +import { artifacts, LibAssetDataContract } from '@0x/contracts-dev-utils'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/dev-utils/test/lib_transaction_decoder.ts b/contracts/tests/test/dev-utils/lib_transaction_decoder.ts similarity index 98% rename from contracts/dev-utils/test/lib_transaction_decoder.ts rename to contracts/tests/test/dev-utils/lib_transaction_decoder.ts index 7c4ea38894..9fe5ee13d6 100644 --- a/contracts/dev-utils/test/lib_transaction_decoder.ts +++ b/contracts/tests/test/dev-utils/lib_transaction_decoder.ts @@ -4,7 +4,7 @@ import { BlockchainLifecycle } from '@0x/dev-utils'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; -import { artifacts, LibTransactionDecoderContract } from '../src'; +import { artifacts, LibTransactionDecoderContract } from '@0x/contracts-dev-utils'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/dev-utils/test/order_validation_utils.ts b/contracts/tests/test/dev-utils/order_validation_utils.ts similarity index 99% rename from contracts/dev-utils/test/order_validation_utils.ts rename to contracts/tests/test/dev-utils/order_validation_utils.ts index 8d4087fb75..e8d2c126fd 100644 --- a/contracts/dev-utils/test/order_validation_utils.ts +++ b/contracts/tests/test/dev-utils/order_validation_utils.ts @@ -24,7 +24,7 @@ import { OrderTransferResults, SignedOrder } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import * as chai from 'chai'; -import { artifacts, DevUtilsContract } from '../src'; +import { artifacts, DevUtilsContract } from '@0x/contracts-dev-utils'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/tests/tsconfig.json b/contracts/tests/tsconfig.json new file mode 100644 index 0000000000..6d6a1bf83b --- /dev/null +++ b/contracts/tests/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true }, + "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], + "exclude": ["./lib/**/*"] +} diff --git a/contracts/utils/CHANGELOG.json b/contracts/utils/CHANGELOG.json index 5820e68076..dc3f8d93a4 100644 --- a/contracts/utils/CHANGELOG.json +++ b/contracts/utils/CHANGELOG.json @@ -65,6 +65,14 @@ { "note": "Emit an event in `transferOwnership`", "pr": 2253 + }, + { + "note": "Removed `deepCopyBytes`, `popLast20Bytes`, `readBytesWithLength`, and `writeBytesWithLength` in `LibBytes`.", + "pr": 2265 + }, + { + "note": "Replaced `SafeMath` with `LibSafeMath`", + "pr": 2254 } ], "timestamp": 1570135330 diff --git a/contracts/utils/contracts/src/LibBytes.sol b/contracts/utils/contracts/src/LibBytes.sol index e5b9cd99d9..4646d3b622 100644 --- a/contracts/utils/contracts/src/LibBytes.sol +++ b/contracts/utils/contracts/src/LibBytes.sol @@ -271,33 +271,6 @@ library LibBytes { return result; } - /// @dev Pops the last 20 bytes off of a byte array by modifying its length. - /// @param b Byte array that will be modified. - /// @return The 20 byte address that was popped off. - function popLast20Bytes(bytes memory b) - internal - pure - returns (address result) - { - if (b.length < 20) { - LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( - LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, - b.length, - 20 // 20 is length of address - )); - } - - // Store last 20 bytes. - result = readAddress(b, b.length - 20); - - assembly { - // Subtract 20 from byte array length. - let newLen := sub(mload(b), 20) - mstore(b, newLen) - } - return result; - } - /// @dev Tests equality of two byte arrays. /// @param lhs First byte array to compare. /// @param rhs Second byte array to compare. @@ -523,100 +496,6 @@ library LibBytes { return result; } - /// @dev Reads nested bytes from a specific position. - /// @dev NOTE: the returned value overlaps with the input value. - /// Both should be treated as immutable. - /// @param b Byte array containing nested bytes. - /// @param index Index of nested bytes. - /// @return result Nested bytes. - function readBytesWithLength( - bytes memory b, - uint256 index - ) - internal - pure - returns (bytes memory result) - { - // Read length of nested bytes - uint256 nestedBytesLength = readUint256(b, index); - index += 32; - - // Assert length of is valid, given - // length of nested bytes - if (b.length < index + nestedBytesLength) { - LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( - LibBytesRichErrors - .InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsNestedBytesLengthRequired, - b.length, - index + nestedBytesLength - )); - } - - // Return a pointer to the byte array as it exists inside `b` - assembly { - result := add(b, index) - } - return result; - } - - /// @dev Inserts bytes at a specific position in a byte array. - /// @param b Byte array to insert into. - /// @param index Index in byte array of . - /// @param input bytes to insert. - function writeBytesWithLength( - bytes memory b, - uint256 index, - bytes memory input - ) - internal - pure - { - // Assert length of is valid, given - // length of input - if (b.length < index + 32 + input.length) { - LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( - LibBytesRichErrors - .InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsNestedBytesLengthRequired, - b.length, - index + 32 + input.length // 32 bytes to store length - )); - } - - // Copy into - memCopy( - b.contentAddress() + index, - input.rawAddress(), // includes length of - input.length + 32 // +32 bytes to store length - ); - } - - /// @dev Performs a deep copy of a byte array onto another byte array of greater than or equal length. - /// @param dest Byte array that will be overwritten with source bytes. - /// @param source Byte array to copy onto dest bytes. - function deepCopyBytes( - bytes memory dest, - bytes memory source - ) - internal - pure - { - uint256 sourceLen = source.length; - // Dest length must be >= source length, or some bytes would not be copied. - if (dest.length < sourceLen) { - LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError( - LibBytesRichErrors - .InvalidByteOperationErrorCodes.DestinationLengthGreaterThanOrEqualSourceLengthRequired, - dest.length, - sourceLen - )); - } - memCopy( - dest.contentAddress(), - source.contentAddress(), - sourceLen - ); - } - /// @dev Writes a new length to a byte array. /// Decreasing length will lead to removing the corresponding lower order bytes from the byte array. /// Increasing length may lead to appending adjacent in-memory bytes to the end of the byte array. diff --git a/contracts/utils/contracts/src/SafeMath.sol b/contracts/utils/contracts/src/SafeMath.sol deleted file mode 100644 index bf0e95145a..0000000000 --- a/contracts/utils/contracts/src/SafeMath.sol +++ /dev/null @@ -1,90 +0,0 @@ -pragma solidity ^0.5.9; - -import "./LibRichErrors.sol"; -import "./LibSafeMathRichErrors.sol"; - - -contract SafeMath { - - function _safeMul(uint256 a, uint256 b) - internal - pure - returns (uint256) - { - if (a == 0) { - return 0; - } - uint256 c = a * b; - if (c / a != b) { - LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError( - LibSafeMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW, - a, - b - )); - } - return c; - } - - function _safeDiv(uint256 a, uint256 b) - internal - pure - returns (uint256) - { - if (b == 0) { - LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError( - LibSafeMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO, - a, - b - )); - } - uint256 c = a / b; - return c; - } - - function _safeSub(uint256 a, uint256 b) - internal - pure - returns (uint256) - { - if (b > a) { - LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError( - LibSafeMathRichErrors.BinOpErrorCodes.SUBTRACTION_UNDERFLOW, - a, - b - )); - } - return a - b; - } - - function _safeAdd(uint256 a, uint256 b) - internal - pure - returns (uint256) - { - uint256 c = a + b; - if (c < a) { - LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError( - LibSafeMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW, - a, - b - )); - } - return c; - } - - function _max256(uint256 a, uint256 b) - internal - pure - returns (uint256) - { - return a >= b ? a : b; - } - - function _min256(uint256 a, uint256 b) - internal - pure - returns (uint256) - { - return a < b ? a : b; - } -} diff --git a/contracts/utils/contracts/test/TestLibBytes.sol b/contracts/utils/contracts/test/TestLibBytes.sol index b2f39e5fcc..361b71164a 100644 --- a/contracts/utils/contracts/test/TestLibBytes.sol +++ b/contracts/utils/contracts/test/TestLibBytes.sol @@ -37,18 +37,6 @@ contract TestLibBytes { return (b, result); } - /// @dev Pops the last 20 bytes off of a byte array by modifying its length. - /// @param b Byte array that will be modified. - /// @return The 20 byte address that was popped off. - function publicPopLast20Bytes(bytes memory b) - public - pure - returns (bytes memory, address result) - { - result = b.popLast20Bytes(); - return (b, result); - } - /// @dev Tests equality of two byte arrays. /// @param lhs First byte array to compare. /// @param rhs Second byte array to compare. @@ -73,21 +61,6 @@ contract TestLibBytes { return equal; } - /// @dev Performs a deep copy of a byte array onto another byte array of greater than or equal length. - /// @param dest Byte array that will be overwritten with source bytes. - /// @param source Byte array to copy onto dest bytes. - function publicDeepCopyBytes( - bytes memory dest, - bytes memory source - ) - public - pure - returns (bytes memory) - { - LibBytes.deepCopyBytes(dest, source); - return dest; - } - /// @dev Reads an address from a position in a byte array. /// @param b Byte array containing an address. /// @param index Index in byte array of address. @@ -203,40 +176,6 @@ contract TestLibBytes { return result; } - /// @dev Reads nested bytes from a specific position. - /// @param b Byte array containing nested bytes. - /// @param index Index of nested bytes. - /// @return result Nested bytes. - function publicReadBytesWithLength( - bytes memory b, - uint256 index - ) - public - pure - returns (bytes memory result) - { - result = b.readBytesWithLength(index); - return result; - } - - /// @dev Inserts bytes at a specific position in a byte array. - /// @param b Byte array to insert into. - /// @param index Index in byte array of . - /// @param input bytes to insert. - /// @return b Updated input byte array - function publicWriteBytesWithLength( - bytes memory b, - uint256 index, - bytes memory input - ) - public - pure - returns (bytes memory) - { - b.writeBytesWithLength(index, input); - return b; - } - /// @dev Copies a block of memory from one location to another. /// @param mem Memory contents we want to apply memCopy to /// @param dest Destination offset into . @@ -305,7 +244,7 @@ contract TestLibBytes { } /// @dev Returns a byte array with an updated length. - /// @dev Writes a new length to a byte array. + /// @dev Writes a new length to a byte array. /// Decreasing length will lead to removing the corresponding lower order bytes from the byte array. /// Increasing length may lead to appending adjacent in-memory bytes to the end of the byte array. /// @param b Bytes array to write new length to. diff --git a/contracts/utils/contracts/test/TestSafeMath.sol b/contracts/utils/contracts/test/TestLibSafeMath.sol similarity index 83% rename from contracts/utils/contracts/test/TestSafeMath.sol rename to contracts/utils/contracts/test/TestLibSafeMath.sol index 36670e13af..a3ee8555c0 100644 --- a/contracts/utils/contracts/test/TestSafeMath.sol +++ b/contracts/utils/contracts/test/TestLibSafeMath.sol @@ -18,18 +18,19 @@ pragma solidity ^0.5.9; -import "../src/SafeMath.sol"; +import "../src/LibSafeMath.sol"; -contract TestSafeMath is - SafeMath -{ +contract TestLibSafeMath { + + using LibSafeMath for uint256; + function externalSafeMul(uint256 a, uint256 b) external pure returns (uint256) { - return _safeMul(a, b); + return a.safeMul(b); } function externalSafeDiv(uint256 a, uint256 b) @@ -37,7 +38,7 @@ contract TestSafeMath is pure returns (uint256) { - return _safeDiv(a, b); + return a.safeDiv(b); } function externalSafeSub(uint256 a, uint256 b) @@ -45,7 +46,7 @@ contract TestSafeMath is pure returns (uint256) { - return _safeSub(a, b); + return a.safeSub(b); } function externalSafeAdd(uint256 a, uint256 b) @@ -53,7 +54,7 @@ contract TestSafeMath is pure returns (uint256) { - return _safeAdd(a, b); + return a.safeAdd(b); } function externalMaxUint256(uint256 a, uint256 b) @@ -61,7 +62,7 @@ contract TestSafeMath is pure returns (uint256) { - return _max256(a, b); + return a.max256(b); } function externalMinUint256(uint256 a, uint256 b) @@ -69,6 +70,6 @@ contract TestSafeMath is pure returns (uint256) { - return _min256(a, b); + return a.min256(b); } } diff --git a/contracts/utils/package.json b/contracts/utils/package.json index 7f9631d7fc..a1d1f697dd 100644 --- a/contracts/utils/package.json +++ b/contracts/utils/package.json @@ -22,7 +22,7 @@ "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", @@ -36,7 +36,7 @@ }, "config": { "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", - "abis": "./generated-artifacts/@(Authorizable|IAuthorizable|IOwnable|LibAddress|LibAddressArray|LibAddressArrayRichErrors|LibAuthorizableRichErrors|LibBytes|LibBytesRichErrors|LibEIP1271|LibEIP712|LibFractions|LibOwnableRichErrors|LibReentrancyGuardRichErrors|LibRichErrors|LibSafeMath|LibSafeMathRichErrors|Ownable|ReentrancyGuard|Refundable|SafeMath|TestLibAddress|TestLibAddressArray|TestLibBytes|TestLibEIP712|TestLibRichErrors|TestLogDecoding|TestLogDecodingDownstream|TestOwnable|TestReentrancyGuard|TestRefundable|TestRefundableReceiver|TestSafeMath).json" + "abis": "./generated-artifacts/@(Authorizable|IAuthorizable|IOwnable|LibAddress|LibAddressArray|LibAddressArrayRichErrors|LibAuthorizableRichErrors|LibBytes|LibBytesRichErrors|LibEIP1271|LibEIP712|LibFractions|LibOwnableRichErrors|LibReentrancyGuardRichErrors|LibRichErrors|LibSafeMath|LibSafeMathRichErrors|Ownable|ReentrancyGuard|Refundable|TestLibAddress|TestLibAddressArray|TestLibBytes|TestLibEIP712|TestLibRichErrors|TestLibSafeMath|TestLogDecoding|TestLogDecodingDownstream|TestOwnable|TestReentrancyGuard|TestRefundable|TestRefundableReceiver).json" }, "repository": { "type": "git", diff --git a/contracts/utils/src/artifacts.ts b/contracts/utils/src/artifacts.ts index 47a2d61628..983f2951ed 100644 --- a/contracts/utils/src/artifacts.ts +++ b/contracts/utils/src/artifacts.ts @@ -25,19 +25,18 @@ import * as LibSafeMathRichErrors from '../generated-artifacts/LibSafeMathRichEr import * as Ownable from '../generated-artifacts/Ownable.json'; import * as ReentrancyGuard from '../generated-artifacts/ReentrancyGuard.json'; import * as Refundable from '../generated-artifacts/Refundable.json'; -import * as SafeMath from '../generated-artifacts/SafeMath.json'; import * as TestLibAddress from '../generated-artifacts/TestLibAddress.json'; import * as TestLibAddressArray from '../generated-artifacts/TestLibAddressArray.json'; import * as TestLibBytes from '../generated-artifacts/TestLibBytes.json'; import * as TestLibEIP712 from '../generated-artifacts/TestLibEIP712.json'; import * as TestLibRichErrors from '../generated-artifacts/TestLibRichErrors.json'; +import * as TestLibSafeMath from '../generated-artifacts/TestLibSafeMath.json'; import * as TestLogDecoding from '../generated-artifacts/TestLogDecoding.json'; import * as TestLogDecodingDownstream from '../generated-artifacts/TestLogDecodingDownstream.json'; import * as TestOwnable from '../generated-artifacts/TestOwnable.json'; import * as TestReentrancyGuard from '../generated-artifacts/TestReentrancyGuard.json'; import * as TestRefundable from '../generated-artifacts/TestRefundable.json'; import * as TestRefundableReceiver from '../generated-artifacts/TestRefundableReceiver.json'; -import * as TestSafeMath from '../generated-artifacts/TestSafeMath.json'; export const artifacts = { Authorizable: Authorizable as ContractArtifact, LibAddress: LibAddress as ContractArtifact, @@ -57,7 +56,6 @@ export const artifacts = { Ownable: Ownable as ContractArtifact, ReentrancyGuard: ReentrancyGuard as ContractArtifact, Refundable: Refundable as ContractArtifact, - SafeMath: SafeMath as ContractArtifact, IAuthorizable: IAuthorizable as ContractArtifact, IOwnable: IOwnable as ContractArtifact, TestLibAddress: TestLibAddress as ContractArtifact, @@ -65,11 +63,11 @@ export const artifacts = { TestLibBytes: TestLibBytes as ContractArtifact, TestLibEIP712: TestLibEIP712 as ContractArtifact, TestLibRichErrors: TestLibRichErrors as ContractArtifact, + TestLibSafeMath: TestLibSafeMath as ContractArtifact, TestLogDecoding: TestLogDecoding as ContractArtifact, TestLogDecodingDownstream: TestLogDecodingDownstream as ContractArtifact, TestOwnable: TestOwnable as ContractArtifact, TestReentrancyGuard: TestReentrancyGuard as ContractArtifact, TestRefundable: TestRefundable as ContractArtifact, TestRefundableReceiver: TestRefundableReceiver as ContractArtifact, - TestSafeMath: TestSafeMath as ContractArtifact, }; diff --git a/contracts/utils/src/wrappers.ts b/contracts/utils/src/wrappers.ts index 78edd2ddec..da266a03dd 100644 --- a/contracts/utils/src/wrappers.ts +++ b/contracts/utils/src/wrappers.ts @@ -23,16 +23,15 @@ export * from '../generated-wrappers/lib_safe_math_rich_errors'; export * from '../generated-wrappers/ownable'; export * from '../generated-wrappers/reentrancy_guard'; export * from '../generated-wrappers/refundable'; -export * from '../generated-wrappers/safe_math'; export * from '../generated-wrappers/test_lib_address'; export * from '../generated-wrappers/test_lib_address_array'; export * from '../generated-wrappers/test_lib_bytes'; export * from '../generated-wrappers/test_lib_e_i_p712'; export * from '../generated-wrappers/test_lib_rich_errors'; +export * from '../generated-wrappers/test_lib_safe_math'; export * from '../generated-wrappers/test_log_decoding'; export * from '../generated-wrappers/test_log_decoding_downstream'; export * from '../generated-wrappers/test_ownable'; export * from '../generated-wrappers/test_reentrancy_guard'; export * from '../generated-wrappers/test_refundable'; export * from '../generated-wrappers/test_refundable_receiver'; -export * from '../generated-wrappers/test_safe_math'; diff --git a/contracts/utils/test/authorizable.ts b/contracts/utils/test/authorizable.ts index df70f84e19..b2a1a46876 100644 --- a/contracts/utils/test/authorizable.ts +++ b/contracts/utils/test/authorizable.ts @@ -63,11 +63,7 @@ describe('Authorizable', () => { }); it('should revert if owner attempts to authorize a duplicate address', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const expectedError = new AuthorizableRevertErrors.TargetAlreadyAuthorizedError(address); const tx = authorizable.addAuthorizedAddress.sendTransactionAsync(address, { from: owner }); return expect(tx).to.revertWith(expectedError); @@ -76,27 +72,15 @@ describe('Authorizable', () => { describe('removeAuthorizedAddress', () => { it('should revert if not called by owner', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner); const tx = authorizable.removeAuthorizedAddress.sendTransactionAsync(address, { from: notOwner }); return expect(tx).to.revertWith(expectedError); }); it('should allow owner to remove an authorized address', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); + await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const isAuthorized = await authorizable.authorized.callAsync(address); expect(isAuthorized).to.be.false(); }); @@ -110,11 +94,7 @@ describe('Authorizable', () => { describe('removeAuthorizedAddressAtIndex', () => { it('should revert if not called by owner', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const index = new BigNumber(0); const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner); const tx = authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, { @@ -124,11 +104,7 @@ describe('Authorizable', () => { }); it('should revert if index is >= authorities.length', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const index = new BigNumber(1); const expectedError = new AuthorizableRevertErrors.IndexOutOfBoundsError(index, index); const tx = authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, { @@ -149,16 +125,8 @@ describe('Authorizable', () => { it('should revert if address at index does not match target', async () => { const address1 = address; const address2 = notOwner; - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address1, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address2, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address1, { from: owner }); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address2, { from: owner }); const address1Index = new BigNumber(0); const expectedError = new AuthorizableRevertErrors.AuthorizedAddressMismatchError(address1, address2); const tx = authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address2, address1Index, { @@ -168,18 +136,11 @@ describe('Authorizable', () => { }); it('should allow owner to remove an authorized address', async () => { - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const index = new BigNumber(0); - await authorizable.removeAuthorizedAddressAtIndex.awaitTransactionSuccessAsync( - address, - index, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.removeAuthorizedAddressAtIndex.awaitTransactionSuccessAsync(address, index, { + from: owner, + }); const isAuthorized = await authorizable.authorized.callAsync(address); expect(isAuthorized).to.be.false(); }); @@ -189,19 +150,11 @@ describe('Authorizable', () => { it('should return all authorized addresses', async () => { const initial = await authorizable.getAuthorizedAddresses.callAsync(); expect(initial).to.have.length(0); - await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.addAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const afterAdd = await authorizable.getAuthorizedAddresses.callAsync(); expect(afterAdd).to.have.length(1); expect(afterAdd).to.include(address); - await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync( - address, - { from: owner }, - constants.AWAIT_TRANSACTION_MINED_MS, - ); + await authorizable.removeAuthorizedAddress.awaitTransactionSuccessAsync(address, { from: owner }); const afterRemove = await authorizable.getAuthorizedAddresses.callAsync(); expect(afterRemove).to.have.length(0); }); diff --git a/contracts/utils/test/lib_bytes.ts b/contracts/utils/test/lib_bytes.ts index b7e90e2487..541ea43dff 100644 --- a/contracts/utils/test/lib_bytes.ts +++ b/contracts/utils/test/lib_bytes.ts @@ -1,25 +1,18 @@ -import { chaiSetup, constants, provider, txDefaults, typeEncodingUtils, web3Wrapper } from '@0x/contracts-test-utils'; -import { BlockchainLifecycle } from '@0x/dev-utils'; -import { generatePseudoRandomSalt } from '@0x/order-utils'; +import { blockchainTests, constants, expect } from '@0x/contracts-test-utils'; import { BigNumber, LibBytesRevertErrors } from '@0x/utils'; import BN = require('bn.js'); -import * as chai from 'chai'; -import ethUtil = require('ethereumjs-util'); +import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; import { artifacts, TestLibBytesContract } from '../src'; -chaiSetup.configure(); -const expect = chai.expect; -const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); - // BUG: Ideally we would use fromHex(memory).toString('hex') // https://github.com/Microsoft/TypeScript/issues/23155 const toHex = (buf: Uint8Array): string => buf.reduce((a, v) => a + `00${v.toString(16)}`.slice(-2), '0x'); const fromHex = (str: string): Uint8Array => Uint8Array.from(Buffer.from(str.slice(2), 'hex')); -describe('LibBytes', () => { +blockchainTests('LibBytes', env => { let libBytes: TestLibBytesContract; const byteArrayShorterThan32Bytes = '0x012345'; const byteArrayShorterThan20Bytes = byteArrayShorterThan32Bytes; @@ -37,32 +30,17 @@ describe('LibBytes', () => { const testUint256B = new BigNumber(testBytes32B, 16); const testBytes4 = '0xabcdef12'; const testByte = '0xab'; - let shortData: string; - let shortTestBytes: string; - let shortTestBytesAsBuffer: Buffer; - let wordOfData: string; - let wordOfTestBytes: string; - let wordOfTestBytesAsBuffer: Buffer; - let longData: string; - let longTestBytes: string; - let longTestBytesAsBuffer: Buffer; - before(async () => { - await blockchainLifecycle.startAsync(); - }); - after(async () => { - await blockchainLifecycle.revertAsync(); - }); before(async () => { // Setup accounts & addresses - const accounts = await web3Wrapper.getAvailableAddressesAsync(); + const accounts = await env.getAccountAddressesAsync(); testAddress = accounts[1]; testAddressB = accounts[2]; // Deploy LibBytes libBytes = await TestLibBytesContract.deployFrom0xArtifactAsync( artifacts.TestLibBytes, - provider, - txDefaults, + env.provider, + env.txDefaults, artifacts, ); // Verify lengths of test data @@ -72,32 +50,6 @@ describe('LibBytes', () => { expect(byteArrayLongerThan32BytesLength).to.be.greaterThan(32); const testBytes32Length = ethUtil.toBuffer(testBytes32).byteLength; expect(testBytes32Length).to.be.equal(32); - // Create short test bytes - shortData = '0xffffaa'; - const encodedShortData = ethUtil.toBuffer(shortData); - const shortDataLength = new BigNumber(encodedShortData.byteLength); - const encodedShortDataLength = typeEncodingUtils.encodeUint256(shortDataLength); - shortTestBytesAsBuffer = Buffer.concat([encodedShortDataLength, encodedShortData]); - shortTestBytes = ethUtil.bufferToHex(shortTestBytesAsBuffer); - // Create test bytes one word in length - wordOfData = ethUtil.bufferToHex(typeEncodingUtils.encodeUint256(generatePseudoRandomSalt())); - const encodedWordOfData = ethUtil.toBuffer(wordOfData); - const wordOfDataLength = new BigNumber(encodedWordOfData.byteLength); - const encodedWordOfDataLength = typeEncodingUtils.encodeUint256(wordOfDataLength); - wordOfTestBytesAsBuffer = Buffer.concat([encodedWordOfDataLength, encodedWordOfData]); - wordOfTestBytes = ethUtil.bufferToHex(wordOfTestBytesAsBuffer); - // Create long test bytes (combines short test bytes with word of test bytes) - longData = ethUtil.bufferToHex(Buffer.concat([encodedShortData, encodedWordOfData])); - const longDataLength = new BigNumber(encodedShortData.byteLength + encodedWordOfData.byteLength); - const encodedLongDataLength = typeEncodingUtils.encodeUint256(longDataLength); - longTestBytesAsBuffer = Buffer.concat([encodedLongDataLength, encodedShortData, encodedWordOfData]); - longTestBytes = ethUtil.bufferToHex(longTestBytesAsBuffer); - }); - beforeEach(async () => { - await blockchainLifecycle.startAsync(); - }); - afterEach(async () => { - await blockchainLifecycle.revertAsync(); }); describe('popLastByte', () => { @@ -124,34 +76,6 @@ describe('LibBytes', () => { }); }); - describe('popLast20Bytes', () => { - it('should revert if length is less than 20', async () => { - const byteLen = fromHex(byteArrayShorterThan20Bytes).length; - const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( - LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, - new BigNumber(byteLen), // length of byteArrayShorterThan20Byte - new BigNumber(20), - ); - return expect(libBytes.publicPopLast20Bytes.callAsync(byteArrayShorterThan20Bytes)).to.revertWith( - expectedError, - ); - }); - it('should pop the last 20 bytes from the input and return it when array holds more than 20 bytes', async () => { - const [newBytes, poppedAddress] = await libBytes.publicPopLast20Bytes.callAsync(byteArrayLongerThan32Bytes); - const expectedNewBytes = byteArrayLongerThan32Bytes.slice(0, -40); - const expectedPoppedAddress = `0x${byteArrayLongerThan32Bytes.slice(-40)}`; - expect(newBytes).to.equal(expectedNewBytes); - expect(poppedAddress).to.equal(expectedPoppedAddress); - }); - it('should pop the last 20 bytes from the input and return it when array is exactly 20 bytes', async () => { - const [newBytes, poppedAddress] = await libBytes.publicPopLast20Bytes.callAsync(testAddress); - const expectedNewBytes = '0x'; - const expectedPoppedAddress = testAddress; - expect(newBytes).to.equal(expectedNewBytes); - expect(poppedAddress).to.equal(expectedPoppedAddress); - }); - }); - describe('equals', () => { it('should return true if byte arrays are equal (both arrays < 32 bytes)', async () => { const isEqual = await libBytes.publicEquals.callAsync( @@ -204,48 +128,6 @@ describe('LibBytes', () => { }); }); - describe('deepCopyBytes', () => { - it('should revert if dest is shorter than source', async () => { - const endpointByteLen = (byteArrayShorterThan20Bytes.length - 2) / 2; - const requiredByteLen = (byteArrayLongerThan32Bytes.length - 2) / 2; - const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( - LibBytesRevertErrors.InvalidByteOperationErrorCodes.DestinationLengthGreaterThanOrEqualSourceLengthRequired, - new BigNumber(endpointByteLen), // length of byteArrayShorterThan20Byte - new BigNumber(requiredByteLen), // length of byteArrayShorterThan20Byte - ); - return expect( - libBytes.publicDeepCopyBytes.callAsync(byteArrayShorterThan32Bytes, byteArrayLongerThan32Bytes), - ).to.revertWith(expectedError); - }); - it('should overwrite dest with source if source and dest have equal length', async () => { - const zeroedByteArrayLongerThan32Bytes = `0x${_.repeat('0', byteArrayLongerThan32Bytes.length - 2)}`; - const zeroedBytesAfterCopy = await libBytes.publicDeepCopyBytes.callAsync( - zeroedByteArrayLongerThan32Bytes, - byteArrayLongerThan32Bytes, - ); - return expect(zeroedBytesAfterCopy).to.be.equal(byteArrayLongerThan32Bytes); - }); - it('should overwrite the leftmost len(source) bytes of dest if dest is larger than source', async () => { - const zeroedByteArrayLongerThan32Bytes = `0x${_.repeat('0', byteArrayLongerThan32Bytes.length * 2)}`; - const zeroedBytesAfterCopy = await libBytes.publicDeepCopyBytes.callAsync( - zeroedByteArrayLongerThan32Bytes, - byteArrayLongerThan32Bytes, - ); - const copiedBytes = zeroedBytesAfterCopy.slice(0, byteArrayLongerThan32Bytes.length); - return expect(copiedBytes).to.be.equal(byteArrayLongerThan32Bytes); - }); - it('should not overwrite the rightmost bytes of dest if dest is larger than source', async () => { - const zeroedByteArrayLongerThan32Bytes = `0x${_.repeat('0', byteArrayLongerThan32Bytes.length * 2)}`; - const zeroedBytesAfterCopy = await libBytes.publicDeepCopyBytes.callAsync( - zeroedByteArrayLongerThan32Bytes, - byteArrayLongerThan32Bytes, - ); - const expectedNotCopiedBytes = zeroedByteArrayLongerThan32Bytes.slice(byteArrayLongerThan32Bytes.length); - const notCopiedBytes = zeroedBytesAfterCopy.slice(byteArrayLongerThan32Bytes.length); - return expect(notCopiedBytes).to.be.equal(expectedNotCopiedBytes); - }); - }); - describe('readAddress', () => { it('should successfully read address when the address takes up the whole array', async () => { const byteArray = ethUtil.addHexPrefix(testAddress); @@ -576,225 +458,6 @@ describe('LibBytes', () => { }); }); - describe('readBytesWithLength', () => { - it('should successfully read short, nested array of bytes when it takes up the whole array', async () => { - const testBytesOffset = new BigNumber(0); - const bytes = await libBytes.publicReadBytesWithLength.callAsync(shortTestBytes, testBytesOffset); - return expect(bytes).to.be.equal(shortData); - }); - it('should successfully read short, nested array of bytes when it is offset in the array', async () => { - const prefixByteArrayBuffer = ethUtil.toBuffer('0xabcdef'); - const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, shortTestBytesAsBuffer]); - const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer); - const testUint256Offset = new BigNumber(prefixByteArrayBuffer.byteLength); - const bytes = await libBytes.publicReadBytesWithLength.callAsync(combinedByteArray, testUint256Offset); - return expect(bytes).to.be.equal(shortData); - }); - it('should successfully read a nested array of bytes - one word in length - when it takes up the whole array', async () => { - const testBytesOffset = new BigNumber(0); - const bytes = await libBytes.publicReadBytesWithLength.callAsync(wordOfTestBytes, testBytesOffset); - return expect(bytes).to.be.equal(wordOfData); - }); - it('should successfully read a nested array of bytes - one word in length - when it is offset in the array', async () => { - const prefixByteArrayBuffer = ethUtil.toBuffer('0xabcdef'); - const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, wordOfTestBytesAsBuffer]); - const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer); - const testUint256Offset = new BigNumber(prefixByteArrayBuffer.byteLength); - const bytes = await libBytes.publicReadBytesWithLength.callAsync(combinedByteArray, testUint256Offset); - return expect(bytes).to.be.equal(wordOfData); - }); - it('should successfully read long, nested array of bytes when it takes up the whole array', async () => { - const testBytesOffset = new BigNumber(0); - const bytes = await libBytes.publicReadBytesWithLength.callAsync(longTestBytes, testBytesOffset); - return expect(bytes).to.be.equal(longData); - }); - it('should successfully read long, nested array of bytes when it is offset in the array', async () => { - const prefixByteArrayBuffer = ethUtil.toBuffer('0xabcdef'); - const combinedByteArrayBuffer = Buffer.concat([prefixByteArrayBuffer, longTestBytesAsBuffer]); - const combinedByteArray = ethUtil.bufferToHex(combinedByteArrayBuffer); - const testUint256Offset = new BigNumber(prefixByteArrayBuffer.byteLength); - const bytes = await libBytes.publicReadBytesWithLength.callAsync(combinedByteArray, testUint256Offset); - return expect(bytes).to.be.equal(longData); - }); - it('should fail if the byte array is too short to hold the length of a nested byte array', async () => { - // The length of the nested array is 32 bytes. By storing less than 32 bytes, a length cannot be read. - const offset = new BigNumber(0); - const byteLen = new BigNumber(fromHex(byteArrayShorterThan32Bytes).length); - const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( - LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, - byteLen, - new BigNumber(32), - ); - return expect( - libBytes.publicReadBytesWithLength.callAsync(byteArrayShorterThan32Bytes, offset), - ).to.revertWith(expectedError); - }); - it('should fail if we store a nested byte array length, without a nested byte array', async () => { - const offset = new BigNumber(0); - const byteLen = new BigNumber(fromHex(testBytes32).length); - const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( - LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsNestedBytesLengthRequired, - byteLen, - new BigNumber(testBytes32).plus(32), - ); - return expect(libBytes.publicReadBytesWithLength.callAsync(testBytes32, offset)).to.revertWith( - expectedError, - ); - }); - it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array', async () => { - const badOffset = new BigNumber(ethUtil.toBuffer(byteArrayShorterThan32Bytes).byteLength); - const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( - LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, - badOffset, - badOffset.plus(new BigNumber(32)), - ); - return expect( - libBytes.publicReadBytesWithLength.callAsync(byteArrayShorterThan32Bytes, badOffset), - ).to.revertWith(expectedError); - }); - it('should fail if the length between the offset and end of the byte array is too short to hold the nested byte array', async () => { - const badOffset = new BigNumber(ethUtil.toBuffer(testBytes32).byteLength); - const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( - LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, - badOffset, - badOffset.plus(new BigNumber(32)), - ); - return expect(libBytes.publicReadBytesWithLength.callAsync(testBytes32, badOffset)).to.revertWith( - expectedError, - ); - }); - }); - - describe('writeBytesWithLength', () => { - it('should successfully write short, nested array of bytes when it takes up the whole array', async () => { - const testBytesOffset = new BigNumber(0); - const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(shortTestBytesAsBuffer.byteLength)); - const bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync( - emptyByteArray, - testBytesOffset, - shortData, - ); - const bytesRead = await libBytes.publicReadBytesWithLength.callAsync(bytesWritten, testBytesOffset); - return expect(bytesRead).to.be.equal(shortData); - }); - it('should successfully write short, nested array of bytes when it is offset in the array', async () => { - // Write a prefix to the array - const prefixData = '0xabcdef'; - const prefixDataAsBuffer = ethUtil.toBuffer(prefixData); - const prefixOffset = new BigNumber(0); - const emptyByteArray = ethUtil.bufferToHex( - Buffer.alloc(prefixDataAsBuffer.byteLength + shortTestBytesAsBuffer.byteLength), - ); - let bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync( - emptyByteArray, - prefixOffset, - prefixData, - ); - // Write data after prefix - const testBytesOffset = new BigNumber(prefixDataAsBuffer.byteLength); - bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync( - bytesWritten, - testBytesOffset, - shortData, - ); - // Read data after prefix and validate - const bytes = await libBytes.publicReadBytesWithLength.callAsync(bytesWritten, testBytesOffset); - return expect(bytes).to.be.equal(shortData); - }); - it('should successfully write a nested array of bytes - one word in length - when it takes up the whole array', async () => { - const testBytesOffset = new BigNumber(0); - const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(wordOfTestBytesAsBuffer.byteLength)); - const bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync( - emptyByteArray, - testBytesOffset, - wordOfData, - ); - const bytesRead = await libBytes.publicReadBytesWithLength.callAsync(bytesWritten, testBytesOffset); - return expect(bytesRead).to.be.equal(wordOfData); - }); - it('should successfully write a nested array of bytes - one word in length - when it is offset in the array', async () => { - // Write a prefix to the array - const prefixData = '0xabcdef'; - const prefixDataAsBuffer = ethUtil.toBuffer(prefixData); - const prefixOffset = new BigNumber(0); - const emptyByteArray = ethUtil.bufferToHex( - Buffer.alloc(prefixDataAsBuffer.byteLength + wordOfTestBytesAsBuffer.byteLength), - ); - let bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync( - emptyByteArray, - prefixOffset, - prefixData, - ); - // Write data after prefix - const testBytesOffset = new BigNumber(prefixDataAsBuffer.byteLength); - bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync( - bytesWritten, - testBytesOffset, - wordOfData, - ); - // Read data after prefix and validate - const bytes = await libBytes.publicReadBytesWithLength.callAsync(bytesWritten, testBytesOffset); - return expect(bytes).to.be.equal(wordOfData); - }); - it('should successfully write a long, nested bytes when it takes up the whole array', async () => { - const testBytesOffset = new BigNumber(0); - const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(longTestBytesAsBuffer.byteLength)); - const bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync( - emptyByteArray, - testBytesOffset, - longData, - ); - const bytesRead = await libBytes.publicReadBytesWithLength.callAsync(bytesWritten, testBytesOffset); - return expect(bytesRead).to.be.equal(longData); - }); - it('should successfully write long, nested array of bytes when it is offset in the array', async () => { - // Write a prefix to the array - const prefixData = '0xabcdef'; - const prefixDataAsBuffer = ethUtil.toBuffer(prefixData); - const prefixOffset = new BigNumber(0); - const emptyByteArray = ethUtil.bufferToHex( - Buffer.alloc(prefixDataAsBuffer.byteLength + longTestBytesAsBuffer.byteLength), - ); - let bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync( - emptyByteArray, - prefixOffset, - prefixData, - ); - // Write data after prefix - const testBytesOffset = new BigNumber(prefixDataAsBuffer.byteLength); - bytesWritten = await libBytes.publicWriteBytesWithLength.callAsync(bytesWritten, testBytesOffset, longData); - // Read data after prefix and validate - const bytes = await libBytes.publicReadBytesWithLength.callAsync(bytesWritten, testBytesOffset); - return expect(bytes).to.be.equal(longData); - }); - it('should fail if the byte array is too short to hold the length of a nested byte array', async () => { - const offset = new BigNumber(0); - const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(1)); - const inputLen = new BigNumber((longData.length - 2) / 2); - const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( - LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsNestedBytesLengthRequired, - new BigNumber(1), - new BigNumber(32).plus(inputLen), - ); - return expect( - libBytes.publicWriteBytesWithLength.callAsync(emptyByteArray, offset, longData), - ).to.revertWith(expectedError); - }); - it('should fail if the length between the offset and end of the byte array is too short to hold the length of a nested byte array', async () => { - const emptyByteArray = ethUtil.bufferToHex(Buffer.alloc(shortTestBytesAsBuffer.byteLength)); - const badOffset = new BigNumber(ethUtil.toBuffer(shortTestBytesAsBuffer).byteLength); - const inputLen = new BigNumber((shortData.length - 2) / 2); - const expectedError = new LibBytesRevertErrors.InvalidByteOperationError( - LibBytesRevertErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsNestedBytesLengthRequired, - badOffset, - badOffset.plus(new BigNumber(32)).plus(inputLen), - ); - return expect( - libBytes.publicWriteBytesWithLength.callAsync(emptyByteArray, badOffset, shortData), - ).to.revertWith(expectedError); - }); - }); - describe('memCopy', () => { // Create memory 0x000102...FF const memSize = 256; diff --git a/contracts/utils/test/safe_math.ts b/contracts/utils/test/lib_safe_math.ts similarity index 95% rename from contracts/utils/test/safe_math.ts rename to contracts/utils/test/lib_safe_math.ts index 15590b29ff..39e1ae5d1a 100644 --- a/contracts/utils/test/safe_math.ts +++ b/contracts/utils/test/lib_safe_math.ts @@ -2,7 +2,7 @@ import { blockchainTests, constants, describe, expect } from '@0x/contracts-test import { BigNumber, SafeMathRevertErrors } from '@0x/utils'; import * as _ from 'lodash'; -import { artifacts, TestSafeMathContract } from '../src'; +import { artifacts, TestLibSafeMathContract } from '../src'; import * as ReferenceFunctions from '../src/reference_functions'; function toBigNumber(a: number | string): BigNumber { @@ -11,19 +11,19 @@ function toBigNumber(a: number | string): BigNumber { blockchainTests('SafeMath', env => { const { ONE_ETHER } = constants; - let safeMath: TestSafeMathContract; + let safeMath: TestLibSafeMathContract; before(async () => { // Deploy SafeMath - safeMath = await TestSafeMathContract.deployFrom0xArtifactAsync( - artifacts.TestSafeMath, + safeMath = await TestLibSafeMathContract.deployFrom0xArtifactAsync( + artifacts.TestLibSafeMath, env.provider, env.txDefaults, {}, ); }); - describe('_safeMul', () => { + describe('safeMul', () => { it('should match the output of the reference function', async () => { const a = ONE_ETHER; const b = ONE_ETHER.times(2); @@ -59,7 +59,7 @@ blockchainTests('SafeMath', env => { }); }); - describe('_safeDiv', () => { + describe('safeDiv', () => { it('should match the output of the reference function', async () => { const a = ONE_ETHER; const b = ONE_ETHER.times(2); @@ -100,7 +100,7 @@ blockchainTests('SafeMath', env => { }); }); - describe('_safeSub', () => { + describe('safeSub', () => { it('should match the output of the reference function', async () => { const a = ONE_ETHER; const b = ONE_ETHER.dividedToIntegerBy(2); @@ -131,7 +131,7 @@ blockchainTests('SafeMath', env => { }); }); - describe('_safeAdd', () => { + describe('safeAdd', () => { it('should match the output of the reference function', async () => { const a = ONE_ETHER; const b = ONE_ETHER.dividedToIntegerBy(2); @@ -167,7 +167,7 @@ blockchainTests('SafeMath', env => { }); }); - describe('_maxUint256', () => { + describe('maxUint256', () => { it('should return first argument if it is greater than the second', async () => { const result = await safeMath.externalMaxUint256.callAsync(toBigNumber(13), constants.ZERO_AMOUNT); expect(result).bignumber.to.be.eq(toBigNumber(13)); @@ -184,7 +184,7 @@ blockchainTests('SafeMath', env => { }); }); - describe('_minUint256', () => { + describe('minUint256', () => { it('should return first argument if it is less than the second', async () => { const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBigNumber(13)); expect(result).bignumber.to.be.eq(toBigNumber(13)); diff --git a/contracts/utils/tsconfig.json b/contracts/utils/tsconfig.json index 13059711d1..58803aad69 100644 --- a/contracts/utils/tsconfig.json +++ b/contracts/utils/tsconfig.json @@ -23,19 +23,18 @@ "generated-artifacts/Ownable.json", "generated-artifacts/ReentrancyGuard.json", "generated-artifacts/Refundable.json", - "generated-artifacts/SafeMath.json", "generated-artifacts/TestLibAddress.json", "generated-artifacts/TestLibAddressArray.json", "generated-artifacts/TestLibBytes.json", "generated-artifacts/TestLibEIP712.json", "generated-artifacts/TestLibRichErrors.json", + "generated-artifacts/TestLibSafeMath.json", "generated-artifacts/TestLogDecoding.json", "generated-artifacts/TestLogDecodingDownstream.json", "generated-artifacts/TestOwnable.json", "generated-artifacts/TestReentrancyGuard.json", "generated-artifacts/TestRefundable.json", - "generated-artifacts/TestRefundableReceiver.json", - "generated-artifacts/TestSafeMath.json" + "generated-artifacts/TestRefundableReceiver.json" ], "exclude": ["./deploy/solc/solc_bin"] } diff --git a/package.json b/package.json index 7eeed92f4f..d80b0ac141 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "lint:contracts": "wsrun lint -p ${npm_package_config_contractsPackages} -c --fast-exit --stages --exclude-missing" }, "config": { - "contractsPackages": "@0x/contracts-asset-proxy @0x/contracts-dev-utils @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-integrations @0x/contracts-multisig @0x/contracts-staking @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator", + "contractsPackages": "@0x/contracts-asset-proxy @0x/contracts-dev-utils @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-integrations @0x/contracts-multisig @0x/contracts-staking @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator @0x/contracts-tests", "mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic", "packagesWithDocPages": "contract-wrappers 0x.js connect json-schemas subproviders web3-wrapper order-utils sol-compiler sol-coverage sol-profiler sol-trace ethereum-types asset-buyer asset-swapper migrations", "ignoreDependencyVersions": "@types/styled-components @types/node", diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 5f857bb0fa..291ab39c5b 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -83,6 +83,8 @@ export { SimpleEvmOutput, SimpleEvmBytecodeOutput, EIP712DomainWithDefaultSchema, + AwaitTransactionSuccessOpts, + SendTransactionOpts, EventCallback, IndexedFilterValues, DecodedLogEvent, diff --git a/packages/abi-gen-wrappers/CHANGELOG.json b/packages/abi-gen-wrappers/CHANGELOG.json index d1fb15b3c8..e58a45f47a 100644 --- a/packages/abi-gen-wrappers/CHANGELOG.json +++ b/packages/abi-gen-wrappers/CHANGELOG.json @@ -1,4 +1,25 @@ [ + { + "version": "5.4.0-beta.1", + "changes": [ + { + "note": "Remove debug functions `getABIDecodedTransactionData` and `getABIDecodedReturnData`", + "pr": 2243 + }, + { + "note": "Remove `getABIEncodedTransactionData` for constant functions (pure and view)", + "pr": 2243 + }, + { + "note": "Introduce TxOpts object for `sendTransactionAsync` and `awaitTransactionSuccessAsync`. Replaces `timeoutMs` and `pollingIntervalMs` arguments for `awaitTransactionSuccessAsync`", + "pr": 2243 + }, + { + "note": "Remove `validateAndSendTransactionAsync`. Replaced with `shouldValidate` key in TxOpts. Defaults to true", + "pr": 2243 + } + ] + }, { "version": "5.4.0-beta.0", "changes": [ diff --git a/packages/abi-gen-wrappers/package.json b/packages/abi-gen-wrappers/package.json index 48925f10e3..7c543f252e 100644 --- a/packages/abi-gen-wrappers/package.json +++ b/packages/abi-gen-wrappers/package.json @@ -21,7 +21,7 @@ "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output src/generated-wrappers --backend ethers" }, "config": { - "abis": "../contract-artifacts/artifacts/@(AssetProxyOwner|DevUtils|DutchAuction|DummyERC20Token|DummyERC721Token|ERC20Proxy|ERC20Token|ERC721Proxy|ERC721Token|Exchange|Forwarder|IAssetProxy|IValidator|IWallet|MultiAssetProxy|OrderValidator|WETH9|ZRXToken|Coordinator|CoordinatorRegistry|EthBalanceChecker|ERC1155Proxy|StaticCallProxy).json" + "abis": "../contract-artifacts/artifacts/@(AssetProxyOwner|DevUtils|DutchAuction|DummyERC20Token|DummyERC721Token|ERC1155Mintable|ERC20Proxy|ERC20Token|ERC721Proxy|ERC721Token|Exchange|Forwarder|IAssetProxy|IValidator|IWallet|MultiAssetProxy|OrderValidator|WETH9|ZRXToken|Coordinator|CoordinatorRegistry|EthBalanceChecker|ERC1155Proxy|StaticCallProxy).json" }, "repository": { "type": "git", @@ -34,21 +34,20 @@ "homepage": "https://github.com/0xProject/0x-monorepo/packages/abi-gen-wrappers/README.md", "devDependencies": { "@0x/abi-gen": "^4.3.0-beta.0", - "@0x/assert": "^2.2.0-beta.0", - "@0x/json-schemas": "^4.1.0-beta.0", + "@0x/contract-artifacts": "^2.3.0-beta.0", "@0x/tslint-config": "^3.0.1", - "@0x/types": "^2.5.0-beta.0", - "@0x/utils": "^4.6.0-beta.0", - "@0x/web3-wrapper": "^6.1.0-beta.0", - "ethereum-types": "^2.2.0-beta.0", - "ethers": "~4.0.4", - "lodash": "^4.17.11", "shx": "^0.2.2" }, "dependencies": { + "@0x/assert": "^2.2.0-beta.0", "@0x/base-contract": "^5.5.0-beta.0", "@0x/contract-addresses": "^3.3.0-beta.0", - "@0x/contract-artifacts": "^2.3.0-beta.0" + "@0x/json-schemas": "^4.1.0-beta.0", + "@0x/types": "^2.5.0-beta.0", + "@0x/utils": "^4.6.0-beta.0", + "@0x/web3-wrapper": "^6.1.0-beta.0", + "ethereum-types": "^2.2.0-beta.0", + "ethers": "~4.0.4" }, "publishConfig": { "access": "public" diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/asset_proxy_owner.ts b/packages/abi-gen-wrappers/src/generated-wrappers/asset_proxy_owner.ts index 7f9cb9d1e0..20e56f1633 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/asset_proxy_owner.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/asset_proxy_owner.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -113,8 +119,10 @@ export interface AssetProxyOwnerTimeLockChangeEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class AssetProxyOwnerContract extends BaseContract { - public static deployedBytecode = - '0x6080604052600436106101a15760003560e01c80639ace38c2116100e1578063c01a8c841161008a578063d74f8edd11610064578063d74f8edd146104ff578063dc8452cd14610514578063e20056e614610529578063ee22610b14610549576101a1565b8063c01a8c841461049f578063c6427474146104bf578063d38f2d82146104df576101a1565b8063b5dc40c3116100bb578063b5dc40c31461044a578063b77bf6001461046a578063ba51a6df1461047f576101a1565b80639ace38c2146103cb578063a0e67e2b146103fb578063a8abe69a1461041d576101a1565b8063547415251161014e578063784547a711610128578063784547a71461033d5780637ad28c511461035d5780637f05c8b61461037d5780638b51d13f146103ab576101a1565b806354741525146102dd5780637065cb48146102fd578063751ad5601461031d576101a1565b80632f54bf6e1161017f5780632f54bf6e1461026e5780633411c81c1461029b57806337bd78a0146102bb576101a1565b8063025e7c27146101f8578063173825d91461022e57806320ea8d861461024e575b34156101f6573373ffffffffffffffffffffffffffffffffffffffff167fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c346040516101ed9190612b44565b60405180910390a25b005b34801561020457600080fd5b50610218610213366004612580565b610569565b6040516102259190612616565b60405180910390f35b34801561023a57600080fd5b506101f6610249366004612303565b61059d565b34801561025a57600080fd5b506101f6610269366004612580565b61084c565b34801561027a57600080fd5b5061028e610289366004612303565b6109a7565b6040516102259190612745565b3480156102a757600080fd5b5061028e6102b6366004612598565b6109bc565b3480156102c757600080fd5b506102d06109dc565b6040516102259190612b44565b3480156102e957600080fd5b506102d06102f83660046124c0565b6109e2565b34801561030957600080fd5b506101f6610318366004612303565b610a4e565b34801561032957600080fd5b506101f66103383660046124f4565b610c73565b34801561034957600080fd5b5061028e610358366004612580565b610cbe565b34801561036957600080fd5b506101f6610378366004612580565b610d52565b34801561038957600080fd5b5061039d610398366004612563565b610dcb565b604051610225929190612750565b3480156103b757600080fd5b506102d06103c6366004612580565b610e04565b3480156103d757600080fd5b506103eb6103e6366004612580565b610e80565b6040516102259493929190612637565b34801561040757600080fd5b50610410610f69565b60405161022591906126b4565b34801561042957600080fd5b5061043d6104383660046125bc565b610fd9565b604051610225919061270d565b34801561045657600080fd5b50610410610465366004612580565b611104565b34801561047657600080fd5b506102d06112bc565b34801561048b57600080fd5b506101f661049a366004612580565b6112c2565b3480156104ab57600080fd5b506101f66104ba366004612580565b61139e565b3480156104cb57600080fd5b506102d06104da366004612357565b611568565b3480156104eb57600080fd5b506102d06104fa366004612580565b611587565b34801561050b57600080fd5b506102d0611599565b34801561052057600080fd5b506102d061159e565b34801561053557600080fd5b506101f661054436600461231f565b6115a4565b34801561055557600080fd5b506101f6610564366004612580565b61182e565b6003818154811061057657fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b3330146105df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612a68565b60405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116600090815260026020526040902054819060ff16610640576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6906129fa565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260026020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b6003547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff018110156107bc578273ffffffffffffffffffffffffffffffffffffffff16600382815481106106dc57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614156107b457600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811061073457fe5b6000918252602090912001546003805473ffffffffffffffffffffffffffffffffffffffff909216918390811061076757fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506107bc565b60010161068c565b50600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01906107ee9082612100565b50600354600454111561080757600354610807906112c2565b60405173ffffffffffffffffffffffffffffffffffffffff8316907f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b9090600090a25050565b3360008181526002602052604090205460ff16610895576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6906129fa565b60008281526001602090815260408083203380855292529091205483919060ff166108ec576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612955565b600084815260208190526040902060030154849060ff161561093a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612ad6565b600085815260016020908152604080832033808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555187927ff6a317157440607f36269043eb55f1287a5a19ba2216afeab88cd46cbcfb88e991a35050505050565b60026020526000908152604090205460ff1681565b600160209081526000928352604080842090915290825290205460ff1681565b60065481565b6000805b600554811015610a4757838015610a0f575060008181526020819052604090206003015460ff16155b80610a335750828015610a33575060008181526020819052604090206003015460ff165b15610a3f576001820191505b6001016109e6565b5092915050565b333014610a87576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612a68565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260026020526040902054819060ff1615610ae9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612879565b8173ffffffffffffffffffffffffffffffffffffffff8116610b37576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d69061280b565b60038054905060010160045460328211158015610b545750818111155b8015610b5f57508015155b8015610b6a57508115155b610ba0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612b0d565b73ffffffffffffffffffffffffffffffffffffffff851660008181526002602052604080822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600190811790915560038054918201815583527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055517ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d9190a25050505050565b333014610cac576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612a68565b610cb884848484611b79565b50505050565b600080805b600354811015610d4a5760008481526001602052604081206003805491929184908110610cec57fe5b600091825260208083209091015473ffffffffffffffffffffffffffffffffffffffff16835282019290925260400190205460ff1615610d2d576001820191505b600454821415610d4257600192505050610d4d565b600101610cc3565b50505b919050565b333014610d8b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612a68565b60068190556040517fd1c9101a34feff75cccef14a28785a0279cb0b49c1f321f21f5f422e746b437790610dc0908390612b44565b60405180910390a150565b600860209081526000928352604080842090915290825290205460ff81169061010090046fffffffffffffffffffffffffffffffff1682565b6000805b600354811015610e7a5760008381526001602052604081206003805491929184908110610e3157fe5b600091825260208083209091015473ffffffffffffffffffffffffffffffffffffffff16835282019290925260400190205460ff1615610e72576001820191505b600101610e08565b50919050565b60006020818152918152604090819020805460018083015460028085018054875161010095821615959095027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff011691909104601f810188900488028401880190965285835273ffffffffffffffffffffffffffffffffffffffff90931695909491929190830182828015610f565780601f10610f2b57610100808354040283529160200191610f56565b820191906000526020600020905b815481529060010190602001808311610f3957829003601f168201915b5050506003909301549192505060ff1684565b60606003805480602002602001604051908101604052809291908181526020018280548015610fce57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610fa3575b505050505090505b90565b606080600554604051908082528060200260200182016040528015611008578160200160208202803883390190505b5090506000805b60055481101561108957858015611038575060008181526020819052604090206003015460ff16155b8061105c575084801561105c575060008181526020819052604090206003015460ff165b15611081578083838151811061106e57fe5b6020026020010181815250506001820191505b60010161100f565b8787036040519080825280602002602001820160405280156110b5578160200160208202803883390190505b5093508790505b868110156110f9578281815181106110d057fe5b602002602001015184898303815181106110e657fe5b60209081029190910101526001016110bc565b505050949350505050565b606080600380549050604051908082528060200260200182016040528015611136578160200160208202803883390190505b5090506000805b60035481101561122d576000858152600160205260408120600380549192918490811061116657fe5b600091825260208083209091015473ffffffffffffffffffffffffffffffffffffffff16835282019290925260400190205460ff161561122557600381815481106111ad57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168383815181106111e457fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250506001820191505b60010161113d565b81604051908082528060200260200182016040528015611257578160200160208202803883390190505b509350600090505b818110156112b45782818151811061127357fe5b602002602001015184828151811061128757fe5b73ffffffffffffffffffffffffffffffffffffffff9092166020928302919091019091015260010161125f565b505050919050565b60055481565b3330146112fb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612a68565b60035481603282118015906113105750818111155b801561131b57508015155b801561132657508115155b61135c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612b0d565b60048390556040517fa3f1ee9126a074d9326c682f561767f710e927faa811f7a99829d49dc421797a90611391908590612b44565b60405180910390a1505050565b3360008181526002602052604090205460ff166113e7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6906129fa565b600082815260208190526040902054829073ffffffffffffffffffffffffffffffffffffffff16611444576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d69061291e565b60008381526001602090815260408083203380855292529091205484919060ff161561149c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6906128b0565b846114a681610cbe565b156114dd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612a9f565b600086815260016020818152604080842033808652925280842080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016909317909255905188927f4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef91a361155186610cbe565b15611560576115608642611cb1565b505050505050565b6000611575848484611d00565b90506115808161139e565b9392505050565b60076020526000908152604090205481565b603281565b60045481565b3330146115dd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612a68565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260026020526040902054829060ff1661163e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6906129fa565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260026020526040902054829060ff16156116a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612879565b60005b60035481101561175c578473ffffffffffffffffffffffffffffffffffffffff16600382815481106116d157fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16141561175457836003828154811061170757fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061175c565b6001016116a3565b5073ffffffffffffffffffffffffffffffffffffffff80851660008181526002602052604080822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0090811690915593871682528082208054909416600117909355915190917f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b9091a260405173ffffffffffffffffffffffffffffffffffffffff8416907ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d90600090a250505050565b600081815260208190526040902060030154819060ff161561187c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612ad6565b8161188681610cbe565b6118bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6906128e7565b6000838152602081815260409182902060038101805460017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00909116811790915560028083018054865161010094821615949094027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff011691909104601f81018590048502830185019095528482529193606093849384939290918301828280156119a85780601f1061197d576101008083540402835291602001916119a8565b820191906000526020600020905b81548152906001019060200180831161198b57829003601f168201915b50505050508060200190516119c091908101906123ec565b9250925092506000835190508251811480156119dc5750815181145b611a12576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d69061298c565b600088815260076020526040812054905b828114611b4257611a5b82878381518110611a3a57fe5b6020026020010151878481518110611a4e57fe5b6020026020010151611e5e565b6000858281518110611a6957fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16858381518110611a9357fe5b6020026020010151888481518110611aa757fe5b6020026020010151604051611abc91906125fa565b60006040518083038185875af1925050503d8060008114611af9576040519150601f19603f3d011682016040523d82523d6000602084013e611afe565b606091505b5050905080611b39576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6906129c3565b50600101611a23565b5060405189907f33e13ecb54c3076d8e8bb8c2881800a4d972b792045ffae98fdf46df365fed7590600090a2505050505050505050565b600084611b87576000611b89565b815b9050611b93612129565b5060408051808201825286151581526fffffffffffffffffffffffffffffffff80841660208084019182527fffffffff00000000000000000000000000000000000000000000000000000000891660009081526008825285812073ffffffffffffffffffffffffffffffffffffffff8a168252909152849020835181549251909316610100027fffffffffffffffffffffffffffffff00000000000000000000000000000000ff9315157fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00909316929092179290921617905590517f694405724de467488eda192d814f39ffe7f6503fe0b1eefd4ea332f9c611c5ec90611ca190879087908a908790612772565b60405180910390a1505050505050565b600082815260076020526040908190208290555182907f0b237afe65f1514fd7ea3f923ea4fe792bdd07000a912b6cd1602a8e7f573c8d90611cf4908490612b44565b60405180910390a25050565b60008373ffffffffffffffffffffffffffffffffffffffff8116611d50576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d69061280b565b6005546040805160808101825273ffffffffffffffffffffffffffffffffffffffff8881168252602080830189815283850189815260006060860181905287815280845295909520845181547fffffffffffffffffffffffff00000000000000000000000000000000000000001694169390931783555160018301559251805194965091939092611de8926002850192910190612140565b5060609190910151600390910180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001691151591909117905560058054600101905560405182907fc0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e5190600090a2509392505050565b6000611e70838263ffffffff611fbd16565b9050611e7a612129565b507fffffffff000000000000000000000000000000000000000000000000000000008116600090815260086020908152604080832073ffffffffffffffffffffffffffffffffffffffff8616845282529182902082518084019093525460ff811615801584526101009091046fffffffffffffffffffffffffffffffff1691830191909152611f69576020810151611f2b9086906fffffffffffffffffffffffffffffffff1663ffffffff61201816565b421015611f64576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612a31565b611fb6565b600654611f7d90869063ffffffff61201816565b421015611fb6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d690612842565b5050505050565b60008160040183511015611fe357611fe3611fde6003855185600401612034565b6120d9565b5060208183018101519101907fffffffff00000000000000000000000000000000000000000000000000000000165b92915050565b60008282018381101561158057611580611fde600086866120e1565b6060632800659560e01b848484604051602401612053939291906127fd565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290509392505050565b805160208201fd5b606063e946c1bb60e01b848484604051602401612053939291906127db565b815481835581811115612124576000838152602090206121249181019083016121be565b505050565b604080518082019091526000808252602082015290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061218157805160ff19168380011785556121ae565b828001600101855582156121ae579182015b828111156121ae578251825591602001919060010190612193565b506121ba9291506121be565b5090565b610fd691905b808211156121ba57600081556001016121c4565b600082601f8301126121e8578081fd5b81516121fb6121f682612b74565b612b4d565b81815291506020808301908481018184028601820187101561221c57600080fd5b60005b8481101561224457815161223281612c02565b8452928201929082019060010161221f565b505050505092915050565b600082601f83011261225f578081fd5b815161226d6121f682612b74565b81815291506020808301908481018184028601820187101561228e57600080fd5b60005b8481101561224457815184529282019290820190600101612291565b8035801515811461201257600080fd5b600082601f8301126122cd578081fd5b81516122db6121f682612b94565b91508082528360208285010111156122f257600080fd5b610a47816020840160208601612bd6565b600060208284031215612314578081fd5b813561158081612c02565b60008060408385031215612331578081fd5b823561233c81612c02565b9150602083013561234c81612c02565b809150509250929050565b60008060006060848603121561236b578081fd5b833561237681612c02565b925060208401359150604084013567ffffffffffffffff811115612398578182fd5b80850186601f8201126123a9578283fd5b803591506123b96121f683612b94565b8281528760208484010111156123cd578384fd5b8260208301602083013783602084830101528093505050509250925092565b600080600060608486031215612400578283fd5b835167ffffffffffffffff80821115612417578485fd5b81860187601f820112612428578586fd5b805192506124386121f684612b74565b83815260208082019190838101895b878110156124705761245e8d8484518901016122bd565b85529382019390820190600101612447565b50508901519097509350505080821115612488578384fd5b612494878388016121d8565b935060408601519150808211156124a9578283fd5b506124b68682870161224f565b9150509250925092565b600080604083850312156124d2578182fd5b6124dc84846122ad565b91506124eb84602085016122ad565b90509250929050565b60008060008060808587031215612509578081fd5b843561251481612c27565b9350602085013561252481612c35565b9250604085013561253481612c02565b915060608501356fffffffffffffffffffffffffffffffff81168114612558578182fd5b939692955090935050565b60008060408385031215612575578182fd5b823561233c81612c35565b600060208284031215612591578081fd5b5035919050565b600080604083850312156125aa578182fd5b82359150602083013561234c81612c02565b600080600080608085870312156125d1578182fd5b843593506020850135925060408501356125ea81612c27565b9150606085013561255881612c27565b6000825161260c818460208701612bd6565b9190910192915050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b600073ffffffffffffffffffffffffffffffffffffffff861682528460208301526080604083015283518060808401526126788160a0850160208801612bd6565b921515606083015250601f919091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0160160a0019392505050565b602080825282518282018190526000918401906040840190835b8181101561270257835173ffffffffffffffffffffffffffffffffffffffff168352602093840193909201916001016126ce565b509095945050505050565b602080825282518282018190526000918401906040840190835b81811015612702578351835260209384019390920191600101612727565b901515815260200190565b91151582526fffffffffffffffffffffffffffffffff16602082015260400190565b7fffffffff0000000000000000000000000000000000000000000000000000000094909416845273ffffffffffffffffffffffffffffffffffffffff929092166020840152151560408301526fffffffffffffffffffffffffffffffff16606082015260800190565b60608101600485106127e957fe5b938152602081019290925260409091015290565b60608101600885106127e957fe5b6020808252600c908201527f4e554c4c5f414444524553530000000000000000000000000000000000000000604082015260600190565b6020808252601c908201527f44454641554c545f54494d455f4c4f434b5f494e434f4d504c45544500000000604082015260600190565b6020808252600c908201527f4f574e45525f4558495354530000000000000000000000000000000000000000604082015260600190565b60208082526014908201527f54585f414c52454144595f434f4e4649524d4544000000000000000000000000604082015260600190565b60208082526016908201527f54585f4e4f545f46554c4c595f434f4e4649524d454400000000000000000000604082015260600190565b6020808252600f908201527f54585f444f45534e545f45584953540000000000000000000000000000000000604082015260600190565b60208082526010908201527f54585f4e4f545f434f4e4649524d454400000000000000000000000000000000604082015260600190565b60208082526016908201527f455155414c5f4c454e475448535f524551554952454400000000000000000000604082015260600190565b60208082526010908201527f4641494c45445f455845435554494f4e00000000000000000000000000000000604082015260600190565b60208082526012908201527f4f574e45525f444f45534e545f45584953540000000000000000000000000000604082015260600190565b6020808252601b908201527f435553544f4d5f54494d455f4c4f434b5f494e434f4d504c4554450000000000604082015260600190565b60208082526017908201527f4f4e4c595f43414c4c41424c455f42595f57414c4c4554000000000000000000604082015260600190565b60208082526012908201527f54585f46554c4c595f434f4e4649524d45440000000000000000000000000000604082015260600190565b60208082526013908201527f54585f414c52454144595f455845435554454400000000000000000000000000604082015260600190565b60208082526014908201527f494e56414c49445f524551554952454d454e5453000000000000000000000000604082015260600190565b90815260200190565b60405181810167ffffffffffffffff81118282101715612b6c57600080fd5b604052919050565b600067ffffffffffffffff821115612b8a578081fd5b5060209081020190565b600067ffffffffffffffff821115612baa578081fd5b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b60005b83811015612bf1578181015183820152602001612bd9565b83811115610cb85750506000910152565b73ffffffffffffffffffffffffffffffffffffffff81168114612c2457600080fd5b50565b8015158114612c2457600080fd5b7fffffffff0000000000000000000000000000000000000000000000000000000081168114612c2457600080fdfea365627a7a723158200ac5186607cd3ec8212bb7bd34d7047a94bed6fb931222d7ea453055d00701cd6c6578706572696d656e74616cf564736f6c634300050c0040'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; public MAX_OWNER_COUNT = { /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an @@ -157,41 +165,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('MAX_OWNER_COUNT()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('MAX_OWNER_COUNT()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('MAX_OWNER_COUNT()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Allows to add a new owner. Transaction has to be sent by wallet. @@ -204,7 +177,11 @@ export class AssetProxyOwnerContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(owner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + owner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('owner', owner); const self = (this as any) as AssetProxyOwnerContract; const encodedData = self._strictEncodeArguments('addOwner(address)', [owner.toLowerCase()]); @@ -220,6 +197,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.addOwner.callAsync(owner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -234,20 +215,19 @@ export class AssetProxyOwnerContract extends BaseContract { awaitTransactionSuccessAsync( owner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('owner', owner); const self = (this as any) as AssetProxyOwnerContract; - const txHashPromise = self.addOwner.sendTransactionAsync(owner.toLowerCase(), txData); + const txHashPromise = self.addOwner.sendTransactionAsync(owner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -277,11 +257,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -339,28 +314,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('addOwner(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('addOwner(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -374,7 +333,11 @@ export class AssetProxyOwnerContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(_required: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + _required: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isBigNumber('_required', _required); const self = (this as any) as AssetProxyOwnerContract; const encodedData = self._strictEncodeArguments('changeRequirement(uint256)', [_required]); @@ -390,6 +353,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.changeRequirement.callAsync(_required, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -404,20 +371,19 @@ export class AssetProxyOwnerContract extends BaseContract { awaitTransactionSuccessAsync( _required: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('_required', _required); const self = (this as any) as AssetProxyOwnerContract; - const txHashPromise = self.changeRequirement.sendTransactionAsync(_required, txData); + const txHashPromise = self.changeRequirement.sendTransactionAsync(_required, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -447,14 +413,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -516,28 +474,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [BigNumber] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('changeRequirement(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('changeRequirement(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -555,6 +497,7 @@ export class AssetProxyOwnerContract extends BaseContract { async sendTransactionAsync( _secondsTimeLocked: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isBigNumber('_secondsTimeLocked', _secondsTimeLocked); const self = (this as any) as AssetProxyOwnerContract; @@ -571,6 +514,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.changeTimeLock.callAsync(_secondsTimeLocked, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -586,20 +533,19 @@ export class AssetProxyOwnerContract extends BaseContract { awaitTransactionSuccessAsync( _secondsTimeLocked: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('_secondsTimeLocked', _secondsTimeLocked); const self = (this as any) as AssetProxyOwnerContract; - const txHashPromise = self.changeTimeLock.sendTransactionAsync(_secondsTimeLocked, txData); + const txHashPromise = self.changeTimeLock.sendTransactionAsync(_secondsTimeLocked, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -630,14 +576,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -703,28 +641,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [BigNumber] { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('changeTimeLock(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('changeTimeLock(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -738,7 +660,11 @@ export class AssetProxyOwnerContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(transactionId: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + transactionId: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isBigNumber('transactionId', transactionId); const self = (this as any) as AssetProxyOwnerContract; const encodedData = self._strictEncodeArguments('confirmTransaction(uint256)', [transactionId]); @@ -754,6 +680,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.confirmTransaction.callAsync(transactionId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -768,20 +698,19 @@ export class AssetProxyOwnerContract extends BaseContract { awaitTransactionSuccessAsync( transactionId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('transactionId', transactionId); const self = (this as any) as AssetProxyOwnerContract; - const txHashPromise = self.confirmTransaction.sendTransactionAsync(transactionId, txData); + const txHashPromise = self.confirmTransaction.sendTransactionAsync(transactionId, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -811,14 +740,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -882,28 +803,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [BigNumber] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('confirmTransaction(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('confirmTransaction(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public confirmationTimes = { @@ -953,42 +858,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: BigNumber): string { - assert.isBigNumber('index_0', index_0); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('confirmationTimes(uint256)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('confirmationTimes(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('confirmationTimes(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public confirmations = { /** @@ -1042,46 +911,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: BigNumber, index_1: string): string { - assert.isBigNumber('index_0', index_0); - assert.isString('index_1', index_1); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('confirmations(uint256,address)', [ - index_0, - index_1.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('confirmations(uint256,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('confirmations(uint256,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Allows anyone to execute a confirmed transaction. @@ -1097,7 +926,11 @@ export class AssetProxyOwnerContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(transactionId: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + transactionId: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isBigNumber('transactionId', transactionId); const self = (this as any) as AssetProxyOwnerContract; const encodedData = self._strictEncodeArguments('executeTransaction(uint256)', [transactionId]); @@ -1113,6 +946,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.executeTransaction.callAsync(transactionId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1127,20 +964,19 @@ export class AssetProxyOwnerContract extends BaseContract { awaitTransactionSuccessAsync( transactionId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('transactionId', transactionId); const self = (this as any) as AssetProxyOwnerContract; - const txHashPromise = self.executeTransaction.sendTransactionAsync(transactionId, txData); + const txHashPromise = self.executeTransaction.sendTransactionAsync(transactionId, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1170,14 +1006,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1241,28 +1069,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [BigNumber] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('executeTransaction(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('executeTransaction(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public functionCallTimeLocks = { @@ -1317,46 +1129,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string, index_1: string): string { - assert.isString('index_0', index_0); - assert.isString('index_1', index_1); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('functionCallTimeLocks(bytes4,address)', [ - index_0, - index_1.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('functionCallTimeLocks(bytes4,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [boolean, BigNumber] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('functionCallTimeLocks(bytes4,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[boolean, BigNumber]>(returnData); - return abiDecodedReturnData; - }, }; /** * Returns number of confirmations of a transaction. @@ -1410,45 +1182,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param transactionId Transaction ID. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(transactionId: BigNumber): string { - assert.isBigNumber('transactionId', transactionId); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getConfirmationCount(uint256)', [ - transactionId, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getConfirmationCount(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getConfirmationCount(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Returns array with owner addresses, which confirmed transaction. @@ -1502,43 +1235,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param transactionId Transaction ID. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(transactionId: BigNumber): string { - assert.isBigNumber('transactionId', transactionId); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getConfirmations(uint256)', [transactionId]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getConfirmations(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string[] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getConfirmations(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Returns list of owners. @@ -1586,41 +1282,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getOwners()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getOwners()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string[] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getOwners()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Returns total number of transactions after filers are applied. @@ -1677,48 +1338,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param pending Include pending transactions. - * @param executed Include executed transactions. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(pending: boolean, executed: boolean): string { - assert.isBoolean('pending', pending); - assert.isBoolean('executed', executed); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getTransactionCount(bool,bool)', [ - pending, - executed, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): boolean { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getTransactionCount(bool,bool)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getTransactionCount(bool,bool)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Returns list of transaction IDs in defined range. @@ -1786,52 +1405,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param from Index start position of transaction array. - * @param to Index end position of transaction array. - * @param pending Include pending transactions. - * @param executed Include executed transactions. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(from: BigNumber, to: BigNumber, pending: boolean, executed: boolean): string { - assert.isBigNumber('from', from); - assert.isBigNumber('to', to); - assert.isBoolean('pending', pending); - assert.isBoolean('executed', executed); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getTransactionIds(uint256,uint256,bool,bool)', - [from, to, pending, executed], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getTransactionIds(uint256,uint256,bool,bool)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber[] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('getTransactionIds(uint256,uint256,bool,bool)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Returns the confirmation status of a transaction. @@ -1885,43 +1458,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param transactionId Transaction ID. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(transactionId: BigNumber): string { - assert.isBigNumber('transactionId', transactionId); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('isConfirmed(uint256)', [transactionId]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('isConfirmed(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('isConfirmed(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public isOwner = { /** @@ -1970,42 +1506,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('isOwner(address)', [index_0.toLowerCase()]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('isOwner(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('isOwner(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public owners = { /** @@ -2054,42 +1554,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: BigNumber): string { - assert.isBigNumber('index_0', index_0); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owners(uint256)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('owners(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('owners(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Registers a custom timelock to a specific function selector / destination combo @@ -2112,6 +1576,7 @@ export class AssetProxyOwnerContract extends BaseContract { destination: string, newSecondsTimeLocked: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isBoolean('hasCustomTimeLock', hasCustomTimeLock); assert.isString('functionSelector', functionSelector); @@ -2136,6 +1601,16 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.registerFunctionCall.callAsync( + hasCustomTimeLock, + functionSelector, + destination, + newSecondsTimeLocked, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2157,8 +1632,7 @@ export class AssetProxyOwnerContract extends BaseContract { destination: string, newSecondsTimeLocked: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBoolean('hasCustomTimeLock', hasCustomTimeLock); assert.isString('functionSelector', functionSelector); @@ -2171,6 +1645,7 @@ export class AssetProxyOwnerContract extends BaseContract { destination.toLowerCase(), newSecondsTimeLocked, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -2178,8 +1653,8 @@ export class AssetProxyOwnerContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2227,29 +1702,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - hasCustomTimeLock: boolean, - functionSelector: string, - destination: string, - newSecondsTimeLocked: BigNumber, - txData?: Partial | undefined, - ): Promise { - await (this as any).registerFunctionCall.callAsync( - hasCustomTimeLock, - functionSelector, - destination, - newSecondsTimeLocked, - txData, - ); - const txHash = await (this as any).registerFunctionCall.sendTransactionAsync( - hasCustomTimeLock, - functionSelector, - destination, - newSecondsTimeLocked, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2341,28 +1793,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [boolean, string, string, BigNumber] { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('registerFunctionCall(bool,bytes4,address,uint128)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[boolean, string, string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('registerFunctionCall(bool,bytes4,address,uint128)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -2376,7 +1812,11 @@ export class AssetProxyOwnerContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(owner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + owner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('owner', owner); const self = (this as any) as AssetProxyOwnerContract; const encodedData = self._strictEncodeArguments('removeOwner(address)', [owner.toLowerCase()]); @@ -2392,6 +1832,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeOwner.callAsync(owner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2406,20 +1850,19 @@ export class AssetProxyOwnerContract extends BaseContract { awaitTransactionSuccessAsync( owner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('owner', owner); const self = (this as any) as AssetProxyOwnerContract; - const txHashPromise = self.removeOwner.sendTransactionAsync(owner.toLowerCase(), txData); + const txHashPromise = self.removeOwner.sendTransactionAsync(owner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2449,11 +1892,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2513,28 +1951,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('removeOwner(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('removeOwner(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -2553,6 +1975,7 @@ export class AssetProxyOwnerContract extends BaseContract { owner: string, newOwner: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('owner', owner); assert.isString('newOwner', newOwner); @@ -2573,6 +1996,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.replaceOwner.callAsync(owner, newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2589,8 +2016,7 @@ export class AssetProxyOwnerContract extends BaseContract { owner: string, newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('owner', owner); assert.isString('newOwner', newOwner); @@ -2599,6 +2025,7 @@ export class AssetProxyOwnerContract extends BaseContract { owner.toLowerCase(), newOwner.toLowerCase(), txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -2606,8 +2033,8 @@ export class AssetProxyOwnerContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2642,15 +2069,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2723,28 +2141,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, string] { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('replaceOwner(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('replaceOwner(address,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public required = { @@ -2789,41 +2191,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('required()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('required()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('required()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Allows an owner to revoke a confirmation for a transaction. @@ -2836,7 +2203,11 @@ export class AssetProxyOwnerContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(transactionId: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + transactionId: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isBigNumber('transactionId', transactionId); const self = (this as any) as AssetProxyOwnerContract; const encodedData = self._strictEncodeArguments('revokeConfirmation(uint256)', [transactionId]); @@ -2852,6 +2223,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.revokeConfirmation.callAsync(transactionId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2866,20 +2241,19 @@ export class AssetProxyOwnerContract extends BaseContract { awaitTransactionSuccessAsync( transactionId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('transactionId', transactionId); const self = (this as any) as AssetProxyOwnerContract; - const txHashPromise = self.revokeConfirmation.sendTransactionAsync(transactionId, txData); + const txHashPromise = self.revokeConfirmation.sendTransactionAsync(transactionId, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2909,14 +2283,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2980,28 +2346,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [BigNumber] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('revokeConfirmation(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('revokeConfirmation(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public secondsTimeLocked = { @@ -3046,41 +2396,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('secondsTimeLocked()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('secondsTimeLocked()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('secondsTimeLocked()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Allows an owner to submit and confirm a transaction. @@ -3100,6 +2415,7 @@ export class AssetProxyOwnerContract extends BaseContract { value: BigNumber, data: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('destination', destination); assert.isBigNumber('value', value); @@ -3122,6 +2438,10 @@ export class AssetProxyOwnerContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.submitTransaction.callAsync(destination, value, data, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -3140,8 +2460,7 @@ export class AssetProxyOwnerContract extends BaseContract { value: BigNumber, data: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('destination', destination); assert.isBigNumber('value', value); @@ -3152,6 +2471,7 @@ export class AssetProxyOwnerContract extends BaseContract { value, data, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -3159,8 +2479,8 @@ export class AssetProxyOwnerContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -3203,16 +2523,6 @@ export class AssetProxyOwnerContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -3293,28 +2603,12 @@ export class AssetProxyOwnerContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): string { + getSelector(): string { const self = (this as any) as AssetProxyOwnerContract; const abiEncoder = self._lookupAbiEncoder('submitTransaction(address,uint256,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('submitTransaction(address,uint256,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public transactionCount = { @@ -3359,41 +2653,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('transactionCount()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('transactionCount()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('transactionCount()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transactions = { /** @@ -3442,44 +2701,6 @@ export class AssetProxyOwnerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: BigNumber): string { - assert.isBigNumber('index_0', index_0); - const self = (this as any) as AssetProxyOwnerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('transactions(uint256)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [BigNumber] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('transactions(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, BigNumber, string, boolean] { - const self = (this as any) as AssetProxyOwnerContract; - const abiEncoder = self._lookupAbiEncoder('transactions(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, BigNumber, string, boolean]>( - returnData, - ); - return abiDecodedReturnData; - }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/coordinator.ts b/packages/abi-gen-wrappers/src/generated-wrappers/coordinator.ts index 482663decc..238bc768c9 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/coordinator.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/coordinator.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class CoordinatorContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode: string | undefined; /** * Recovers the address of a signer given a hash and signature. @@ -62,7 +71,7 @@ export class CoordinatorContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -75,48 +84,6 @@ export class CoordinatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param hash Any 32 byte hash. - * @param signature Proof that the hash has been signed by signer. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(hash: string, signature: string): string { - assert.isString('hash', hash); - assert.isString('signature', signature); - const self = (this as any) as CoordinatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getSignerAddress(bytes32,bytes)', [ - hash, - signature, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('getSignerAddress(bytes32,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('getSignerAddress(bytes32,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Calculates the EIP712 hash of a 0x transaction using the domain separator of the Exchange contract. @@ -171,49 +138,6 @@ export class CoordinatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param transaction 0x transaction containing salt, signerAddress, and data. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(transaction: { salt: BigNumber; signerAddress: string; data: string }): string { - const self = (this as any) as CoordinatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getTransactionHash((uint256,address,bytes))', - [transaction], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): { salt: BigNumber; signerAddress: string; data: string } { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('getTransactionHash((uint256,address,bytes))'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - salt: BigNumber; - signerAddress: string; - data: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('getTransactionHash((uint256,address,bytes))'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Calculated the EIP712 hash of the Coordinator approval mesasage using the domain separator of this contract. @@ -275,63 +199,6 @@ export class CoordinatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param approval Coordinator approval message containing the transaction - * hash, transaction signature, and expiration of the approval. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(approval: { - txOrigin: string; - transactionHash: string; - transactionSignature: string; - approvalExpirationTimeSeconds: BigNumber; - }): string { - const self = (this as any) as CoordinatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getCoordinatorApprovalHash((address,bytes32,bytes,uint256))', - [approval], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - txOrigin: string; - transactionHash: string; - transactionSignature: string; - approvalExpirationTimeSeconds: BigNumber; - } { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('getCoordinatorApprovalHash((address,bytes32,bytes,uint256))'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - txOrigin: string; - transactionHash: string; - transactionSignature: string; - approvalExpirationTimeSeconds: BigNumber; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('getCoordinatorApprovalHash((address,bytes32,bytes,uint256))'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Executes a 0x transaction that has been signed by the feeRecipients that correspond to each order in the transaction's Exchange calldata. @@ -359,6 +226,7 @@ export class CoordinatorContract extends BaseContract { approvalExpirationTimeSeconds: BigNumber[], approvalSignatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('txOrigin', txOrigin); assert.isString('transactionSignature', transactionSignature); @@ -387,6 +255,17 @@ export class CoordinatorContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.executeTransaction.callAsync( + transaction, + txOrigin, + transactionSignature, + approvalExpirationTimeSeconds, + approvalSignatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -413,8 +292,7 @@ export class CoordinatorContract extends BaseContract { approvalExpirationTimeSeconds: BigNumber[], approvalSignatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('txOrigin', txOrigin); assert.isString('transactionSignature', transactionSignature); @@ -428,6 +306,7 @@ export class CoordinatorContract extends BaseContract { approvalExpirationTimeSeconds, approvalSignatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -435,8 +314,8 @@ export class CoordinatorContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -493,32 +372,6 @@ export class CoordinatorContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -632,36 +485,14 @@ export class CoordinatorContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): [{ salt: BigNumber; signerAddress: string; data: string }, string, string, BigNumber[], string[]] { + getSelector(): string { const self = (this as any) as CoordinatorContract; const abiEncoder = self._lookupAbiEncoder( 'executeTransaction((uint256,address,bytes),address,bytes,uint256[],bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [{ salt: BigNumber; signerAddress: string; data: string }, string, string, BigNumber[], string[]] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'executeTransaction((uint256,address,bytes),address,bytes,uint256[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public EIP712_EXCHANGE_DOMAIN_HASH = { @@ -706,41 +537,6 @@ export class CoordinatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as CoordinatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments('EIP712_EXCHANGE_DOMAIN_HASH()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('EIP712_EXCHANGE_DOMAIN_HASH()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('EIP712_EXCHANGE_DOMAIN_HASH()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Validates that the 0x transaction has been approved by all of the feeRecipients @@ -820,77 +616,6 @@ export class CoordinatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param transaction 0x transaction containing salt, signerAddress, and data. - * @param txOrigin Required signer of Ethereum transaction calling this - * function. - * @param transactionSignature Proof that the transaction has been signed by - * the signer. - * @param approvalExpirationTimeSeconds Array of expiration times in seconds - * for which each corresponding approval signature expires. - * @param approvalSignatures Array of signatures that correspond to the - * feeRecipients of each order in the transaction's Exchange calldata. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - transaction: { salt: BigNumber; signerAddress: string; data: string }, - txOrigin: string, - transactionSignature: string, - approvalExpirationTimeSeconds: BigNumber[], - approvalSignatures: string[], - ): string { - assert.isString('txOrigin', txOrigin); - assert.isString('transactionSignature', transactionSignature); - assert.isArray('approvalExpirationTimeSeconds', approvalExpirationTimeSeconds); - assert.isArray('approvalSignatures', approvalSignatures); - const self = (this as any) as CoordinatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'assertValidCoordinatorApprovals((uint256,address,bytes),address,bytes,uint256[],bytes[])', - [ - transaction, - txOrigin.toLowerCase(), - transactionSignature, - approvalExpirationTimeSeconds, - approvalSignatures, - ], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): [{ salt: BigNumber; signerAddress: string; data: string }, string, string, BigNumber[], string[]] { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'assertValidCoordinatorApprovals((uint256,address,bytes),address,bytes,uint256[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [{ salt: BigNumber; signerAddress: string; data: string }, string, string, BigNumber[], string[]] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'assertValidCoordinatorApprovals((uint256,address,bytes),address,bytes,uint256[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Decodes the orders from Exchange calldata representing any fill method. @@ -938,7 +663,7 @@ export class CoordinatorContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -966,73 +691,6 @@ export class CoordinatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param data Exchange calldata representing a fill method. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(data: string): string { - assert.isString('data', data); - const self = (this as any) as CoordinatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeOrdersFromFillData(bytes)', [data]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('decodeOrdersFromFillData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): 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; - }> { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('decodeOrdersFromFillData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - 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; - }> - >(returnData); - return abiDecodedReturnData; - }, }; public EIP712_COORDINATOR_DOMAIN_HASH = { /** @@ -1076,41 +734,6 @@ export class CoordinatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as CoordinatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments('EIP712_COORDINATOR_DOMAIN_HASH()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('EIP712_COORDINATOR_DOMAIN_HASH()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as CoordinatorContract; - const abiEncoder = self._lookupAbiEncoder('EIP712_COORDINATOR_DOMAIN_HASH()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/coordinator_registry.ts b/packages/abi-gen-wrappers/src/generated-wrappers/coordinator_registry.ts index 827b221b04..57abe22dc0 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/coordinator_registry.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/coordinator_registry.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -40,6 +46,9 @@ export interface CoordinatorRegistryCoordinatorEndpointSetEventArgs extends Deco // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class CoordinatorRegistryContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode: string | undefined; /** * Called by a Coordinator operator to set the endpoint of their Coordinator. @@ -52,7 +61,11 @@ export class CoordinatorRegistryContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(coordinatorEndpoint: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + coordinatorEndpoint: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('coordinatorEndpoint', coordinatorEndpoint); const self = (this as any) as CoordinatorRegistryContract; const encodedData = self._strictEncodeArguments('setCoordinatorEndpoint(string)', [coordinatorEndpoint]); @@ -68,6 +81,10 @@ export class CoordinatorRegistryContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.setCoordinatorEndpoint.callAsync(coordinatorEndpoint, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -82,20 +99,19 @@ export class CoordinatorRegistryContract extends BaseContract { awaitTransactionSuccessAsync( coordinatorEndpoint: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('coordinatorEndpoint', coordinatorEndpoint); const self = (this as any) as CoordinatorRegistryContract; - const txHashPromise = self.setCoordinatorEndpoint.sendTransactionAsync(coordinatorEndpoint, txData); + const txHashPromise = self.setCoordinatorEndpoint.sendTransactionAsync(coordinatorEndpoint, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -125,14 +141,6 @@ export class CoordinatorRegistryContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -196,28 +204,12 @@ export class CoordinatorRegistryContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as CoordinatorRegistryContract; const abiEncoder = self._lookupAbiEncoder('setCoordinatorEndpoint(string)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as CoordinatorRegistryContract; - const abiEncoder = self._lookupAbiEncoder('setCoordinatorEndpoint(string)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -273,45 +265,6 @@ export class CoordinatorRegistryContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param coordinatorOperator operator of the Coordinator endpoint. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(coordinatorOperator: string): string { - assert.isString('coordinatorOperator', coordinatorOperator); - const self = (this as any) as CoordinatorRegistryContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getCoordinatorEndpoint(address)', [ - coordinatorOperator.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as CoordinatorRegistryContract; - const abiEncoder = self._lookupAbiEncoder('getCoordinatorEndpoint(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as CoordinatorRegistryContract; - const abiEncoder = self._lookupAbiEncoder('getCoordinatorEndpoint(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/dev_utils.ts b/packages/abi-gen-wrappers/src/generated-wrappers/dev_utils.ts index ea3cf1904a..70bd9bed76 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/dev_utils.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/dev_utils.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class DevUtilsContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode = '0x608060405234801561001057600080fd5b506004361061025c5760003560e01c80639a7e752611610145578063cafd3a07116100bd578063d3d862d11161008c578063e4e6e7da11610071578063e4e6e7da1461063a578063e77286eb1461065b578063ee4f5a941461067d5761025c565b8063d3d862d114610605578063e25cabf7146106185761025c565b8063cafd3a071461059e578063d001c5dc146105bf578063d186037f146105d2578063d3637905146105e55761025c565b8063a6627e9f11610114578063b43cffe1116100f9578063b43cffe114610548578063bbb2dcf61461055b578063bc03f9641461057d5761025c565b8063a6627e9f14610512578063acaedc74146105255761025c565b80639a7e7526146104985780639eadc835146104bb578063a0901e51146104df578063a5cd62ba146104f25761025c565b8063459be5e2116101d85780636f83188e116101a75780637b66ad341161018c5780637b66ad34146104515780637d727512146104725780638f4ce479146104855761025c565b80636f83188e1461040d5780637914b2ec146104305761025c565b8063459be5e21461038a5780634dfdac20146103ab578063590aa875146103cb57806365129042146103eb5761025c565b80632322cf761161022f578063327d305411610214578063327d30541461033257806332aae3ad146103455780633db6dc61146103675761025c565b80632322cf76146102f0578063314853ff146103105761025c565b806302d0aec31461026157806304a5618a1461028b5780630d7b7d76146102ad578063165979e1146102ce575b600080fd5b61027461026f3660046149dd565b61069f565b6040516102829291906152e4565b60405180910390f35b61029e6102993660046149dd565b6106fb565b60405161028293929190615387565b6102c06102bb366004614565565b6107a9565b604051610282929190615292565b6102e16102dc3660046149dd565b6107cb565b604051610282939291906154c2565b6103036102fe366004614565565b610828565b6040516102829190615731565b61032361031e3660046149dd565b610850565b604051610282939291906152b9565b6102c06103403660046149dd565b610897565b6103586103533660046149dd565b6108d9565b60405161028293929190615438565b61037a6103753660046149dd565b61092c565b6040516102829493929190615258565b61039d6103983660046149dd565b610976565b6040516102829291906154ab565b6103be6103b936600461448c565b6109cc565b60405161028291906151f2565b6103de6103d936600461435d565b610a4f565b60405161028291906153e7565b6103fe6103f93660046149dd565b610ad3565b60405161028293929190614fdf565b61042061041b3660046149dd565b610b0d565b6040516102829493929190615535565b61044361043e3660046149dd565b61164e565b604051610282929190615301565b61046461045f3660046149dd565b611686565b604051610282929190614fc5565b610303610480366004614565565b6116be565b6104436104933660046149dd565b611dd3565b6104ab6104a63660046149dd565b611e63565b60405161028294939291906154f1565b6104ce6104c93660046149dd565b611ec4565b604051610282959493929190615324565b6103be6104ed3660046145d4565b611f6f565b61050561050036600461463a565b611fe8565b60405161028291906150f9565b6103de6105203660046145a9565b6120ac565b6105386105333660046149dd565b612133565b6040516102829493929190615055565b6103de6105563660046144da565b61216f565b61056e6105693660046149dd565b6121fc565b604051610282939291906153b2565b61059061058b3660046149dd565b6122a9565b6040516102829291906152a0565b6105b16105ac3660046149dd565b6122e2565b604051610282929190615528565b6103be6105cd36600461448c565b612330565b6103036105e0366004614565565b61239e565b6105f86105f3366004614a94565b6129e1565b60405161028291906154dd565b6103de6106133660046147e2565b612f7e565b61062b6106263660046146be565b612fb6565b60405161028293929190615146565b61064d61064836600461448c565b6130ee565b604051610282929190615233565b61066e610669366004614aec565b613107565b604051610282939291906156d5565b61069061068b3660046149dd565b613341565b60405161028293929190615481565b6000806106b3836106ae61337e565b6133a2565b60006106cc60048551866133fc9092919063ffffffff16565b8060200190516106df9190810190614990565b909350905060ff811660068111156106f357fe5b915050915091565b6000808061070f848263ffffffff61343f16565b92506001600160e01b031983167f02571792000000000000000000000000000000000000000000000000000000001461077d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107749061569e565b60405180910390fd5b61078e84601063ffffffff61347316565b91506107a184602463ffffffff6134a616565b929491935050565b6000806107b684846116be565b91506107c2848461239e565b90509250929050565b60008060006107dc846106ae6134b2565b60006107f560048651876133fc9092919063ffffffff16565b8060200190516108089190810190614d20565b9094509250905060ff8116600281111561081e57fe5b9350509193909250565b600080600061083785856107a9565b9150915061084582826134d6565b925050505b92915050565b6000606080610861846106ae6134ec565b835161087790859060049063ffffffff6133fc16565b80602001905161088a9190810190614930565b9196909550909350915050565b6000806108a6836106ae613510565b82516108bc90849060049063ffffffff6133fc16565b8060200190516108cf91908101906148d2565b9094909350915050565b60008060606108ea846106ae613534565b600061090360048651876133fc9092919063ffffffff16565b8060200190516109169190810190614cd4565b9094509250905060ff8116600181111561081e57fe5b60008060608061093e856106ae613558565b845161095490869060049063ffffffff6133fc16565b806020019051610967919081019061488e565b92989197509550909350915050565b600080610985836106ae61357c565b600061099e60048551866133fc9092919063ffffffff16565b8060200190516109b19190810190614c07565b9250905060ff811660038111156109c457fe5b925050915091565b6060600082519050806040519080825280602002602001820160405280156109fe578160200160208202803883390190505b50915060005b818114610a4757610a2885858381518110610a1b57fe5b602002602001015161239e565b838281518110610a3457fe5b6020908102919091010152600101610a04565b505092915050565b6040516060907ff47261b00000000000000000000000000000000000000000000000000000000090610a85908490602401614fb1565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b0319909316929092179091529050919050565b6000806000610ae4846106ae6135a0565b8351610afa90859060049063ffffffff6133fc16565b80602001905161088a91908101906143b2565b60608080806000610b24868263ffffffff61343f16565b90506001600160e01b031981167fdedfc1f1000000000000000000000000000000000000000000000000000000001415610b95576040518060400160405280601181526020017f626174636843616e63656c4f72646572730000000000000000000000000000008152509450611124565b6001600160e01b031981167f9694a402000000000000000000000000000000000000000000000000000000001415610c04576040518060400160405280600f81526020017f626174636846696c6c4f726465727300000000000000000000000000000000008152509450611124565b6001600160e01b031981167f8ea8dfe4000000000000000000000000000000000000000000000000000000001415610c73576040518060400160405280601681526020017f626174636846696c6c4f72646572734e6f5468726f77000000000000000000008152509450611124565b6001600160e01b031981167fbeee2e14000000000000000000000000000000000000000000000000000000001415610ce2576040518060400160405280601581526020017f626174636846696c6c4f724b696c6c4f726465727300000000000000000000008152509450611124565b6001600160e01b031981167f2da62987000000000000000000000000000000000000000000000000000000001415610d51576040518060400160405280600b81526020017f63616e63656c4f726465720000000000000000000000000000000000000000008152509450611124565b6001600160e01b031981167f9b44d556000000000000000000000000000000000000000000000000000000001415610dc0576040518060400160405280600981526020017f66696c6c4f7264657200000000000000000000000000000000000000000000008152509450611124565b6001600160e01b031981167fe14b58c4000000000000000000000000000000000000000000000000000000001415610e2f576040518060400160405280600f81526020017f66696c6c4f724b696c6c4f7264657200000000000000000000000000000000008152509450611124565b6001600160e01b031981167f78d29ac1000000000000000000000000000000000000000000000000000000001415610e9e576040518060400160405280601681526020017f6d61726b65744275794f72646572734e6f5468726f77000000000000000000008152509450611124565b6001600160e01b031981167f369da099000000000000000000000000000000000000000000000000000000001415610f0d576040518060400160405280601781526020017f6d61726b657453656c6c4f72646572734e6f5468726f770000000000000000008152509450611124565b6001600160e01b031981167f8bc8efb3000000000000000000000000000000000000000000000000000000001415610f7c576040518060400160405280601981526020017f6d61726b65744275794f726465727346696c6c4f724b696c6c000000000000008152509450611124565b6001600160e01b031981167fa6c3bf33000000000000000000000000000000000000000000000000000000001415610feb576040518060400160405280601a81526020017f6d61726b657453656c6c4f726465727346696c6c4f724b696c6c0000000000008152509450611124565b6001600160e01b031981167f88ec79fb00000000000000000000000000000000000000000000000000000000141561105a576040518060400160405280600b81526020017f6d617463684f72646572730000000000000000000000000000000000000000008152509450611124565b6001600160e01b031981167f4f9559b10000000000000000000000000000000000000000000000000000000014806110bb57506001600160e01b031981167f2280c91000000000000000000000000000000000000000000000000000000000145b156110f2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077490615630565b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610774906155f9565b6001600160e01b031981167fdedfc1f10000000000000000000000000000000000000000000000000000000014156111c957855161116c90879060049063ffffffff6135c416565b80602001905161117f9190810190614607565b604080516000808252602082019092529195505b50604080516000808252602082019092529194506111c1565b60608152602001906001900390816111ac5790505b509150611646565b6001600160e01b031981167fbeee2e1400000000000000000000000000000000000000000000000000000000148061122a57506001600160e01b031981167f9694a40200000000000000000000000000000000000000000000000000000000145b8061125e57506001600160e01b031981167f8ea8dfe400000000000000000000000000000000000000000000000000000000145b156112785761126c86613644565b91955093509150611646565b6001600160e01b031981167f2da629870000000000000000000000000000000000000000000000000000000014156113605760408051600180825281830190925290816020015b6112c7613c90565b8152602001906001900390816112bf57505086519094506112f290879060049063ffffffff6135c416565b8060200190516113059190810190614a61565b8460008151811061131257fe5b602002602001018190525060006040519080825280602002602001820160405280156111935781602001602082028038833901905050604080516000808252602082019092529194506111c1565b6001600160e01b031981167fe14b58c40000000000000000000000000000000000000000000000000000000014806113c157506001600160e01b031981167f9b44d55600000000000000000000000000000000000000000000000000000000145b156113cf5761126c86613673565b6001600160e01b031981167f78d29ac100000000000000000000000000000000000000000000000000000000148061143057506001600160e01b031981167f369da09900000000000000000000000000000000000000000000000000000000145b8061146457506001600160e01b031981167f8bc8efb300000000000000000000000000000000000000000000000000000000145b8061149857506001600160e01b031981167fa6c3bf3300000000000000000000000000000000000000000000000000000000145b156114a65761126c8661376d565b6001600160e01b031981167f88ec79fb000000000000000000000000000000000000000000000000000000001415611646576114e0613c90565b6114e8613c90565b60608061150260048b518c6135c49092919063ffffffff16565b8060200190516115159190810190614b43565b604080516002808252606082019092529498509296509094509250816020015b61153d613c90565b815260200190600190039081611535579050509750838860008151811061156057fe5b6020026020010181905250828860018151811061157957fe5b602090810291909101015260408051600280825260608201909252908160200160208202803883390190505096508360a00151876000815181106115b957fe5b6020026020010181815250508260a00151876001815181106115d757fe5b60209081029190910101526040805160028082526060820190925290816020015b60608152602001906001900390816115f8579050509550818660008151811061161d57fe5b6020026020010181905250808660018151811061163657fe5b6020026020010181905250505050505b509193509193565b60008061165d836106ae6137e1565b825161167390849060049063ffffffff6133fc16565b8060200190516108cf91908101906149b4565b600080611695836106ae613805565b82516116ab90849060049063ffffffff6133fc16565b8060200190516108cf9190810190614379565b6000806116d1838263ffffffff61343f16565b90506001600160e01b031981167ff47261b000000000000000000000000000000000000000000000000000000000141561184657600061171884601063ffffffff61347316565b6040519091506060907f70a082310000000000000000000000000000000000000000000000000000000090611751908890602401614fb1565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060006060836001600160a01b0316836040516117cc9190614f95565b600060405180830381855afa9150503d8060008114611807576040519150601f19603f3d011682016040523d82523d6000602084013e61180c565b606091505b509150915081801561181f575080516020145b61182a57600061183b565b61183b81600063ffffffff6134a616565b955050505050611dcc565b6001600160e01b031981167f025717920000000000000000000000000000000000000000000000000000000014156119e157600080611884856106fb565b6040519194509250606091507f6352211e00000000000000000000000000000000000000000000000000000000906118c0908490602401615731565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060006060846001600160a01b03168360405161193b9190614f95565b600060405180830381855afa9150503d8060008114611976576040519150601f19603f3d011682016040523d82523d6000602084013e61197b565b606091505b50915091506000828015611990575081516020145b61199b5760006119ac565b6119ac82600c63ffffffff61347316565b9050896001600160a01b0316816001600160a01b0316146119ce5760006119d1565b60015b60ff169750505050505050611dcc565b6001600160e01b031981167fa7cb5fb7000000000000000000000000000000000000000000000000000000001415611bc4576000606080611a2186611ec4565b5081519296509094509250905060005b818114611bba5783516060907efdd58e00000000000000000000000000000000000000000000000000000000908b90879085908110611a6c57fe5b6020026020010151604051602401611a85929190615089565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060006060876001600160a01b031683604051611b009190614f95565b600060405180830381855afa9150503d8060008114611b3b576040519150601f19603f3d011682016040523d82523d6000602084013e611b40565b606091505b50915091506000828015611b55575081516020145b611b60576000611b71565b611b7182600063ffffffff6134a616565b90506000878681518110611b8157fe5b60200260200101518281611b9157fe5b0490508b811080611ba057508b155b15611ba957809b505b505060019093019250611a31915050565b5050505050611dcc565b6001600160e01b031981167fc339d10a000000000000000000000000000000000000000000000000000000001415611d15576040516060907fa85e59e40000000000000000000000000000000000000000000000000000000090611c33908690600090819081906024016153fa565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b03199094169390931790925260045491519092506000916001600160a01b031690611c9a908490614f95565b600060405180830381855afa9150503d8060008114611cd5576040519150601f19603f3d011682016040523d82523d6000602084013e611cda565b606091505b5050905080611cea576000611d0c565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5b93505050611dcc565b6001600160e01b031981167f94cfcdd7000000000000000000000000000000000000000000000000000000001415611dcc57606080611d53856121fc565b80519194509250905060005b818114611dc7576000611d8589858481518110611d7857fe5b60200260200101516116be565b90506000858381518110611d9557fe5b60200260200101518281611da557fe5b04905087811080611db4575087155b15611dbd578097505b5050600101611d5f565b505050505b5092915050565b600080611de6838263ffffffff61343f16565b91506001600160e01b031982167ff47261b00000000000000000000000000000000000000000000000000000000014611e4b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107749061569e565b611e5c83601063ffffffff61347316565b9050915091565b60008060006060611e76856106ae613829565b6000611e8f60048751886133fc9092919063ffffffff16565b806020019051611ea29190810190614c76565b91965094509250905060ff81166006811115611eba57fe5b9450509193509193565b60008060608080611edb868563ffffffff61343f16565b94506001600160e01b031985167fa7cb5fb70000000000000000000000000000000000000000000000000000000014611f40576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107749061569e565b505050506024828101516044840151606485015160848601519496929591820184019490820184019391010190565b6060808251604051908082528060200260200182016040528015611f9d578160200160208202803883390190505b50905060005b83518114611dcc57838181518110611fb757fe5b60200260200101516001600160a01b031631828281518110611fd557fe5b6020908102919091010152600101611fa3565b60606000845190508060405190808252806020026020018201604052801561201a578160200160208202803883390190505b50915060005b8181146120a25761206b86828151811061203657fe5b602002602001015186838151811061204a57fe5b602002602001015186848151811061205e57fe5b60200260200101516129e1565b83828151811061207757fe5b6020026020010190600481111561208a57fe5b9081600481111561209757fe5b905250600101612020565b50505b9392505050565b6040516060907f0257179200000000000000000000000000000000000000000000000000000000906120e49085908590602401615089565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b031990931692909217909152905092915050565b60006060806060612146856106ae61384d565b845161215c90869060049063ffffffff6133fc16565b80602001905161096791908101906143f4565b6040516060907fa7cb5fb700000000000000000000000000000000000000000000000000000000906121ab908790879087908790602401615003565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b0319909316929092179091529050949350505050565b6000606080612211848463ffffffff61343f16565b92506001600160e01b031983167f94cfcdd70000000000000000000000000000000000000000000000000000000014612276576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107749061569e565b835161228c90859060049063ffffffff6135c416565b80602001905161229f9190810190614817565b9395909450915050565b600060606122b9836106ae613871565b82516122cf90849060049063ffffffff6133fc16565b8060200190516108cf91908101906148f5565b6000806122f1836106ae613895565b600061230a60048551866133fc9092919063ffffffff16565b80602001905161231d9190810190614c07565b9250905060ff811660018111156109c457fe5b606060008251905080604051908082528060200260200182016040528015612362578160200160208202803883390190505b50915060005b818114610a475761237f85858381518110611d7857fe5b83828151811061238b57fe5b6020908102919091010152600101612368565b6000806123b1838263ffffffff61343f16565b90506001600160e01b031981167f94cfcdd7000000000000000000000000000000000000000000000000000000001415612463576060806123f1856121fc565b80519194509250905060005b81811461245857600061241689858481518110610a1b57fe5b9050600085838151811061242657fe5b6020026020010151828161243657fe5b04905087811080612445575087155b1561244e578097505b50506001016123fd565b5061084a9350505050565b6001600160e01b031981167ff47261b00000000000000000000000000000000000000000000000000000000014156124ee5760006124a884601063ffffffff61347316565b6001546040519192506060917fdd62ed3e00000000000000000000000000000000000000000000000000000000916117519189916001600160a01b031690602401614fc5565b6001600160e01b031981167f025717920000000000000000000000000000000000000000000000000000000014156127de5760008061252c856106fb565b600254604051929550909350606092507fe985e9c50000000000000000000000000000000000000000000000000000000091612578918a916001600160a01b0390911690602401614fc5565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060006060846001600160a01b0316836040516125f39190614f95565b600060405180830381855afa9150503d806000811461262e576040519150601f19603f3d011682016040523d82523d6000602084013e612633565b606091505b509150915081158061264757508051602014155b80612663575061265e81600063ffffffff6134a616565b600114155b156127b1576040516060907f081812fc000000000000000000000000000000000000000000000000000000009061269e908790602401615731565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050856001600160a01b0316816040516127159190614f95565b600060405180830381855afa9150503d8060008114612750576040519150601f19603f3d011682016040523d82523d6000602084013e612755565b606091505b509093509150828015612769575081516020145b801561279857506002546001600160a01b031661278d83600c63ffffffff61347316565b6001600160a01b0316145b6127a35760006127a6565b60015b60ff16975050611bba565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff96505050505050611dcc565b6001600160e01b031981167fa7cb5fb700000000000000000000000000000000000000000000000000000000141561298657600061281b84611ec4565b5050600354604051929450606093507fe985e9c50000000000000000000000000000000000000000000000000000000092612865925089916001600160a01b031690602401614fc5565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050905060006060836001600160a01b0316836040516128e09190614f95565b600060405180830381855afa9150503d806000811461291b576040519150601f19603f3d011682016040523d82523d6000602084013e612920565b606091505b5091509150818015612933575080516020145b801561294f575061294b81600063ffffffff6134a616565b6001145b61295a57600061183b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff955050505050611dcc565b6001600160e01b031981167fc339d10a000000000000000000000000000000000000000000000000000000001415611dcc57507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9392505050565b60006129eb613d23565b612a7c8584600560009054906101000a90046001600160a01b03166001600160a01b0316631ce4c78b6040518163ffffffff1660e01b815260040160206040518083038186803b158015612a3e57600080fd5b505afa158015612a52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250612a769190810190614bef565b3a6138b9565b60408051600480825260a0820190925291925060609190816020015b6060815260200190600190039081612a9857505060408051600480825260a082019092529192506060919060208201608080388339505060408051600480825260a08201909252929350606092915060208201608080388339505060408051600480825260a0820190925292935060609291506020820160808038833901905050905088610160015184600081518110612b2e57fe5b60200260200101819052508783600081518110612b4757fe5b60200260200101906001600160a01b031690816001600160a01b031681525050886000015182600081518110612b7957fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508681600081518110612ba757fe5b60200260200101818152505088610140015184600181518110612bc657fe5b6020026020010181905250886000015183600181518110612be357fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508782600181518110612c1157fe5b60200260200101906001600160a01b031690816001600160a01b031681525050846000015181600181518110612c4357fe5b602002602001018181525050886101a0015184600281518110612c6257fe5b60200260200101819052508783600281518110612c7b57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050886040015182600281518110612cad57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050846060015181600281518110612cdf57fe5b60200260200101818152505088610180015184600381518110612cfe57fe5b6020026020010181905250886000015183600381518110612d1b57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050886040015182600381518110612d4d57fe5b60200260200101906001600160a01b031690816001600160a01b031681525050846040015181600381518110612d7f57fe5b60209081029190910101526040516060907fb04fbddd0000000000000000000000000000000000000000000000000000000090612dc69087908790879087906024016150a2565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b03199094169390931790925260055491519092506060916001600160a01b031690612e2d908490614f95565b6000604051808303816000865af19150503d8060008114612e6a576040519150601f19603f3d011682016040523d82523d6000602084013e612e6f565b606091505b50915060009050612e86828263ffffffff61343f16565b9050612e90613534565b6001600160e01b031982811691161415612ed2576000612eaf836108d9565b5091505060ff81166004811115612ec257fe5b99505050505050505050506120a5565b612eda6134ec565b6001600160e01b031982811691161415612f0d576000612ef983610850565b509091505060ff81166004811115612ec257fe5b815160208301207ff43f26ea5a94b478394a975e856464913dc1a8a1ca70939d974aa7c238aa0ce01415612f4c576004985050505050505050506120a5565b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610774906155c2565b6040516060907f94cfcdd700000000000000000000000000000000000000000000000000000000906120e49085908590602401615205565b606080606060008551905080604051908082528060200260200182016040528015612ffb57816020015b612fe8613d52565b815260200190600190039081612fe05790505b50935080604051908082528060200260200182016040528015613028578160200160208202803883390190505b50925080604051908082528060200260200182016040528015613055578160200160208202803883390190505b50915060005b8181146130e55761309287828151811061307157fe5b602002602001015187838151811061308557fe5b6020026020010151613107565b87518890859081106130a057fe5b602002602001018785815181106130b357fe5b602002602001018786815181106130c657fe5b931515602094850291909101909301929092529190525260010161305b565b50509250925092565b6060806130fb8484612330565b91506107c284846109cc565b61310f613d52565b600080546040517f9d3fa4b900000000000000000000000000000000000000000000000000000000815282916001600160a01b031690639d3fa4b9906131599088906004016156f9565b60606040518083038186803b15801561317157600080fd5b505afa158015613185573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506131a99190810190614a10565b85516000546040517fa12dcc6f00000000000000000000000000000000000000000000000000000000815292955090916001600160a01b039091169063a12dcc6f906131fb908990899060040161570c565b60206040518083038186803b15801561321357600080fd5b505afa158015613227573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061324b919081019061486e565b9150600061325e82886101400151610828565b60a088015160c08901516101808a01516101408b01519394509192909160009161328d9163ffffffff61393016565b156132ba576132b3846132ad848d6080015161395590919063ffffffff16565b85613971565b9050613313565b816132ce576132b3848b6080015185613971565b60006132df868c6101800151610828565b905060006132f2868d6080015187613971565b90506000613301838688613971565b905061330d82826134d6565b93505050505b61333361332d89604001518561399b90919063ffffffff16565b826134d6565b965050505050509250925092565b6000806000613352846106ae6139ba565b600061336b60048651876133fc9092919063ffffffff16565b8060200190516108089190810190614c34565b7ffdb6ca8d0000000000000000000000000000000000000000000000000000000090565b60006133af83600061343f565b90506001600160e01b0319808216908316146133f7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077490615667565b505050565b60608183111561341a5761341a613415600085856139de565b613a4d565b83518211156134335761343361341560018487516139de565b50819003910190815290565b600081600401835110156134605761346061341560038551856004016139de565b5001602001516001600160e01b03191690565b600081601401835110156134945761349461341560048551856014016139de565b5001601401516001600160a01b031690565b60006120a58383613a55565b7f18e4b1410000000000000000000000000000000000000000000000000000000090565b60008183106134e557816120a5565b5090919050565b7f4678472b0000000000000000000000000000000000000000000000000000000090565b7fb6555d6f0000000000000000000000000000000000000000000000000000000090565b7f488219a60000000000000000000000000000000000000000000000000000000090565b7f1b8388f70000000000000000000000000000000000000000000000000000000090565b7fe94a7ed00000000000000000000000000000000000000000000000000000000090565b7f4ad312750000000000000000000000000000000000000000000000000000000090565b6060818311156135dd576135dd613415600085856139de565b83518211156135f6576135f661341560018487516139de565b8282036040519080825280601f01601f191660200182016040528015613623576020820181803883390190505b5090506120a561363282613a7f565b8461363c87613a7f565b018351613a85565b606080606061366060048551866135c49092919063ffffffff16565b80602001905161088a9190810190614715565b60408051600180825281830190925260609182918291816020015b613696613c90565b81526020019060019003908161368e5750506040805160018082528183019092529194506020808301908038833901905050604080516001808252818301909252919350816020015b60608152602001906001900390816136df575050845190915061370c90859060049063ffffffff6135c416565b80602001905161371f9190810190614b9c565b8560008151811061372c57fe5b602002602001018560008151811061374057fe5b602002602001018560008151811061375457fe5b6020908102919091010192909252919052529193909250565b6040805160018082528183019092526060918291829160208083019080388339505085519193506137a99186915060049063ffffffff6135c416565b8060200190516137bc919081019061478f565b845185906000906137c957fe5b60209081029190910101919091529095929450925050565b7f11c7b7200000000000000000000000000000000000000000000000000000000090565b7fa15c0d060000000000000000000000000000000000000000000000000000000090565b7f7e5a23180000000000000000000000000000000000000000000000000000000090565b7f5bd0428d0000000000000000000000000000000000000000000000000000000090565b7f20d11f610000000000000000000000000000000000000000000000000000000090565b7ff59851840000000000000000000000000000000000000000000000000000000090565b6138c1613d23565b6020810184905260a085015160808601516138dd918691613b2a565b815260a085015160c08601516138f4918691613b2a565b604082015260a085015160e086015161390e918691613b2a565b6060820152613923828463ffffffff613b5e16565b6080820152949350505050565b6000815183511480156120a55750508051602091820120825192909101919091201490565b6000828201838110156120a5576120a561341560008686613b8b565b600061399383613987868563ffffffff613b5e16565b9063ffffffff613baa16565b949350505050565b6000828211156139b4576139b461341560028585613b8b565b50900390565b7fe53c76c80000000000000000000000000000000000000000000000000000000090565b6060632800659560e01b8484846040516024016139fd939291906154cf565b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff166001600160e01b03199093169290921790915290509392505050565b805160208201fd5b60008160200183511015613a7657613a7661341560058551856020016139de565b50016020015190565b60200190565b6020811015613aaf576001816020036101000a0380198351168185511680821786525050506133f7565b82821415613abc576133f7565b82821115613af65760208103905080820181840181515b82851015613aee578451865260209586019590940193613ad3565b9052506133f7565b60208103905080820181840183515b81861215613b215782518252601f199283019290910190613b05565b85525050505050565b6000613b37848484613bd4565b15613b4a57613b4a613415858585613c3a565b61399383613987868563ffffffff613b5e16565b600082613b6d5750600061084a565b82820282848281613b7a57fe5b04146120a5576120a5613415600186865b606063e946c1bb60e01b8484846040516024016139fd93929190615460565b600081613bc057613bc061341560038585613b8b565b6000828481613bcb57fe5b04949350505050565b600082613be657613be6613415613c59565b811580613bf1575083155b15613bfe575060006120a5565b60008380613c0857fe5b8584099050613c1d858463ffffffff613b5e16565b613c2f826103e863ffffffff613b5e16565b101595945050505050565b606063339f3de260e01b8484846040516024016139fd9392919061573a565b60408051808201909152600481527fa791837c00000000000000000000000000000000000000000000000000000000602082015290565b604051806101c0016040528060006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001606081526020016060815260200160608152602001606081525090565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b604080516060810182526000808252602082018190529181019190915290565b803561084a81615816565b805161084a81615816565b600082601f830112613d98578081fd5b8135613dab613da682615777565b615750565b818152915060208083019084810181840286018201871015613dcc57600080fd5b60005b84811015611dc7578135613de281615816565b84529282019290820190600101613dcf565b600082601f830112613e04578081fd5b8151613e12613da682615777565b8181529150602080830190840160005b83811015613e4f57613e3a8760208451890101614074565b83526020928301929190910190600101613e22565b5050505092915050565b600082601f830112613e69578081fd5b8135613e77613da682615777565b8181529150602080830190840160005b83811015613e4f57613e9f8760208435890101614026565b83526020928301929190910190600101613e87565b600082601f830112613ec4578081fd5b8151613ed2613da682615777565b8181529150602080830190840160005b83811015613e4f57613efa8760208451890101614209565b83526020928301929190910190600101613ee2565b600082601f830112613f1f578081fd5b8135613f2d613da682615777565b8181529150602080830190840160005b83811015613e4f57613f5587602084358901016140ba565b83526020928301929190910190600101613f3d565b600082601f830112613f7a578081fd5b8151613f88613da682615777565b818152915060208083019084810181840286018201871015613fa957600080fd5b60005b84811015611dc757815184529282019290820190600101613fac565b600082601f830112613fd8578081fd5b8135613fe6613da682615777565b81815291506020808301908481018184028601820187101561400757600080fd5b60005b84811015611dc75781358452928201929082019060010161400a565b600082601f830112614036578081fd5b8135614044613da682615797565b915080825283602082850101111561405b57600080fd5b8060208401602084013760009082016020015292915050565b600082601f830112614084578081fd5b8151614092613da682615797565b91508082528360208285010111156140a957600080fd5b611dcc8160208401602086016157bb565b60006101c08083850312156140cd578182fd5b6140d681615750565b9150506140e38383613d72565b81526140f28360208401613d72565b60208201526141048360408401613d72565b60408201526141168360608401613d72565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e08201526101008083013581830152506101208083013581830152506101408083013567ffffffffffffffff8082111561417857600080fd5b61418486838701614026565b838501526101609250828501359150808211156141a057600080fd5b6141ac86838701614026565b838501526101809250828501359150808211156141c857600080fd5b6141d486838701614026565b838501526101a09250828501359150808211156141f057600080fd5b506141fd85828601614026565b82840152505092915050565b60006101c080838503121561421c578182fd5b61422581615750565b9150506142328383613d7d565b81526142418360208401613d7d565b60208201526142538360408401613d7d565b60408201526142658360608401613d7d565b60608201526080820151608082015260a082015160a082015260c082015160c082015260e082015160e08201526101008083015181830152506101208083015181830152506101408083015167ffffffffffffffff808211156142c757600080fd5b6142d386838701614074565b838501526101609250828501519150808211156142ef57600080fd5b6142fb86838701614074565b8385015261018092508285015191508082111561431757600080fd5b61432386838701614074565b838501526101a092508285015191508082111561433f57600080fd5b506141fd85828601614074565b805160ff8116811461084a57600080fd5b60006020828403121561436e578081fd5b81356120a581615816565b6000806040838503121561438b578081fd5b825161439681615816565b60208401519092506143a781615816565b809150509250929050565b6000806000606084860312156143c6578081fd5b83516143d181615816565b60208501519093506143e281615816565b80925050604084015190509250925092565b60008060008060808587031215614409578182fd5b845161441481615816565b602086015190945067ffffffffffffffff80821115614431578384fd5b61443d88838901614074565b94506040870151915080821115614452578384fd5b61445e88838901614074565b93506060870151915080821115614473578283fd5b5061448087828801614074565b91505092959194509250565b6000806040838503121561449e578182fd5b82356144a981615816565b9150602083013567ffffffffffffffff8111156144c4578182fd5b6144d085828601613e59565b9150509250929050565b600080600080608085870312156144ef578182fd5b84356144fa81615816565b9350602085013567ffffffffffffffff80821115614516578384fd5b61452288838901613fc8565b94506040870135915080821115614537578384fd5b61454388838901613fc8565b93506060870135915080821115614558578283fd5b5061448087828801614026565b60008060408385031215614577578182fd5b823561458281615816565b9150602083013567ffffffffffffffff81111561459d578182fd5b6144d085828601614026565b600080604083850312156145bb578182fd5b82356145c681615816565b946020939093013593505050565b6000602082840312156145e5578081fd5b813567ffffffffffffffff8111156145fb578182fd5b61399384828501613d88565b600060208284031215614618578081fd5b815167ffffffffffffffff81111561462e578182fd5b61399384828501613eb4565b60008060006060848603121561464e578081fd5b833567ffffffffffffffff80821115614665578283fd5b61467187838801613f0f565b94506020860135915080821115614686578283fd5b61469287838801613d88565b935060408601359150808211156146a7578283fd5b506146b486828701613fc8565b9150509250925092565b600080604083850312156146d0578182fd5b823567ffffffffffffffff808211156146e7578384fd5b6146f386838701613f0f565b93506020850135915080821115614708578283fd5b506144d085828601613e59565b600080600060608486031215614729578081fd5b835167ffffffffffffffff80821115614740578283fd5b61474c87838801613eb4565b94506020860151915080821115614761578283fd5b61476d87838801613f6a565b93506040860151915080821115614782578283fd5b506146b486828701613df4565b6000806000606084860312156147a3578081fd5b835167ffffffffffffffff808211156147ba578283fd5b6147c687838801613eb4565b9450602086015193506040860151915080821115614782578283fd5b600080604083850312156147f4578182fd5b823567ffffffffffffffff8082111561480b578384fd5b6146f386838701613fc8565b60008060408385031215614829578182fd5b825167ffffffffffffffff80821115614840578384fd5b61484c86838701613f6a565b93506020850151915080821115614861578283fd5b506144d085828601613df4565b60006020828403121561487f578081fd5b815180151581146120a5578182fd5b600080600080608085870312156148a3578182fd5b8451935060208501516148b581615816565b604086015190935067ffffffffffffffff80821115614452578384fd5b600080604083850312156148e4578182fd5b505080516020909101519092909150565b60008060408385031215614907578182fd5b82519150602083015167ffffffffffffffff811115614924578182fd5b6144d085828601614074565b600080600060608486031215614944578081fd5b83519250602084015167ffffffffffffffff80821115614962578283fd5b61496e87838801614074565b93506040860151915080821115614983578283fd5b506146b486828701614074565b600080604083850312156149a2578182fd5b8251915060208301516143a78161582b565b600080604083850312156149c6578182fd5b82516001600160e01b031981168114614396578283fd5b6000602082840312156149ee578081fd5b813567ffffffffffffffff811115614a04578182fd5b61399384828501614026565b60006060828403128015614a22578182fd5b8015614a2c578182fd5b50614a376060615750565b8251614a428161582b565b8152602083810151908201526040928301519281019290925250919050565b600060208284031215614a72578081fd5b815167ffffffffffffffff811115614a88578182fd5b61399384828501614209565b600080600060608486031215614aa8578081fd5b833567ffffffffffffffff811115614abe578182fd5b614aca868287016140ba565b9350506020840135614adb81615816565b929592945050506040919091013590565b60008060408385031215614afe578182fd5b823567ffffffffffffffff80821115614b15578384fd5b614b21868387016140ba565b93506020850135915080821115614b36578283fd5b506144d085828601614026565b60008060008060808587031215614b58578182fd5b845167ffffffffffffffff80821115614b6f578384fd5b614b7b88838901614209565b95506020870151915080821115614b90578384fd5b61443d88838901614209565b600080600060608486031215614bb0578081fd5b835167ffffffffffffffff80821115614bc7578283fd5b614bd387838801614209565b9450602086015193506040860151915080821115614983578283fd5b600060208284031215614c00578081fd5b5051919050565b60008060408385031215614c19578182fd5b8251614c248161582b565b6020939093015192949293505050565b600080600060608486031215614c48578081fd5b8351614c538161582b565b602085015160408601519194509250614c6b81615816565b809150509250925092565b60008060008060808587031215614c8b578182fd5b614c95868661434c565b9350602085015192506040850151614cac81615816565b606086015190925067ffffffffffffffff811115614cc8578182fd5b61448087828801614074565b600080600060608486031215614ce8578081fd5b614cf2858561434c565b925060208401519150604084015167ffffffffffffffff811115614d14578182fd5b6146b486828701614074565b600080600060608486031215614d34578081fd5b614d3e858561434c565b925060208401519150604084015190509250925092565b1515815260200190565b6000614d6b8383614e78565b505060600190565b6001600160a01b03169052565b6000815180845260208401935060208301825b82811015614dba5781516001600160a01b0316865260209586019590910190600101614d93565b5093949350505050565b600081518084526020840180819550602083028101915060208501845b84811015614e0f578284038852614df9848351614e4c565b6020988901989094509190910190600101614de1565b50919695505050505050565b6000815180845260208401935060208301825b82811015614dba578151865260209586019590910190600101614e2e565b60008151808452614e648160208601602086016157bb565b601f01601f19169290920160200192915050565b805160ff16825260208082015190830152604090810151910152565b60006101c0614ea4848451614d73565b6020830151614eb66020860182614d73565b506040830151614ec96040860182614d73565b506060830151614edc6060860182614d73565b506080830151608085015260a083015160a085015260c083015160c085015260e083015160e0850152610100808401518186015250610120808401518186015250610140808401518282870152614f3583870182614e4c565b91505061016091508184015185820383870152614f528282614e4c565b925050506101808084015185830382870152614f6e8382614e4c565b9150506101a091508184015185820383870152614f8b8282614e4c565b9695505050505050565b60008251614fa78184602087016157bb565b9190910192915050565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b60006001600160a01b0386168252608060208301526150256080830186614e1b565b82810360408401526150378186614e1b565b83810360608501526150498186614e4c565b98975050505050505050565b60006001600160a01b0386168252608060208301526150776080830186614e4c565b82810360408401526150378186614e4c565b6001600160a01b03929092168252602082015260400190565b6000608082526150b56080830187614dc4565b82810360208401526150c78187614d80565b83810360408501526150d98187614d80565b91505082810360608401526150ee8185614e1b565b979650505050505050565b602080825282518282018190526000918401906040840190835b8181101561513b5783516005811061512757fe5b835260209384019390920191600101615113565b509095945050505050565b6000606082016060835280865161515d8184615731565b9150602088019250835b8181101561518b5761517a838551614d5f565b602094909401939250600101615167565b5050838103602085015261519f8187614e1b565b91505082810360408401528084516151b78184615731565b9150602086019250835b818110156151e5576151d4838551614d55565b6020949094019392506001016151c1565b5090979650505050505050565b6000602082526120a56020830184614e1b565b6000604082526152186040830185614e1b565b828103602084015261522a8185614dc4565b95945050505050565b6000604082526152466040830185614e1b565b828103602084015261522a8185614e1b565b60008582526001600160a01b0385166020830152608060408301526152806080830185614e4c565b82810360608401526150ee8185614e4c565b918252602082015260400190565b6000838252604060208301526139936040830184614e4c565b6000848252606060208301526152d26060830185614e4c565b8281036040840152614f8b8185614e4c565b828152604081016152f48361580c565b8260208301529392505050565b6001600160e01b03199290921682526001600160a01b0316602082015260400190565b60006001600160e01b0319871682526001600160a01b038616602083015260a0604083015261535660a0830186614e1b565b82810360608401526153688186614e1b565b838103608085015261537a8186614e4c565b9998505050505050505050565b6001600160e01b03199390931683526001600160a01b03919091166020830152604082015260600190565b60006001600160e01b031985168252606060208301526153d56060830185614e1b565b8281036040840152614f8b8185614dc4565b6000602082526120a56020830184614e4c565b60006080825261540d6080830187614e4c565b6001600160a01b03958616602084015293909416604082015260ff9190911660609091015292915050565b6000615443856157eb565b8482528360208301526060604083015261522a6060830184614e4c565b6060810161546d856157f8565b938152602081019290925260409091015290565b6060810161548e85615802565b93815260208101929092526001600160a01b031660409091015290565b604081016154b8846157f8565b9281526020015290565b6060810161546d85615802565b606081016008851061546d57fe5b60208101600583106154eb57fe5b91905290565b60006154fc8661580c565b8582528460208301526001600160a01b038416604083015260806060830152614f8b6080830184614e4c565b604081016154b8846157eb565b6000608082526155486080830187614e4c565b602083820381850152818751808452828401915082838202850101838a01865b8381101561559657601f19878403018552615584838351614e94565b94860194925090850190600101615568565b505086810360408801526155aa818a614e1b565b94505050505082810360608401526150ee8185614dc4565b60208082526013908201527f554e4b4e4f574e5f52455455524e5f4441544100000000000000000000000000604082015260600190565b60208082526019908201527f554e4b4e4f574e5f46554e4354494f4e5f53454c4543544f5200000000000000604082015260600190565b6020808252600d908201527f554e494d504c454d454e54454400000000000000000000000000000000000000604082015260600190565b6020808252600c908201527f4241445f53454c4543544f520000000000000000000000000000000000000000604082015260600190565b6020808252600e908201527f57524f4e475f50524f58595f4944000000000000000000000000000000000000604082015260600190565b60a081016156e38286614e78565b8360608301528215156080830152949350505050565b6000602082526120a56020830184614e94565b60006040825261571f6040830185614e94565b828103602084015261522a8185614e4c565b90815260200190565b9283526020830191909152604082015260600190565b60405181810167ffffffffffffffff8111828210171561576f57600080fd5b604052919050565b600067ffffffffffffffff82111561578d578081fd5b5060209081020190565b600067ffffffffffffffff8211156157ad578081fd5b50601f01601f191660200190565b60005b838110156157d65781810151838201526020016157be565b838111156157e5576000848401525b50505050565b600281106157f557fe5b50565b600481106157f557fe5b600381106157f557fe5b600781106157f557fe5b6001600160a01b03811681146157f557600080fd5b60ff811681146157f557600080fdfea365627a7a723158200ea049525ebc74d73f3bf7858c601bd21168267b0dfb4abbdb7787cfd7233a2c6c6578706572696d656e74616cf564736f6c634300050c0040'; /** @@ -61,7 +70,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -74,45 +83,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeAssetProxyDispatchError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeAssetProxyDispatchError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [number, string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeAssetProxyDispatchError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[number, string, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded AssetProxyExistsError. @@ -145,7 +115,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -158,45 +128,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeAssetProxyExistsError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeAssetProxyExistsError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeAssetProxyExistsError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded AssetProxyTransferError. @@ -229,7 +160,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -242,45 +173,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeAssetProxyTransferError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeAssetProxyTransferError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeAssetProxyTransferError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded SignatureValidatorError. @@ -313,7 +205,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -326,47 +218,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeEIP1271SignatureError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeEIP1271SignatureError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string, string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeEIP1271SignatureError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string, string, string]>( - returnData, - ); - return abiDecodedReturnData; - }, }; /** * Decode ERC-1155 asset data from the format described in the AssetProxy contract specification. @@ -400,7 +251,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -415,46 +266,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param assetData AssetProxy-compliant asset data describing an ERC-1155 set - * of assets. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(assetData: string): string { - assert.isString('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeERC1155AssetData(bytes)', [assetData]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeERC1155AssetData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string, BigNumber[], BigNumber[], string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeERC1155AssetData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - [string, string, BigNumber[], BigNumber[], string] - >(returnData); - return abiDecodedReturnData; - }, }; /** * Decode ERC-20 asset data from the format described in the AssetProxy contract specification. @@ -487,7 +298,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -500,43 +311,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param assetData AssetProxy-compliant asset data describing an ERC-20 asset. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(assetData: string): string { - assert.isString('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeERC20AssetData(bytes)', [assetData]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeERC20AssetData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeERC20AssetData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decode ERC-721 asset data from the format described in the AssetProxy contract specification. @@ -570,7 +344,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -583,44 +357,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param assetData AssetProxy-compliant asset data describing an ERC-721 - * asset. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(assetData: string): string { - assert.isString('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeERC721AssetData(bytes)', [assetData]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeERC721AssetData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string, BigNumber] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeERC721AssetData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string, BigNumber]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded OrderStatusError. @@ -653,7 +389,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -666,45 +402,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeExchangeInvalidContextError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeExchangeInvalidContextError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [number, string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeExchangeInvalidContextError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[number, string, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded FillError. @@ -737,7 +434,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -750,43 +447,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeFillError(bytes)', [encoded]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeFillError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [number, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeFillError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[number, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded IncompleteFillError. @@ -819,7 +479,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -832,45 +492,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeIncompleteFillError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeIncompleteFillError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [number, BigNumber, BigNumber] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeIncompleteFillError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[number, BigNumber, BigNumber]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decode multi-asset data from the format described in the AssetProxy contract specification. @@ -903,7 +524,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -916,50 +537,11 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param assetData AssetProxy-compliant data describing a multi-asset basket. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(assetData: string): string { - assert.isString('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeMultiAssetData(bytes)', [assetData]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeMultiAssetData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, BigNumber[], string[]] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeMultiAssetData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, BigNumber[], string[]]>( - returnData, - ); - return abiDecodedReturnData; - }, - }; - /** - * Decompose an ABI-encoded NegativeSpreadError. - */ - public decodeNegativeSpreadError = { + }; + /** + * Decompose an ABI-encoded NegativeSpreadError. + */ + public decodeNegativeSpreadError = { /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -987,7 +569,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1000,45 +582,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeNegativeSpreadError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeNegativeSpreadError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeNegativeSpreadError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded OrderEpochError. @@ -1071,7 +614,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1084,43 +627,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeOrderEpochError(bytes)', [encoded]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeOrderEpochError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string, BigNumber] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeOrderEpochError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string, BigNumber]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded OrderStatusError. @@ -1153,7 +659,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1166,43 +672,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeOrderStatusError(bytes)', [encoded]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeOrderStatusError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, number] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeOrderStatusError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, number]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded SignatureError. @@ -1235,7 +704,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1248,45 +717,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeSignatureError(bytes)', [encoded]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeSignatureError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [number, string, string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeSignatureError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[number, string, string, string]>( - returnData, - ); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded SignatureValidatorNotApprovedError. @@ -1321,7 +751,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1334,46 +764,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'decodeSignatureValidatorNotApprovedError(bytes)', - [encoded], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeSignatureValidatorNotApprovedError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeSignatureValidatorNotApprovedError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded SignatureWalletError. @@ -1406,7 +796,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1419,47 +809,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeSignatureWalletError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeSignatureWalletError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string, string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeSignatureWalletError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string, string, string]>( - returnData, - ); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded TransactionError. @@ -1492,7 +841,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1505,43 +854,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeTransactionError(bytes)', [encoded]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeTransactionError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [number, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeTransactionError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[number, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decompose an ABI-encoded TransactionExecutionError. @@ -1574,7 +886,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1587,45 +899,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param encoded ABI-encoded revert error. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(encoded: string): string { - assert.isString('encoded', encoded); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeTransactionExecutionError(bytes)', [ - encoded, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeTransactionExecutionError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeTransactionExecutionError(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string]>(returnData); - return abiDecodedReturnData; - }, }; /** * Decodes the call data for an Exchange contract method call. @@ -1681,7 +954,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1716,106 +989,22 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, + }; + /** + * Encode ERC-1155 asset data into the format described in the AssetProxy contract specification. + */ + public encodeERC1155AssetData = { /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param transactionData ABI-encoded calldata for an Exchange contract - * method call. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(transactionData: string): string { - assert.isString('transactionData', transactionData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decodeZeroExTransactionData(bytes)', [ - transactionData, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeZeroExTransactionData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): [ - string, - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - BigNumber[], - string[] - ] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('decodeZeroExTransactionData(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - [ - string, - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - BigNumber[], - string[] - ] - >(returnData); - return abiDecodedReturnData; - }, - }; - /** - * Encode ERC-1155 asset data into the format described in the AssetProxy contract specification. - */ - public encodeERC1155AssetData = { - /** - * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an - * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas - * since they don't modify state. - * @param tokenAddress The address of the ERC-1155 contract hosting the - * asset(s) to be traded. - * @param tokenIds The identifiers of the specific assets to be traded. - * @param tokenValues The amounts of each asset to be traded. - * @param callbackData Data to be passed to receiving contracts when a transfer - * is performed. - * @returns AssetProxy-compliant asset data describing the set of assets. + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param tokenAddress The address of the ERC-1155 contract hosting the + * asset(s) to be traded. + * @param tokenIds The identifiers of the specific assets to be traded. + * @param tokenValues The amounts of each asset to be traded. + * @param callbackData Data to be passed to receiving contracts when a transfer + * is performed. + * @returns AssetProxy-compliant asset data describing the set of assets. */ async callAsync( tokenAddress: string, @@ -1846,7 +1035,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1859,59 +1048,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param tokenAddress The address of the ERC-1155 contract hosting the - * asset(s) to be traded. - * @param tokenIds The identifiers of the specific assets to be traded. - * @param tokenValues The amounts of each asset to be traded. - * @param callbackData Data to be passed to receiving contracts when a transfer - * is performed. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - tokenAddress: string, - tokenIds: BigNumber[], - tokenValues: BigNumber[], - callbackData: string, - ): string { - assert.isString('tokenAddress', tokenAddress); - assert.isArray('tokenIds', tokenIds); - assert.isArray('tokenValues', tokenValues); - assert.isString('callbackData', callbackData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'encodeERC1155AssetData(address,uint256[],uint256[],bytes)', - [tokenAddress.toLowerCase(), tokenIds, tokenValues, callbackData], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('encodeERC1155AssetData(address,uint256[],uint256[],bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('encodeERC1155AssetData(address,uint256[],uint256[],bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Encode ERC-20 asset data into the format described in the AssetProxy contract specification. @@ -1947,7 +1083,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1960,46 +1096,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param tokenAddress The address of the ERC-20 contract hosting the asset to - * be traded. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(tokenAddress: string): string { - assert.isString('tokenAddress', tokenAddress); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('encodeERC20AssetData(address)', [ - tokenAddress.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('encodeERC20AssetData(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('encodeERC20AssetData(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Encode ERC-721 asset data into the format described in the AssetProxy specification. @@ -2039,7 +1135,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2052,49 +1148,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param tokenAddress The address of the ERC-721 contract hosting the asset to - * be traded. - * @param tokenId The identifier of the specific asset to be traded. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(tokenAddress: string, tokenId: BigNumber): string { - assert.isString('tokenAddress', tokenAddress); - assert.isBigNumber('tokenId', tokenId); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('encodeERC721AssetData(address,uint256)', [ - tokenAddress.toLowerCase(), - tokenId, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('encodeERC721AssetData(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('encodeERC721AssetData(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Encode data for multiple assets, per the AssetProxy contract specification. @@ -2134,7 +1187,7 @@ export class DevUtilsContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2147,49 +1200,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param amounts The amounts of each asset to be traded. - * @param nestedAssetData AssetProxy-compliant data describing each asset to be - * traded. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(amounts: BigNumber[], nestedAssetData: string[]): string { - assert.isArray('amounts', amounts); - assert.isArray('nestedAssetData', nestedAssetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('encodeMultiAssetData(uint256[],bytes[])', [ - amounts, - nestedAssetData, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber[] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('encodeMultiAssetData(uint256[],bytes[])'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('encodeMultiAssetData(uint256[],bytes[])'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Returns the number of asset(s) (described by assetData) that the corresponding AssetProxy contract is authorized to spend. When the asset data contains multiple assets (eg for Multi-Asset), the return value indicates how many complete "baskets" of those assets may be spent by all of the corresponding AssetProxy contracts. @@ -2250,49 +1260,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param ownerAddress Owner of the assets specified by assetData. - * @param assetData Details of asset, encoded per the AssetProxy contract - * specification. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(ownerAddress: string, assetData: string): string { - assert.isString('ownerAddress', ownerAddress); - assert.isString('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getAssetProxyAllowance(address,bytes)', [ - ownerAddress.toLowerCase(), - assetData, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getAssetProxyAllowance(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getAssetProxyAllowance(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Returns the owner's balance of the assets(s) specified in assetData. When the asset data contains multiple assets (eg in ERC1155 or Multi-Asset), the return value indicates how many complete "baskets" of those assets are owned by owner. @@ -2353,49 +1320,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param ownerAddress Owner of the assets specified by assetData. - * @param assetData Details of asset, encoded per the AssetProxy contract - * specification. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(ownerAddress: string, assetData: string): string { - assert.isString('ownerAddress', ownerAddress); - assert.isString('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getBalance(address,bytes)', [ - ownerAddress.toLowerCase(), - assetData, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBalance(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBalance(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Calls getBalance() and getAllowance() for assetData. @@ -2456,49 +1380,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param ownerAddress Owner of the assets specified by assetData. - * @param assetData Details of asset, encoded per the AssetProxy contract - * specification. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(ownerAddress: string, assetData: string): string { - assert.isString('ownerAddress', ownerAddress); - assert.isString('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getBalanceAndAssetProxyAllowance(address,bytes)', - [ownerAddress.toLowerCase(), assetData], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBalanceAndAssetProxyAllowance(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [BigNumber, BigNumber] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBalanceAndAssetProxyAllowance(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[BigNumber, BigNumber]>(returnData); - return abiDecodedReturnData; - }, }; /** * Calls getAssetProxyAllowance() for each element of assetData. @@ -2559,49 +1440,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param ownerAddress Owner of the assets specified by assetData. - * @param assetData Array of asset details, each encoded per the AssetProxy - * contract specification. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(ownerAddress: string, assetData: string[]): string { - assert.isString('ownerAddress', ownerAddress); - assert.isArray('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getBatchAssetProxyAllowances(address,bytes[])', - [ownerAddress.toLowerCase(), assetData], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBatchAssetProxyAllowances(address,bytes[])'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber[] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBatchAssetProxyAllowances(address,bytes[])'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Calls getBalance() for each element of assetData. @@ -2662,49 +1500,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param ownerAddress Owner of the assets specified by assetData. - * @param assetData Array of asset details, each encoded per the AssetProxy - * contract specification. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(ownerAddress: string, assetData: string[]): string { - assert.isString('ownerAddress', ownerAddress); - assert.isArray('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getBatchBalances(address,bytes[])', [ - ownerAddress.toLowerCase(), - assetData, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBatchBalances(address,bytes[])'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber[] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBatchBalances(address,bytes[])'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Calls getBatchBalances() and getBatchAllowances() for each element of assetData. @@ -2765,49 +1560,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param ownerAddress Owner of the assets specified by assetData. - * @param assetData Array of asset details, each encoded per the AssetProxy - * contract specification. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(ownerAddress: string, assetData: string[]): string { - assert.isString('ownerAddress', ownerAddress); - assert.isArray('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getBatchBalancesAndAssetProxyAllowances(address,bytes[])', - [ownerAddress.toLowerCase(), assetData], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string[]] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBatchBalancesAndAssetProxyAllowances(address,bytes[])'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string[]]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [BigNumber[], BigNumber[]] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getBatchBalancesAndAssetProxyAllowances(address,bytes[])'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[BigNumber[], BigNumber[]]>(returnData); - return abiDecodedReturnData; - }, }; /** * Batch fetches ETH balances @@ -2861,43 +1613,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param addresses Array of addresses. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(addresses: string[]): string { - assert.isArray('addresses', addresses); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getEthBalances(address[])', [addresses]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string[] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getEthBalances(address[])'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber[] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getEthBalances(address[])'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Fetches all order-relevant information needed to validate if the supplied order is fillable. @@ -2952,141 +1667,32 @@ export class DevUtilsContract extends BaseContract { ); const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { - to: self.address, - ...callData, - data: encodedData, - }, - self._web3Wrapper.getContractDefaults(), - ); - callDataWithDefaults.from = callDataWithDefaults.from - ? callDataWithDefaults.from.toLowerCase() - : callDataWithDefaults.from; - let rawCallResult; - try { - rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); - } catch (err) { - BaseContract._throwIfThrownErrorIsRevertError(err); - throw err; - } - BaseContract._throwIfCallResultIsRevertError(rawCallResult); - const abiEncoder = self._lookupAbiEncoder( - 'getOrderRelevantState((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)', - ); - // tslint:disable boolean-naming - const result = abiEncoder.strictDecodeReturnValue< - [{ orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }, BigNumber, boolean] - >(rawCallResult); - // tslint:enable boolean-naming - return result; - }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param order The order structure. - * @param signature Signature provided by maker that proves the order's - * authenticity. `0x01` can always be provided if the signature does not - * need to be validated. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }, - signature: string, - ): string { - assert.isString('signature', signature); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getOrderRelevantState((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)', - [order, signature], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): [ - { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }, - string - ] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrderRelevantState((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [ - { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }, - string - ] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): [{ orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }, BigNumber, boolean] { - const self = (this as any) as DevUtilsContract; + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); const abiEncoder = self._lookupAbiEncoder( 'getOrderRelevantState((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)', ); // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< + const result = abiEncoder.strictDecodeReturnValue< [{ orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }, BigNumber, boolean] - >(returnData); - return abiDecodedReturnData; + >(rawCallResult); + // tslint:enable boolean-naming + return result; }, }; /** @@ -3178,124 +1784,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param orders Array of order structures. - * @param signatures Array of signatures provided by makers that prove the - * authenticity of the orders. `0x01` can always be provided if a signature - * does not need to be validated. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - signatures: string[], - ): string { - assert.isArray('orders', orders); - assert.isArray('signatures', signatures); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getOrderRelevantStates((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])', - [orders, signatures], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): [ - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - string[] - ] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrderRelevantStates((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [ - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - string[] - ] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): [ - Array<{ orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }>, - BigNumber[], - boolean[] - ] { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrderRelevantStates((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - [ - Array<{ orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }>, - BigNumber[], - boolean[] - ] - >(returnData); - return abiDecodedReturnData; - }, }; /** * Simulates all of the transfers within an order and returns the index of the first failed transfer. @@ -3331,6 +1819,7 @@ export class DevUtilsContract extends BaseContract { takerAddress: string, takerAssetFillAmount: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('takerAddress', takerAddress); assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); @@ -3351,6 +1840,15 @@ export class DevUtilsContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.getSimulatedOrderTransferResults.callAsync( + order, + takerAddress, + takerAssetFillAmount, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -3385,8 +1883,7 @@ export class DevUtilsContract extends BaseContract { takerAddress: string, takerAssetFillAmount: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('takerAddress', takerAddress); assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); @@ -3396,6 +1893,7 @@ export class DevUtilsContract extends BaseContract { takerAddress.toLowerCase(), takerAssetFillAmount, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -3403,8 +1901,8 @@ export class DevUtilsContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -3461,41 +1959,6 @@ export class DevUtilsContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }, - takerAddress: string, - takerAssetFillAmount: BigNumber, - txData?: Partial | undefined, - ): Promise { - await (this as any).getSimulatedOrderTransferResults.callAsync( - order, - takerAddress, - takerAssetFillAmount, - txData, - ); - const txHash = await (this as any).getSimulatedOrderTransferResults.sendTransactionAsync( - order, - takerAddress, - takerAssetFillAmount, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -3610,64 +2073,14 @@ export class DevUtilsContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder( - 'getSimulatedOrderTransferResults((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),address,uint256)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): number { + getSelector(): string { const self = (this as any) as DevUtilsContract; const abiEncoder = self._lookupAbiEncoder( 'getSimulatedOrderTransferResults((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),address,uint256)', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -3705,6 +2118,7 @@ export class DevUtilsContract extends BaseContract { takerAddresses: string[], takerAssetFillAmounts: BigNumber[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isArray('takerAddresses', takerAddresses); @@ -3726,6 +2140,15 @@ export class DevUtilsContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.getSimulatedOrdersTransferResults.callAsync( + orders, + takerAddresses, + takerAssetFillAmounts, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -3761,8 +2184,7 @@ export class DevUtilsContract extends BaseContract { takerAddresses: string[], takerAssetFillAmounts: BigNumber[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isArray('takerAddresses', takerAddresses); @@ -3773,6 +2195,7 @@ export class DevUtilsContract extends BaseContract { takerAddresses, takerAssetFillAmounts, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -3780,8 +2203,8 @@ export class DevUtilsContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -3840,41 +2263,6 @@ export class DevUtilsContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - takerAddresses: string[], - takerAssetFillAmounts: BigNumber[], - txData?: Partial | undefined, - ): Promise { - await (this as any).getSimulatedOrdersTransferResults.callAsync( - orders, - takerAddresses, - takerAssetFillAmounts, - txData, - ); - const txHash = await (this as any).getSimulatedOrdersTransferResults.sendTransactionAsync( - orders, - takerAddresses, - takerAssetFillAmounts, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -3993,66 +2381,14 @@ export class DevUtilsContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder( - 'getSimulatedOrdersTransferResults((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],address[],uint256[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): number[] { + getSelector(): string { const self = (this as any) as DevUtilsContract; const abiEncoder = self._lookupAbiEncoder( 'getSimulatedOrdersTransferResults((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],address[],uint256[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -4114,49 +2450,6 @@ export class DevUtilsContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param ownerAddress Address of the owner of the asset. - * @param assetData Description of tokens, per the AssetProxy contract - * specification. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(ownerAddress: string, assetData: string): string { - assert.isString('ownerAddress', ownerAddress); - assert.isString('assetData', assetData); - const self = (this as any) as DevUtilsContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getTransferableAssetAmount(address,bytes)', [ - ownerAddress.toLowerCase(), - assetData, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getTransferableAssetAmount(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DevUtilsContract; - const abiEncoder = self._lookupAbiEncoder('getTransferableAssetAmount(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/dummy_erc20_token.ts b/packages/abi-gen-wrappers/src/generated-wrappers/dummy_erc20_token.ts index b8b2279a97..304044c949 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/dummy_erc20_token.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/dummy_erc20_token.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -48,8 +54,10 @@ export interface DummyERC20TokenTransferEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class DummyERC20TokenContract extends BaseContract { - public static deployedBytecode = - '0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c806395d89b411161008c578063dd62ed3e11610066578063dd62ed3e146102e2578063e30443bc1461031d578063f2fde38b14610356578063fa9b701814610389576100ea565b806395d89b4114610282578063a0712d681461028a578063a9059cbb146102a9576100ea565b806323b872dd116100c857806323b872dd146101d3578063313ce5671461021657806370a082311461021e5780638da5cb5b14610251576100ea565b806306fdde03146100ef578063095ea7b31461016c57806318160ddd146101b9575b600080fd5b6100f7610391565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610131578181015183820152602001610119565b50505050905090810190601f16801561015e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a56004803603604081101561018257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813516906020013561043d565b604080519115158252519081900360200190f35b6101c16104b0565b60408051918252519081900360200190f35b6101a5600480360360608110156101e957600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356104b6565b6101c1610772565b6101c16004803603602081101561023457600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610778565b6102596107a0565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6100f76107bc565b6102a7600480360360208110156102a057600080fd5b5035610835565b005b6101a5600480360360408110156102bf57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356108bb565b6101c1600480360360408110156102f857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610a4a565b6102a76004803603604081101561033357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610a82565b6102a76004803603602081101561036c57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610b18565b6101c1610b95565b6004805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156104355780601f1061040a57610100808354040283529160200191610435565b820191906000526020600020905b81548152906001019060200180831161041857829003601f168201915b505050505081565b33600081815260026020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60035490565b73ffffffffffffffffffffffffffffffffffffffff83166000818152600260209081526040808320338452825280832054938352600190915281205490919083111561056357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f45524332305f494e53554646494349454e545f42414c414e4345000000000000604482015290519081900360640190fd5b828110156105d257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f45524332305f494e53554646494349454e545f414c4c4f57414e434500000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8416600090815260016020526040902054838101101561066857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f55494e543235365f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff808516600090815260016020526040808220805487019055918716815220805484900390557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156107025773ffffffffffffffffffffffffffffffffffffffff851660009081526002602090815260408083203384529091529020805484900390555b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3506001949350505050565b60065481565b73ffffffffffffffffffffffffffffffffffffffff1660009081526001602052604090205490565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b6005805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156104355780601f1061040a57610100808354040283529160200191610435565b69021e19e0c9bab24000008111156108ae57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f56414c55455f544f4f5f4c415247450000000000000000000000000000000000604482015290519081900360640190fd5b6108b83382610ba3565b50565b3360009081526001602052604081205482111561093957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f45524332305f494e53554646494349454e545f42414c414e4345000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604090205482810110156109cf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f55494e543235365f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b3360008181526001602090815260408083208054879003905573ffffffffffffffffffffffffffffffffffffffff871680845292819020805487019055805186815290519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a350600192915050565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260026020908152604080832093909416825291909152205490565b610a8a610c5c565b73ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090205480821015610ad557610acd600354610ac88385610ca5565b610ca5565b600355610aee565b610aea600354610ae58484610ca5565b610cc4565b6003555b5073ffffffffffffffffffffffffffffffffffffffff909116600090815260016020526040902055565b610b20610c5c565b73ffffffffffffffffffffffffffffffffffffffff8116610b5057610b4b610b46610ce7565b610d1e565b6108b8565b6000805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff000000000000000000000000000000000000000090911617905550565b69021e19e0c9bab240000081565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260016020526040902054610bd4908290610cc4565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260016020526040902055600354610c079082610cc4565b60035560408051828152905173ffffffffffffffffffffffffffffffffffffffff8416916000917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610ca357600054610ca390610b4690339073ffffffffffffffffffffffffffffffffffffffff16610d26565b565b600082821115610cbe57610cbe610b4660028585610db2565b50900390565b600082820183811015610ce057610ce0610b4660008686610db2565b9392505050565b60408051808201909152600481527fe69edc3e00000000000000000000000000000000000000000000000000000000602082015290565b805160208201fd5b6040805173ffffffffffffffffffffffffffffffffffffffff808516602483015283166044808301919091528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f1de45ad10000000000000000000000000000000000000000000000000000000017905292915050565b606063e946c1bb60e01b84848460405160240180846003811115610dd257fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050939250505056fea265627a7a7231582089c03e503c77db7069bea8a94ec1c47ee5201d8bdb53857e70a882a1130e1ac364736f6c634300050c0032'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; public MAX_MINT_AMOUNT = { /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an @@ -92,41 +100,6 @@ export class DummyERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('MAX_MINT_AMOUNT()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('MAX_MINT_AMOUNT()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('MAX_MINT_AMOUNT()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public allowance = { /** @@ -183,48 +156,6 @@ export class DummyERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _owner The address of the account owning tokens - * @param _spender The address of the account able to transfer the tokens - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string, _spender: string): string { - assert.isString('_owner', _owner); - assert.isString('_spender', _spender); - const self = (this as any) as DummyERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('allowance(address,address)', [ - _owner.toLowerCase(), - _spender.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('allowance(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('allowance(address,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * `msg.sender` approves `_spender` to spend `_value` tokens @@ -242,6 +173,7 @@ export class DummyERC20TokenContract extends BaseContract { _spender: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_spender', _spender); assert.isBigNumber('_value', _value); @@ -262,6 +194,10 @@ export class DummyERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.approve.callAsync(_spender, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -278,21 +214,20 @@ export class DummyERC20TokenContract extends BaseContract { _spender: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_spender', _spender); assert.isBigNumber('_value', _value); const self = (this as any) as DummyERC20TokenContract; - const txHashPromise = self.approve.sendTransactionAsync(_spender.toLowerCase(), _value, txData); + const txHashPromise = self.approve.sendTransactionAsync(_spender.toLowerCase(), _value, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -331,15 +266,6 @@ export class DummyERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -413,28 +339,12 @@ export class DummyERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): string { + getSelector(): string { const self = (this as any) as DummyERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -489,43 +399,6 @@ export class DummyERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _owner The address from which the balance will be retrieved - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string): string { - assert.isString('_owner', _owner); - const self = (this as any) as DummyERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('balanceOf(address)', [_owner.toLowerCase()]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public decimals = { /** @@ -569,41 +442,6 @@ export class DummyERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decimals()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('decimals()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('decimals()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Mints new tokens for sender @@ -616,7 +454,11 @@ export class DummyERC20TokenContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(_value: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + _value: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isBigNumber('_value', _value); const self = (this as any) as DummyERC20TokenContract; const encodedData = self._strictEncodeArguments('mint(uint256)', [_value]); @@ -632,6 +474,10 @@ export class DummyERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.mint.callAsync(_value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -646,20 +492,19 @@ export class DummyERC20TokenContract extends BaseContract { awaitTransactionSuccessAsync( _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('_value', _value); const self = (this as any) as DummyERC20TokenContract; - const txHashPromise = self.mint.sendTransactionAsync(_value, txData); + const txHashPromise = self.mint.sendTransactionAsync(_value, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -689,14 +534,6 @@ export class DummyERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -754,28 +591,12 @@ export class DummyERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [BigNumber] { + getSelector(): string { const self = (this as any) as DummyERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('mint(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('mint(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public name = { @@ -820,41 +641,6 @@ export class DummyERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('name()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('name()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('name()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public owner = { /** @@ -898,41 +684,6 @@ export class DummyERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owner()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Sets the balance of target address @@ -950,6 +701,7 @@ export class DummyERC20TokenContract extends BaseContract { _target: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_target', _target); assert.isBigNumber('_value', _value); @@ -970,6 +722,10 @@ export class DummyERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.setBalance.callAsync(_target, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -986,21 +742,20 @@ export class DummyERC20TokenContract extends BaseContract { _target: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_target', _target); assert.isBigNumber('_value', _value); const self = (this as any) as DummyERC20TokenContract; - const txHashPromise = self.setBalance.sendTransactionAsync(_target.toLowerCase(), _value, txData); + const txHashPromise = self.setBalance.sendTransactionAsync(_target.toLowerCase(), _value, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1039,15 +794,6 @@ export class DummyERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1120,28 +866,12 @@ export class DummyERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { + getSelector(): string { const self = (this as any) as DummyERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('setBalance(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('setBalance(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public symbol = { @@ -1186,41 +916,6 @@ export class DummyERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('symbol()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('symbol()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('symbol()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Query total supply of token @@ -1268,41 +963,6 @@ export class DummyERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('totalSupply()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('totalSupply()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('totalSupply()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * send `value` token to `to` from `msg.sender` @@ -1320,6 +980,7 @@ export class DummyERC20TokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_to', _to); assert.isBigNumber('_value', _value); @@ -1337,6 +998,10 @@ export class DummyERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transfer.callAsync(_to, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1353,21 +1018,20 @@ export class DummyERC20TokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_to', _to); assert.isBigNumber('_value', _value); const self = (this as any) as DummyERC20TokenContract; - const txHashPromise = self.transfer.sendTransactionAsync(_to.toLowerCase(), _value, txData); + const txHashPromise = self.transfer.sendTransactionAsync(_to.toLowerCase(), _value, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1399,15 +1063,6 @@ export class DummyERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1478,28 +1133,12 @@ export class DummyERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): boolean { + getSelector(): string { const self = (this as any) as DummyERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1520,6 +1159,7 @@ export class DummyERC20TokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -1542,6 +1182,10 @@ export class DummyERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferFrom.callAsync(_from, _to, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1560,8 +1204,7 @@ export class DummyERC20TokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -1572,6 +1215,7 @@ export class DummyERC20TokenContract extends BaseContract { _to.toLowerCase(), _value, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1579,8 +1223,8 @@ export class DummyERC20TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1623,16 +1267,6 @@ export class DummyERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1713,28 +1347,12 @@ export class DummyERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): boolean { + getSelector(): string { const self = (this as any) as DummyERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public transferOwnership = { @@ -1744,7 +1362,11 @@ export class DummyERC20TokenContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + newOwner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('newOwner', newOwner); const self = (this as any) as DummyERC20TokenContract; const encodedData = self._strictEncodeArguments('transferOwnership(address)', [newOwner.toLowerCase()]); @@ -1760,6 +1382,10 @@ export class DummyERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferOwnership.callAsync(newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1773,20 +1399,19 @@ export class DummyERC20TokenContract extends BaseContract { awaitTransactionSuccessAsync( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('newOwner', newOwner); const self = (this as any) as DummyERC20TokenContract; - const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData); + const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1815,11 +1440,6 @@ export class DummyERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1877,28 +1497,12 @@ export class DummyERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as DummyERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as DummyERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; private readonly _subscriptionManager: SubscriptionManager; diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/dummy_erc721_token.ts b/packages/abi-gen-wrappers/src/generated-wrappers/dummy_erc721_token.ts index 5540962892..5fb1cf8f24 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/dummy_erc721_token.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/dummy_erc721_token.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -58,8 +64,10 @@ export interface DummyERC721TokenTransferEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class DummyERC721TokenContract extends BaseContract { - public static deployedBytecode = - '0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806370a0823111610097578063a22cb46511610066578063a22cb46514610362578063b88d4fde1461039d578063e985e9c51461043a578063f2fde38b14610489576100f5565b806370a08231146102d45780638da5cb5b1461031957806395d89b41146103215780639dc29fac14610329576100f5565b806323b872dd116100d357806323b872dd146101f857806340c10f191461023b57806342842e0e146102745780636352211e146102b7576100f5565b806306fdde03146100fa578063081812fc14610177578063095ea7b3146101bd575b600080fd5b6101026104bc565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561013c578181015183820152602001610124565b50505050905090810190601f1680156101695780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101946004803603602081101561018d57600080fd5b5035610568565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6101f6600480360360408110156101d357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610590565b005b6101f66004803603606081101561020e57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356106b2565b6101f66004803603604081101561025157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610a20565b6101f66004803603606081101561028a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610a2e565b610194600480360360208110156102cd57600080fd5b5035610bc8565b610307600480360360208110156102ea57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610c5f565b60408051918252519081900360200190f35b610194610d0c565b610102610d28565b6101f66004803603604081101561033f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610da1565b6101f66004803603604081101561037857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001351515610db3565b6101f6600480360360808110156103b357600080fd5b73ffffffffffffffffffffffffffffffffffffffff8235811692602081013590911691604082013591908101906080810160608201356401000000008111156103fb57600080fd5b82018360208201111561040d57600080fd5b8035906020019184600183028401116401000000008311171561042f57600080fd5b509092509050610e4c565b6104756004803603604081101561045057600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611017565b604080519115158252519081900360200190f35b6101f66004803603602081101561049f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611052565b6005805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156105605780601f1061053557610100808354040283529160200191610560565b820191906000526020600020905b81548152906001019060200180831161054357829003601f168201915b505050505081565b60009081526002602052604090205473ffffffffffffffffffffffffffffffffffffffff1690565b600061059b82610bc8565b90503373ffffffffffffffffffffffffffffffffffffffff821614806105c657506105c68133611017565b61063157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4552433732315f494e56414c49445f53454e4445520000000000000000000000604482015290519081900360640190fd5b60008281526002602052604080822080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff87811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b73ffffffffffffffffffffffffffffffffffffffff821661073457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4552433732315f5a45524f5f544f5f4144445245535300000000000000000000604482015290519081900360640190fd5b600061073f82610bc8565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16146107db57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4552433732315f4f574e45525f4d49534d415443480000000000000000000000604482015290519081900360640190fd5b3360006107e784610568565b90508273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16148061082857506108288383611017565b8061085e57508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b6108c957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4552433732315f494e56414c49445f5350454e44455200000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81161561091a57600084815260026020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001690555b600084815260016020818152604080842080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8b8116919091179091558a168452600390915290912054610984916110ce565b73ffffffffffffffffffffffffffffffffffffffff80881660009081526003602052604080822093909355908716815220546109c19060016110ed565b73ffffffffffffffffffffffffffffffffffffffff808716600081815260036020526040808220949094559251879391928a16917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050505050565b610a2a8282611110565b5050565b610a398383836106b2565b813b8015610bc257604080517f150b7a0200000000000000000000000000000000000000000000000000000000815233600482015273ffffffffffffffffffffffffffffffffffffffff8681166024830152604482018590526080606483015260006084830181905292519086169163150b7a029160c480830192602092919082900301818787803b158015610ace57600080fd5b505af1158015610ae2573d6000803e3d6000fd5b505050506040513d6020811015610af857600080fd5b505160405190915080602f61166c8239602f01905060405180910390207bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614610bc057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4552433732315f494e56414c49445f53454c4543544f52000000000000000000604482015290519081900360640190fd5b505b50505050565b60008181526001602052604081205473ffffffffffffffffffffffffffffffffffffffff1680610c5957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4552433732315f5a45524f5f4f574e4552000000000000000000000000000000604482015290519081900360640190fd5b92915050565b600073ffffffffffffffffffffffffffffffffffffffff8216610ce357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4552433732315f5a45524f5f4f574e4552000000000000000000000000000000604482015290519081900360640190fd5b5073ffffffffffffffffffffffffffffffffffffffff1660009081526003602052604090205490565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b6006805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156105605780601f1061053557610100808354040283529160200191610560565b610da96112e3565b610a2a828261132c565b33600081815260046020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016861515908117909155815190815290519293927f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31929181900390910190a35050565b610e578585856106b2565b833b801561100f576040517f150b7a02000000000000000000000000000000000000000000000000000000008152336004820181815273ffffffffffffffffffffffffffffffffffffffff89811660248501526044840188905260806064850190815260848501879052600094918a169363150b7a029390928c928b928b928b929060a401848480828437600081840152601f19601f8201169050808301925050509650505050505050602060405180830381600087803b158015610f1b57600080fd5b505af1158015610f2f573d6000803e3d6000fd5b505050506040513d6020811015610f4557600080fd5b505160405190915080602f61166c8239602f01905060405180910390207bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161461100d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4552433732315f494e56414c49445f53454c4543544f52000000000000000000604482015290519081900360640190fd5b505b505050505050565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260046020908152604080832093909416825291909152205460ff1690565b61105a6112e3565b73ffffffffffffffffffffffffffffffffffffffff811661108a57611085611080611501565b611538565b6110cb565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83161790555b50565b6000828211156110e7576110e761108060028585611540565b50900390565b6000828201838110156111095761110961108060008686611540565b9392505050565b73ffffffffffffffffffffffffffffffffffffffff821661119257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4552433732315f5a45524f5f544f5f4144445245535300000000000000000000604482015290519081900360640190fd5b60008181526001602052604090205473ffffffffffffffffffffffffffffffffffffffff16801561122457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f4552433732315f4f574e45525f414c52454144595f4558495354530000000000604482015290519081900360640190fd5b600082815260016020818152604080842080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8916908117909155845260039091529091205461128a916110ed565b73ffffffffffffffffffffffffffffffffffffffff84166000818152600360205260408082209390935591518492907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a4505050565b60005473ffffffffffffffffffffffffffffffffffffffff16331461132a5760005461132a9061108090339073ffffffffffffffffffffffffffffffffffffffff166115df565b565b73ffffffffffffffffffffffffffffffffffffffff82166113ae57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4552433732315f5a45524f5f4f574e45525f4144445245535300000000000000604482015290519081900360640190fd5b60008181526001602052604090205473ffffffffffffffffffffffffffffffffffffffff908116908316811461144557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4552433732315f4f574e45525f4d49534d415443480000000000000000000000604482015290519081900360640190fd5b600082815260016020818152604080842080547fffffffffffffffffffffffff000000000000000000000000000000000000000016905573ffffffffffffffffffffffffffffffffffffffff871684526003909152909120546114a7916110ce565b73ffffffffffffffffffffffffffffffffffffffff8416600081815260036020526040808220939093559151849291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908390a4505050565b60408051808201909152600481527fe69edc3e00000000000000000000000000000000000000000000000000000000602082015290565b805160208201fd5b606063e946c1bb60e01b8484846040516024018084600381111561156057fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090509392505050565b6040805173ffffffffffffffffffffffffffffffffffffffff808516602483015283166044808301919091528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f1de45ad1000000000000000000000000000000000000000000000000000000001790529291505056fe6f6e455243373231526563656976656428616464726573732c616464726573732c75696e743235362c627974657329a265627a7a723158207bb3c4b1d40aa051fbb8e4f8230bb310013e75ca9fa97c528018b4c4aba3b92564736f6c634300050c0032'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; /** * The zero address indicates there is no approved address. * Throws unless `msg.sender` is the current NFT owner, or an authorized @@ -78,6 +86,7 @@ export class DummyERC721TokenContract extends BaseContract { _approved: string, _tokenId: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_approved', _approved); assert.isBigNumber('_tokenId', _tokenId); @@ -98,6 +107,10 @@ export class DummyERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.approve.callAsync(_approved, _tokenId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -114,21 +127,20 @@ export class DummyERC721TokenContract extends BaseContract { _approved: string, _tokenId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_approved', _approved); assert.isBigNumber('_tokenId', _tokenId); const self = (this as any) as DummyERC721TokenContract; - const txHashPromise = self.approve.sendTransactionAsync(_approved.toLowerCase(), _tokenId, txData); + const txHashPromise = self.approve.sendTransactionAsync(_approved.toLowerCase(), _tokenId, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -167,15 +179,6 @@ export class DummyERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -248,28 +251,12 @@ export class DummyERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { + getSelector(): string { const self = (this as any) as DummyERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -325,43 +312,6 @@ export class DummyERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _owner An address for whom to query the balance - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string): string { - assert.isString('_owner', _owner); - const self = (this as any) as DummyERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('balanceOf(address)', [_owner.toLowerCase()]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Function to burn a token @@ -380,6 +330,7 @@ export class DummyERC721TokenContract extends BaseContract { _owner: string, _tokenId: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_owner', _owner); assert.isBigNumber('_tokenId', _tokenId); @@ -397,6 +348,10 @@ export class DummyERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.burn.callAsync(_owner, _tokenId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -413,21 +368,20 @@ export class DummyERC721TokenContract extends BaseContract { _owner: string, _tokenId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_owner', _owner); assert.isBigNumber('_tokenId', _tokenId); const self = (this as any) as DummyERC721TokenContract; - const txHashPromise = self.burn.sendTransactionAsync(_owner.toLowerCase(), _tokenId, txData); + const txHashPromise = self.burn.sendTransactionAsync(_owner.toLowerCase(), _tokenId, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -463,15 +417,6 @@ export class DummyERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -541,28 +486,12 @@ export class DummyERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('burn(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as DummyERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('burn(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -617,43 +546,6 @@ export class DummyERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _tokenId The NFT to find the approved address for - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_tokenId: BigNumber): string { - assert.isBigNumber('_tokenId', _tokenId); - const self = (this as any) as DummyERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getApproved(uint256)', [_tokenId]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('getApproved(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('getApproved(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public isApprovedForAll = { /** @@ -710,48 +602,6 @@ export class DummyERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _owner The address that owns the NFTs - * @param _operator The address that acts on behalf of the owner - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string, _operator: string): string { - assert.isString('_owner', _owner); - assert.isString('_operator', _operator); - const self = (this as any) as DummyERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('isApprovedForAll(address,address)', [ - _owner.toLowerCase(), - _operator.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('isApprovedForAll(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('isApprovedForAll(address,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Function to mint a new token @@ -770,6 +620,7 @@ export class DummyERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_to', _to); assert.isBigNumber('_tokenId', _tokenId); @@ -787,6 +638,10 @@ export class DummyERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.mint.callAsync(_to, _tokenId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -803,21 +658,20 @@ export class DummyERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_to', _to); assert.isBigNumber('_tokenId', _tokenId); const self = (this as any) as DummyERC721TokenContract; - const txHashPromise = self.mint.sendTransactionAsync(_to.toLowerCase(), _tokenId, txData); + const txHashPromise = self.mint.sendTransactionAsync(_to.toLowerCase(), _tokenId, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -853,15 +707,6 @@ export class DummyERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -931,28 +776,12 @@ export class DummyERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('mint(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as DummyERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('mint(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public name = { @@ -997,41 +826,6 @@ export class DummyERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('name()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('name()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('name()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public owner = { /** @@ -1075,41 +869,6 @@ export class DummyERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owner()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * NFTs assigned to zero address are considered invalid, and queries @@ -1164,43 +923,6 @@ export class DummyERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _tokenId The identifier for an NFT - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_tokenId: BigNumber): string { - assert.isBigNumber('_tokenId', _tokenId); - const self = (this as any) as DummyERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('ownerOf(uint256)', [_tokenId]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('ownerOf(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('ownerOf(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * This works identically to the other function with an extra data parameter, @@ -1221,6 +943,7 @@ export class DummyERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -1243,6 +966,10 @@ export class DummyERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.safeTransferFrom1.callAsync(_from, _to, _tokenId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1261,8 +988,7 @@ export class DummyERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -1273,6 +999,7 @@ export class DummyERC721TokenContract extends BaseContract { _to.toLowerCase(), _tokenId, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1280,8 +1007,8 @@ export class DummyERC721TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1324,16 +1051,6 @@ export class DummyERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1413,28 +1130,12 @@ export class DummyERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string, BigNumber] { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as DummyERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1463,6 +1164,7 @@ export class DummyERC721TokenContract extends BaseContract { _tokenId: BigNumber, _data: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -1487,6 +1189,10 @@ export class DummyERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.safeTransferFrom2.callAsync(_from, _to, _tokenId, _data, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1507,8 +1213,7 @@ export class DummyERC721TokenContract extends BaseContract { _tokenId: BigNumber, _data: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -1521,6 +1226,7 @@ export class DummyERC721TokenContract extends BaseContract { _tokenId, _data, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1528,8 +1234,8 @@ export class DummyERC721TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1576,23 +1282,6 @@ export class DummyERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1677,28 +1366,12 @@ export class DummyERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, string, BigNumber, string] { + getSelector(): string { const self = (this as any) as DummyERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, BigNumber, string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1718,6 +1391,7 @@ export class DummyERC721TokenContract extends BaseContract { _operator: string, _approved: boolean, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_operator', _operator); assert.isBoolean('_approved', _approved); @@ -1738,6 +1412,10 @@ export class DummyERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.setApprovalForAll.callAsync(_operator, _approved, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1754,8 +1432,7 @@ export class DummyERC721TokenContract extends BaseContract { _operator: string, _approved: boolean, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_operator', _operator); assert.isBoolean('_approved', _approved); @@ -1764,6 +1441,7 @@ export class DummyERC721TokenContract extends BaseContract { _operator.toLowerCase(), _approved, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1771,8 +1449,8 @@ export class DummyERC721TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1811,15 +1489,6 @@ export class DummyERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1892,28 +1561,12 @@ export class DummyERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, boolean] { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('setApprovalForAll(address,bool)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, boolean]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as DummyERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('setApprovalForAll(address,bool)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public symbol = { @@ -1958,41 +1611,6 @@ export class DummyERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('symbol()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('symbol()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('symbol()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Throws unless `msg.sender` is the current owner, an authorized @@ -2015,6 +1633,7 @@ export class DummyERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -2037,6 +1656,10 @@ export class DummyERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferFrom.callAsync(_from, _to, _tokenId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2055,8 +1678,7 @@ export class DummyERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -2067,6 +1689,7 @@ export class DummyERC721TokenContract extends BaseContract { _to.toLowerCase(), _tokenId, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -2074,8 +1697,8 @@ export class DummyERC721TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2118,16 +1741,6 @@ export class DummyERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2207,28 +1820,12 @@ export class DummyERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string, BigNumber] { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as DummyERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public transferOwnership = { @@ -2238,7 +1835,11 @@ export class DummyERC721TokenContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + newOwner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('newOwner', newOwner); const self = (this as any) as DummyERC721TokenContract; const encodedData = self._strictEncodeArguments('transferOwnership(address)', [newOwner.toLowerCase()]); @@ -2254,6 +1855,10 @@ export class DummyERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferOwnership.callAsync(newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2267,20 +1872,19 @@ export class DummyERC721TokenContract extends BaseContract { awaitTransactionSuccessAsync( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('newOwner', newOwner); const self = (this as any) as DummyERC721TokenContract; - const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData); + const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2309,11 +1913,6 @@ export class DummyERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2371,28 +1970,12 @@ export class DummyERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as DummyERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as DummyERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; private readonly _subscriptionManager: SubscriptionManager; diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/dutch_auction.ts b/packages/abi-gen-wrappers/src/generated-wrappers/dutch_auction.ts index c0d8d3fb7c..15a3297209 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/dutch_auction.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/dutch_auction.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class DutchAuctionContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode: string | undefined; /** * Calculates the Auction Details for the given order @@ -56,6 +65,7 @@ export class DutchAuctionContract extends BaseContract { takerAssetData: string; }, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { const self = (this as any) as DutchAuctionContract; const encodedData = self._strictEncodeArguments( @@ -74,6 +84,10 @@ export class DutchAuctionContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.getAuctionDetails.callAsync(order, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -101,19 +115,18 @@ export class DutchAuctionContract extends BaseContract { takerAssetData: string; }, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { const self = (this as any) as DutchAuctionContract; - const txHashPromise = self.getAuctionDetails.sendTransactionAsync(order, txData); + const txHashPromise = self.getAuctionDetails.sendTransactionAsync(order, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -161,27 +174,6 @@ export class DutchAuctionContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -290,76 +282,14 @@ export class DutchAuctionContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - } { + getSelector(): string { const self = (this as any) as DutchAuctionContract; const abiEncoder = self._lookupAbiEncoder( 'getAuctionDetails((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes))', ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): { - beginTimeSeconds: BigNumber; - endTimeSeconds: BigNumber; - beginAmount: BigNumber; - endAmount: BigNumber; - currentAmount: BigNumber; - currentTimeSeconds: BigNumber; - } { - const self = (this as any) as DutchAuctionContract; - const abiEncoder = self._lookupAbiEncoder( - 'getAuctionDetails((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes))', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - beginTimeSeconds: BigNumber; - endTimeSeconds: BigNumber; - beginAmount: BigNumber; - endAmount: BigNumber; - currentAmount: BigNumber; - currentTimeSeconds: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -424,6 +354,7 @@ export class DutchAuctionContract extends BaseContract { buySignature: string, sellSignature: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('buySignature', buySignature); assert.isString('sellSignature', sellSignature); @@ -444,6 +375,10 @@ export class DutchAuctionContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.matchOrders.callAsync(buyOrder, sellOrder, buySignature, sellSignature, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -492,8 +427,7 @@ export class DutchAuctionContract extends BaseContract { buySignature: string, sellSignature: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('buySignature', buySignature); assert.isString('sellSignature', sellSignature); @@ -504,6 +438,7 @@ export class DutchAuctionContract extends BaseContract { buySignature, sellSignature, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -511,8 +446,8 @@ export class DutchAuctionContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -583,49 +518,6 @@ export class DutchAuctionContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -796,90 +688,14 @@ export class DutchAuctionContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - } { - const self = (this as any) as DutchAuctionContract; - const abiEncoder = self._lookupAbiEncoder( - 'matchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),bytes,bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - left: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - }; - right: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - }; - leftMakerAssetSpreadAmount: BigNumber; - } { + getSelector(): string { const self = (this as any) as DutchAuctionContract; const abiEncoder = self._lookupAbiEncoder( 'matchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),bytes,bytes)', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - left: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - }; - right: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - }; - leftMakerAssetSpreadAmount: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public static async deployFrom0xArtifactAsync( diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/erc1155_mintable.ts b/packages/abi-gen-wrappers/src/generated-wrappers/erc1155_mintable.ts new file mode 100644 index 0000000000..9d8a0f0167 --- /dev/null +++ b/packages/abi-gen-wrappers/src/generated-wrappers/erc1155_mintable.ts @@ -0,0 +1,2841 @@ +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming +// tslint:disable:whitespace no-unbound-method no-trailing-whitespace +// tslint:disable:no-unused-variable +import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; +import { schemas } from '@0x/json-schemas'; +import { + BlockParam, + BlockParamLiteral, + BlockRange, + CallData, + ContractAbi, + ContractArtifact, + DecodedLogArgs, + LogWithDecodedArgs, + MethodAbi, + TransactionReceiptWithDecodedLogs, + TxData, + TxDataPayable, + SupportedProvider, +} from 'ethereum-types'; +import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; +import { Web3Wrapper } from '@0x/web3-wrapper'; +import { assert } from '@0x/assert'; +import * as ethers from 'ethers'; +// tslint:enable:no-unused-variable + +export type ERC1155MintableEventArgs = + | ERC1155MintableApprovalForAllEventArgs + | ERC1155MintableTransferBatchEventArgs + | ERC1155MintableTransferSingleEventArgs + | ERC1155MintableURIEventArgs; + +export enum ERC1155MintableEvents { + ApprovalForAll = 'ApprovalForAll', + TransferBatch = 'TransferBatch', + TransferSingle = 'TransferSingle', + URI = 'URI', +} + +export interface ERC1155MintableApprovalForAllEventArgs extends DecodedLogArgs { + owner: string; + operator: string; + approved: boolean; +} + +export interface ERC1155MintableTransferBatchEventArgs extends DecodedLogArgs { + operator: string; + from: string; + to: string; + ids: BigNumber[]; + values: BigNumber[]; +} + +export interface ERC1155MintableTransferSingleEventArgs extends DecodedLogArgs { + operator: string; + from: string; + to: string; + id: BigNumber; + value: BigNumber; +} + +export interface ERC1155MintableURIEventArgs extends DecodedLogArgs { + value: string; + id: BigNumber; +} + +/* istanbul ignore next */ +// tslint:disable:no-parameter-reassignment +// tslint:disable-next-line:class-name +export class ERC1155MintableContract extends BaseContract { + /** + * @ignore + */ + public static deployedBytecode = + '0x608060405234801561001057600080fd5b50600436106101765760003560e01c80639f4b286a116100d8578063e0a5c9491161008c578063f242432a11610066578063f242432a146107bb578063f94190881461085d578063fc67bf1c146108d457610176565b8063e0a5c94914610726578063e44591f014610763578063e985e9c51461078057610176565b8063adebf6f2116100bd578063adebf6f21461067a578063cc10e40114610697578063cd53d08e1461070957610176565b80639f4b286a146105c8578063a22cb4651461063f57610176565b80636352211e1161012f5780637269a327116101145780637269a327146104c557806378b27221146104e25780639cca1c64146105ab57610176565b80636352211e146104625780636f969c2d146104a857610176565b80632eb2c2d6116101605780632eb2c2d6146101e35780634e1273f41461031f5780635e81b9581461043157610176565b8062fdd58e1461017b57806308d7d469146101c6575b600080fd5b6101b46004803603604081101561019157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356108dc565b60408051918252519081900360200190f35b6101b4600480360360208110156101dc57600080fd5b5035610966565b61031d600480360360a08110156101f957600080fd5b73ffffffffffffffffffffffffffffffffffffffff823581169260208101359091169181019060608101604082013564010000000081111561023a57600080fd5b82018360208201111561024c57600080fd5b8035906020019184602083028401116401000000008311171561026e57600080fd5b91939092909160208101903564010000000081111561028c57600080fd5b82018360208201111561029e57600080fd5b803590602001918460208302840111640100000000831117156102c057600080fd5b9193909290916020810190356401000000008111156102de57600080fd5b8201836020820111156102f057600080fd5b8035906020019184600183028401116401000000008311171561031257600080fd5b509092509050610978565b005b6103e16004803603604081101561033557600080fd5b81019060208101813564010000000081111561035057600080fd5b82018360208201111561036257600080fd5b8035906020019184602083028401116401000000008311171561038457600080fd5b9193909290916020810190356401000000008111156103a257600080fd5b8201836020820111156103b457600080fd5b803590602001918460208302840111640100000000831117156103d657600080fd5b509092509050611192565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561041d578181015183820152602001610405565b505050509050019250505060405180910390f35b61044e6004803603602081101561044757600080fd5b5035611357565b604080519115158252519081900360200190f35b61047f6004803603602081101561047857600080fd5b503561139d565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6101b4600480360360208110156104be57600080fd5b50356113c5565b61044e600480360360208110156104db57600080fd5b50356113ea565b61031d600480360360608110156104f857600080fd5b8135919081019060408101602082013564010000000081111561051a57600080fd5b82018360208201111561052c57600080fd5b8035906020019184602083028401116401000000008311171561054e57600080fd5b91939092909160208101903564010000000081111561056c57600080fd5b82018360208201111561057e57600080fd5b803590602001918460208302840111640100000000831117156105a057600080fd5b50909250905061142f565b6101b4600480360360208110156105c157600080fd5b5035611760565b61031d600480360360408110156105de57600080fd5b8135919081019060408101602082013564010000000081111561060057600080fd5b82018360208201111561061257600080fd5b8035906020019184600183028401116401000000008311171561063457600080fd5b509092509050611775565b61031d6004803603604081101561065557600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001351515611875565b61044e6004803603602081101561069057600080fd5b503561190e565b6101b4600480360360408110156106ad57600080fd5b8101906020810181356401000000008111156106c857600080fd5b8201836020820111156106da57600080fd5b803590602001918460018302840111640100000000831117156106fc57600080fd5b9193509150351515611934565b61047f6004803603602081101561071f57600080fd5b5035611a6d565b61072e611a95565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b61044e6004803603602081101561077957600080fd5b5035611ab9565b61044e6004803603604081101561079657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611ae1565b61031d600480360360a08110156107d157600080fd5b73ffffffffffffffffffffffffffffffffffffffff823581169260208101359091169160408201359160608101359181019060a08101608082013564010000000081111561081e57600080fd5b82018360208201111561083057600080fd5b8035906020019184600183028401116401000000008311171561085257600080fd5b509092509050611b1c565b61031d6004803603604081101561087357600080fd5b8135919081019060408101602082013564010000000081111561089557600080fd5b8201836020820111156108a757600080fd5b803590602001918460208302840111640100000000831117156108c957600080fd5b5090925090506120fb565b61072e61242b565b60006108e782611357565b1561092e5760008281526020819052604090205473ffffffffffffffffffffffffffffffffffffffff848116911614610921576000610924565b60015b60ff169050610960565b50600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff861684529091529020545b92915050565b60056020526000908152604090205481565b73ffffffffffffffffffffffffffffffffffffffff87166109fa57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f43414e4e4f545f5452414e534645525f544f5f414444524553535f5a45524f00604482015290519081900360640190fd5b848314610a6857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f544f4b454e5f414e445f56414c5545535f4c454e4754485f4d49534d41544348604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8816331480610ac1575073ffffffffffffffffffffffffffffffffffffffff8816600090815260026020908152604080832033845290915290205460ff1615156001145b610b2c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f494e53554646494349454e545f414c4c4f57414e434500000000000000000000604482015290519081900360640190fd5b60005b85811015610deb576000878783818110610b4557fe5b9050602002013590506000868684818110610b5c57fe5b905060200201359050610b6e82611ab9565b15610cc85780600114610be257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f414d4f554e545f455155414c5f544f5f4f4e455f524551554952454400000000604482015290519081900360640190fd5b60008281526020819052604090205473ffffffffffffffffffffffffffffffffffffffff8c8116911614610c7757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4e46545f4e4f545f4f574e45445f42595f46524f4d5f41444452455353000000604482015290519081900360640190fd5b600082815260208190526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8c16179055610de1565b600082815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8f168452909152902054610d02908261244f565b6001600084815260200190815260200160002060008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610db06001600084815260200190815260200160002060008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482612473565b600083815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8f1684529091529020555b5050600101610b2f565b508673ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb898989896040518080602001806020018381038352878782818152602001925060200280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169091018481038352858152602090810191508690860280828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039850909650505050505050a4610f1f8773ffffffffffffffffffffffffffffffffffffffff1661248f565b156111885760008773ffffffffffffffffffffffffffffffffffffffff1663bc197c81338b8a8a8a8a8a8a6040518963ffffffff1660e01b8152600401808973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001806020018060200184810384528a8a82818152602001925060200280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169091018581038452888152602090810191508990890280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910185810383528681526020019050868680828437600081840152601f19601f8201169050808301925050509b505050505050505050505050602060405180830381600087803b1580156110a857600080fd5b505af11580156110bc573d6000803e3d6000fd5b505050506040513d60208110156110d257600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167fbc197c81000000000000000000000000000000000000000000000000000000001461118657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b5050505050505050565b60608382146111ec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061256a6024913960400191505060405180910390fd5b604080518581526020808702820101909152848015611215578160200160208202803883390190505b50905060005b8481101561134e57600084848381811061123157fe5b90506020020135905061124381611357565b156112b95786868381811061125457fe5b600084815260208181526040909120549102929092013573ffffffffffffffffffffffffffffffffffffffff9081169216919091149050611296576000611299565b60015b60ff168383815181106112a857fe5b602002602001018181525050611345565b6000818152600160205260408120908888858181106112d457fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483838151811061133857fe5b6020026020010181815250505b5060010161121b565b50949350505050565b60007f80000000000000000000000000000000000000000000000000000000000000008083161480156109605750506fffffffffffffffffffffffffffffffff16151590565b60009081526020819052604090205473ffffffffffffffffffffffffffffffffffffffff1690565b7fffffffffffffffffffffffffffffffff000000000000000000000000000000001690565b60007f80000000000000000000000000000000000000000000000000000000000000008083161480156109605750506fffffffffffffffffffffffffffffffff161590565b600085815260046020526040902054859073ffffffffffffffffffffffffffffffffffffffff16331461146157600080fd5b61146a8661190e565b6114bf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d81526020018061258e602d913960400191505060405180910390fd5b60005b848110156117575760008686838181106114d857fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff169050600085858481811061150557fe5b60008c815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8916845282529091205491029290920135925061154a91839150612473565b60008a815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083528184209490945580518d8152918201859052805133927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6292908290030190a46115d68273ffffffffffffffffffffffffffffffffffffffff1661248f565b1561174d57604080517ff23a6e6100000000000000000000000000000000000000000000000000000000815233600482018190526024820152604481018b90526064810183905260a06084820152600060a48201819052915173ffffffffffffffffffffffffffffffffffffffff85169163f23a6e619160e480830192602092919082900301818787803b15801561166d57600080fd5b505af1158015611681573d6000803e3d6000fd5b505050506040513d602081101561169757600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e61000000000000000000000000000000000000000000000000000000001461174b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b50506001016114c2565b50505050505050565b6fffffffffffffffffffffffffffffffff1690565b600083815260046020908152604080832080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163390811790915581518781529283018490528151849391927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62928290030190a4801561187057827f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b838360405180806020018281038252848482818152602001925080828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039550909350505050a25b505050565b33600081815260026020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016861515908117909155815190815290519293927f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31929181900390910190a35050565b7f8000000000000000000000000000000000000000000000000000000000000000161590565b600380546001019081905560801b811561196b577f8000000000000000000000000000000000000000000000000000000000000000175b600081815260046020908152604080832080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163390811790915581518581529283018490528151849391927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62928290030190a48215611a6657807f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b858560405180806020018281038252848482818152602001925080828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039550909350505050a25b9392505050565b60046020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b7ff23a6e610000000000000000000000000000000000000000000000000000000081565b7f80000000000000000000000000000000000000000000000000000000000000009081161490565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260026020908152604080832093909416825291909152205460ff1690565b73ffffffffffffffffffffffffffffffffffffffff8516611b9e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f43414e4e4f545f5452414e534645525f544f5f414444524553535f5a45524f00604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8616331480611bf7575073ffffffffffffffffffffffffffffffffffffffff8616600090815260026020908152604080832033845290915290205460ff1615156001145b611c6257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f494e53554646494349454e545f414c4c4f57414e434500000000000000000000604482015290519081900360640190fd5b611c6b84611ab9565b15611dc55782600114611cdf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f414d4f554e545f455155414c5f544f5f4f4e455f524551554952454400000000604482015290519081900360640190fd5b60008481526020819052604090205473ffffffffffffffffffffffffffffffffffffffff878116911614611d7457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4e46545f4e4f545f4f574e45445f42595f46524f4d5f41444452455353000000604482015290519081900360640190fd5b600084815260208190526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8716179055611e74565b600084815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8a168452909152902054611dff908461244f565b600085815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8b81168552925280832093909355871681522054611e439084612473565b600085815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8a1684529091529020555b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628787604051808381526020018281526020019250505060405180910390a4611f178573ffffffffffffffffffffffffffffffffffffffff1661248f565b156120f35760008573ffffffffffffffffffffffffffffffffffffffff1663f23a6e613389888888886040518763ffffffff1660e01b8152600401808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f820116905080830192505050975050505050505050602060405180830381600087803b15801561201557600080fd5b505af1158015612029573d6000803e3d6000fd5b505050506040513d602081101561203f57600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e61000000000000000000000000000000000000000000000000000000001461175757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505050505050565b600083815260046020526040902054839073ffffffffffffffffffffffffffffffffffffffff16331461212d57600080fd5b61213684611ab9565b61218b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d81526020018061253d602d913960400191505060405180910390fd5b600084815260056020526040812054600101905b838110156123f75760008585838181106121b557fe5b8486018a176000818152602081815260408083208054958302979097013573ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffff00000000000000000000000000000000000000009095168517909655855183815260019181019190915285519396509194869450909233927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6292908290030190a46122768273ffffffffffffffffffffffffffffffffffffffff1661248f565b156123ed57604080517ff23a6e6100000000000000000000000000000000000000000000000000000000815233600482018190526024820152604481018390526001606482015260a06084820152600060a48201819052915173ffffffffffffffffffffffffffffffffffffffff85169163f23a6e619160e480830192602092919082900301818787803b15801561230d57600080fd5b505af1158015612321573d6000803e3d6000fd5b505050506040513d602081101561233757600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e6100000000000000000000000000000000000000000000000000000000146123eb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b505060010161219f565b50600085815260056020526040902054612412908490612473565b6000958652600560205260409095209490945550505050565b7fbc197c810000000000000000000000000000000000000000000000000000000081565b60008282111561246d5761246d61246860028585612495565b612534565b50900390565b600082820183811015611a6657611a6661246860008686612495565b3b151590565b606063e946c1bb60e01b848484604051602401808460038111156124b557fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090509392505050565b805160208201fdfe54524945445f544f5f4d494e545f4e4f4e5f46554e4749424c455f464f525f46554e4749424c455f544f4b454e4f574e4552535f414e445f4944535f4d5553545f484156455f53414d455f4c454e47544854524945445f544f5f4d494e545f46554e4749424c455f464f525f4e4f4e5f46554e4749424c455f544f4b454ea265627a7a723158205af7d187cbffb255b374d24e5838a04f6b3a3245622025907396b2a61f9d93da64736f6c634300050c0032'; + public ERC1155_BATCH_RECEIVED = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('ERC1155_BATCH_RECEIVED()', []); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('ERC1155_BATCH_RECEIVED()'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + public ERC1155_RECEIVED = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync(callData: Partial = {}, defaultBlock?: BlockParam): Promise { + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('ERC1155_RECEIVED()', []); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('ERC1155_RECEIVED()'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + public balanceOf = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param owner The address of the token holder + * @param id ID of the Token + * @returns The _owner's balance of the Token type requested + */ + async callAsync( + owner: string, + id: BigNumber, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isString('owner', owner); + assert.isBigNumber('id', id); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('balanceOf(address,uint256)', [owner.toLowerCase(), id]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('balanceOf(address,uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + public balanceOfBatch = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param owners The addresses of the token holders + * @param ids ID of the Tokens + * @returns The _owner's balance of the Token types requested + */ + async callAsync( + owners: string[], + ids: BigNumber[], + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isArray('owners', owners); + assert.isArray('ids', ids); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('balanceOfBatch(address[],uint256[])', [owners, ids]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('balanceOfBatch(address[],uint256[])'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * creates a new token + */ + public create = { + /** + * Sends an Ethereum transaction executing this method with the supplied parameters. This is a read/write + * Ethereum operation and will cost gas. + * @param uri URI of token + * @param isNF is non-fungible token + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async sendTransactionAsync( + uri: string, + isNF: boolean, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + assert.isString('uri', uri); + assert.isBoolean('isNF', isNF); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('create(string,bool)', [uri, isNF]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + if (opts.shouldValidate !== false) { + await self.create.callAsync(uri, isNF, txDataWithDefaults); + } + + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + return txHash; + }, + /** + * Sends an Ethereum transaction and waits until the transaction has been successfully mined without reverting. + * If the transaction was mined, but reverted, an error is thrown. + * @param uri URI of token + * @param isNF is non-fungible token + * @param txData Additional data for transaction + * @param pollingIntervalMs Interval at which to poll for success + * @returns A promise that resolves when the transaction is successful + */ + awaitTransactionSuccessAsync( + uri: string, + isNF: boolean, + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + assert.isString('uri', uri); + assert.isBoolean('isNF', isNF); + const self = (this as any) as ERC1155MintableContract; + const txHashPromise = self.create.sendTransactionAsync(uri, isNF, txData, opts); + return new PromiseWithTransactionHash( + txHashPromise, + (async (): Promise => { + // When the transaction hash resolves, wait for it to be mined. + return self._web3Wrapper.awaitTransactionSuccessAsync( + await txHashPromise, + opts.pollingIntervalMs, + opts.timeoutMs, + ); + })(), + ); + }, + /** + * Estimates the gas cost of sending an Ethereum transaction calling this method with these arguments. + * @param uri URI of token + * @param isNF is non-fungible token + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async estimateGasAsync(uri: string, isNF: boolean, txData?: Partial | undefined): Promise { + assert.isString('uri', uri); + assert.isBoolean('isNF', isNF); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('create(string,bool)', [uri, isNF]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; + }, + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param uri URI of token + * @param isNF is non-fungible token + * @returns type_ of token (a unique identifier) + */ + async callAsync( + uri: string, + isNF: boolean, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isString('uri', uri); + assert.isBoolean('isNF', isNF); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('create(string,bool)', [uri, isNF]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('create(string,bool)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + /** + * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before + * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used + * to create a 0x transaction (see protocol spec for more details). + * @param uri URI of token + * @param isNF is non-fungible token + * @returns The ABI encoded transaction data as a string + */ + getABIEncodedTransactionData(uri: string, isNF: boolean): string { + assert.isString('uri', uri); + assert.isBoolean('isNF', isNF); + const self = (this as any) as ERC1155MintableContract; + const abiEncodedTransactionData = self._strictEncodeArguments('create(string,bool)', [uri, isNF]); + return abiEncodedTransactionData; + }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as ERC1155MintableContract; + const abiEncoder = self._lookupAbiEncoder('create(string,bool)'); + return abiEncoder.getSelector(); + }, + }; + /** + * creates a new token + */ + public createWithType = { + /** + * Sends an Ethereum transaction executing this method with the supplied parameters. This is a read/write + * Ethereum operation and will cost gas. + * @param type_ of token + * @param uri URI of token + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async sendTransactionAsync( + type_: BigNumber, + uri: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + assert.isBigNumber('type_', type_); + assert.isString('uri', uri); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('createWithType(uint256,string)', [type_, uri]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + if (opts.shouldValidate !== false) { + await self.createWithType.callAsync(type_, uri, txDataWithDefaults); + } + + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + return txHash; + }, + /** + * Sends an Ethereum transaction and waits until the transaction has been successfully mined without reverting. + * If the transaction was mined, but reverted, an error is thrown. + * @param type_ of token + * @param uri URI of token + * @param txData Additional data for transaction + * @param pollingIntervalMs Interval at which to poll for success + * @returns A promise that resolves when the transaction is successful + */ + awaitTransactionSuccessAsync( + type_: BigNumber, + uri: string, + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + assert.isBigNumber('type_', type_); + assert.isString('uri', uri); + const self = (this as any) as ERC1155MintableContract; + const txHashPromise = self.createWithType.sendTransactionAsync(type_, uri, txData, opts); + return new PromiseWithTransactionHash( + txHashPromise, + (async (): Promise => { + // When the transaction hash resolves, wait for it to be mined. + return self._web3Wrapper.awaitTransactionSuccessAsync( + await txHashPromise, + opts.pollingIntervalMs, + opts.timeoutMs, + ); + })(), + ); + }, + /** + * Estimates the gas cost of sending an Ethereum transaction calling this method with these arguments. + * @param type_ of token + * @param uri URI of token + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async estimateGasAsync(type_: BigNumber, uri: string, txData?: Partial | undefined): Promise { + assert.isBigNumber('type_', type_); + assert.isString('uri', uri); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('createWithType(uint256,string)', [type_, uri]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; + }, + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param type_ of token + * @param uri URI of token + */ + async callAsync( + type_: BigNumber, + uri: string, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isBigNumber('type_', type_); + assert.isString('uri', uri); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('createWithType(uint256,string)', [type_, uri]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('createWithType(uint256,string)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + /** + * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before + * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used + * to create a 0x transaction (see protocol spec for more details). + * @param type_ of token + * @param uri URI of token + * @returns The ABI encoded transaction data as a string + */ + getABIEncodedTransactionData(type_: BigNumber, uri: string): string { + assert.isBigNumber('type_', type_); + assert.isString('uri', uri); + const self = (this as any) as ERC1155MintableContract; + const abiEncodedTransactionData = self._strictEncodeArguments('createWithType(uint256,string)', [ + type_, + uri, + ]); + return abiEncodedTransactionData; + }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as ERC1155MintableContract; + const abiEncoder = self._lookupAbiEncoder('createWithType(uint256,string)'); + return abiEncoder.getSelector(); + }, + }; + public creators = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync( + index_0: BigNumber, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isBigNumber('index_0', index_0); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('creators(uint256)', [index_0]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('creators(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * Returns base type of non-fungible token + */ + public getNonFungibleBaseType = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync( + id: BigNumber, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isBigNumber('id', id); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('getNonFungibleBaseType(uint256)', [id]); + const encodedDataBytes = Buffer.from(encodedData.substr(2), 'hex'); + + let rawCallResult; + try { + rawCallResult = await self._evmExecAsync(encodedDataBytes); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + + const abiEncoder = self._lookupAbiEncoder('getNonFungibleBaseType(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * Returns index of non-fungible token + */ + public getNonFungibleIndex = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync( + id: BigNumber, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isBigNumber('id', id); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('getNonFungibleIndex(uint256)', [id]); + const encodedDataBytes = Buffer.from(encodedData.substr(2), 'hex'); + + let rawCallResult; + try { + rawCallResult = await self._evmExecAsync(encodedDataBytes); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + + const abiEncoder = self._lookupAbiEncoder('getNonFungibleIndex(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + public isApprovedForAll = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param owner The owner of the Tokens + * @param operator Address of authorized operator + * @returns True if the operator is approved, false if not + */ + async callAsync( + owner: string, + operator: string, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isString('owner', owner); + assert.isString('operator', operator); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('isApprovedForAll(address,address)', [ + owner.toLowerCase(), + operator.toLowerCase(), + ]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('isApprovedForAll(address,address)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * Returns true if token is fungible + */ + public isFungible = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync(id: BigNumber, callData: Partial = {}, defaultBlock?: BlockParam): Promise { + assert.isBigNumber('id', id); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('isFungible(uint256)', [id]); + const encodedDataBytes = Buffer.from(encodedData.substr(2), 'hex'); + + let rawCallResult; + try { + rawCallResult = await self._evmExecAsync(encodedDataBytes); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + + const abiEncoder = self._lookupAbiEncoder('isFungible(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * Returns true if token is non-fungible + */ + public isNonFungible = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync(id: BigNumber, callData: Partial = {}, defaultBlock?: BlockParam): Promise { + assert.isBigNumber('id', id); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('isNonFungible(uint256)', [id]); + const encodedDataBytes = Buffer.from(encodedData.substr(2), 'hex'); + + let rawCallResult; + try { + rawCallResult = await self._evmExecAsync(encodedDataBytes); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + + const abiEncoder = self._lookupAbiEncoder('isNonFungible(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * Returns true if input is base-type of a non-fungible token + */ + public isNonFungibleBaseType = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync(id: BigNumber, callData: Partial = {}, defaultBlock?: BlockParam): Promise { + assert.isBigNumber('id', id); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('isNonFungibleBaseType(uint256)', [id]); + const encodedDataBytes = Buffer.from(encodedData.substr(2), 'hex'); + + let rawCallResult; + try { + rawCallResult = await self._evmExecAsync(encodedDataBytes); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + + const abiEncoder = self._lookupAbiEncoder('isNonFungibleBaseType(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * Returns true if input is a non-fungible token + */ + public isNonFungibleItem = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync(id: BigNumber, callData: Partial = {}, defaultBlock?: BlockParam): Promise { + assert.isBigNumber('id', id); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('isNonFungibleItem(uint256)', [id]); + const encodedDataBytes = Buffer.from(encodedData.substr(2), 'hex'); + + let rawCallResult; + try { + rawCallResult = await self._evmExecAsync(encodedDataBytes); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + + const abiEncoder = self._lookupAbiEncoder('isNonFungibleItem(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + public maxIndex = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync( + index_0: BigNumber, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isBigNumber('index_0', index_0); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('maxIndex(uint256)', [index_0]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('maxIndex(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * mints fungible tokens + */ + public mintFungible = { + /** + * Sends an Ethereum transaction executing this method with the supplied parameters. This is a read/write + * Ethereum operation and will cost gas. + * @param id token type + * @param to beneficiaries of minted tokens + * @param quantities amounts of minted tokens + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async sendTransactionAsync( + id: BigNumber, + to: string[], + quantities: BigNumber[], + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + assert.isBigNumber('id', id); + assert.isArray('to', to); + assert.isArray('quantities', quantities); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('mintFungible(uint256,address[],uint256[])', [ + id, + to, + quantities, + ]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + if (opts.shouldValidate !== false) { + await self.mintFungible.callAsync(id, to, quantities, txDataWithDefaults); + } + + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + return txHash; + }, + /** + * Sends an Ethereum transaction and waits until the transaction has been successfully mined without reverting. + * If the transaction was mined, but reverted, an error is thrown. + * @param id token type + * @param to beneficiaries of minted tokens + * @param quantities amounts of minted tokens + * @param txData Additional data for transaction + * @param pollingIntervalMs Interval at which to poll for success + * @returns A promise that resolves when the transaction is successful + */ + awaitTransactionSuccessAsync( + id: BigNumber, + to: string[], + quantities: BigNumber[], + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + assert.isBigNumber('id', id); + assert.isArray('to', to); + assert.isArray('quantities', quantities); + const self = (this as any) as ERC1155MintableContract; + const txHashPromise = self.mintFungible.sendTransactionAsync(id, to, quantities, txData, opts); + return new PromiseWithTransactionHash( + txHashPromise, + (async (): Promise => { + // When the transaction hash resolves, wait for it to be mined. + return self._web3Wrapper.awaitTransactionSuccessAsync( + await txHashPromise, + opts.pollingIntervalMs, + opts.timeoutMs, + ); + })(), + ); + }, + /** + * Estimates the gas cost of sending an Ethereum transaction calling this method with these arguments. + * @param id token type + * @param to beneficiaries of minted tokens + * @param quantities amounts of minted tokens + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async estimateGasAsync( + id: BigNumber, + to: string[], + quantities: BigNumber[], + txData?: Partial | undefined, + ): Promise { + assert.isBigNumber('id', id); + assert.isArray('to', to); + assert.isArray('quantities', quantities); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('mintFungible(uint256,address[],uint256[])', [ + id, + to, + quantities, + ]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; + }, + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param id token type + * @param to beneficiaries of minted tokens + * @param quantities amounts of minted tokens + */ + async callAsync( + id: BigNumber, + to: string[], + quantities: BigNumber[], + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isBigNumber('id', id); + assert.isArray('to', to); + assert.isArray('quantities', quantities); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('mintFungible(uint256,address[],uint256[])', [ + id, + to, + quantities, + ]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('mintFungible(uint256,address[],uint256[])'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + /** + * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before + * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used + * to create a 0x transaction (see protocol spec for more details). + * @param id token type + * @param to beneficiaries of minted tokens + * @param quantities amounts of minted tokens + * @returns The ABI encoded transaction data as a string + */ + getABIEncodedTransactionData(id: BigNumber, to: string[], quantities: BigNumber[]): string { + assert.isBigNumber('id', id); + assert.isArray('to', to); + assert.isArray('quantities', quantities); + const self = (this as any) as ERC1155MintableContract; + const abiEncodedTransactionData = self._strictEncodeArguments('mintFungible(uint256,address[],uint256[])', [ + id, + to, + quantities, + ]); + return abiEncodedTransactionData; + }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as ERC1155MintableContract; + const abiEncoder = self._lookupAbiEncoder('mintFungible(uint256,address[],uint256[])'); + return abiEncoder.getSelector(); + }, + }; + /** + * mints a non-fungible token + */ + public mintNonFungible = { + /** + * Sends an Ethereum transaction executing this method with the supplied parameters. This is a read/write + * Ethereum operation and will cost gas. + * @param type_ token type + * @param to beneficiaries of minted tokens + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async sendTransactionAsync( + type_: BigNumber, + to: string[], + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + assert.isBigNumber('type_', type_); + assert.isArray('to', to); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('mintNonFungible(uint256,address[])', [type_, to]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + if (opts.shouldValidate !== false) { + await self.mintNonFungible.callAsync(type_, to, txDataWithDefaults); + } + + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + return txHash; + }, + /** + * Sends an Ethereum transaction and waits until the transaction has been successfully mined without reverting. + * If the transaction was mined, but reverted, an error is thrown. + * @param type_ token type + * @param to beneficiaries of minted tokens + * @param txData Additional data for transaction + * @param pollingIntervalMs Interval at which to poll for success + * @returns A promise that resolves when the transaction is successful + */ + awaitTransactionSuccessAsync( + type_: BigNumber, + to: string[], + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + assert.isBigNumber('type_', type_); + assert.isArray('to', to); + const self = (this as any) as ERC1155MintableContract; + const txHashPromise = self.mintNonFungible.sendTransactionAsync(type_, to, txData, opts); + return new PromiseWithTransactionHash( + txHashPromise, + (async (): Promise => { + // When the transaction hash resolves, wait for it to be mined. + return self._web3Wrapper.awaitTransactionSuccessAsync( + await txHashPromise, + opts.pollingIntervalMs, + opts.timeoutMs, + ); + })(), + ); + }, + /** + * Estimates the gas cost of sending an Ethereum transaction calling this method with these arguments. + * @param type_ token type + * @param to beneficiaries of minted tokens + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async estimateGasAsync(type_: BigNumber, to: string[], txData?: Partial | undefined): Promise { + assert.isBigNumber('type_', type_); + assert.isArray('to', to); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('mintNonFungible(uint256,address[])', [type_, to]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; + }, + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param type_ token type + * @param to beneficiaries of minted tokens + */ + async callAsync( + type_: BigNumber, + to: string[], + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isBigNumber('type_', type_); + assert.isArray('to', to); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('mintNonFungible(uint256,address[])', [type_, to]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('mintNonFungible(uint256,address[])'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + /** + * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before + * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used + * to create a 0x transaction (see protocol spec for more details). + * @param type_ token type + * @param to beneficiaries of minted tokens + * @returns The ABI encoded transaction data as a string + */ + getABIEncodedTransactionData(type_: BigNumber, to: string[]): string { + assert.isBigNumber('type_', type_); + assert.isArray('to', to); + const self = (this as any) as ERC1155MintableContract; + const abiEncodedTransactionData = self._strictEncodeArguments('mintNonFungible(uint256,address[])', [ + type_, + to, + ]); + return abiEncodedTransactionData; + }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as ERC1155MintableContract; + const abiEncoder = self._lookupAbiEncoder('mintNonFungible(uint256,address[])'); + return abiEncoder.getSelector(); + }, + }; + /** + * returns owner of a non-fungible token + */ + public ownerOf = { + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + */ + async callAsync(id: BigNumber, callData: Partial = {}, defaultBlock?: BlockParam): Promise { + assert.isBigNumber('id', id); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('ownerOf(uint256)', [id]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('ownerOf(uint256)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + }; + /** + * MUST emit TransferBatch event on success. Caller must be approved to manage the _from account's tokens (see isApprovedForAll). MUST throw if `_to` is the zero address. MUST throw if length of `_ids` is not the same as length of `_values`. MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_values` sent. MUST throw on any other error. When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return value is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`. + */ + public safeBatchTransferFrom = { + /** + * Sends an Ethereum transaction executing this method with the supplied parameters. This is a read/write + * Ethereum operation and will cost gas. + * @param from Source addresses + * @param to Target addresses + * @param ids IDs of each token type + * @param values Transfer amounts per token type + * @param data Additional data with no specified format, sent in call to `_to` + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async sendTransactionAsync( + from: string, + to: string, + ids: BigNumber[], + values: BigNumber[], + data: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + assert.isString('from', from); + assert.isString('to', to); + assert.isArray('ids', ids); + assert.isArray('values', values); + assert.isString('data', data); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments( + 'safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)', + [from.toLowerCase(), to.toLowerCase(), ids, values, data], + ); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + if (opts.shouldValidate !== false) { + await self.safeBatchTransferFrom.callAsync(from, to, ids, values, data, txDataWithDefaults); + } + + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + return txHash; + }, + /** + * Sends an Ethereum transaction and waits until the transaction has been successfully mined without reverting. + * If the transaction was mined, but reverted, an error is thrown. + * @param from Source addresses + * @param to Target addresses + * @param ids IDs of each token type + * @param values Transfer amounts per token type + * @param data Additional data with no specified format, sent in call to `_to` + * @param txData Additional data for transaction + * @param pollingIntervalMs Interval at which to poll for success + * @returns A promise that resolves when the transaction is successful + */ + awaitTransactionSuccessAsync( + from: string, + to: string, + ids: BigNumber[], + values: BigNumber[], + data: string, + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + assert.isString('from', from); + assert.isString('to', to); + assert.isArray('ids', ids); + assert.isArray('values', values); + assert.isString('data', data); + const self = (this as any) as ERC1155MintableContract; + const txHashPromise = self.safeBatchTransferFrom.sendTransactionAsync( + from.toLowerCase(), + to.toLowerCase(), + ids, + values, + data, + txData, + opts, + ); + return new PromiseWithTransactionHash( + txHashPromise, + (async (): Promise => { + // When the transaction hash resolves, wait for it to be mined. + return self._web3Wrapper.awaitTransactionSuccessAsync( + await txHashPromise, + opts.pollingIntervalMs, + opts.timeoutMs, + ); + })(), + ); + }, + /** + * Estimates the gas cost of sending an Ethereum transaction calling this method with these arguments. + * @param from Source addresses + * @param to Target addresses + * @param ids IDs of each token type + * @param values Transfer amounts per token type + * @param data Additional data with no specified format, sent in call to `_to` + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async estimateGasAsync( + from: string, + to: string, + ids: BigNumber[], + values: BigNumber[], + data: string, + txData?: Partial | undefined, + ): Promise { + assert.isString('from', from); + assert.isString('to', to); + assert.isArray('ids', ids); + assert.isArray('values', values); + assert.isString('data', data); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments( + 'safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)', + [from.toLowerCase(), to.toLowerCase(), ids, values, data], + ); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; + }, + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param from Source addresses + * @param to Target addresses + * @param ids IDs of each token type + * @param values Transfer amounts per token type + * @param data Additional data with no specified format, sent in call to `_to` + */ + async callAsync( + from: string, + to: string, + ids: BigNumber[], + values: BigNumber[], + data: string, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isString('from', from); + assert.isString('to', to); + assert.isArray('ids', ids); + assert.isArray('values', values); + assert.isString('data', data); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments( + 'safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)', + [from.toLowerCase(), to.toLowerCase(), ids, values, data], + ); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder( + 'safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)', + ); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + /** + * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before + * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used + * to create a 0x transaction (see protocol spec for more details). + * @param from Source addresses + * @param to Target addresses + * @param ids IDs of each token type + * @param values Transfer amounts per token type + * @param data Additional data with no specified format, sent in call to `_to` + * @returns The ABI encoded transaction data as a string + */ + getABIEncodedTransactionData( + from: string, + to: string, + ids: BigNumber[], + values: BigNumber[], + data: string, + ): string { + assert.isString('from', from); + assert.isString('to', to); + assert.isArray('ids', ids); + assert.isArray('values', values); + assert.isString('data', data); + const self = (this as any) as ERC1155MintableContract; + const abiEncodedTransactionData = self._strictEncodeArguments( + 'safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)', + [from.toLowerCase(), to.toLowerCase(), ids, values, data], + ); + return abiEncodedTransactionData; + }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as ERC1155MintableContract; + const abiEncoder = self._lookupAbiEncoder( + 'safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)', + ); + return abiEncoder.getSelector(); + }, + }; + /** + * MUST emit TransferSingle event on success. Caller must be approved to manage the _from account's tokens (see isApprovedForAll). MUST throw if `_to` is the zero address. MUST throw if balance of sender for token `_id` is lower than the `_value` sent. MUST throw on any other error. When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return value is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`. + */ + public safeTransferFrom = { + /** + * Sends an Ethereum transaction executing this method with the supplied parameters. This is a read/write + * Ethereum operation and will cost gas. + * @param from Source address + * @param to Target address + * @param id ID of the token type + * @param value Transfer amount + * @param data Additional data with no specified format, sent in call to `_to` + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async sendTransactionAsync( + from: string, + to: string, + id: BigNumber, + value: BigNumber, + data: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + assert.isString('from', from); + assert.isString('to', to); + assert.isBigNumber('id', id); + assert.isBigNumber('value', value); + assert.isString('data', data); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('safeTransferFrom(address,address,uint256,uint256,bytes)', [ + from.toLowerCase(), + to.toLowerCase(), + id, + value, + data, + ]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + if (opts.shouldValidate !== false) { + await self.safeTransferFrom.callAsync(from, to, id, value, data, txDataWithDefaults); + } + + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + return txHash; + }, + /** + * Sends an Ethereum transaction and waits until the transaction has been successfully mined without reverting. + * If the transaction was mined, but reverted, an error is thrown. + * @param from Source address + * @param to Target address + * @param id ID of the token type + * @param value Transfer amount + * @param data Additional data with no specified format, sent in call to `_to` + * @param txData Additional data for transaction + * @param pollingIntervalMs Interval at which to poll for success + * @returns A promise that resolves when the transaction is successful + */ + awaitTransactionSuccessAsync( + from: string, + to: string, + id: BigNumber, + value: BigNumber, + data: string, + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + assert.isString('from', from); + assert.isString('to', to); + assert.isBigNumber('id', id); + assert.isBigNumber('value', value); + assert.isString('data', data); + const self = (this as any) as ERC1155MintableContract; + const txHashPromise = self.safeTransferFrom.sendTransactionAsync( + from.toLowerCase(), + to.toLowerCase(), + id, + value, + data, + txData, + opts, + ); + return new PromiseWithTransactionHash( + txHashPromise, + (async (): Promise => { + // When the transaction hash resolves, wait for it to be mined. + return self._web3Wrapper.awaitTransactionSuccessAsync( + await txHashPromise, + opts.pollingIntervalMs, + opts.timeoutMs, + ); + })(), + ); + }, + /** + * Estimates the gas cost of sending an Ethereum transaction calling this method with these arguments. + * @param from Source address + * @param to Target address + * @param id ID of the token type + * @param value Transfer amount + * @param data Additional data with no specified format, sent in call to `_to` + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async estimateGasAsync( + from: string, + to: string, + id: BigNumber, + value: BigNumber, + data: string, + txData?: Partial | undefined, + ): Promise { + assert.isString('from', from); + assert.isString('to', to); + assert.isBigNumber('id', id); + assert.isBigNumber('value', value); + assert.isString('data', data); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('safeTransferFrom(address,address,uint256,uint256,bytes)', [ + from.toLowerCase(), + to.toLowerCase(), + id, + value, + data, + ]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; + }, + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param from Source address + * @param to Target address + * @param id ID of the token type + * @param value Transfer amount + * @param data Additional data with no specified format, sent in call to `_to` + */ + async callAsync( + from: string, + to: string, + id: BigNumber, + value: BigNumber, + data: string, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isString('from', from); + assert.isString('to', to); + assert.isBigNumber('id', id); + assert.isBigNumber('value', value); + assert.isString('data', data); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('safeTransferFrom(address,address,uint256,uint256,bytes)', [ + from.toLowerCase(), + to.toLowerCase(), + id, + value, + data, + ]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256,uint256,bytes)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + /** + * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before + * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used + * to create a 0x transaction (see protocol spec for more details). + * @param from Source address + * @param to Target address + * @param id ID of the token type + * @param value Transfer amount + * @param data Additional data with no specified format, sent in call to `_to` + * @returns The ABI encoded transaction data as a string + */ + getABIEncodedTransactionData(from: string, to: string, id: BigNumber, value: BigNumber, data: string): string { + assert.isString('from', from); + assert.isString('to', to); + assert.isBigNumber('id', id); + assert.isBigNumber('value', value); + assert.isString('data', data); + const self = (this as any) as ERC1155MintableContract; + const abiEncodedTransactionData = self._strictEncodeArguments( + 'safeTransferFrom(address,address,uint256,uint256,bytes)', + [from.toLowerCase(), to.toLowerCase(), id, value, data], + ); + return abiEncodedTransactionData; + }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as ERC1155MintableContract; + const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256,uint256,bytes)'); + return abiEncoder.getSelector(); + }, + }; + /** + * MUST emit the ApprovalForAll event on success. + */ + public setApprovalForAll = { + /** + * Sends an Ethereum transaction executing this method with the supplied parameters. This is a read/write + * Ethereum operation and will cost gas. + * @param operator Address to add to the set of authorized operators + * @param approved True if the operator is approved, false to revoke approval + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async sendTransactionAsync( + operator: string, + approved: boolean, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { + assert.isString('operator', operator); + assert.isBoolean('approved', approved); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('setApprovalForAll(address,bool)', [ + operator.toLowerCase(), + approved, + ]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + if (opts.shouldValidate !== false) { + await self.setApprovalForAll.callAsync(operator, approved, txDataWithDefaults); + } + + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); + return txHash; + }, + /** + * Sends an Ethereum transaction and waits until the transaction has been successfully mined without reverting. + * If the transaction was mined, but reverted, an error is thrown. + * @param operator Address to add to the set of authorized operators + * @param approved True if the operator is approved, false to revoke approval + * @param txData Additional data for transaction + * @param pollingIntervalMs Interval at which to poll for success + * @returns A promise that resolves when the transaction is successful + */ + awaitTransactionSuccessAsync( + operator: string, + approved: boolean, + txData?: Partial, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, + ): PromiseWithTransactionHash { + assert.isString('operator', operator); + assert.isBoolean('approved', approved); + const self = (this as any) as ERC1155MintableContract; + const txHashPromise = self.setApprovalForAll.sendTransactionAsync( + operator.toLowerCase(), + approved, + txData, + opts, + ); + return new PromiseWithTransactionHash( + txHashPromise, + (async (): Promise => { + // When the transaction hash resolves, wait for it to be mined. + return self._web3Wrapper.awaitTransactionSuccessAsync( + await txHashPromise, + opts.pollingIntervalMs, + opts.timeoutMs, + ); + })(), + ); + }, + /** + * Estimates the gas cost of sending an Ethereum transaction calling this method with these arguments. + * @param operator Address to add to the set of authorized operators + * @param approved True if the operator is approved, false to revoke approval + * @param txData Additional data for transaction + * @returns The hash of the transaction + */ + async estimateGasAsync( + operator: string, + approved: boolean, + txData?: Partial | undefined, + ): Promise { + assert.isString('operator', operator); + assert.isBoolean('approved', approved); + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('setApprovalForAll(address,bool)', [ + operator.toLowerCase(), + approved, + ]); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; + }, + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param operator Address to add to the set of authorized operators + * @param approved True if the operator is approved, false to revoke approval + */ + async callAsync( + operator: string, + approved: boolean, + callData: Partial = {}, + defaultBlock?: BlockParam, + ): Promise { + assert.isString('operator', operator); + assert.isBoolean('approved', approved); + assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (defaultBlock !== undefined) { + assert.isBlockParam('defaultBlock', defaultBlock); + } + const self = (this as any) as ERC1155MintableContract; + const encodedData = self._strictEncodeArguments('setApprovalForAll(address,bool)', [ + operator.toLowerCase(), + approved, + ]); + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...callData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); + const abiEncoder = self._lookupAbiEncoder('setApprovalForAll(address,bool)'); + // tslint:disable boolean-naming + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; + }, + /** + * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before + * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used + * to create a 0x transaction (see protocol spec for more details). + * @param operator Address to add to the set of authorized operators + * @param approved True if the operator is approved, false to revoke approval + * @returns The ABI encoded transaction data as a string + */ + getABIEncodedTransactionData(operator: string, approved: boolean): string { + assert.isString('operator', operator); + assert.isBoolean('approved', approved); + const self = (this as any) as ERC1155MintableContract; + const abiEncodedTransactionData = self._strictEncodeArguments('setApprovalForAll(address,bool)', [ + operator.toLowerCase(), + approved, + ]); + return abiEncodedTransactionData; + }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as ERC1155MintableContract; + const abiEncoder = self._lookupAbiEncoder('setApprovalForAll(address,bool)'); + return abiEncoder.getSelector(); + }, + }; + private readonly _subscriptionManager: SubscriptionManager; + public static async deployFrom0xArtifactAsync( + artifact: ContractArtifact | SimpleContractArtifact, + supportedProvider: SupportedProvider, + txDefaults: Partial, + logDecodeDependencies: { [contractName: string]: ContractArtifact | SimpleContractArtifact }, + ): Promise { + assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + if (artifact.compilerOutput === undefined) { + throw new Error('Compiler output not found in the artifact file'); + } + const provider = providerUtils.standardizeOrThrow(supportedProvider); + const bytecode = artifact.compilerOutput.evm.bytecode.object; + const abi = artifact.compilerOutput.abi; + const logDecodeDependenciesAbiOnly: { [contractName: string]: ContractAbi } = {}; + if (Object.keys(logDecodeDependencies) !== undefined) { + for (const key of Object.keys(logDecodeDependencies)) { + logDecodeDependenciesAbiOnly[key] = logDecodeDependencies[key].compilerOutput.abi; + } + } + return ERC1155MintableContract.deployAsync(bytecode, abi, provider, txDefaults, logDecodeDependenciesAbiOnly); + } + public static async deployAsync( + bytecode: string, + abi: ContractAbi, + supportedProvider: SupportedProvider, + txDefaults: Partial, + logDecodeDependencies: { [contractName: string]: ContractAbi }, + ): Promise { + assert.isHexString('bytecode', bytecode); + assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [ + schemas.addressSchema, + schemas.numberSchema, + schemas.jsNumber, + ]); + const provider = providerUtils.standardizeOrThrow(supportedProvider); + const constructorAbi = BaseContract._lookupConstructorAbi(abi); + [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString); + const iface = new ethers.utils.Interface(abi); + const deployInfo = iface.deployFunction; + const txData = deployInfo.encode(bytecode, []); + const web3Wrapper = new Web3Wrapper(provider); + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { data: txData }, + txDefaults, + web3Wrapper.estimateGasAsync.bind(web3Wrapper), + ); + const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults); + logUtils.log(`transactionHash: ${txHash}`); + const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); + logUtils.log(`ERC1155Mintable successfully deployed at ${txReceipt.contractAddress}`); + const contractInstance = new ERC1155MintableContract( + txReceipt.contractAddress as string, + provider, + txDefaults, + logDecodeDependencies, + ); + contractInstance.constructorArgs = []; + return contractInstance; + } + + /** + * @returns The contract ABI + */ + public static ABI(): ContractAbi { + const abi = [ + { + anonymous: false, + inputs: [ + { + name: 'owner', + type: 'address', + indexed: true, + }, + { + name: 'operator', + type: 'address', + indexed: true, + }, + { + name: 'approved', + type: 'bool', + indexed: false, + }, + ], + name: 'ApprovalForAll', + outputs: [], + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + name: 'operator', + type: 'address', + indexed: true, + }, + { + name: 'from', + type: 'address', + indexed: true, + }, + { + name: 'to', + type: 'address', + indexed: true, + }, + { + name: 'ids', + type: 'uint256[]', + indexed: false, + }, + { + name: 'values', + type: 'uint256[]', + indexed: false, + }, + ], + name: 'TransferBatch', + outputs: [], + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + name: 'operator', + type: 'address', + indexed: true, + }, + { + name: 'from', + type: 'address', + indexed: true, + }, + { + name: 'to', + type: 'address', + indexed: true, + }, + { + name: 'id', + type: 'uint256', + indexed: false, + }, + { + name: 'value', + type: 'uint256', + indexed: false, + }, + ], + name: 'TransferSingle', + outputs: [], + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + name: 'value', + type: 'string', + indexed: false, + }, + { + name: 'id', + type: 'uint256', + indexed: true, + }, + ], + name: 'URI', + outputs: [], + type: 'event', + }, + { + constant: true, + inputs: [], + name: 'ERC1155_BATCH_RECEIVED', + outputs: [ + { + name: '', + type: 'bytes4', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [], + name: 'ERC1155_RECEIVED', + outputs: [ + { + name: '', + type: 'bytes4', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'owner', + type: 'address', + }, + { + name: 'id', + type: 'uint256', + }, + ], + name: 'balanceOf', + outputs: [ + { + name: '', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'owners', + type: 'address[]', + }, + { + name: 'ids', + type: 'uint256[]', + }, + ], + name: 'balanceOfBatch', + outputs: [ + { + name: 'balances_', + type: 'uint256[]', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: false, + inputs: [ + { + name: 'uri', + type: 'string', + }, + { + name: 'isNF', + type: 'bool', + }, + ], + name: 'create', + outputs: [ + { + name: 'type_', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: false, + inputs: [ + { + name: 'type_', + type: 'uint256', + }, + { + name: 'uri', + type: 'string', + }, + ], + name: 'createWithType', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'index_0', + type: 'uint256', + }, + ], + name: 'creators', + outputs: [ + { + name: '', + type: 'address', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'id', + type: 'uint256', + }, + ], + name: 'getNonFungibleBaseType', + outputs: [ + { + name: '', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'pure', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'id', + type: 'uint256', + }, + ], + name: 'getNonFungibleIndex', + outputs: [ + { + name: '', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'pure', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'owner', + type: 'address', + }, + { + name: 'operator', + type: 'address', + }, + ], + name: 'isApprovedForAll', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'id', + type: 'uint256', + }, + ], + name: 'isFungible', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'pure', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'id', + type: 'uint256', + }, + ], + name: 'isNonFungible', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'pure', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'id', + type: 'uint256', + }, + ], + name: 'isNonFungibleBaseType', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'pure', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'id', + type: 'uint256', + }, + ], + name: 'isNonFungibleItem', + outputs: [ + { + name: '', + type: 'bool', + }, + ], + payable: false, + stateMutability: 'pure', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'index_0', + type: 'uint256', + }, + ], + name: 'maxIndex', + outputs: [ + { + name: '', + type: 'uint256', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: false, + inputs: [ + { + name: 'id', + type: 'uint256', + }, + { + name: 'to', + type: 'address[]', + }, + { + name: 'quantities', + type: 'uint256[]', + }, + ], + name: 'mintFungible', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: false, + inputs: [ + { + name: 'type_', + type: 'uint256', + }, + { + name: 'to', + type: 'address[]', + }, + ], + name: 'mintNonFungible', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: true, + inputs: [ + { + name: 'id', + type: 'uint256', + }, + ], + name: 'ownerOf', + outputs: [ + { + name: '', + type: 'address', + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + { + constant: false, + inputs: [ + { + name: 'from', + type: 'address', + }, + { + name: 'to', + type: 'address', + }, + { + name: 'ids', + type: 'uint256[]', + }, + { + name: 'values', + type: 'uint256[]', + }, + { + name: 'data', + type: 'bytes', + }, + ], + name: 'safeBatchTransferFrom', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: false, + inputs: [ + { + name: 'from', + type: 'address', + }, + { + name: 'to', + type: 'address', + }, + { + name: 'id', + type: 'uint256', + }, + { + name: 'value', + type: 'uint256', + }, + { + name: 'data', + type: 'bytes', + }, + ], + name: 'safeTransferFrom', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + { + constant: false, + inputs: [ + { + name: 'operator', + type: 'address', + }, + { + name: 'approved', + type: 'bool', + }, + ], + name: 'setApprovalForAll', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function', + }, + ] as ContractAbi; + return abi; + } + /** + * Subscribe to an event type emitted by the ERC1155Mintable contract. + * @param eventName The ERC1155Mintable contract event you would like to subscribe to. + * @param indexFilterValues An object where the keys are indexed args returned by the event and + * the value is the value you are interested in. E.g `{maker: aUserAddressHex}` + * @param callback Callback that gets called when a log is added/removed + * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) + * @return Subscription token used later to unsubscribe + */ + public subscribe( + eventName: ERC1155MintableEvents, + indexFilterValues: IndexedFilterValues, + callback: EventCallback, + isVerbose: boolean = false, + blockPollingIntervalMs?: number, + ): string { + assert.doesBelongToStringEnum('eventName', eventName, ERC1155MintableEvents); + assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); + assert.isFunction('callback', callback); + const subscriptionToken = this._subscriptionManager.subscribe( + this.address, + eventName, + indexFilterValues, + ERC1155MintableContract.ABI(), + callback, + isVerbose, + blockPollingIntervalMs, + ); + return subscriptionToken; + } + /** + * Cancel a subscription + * @param subscriptionToken Subscription token returned by `subscribe()` + */ + public unsubscribe(subscriptionToken: string): void { + this._subscriptionManager.unsubscribe(subscriptionToken); + } + /** + * Cancels all existing subscriptions + */ + public unsubscribeAll(): void { + this._subscriptionManager.unsubscribeAll(); + } + /** + * Gets historical logs without creating a subscription + * @param eventName The ERC1155Mintable contract event you would like to subscribe to. + * @param blockRange Block range to get logs from. + * @param indexFilterValues An object where the keys are indexed args returned by the event and + * the value is the value you are interested in. E.g `{_from: aUserAddressHex}` + * @return Array of logs that match the parameters + */ + public async getLogsAsync( + eventName: ERC1155MintableEvents, + blockRange: BlockRange, + indexFilterValues: IndexedFilterValues, + ): Promise>> { + assert.doesBelongToStringEnum('eventName', eventName, ERC1155MintableEvents); + assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); + assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); + const logs = await this._subscriptionManager.getLogsAsync( + this.address, + eventName, + blockRange, + indexFilterValues, + ERC1155MintableContract.ABI(), + ); + return logs; + } + constructor( + address: string, + supportedProvider: SupportedProvider, + txDefaults?: Partial, + logDecodeDependencies?: { [contractName: string]: ContractAbi }, + deployedBytecode: string | undefined = ERC1155MintableContract.deployedBytecode, + ) { + super( + 'ERC1155Mintable', + ERC1155MintableContract.ABI(), + address, + supportedProvider, + txDefaults, + logDecodeDependencies, + deployedBytecode, + ); + classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']); + this._subscriptionManager = new SubscriptionManager( + ERC1155MintableContract.ABI(), + this._web3Wrapper, + ); + } +} + +// tslint:disable:max-file-line-count +// tslint:enable:no-unbound-method no-parameter-reassignment no-consecutive-blank-lines ordered-imports align +// tslint:enable:trailing-comma whitespace no-trailing-whitespace diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/erc1155_proxy.ts b/packages/abi-gen-wrappers/src/generated-wrappers/erc1155_proxy.ts index ad2fcd745e..d5c947103f 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/erc1155_proxy.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/erc1155_proxy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -48,6 +54,9 @@ export interface ERC1155ProxyAuthorizedAddressRemovedEventArgs extends DecodedLo // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class ERC1155ProxyContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode = '0x608060405234801561001057600080fd5b50600436106100be5760003560e01c8063a85e59e411610076578063b91816111161005b578063b918161114610285578063d39de6e9146102cc578063f2fde38b14610324576100be565b8063a85e59e4146101b2578063ae25532e14610248576100be565b806370712939116100a7578063707129391461013e5780638da5cb5b146101715780639ad2674414610179576100be565b806342f1181e146100c3578063494503d4146100f8575b600080fd5b6100f6600480360360208110156100d957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610357565b005b6101156004803603602081101561010e57600080fd5b5035610543565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6100f66004803603602081101561015457600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610577565b61011561086a565b6100f66004803603604081101561018f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610886565b6100f6600480360360808110156101c857600080fd5b8101906020810181356401000000008111156101e357600080fd5b8201836020820111156101f557600080fd5b8035906020019184600183028401116401000000008311171561021757600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610c37565b610250611138565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b6102b86004803603602081101561029b57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611159565b604080519115158252519081900360200190f35b6102d461116e565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156103105781810151838201526020016102f8565b505050509050019250505060405180910390f35b6100f66004803603602081101561033a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166111dd565b60005473ffffffffffffffffffffffffffffffffffffffff1633146103dd57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff161561047257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f5441524745545f414c52454144595f415554484f52495a454400000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168317905560028054928301815583527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace90910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055513392917f3147867c59d17e8fa9d522465651d44aae0a9e38f902f3475b97e58072f0ed4c91a350565b6002818154811061055057fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b60005473ffffffffffffffffffffffffffffffffffffffff1633146105fd57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff1661069157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5441524745545f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116600090815260016020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b600254811015610823578173ffffffffffffffffffffffffffffffffffffffff166002828154811061070b57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16141561081b57600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811061076357fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff909216918390811061079657fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01906108159082611407565b50610823565b6001016106dd565b50604051339073ffffffffffffffffffffffffffffffffffffffff8316907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a350565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b60005473ffffffffffffffffffffffffffffffffffffffff16331461090c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090205460ff166109a057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5441524745545f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b6002548110610a1057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f494e4445585f4f55545f4f465f424f554e445300000000000000000000000000604482015290519081900360640190fd5b8173ffffffffffffffffffffffffffffffffffffffff1660028281548110610a3457fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614610ac257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f415554484f52495a45445f414444524553535f4d49534d415443480000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8216600090815260016020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101908110610b3d57fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff9092169183908110610b7057fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190610bef9082611407565b50604051339073ffffffffffffffffffffffffffffffffffffffff8416907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a35050565b3360009081526001602052604090205460ff16610cb557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f53454e4445525f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b60006060806060610d0b60048a8a90508b8b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092949392505063ffffffff6112c3169050565b8060200190516080811015610d1f57600080fd5b815160208301805160405192949293830192919084640100000000821115610d4657600080fd5b908301906020820185811115610d5b57600080fd5b8251866020820283011164010000000082111715610d7857600080fd5b82525081516020918201928201910280838360005b83811015610da5578181015183820152602001610d8d565b5050505090500160405260200180516040519392919084640100000000821115610dce57600080fd5b908301906020820185811115610de357600080fd5b8251866020820283011164010000000082111715610e0057600080fd5b82525081516020918201928201910280838360005b83811015610e2d578181015183820152602001610e15565b5050505090500160405260200180516040519392919084640100000000821115610e5657600080fd5b908301906020820185811115610e6b57600080fd5b8251640100000000811182820188101715610e8557600080fd5b82525081516020918201929091019080838360005b83811015610eb2578181015183820152602001610e9a565b50505050905090810190601f168015610edf5780820380516001836020036101000a031916815260200191505b506040525050509350935093509350600082519050606081604051908082528060200260200182016040528015610f20578160200160208202803883390190505b50905060005b828114610f6957610f4a858281518110610f3c57fe5b602002602001015189611306565b828281518110610f5657fe5b6020908102919091010152600101610f26565b508573ffffffffffffffffffffffffffffffffffffffff16632eb2c2d68a8a8885886040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001806020018060200180602001848103845287818151815260200191508051906020019060200280838360005b8381101561104657818101518382015260200161102e565b50505050905001848103835286818151815260200191508051906020019060200280838360005b8381101561108557818101518382015260200161106d565b50505050905001848103825285818151815260200191508051906020019080838360005b838110156110c15781810151838201526020016110a9565b50505050905090810190601f1680156110ee5780820380516001836020036101000a031916815260200191505b5098505050505050505050600060405180830381600087803b15801561111357600080fd5b505af1158015611127573d6000803e3d6000fd5b505050505050505050505050505050565b6000604051808061144f603091396030019050604051809103902090505b90565b60016020526000908152604090205460ff1681565b606060028054806020026020016040519081016040528092919081815260200182805480156111d357602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff1681526001909101906020018083116111a8575b5050505050905090565b60005473ffffffffffffffffffffffffffffffffffffffff16331461126357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116156112c057600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83161790555b50565b6060818311156112e1576112e16112dc60008585611340565b6113df565b83518211156112fa576112fa6112dc6001848751611340565b50819003910190815290565b6000826113155750600061133a565b8282028284828161132257fe5b0414611337576113376112dc600186866113e7565b90505b92915050565b6060632800659560e01b8484846040516024018084600781111561136057fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090509392505050565b805160208201fd5b606063e946c1bb60e01b8484846040516024018084600381111561136057fe5b81548183558181111561142b5760008381526020902061142b918101908301611430565b505050565b61115691905b8082111561144a5760008155600101611436565b509056fe4552433131353541737365747328616464726573732c75696e743235365b5d2c75696e743235365b5d2c627974657329a265627a7a72315820be5e6597d38133fd52aac17250498790f106d5d4d0e4ab30d0e854a2db1e2ffe64736f6c634300050c0032'; /** @@ -61,7 +70,11 @@ export class ERC1155ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + target: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('target', target); const self = (this as any) as ERC1155ProxyContract; const encodedData = self._strictEncodeArguments('addAuthorizedAddress(address)', [target.toLowerCase()]); @@ -77,6 +90,10 @@ export class ERC1155ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.addAuthorizedAddress.callAsync(target, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -91,20 +108,19 @@ export class ERC1155ProxyContract extends BaseContract { awaitTransactionSuccessAsync( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); const self = (this as any) as ERC1155ProxyContract; - const txHashPromise = self.addAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData); + const txHashPromise = self.addAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -134,11 +150,6 @@ export class ERC1155ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -198,28 +209,12 @@ export class ERC1155ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('addAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ERC1155ProxyContract; const abiEncoder = self._lookupAbiEncoder('addAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public authorities = { @@ -269,42 +264,6 @@ export class ERC1155ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: BigNumber): string { - assert.isBigNumber('index_0', index_0); - const self = (this as any) as ERC1155ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('authorities(uint256)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorities(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorities(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public authorized = { /** @@ -353,44 +312,6 @@ export class ERC1155ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as ERC1155ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('authorized(address)', [ - index_0.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorized(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorized(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Gets all authorized addresses. @@ -438,41 +359,6 @@ export class ERC1155ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC1155ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getAuthorizedAddresses()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAuthorizedAddresses()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string[] { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAuthorizedAddresses()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Gets the proxy id associated with the proxy address. @@ -499,7 +385,7 @@ export class ERC1155ProxyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -512,41 +398,6 @@ export class ERC1155ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC1155ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getProxyId()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public owner = { /** @@ -590,41 +441,6 @@ export class ERC1155ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC1155ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owner()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Removes authorizion of an address. @@ -637,7 +453,11 @@ export class ERC1155ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + target: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('target', target); const self = (this as any) as ERC1155ProxyContract; const encodedData = self._strictEncodeArguments('removeAuthorizedAddress(address)', [target.toLowerCase()]); @@ -653,6 +473,10 @@ export class ERC1155ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeAuthorizedAddress.callAsync(target, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -667,20 +491,19 @@ export class ERC1155ProxyContract extends BaseContract { awaitTransactionSuccessAsync( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); const self = (this as any) as ERC1155ProxyContract; - const txHashPromise = self.removeAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData); + const txHashPromise = self.removeAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -710,11 +533,6 @@ export class ERC1155ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -774,28 +592,12 @@ export class ERC1155ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ERC1155ProxyContract; const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -814,6 +616,7 @@ export class ERC1155ProxyContract extends BaseContract { target: string, index: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('target', target); assert.isBigNumber('index', index); @@ -834,6 +637,10 @@ export class ERC1155ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeAuthorizedAddressAtIndex.callAsync(target, index, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -850,8 +657,7 @@ export class ERC1155ProxyContract extends BaseContract { target: string, index: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); assert.isBigNumber('index', index); @@ -860,6 +666,7 @@ export class ERC1155ProxyContract extends BaseContract { target.toLowerCase(), index, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -867,8 +674,8 @@ export class ERC1155ProxyContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -907,19 +714,6 @@ export class ERC1155ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -992,28 +786,12 @@ export class ERC1155ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddressAtIndex(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ERC1155ProxyContract; const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddressAtIndex(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1038,6 +816,7 @@ export class ERC1155ProxyContract extends BaseContract { to: string, amount: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('assetData', assetData); assert.isString('from', from); @@ -1062,6 +841,10 @@ export class ERC1155ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferFrom.callAsync(assetData, from, to, amount, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1084,8 +867,7 @@ export class ERC1155ProxyContract extends BaseContract { to: string, amount: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('assetData', assetData); assert.isString('from', from); @@ -1098,6 +880,7 @@ export class ERC1155ProxyContract extends BaseContract { to.toLowerCase(), amount, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1105,8 +888,8 @@ export class ERC1155ProxyContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1155,17 +938,6 @@ export class ERC1155ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1254,28 +1026,12 @@ export class ERC1155ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string, string, BigNumber] { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ERC1155ProxyContract; const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public transferOwnership = { @@ -1285,7 +1041,11 @@ export class ERC1155ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + newOwner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('newOwner', newOwner); const self = (this as any) as ERC1155ProxyContract; const encodedData = self._strictEncodeArguments('transferOwnership(address)', [newOwner.toLowerCase()]); @@ -1301,6 +1061,10 @@ export class ERC1155ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferOwnership.callAsync(newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1314,20 +1078,19 @@ export class ERC1155ProxyContract extends BaseContract { awaitTransactionSuccessAsync( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('newOwner', newOwner); const self = (this as any) as ERC1155ProxyContract; - const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData); + const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1356,11 +1119,6 @@ export class ERC1155ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1418,28 +1176,12 @@ export class ERC1155ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as ERC1155ProxyContract; const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC1155ProxyContract; - const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; private readonly _subscriptionManager: SubscriptionManager; diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/erc20_proxy.ts b/packages/abi-gen-wrappers/src/generated-wrappers/erc20_proxy.ts index f50041fe22..5608cbf8e0 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/erc20_proxy.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/erc20_proxy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -48,6 +54,9 @@ export interface ERC20ProxyAuthorizedAddressRemovedEventArgs extends DecodedLogA // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class ERC20ProxyContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode = '0x608060405234801561001057600080fd5b50600436106100a35760003560e01c80639ad2674411610076578063b91816111161005b578063b918161114610374578063d39de6e9146103bb578063f2fde38b14610413576100a3565b80639ad26744146102fe578063ae25532e14610337576100a3565b806342f1181e14610248578063494503d41461027d57806370712939146102c35780638da5cb5b146102f6575b7fffffffff00000000000000000000000000000000000000000000000000000000600035167fa85e59e40000000000000000000000000000000000000000000000000000000081141561024257604080513381526001602082015290812054610177577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c1553454e4445525f4e4f545f415554484f52495a454400000000000000604052600060605260646000fd5b50602860043501357f23b872dd0000000000000000000000000000000000000000000000000000000060005260606024600437602060006064600080855af1600080511160203d14163d15178116905080156101cf57005b50507f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c0f5452414e534645525f4641494c454400000000000000000000000000604052600060605260646000fd5b50600080fd5b61027b6004803603602081101561025e57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610446565b005b61029a6004803603602081101561029357600080fd5b5035610632565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61027b600480360360208110156102d957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610666565b61029a610959565b61027b6004803603604081101561031457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610975565b61033f610d26565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b6103a76004803603602081101561038a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610d5c565b604080519115158252519081900360200190f35b6103c3610d71565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156103ff5781810151838201526020016103e7565b505050509050019250505060405180910390f35b61027b6004803603602081101561042957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610de0565b60005473ffffffffffffffffffffffffffffffffffffffff1633146104cc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff161561056157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f5441524745545f414c52454144595f415554484f52495a454400000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168317905560028054928301815583527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace90910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055513392917f3147867c59d17e8fa9d522465651d44aae0a9e38f902f3475b97e58072f0ed4c91a350565b6002818154811061063f57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b60005473ffffffffffffffffffffffffffffffffffffffff1633146106ec57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff1661078057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5441524745545f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116600090815260016020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b600254811015610912578173ffffffffffffffffffffffffffffffffffffffff16600282815481106107fa57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16141561090a57600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811061085257fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff909216918390811061088557fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01906109049082610ec6565b50610912565b6001016107cc565b50604051339073ffffffffffffffffffffffffffffffffffffffff8316907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a350565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b60005473ffffffffffffffffffffffffffffffffffffffff1633146109fb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090205460ff16610a8f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5441524745545f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b6002548110610aff57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f494e4445585f4f55545f4f465f424f554e445300000000000000000000000000604482015290519081900360640190fd5b8173ffffffffffffffffffffffffffffffffffffffff1660028281548110610b2357fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614610bb157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f415554484f52495a45445f414444524553535f4d49534d415443480000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8216600090815260016020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101908110610c2c57fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff9092169183908110610c5f57fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190610cde9082610ec6565b50604051339073ffffffffffffffffffffffffffffffffffffffff8416907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a35050565b604080517f4552433230546f6b656e28616464726573732900000000000000000000000000815290519081900360130190205b90565b60016020526000908152604090205460ff1681565b60606002805480602002602001604051908101604052809291908181526020018280548015610dd657602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610dab575b5050505050905090565b60005473ffffffffffffffffffffffffffffffffffffffff163314610e6657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811615610ec357600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83161790555b50565b815481835581811115610eea57600083815260209020610eea918101908301610eef565b505050565b610d5991905b80821115610f095760008155600101610ef5565b509056fea265627a7a72315820cb3312567959522bd12ea03b9812cab2bace85fe5f172b3ae8014b3eacc85fa864736f6c634300050b0032'; /** @@ -61,7 +70,11 @@ export class ERC20ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + target: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('target', target); const self = (this as any) as ERC20ProxyContract; const encodedData = self._strictEncodeArguments('addAuthorizedAddress(address)', [target.toLowerCase()]); @@ -77,6 +90,10 @@ export class ERC20ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.addAuthorizedAddress.callAsync(target, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -91,20 +108,19 @@ export class ERC20ProxyContract extends BaseContract { awaitTransactionSuccessAsync( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); const self = (this as any) as ERC20ProxyContract; - const txHashPromise = self.addAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData); + const txHashPromise = self.addAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -134,11 +150,6 @@ export class ERC20ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -198,28 +209,12 @@ export class ERC20ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as ERC20ProxyContract; const abiEncoder = self._lookupAbiEncoder('addAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('addAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public authorities = { @@ -269,42 +264,6 @@ export class ERC20ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: BigNumber): string { - assert.isBigNumber('index_0', index_0); - const self = (this as any) as ERC20ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('authorities(uint256)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorities(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorities(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Removes authorizion of an address. @@ -317,7 +276,11 @@ export class ERC20ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + target: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('target', target); const self = (this as any) as ERC20ProxyContract; const encodedData = self._strictEncodeArguments('removeAuthorizedAddress(address)', [target.toLowerCase()]); @@ -333,6 +296,10 @@ export class ERC20ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeAuthorizedAddress.callAsync(target, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -347,20 +314,19 @@ export class ERC20ProxyContract extends BaseContract { awaitTransactionSuccessAsync( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); const self = (this as any) as ERC20ProxyContract; - const txHashPromise = self.removeAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData); + const txHashPromise = self.removeAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -390,11 +356,6 @@ export class ERC20ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -454,28 +415,12 @@ export class ERC20ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as ERC20ProxyContract; const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public owner = { @@ -520,41 +465,6 @@ export class ERC20ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC20ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owner()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Removes authorizion of an address. @@ -572,6 +482,7 @@ export class ERC20ProxyContract extends BaseContract { target: string, index: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('target', target); assert.isBigNumber('index', index); @@ -592,6 +503,10 @@ export class ERC20ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeAuthorizedAddressAtIndex.callAsync(target, index, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -608,8 +523,7 @@ export class ERC20ProxyContract extends BaseContract { target: string, index: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); assert.isBigNumber('index', index); @@ -618,6 +532,7 @@ export class ERC20ProxyContract extends BaseContract { target.toLowerCase(), index, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -625,8 +540,8 @@ export class ERC20ProxyContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -665,19 +580,6 @@ export class ERC20ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -750,28 +652,12 @@ export class ERC20ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { + getSelector(): string { const self = (this as any) as ERC20ProxyContract; const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddressAtIndex(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddressAtIndex(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -799,7 +685,7 @@ export class ERC20ProxyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -812,41 +698,6 @@ export class ERC20ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC20ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getProxyId()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public authorized = { /** @@ -895,44 +746,6 @@ export class ERC20ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as ERC20ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('authorized(address)', [ - index_0.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorized(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorized(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Gets all authorized addresses. @@ -980,41 +793,6 @@ export class ERC20ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC20ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getAuthorizedAddresses()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAuthorizedAddresses()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string[] { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAuthorizedAddresses()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transferOwnership = { /** @@ -1023,7 +801,11 @@ export class ERC20ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + newOwner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('newOwner', newOwner); const self = (this as any) as ERC20ProxyContract; const encodedData = self._strictEncodeArguments('transferOwnership(address)', [newOwner.toLowerCase()]); @@ -1039,6 +821,10 @@ export class ERC20ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferOwnership.callAsync(newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1052,20 +838,19 @@ export class ERC20ProxyContract extends BaseContract { awaitTransactionSuccessAsync( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('newOwner', newOwner); const self = (this as any) as ERC20ProxyContract; - const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData); + const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1094,11 +879,6 @@ export class ERC20ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1156,28 +936,12 @@ export class ERC20ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ERC20ProxyContract; - const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ERC20ProxyContract; const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; private readonly _subscriptionManager: SubscriptionManager; diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/erc20_token.ts b/packages/abi-gen-wrappers/src/generated-wrappers/erc20_token.ts index 7ce2e25780..df2b061a3a 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/erc20_token.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/erc20_token.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -48,8 +54,10 @@ export interface ERC20TokenApprovalEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class ERC20TokenContract extends BaseContract { - public static deployedBytecode = - '0x608060405234801561001057600080fd5b50600436106100725760003560e01c806370a082311161005057806370a0823114610121578063a9059cbb14610154578063dd62ed3e1461018d57610072565b8063095ea7b31461007757806318160ddd146100c457806323b872dd146100de575b600080fd5b6100b06004803603604081101561008d57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356101c8565b604080519115158252519081900360200190f35b6100cc61023b565b60408051918252519081900360200190f35b6100b0600480360360608110156100f457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610241565b6100cc6004803603602081101561013757600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661049d565b6100b06004803603604081101561016a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356104c5565b6100cc600480360360408110156101a357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610652565b33600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b60025490565b73ffffffffffffffffffffffffffffffffffffffff83166000908152602081905260408120548211156102d557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f45524332305f494e53554646494349454e545f42414c414e4345000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8416600090815260016020908152604080832033845290915290205482111561037457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f45524332305f494e53554646494349454e545f414c4c4f57414e434500000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8316600090815260208190526040902054828101101561040a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f55494e543235365f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff80841660008181526020818152604080832080548801905593881680835284832080548890039055600182528483203384528252918490208054879003905583518681529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35060019392505050565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b3360009081526020819052604081205482111561054357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f45524332305f494e53554646494349454e545f42414c414e4345000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff831660009081526020819052604090205482810110156105d957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f55494e543235365f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b336000818152602081815260408083208054879003905573ffffffffffffffffffffffffffffffffffffffff871680845292819020805487019055805186815290519293927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929181900390910190a350600192915050565b73ffffffffffffffffffffffffffffffffffffffff91821660009081526001602090815260408083209390941682529190915220549056fea265627a7a723158205713efa92f66e67a8d01b80af8500df66bd6e9862dcf791e587181109d8ab0c464736f6c634300050b0032'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; /** * `msg.sender` approves `_spender` to spend `_value` tokens */ @@ -66,6 +74,7 @@ export class ERC20TokenContract extends BaseContract { _spender: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_spender', _spender); assert.isBigNumber('_value', _value); @@ -86,6 +95,10 @@ export class ERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.approve.callAsync(_spender, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -102,21 +115,20 @@ export class ERC20TokenContract extends BaseContract { _spender: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_spender', _spender); assert.isBigNumber('_value', _value); const self = (this as any) as ERC20TokenContract; - const txHashPromise = self.approve.sendTransactionAsync(_spender.toLowerCase(), _value, txData); + const txHashPromise = self.approve.sendTransactionAsync(_spender.toLowerCase(), _value, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -155,15 +167,6 @@ export class ERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -237,28 +240,12 @@ export class ERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): string { + getSelector(): string { const self = (this as any) as ERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -307,41 +294,6 @@ export class ERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('totalSupply()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('totalSupply()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('totalSupply()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * send `value` token to `to` from `from` on the condition it is approved by `from` @@ -361,6 +313,7 @@ export class ERC20TokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -383,6 +336,10 @@ export class ERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferFrom.callAsync(_from, _to, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -401,8 +358,7 @@ export class ERC20TokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -413,6 +369,7 @@ export class ERC20TokenContract extends BaseContract { _to.toLowerCase(), _value, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -420,8 +377,8 @@ export class ERC20TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -464,16 +421,6 @@ export class ERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -554,28 +501,12 @@ export class ERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): string { + getSelector(): string { const self = (this as any) as ERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -630,43 +561,6 @@ export class ERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _owner The address from which the balance will be retrieved - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string): string { - assert.isString('_owner', _owner); - const self = (this as any) as ERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('balanceOf(address)', [_owner.toLowerCase()]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * send `value` token to `to` from `msg.sender` @@ -684,6 +578,7 @@ export class ERC20TokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_to', _to); assert.isBigNumber('_value', _value); @@ -701,6 +596,10 @@ export class ERC20TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transfer.callAsync(_to, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -717,21 +616,20 @@ export class ERC20TokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_to', _to); assert.isBigNumber('_value', _value); const self = (this as any) as ERC20TokenContract; - const txHashPromise = self.transfer.sendTransactionAsync(_to.toLowerCase(), _value, txData); + const txHashPromise = self.transfer.sendTransactionAsync(_to.toLowerCase(), _value, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -763,15 +661,6 @@ export class ERC20TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -842,28 +731,12 @@ export class ERC20TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): boolean { + getSelector(): string { const self = (this as any) as ERC20TokenContract; const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public allowance = { @@ -921,48 +794,6 @@ export class ERC20TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _owner The address of the account owning tokens - * @param _spender The address of the account able to transfer the tokens - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string, _spender: string): string { - assert.isString('_owner', _owner); - assert.isString('_spender', _spender); - const self = (this as any) as ERC20TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('allowance(address,address)', [ - _owner.toLowerCase(), - _spender.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('allowance(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ERC20TokenContract; - const abiEncoder = self._lookupAbiEncoder('allowance(address,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/erc721_proxy.ts b/packages/abi-gen-wrappers/src/generated-wrappers/erc721_proxy.ts index c93e5df751..7b84ca85b7 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/erc721_proxy.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/erc721_proxy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -48,6 +54,9 @@ export interface ERC721ProxyAuthorizedAddressRemovedEventArgs extends DecodedLog // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class ERC721ProxyContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode = '0x608060405234801561001057600080fd5b50600436106100a35760003560e01c80639ad2674411610076578063b91816111161005b578063b9181611146103ea578063d39de6e914610431578063f2fde38b14610489576100a3565b80639ad2674414610374578063ae25532e146103ad576100a3565b806342f1181e146102be578063494503d4146102f357806370712939146103395780638da5cb5b1461036c575b7fffffffff00000000000000000000000000000000000000000000000000000000600035167fa85e59e4000000000000000000000000000000000000000000000000000000008114156102b857604080513381526001602082015290812054610177577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c1553454e4445525f4e4f545f415554484f52495a454400000000000000604052600060605260646000fd5b50600160643503156101f4577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c0e494e56414c49445f414d4f554e540000000000000000000000000000604052600060605260646000fd5b7f23b872dd000000000000000000000000000000000000000000000000000000006000526040602460043760043560206048820160443760288101356000806064600080855af1915050801561024657005b507f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c0f5452414e534645525f4641494c454400000000000000000000000000604052600060605260646000fd5b50600080fd5b6102f1600480360360208110156102d457600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166104bc565b005b6103106004803603602081101561030957600080fd5b50356106a8565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6102f16004803603602081101561034f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166106dc565b6103106109cf565b6102f16004803603604081101561038a57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356109eb565b6103b5610d9c565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b61041d6004803603602081101561040057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610dd2565b604080519115158252519081900360200190f35b610439610de7565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561047557818101518382015260200161045d565b505050509050019250505060405180910390f35b6102f16004803603602081101561049f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610e56565b60005473ffffffffffffffffffffffffffffffffffffffff16331461054257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff16156105d757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f5441524745545f414c52454144595f415554484f52495a454400000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168317905560028054928301815583527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace90910180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055513392917f3147867c59d17e8fa9d522465651d44aae0a9e38f902f3475b97e58072f0ed4c91a350565b600281815481106106b557fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b60005473ffffffffffffffffffffffffffffffffffffffff16331461076257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602052604090205460ff166107f657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5441524745545f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116600090815260016020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b600254811015610988578173ffffffffffffffffffffffffffffffffffffffff166002828154811061087057fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16141561098057600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081106108c857fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff90921691839081106108fb57fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff019061097a9082610f3c565b50610988565b600101610842565b50604051339073ffffffffffffffffffffffffffffffffffffffff8316907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a350565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b60005473ffffffffffffffffffffffffffffffffffffffff163314610a7157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff821660009081526001602052604090205460ff16610b0557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5441524745545f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b6002548110610b7557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f494e4445585f4f55545f4f465f424f554e445300000000000000000000000000604482015290519081900360640190fd5b8173ffffffffffffffffffffffffffffffffffffffff1660028281548110610b9957fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614610c2757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f415554484f52495a45445f414444524553535f4d49534d415443480000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8216600090815260016020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101908110610ca257fe5b6000918252602090912001546002805473ffffffffffffffffffffffffffffffffffffffff9092169183908110610cd557fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190610d549082610f3c565b50604051339073ffffffffffffffffffffffffffffffffffffffff8416907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a35050565b604080517f455243373231546f6b656e28616464726573732c75696e7432353629000000008152905190819003601c0190205b90565b60016020526000908152604090205460ff1681565b60606002805480602002602001604051908101604052809291908181526020018280548015610e4c57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610e21575b5050505050905090565b60005473ffffffffffffffffffffffffffffffffffffffff163314610edc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811615610f3957600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83161790555b50565b815481835581811115610f6057600083815260209020610f60918101908301610f65565b505050565b610dcf91905b80821115610f7f5760008155600101610f6b565b509056fea265627a7a723158201e53a891f6df3931041b820f71387e9eecd97f7ea0d346c54fab37668bd022ec64736f6c634300050b0032'; /** @@ -61,7 +70,11 @@ export class ERC721ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + target: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('target', target); const self = (this as any) as ERC721ProxyContract; const encodedData = self._strictEncodeArguments('addAuthorizedAddress(address)', [target.toLowerCase()]); @@ -77,6 +90,10 @@ export class ERC721ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.addAuthorizedAddress.callAsync(target, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -91,20 +108,19 @@ export class ERC721ProxyContract extends BaseContract { awaitTransactionSuccessAsync( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); const self = (this as any) as ERC721ProxyContract; - const txHashPromise = self.addAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData); + const txHashPromise = self.addAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -134,11 +150,6 @@ export class ERC721ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -198,28 +209,12 @@ export class ERC721ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as ERC721ProxyContract; const abiEncoder = self._lookupAbiEncoder('addAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('addAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public authorities = { @@ -269,42 +264,6 @@ export class ERC721ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: BigNumber): string { - assert.isBigNumber('index_0', index_0); - const self = (this as any) as ERC721ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('authorities(uint256)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorities(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorities(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Removes authorizion of an address. @@ -317,7 +276,11 @@ export class ERC721ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + target: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('target', target); const self = (this as any) as ERC721ProxyContract; const encodedData = self._strictEncodeArguments('removeAuthorizedAddress(address)', [target.toLowerCase()]); @@ -333,6 +296,10 @@ export class ERC721ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeAuthorizedAddress.callAsync(target, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -347,20 +314,19 @@ export class ERC721ProxyContract extends BaseContract { awaitTransactionSuccessAsync( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); const self = (this as any) as ERC721ProxyContract; - const txHashPromise = self.removeAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData); + const txHashPromise = self.removeAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -390,11 +356,6 @@ export class ERC721ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -454,28 +415,12 @@ export class ERC721ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as ERC721ProxyContract; const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public owner = { @@ -520,41 +465,6 @@ export class ERC721ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC721ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owner()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Removes authorizion of an address. @@ -572,6 +482,7 @@ export class ERC721ProxyContract extends BaseContract { target: string, index: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('target', target); assert.isBigNumber('index', index); @@ -592,6 +503,10 @@ export class ERC721ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeAuthorizedAddressAtIndex.callAsync(target, index, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -608,8 +523,7 @@ export class ERC721ProxyContract extends BaseContract { target: string, index: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); assert.isBigNumber('index', index); @@ -618,6 +532,7 @@ export class ERC721ProxyContract extends BaseContract { target.toLowerCase(), index, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -625,8 +540,8 @@ export class ERC721ProxyContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -665,19 +580,6 @@ export class ERC721ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -750,28 +652,12 @@ export class ERC721ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { + getSelector(): string { const self = (this as any) as ERC721ProxyContract; const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddressAtIndex(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddressAtIndex(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -799,7 +685,7 @@ export class ERC721ProxyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -812,41 +698,6 @@ export class ERC721ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC721ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getProxyId()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public authorized = { /** @@ -895,44 +746,6 @@ export class ERC721ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as ERC721ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('authorized(address)', [ - index_0.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorized(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorized(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Gets all authorized addresses. @@ -980,41 +793,6 @@ export class ERC721ProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ERC721ProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getAuthorizedAddresses()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAuthorizedAddresses()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string[] { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAuthorizedAddresses()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transferOwnership = { /** @@ -1023,7 +801,11 @@ export class ERC721ProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + newOwner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('newOwner', newOwner); const self = (this as any) as ERC721ProxyContract; const encodedData = self._strictEncodeArguments('transferOwnership(address)', [newOwner.toLowerCase()]); @@ -1039,6 +821,10 @@ export class ERC721ProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferOwnership.callAsync(newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1052,20 +838,19 @@ export class ERC721ProxyContract extends BaseContract { awaitTransactionSuccessAsync( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('newOwner', newOwner); const self = (this as any) as ERC721ProxyContract; - const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData); + const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1094,11 +879,6 @@ export class ERC721ProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1156,28 +936,12 @@ export class ERC721ProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ERC721ProxyContract; - const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ERC721ProxyContract; const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; private readonly _subscriptionManager: SubscriptionManager; diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/erc721_token.ts b/packages/abi-gen-wrappers/src/generated-wrappers/erc721_token.ts index 6609198dec..00ee288b74 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/erc721_token.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/erc721_token.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -58,8 +64,10 @@ export interface ERC721TokenTransferEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class ERC721TokenContract extends BaseContract { - public static deployedBytecode = - '0x608060405234801561001057600080fd5b50600436106100a35760003560e01c80636352211e11610076578063a22cb4651161005b578063a22cb46514610211578063b88d4fde1461024c578063e985e9c5146102e9576100a3565b80636352211e146101af57806370a08231146101cc576100a3565b8063081812fc146100a8578063095ea7b3146100ee57806323b872dd1461012957806342842e0e1461016c575b600080fd5b6100c5600480360360208110156100be57600080fd5b5035610338565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6101276004803603604081101561010457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610360565b005b6101276004803603606081101561013f57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610482565b6101276004803603606081101561018257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356107ef565b6100c5600480360360208110156101c557600080fd5b5035610989565b6101ff600480360360208110156101e257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610a20565b60408051918252519081900360200190f35b6101276004803603604081101561022757600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001351515610acd565b6101276004803603608081101561026257600080fd5b73ffffffffffffffffffffffffffffffffffffffff8235811692602081013590911691604082013591908101906080810160608201356401000000008111156102aa57600080fd5b8201836020820111156102bc57600080fd5b803590602001918460018302840111640100000000831117156102de57600080fd5b509092509050610b66565b610324600480360360408110156102ff57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610d31565b604080519115158252519081900360200190f35b60009081526001602052604090205473ffffffffffffffffffffffffffffffffffffffff1690565b600061036b82610989565b90503373ffffffffffffffffffffffffffffffffffffffff8216148061039657506103968133610d31565b61040157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4552433732315f494e56414c49445f53454e4445520000000000000000000000604482015290519081900360640190fd5b60008281526001602052604080822080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff87811691821790925591518593918516917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591a4505050565b73ffffffffffffffffffffffffffffffffffffffff821661050457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4552433732315f5a45524f5f544f5f4144445245535300000000000000000000604482015290519081900360640190fd5b600061050f82610989565b90508073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16146105ab57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4552433732315f4f574e45525f4d49534d415443480000000000000000000000604482015290519081900360640190fd5b3360006105b784610338565b90508273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806105f857506105f88383610d31565b8061062e57508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b61069957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4552433732315f494e56414c49445f5350454e44455200000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116156106ea57600084815260016020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001690555b60008481526020818152604080832080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8a811691909117909155891683526002909152902054610753906001610d6c565b73ffffffffffffffffffffffffffffffffffffffff8088166000908152600260205260408082209390935590871681522054610790906001610d90565b73ffffffffffffffffffffffffffffffffffffffff808716600081815260026020526040808220949094559251879391928a16917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050505050565b6107fa838383610482565b813b801561098357604080517f150b7a0200000000000000000000000000000000000000000000000000000000815233600482015273ffffffffffffffffffffffffffffffffffffffff8681166024830152604482018590526080606483015260006084830181905292519086169163150b7a029160c480830192602092919082900301818787803b15801561088f57600080fd5b505af11580156108a3573d6000803e3d6000fd5b505050506040513d60208110156108b957600080fd5b505160405190915080602f610e5b8239602f01905060405180910390207bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161461098157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4552433732315f494e56414c49445f53454c4543544f52000000000000000000604482015290519081900360640190fd5b505b50505050565b60008181526020819052604081205473ffffffffffffffffffffffffffffffffffffffff1680610a1a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4552433732315f5a45524f5f4f574e4552000000000000000000000000000000604482015290519081900360640190fd5b92915050565b600073ffffffffffffffffffffffffffffffffffffffff8216610aa457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4552433732315f5a45524f5f4f574e4552000000000000000000000000000000604482015290519081900360640190fd5b5073ffffffffffffffffffffffffffffffffffffffff1660009081526002602052604090205490565b33600081815260036020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016861515908117909155815190815290519293927f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31929181900390910190a35050565b610b71858585610482565b833b8015610d29576040517f150b7a02000000000000000000000000000000000000000000000000000000008152336004820181815273ffffffffffffffffffffffffffffffffffffffff89811660248501526044840188905260806064850190815260848501879052600094918a169363150b7a029390928c928b928b928b929060a401848480828437600081840152601f19601f8201169050808301925050509650505050505050602060405180830381600087803b158015610c3557600080fd5b505af1158015610c49573d6000803e3d6000fd5b505050506040513d6020811015610c5f57600080fd5b505160405190915080602f610e5b8239602f01905060405180910390207bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614610d2757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4552433732315f494e56414c49445f53454c4543544f52000000000000000000604482015290519081900360640190fd5b505b505050505050565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260036020908152604080832093909416825291909152205460ff1690565b600082821115610d8a57610d8a610d8560028585610db3565b610e52565b50900390565b600082820183811015610dac57610dac610d8560008686610db3565b9392505050565b606063e946c1bb60e01b84848460405160240180846003811115610dd357fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090509392505050565b805160208201fdfe6f6e455243373231526563656976656428616464726573732c616464726573732c75696e743235362c627974657329a265627a7a723158204bc74831490bca4fbe1805808d58d6b0e12f618a37565e744e91d8dc73dc18b164736f6c634300050c0032'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; /** * The zero address indicates there is no approved address. * Throws unless `msg.sender` is the current NFT owner, or an authorized @@ -78,6 +86,7 @@ export class ERC721TokenContract extends BaseContract { _approved: string, _tokenId: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_approved', _approved); assert.isBigNumber('_tokenId', _tokenId); @@ -98,6 +107,10 @@ export class ERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.approve.callAsync(_approved, _tokenId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -114,21 +127,20 @@ export class ERC721TokenContract extends BaseContract { _approved: string, _tokenId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_approved', _approved); assert.isBigNumber('_tokenId', _tokenId); const self = (this as any) as ERC721TokenContract; - const txHashPromise = self.approve.sendTransactionAsync(_approved.toLowerCase(), _tokenId, txData); + const txHashPromise = self.approve.sendTransactionAsync(_approved.toLowerCase(), _tokenId, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -167,15 +179,6 @@ export class ERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -248,28 +251,12 @@ export class ERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { + getSelector(): string { const self = (this as any) as ERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -325,43 +312,6 @@ export class ERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _owner An address for whom to query the balance - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string): string { - assert.isString('_owner', _owner); - const self = (this as any) as ERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('balanceOf(address)', [_owner.toLowerCase()]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Throws if `_tokenId` is not a valid NFT. @@ -415,43 +365,6 @@ export class ERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _tokenId The NFT to find the approved address for - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_tokenId: BigNumber): string { - assert.isBigNumber('_tokenId', _tokenId); - const self = (this as any) as ERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getApproved(uint256)', [_tokenId]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('getApproved(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('getApproved(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public isApprovedForAll = { /** @@ -508,48 +421,6 @@ export class ERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _owner The address that owns the NFTs - * @param _operator The address that acts on behalf of the owner - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string, _operator: string): string { - assert.isString('_owner', _owner); - assert.isString('_operator', _operator); - const self = (this as any) as ERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('isApprovedForAll(address,address)', [ - _owner.toLowerCase(), - _operator.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('isApprovedForAll(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('isApprovedForAll(address,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * NFTs assigned to zero address are considered invalid, and queries @@ -604,43 +475,6 @@ export class ERC721TokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param _tokenId The identifier for an NFT - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_tokenId: BigNumber): string { - assert.isBigNumber('_tokenId', _tokenId); - const self = (this as any) as ERC721TokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('ownerOf(uint256)', [_tokenId]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('ownerOf(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('ownerOf(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * This works identically to the other function with an extra data parameter, @@ -661,6 +495,7 @@ export class ERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -683,6 +518,10 @@ export class ERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.safeTransferFrom1.callAsync(_from, _to, _tokenId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -701,8 +540,7 @@ export class ERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -713,6 +551,7 @@ export class ERC721TokenContract extends BaseContract { _to.toLowerCase(), _tokenId, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -720,8 +559,8 @@ export class ERC721TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -764,16 +603,6 @@ export class ERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -853,28 +682,12 @@ export class ERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, string, BigNumber] { + getSelector(): string { const self = (this as any) as ERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -903,6 +716,7 @@ export class ERC721TokenContract extends BaseContract { _tokenId: BigNumber, _data: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -927,6 +741,10 @@ export class ERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.safeTransferFrom2.callAsync(_from, _to, _tokenId, _data, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -947,8 +765,7 @@ export class ERC721TokenContract extends BaseContract { _tokenId: BigNumber, _data: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -961,6 +778,7 @@ export class ERC721TokenContract extends BaseContract { _tokenId, _data, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -968,8 +786,8 @@ export class ERC721TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1016,23 +834,6 @@ export class ERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1117,28 +918,12 @@ export class ERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, string, BigNumber, string] { + getSelector(): string { const self = (this as any) as ERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, BigNumber, string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('safeTransferFrom(address,address,uint256,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1158,6 +943,7 @@ export class ERC721TokenContract extends BaseContract { _operator: string, _approved: boolean, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_operator', _operator); assert.isBoolean('_approved', _approved); @@ -1178,6 +964,10 @@ export class ERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.setApprovalForAll.callAsync(_operator, _approved, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1194,8 +984,7 @@ export class ERC721TokenContract extends BaseContract { _operator: string, _approved: boolean, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_operator', _operator); assert.isBoolean('_approved', _approved); @@ -1204,6 +993,7 @@ export class ERC721TokenContract extends BaseContract { _operator.toLowerCase(), _approved, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1211,8 +1001,8 @@ export class ERC721TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1251,15 +1041,6 @@ export class ERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1332,28 +1113,12 @@ export class ERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, boolean] { + getSelector(): string { const self = (this as any) as ERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('setApprovalForAll(address,bool)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, boolean]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('setApprovalForAll(address,bool)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1377,6 +1142,7 @@ export class ERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -1399,6 +1165,10 @@ export class ERC721TokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferFrom.callAsync(_from, _to, _tokenId, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1417,8 +1187,7 @@ export class ERC721TokenContract extends BaseContract { _to: string, _tokenId: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -1429,6 +1198,7 @@ export class ERC721TokenContract extends BaseContract { _to.toLowerCase(), _tokenId, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1436,8 +1206,8 @@ export class ERC721TokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1480,16 +1250,6 @@ export class ERC721TokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1569,28 +1329,12 @@ export class ERC721TokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string, string, BigNumber] { + getSelector(): string { const self = (this as any) as ERC721TokenContract; const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ERC721TokenContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; private readonly _subscriptionManager: SubscriptionManager; diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/eth_balance_checker.ts b/packages/abi-gen-wrappers/src/generated-wrappers/eth_balance_checker.ts index c973546cf0..4fac46c6b4 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/eth_balance_checker.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/eth_balance_checker.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,8 +34,10 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class EthBalanceCheckerContract extends BaseContract { - public static deployedBytecode = - '0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063a0901e5114610030575b600080fd5b6100d36004803603602081101561004657600080fd5b81019060208101813564010000000081111561006157600080fd5b82018360208201111561007357600080fd5b8035906020019184602083028401116401000000008311171561009557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610123945050505050565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561010f5781810151838201526020016100f7565b505050509050019250505060405180910390f35b6060808251604051908082528060200260200182016040528015610151578160200160208202803883390190505b50905060005b835181146101a95783818151811061016b57fe5b602002602001015173ffffffffffffffffffffffffffffffffffffffff163182828151811061019657fe5b6020908102919091010152600101610157565b509291505056fea265627a7a7231582094309783f0b63086d85d9cb4f6e5be253699056ac1580a863367c5076ecb5c1864736f6c634300050b0032'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; /** * Batch fetches ETH balances */ @@ -82,43 +90,6 @@ export class EthBalanceCheckerContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param addresses Array of addresses. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(addresses: string[]): string { - assert.isArray('addresses', addresses); - const self = (this as any) as EthBalanceCheckerContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getEthBalances(address[])', [addresses]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string[] { - const self = (this as any) as EthBalanceCheckerContract; - const abiEncoder = self._lookupAbiEncoder('getEthBalances(address[])'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber[] { - const self = (this as any) as EthBalanceCheckerContract; - const abiEncoder = self._lookupAbiEncoder('getEthBalances(address[])'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/exchange.ts b/packages/abi-gen-wrappers/src/generated-wrappers/exchange.ts index bb8fc0584c..bb4329eef8 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/exchange.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/exchange.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -107,8 +113,10 @@ export interface ExchangeTransactionExecutionEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class ExchangeContract extends BaseContract { - public static deployedBytecode = - '0x6080604052600436106102d15760003560e01c80638da5cb5b11610179578063beee2e14116100d6578063dd885e2d1161008a578063eea086ba11610064578063eea086ba14610715578063f2fde38b1461072a578063fc74896d1461074a576102d1565b8063dd885e2d146106cd578063dedfc1f1146106ef578063e14b58c414610702576102d1565b8063c26cfecd116100bb578063c26cfecd14610678578063c585bb931461068d578063d9bfa73e146106ad576102d1565b8063beee2e1414610645578063c0fa16cc14610658576102d1565b80639d3fa4b91161012d578063a6c3bf3311610112578063a6c3bf33146105ff578063b04fbddd14610612578063b718e29214610632576102d1565b80639d3fa4b9146105b2578063a12dcc6f146105df576102d1565b80639331c7421161015e5780639331c7421461056c5780639694a4021461058c5780639b44d5561461059f576102d1565b80638da5cb5b146105375780638ea8dfe41461054c576102d1565b80636a1a80fd116102325780638171c407116101e657806388ec79fb116101c057806388ec79fb146104e45780638bc8efb3146105045780638d45cd2314610517576102d1565b80638171c4071461048f57806382c174d0146104af578063850a1501146104cf576102d1565b806377fcce681161021757806377fcce681461044957806378d29ac11461045c5780637b8e35141461046f576102d1565b80636a1a80fd146104165780636fcf3e9e14610436576102d1565b80632da629871161028957806346c02d7a1161026e57806346c02d7a146103c35780634f9559b1146103d657806360704108146103e9576102d1565b80632da629871461038e578063369da099146103a3576102d1565b80632280c910116102ba5780632280c9101461032e578063288cdc911461034e5780632ac126221461036e576102d1565b80630228e168146102d65780631ce4c78b1461030c575b600080fd5b3480156102e257600080fd5b506102f66102f1366004614e64565b61076a565b60405161030391906154c4565b60405180910390f35b34801561031857600080fd5b5061032161077f565b60405161030391906154cf565b61034161033c366004615108565b610785565b60405161030391906156a0565b34801561035a57600080fd5b50610321610369366004614e64565b6107c7565b34801561037a57600080fd5b506102f6610389366004614e64565b6107d9565b6103a161039c366004614f82565b6107ee565b005b6103b66103b1366004614d60565b610812565b60405161030391906159c2565b6103a16103d1366004614e64565b610939565b6103a16103e4366004614e64565b6109ac565b3480156103f557600080fd5b50610409610404366004614eed565b610ab9565b604051610303919061535b565b610429610424366004614c40565b610b07565b604051610303919061594b565b610429610444366004614c40565b610b3f565b6103a1610457366004614b2a565b610b5d565b6103b661046a366004614d60565b610c20565b34801561047b57600080fd5b506102f661048a366004614af6565b610d70565b34801561049b57600080fd5b506102f66104aa366004614ea0565b610d90565b3480156104bb57600080fd5b506102f66104ca366004614e7c565b610def565b3480156104db57600080fd5b50610409610e0f565b6104f76104f236600461500c565b610e2b565b60405161030391906159d0565b6103b6610512366004614d60565b610e49565b34801561052357600080fd5b506102f6610532366004615108565b610e7d565b34801561054357600080fd5b50610409610ea2565b61055f61055a366004614cdc565b610ebe565b60405161030391906154b1565b34801561057857600080fd5b506103a1610587366004614e64565b610fe9565b61055f61059a366004614cdc565b611031565b6103b66105ad3660046150a8565b6110f8565b3480156105be57600080fd5b506105d26105cd366004614f82565b61111d565b6040516103039190615a12565b3480156105eb57600080fd5b506102f66105fa366004614fb5565b611201565b6103b661060d366004614d60565b611226565b34801561061e57600080fd5b506103a161062d366004614b65565b61125a565b6104f761064036600461500c565b611306565b61055f610653366004614cdc565b611324565b34801561066457600080fd5b506103a1610673366004614adb565b6113d9565b34801561068457600080fd5b5061032161147c565b34801561069957600080fd5b506103a16106a8366004614adb565b611482565b3480156106b957600080fd5b506103216106c8366004614af6565b611616565b3480156106d957600080fd5b506106e2611633565b604051610303919061562b565b6103a16106fd366004614c0d565b611657565b6103b66107103660046150a8565b611699565b34801561072157600080fd5b506104096116b4565b34801561073657600080fd5b506103a1610745366004614adb565b6116d0565b61075d610758366004614db3565b611748565b6040516103039190615433565b60056020526000908152604090205460ff1681565b60035481565b606061078f61187b565b156107a55761079e838361189d565b90506107c1565b6107ad6119b7565b6107b7838361189d565b90506107c16119f9565b92915050565b60096020526000908152604090205481565b600a6020526000908152604090205460ff1681565b6107f6611a2b565b6107ff81611a9a565b610807611ad7565b61080f611aeb565b50565b61081a614561565b61082261187b565b156108b857835160005b8181146108b157600061084c846020015187611b1590919063ffffffff16565b9050610856614561565b61088788848151811061086557fe5b60200260200101518388868151811061087a57fe5b6020026020010151611b34565b90506108938582611c75565b9450868560200151106108a75750506108b1565b505060010161082c565b5050610932565b6108c06119b7565b835160005b8181146109285760006108e5846020015187611b1590919063ffffffff16565b90506108ef614561565b6108fe88848151811061086557fe5b905061090a8582611c75565b94508685602001511061091e575050610928565b50506001016108c5565b50506109326119f9565b9392505050565b610941611a2b565b600061094b611d10565b600083815260076020908152604080832073ffffffffffffffffffffffffffffffffffffffff90941683529290522080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905550610807611ad7565b6109b4611a2b565b60006109be611d10565b9050600073ffffffffffffffffffffffffffffffffffffffff821633146109e557336109e8565b60005b73ffffffffffffffffffffffffffffffffffffffff8084166000908152600b60209081526040808320938516835292905220549091506001840190808211610a3d57610a3d610a38858584611d42565b611de7565b73ffffffffffffffffffffffffffffffffffffffff8085166000818152600b602090815260408083209488168084529490915290819020859055517f82af639571738f4ebd4268fb0363d8957ebe1bbb9e78dba5ebd69eed39b154f090610aa59086906154cf565b60405180910390a350505050610807611ad7565b7fffffffff00000000000000000000000000000000000000000000000000000000811660009081526002602052604090205473ffffffffffffffffffffffffffffffffffffffff165b919050565b610b0f614590565b610b17611a2b565b610b25858585856001611def565b9050610b2f611ad7565b610b37611aeb565b949350505050565b610b47614590565b610b4f611a2b565b610b25858585856000611def565b610b65611a2b565b6000610b6f611d10565b73ffffffffffffffffffffffffffffffffffffffff8181166000818152600860209081526040808320948916808452949091529081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00168715151790555192935090917fa8656e308026eeabce8f0bc18048433252318ab80ac79da0b3d3d8697dfba89190610c039086906154c4565b60405180910390a350610c14611ad7565b610c1c611aeb565b5050565b610c28614561565b610c3061187b565b15610cee57835160005b8181146108b1578251600090610c5790879063ffffffff611b1516565b90506000610c94888481518110610c6a57fe5b602002602001015160a00151898581518110610c8257fe5b6020026020010151608001518461215c565b9050610c9e614561565b610cc2898581518110610cad57fe5b60200260200101518389878151811061087a57fe5b9050610cce8682611c75565b955087866000015110610ce3575050506108b1565b505050600101610c3a565b610cf66119b7565b835160005b818114610928578251600090610d1890879063ffffffff611b1516565b90506000610d2b888481518110610c6a57fe5b9050610d35614561565b610d44898581518110610cad57fe5b9050610d508682611c75565b955087866000015110610d6557505050610928565b505050600101610cfb565b600860209081526000928352604080842090915290825290205460ff1681565b600080610d9e85858561217e565b90506005816008811115610dae57fe5b1480610dc557506007816008811115610dc357fe5b145b15610dda57610dda610a3860058787876121fd565b610de6818686866122a5565b95945050505050565b600760209081526000928352604080842090915290825290205460ff1681565b60045473ffffffffffffffffffffffffffffffffffffffff1681565b610e336145b8565b610e3b611a2b565b610b25858585856000612515565b610e51614561565b610e5c848484610c20565b9050828160000151101561093257610932610a386000858460000151612602565b600080610e956001548561262190919063ffffffff16565b9050610b37848285612635565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b6060610ec861187b565b15610f6b578351604080518281526020808402820101909152818015610f0857816020015b610ef5614561565b815260200190600190039081610eed5790505b50915060005b8181146108b157610f4c868281518110610f2457fe5b6020026020010151868381518110610f3857fe5b602002602001015186848151811061087a57fe5b838281518110610f5857fe5b6020908102919091010152600101610f0e565b610f736119b7565b8351604080518281526020808402820101909152818015610fae57816020015b610f9b614561565b815260200190600190039081610f935790505b50915060005b81811461092857610fca868281518110610f2457fe5b838281518110610fd657fe5b6020908102919091010152600101610fb4565b610ff16126bb565b7f3a3e76d7a75e198aef1f53137e4f2a8a2ec74e2e9526db8404d08ccc9f1e621d60035482604051611024929190615543565b60405180910390a1600355565b606061103b611a2b565b835160408051828152602080840282010190915281801561107657816020015b611063614561565b81526020019060019003908161105b5790505b50915060005b8181146110e6576110c786828151811061109257fe5b60200260200101518683815181106110a657fe5b60200260200101518684815181106110ba57fe5b6020026020010151612702565b8382815181106110d357fe5b602090810291909101015260010161107c565b50506110f0611ad7565b610932611aeb565b611100614561565b611108611a2b565b611113848484612702565b90506110f0611ad7565b6111256145ec565b61112e826127a4565b60408301526020820152608082015161114e5760015b60ff168152610b02565b60a082015161115e576002611144565b8160a00151816040015110611174576005611144565b8161010001514210611187576004611144565b6020808201516000908152600a909152604090205460ff16156111ab576006611144565b610120820151825173ffffffffffffffffffffffffffffffffffffffff9081166000908152600b6020908152604080832060608801519094168352929052205411156111f8576006611144565b60038152919050565b600080611219600154856127d590919063ffffffff16565b9050610b378482856127e4565b61122e614561565b611239848484610812565b9050828160200151101561093257610932610a386001858460200151612602565b835160005b8181146112ca576112c28160001b87838151811061127957fe5b602002602001015187848151811061128d57fe5b60200260200101518785815181106112a157fe5b60200260200101518786815181106112b557fe5b6020026020010151612839565b60010161125f565b506040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112fd90615914565b60405180910390fd5b61130e6145b8565b611316611a2b565b610b25858585856001612515565b606061132e611a2b565b835160408051828152602080840282010190915281801561136957816020015b611356614561565b81526020019060019003908161134e5790505b50915060005b8181146110e6576113ba86828151811061138557fe5b602002602001015186838151811061139957fe5b60200260200101518684815181106113ad57fe5b60200260200101516129f3565b8382815181106113c657fe5b602090810291909101015260010161136f565b6113e16126bb565b6004546040517fe1a5430ebec577336427f40f15822f1f36c5e3509ff209d6db9e6c9e6941cb0b9161142d9173ffffffffffffffffffffffffffffffffffffffff90911690849061537c565b60405180910390a1600480547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60015481565b61148a6126bb565b60008173ffffffffffffffffffffffffffffffffffffffff1663ae25532e6040518163ffffffff1660e01b815260040160206040518083038186803b1580156114d257600080fd5b505afa1580156114e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061150a9190810190614f09565b7fffffffff00000000000000000000000000000000000000000000000000000000811660009081526002602052604090205490915073ffffffffffffffffffffffffffffffffffffffff16801561156857611568610a388383612a26565b7fffffffff0000000000000000000000000000000000000000000000000000000082166000908152600260205260409081902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8616179055517fd2c6b762299c609bdb96520b58a49bfb80186934d4f71a86a367571a15c03194906116099084908690615658565b60405180910390a1505050565b600b60209081526000928352604080842090915290825290205481565b7f20c13b0b0000000000000000000000000000000000000000000000000000000081565b61165f611a2b565b805160005b81811461168f5761168783828151811061167a57fe5b6020026020010151611a9a565b600101611664565b5050610807611ad7565b6116a1614561565b6116a9611a2b565b6111138484846129f3565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b6116d86126bb565b73ffffffffffffffffffffffffffffffffffffffff8116611703576116fe610a38612ac8565b61080f565b6000805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff000000000000000000000000000000000000000090911617905550565b606061175261187b565b156117f457825160408051828152602080840282010190915260609082801561178f57816020015b606081526020019060019003908161177a5790505b50905060005b8281146117eb576117cc8682815181106117ab57fe5b60200260200101518683815181106117bf57fe5b602002602001015161189d565b8282815181106117d857fe5b6020908102919091010152600101611795565b509150506107c1565b6117fc6119b7565b825160408051828152602080840282010190915260609082801561183457816020015b606081526020019060019003908161181f5790505b50905060005b82811461186f576118508682815181106117ab57fe5b82828151811061185c57fe5b602090810291909101015260010161183a565b509150506107c16119f9565b6000547501000000000000000000000000000000000000000000900460ff1690565b606060006118b66001548561262190919063ffffffff16565b90506118c3848483612aff565b60608401516118d28180612bd3565b60008281526005602052604080822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055608087015190516060913091611920919061530e565b600060405180830381855af49150503d806000811461195b576040519150601f19603f3d011682016040523d82523d6000602084013e611960565b606091505b50915091508161197757611977610a388583612c36565b611982836000612bd3565b60405184907fa4a7329f1dd821363067e07d359e347b4af9b1efe4b6cccf13240228af3c800d90600090a29695505050505050565b600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff167501000000000000000000000000000000000000000000179055565b600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff169055611a29612c53565b565b60005474010000000000000000000000000000000000000000900460ff1615611a5957611a59610a38612c88565b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055565b611aa26145ec565b611aab8261111d565b9050611ab78282612cbf565b805160ff16600314611ac9575061080f565b610c1c828260200151612d6e565b611adf61187b565b611a2957611a29612c53565b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff169055565b600082821115611b2e57611b2e610a3860028585612e17565b50900390565b611b3c614561565b6040516060907f9b44d5560000000000000000000000000000000000000000000000000000000090611b7690879087908790602401615a58565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050600060603073ffffffffffffffffffffffffffffffffffffffff1683604051611bfe919061530e565b600060405180830381855af49150503d8060008114611c39576040519150601f19603f3d011682016040523d82523d6000602084013e611c3e565b606091505b50915091508115611c6b57805160a014611c5457fe5b80806020019051611c689190810190614f25565b93505b5050509392505050565b611c7d614561565b81518351611c909163ffffffff612e3616565b815260208083015190840151611cab9163ffffffff612e3616565b602082015260408083015190840151611cc99163ffffffff612e3616565b604082015260608083015190840151611ce79163ffffffff612e3616565b606082015260808083015190840151611d059163ffffffff612e3616565b608082015292915050565b60065460009073ffffffffffffffffffffffffffffffffffffffff16818115611d395781611d3b565b335b9250505090565b6060634ad3127560e01b848484604051602401611d61939291906153a3565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290509392505050565b805160208201fd5b611df7614590565b8551611e0a57611e0a610a386000612e52565b8451611e1d57611e1d610a386001612e52565b8351865114611e3357611e33610a386002612e52565b8251855114611e4957611e49610a386003612e52565b8551604051908082528060200260200182016040528015611e8457816020015b611e71614561565b815260200190600190039081611e695790505b5081528451604080518281526020808402820101909152908015611ec257816020015b611eaf614561565b815260200190600190039081611ea75790505b506020820152600080611ed361460c565b88600081518110611ee057fe5b60200260200101519050611ef261460c565b88600081518110611eff57fe5b602002602001015190506000611f14836127a4565b9150506000611f22836127a4565b915050611f2d614561565b611f35614561565b611f3d6145b8565b611f7087878f8c81518110611f4e57fe5b60200260200101518f8c81518110611f6257fe5b60200260200101518f612515565b805160200151909150611f8a90869063ffffffff612e3616565b9450611fa781602001516020015185612e3690919063ffffffff16565b9350611fb7838260000151611c75565b9250611fc7828260200151611c75565b9150611fe481604001518b60400151612e3690919063ffffffff16565b60408b0152606080820151908b01516120029163ffffffff612e3616565b60608b015260a087015185106120ad578951805160018b019a859291811061202657fe5b60200260200101819052506040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525092508e5189141561208a57818a60200151898151811061207957fe5b60200260200101819052505061214b565b8e898151811061209657fe5b602002602001015196506120a9876127a4565b9550505b8560a00151841061214557818a6020015189806001019a50815181106120cf57fe5b60200260200101819052506040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525091508d5188141561212257828a600001518a8151811061207957fe5b8d888151811061212e57fe5b60200260200101519550612141866127a4565b9450505b50611f35565b505050505050505095945050505050565b6000610b3783612172868563ffffffff612ef116565b9063ffffffff612f2216565b600061218b848484612f4c565b905073ffffffffffffffffffffffffffffffffffffffff83166121b8576121b8610a3860068686866121fd565b600881818111156121c557fe5b60ff16106121dd576121dd610a3860038686866121fd565b60008160088111156121eb57fe5b141561093257610932610a3860048686865b6060637e5a231860e01b8585858560405160240161221e94939291906158b9565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050949350505050565b600060018560088111156122b557fe5b14156122dc5781516001146122d4576122d4610a3860028686866121fd565b506000610b37565b60028560088111156122ea57fe5b14156123e357815160421461230957612309610a3860028686866121fd565b60008260008151811061231857fe5b016020015160f81c9050600061233584600163ffffffff612f8b16565b9050600061234a85602163ffffffff612f8b16565b9050600060018885858560405160008152602001604052604051612371949392919061560d565b6020604051602081039080840390855afa158015612393573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015173ffffffffffffffffffffffffffffffffffffffff8981169116149550610b37945050505050565b60038560088111156123f157fe5b141561249e57815160421461241057612410610a3860028686866121fd565b60008260008151811061241f57fe5b016020015160f81c9050600061243c84600163ffffffff612f8b16565b9050600061245185602163ffffffff612f8b16565b90506000600188604051602001612468919061532a565b6040516020818303038152906040528051906020012085858560405160008152602001604052604051612371949392919061560d565b60048560088111156124ac57fe5b14156124c4576124bd848484612fb5565b9050610b37565b60068560088111156124d257fe5b146124d957fe5b50600083815260076020908152604080832073ffffffffffffffffffffffffffffffffffffffff8616845290915290205460ff16949350505050565b61251d6145b8565b61016080870151610140808801919091528701519086015261253d6145ec565b6125468761111d565b90506125506145ec565b6125598761111d565b90506000612565611d10565b90506125738984838a6131ab565b61257f888383896131ab565b6125938989856020015185602001516132e1565b6125ac8989856040015185604001516003543a8b61332c565b93506125c78982856020015186604001518860000151613481565b6125e08882846020015185604001518860200151613481565b6125f6836020015183602001518b8b858961355f565b50505095945050505050565b60606318e4b14160e01b848484604051602401611d619392919061589e565b60006109328261263085613706565b61378e565b60608301516000908161264985838661217e565b9050600581600881111561265957fe5b141561267b5761267461266c87876137c8565b868487613800565b92506126b2565b600781600881111561268957fe5b14156126a35761267461269c87876137c8565b83866138b4565b6126af818684876122a5565b92505b50509392505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314611a2957600054611a2990610a3890339073ffffffffffffffffffffffffffffffffffffffff166138c3565b61270a614561565b6127126145ec565b61271b8561111d565b90506000612727611d10565b9050612735868383876131ab565b600061275283604001518860a00151611b1590919063ffffffff16565b9050600061276087836138e0565b905061277088826003543a6138f6565b945060008460200151905061278c89858388604001518a613481565b612798818a868961396d565b50505050509392505050565b6000806127bc600154846127d590919063ffffffff16565b6000818152600960205260409020549092509050915091565b60006109328261263085613a04565b8251600090816127f585838661217e565b9050600581600881111561280557fe5b14156128185761267461266c8787613adb565b600781600881111561282657fe5b14156126a35761267461269c8787613adb565b80156129ec57600384511161285757612857610a3860008787613b13565b6000612869858263ffffffff613b3216565b7fffffffff00000000000000000000000000000000000000000000000000000000811660009081526002602052604090205490915073ffffffffffffffffffffffffffffffffffffffff16806128c8576128c8610a3860018989613b13565b6040516060907fa85e59e400000000000000000000000000000000000000000000000000000000906129049089908990899089906024016156b3565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050600060608373ffffffffffffffffffffffffffffffffffffffff168360405161298c919061530e565b6000604051808303816000865af19150503d80600081146129c9576040519150601f19603f3d011682016040523d82523d6000602084013e6129ce565b606091505b5091509150816129e6576129e6610a388b8b84613b7e565b50505050505b5050505050565b6129fb614561565b612a06848484612702565b90508281602001511461093257610932610a386002858460200151612602565b60606311c7b72060e01b8383604051602401612a43929190615658565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905092915050565b60408051808201909152600481527fe69edc3e00000000000000000000000000000000000000000000000000000000602082015290565b82602001514210612b1857612b18610a38600183613b9d565b60408301513a8114612b3257612b32610a38833a84613bba565b60065473ffffffffffffffffffffffffffffffffffffffff168015612b5e57612b5e610a388483613bd9565b60008381526005602052604090205460ff1615612b8357612b83610a38600085613b9d565b606085015173ffffffffffffffffffffffffffffffffffffffff81163314801590612bb65750612bb4868587612635565b155b15612bcb57612bcb610a3860018684896121fd565b505050505050565b73ffffffffffffffffffffffffffffffffffffffff82163314610c1c576006805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff00000000000000000000000000000000000000009091161790555050565b60606320d11f6160e01b8383604051602401612a43929190615551565b3031801561080f57604051339082156108fc029083906000818181858888f19350505050158015610c1c573d6000803e3d6000fd5b60408051808201909152600481527f0c3b823f00000000000000000000000000000000000000000000000000000000602082015290565b606082015173ffffffffffffffffffffffffffffffffffffffff1615612d1357606082015173ffffffffffffffffffffffffffffffffffffffff163314612d1357612d13610a386002836020015133613bf6565b6000612d1d611d10565b90508073ffffffffffffffffffffffffffffffffffffffff16836000015173ffffffffffffffffffffffffffffffffffffffff1614612d6957612d69610a386000846020015184613bf6565b505050565b6000818152600a60205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558281015183516101408501516101608601519351859473ffffffffffffffffffffffffffffffffffffffff9485169493909316927f02c310a9a43963ff31a754a4099cc435ed498049687539d72d7818d9b093415c92612e0b92909190339061571b565b60405180910390a45050565b606063e946c1bb60e01b848484604051602401611d6193929190615846565b60008282018381101561093257610932610a3860008686612e17565b606063d4092f4f60e01b82604051602401612e6d9190615833565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050919050565b600082612f00575060006107c1565b82820282848281612f0d57fe5b041461093257610932610a3860018686612e17565b600081612f3857612f38610a3860038585612e17565b6000828481612f4357fe5b04949350505050565b6000815160001415612f6857612f68610a3860028686866121fd565b81600183510381518110612f7857fe5b016020015160f81c6008811115610b3757fe5b60008160200183511015612fac57612fac610a386005855185602001613c15565b50016020015190565b8051600090612fec837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff830163ffffffff613c3416565b6040516060907f1626ba7e00000000000000000000000000000000000000000000000000000000906130249088908790602401615551565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290506130b3848363ffffffff613c3416565b600060608673ffffffffffffffffffffffffffffffffffffffff16836040516130dc919061530e565b600060405180830381855afa9150503d8060008114613117576040519150601f19603f3d011682016040523d82523d6000602084013e61311c565b606091505b509150915081801561312f575080516020145b15613191577fb06713810000000000000000000000000000000000000000000000000000000061316682600063ffffffff613b3216565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614945050505050610932565b6131a0610a3889898985613c38565b505050509392505050565b825160ff166003146131da576131da610a388460200151856000015160ff1660068111156131d557fe5b613c59565b606084015173ffffffffffffffffffffffffffffffffffffffff161561322e57606084015173ffffffffffffffffffffffffffffffffffffffff16331461322e5761322e610a386002856020015133613bf6565b602084015173ffffffffffffffffffffffffffffffffffffffff1615613298578173ffffffffffffffffffffffffffffffffffffffff16846020015173ffffffffffffffffffffffffffffffffffffffff161461329857613298610a386001856020015185613bf6565b8351604084015115806132b557506132b584602001518284613c76565b156129ec576132c9858560200151846127e4565b6129ec576129ec610a386000866020015184866121fd565b60a080840151908501516132fa9163ffffffff612ef116565b608080850151908601516133139163ffffffff612ef116565b101561332657613326610a388383613cc9565b50505050565b6133346145b8565b60a088015160009061334c908863ffffffff611b1516565b905060006133638a608001518b60a0015184613ce6565b9050600061337e888b60a00151611b1590919063ffffffff16565b905060006133958b608001518c60a0015184613ce6565b905085156133b2576133ab8c8c85878587613d1a565b94506133c3565b6133c08c8c85878587613dec565b94505b84515160808d015160c08e01516133db929190613ce6565b85516040015284516020015160a08d015160e08e01516133fc929190613ce6565b85516060015260208501515160808c015160c08d015161341d929190613ce6565b856020015160400181815250506134458560200151602001518c60a001518d60e00151613ce6565b6020860151606001526000613460888a63ffffffff612ef116565b86516080908101829052602088015101525050505050979650505050505050565b602081015161349790839063ffffffff612e3616565b600960008581526020019081526020016000208190555082856040015173ffffffffffffffffffffffffffffffffffffffff16866000015173ffffffffffffffffffffffffffffffffffffffff167f6869791f0a34781b29882982cc39e882768cf2c96995c2a110c577c53bc932d58861014001518961016001518a61018001518b6101a001518b338a600001518b602001518c604001518d606001518e608001516040516135509b9a99989796959493929190615767565b60405180910390a45050505050565b8351835160408087015190860151610140870151855160200151613588918b9186908890612839565b6135a28a8961014001518686896020015160200151612839565b6135bc898861018001518584896020015160400151612839565b6135d68a8961018001518685896000015160400151612839565b6135ec8a89610140015186898960400151612839565b6136028988610140015185898960600151612839565b600061361a8b8b88600001516080015188888c613e85565b905080613637578551600060809182018190526020880151909101525b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614801561368757506101a080890151908a01516136879163ffffffff613ee216565b156136c5576136c08b8a6101a0015189866136bb8b60200151606001518c6000015160600151612e3690919063ffffffff16565b612839565b6136f9565b6136df8a896101a0015189858a6020015160600151612839565b6136f98b8a6101a0015189868a6000015160600151612839565b5050505050505050505050565b608081810151825160208085015160408087015160609788015186519685019690962082517fec69816980a3a3ca4554410e60253953e9ff375ba4536a98adfa15cc71541508815294850195909552908301919091529481019490945273ffffffffffffffffffffffffffffffffffffffff9091169183019190915260a082015260c0902090565b6040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b6040516060907fde047db40000000000000000000000000000000000000000000000000000000090612a439085908590602401615a83565b8051600090601581101561381e5761381e610a3860028787876121fd565b6000613852847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeb840163ffffffff613f0716565b73ffffffffffffffffffffffffffffffffffffffff80871660009081526008602090815260408083209385168352929052205490915060ff1661389c5761389c610a388683613f47565b6138a98188866015613f64565b979650505050505050565b6000610b378385846001613f64565b6060631de45ad160e01b8383604051602401612a4392919061537c565b60008183106138ef5781610932565b5090919050565b6138fe614561565b6020810184905260a0850151608086015161391a918691613ce6565b815260a085015160c0860151613931918691613ce6565b604082015260a085015160e086015161394b918691613ce6565b6060820152613960828463ffffffff612ef116565b6080820152949350505050565b613987848461016001518486600001518560200151612839565b6139a1848461014001518560000151858560000151612839565b6139bb84846101a001518486604001518560600151612839565b6139d984846101800151856000015186604001518560400151612839565b60006139ef85836080015186600001518661413b565b9050806129ec57600060808301525050505050565b6101408101516101608201516101808301516101a08401516000937ff80322eb8376aafb64eadf8f0d7623f22130fd9491a221e902b713cb984a753493909290916020871015613a5057fe5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe087018051610140890180516101608b0180516101808d0180516101a08f0180519d89528c5160209d8e012087528b519b8d019b909b2084528951998c01999099208152875197909a019690962088526101e085209390945290529190529252919091529050919050565b6040516060907f3efe50c80000000000000000000000000000000000000000000000000000000090612a439085908590602401615a36565b606063488219a660e01b848484604051602401611d619392919061580b565b60008160040183511015613b5357613b53610a386003855185600401613c15565b5001602001517fffffffff000000000000000000000000000000000000000000000000000000001690565b6060634678472b60e01b848484604051602401611d619392919061556a565b606063f598518460e01b8383604051602401612a439291906158fd565b606063a26dac0960e01b848484604051602401611d61939291906155f7565b606063dec4aedf60e01b8383604051602401612a439291906154d8565b606063e53c76c860e01b848484604051602401611d6193929190615867565b6060632800659560e01b848484604051602401611d61939291906158ab565b9052565b6060631b8388f760e01b8585858560405160240161221e94939291906154fc565b606063fdb6ca8d60e01b8383604051602401612a43929190615595565b600080613c84858585612f4c565b90506004816008811115613c9457fe5b1480613cab57506005816008811115613ca957fe5b145b80610de657506007816008811115613cbf57fe5b1495945050505050565b606063b6555d6f60e01b8383604051602401612a43929190615543565b6000613cf3848484614181565b15613d0657613d06610a388585856141e7565b610b3783612172868563ffffffff612ef116565b613d226145b8565b81851184841184861115613d4257613d3b898686614206565b9250613d91565b86841115613d825782518790528251602001869052608088015160a0890151613d6c919089613ce6565b6020808501805192909252905101879052613d91565b613d8e87878787614243565b92505b8115613db7576020808401510151835151613db19163ffffffff611b1516565b60408401525b8015613ddf5782516020908101519084015151613dd99163ffffffff611b1516565b60608401525b50505b9695505050505050565b613df46145b8565b82841115613e0e57613e07878484614206565b9050613e5c565b82841015613e4d5780518590528051602090810185905281015184905260a08601516080870151613e4091908661426e565b6020808301510152613e5c565b613e5985858585614243565b90505b6020808201510151815151613e769163ffffffff611b1516565b60408201529695505050505050565b60045460009073ffffffffffffffffffffffffffffffffffffffff168015613ed85730316000613eb98a84848b8b8a6142c2565b9050613ecb89848385038b8a8a6142c2565b5060019350505050613de2565b6000915050613de2565b6000815183511480156109325750508051602091820120825192909101919091201490565b60008160140183511015613f2857613f28610a386004855185601401613c15565b50016014015173ffffffffffffffffffffffffffffffffffffffff1690565b606063a15c0d0660e01b8383604051602401612a4392919061537c565b8151600090613f7b8484830363ffffffff613c3416565b6040516060907f20c13b0b0000000000000000000000000000000000000000000000000000000090613fb390889088906024016156f6565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050614042858363ffffffff613c3416565b600060608873ffffffffffffffffffffffffffffffffffffffff168360405161406b919061530e565b600060405180830381855afa9150503d80600081146140a6576040519150601f19603f3d011682016040523d82523d6000602084013e6140ab565b606091505b50915091508180156140be575080516020145b15614120577f20c13b0b000000000000000000000000000000000000000000000000000000006140f582600063ffffffff613b3216565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614945050505050610b37565b61412f610a388a8a8a856143fa565b50505050949350505050565b60045460009073ffffffffffffffffffffffffffffffffffffffff1680156141775761416c868230318888886142c2565b506001915050610b37565b6000915050610b37565b60008261419357614193610a3861441b565b81158061419e575083155b156141ab57506000610932565b600083806141b557fe5b85840990506141ca858463ffffffff612ef116565b6141dc826103e863ffffffff612ef116565b101595945050505050565b606063339f3de260e01b848484604051602401611d61939291906155f7565b61420e6145b8565b60208082018051859052518101839052815101839052608084015160a0850151614239919085613ce6565b8151529392505050565b61424b6145b8565b805194909452835160209081019390935282840180519290925290519091015290565b600061427b848484614452565b1561428e5761428e610a388585856141e7565b610b37836121726142a682600163ffffffff611b1516565b6142b6888763ffffffff612ef116565b9063ffffffff612e3616565b60008385106142ce5750825b6040516060907fa3b4a3270000000000000000000000000000000000000000000000000000000090614308908690869089906024016153a3565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050509050600060608873ffffffffffffffffffffffffffffffffffffffff168484604051614391919061530e565b60006040518083038185875af1925050503d80600081146143ce576040519150601f19603f3d011682016040523d82523d6000602084013e6143d3565b606091505b5091509150816143ed576143ed610a388b898989866144b6565b5050509695505050505050565b6060635bd0428d60e01b8585858560405160240161221e94939291906153d4565b60408051808201909152600481527fa791837c00000000000000000000000000000000000000000000000000000000602082015290565b60008261446457614464610a3861441b565b81158061446f575083155b1561447c57506000610932565b6000838061448657fe5b85840990508361449c818363ffffffff611b1516565b816144a357fe5b0690506141ca858463ffffffff612ef116565b60606387cb1e7560e01b86868686866040516024016144d99594939291906155b2565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905095945050505050565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b6040518060800160405280606081526020016060815260200160008152602001600081525090565b60405180608001604052806145cb614561565b81526020016145d8614561565b815260200160008152602001600081525090565b604080516060810182526000808252602082018190529181019190915290565b604051806101c00160405280600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001606081526020016060815260200160608152602001606081525090565b803573ffffffffffffffffffffffffffffffffffffffff811681146107c157600080fd5b600082601f830112614707578081fd5b813561471a61471582615b14565b615aed565b81815291506020808301908481018184028601820187101561473b57600080fd5b60005b848110156147625761475088836146d3565b8452928201929082019060010161473e565b505050505092915050565b600082601f83011261477d578081fd5b813561478b61471582615b14565b8181529150602080830190840160005b838110156147c8576147b3876020843589010161488b565b8352602092830192919091019060010161479b565b5050505092915050565b600082601f8301126147e2578081fd5b81356147f061471582615b14565b8181529150602080830190840160005b838110156147c8576148188760208435890101614912565b83526020928301929190910190600101614800565b600082601f83011261483d578081fd5b813561484b61471582615b14565b81815291506020808301908481018184028601820187101561486c57600080fd5b60005b848110156147625781358452928201929082019060010161486f565b600082601f83011261489b578081fd5b813567ffffffffffffffff8111156148b1578182fd5b6148e260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601615aed565b91508082528360208285010111156148f957600080fd5b8060208401602084013760009082016020015292915050565b60006101c0808385031215614925578182fd5b61492e81615aed565b91505061493b83836146d3565b815261494a83602084016146d3565b602082015261495c83604084016146d3565b604082015261496e83606084016146d3565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e08201526101008083013581830152506101208083013581830152506101408083013567ffffffffffffffff808211156149d057600080fd5b6149dc8683870161488b565b838501526101609250828501359150808211156149f857600080fd5b614a048683870161488b565b83850152610180925082850135915080821115614a2057600080fd5b614a2c8683870161488b565b838501526101a0925082850135915080821115614a4857600080fd5b50614a558582860161488b565b82840152505092915050565b600060a08284031215614a72578081fd5b614a7c60a0615aed565b90508135815260208201356020820152604082013560408201526060820135614aa481615b88565b6060820152608082013567ffffffffffffffff811115614ac357600080fd5b614acf8482850161488b565b60808301525092915050565b600060208284031215614aec578081fd5b61093283836146d3565b60008060408385031215614b08578081fd5b614b1284846146d3565b9150614b2184602085016146d3565b90509250929050565b60008060408385031215614b3c578182fd5b614b4684846146d3565b915060208301358015158114614b5a578182fd5b809150509250929050565b60008060008060808587031215614b7a578182fd5b843567ffffffffffffffff80821115614b91578384fd5b614b9d8883890161476d565b95506020870135915080821115614bb2578384fd5b614bbe888389016146f7565b94506040870135915080821115614bd3578384fd5b614bdf888389016146f7565b93506060870135915080821115614bf4578283fd5b50614c018782880161482d565b91505092959194509250565b600060208284031215614c1e578081fd5b813567ffffffffffffffff811115614c34578182fd5b610b37848285016147d2565b60008060008060808587031215614c55578182fd5b843567ffffffffffffffff80821115614c6c578384fd5b614c78888389016147d2565b95506020870135915080821115614c8d578384fd5b614c99888389016147d2565b94506040870135915080821115614cae578384fd5b614cba8883890161476d565b93506060870135915080821115614ccf578283fd5b50614c018782880161476d565b600080600060608486031215614cf0578081fd5b833567ffffffffffffffff80821115614d07578283fd5b614d13878388016147d2565b94506020860135915080821115614d28578283fd5b614d348783880161482d565b93506040860135915080821115614d49578283fd5b50614d568682870161476d565b9150509250925092565b600080600060608486031215614d74578081fd5b833567ffffffffffffffff80821115614d8b578283fd5b614d97878388016147d2565b9450602086013593506040860135915080821115614d49578283fd5b60008060408385031215614dc5578182fd5b823567ffffffffffffffff80821115614ddc578384fd5b81850186601f820112614ded578485fd5b80359250614dfd61471584615b14565b83815260208082019190838101885b87811015614e3557614e238c848435890101614a61565b85529382019390820190600101614e0c565b50919750880135945050505080821115614e4d578283fd5b50614e5a8582860161476d565b9150509250929050565b600060208284031215614e75578081fd5b5035919050565b60008060408385031215614e8e578182fd5b823591506020830135614b5a81615b88565b600080600060608486031215614eb4578081fd5b833592506020840135614ec681615b88565b9150604084013567ffffffffffffffff811115614ee1578182fd5b614d568682870161488b565b600060208284031215614efe578081fd5b813561093281615baa565b600060208284031215614f1a578081fd5b815161093281615baa565b600060a0828403128015614f37578182fd5b8015614f41578182fd5b50614f4c60a0615aed565b82518152602083015160208201526040830151604082015260608301516060820152608083015160808201528091505092915050565b600060208284031215614f93578081fd5b813567ffffffffffffffff811115614fa9578182fd5b610b3784828501614912565b60008060408385031215614fc7578182fd5b823567ffffffffffffffff80821115614fde578384fd5b614fea86838701614912565b93506020850135915080821115614fff578283fd5b50614e5a8582860161488b565b60008060008060808587031215615021578182fd5b843567ffffffffffffffff80821115615038578384fd5b61504488838901614912565b95506020870135915080821115615059578384fd5b61506588838901614912565b9450604087013591508082111561507a578384fd5b6150868883890161488b565b9350606087013591508082111561509b578283fd5b50614c018782880161488b565b6000806000606084860312156150bc578081fd5b833567ffffffffffffffff808211156150d3578283fd5b6150df87838801614912565b94506020860135935060408601359150808211156150fb578283fd5b50614d568682870161488b565b6000806040838503121561511a578182fd5b823567ffffffffffffffff80821115615131578384fd5b614fea86838701614a61565b73ffffffffffffffffffffffffffffffffffffffff169052565b6000815180845260208401935060208301825b828110156151935761517d8683516151e7565b60a095909501946020919091019060010161516a565b5093949350505050565b600081518084526151b5816020860160208601615b34565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b80518252602081015160208301526040810151604083015260608101516060830152608081015160808301525050565b60006101c061522784845161513d565b6020830151615239602086018261513d565b50604083015161524c604086018261513d565b50606083015161525f606086018261513d565b506080830151608085015260a083015160a085015260c083015160c085015260e083015160e08501526101008084015181860152506101208084015181860152506101408084015182828701526152b88387018261519d565b915050610160915081840151858203838701526152d5828261519d565b9250505061018080840151858303828701526152f1838261519d565b9150506101a091508184015185820383870152613de2828261519d565b60008251615320818460208701615b34565b9190910192915050565b7f19457468657265756d205369676e6564204d6573736167653a0a3332000000008152601c810191909152603c0190565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b600073ffffffffffffffffffffffffffffffffffffffff8616825260806020830152615403608083018661519d565b8281036040840152615415818661519d565b8381036060850152615427818661519d565b98975050505050505050565b6000602080830181845280855180835260408601915060408482028701019250838701855b828110156154a4577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc088860301845261549285835161519d565b94509285019290850190600101615458565b5092979650505050505050565b6000602082526109326020830184615157565b901515815260200190565b90815260200190565b91825273ffffffffffffffffffffffffffffffffffffffff16602082015260400190565b600085825273ffffffffffffffffffffffffffffffffffffffff8516602083015260806040830152615531608083018561519d565b82810360608401526138a9818561519d565b918252602082015260400190565b600083825260406020830152610b37604083018461519d565b600084825260606020830152615583606083018561519d565b8281036040840152613de2818561519d565b828152604081016155a583615b7e565b8260208301529392505050565b600086825285602083015273ffffffffffffffffffffffffffffffffffffffff808616604084015280851660608401525060a060808301526138a960a083018461519d565b9283526020830191909152604082015260600190565b93845260ff9290921660208401526040830152606082015260800190565b7fffffffff0000000000000000000000000000000000000000000000000000000091909116815260200190565b7fffffffff0000000000000000000000000000000000000000000000000000000092909216825273ffffffffffffffffffffffffffffffffffffffff16602082015260400190565b600060208252610932602083018461519d565b6000608082526156c6608083018761519d565b73ffffffffffffffffffffffffffffffffffffffff95861660208401529390941660408201526060015292915050565b600060408252615709604083018561519d565b8281036020840152610de6818561519d565b60006060825261572e606083018661519d565b8281036020840152615740818661519d565b91505073ffffffffffffffffffffffffffffffffffffffff83166040830152949350505050565b600061016080835261577b8184018f61519d565b838103602085015261578d818f61519d565b91505082810360408401526157a2818d61519d565b83810360608501526157b4818d61519d565b73ffffffffffffffffffffffffffffffffffffffff9b8c16608086015299909a1660a0840152505060c081019590955260e08501939093526101008401919091526101208301526101409091015295945050505050565b600061581685615b60565b84825283602083015260606040830152610de6606083018461519d565b6020810161584083615b6a565b91905290565b6060810161585385615b6a565b938152602081019290925260409091015290565b6060810161587485615b74565b938152602081019290925273ffffffffffffffffffffffffffffffffffffffff1660409091015290565b6060810161585385615b74565b606081016008851061585357fe5b60006158c486615b7e565b85825284602083015273ffffffffffffffffffffffffffffffffffffffff8416604083015260806060830152613de2608083018461519d565b6040810161590a84615b60565b9281526020015290565b60208082526014908201527f5452414e53464552535f5355434345535346554c000000000000000000000000604082015260600190565b60006020825282516080602084015261596760a0840182615157565b602085015191507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08482030160408501526159a28183615157565b604086015160608601526060860151608086015280935050505092915050565b60a081016107c182846151e7565b6000610180820190506159e48284516151e7565b60208301516159f660a08401826151e7565b5060408301516101408301526060909201516101609091015290565b815160ff168152602080830151908201526040918201519181019190915260600190565b600060408252615a496040830185615217565b90508260208301529392505050565b600060608252615a6b6060830186615217565b8460208401528281036040840152613de2818561519d565b60006040825283516040830152602084015160608301526040840151608083015273ffffffffffffffffffffffffffffffffffffffff60608501511660a0830152608084015160a060c0840152615add60e084018261519d565b9150508260208301529392505050565b60405181810167ffffffffffffffff81118282101715615b0c57600080fd5b604052919050565b600067ffffffffffffffff821115615b2a578081fd5b5060209081020190565b60005b83811015615b4f578181015183820152602001615b37565b838111156133265750506000910152565b6002811061080f57fe5b6004811061080f57fe5b6003811061080f57fe5b6007811061080f57fe5b73ffffffffffffffffffffffffffffffffffffffff8116811461080f57600080fd5b7fffffffff000000000000000000000000000000000000000000000000000000008116811461080f57600080fd5b8351602094850120835193850193909320604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f815295860194909452928401929092526060830152608082015260a090209056fea365627a7a723158206fc97c5a1d6fde6b2ada9eb4429966e52d7e2da39180893c04bf55c840b346a16c6578706572696d656e74616cf564736f6c634300050c0040'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; public EIP1271_MAGIC_VALUE = { /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an @@ -151,41 +159,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('EIP1271_MAGIC_VALUE()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('EIP1271_MAGIC_VALUE()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('EIP1271_MAGIC_VALUE()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public EIP712_EXCHANGE_DOMAIN_HASH = { /** @@ -229,41 +202,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('EIP712_EXCHANGE_DOMAIN_HASH()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('EIP712_EXCHANGE_DOMAIN_HASH()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('EIP712_EXCHANGE_DOMAIN_HASH()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public allowedValidators = { /** @@ -317,46 +255,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string, index_1: string): string { - assert.isString('index_0', index_0); - assert.isString('index_1', index_1); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('allowedValidators(address,address)', [ - index_0.toLowerCase(), - index_1.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('allowedValidators(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('allowedValidators(address,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Executes multiple calls of cancelOrder. @@ -387,6 +285,7 @@ export class ExchangeContract extends BaseContract { takerFeeAssetData: string; }>, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); const self = (this as any) as ExchangeContract; @@ -406,6 +305,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.batchCancelOrders.callAsync(orders, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -435,20 +338,19 @@ export class ExchangeContract extends BaseContract { takerFeeAssetData: string; }>, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); const self = (this as any) as ExchangeContract; - const txHashPromise = self.batchCancelOrders.sendTransactionAsync(orders, txData); + const txHashPromise = self.batchCancelOrders.sendTransactionAsync(orders, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -499,29 +401,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -623,70 +502,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): [ - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - ] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'batchCancelOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [ - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - ] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'batchCancelOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -712,6 +535,7 @@ export class ExchangeContract extends BaseContract { }>, signatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('transactions', transactions); assert.isArray('signatures', signatures); @@ -732,6 +556,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.batchExecuteTransactions.callAsync(transactions, signatures, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -755,21 +583,25 @@ export class ExchangeContract extends BaseContract { }>, signatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('transactions', transactions); assert.isArray('signatures', signatures); const self = (this as any) as ExchangeContract; - const txHashPromise = self.batchExecuteTransactions.sendTransactionAsync(transactions, signatures, txData); + const txHashPromise = self.batchExecuteTransactions.sendTransactionAsync( + transactions, + signatures, + txData, + opts, + ); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -815,25 +647,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - transactions: Array<{ - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - }>, - signatures: string[], - txData?: Partial | undefined, - ): Promise { - await (this as any).batchExecuteTransactions.callAsync(transactions, signatures, txData); - const txHash = await (this as any).batchExecuteTransactions.sendTransactionAsync( - transactions, - signatures, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -926,48 +739,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): Array<{ - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'batchExecuteTransactions((uint256,uint256,uint256,address,bytes)[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - Array<{ - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): string[] { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'batchExecuteTransactions((uint256,uint256,uint256,address,bytes)[],bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1004,6 +783,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts: BigNumber[], signatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isArray('takerAssetFillAmounts', takerAssetFillAmounts); @@ -1025,6 +805,15 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.batchFillOrKillOrders.callAsync( + orders, + takerAssetFillAmounts, + signatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1059,8 +848,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts: BigNumber[], signatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isArray('takerAssetFillAmounts', takerAssetFillAmounts); @@ -1071,6 +859,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts, signatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1078,8 +867,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1137,36 +926,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1299,82 +1058,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'batchFillOrKillOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }> { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'batchFillOrKillOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }> - >(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1411,6 +1102,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts: BigNumber[], signatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isArray('takerAssetFillAmounts', takerAssetFillAmounts); @@ -1432,6 +1124,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.batchFillOrders.callAsync(orders, takerAssetFillAmounts, signatures, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1466,8 +1162,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts: BigNumber[], signatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isArray('takerAssetFillAmounts', takerAssetFillAmounts); @@ -1478,6 +1173,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts, signatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1485,8 +1181,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1544,36 +1240,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1706,82 +1372,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'batchFillOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }> { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'batchFillOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }> - >(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1818,6 +1416,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts: BigNumber[], signatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isArray('takerAssetFillAmounts', takerAssetFillAmounts); @@ -1839,6 +1438,15 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.batchFillOrdersNoThrow.callAsync( + orders, + takerAssetFillAmounts, + signatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1873,8 +1481,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts: BigNumber[], signatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isArray('takerAssetFillAmounts', takerAssetFillAmounts); @@ -1885,6 +1492,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmounts, signatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -1892,8 +1500,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1951,36 +1559,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2113,82 +1691,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'batchFillOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }> { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'batchFillOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }> - >(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -2245,6 +1755,7 @@ export class ExchangeContract extends BaseContract { leftSignatures: string[], rightSignatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('leftOrders', leftOrders); assert.isArray('rightOrders', rightOrders); @@ -2267,6 +1778,16 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.batchMatchOrders.callAsync( + leftOrders, + rightOrders, + leftSignatures, + rightSignatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2319,8 +1840,7 @@ export class ExchangeContract extends BaseContract { leftSignatures: string[], rightSignatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('leftOrders', leftOrders); assert.isArray('rightOrders', rightOrders); @@ -2333,6 +1853,7 @@ export class ExchangeContract extends BaseContract { leftSignatures, rightSignatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -2340,8 +1861,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2418,59 +1939,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - leftOrders: 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - rightOrders: 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - leftSignatures: string[], - rightSignatures: string[], - txData?: Partial | undefined, - ): Promise { - await (this as any).batchMatchOrders.callAsync( - leftOrders, - rightOrders, - leftSignatures, - rightSignatures, - txData, - ); - const txHash = await (this as any).batchMatchOrders.sendTransactionAsync( - leftOrders, - rightOrders, - leftSignatures, - rightSignatures, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2659,102 +2127,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'batchMatchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - left: Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>; - right: Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>; - profitInLeftMakerAsset: BigNumber; - profitInRightMakerAsset: BigNumber; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'batchMatchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - left: Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>; - right: Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>; - profitInLeftMakerAsset: BigNumber; - profitInRightMakerAsset: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -2812,6 +2192,7 @@ export class ExchangeContract extends BaseContract { leftSignatures: string[], rightSignatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('leftOrders', leftOrders); assert.isArray('rightOrders', rightOrders); @@ -2834,6 +2215,16 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.batchMatchOrdersWithMaximalFill.callAsync( + leftOrders, + rightOrders, + leftSignatures, + rightSignatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2886,8 +2277,7 @@ export class ExchangeContract extends BaseContract { leftSignatures: string[], rightSignatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('leftOrders', leftOrders); assert.isArray('rightOrders', rightOrders); @@ -2900,6 +2290,7 @@ export class ExchangeContract extends BaseContract { leftSignatures, rightSignatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -2907,8 +2298,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2985,72 +2376,19 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - leftOrders: 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - rightOrders: 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - leftSignatures: string[], - rightSignatures: string[], - txData?: Partial | undefined, - ): Promise { - await (this as any).batchMatchOrdersWithMaximalFill.callAsync( - leftOrders, - rightOrders, - leftSignatures, - rightSignatures, - txData, - ); - const txHash = await (this as any).batchMatchOrdersWithMaximalFill.sendTransactionAsync( - leftOrders, - rightOrders, - leftSignatures, - rightSignatures, - txData, - ); - return txHash; - }, - /** - * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an - * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas - * since they don't modify state. - * @param leftOrders Set of orders with the same maker / taker asset. - * @param rightOrders Set of orders to match against `leftOrders` - * @param leftSignatures Proof that left orders were created by the left - * makers. - * @param rightSignatures Proof that right orders were created by the right - * makers. - * @returns batchMatchedFillResults Amounts filled and profit generated. - */ - async callAsync( + /** + * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an + * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas + * since they don't modify state. + * @param leftOrders Set of orders with the same maker / taker asset. + * @param rightOrders Set of orders to match against `leftOrders` + * @param leftSignatures Proof that left orders were created by the left + * makers. + * @param rightSignatures Proof that right orders were created by the right + * makers. + * @returns batchMatchedFillResults Amounts filled and profit generated. + */ + async callAsync( leftOrders: Array<{ makerAddress: string; takerAddress: string; @@ -3226,102 +2564,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'batchMatchOrdersWithMaximalFill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - left: Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>; - right: Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>; - profitInLeftMakerAsset: BigNumber; - profitInRightMakerAsset: BigNumber; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'batchMatchOrdersWithMaximalFill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - left: Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>; - right: Array<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>; - profitInLeftMakerAsset: BigNumber; - profitInRightMakerAsset: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -3353,6 +2603,7 @@ export class ExchangeContract extends BaseContract { takerFeeAssetData: string; }, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { const self = (this as any) as ExchangeContract; const encodedData = self._strictEncodeArguments( @@ -3371,6 +2622,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.cancelOrder.callAsync(order, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -3400,19 +2655,18 @@ export class ExchangeContract extends BaseContract { takerFeeAssetData: string; }, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { const self = (this as any) as ExchangeContract; - const txHashPromise = self.cancelOrder.sendTransactionAsync(order, txData); + const txHashPromise = self.cancelOrder.sendTransactionAsync(order, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -3462,29 +2716,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -3582,70 +2813,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): [ - { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } - ] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'cancelOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [ - { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } - ] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'cancelOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -3661,7 +2836,11 @@ export class ExchangeContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(targetOrderEpoch: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + targetOrderEpoch: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isBigNumber('targetOrderEpoch', targetOrderEpoch); const self = (this as any) as ExchangeContract; const encodedData = self._strictEncodeArguments('cancelOrdersUpTo(uint256)', [targetOrderEpoch]); @@ -3677,6 +2856,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.cancelOrdersUpTo.callAsync(targetOrderEpoch, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -3692,20 +2875,19 @@ export class ExchangeContract extends BaseContract { awaitTransactionSuccessAsync( targetOrderEpoch: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('targetOrderEpoch', targetOrderEpoch); const self = (this as any) as ExchangeContract; - const txHashPromise = self.cancelOrdersUpTo.sendTransactionAsync(targetOrderEpoch, txData); + const txHashPromise = self.cancelOrdersUpTo.sendTransactionAsync(targetOrderEpoch, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -3736,14 +2918,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -3809,28 +2983,12 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [BigNumber] { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder('cancelOrdersUpTo(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('cancelOrdersUpTo(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public cancelled = { @@ -3880,42 +3038,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('cancelled(bytes32)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('cancelled(bytes32)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('cancelled(bytes32)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public currentContextAddress = { /** @@ -3959,41 +3081,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('currentContextAddress()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('currentContextAddress()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('currentContextAddress()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Executes an Exchange method call in the context of signer. @@ -4017,6 +3104,7 @@ export class ExchangeContract extends BaseContract { }, signature: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('signature', signature); const self = (this as any) as ExchangeContract; @@ -4036,6 +3124,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.executeTransaction.callAsync(transaction, signature, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -4058,20 +3150,19 @@ export class ExchangeContract extends BaseContract { }, signature: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('signature', signature); const self = (this as any) as ExchangeContract; - const txHashPromise = self.executeTransaction.sendTransactionAsync(transaction, signature, txData); + const txHashPromise = self.executeTransaction.sendTransactionAsync(transaction, signature, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -4115,21 +3206,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - transaction: { - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - }, - signature: string, - txData?: Partial | undefined, - ): Promise { - await (this as any).executeTransaction.callAsync(transaction, signature, txData); - const txHash = await (this as any).executeTransaction.sendTransactionAsync(transaction, signature, txData); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -4218,46 +3294,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): { - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'executeTransaction((uint256,uint256,uint256,address,bytes),bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'executeTransaction((uint256,uint256,uint256,address,bytes),bytes)', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -4293,6 +3337,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount: BigNumber, signature: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); assert.isString('signature', signature); @@ -4313,6 +3358,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.fillOrKillOrder.callAsync(order, takerAssetFillAmount, signature, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -4346,8 +3395,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount: BigNumber, signature: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); assert.isString('signature', signature); @@ -4357,6 +3405,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount, signature, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -4364,8 +3413,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -4421,36 +3470,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -4574,78 +3593,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'fillOrKillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)', ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'fillOrKillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -4681,6 +3636,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount: BigNumber, signature: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); assert.isString('signature', signature); @@ -4701,6 +3657,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.fillOrder.callAsync(order, takerAssetFillAmount, signature, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -4734,21 +3694,26 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount: BigNumber, signature: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); assert.isString('signature', signature); const self = (this as any) as ExchangeContract; - const txHashPromise = self.fillOrder.sendTransactionAsync(order, takerAssetFillAmount, signature, txData); + const txHashPromise = self.fillOrder.sendTransactionAsync( + order, + takerAssetFillAmount, + signature, + txData, + opts, + ); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -4804,36 +3769,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -4958,78 +3893,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'fillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)', ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'fillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public filled = { @@ -5079,42 +3950,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('filled(bytes32)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('filled(bytes32)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('filled(bytes32)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Gets an asset proxy. @@ -5168,43 +4003,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param assetProxyId Id of the asset proxy. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(assetProxyId: string): string { - assert.isString('assetProxyId', assetProxyId); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getAssetProxy(bytes4)', [assetProxyId]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('getAssetProxy(bytes4)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('getAssetProxy(bytes4)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Gets information about an order: status, hash, and amount filled. @@ -5281,102 +4079,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param order Order to gather information on. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }): string { - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getOrderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))', - [order], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): { orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - orderStatus: number; - orderHash: string; - orderTakerAssetFilledAmount: BigNumber; - }>(returnData); - return abiDecodedReturnData; - }, }; /** * Verifies that a hash has been signed by the given signer. @@ -5422,67 +4124,23 @@ export class ExchangeContract extends BaseContract { data: encodedData, }, self._web3Wrapper.getContractDefaults(), - ); - callDataWithDefaults.from = callDataWithDefaults.from - ? callDataWithDefaults.from.toLowerCase() - : callDataWithDefaults.from; - let rawCallResult; - try { - rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); - } catch (err) { - BaseContract._throwIfThrownErrorIsRevertError(err); - throw err; - } - BaseContract._throwIfCallResultIsRevertError(rawCallResult); - const abiEncoder = self._lookupAbiEncoder('isValidHashSignature(bytes32,address,bytes)'); - // tslint:disable boolean-naming - const result = abiEncoder.strictDecodeReturnValue(rawCallResult); - // tslint:enable boolean-naming - return result; - }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param hash Any 32-byte hash. - * @param signerAddress Address that should have signed the given hash. - * @param signature Proof that the hash has been signed by signer. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(hash: string, signerAddress: string, signature: string): string { - assert.isString('hash', hash); - assert.isString('signerAddress', signerAddress); - assert.isString('signature', signature); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'isValidHashSignature(bytes32,address,bytes)', - [hash, signerAddress.toLowerCase(), signature], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('isValidHashSignature(bytes32,address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ExchangeContract; + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); const abiEncoder = self._lookupAbiEncoder('isValidHashSignature(bytes32,address,bytes)'); // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; }, }; /** @@ -5559,101 +4217,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param order The order. - * @param signature Proof that the order has been signed by signer. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }, - signature: string, - ): string { - assert.isString('signature', signature); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'isValidOrderSignature((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)', - [order, signature], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'isValidOrderSignature((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'isValidOrderSignature((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Verifies that a signature for a transaction is valid. @@ -5720,74 +4283,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param transaction The transaction. - * @param signature Proof that the order has been signed by signer. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - transaction: { - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - }, - signature: string, - ): string { - assert.isString('signature', signature); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'isValidTransactionSignature((uint256,uint256,uint256,address,bytes),bytes)', - [transaction, signature], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'isValidTransactionSignature((uint256,uint256,uint256,address,bytes),bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - salt: BigNumber; - expirationTimeSeconds: BigNumber; - gasPrice: BigNumber; - signerAddress: string; - data: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'isValidTransactionSignature((uint256,uint256,uint256,address,bytes),bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Calls marketBuyOrdersNoThrow then reverts if < makerAssetFillAmount has been bought. @@ -5823,6 +4318,7 @@ export class ExchangeContract extends BaseContract { makerAssetFillAmount: BigNumber, signatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isBigNumber('makerAssetFillAmount', makerAssetFillAmount); @@ -5844,6 +4340,15 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.marketBuyOrdersFillOrKill.callAsync( + orders, + makerAssetFillAmount, + signatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -5877,8 +4382,7 @@ export class ExchangeContract extends BaseContract { makerAssetFillAmount: BigNumber, signatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isBigNumber('makerAssetFillAmount', makerAssetFillAmount); @@ -5889,6 +4393,7 @@ export class ExchangeContract extends BaseContract { makerAssetFillAmount, signatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -5896,8 +4401,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -5954,36 +4459,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - makerAssetFillAmount: BigNumber, - signatures: string[], - txData?: Partial | undefined, - ): Promise { - await (this as any).marketBuyOrdersFillOrKill.callAsync(orders, makerAssetFillAmount, signatures, txData); - const txHash = await (this as any).marketBuyOrdersFillOrKill.sendTransactionAsync( - orders, - makerAssetFillAmount, - signatures, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -6110,80 +4585,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'marketBuyOrdersFillOrKill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'marketBuyOrdersFillOrKill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -6221,6 +4630,7 @@ export class ExchangeContract extends BaseContract { makerAssetFillAmount: BigNumber, signatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isBigNumber('makerAssetFillAmount', makerAssetFillAmount); @@ -6242,6 +4652,15 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.marketBuyOrdersNoThrow.callAsync( + orders, + makerAssetFillAmount, + signatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -6275,8 +4694,7 @@ export class ExchangeContract extends BaseContract { makerAssetFillAmount: BigNumber, signatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isBigNumber('makerAssetFillAmount', makerAssetFillAmount); @@ -6287,6 +4705,7 @@ export class ExchangeContract extends BaseContract { makerAssetFillAmount, signatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -6294,8 +4713,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -6330,57 +4749,27 @@ export class ExchangeContract extends BaseContract { txData?: Partial | undefined, ): Promise { assert.isArray('orders', orders); - assert.isBigNumber('makerAssetFillAmount', makerAssetFillAmount); - assert.isArray('signatures', signatures); - const self = (this as any) as ExchangeContract; - const encodedData = self._strictEncodeArguments( - 'marketBuyOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', - [orders, makerAssetFillAmount, signatures], - ); - const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( - { - to: self.address, - ...txData, - data: encodedData, - }, - self._web3Wrapper.getContractDefaults(), - ); - if (txDataWithDefaults.from !== undefined) { - txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); - } - - const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); - return gas; - }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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, + assert.isBigNumber('makerAssetFillAmount', makerAssetFillAmount); + assert.isArray('signatures', signatures); + const self = (this as any) as ExchangeContract; + const encodedData = self._strictEncodeArguments( + 'marketBuyOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', + [orders, makerAssetFillAmount, signatures], ); - return txHash; + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an @@ -6508,80 +4897,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'marketBuyOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'marketBuyOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -6618,6 +4941,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount: BigNumber, signatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); @@ -6639,6 +4963,15 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.marketSellOrdersFillOrKill.callAsync( + orders, + takerAssetFillAmount, + signatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -6672,8 +5005,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount: BigNumber, signatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); @@ -6684,6 +5016,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount, signatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -6691,8 +5024,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -6749,36 +5082,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - takerAssetFillAmount: BigNumber, - signatures: string[], - txData?: Partial | undefined, - ): Promise { - await (this as any).marketSellOrdersFillOrKill.callAsync(orders, takerAssetFillAmount, signatures, txData); - const txHash = await (this as any).marketSellOrdersFillOrKill.sendTransactionAsync( - orders, - takerAssetFillAmount, - signatures, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -6905,80 +5208,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'marketSellOrdersFillOrKill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'marketSellOrdersFillOrKill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -7016,6 +5253,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount: BigNumber, signatures: string[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); @@ -7037,6 +5275,15 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.marketSellOrdersNoThrow.callAsync( + orders, + takerAssetFillAmount, + signatures, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -7070,8 +5317,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount: BigNumber, signatures: string[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isBigNumber('takerAssetFillAmount', takerAssetFillAmount); @@ -7082,6 +5328,7 @@ export class ExchangeContract extends BaseContract { takerAssetFillAmount, signatures, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -7089,8 +5336,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -7147,36 +5394,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -7303,80 +5520,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'marketSellOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'marketSellOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -7432,6 +5583,7 @@ export class ExchangeContract extends BaseContract { leftSignature: string, rightSignature: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('leftSignature', leftSignature); assert.isString('rightSignature', rightSignature); @@ -7452,6 +5604,16 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.matchOrders.callAsync( + leftOrder, + rightOrder, + leftSignature, + rightSignature, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -7502,8 +5664,7 @@ export class ExchangeContract extends BaseContract { leftSignature: string, rightSignature: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('leftSignature', leftSignature); assert.isString('rightSignature', rightSignature); @@ -7514,6 +5675,7 @@ export class ExchangeContract extends BaseContract { leftSignature, rightSignature, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -7521,8 +5683,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -7569,78 +5731,31 @@ export class ExchangeContract extends BaseContract { makerFeeAssetData: string; takerFeeAssetData: string; }, - leftSignature: string, - rightSignature: string, - txData?: Partial | undefined, - ): Promise { - assert.isString('leftSignature', leftSignature); - assert.isString('rightSignature', rightSignature); - const self = (this as any) as ExchangeContract; - const encodedData = self._strictEncodeArguments( - 'matchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)', - [leftOrder, rightOrder, leftSignature, rightSignature], - ); - const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( - { - to: self.address, - ...txData, - data: encodedData, - }, - self._web3Wrapper.getContractDefaults(), - ); - if (txDataWithDefaults.from !== undefined) { - txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); - } - - const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); - return gas; - }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - makerFeeAssetData: string; - takerFeeAssetData: 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, + leftSignature: string, + rightSignature: string, + txData?: Partial | undefined, + ): Promise { + assert.isString('leftSignature', leftSignature); + assert.isString('rightSignature', rightSignature); + const self = (this as any) as ExchangeContract; + const encodedData = self._strictEncodeArguments( + 'matchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)', + [leftOrder, rightOrder, leftSignature, rightSignature], ); - return txHash; + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( + { + to: self.address, + ...txData, + data: encodedData, + }, + self._web3Wrapper.getContractDefaults(), + ); + if (txDataWithDefaults.from !== undefined) { + txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); + } + + const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); + return gas; }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an @@ -7822,100 +5937,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'matchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - left: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }; - right: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }; - profitInLeftMakerAsset: BigNumber; - profitInRightMakerAsset: BigNumber; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'matchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - left: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }; - right: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }; - profitInLeftMakerAsset: BigNumber; - profitInRightMakerAsset: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -7971,6 +6000,7 @@ export class ExchangeContract extends BaseContract { leftSignature: string, rightSignature: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('leftSignature', leftSignature); assert.isString('rightSignature', rightSignature); @@ -7991,6 +6021,16 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.matchOrdersWithMaximalFill.callAsync( + leftOrder, + rightOrder, + leftSignature, + rightSignature, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -8041,8 +6081,7 @@ export class ExchangeContract extends BaseContract { leftSignature: string, rightSignature: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('leftSignature', leftSignature); assert.isString('rightSignature', rightSignature); @@ -8053,6 +6092,7 @@ export class ExchangeContract extends BaseContract { leftSignature, rightSignature, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -8060,8 +6100,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -8134,59 +6174,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }, - leftSignature: string, - rightSignature: string, - txData?: Partial | undefined, - ): Promise { - await (this as any).matchOrdersWithMaximalFill.callAsync( - leftOrder, - rightOrder, - leftSignature, - rightSignature, - txData, - ); - const txHash = await (this as any).matchOrdersWithMaximalFill.sendTransactionAsync( - leftOrder, - rightOrder, - leftSignature, - rightSignature, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -8367,100 +6354,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - } { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'matchOrdersWithMaximalFill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData( - returnData: string, - ): { - left: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }; - right: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }; - profitInLeftMakerAsset: BigNumber; - profitInRightMakerAsset: BigNumber; - } { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'matchOrdersWithMaximalFill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - left: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }; - right: { - makerAssetFilledAmount: BigNumber; - takerAssetFilledAmount: BigNumber; - makerFeePaid: BigNumber; - takerFeePaid: BigNumber; - protocolFeePaid: BigNumber; - }; - profitInLeftMakerAsset: BigNumber; - profitInRightMakerAsset: BigNumber; - }>(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public orderEpoch = { @@ -8497,63 +6398,23 @@ export class ExchangeContract extends BaseContract { data: encodedData, }, self._web3Wrapper.getContractDefaults(), - ); - callDataWithDefaults.from = callDataWithDefaults.from - ? callDataWithDefaults.from.toLowerCase() - : callDataWithDefaults.from; - let rawCallResult; - try { - rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); - } catch (err) { - BaseContract._throwIfThrownErrorIsRevertError(err); - throw err; - } - BaseContract._throwIfCallResultIsRevertError(rawCallResult); - const abiEncoder = self._lookupAbiEncoder('orderEpoch(address,address)'); - // tslint:disable boolean-naming - const result = abiEncoder.strictDecodeReturnValue(rawCallResult); - // tslint:enable boolean-naming - return result; - }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string, index_1: string): string { - assert.isString('index_0', index_0); - assert.isString('index_1', index_1); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('orderEpoch(address,address)', [ - index_0.toLowerCase(), - index_1.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('orderEpoch(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ExchangeContract; + ); + callDataWithDefaults.from = callDataWithDefaults.from + ? callDataWithDefaults.from.toLowerCase() + : callDataWithDefaults.from; + let rawCallResult; + try { + rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); + } catch (err) { + BaseContract._throwIfThrownErrorIsRevertError(err); + throw err; + } + BaseContract._throwIfCallResultIsRevertError(rawCallResult); const abiEncoder = self._lookupAbiEncoder('orderEpoch(address,address)'); // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + const result = abiEncoder.strictDecodeReturnValue(rawCallResult); + // tslint:enable boolean-naming + return result; }, }; public owner = { @@ -8598,41 +6459,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owner()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Approves a hash on-chain. @@ -8646,7 +6472,11 @@ export class ExchangeContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(hash: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + hash: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('hash', hash); const self = (this as any) as ExchangeContract; const encodedData = self._strictEncodeArguments('preSign(bytes32)', [hash]); @@ -8662,6 +6492,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.preSign.callAsync(hash, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -8676,20 +6510,19 @@ export class ExchangeContract extends BaseContract { awaitTransactionSuccessAsync( hash: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('hash', hash); const self = (this as any) as ExchangeContract; - const txHashPromise = self.preSign.sendTransactionAsync(hash, txData); + const txHashPromise = self.preSign.sendTransactionAsync(hash, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -8719,11 +6552,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync(hash: string, txData?: Partial | undefined): Promise { - await (this as any).preSign.callAsync(hash, txData); - const txHash = await (this as any).preSign.sendTransactionAsync(hash, txData); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -8781,28 +6609,12 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('preSign(bytes32)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder('preSign(bytes32)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public preSigned = { @@ -8857,46 +6669,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string, index_1: string): string { - assert.isString('index_0', index_0); - assert.isString('index_1', index_1); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('preSigned(bytes32,address)', [ - index_0, - index_1.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('preSigned(bytes32,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('preSigned(bytes32,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public protocolFeeCollector = { /** @@ -8940,41 +6712,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('protocolFeeCollector()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('protocolFeeCollector()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('protocolFeeCollector()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public protocolFeeMultiplier = { /** @@ -9018,41 +6755,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('protocolFeeMultiplier()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('protocolFeeMultiplier()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('protocolFeeMultiplier()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Registers an asset proxy to its asset proxy id. @@ -9066,7 +6768,11 @@ export class ExchangeContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(assetProxy: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + assetProxy: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('assetProxy', assetProxy); const self = (this as any) as ExchangeContract; const encodedData = self._strictEncodeArguments('registerAssetProxy(address)', [assetProxy.toLowerCase()]); @@ -9082,6 +6788,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.registerAssetProxy.callAsync(assetProxy, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -9096,20 +6806,19 @@ export class ExchangeContract extends BaseContract { awaitTransactionSuccessAsync( assetProxy: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('assetProxy', assetProxy); const self = (this as any) as ExchangeContract; - const txHashPromise = self.registerAssetProxy.sendTransactionAsync(assetProxy.toLowerCase(), txData); + const txHashPromise = self.registerAssetProxy.sendTransactionAsync(assetProxy.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -9139,14 +6848,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -9210,28 +6911,12 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('registerAssetProxy(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder('registerAssetProxy(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -9249,6 +6934,7 @@ export class ExchangeContract extends BaseContract { async sendTransactionAsync( updatedProtocolFeeCollector: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('updatedProtocolFeeCollector', updatedProtocolFeeCollector); const self = (this as any) as ExchangeContract; @@ -9267,6 +6953,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.setProtocolFeeCollectorAddress.callAsync(updatedProtocolFeeCollector, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -9282,14 +6972,14 @@ export class ExchangeContract extends BaseContract { awaitTransactionSuccessAsync( updatedProtocolFeeCollector: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('updatedProtocolFeeCollector', updatedProtocolFeeCollector); const self = (this as any) as ExchangeContract; const txHashPromise = self.setProtocolFeeCollectorAddress.sendTransactionAsync( updatedProtocolFeeCollector.toLowerCase(), txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -9297,8 +6987,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -9334,17 +7024,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - updatedProtocolFeeCollector: string, - txData?: Partial | undefined, - ): Promise { - await (this as any).setProtocolFeeCollectorAddress.callAsync(updatedProtocolFeeCollector, txData); - const txHash = await (this as any).setProtocolFeeCollectorAddress.sendTransactionAsync( - updatedProtocolFeeCollector, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -9412,28 +7091,12 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('setProtocolFeeCollectorAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder('setProtocolFeeCollectorAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -9450,6 +7113,7 @@ export class ExchangeContract extends BaseContract { async sendTransactionAsync( updatedProtocolFeeMultiplier: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isBigNumber('updatedProtocolFeeMultiplier', updatedProtocolFeeMultiplier); const self = (this as any) as ExchangeContract; @@ -9468,6 +7132,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.setProtocolFeeMultiplier.callAsync(updatedProtocolFeeMultiplier, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -9482,14 +7150,14 @@ export class ExchangeContract extends BaseContract { awaitTransactionSuccessAsync( updatedProtocolFeeMultiplier: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('updatedProtocolFeeMultiplier', updatedProtocolFeeMultiplier); const self = (this as any) as ExchangeContract; const txHashPromise = self.setProtocolFeeMultiplier.sendTransactionAsync( updatedProtocolFeeMultiplier, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -9497,8 +7165,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -9533,17 +7201,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - updatedProtocolFeeMultiplier: BigNumber, - txData?: Partial | undefined, - ): Promise { - await (this as any).setProtocolFeeMultiplier.callAsync(updatedProtocolFeeMultiplier, txData); - const txHash = await (this as any).setProtocolFeeMultiplier.sendTransactionAsync( - updatedProtocolFeeMultiplier, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -9609,28 +7266,12 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [BigNumber] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('setProtocolFeeMultiplier(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder('setProtocolFeeMultiplier(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -9650,6 +7291,7 @@ export class ExchangeContract extends BaseContract { validatorAddress: string, approval: boolean, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('validatorAddress', validatorAddress); assert.isBoolean('approval', approval); @@ -9670,6 +7312,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.setSignatureValidatorApproval.callAsync(validatorAddress, approval, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -9686,8 +7332,7 @@ export class ExchangeContract extends BaseContract { validatorAddress: string, approval: boolean, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('validatorAddress', validatorAddress); assert.isBoolean('approval', approval); @@ -9696,6 +7341,7 @@ export class ExchangeContract extends BaseContract { validatorAddress.toLowerCase(), approval, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -9703,8 +7349,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -9743,19 +7389,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -9828,28 +7461,12 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, boolean] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('setSignatureValidatorApproval(address,bool)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, boolean]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder('setSignatureValidatorApproval(address,bool)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -9876,6 +7493,7 @@ export class ExchangeContract extends BaseContract { toAddresses: string[], amounts: BigNumber[], txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('assetData', assetData); assert.isArray('fromAddresses', fromAddresses); @@ -9898,6 +7516,16 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.simulateDispatchTransferFromCalls.callAsync( + assetData, + fromAddresses, + toAddresses, + amounts, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -9922,8 +7550,7 @@ export class ExchangeContract extends BaseContract { toAddresses: string[], amounts: BigNumber[], txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('assetData', assetData); assert.isArray('fromAddresses', fromAddresses); @@ -9936,6 +7563,7 @@ export class ExchangeContract extends BaseContract { toAddresses, amounts, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -9943,8 +7571,8 @@ export class ExchangeContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -9993,29 +7621,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - assetData: string[], - fromAddresses: string[], - toAddresses: string[], - amounts: BigNumber[], - txData?: Partial | undefined, - ): Promise { - await (this as any).simulateDispatchTransferFromCalls.callAsync( - assetData, - fromAddresses, - toAddresses, - amounts, - txData, - ); - const txHash = await (this as any).simulateDispatchTransferFromCalls.sendTransactionAsync( - assetData, - fromAddresses, - toAddresses, - amounts, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -10114,32 +7719,14 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string[], string[], string[], BigNumber[]] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder( - 'simulateDispatchTransferFromCalls(bytes[],address[],address[],uint256[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string[], string[], string[], BigNumber[]]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder( 'simulateDispatchTransferFromCalls(bytes[],address[],address[],uint256[])', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public transactionsExecuted = { @@ -10189,42 +7776,6 @@ export class ExchangeContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as ExchangeContract; - const abiEncodedTransactionData = self._strictEncodeArguments('transactionsExecuted(bytes32)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('transactionsExecuted(bytes32)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('transactionsExecuted(bytes32)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transferOwnership = { /** @@ -10233,7 +7784,11 @@ export class ExchangeContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + newOwner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('newOwner', newOwner); const self = (this as any) as ExchangeContract; const encodedData = self._strictEncodeArguments('transferOwnership(address)', [newOwner.toLowerCase()]); @@ -10249,6 +7804,10 @@ export class ExchangeContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferOwnership.callAsync(newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -10262,20 +7821,19 @@ export class ExchangeContract extends BaseContract { awaitTransactionSuccessAsync( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('newOwner', newOwner); const self = (this as any) as ExchangeContract; - const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData); + const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -10304,11 +7862,6 @@ export class ExchangeContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -10366,28 +7919,12 @@ export class ExchangeContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ExchangeContract; - const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ExchangeContract; const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; private readonly _subscriptionManager: SubscriptionManager; diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/forwarder.ts b/packages/abi-gen-wrappers/src/generated-wrappers/forwarder.ts index 64e7d4abd3..fd921962fc 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/forwarder.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/forwarder.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,8 +34,10 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class ForwarderContract extends BaseContract { - public static deployedBytecode = - '0x6080604052600436106100655760003560e01c8063942d33c011610043578063942d33c014610102578063ae93b97a14610124578063f2fde38b1461013757610065565b8063442026ed14610097578063630f1e6c146100b75780638da5cb5b146100d7575b60025473ffffffffffffffffffffffffffffffffffffffff1633146100955761009561009033610157565b6101f6565b005b3480156100a357600080fd5b506100956100b2366004611bc6565b6101fe565b3480156100c357600080fd5b506100956100d2366004611c06565b6104a8565b3480156100e357600080fd5b506100ec6104f1565b6040516100f99190611dc0565b60405180910390f35b610115610110366004611b1d565b61050d565b6040516100f993929190612047565b610115610132366004611aa0565b610542565b34801561014357600080fd5b50610095610152366004611a68565b61059d565b60606308b1869860e01b826040516024016101729190611dc0565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050919050565b805160208201fd5b600061024a600084848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929392505063ffffffff610614169050565b905060405161025890611d97565b60405180910390207bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156104a35760015460405160009173ffffffffffffffffffffffffffffffffffffffff16906360704108906102d490611d97565b6040519081900381207fffffffff0000000000000000000000000000000000000000000000000000000060e084901b16825261031291600401611e5f565b60206040518083038186803b15801561032a57600080fd5b505afa15801561033e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506103629190810190611a84565b905073ffffffffffffffffffffffffffffffffffffffff811661038a5761038a61009061066a565b60006103d6601086868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929392505063ffffffff6106c4169050565b6040517f095ea7b300000000000000000000000000000000000000000000000000000000815290915073ffffffffffffffffffffffffffffffffffffffff82169063095ea7b39061044d9085907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90600401611de1565b602060405180830381600087803b15801561046757600080fd5b505af115801561047b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061049f9190810190611ba6565b5050505b505050565b6104b0610704565b6104a383838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525085925061074d915050565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b600080600061051a610838565b6105258888886108cd565b90935091506105358386866109f0565b9050955095509592505050565b600080600061054f610838565b6000610573670de0b6b3a764000061056d888263ffffffff610b8f16565b34610bb2565b9050610580888289610bdc565b90945092506105908487876109f0565b9150509450945094915050565b6105a5610704565b73ffffffffffffffffffffffffffffffffffffffff81166105d0576105cb610090610d9f565b610611565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83161790555b50565b60008160040183511015610635576106356100906003855185600401610dd6565b5060208183018101519101907fffffffff00000000000000000000000000000000000000000000000000000000165b92915050565b6040805160048152602481019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167ff3b96b8d0000000000000000000000000000000000000000000000000000000017905290565b600081601401835110156106e5576106e56100906004855185601401610dd6565b50016014015173ffffffffffffffffffffffffffffffffffffffff1690565b60005473ffffffffffffffffffffffffffffffffffffffff16331461074b5760005461074b9061009090339073ffffffffffffffffffffffffffffffffffffffff16610e7b565b565b600061075f838263ffffffff61061416565b905060405161076d90611d97565b60405180910390207bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156107c9576107c48383610f1d565b6104a3565b6040516107d590611d45565b60405180910390207bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561082c576107c48383611085565b6104a361009082611152565b346108485761084861009061116d565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b1580156108b257600080fd5b505af11580156108c6573d6000803e3d6000fd5b5050505050565b82516000908190815b8181146109d1578681815181106108e957fe5b6020026020010151608001516000148061091a575086818151811061090a57fe5b602002602001015160a001516000145b15610924576109c9565b6000610936878563ffffffff6111c716565b905060008061096c8a858151811061094a57fe5b602002602001015189868151811061095e57fe5b6020026020010151856111e6565b915091506109928a858151811061097f57fe5b602002602001015161014001518261074d565b6109a2878363ffffffff610b8f16565b96506109b4868263ffffffff610b8f16565b95508886106109c5575050506109d1565b5050505b6001016108d6565b50848210156109e7576109e76100908684611339565b50935093915050565b600066b1a2bc2ec50000831115610a0d57610a0d61009084611356565b34841115610a2257610a226100908534611371565b6000610a34348663ffffffff6111c716565b9050610a4984670de0b6b3a764000087610bb2565b915080821115610a6057610a60610090838361138e565b8015610b87576002546040517f2e1a7d4d00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690632e1a7d4d90610abc908490600401612030565b600060405180830381600087803b158015610ad657600080fd5b505af1158015610aea573d6000803e3d6000fd5b505050506000821115610b3c5760405173ffffffffffffffffffffffffffffffffffffffff84169083156108fc029084906000818181858888f19350505050158015610b3a573d6000803e3d6000fd5b505b6000610b4e828463ffffffff6111c716565b90508015610b8557604051339082156108fc029083906000818181858888f19350505050158015610b83573d6000803e3d6000fd5b505b505b509392505050565b600082820183811015610bab57610bab610090600086866113ab565b9392505050565b6000610bd483610bc8868563ffffffff6113ca16565b9063ffffffff6113fb16565b949350505050565b6000806000855190506000610c97600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16631ce4c78b6040518163ffffffff1660e01b815260040160206040518083038186803b158015610c5257600080fd5b505afa158015610c66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610c8a9190810190611cad565b3a9063ffffffff6113ca16565b905060005b828114610d9457878181518110610caf57fe5b60200260200101516080015160001480610ce05750878181518110610cd057fe5b602002602001015160a001516000145b15610cea57610d8c565b6000610d0c83610d008a8963ffffffff6111c716565b9063ffffffff6111c716565b9050600080610d428b8581518110610d2057fe5b60200260200101518a8681518110610d3457fe5b602002602001015185611425565b91509150610d558b858151811061097f57fe5b610d65888363ffffffff610b8f16565b9750610d77878263ffffffff610b8f16565b9650898810610d8857505050610d94565b5050505b600101610c9c565b505050935093915050565b60408051808201909152600481527fe69edc3e00000000000000000000000000000000000000000000000000000000602082015290565b6060632800659560e01b848484604051602401610df593929190611ec1565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290509392505050565b6060631de45ad160e01b8383604051602401610e98929190611e07565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905092915050565b6000610f3083601063ffffffff6106c416565b9050600060608273ffffffffffffffffffffffffffffffffffffffff16604051610f5990611d6e565b60405180910390203386604051602401610f74929190611de1565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909416939093179092529051610ffd9190611d29565b6000604051808303816000865af19150503d806000811461103a576040519150601f19603f3d011682016040523d82523d6000602084013e61103f565b606091505b50915091508161105557611055610090826114ea565b3d15611074576000915060203d14156110745760206000803e60005191505b816108c6576108c6610090826114ea565b806001146110995761109961009082611505565b60006110ac83601063ffffffff6106c416565b905060006110c184602463ffffffff61152016565b6040517f23b872dd00000000000000000000000000000000000000000000000000000000815290915073ffffffffffffffffffffffffffffffffffffffff8316906323b872dd9061111a90309033908690600401611e2e565b600060405180830381600087803b15801561113457600080fd5b505af1158015611148573d6000803e3d6000fd5b5050505050505050565b6060637996a27160e01b826040516024016101729190611e5f565b6040805160048152602481019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f8c0e562b0000000000000000000000000000000000000000000000000000000017905290565b6000828211156111e0576111e0610090600285856113ab565b50900390565b6000808460e001516000148061121257506101608501516101a08601516112129163ffffffff61152c16565b1561128057600061122c8660a00151876080015186611552565b905061123661172e565b61124187838861157c565b9050611272816080015161126683606001518460200151610b8f90919063ffffffff16565b9063ffffffff610b8f16565b905190935091506113319050565b6101408501516101a086015161129b9163ffffffff61152c16565b156113205760006112cb8660a001516112c58860e0015189608001516111c790919063ffffffff16565b86611552565b90506112d561172e565b6112e087838861157c565b90506112fd81608001518260200151610b8f90919063ffffffff16565b60608201518251919550611317919063ffffffff6111c716565b92505050611331565b611331610090866101a001516116e9565b935093915050565b60606391353a0c60e01b8383604051602401610e98929190612039565b6060631174fb8060e01b826040516024016101729190612030565b606063cdcbed5d60e01b8383604051602401610e98929190612039565b606063ecf40fd960e01b8383604051602401610e98929190612039565b606063e946c1bb60e01b848484604051602401610df593929190611e9f565b6000826113d957506000610664565b828202828482816113e657fe5b0414610bab57610bab610090600186866113ab565b60008161141157611411610090600385856113ab565b600082848161141c57fe5b04949350505050565b6000808460e001516000148061145157506101408501516101a08601516114519163ffffffff61152c16565b156114a85761145e61172e565b61146986858761157c565b905061148681608001518260200151610b8f90919063ffffffff16565b606082015182519194506114a0919063ffffffff6111c716565b915050611331565b6101608501516101a08601516114c39163ffffffff61152c16565b156113205760a085015160e086015160009161122c916112c590829063ffffffff610b8f16565b6060635e7eb60f60e01b826040516024016101729190611e8c565b606063baffa47460e01b826040516024016101729190612030565b6000610bab8383611704565b600081518351148015610bab575081805190602001208380519060200120149392505050565b6000610bd483610bc861156c82600163ffffffff6111c716565b611266888763ffffffff6113ca16565b61158461172e565b6040516060907f9b44d55600000000000000000000000000000000000000000000000000000000906115be90879087908790602401611ecf565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090941693909317909252600154915190925073ffffffffffffffffffffffffffffffffffffffff90911690600090606090839061166f908690611d29565b6000604051808303816000865af19150503d80600081146116ac576040519150601f19603f3d011682016040523d82523d6000602084013e6116b1565b606091505b509150915081156116de57805160a0146116c757fe5b808060200190516116db9190810190611c50565b94505b505050509392505050565b60606331360af160e01b826040516024016101729190611e8c565b60008160200183511015611725576117256100906005855185602001610dd6565b50016020015190565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b8035610664816120d4565b600082601f830112611778578081fd5b813561178b61178682612084565b61205d565b8181529150602080830190840160005b838110156117c8576117b387602084358901016119e1565b8352602092830192919091019060010161179b565b5050505092915050565b600082601f8301126117e2578081fd5b81356117f061178682612084565b818152915060208083019084810160005b8481101561198f57813587016101c0807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0838c0301121561184157600080fd5b61184a8161205d565b6118568b87850161175d565b81526118658b6040850161175d565b868201526118768b6060850161175d565b60408201526118888b6080850161175d565b606082015260a0830135608082015260c083013560a082015260e083013560c08201526101008084013560e0830152610120808501358284015261014091508185013581840152506101608085013567ffffffffffffffff808211156118ed57600080fd5b6118fb8f8b848a01016119e1565b8486015261018093508387013591508082111561191757600080fd5b6119258f8b848a01016119e1565b838601526101a092508287013591508082111561194157600080fd5b61194f8f8b848a01016119e1565b848601528587013593508084111561196657600080fd5b50506119768d89848801016119e1565b9083015250865250509282019290820190600101611801565b505050505092915050565b60008083601f8401126119ab578182fd5b50813567ffffffffffffffff8111156119c2578182fd5b6020830191508360208285010111156119da57600080fd5b9250929050565b600082601f8301126119f1578081fd5b813567ffffffffffffffff811115611a07578182fd5b611a3860207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8401160161205d565b9150808252836020828501011115611a4f57600080fd5b8060208401602084013760009082016020015292915050565b600060208284031215611a79578081fd5b8135610bab816120d4565b600060208284031215611a95578081fd5b8151610bab816120d4565b60008060008060808587031215611ab5578283fd5b843567ffffffffffffffff80821115611acc578485fd5b611ad8888389016117d2565b95506020870135915080821115611aed578485fd5b50611afa87828801611768565b935050604085013591506060850135611b12816120d4565b939692955090935050565b600080600080600060a08688031215611b34578081fd5b853567ffffffffffffffff80821115611b4b578283fd5b611b5789838a016117d2565b9650602088013595506040880135915080821115611b73578283fd5b50611b8088828901611768565b935050606086013591506080860135611b98816120d4565b809150509295509295909350565b600060208284031215611bb7578081fd5b81518015158114610bab578182fd5b60008060208385031215611bd8578182fd5b823567ffffffffffffffff811115611bee578283fd5b611bfa8582860161199a565b90969095509350505050565b600080600060408486031215611c1a578283fd5b833567ffffffffffffffff811115611c30578384fd5b611c3c8682870161199a565b909790965060209590950135949350505050565b600060a0828403128015611c62578182fd5b8015611c6c578182fd5b50611c7760a061205d565b82518152602083015160208201526040830151604082015260608301516060820152608083015160808201528091505092915050565b600060208284031215611cbe578081fd5b5051919050565b73ffffffffffffffffffffffffffffffffffffffff169052565b60008151808452611cf78160208601602086016120a4565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60008251611d3b8184602087016120a4565b9190910192915050565b7f455243373231546f6b656e28616464726573732c75696e7432353629000000008152601c0190565b7f7472616e7366657228616464726573732c75696e743235362900000000000000815260190190565b7f4552433230546f6b656e28616464726573732900000000000000000000000000815260130190565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b7fffffffff0000000000000000000000000000000000000000000000000000000091909116815260200190565b600060208252610bab6020830184611cdf565b6060810160048510611ead57fe5b938152602081019290925260409091015290565b6060810160088510611ead57fe5b600060608252611ee3606083018651611cc5565b6020850151611ef56080840182611cc5565b506040850151611f0860a0840182611cc5565b506060850151611f1b60c0840182611cc5565b50608085015160e083015260a0850151610100818185015260c08701519150610120828186015260e0880151925061014083818701528289015193506101609250838387015281890151935061018091508382870152808901519350506101c06101a08181880152611f91610220880186611cdf565b848b015195507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa09450848882030183890152611fcd8187611cdf565b925050828a0151945083878303016101e0880152611feb8286611cdf565b9250808a015194505050818582030161020086015261200a8184611cdf565b91505085602085015283810360408501526120258186611cdf565b979650505050505050565b90815260200190565b918252602082015260400190565b9283526020830191909152604082015260600190565b60405181810167ffffffffffffffff8111828210171561207c57600080fd5b604052919050565b600067ffffffffffffffff82111561209a578081fd5b5060209081020190565b60005b838110156120bf5781810151838201526020016120a7565b838111156120ce576000848401525b50505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461061157600080fdfea365627a7a72315820afeb88c9cc19090963cb885eb76d709ca1a151f8f73996031898e2b50578a89b6c6578706572696d656e74616cf564736f6c634300050c0040'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; /** * Approves the respective proxy for a given asset to transfer tokens on the Forwarder contract's behalf. * This is necessary because an order fee denominated in the maker asset (i.e. a percentage fee) is sent by the @@ -45,7 +53,11 @@ export class ForwarderContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(assetData: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + assetData: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('assetData', assetData); const self = (this as any) as ForwarderContract; const encodedData = self._strictEncodeArguments('approveMakerAssetProxy(bytes)', [assetData]); @@ -61,6 +73,10 @@ export class ForwarderContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.approveMakerAssetProxy.callAsync(assetData, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -75,20 +91,19 @@ export class ForwarderContract extends BaseContract { awaitTransactionSuccessAsync( assetData: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('assetData', assetData); const self = (this as any) as ForwarderContract; - const txHashPromise = self.approveMakerAssetProxy.sendTransactionAsync(assetData, txData); + const txHashPromise = self.approveMakerAssetProxy.sendTransactionAsync(assetData, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -118,14 +133,6 @@ export class ForwarderContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync( - assetData: string, - txData?: Partial | undefined, - ): Promise { - await (this as any).approveMakerAssetProxy.callAsync(assetData, txData); - const txHash = await (this as any).approveMakerAssetProxy.sendTransactionAsync(assetData, txData); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -183,28 +190,12 @@ export class ForwarderContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ForwarderContract; - const abiEncoder = self._lookupAbiEncoder('approveMakerAssetProxy(bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ForwarderContract; const abiEncoder = self._lookupAbiEncoder('approveMakerAssetProxy(bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -249,6 +240,7 @@ export class ForwarderContract extends BaseContract { feePercentage: BigNumber, feeRecipient: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isBigNumber('makerAssetBuyAmount', makerAssetBuyAmount); @@ -272,6 +264,17 @@ export class ForwarderContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.marketBuyOrdersWithEth.callAsync( + orders, + makerAssetBuyAmount, + signatures, + feePercentage, + feeRecipient, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -311,8 +314,7 @@ export class ForwarderContract extends BaseContract { feePercentage: BigNumber, feeRecipient: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isBigNumber('makerAssetBuyAmount', makerAssetBuyAmount); @@ -327,6 +329,7 @@ export class ForwarderContract extends BaseContract { feePercentage, feeRecipient.toLowerCase(), txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -334,8 +337,8 @@ export class ForwarderContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -400,47 +403,6 @@ export class ForwarderContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - makerAssetBuyAmount: BigNumber, - signatures: string[], - feePercentage: BigNumber, - feeRecipient: string, - txData?: Partial | undefined, - ): Promise { - await (this as any).marketBuyOrdersWithEth.callAsync( - orders, - makerAssetBuyAmount, - signatures, - feePercentage, - feeRecipient, - txData, - ); - const txHash = await (this as any).marketBuyOrdersWithEth.sendTransactionAsync( - orders, - makerAssetBuyAmount, - signatures, - feePercentage, - feeRecipient, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -571,80 +533,14 @@ export class ForwarderContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): [ - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - BigNumber, - string[], - BigNumber, - string - ] { + getSelector(): string { const self = (this as any) as ForwarderContract; const abiEncoder = self._lookupAbiEncoder( 'marketBuyOrdersWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[],uint256,address)', ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [ - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - BigNumber, - string[], - BigNumber, - string - ] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [BigNumber, BigNumber, BigNumber] { - const self = (this as any) as ForwarderContract; - const abiEncoder = self._lookupAbiEncoder( - 'marketBuyOrdersWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[],uint256,address)', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[BigNumber, BigNumber, BigNumber]>( - returnData, - ); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -685,6 +581,7 @@ export class ForwarderContract extends BaseContract { feePercentage: BigNumber, feeRecipient: string, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isArray('orders', orders); assert.isArray('signatures', signatures); @@ -707,6 +604,16 @@ export class ForwarderContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.marketSellOrdersWithEth.callAsync( + orders, + signatures, + feePercentage, + feeRecipient, + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -744,8 +651,7 @@ export class ForwarderContract extends BaseContract { feePercentage: BigNumber, feeRecipient: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isArray('orders', orders); assert.isArray('signatures', signatures); @@ -758,6 +664,7 @@ export class ForwarderContract extends BaseContract { feePercentage, feeRecipient.toLowerCase(), txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -765,8 +672,8 @@ export class ForwarderContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -828,44 +735,6 @@ export class ForwarderContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - signatures: string[], - feePercentage: BigNumber, - feeRecipient: string, - txData?: Partial | undefined, - ): Promise { - await (this as any).marketSellOrdersWithEth.callAsync( - orders, - signatures, - feePercentage, - feeRecipient, - txData, - ); - const txHash = await (this as any).marketSellOrdersWithEth.sendTransactionAsync( - orders, - signatures, - feePercentage, - feeRecipient, - txData, - ); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -990,78 +859,14 @@ export class ForwarderContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData( - callData: string, - ): [ - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - string[], - BigNumber, - string - ] { - const self = (this as any) as ForwarderContract; - const abiEncoder = self._lookupAbiEncoder( - 'marketSellOrdersWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],uint256,address)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [ - 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; - makerFeeAssetData: string; - takerFeeAssetData: string; - }>, - string[], - BigNumber, - string - ] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [BigNumber, BigNumber, BigNumber] { + getSelector(): string { const self = (this as any) as ForwarderContract; const abiEncoder = self._lookupAbiEncoder( 'marketSellOrdersWithEth((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],uint256,address)', ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[BigNumber, BigNumber, BigNumber]>( - returnData, - ); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public owner = { @@ -1106,41 +911,6 @@ export class ForwarderContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ForwarderContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owner()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ForwarderContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ForwarderContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transferOwnership = { /** @@ -1149,7 +919,11 @@ export class ForwarderContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + newOwner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('newOwner', newOwner); const self = (this as any) as ForwarderContract; const encodedData = self._strictEncodeArguments('transferOwnership(address)', [newOwner.toLowerCase()]); @@ -1165,6 +939,10 @@ export class ForwarderContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferOwnership.callAsync(newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1178,20 +956,19 @@ export class ForwarderContract extends BaseContract { awaitTransactionSuccessAsync( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('newOwner', newOwner); const self = (this as any) as ForwarderContract; - const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData); + const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1220,11 +997,6 @@ export class ForwarderContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1282,28 +1054,12 @@ export class ForwarderContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as ForwarderContract; - const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ForwarderContract; const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1324,6 +1080,7 @@ export class ForwarderContract extends BaseContract { assetData: string, amount: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('assetData', assetData); assert.isBigNumber('amount', amount); @@ -1341,6 +1098,10 @@ export class ForwarderContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.withdrawAsset.callAsync(assetData, amount, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1357,21 +1118,20 @@ export class ForwarderContract extends BaseContract { assetData: string, amount: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('assetData', assetData); assert.isBigNumber('amount', amount); const self = (this as any) as ForwarderContract; - const txHashPromise = self.withdrawAsset.sendTransactionAsync(assetData, amount, txData); + const txHashPromise = self.withdrawAsset.sendTransactionAsync(assetData, amount, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1407,15 +1167,6 @@ export class ForwarderContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1485,28 +1236,12 @@ export class ForwarderContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { - const self = (this as any) as ForwarderContract; - const abiEncoder = self._lookupAbiEncoder('withdrawAsset(bytes,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as ForwarderContract; const abiEncoder = self._lookupAbiEncoder('withdrawAsset(bytes,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public static async deployFrom0xArtifactAsync( diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/i_asset_proxy.ts b/packages/abi-gen-wrappers/src/generated-wrappers/i_asset_proxy.ts index 4a91819df5..1862f8c11a 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/i_asset_proxy.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/i_asset_proxy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class IAssetProxyContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode: string | undefined; /** * Transfers assets. Either succeeds or throws. @@ -49,6 +58,7 @@ export class IAssetProxyContract extends BaseContract { to: string, amount: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('assetData', assetData); assert.isString('from', from); @@ -73,6 +83,10 @@ export class IAssetProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferFrom.callAsync(assetData, from, to, amount, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -93,8 +107,7 @@ export class IAssetProxyContract extends BaseContract { to: string, amount: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('assetData', assetData); assert.isString('from', from); @@ -107,6 +120,7 @@ export class IAssetProxyContract extends BaseContract { to.toLowerCase(), amount, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -114,8 +128,8 @@ export class IAssetProxyContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -162,17 +176,6 @@ export class IAssetProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -257,28 +260,12 @@ export class IAssetProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string, string, BigNumber] { - const self = (this as any) as IAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as IAssetProxyContract; const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -306,7 +293,7 @@ export class IAssetProxyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -319,41 +306,6 @@ export class IAssetProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as IAssetProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getProxyId()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as IAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as IAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/i_validator.ts b/packages/abi-gen-wrappers/src/generated-wrappers/i_validator.ts index d1cd5b401b..1f97f3f316 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/i_validator.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/i_validator.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class IValidatorContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode: string | undefined; /** * Verifies that a signature is valid. @@ -91,51 +100,6 @@ export class IValidatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param hash Message hash that is signed. - * @param signerAddress Address that should have signed the given hash. - * @param signature Proof of signing. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(hash: string, signerAddress: string, signature: string): string { - assert.isString('hash', hash); - assert.isString('signerAddress', signerAddress); - assert.isString('signature', signature); - const self = (this as any) as IValidatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments('isValidSignature(bytes32,address,bytes)', [ - hash, - signerAddress.toLowerCase(), - signature, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as IValidatorContract; - const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as IValidatorContract; - const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/i_wallet.ts b/packages/abi-gen-wrappers/src/generated-wrappers/i_wallet.ts index 9c8399f017..000d0798b6 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/i_wallet.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/i_wallet.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class IWalletContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode: string | undefined; /** * Validates a hash with the `Wallet` signature type. @@ -84,48 +93,6 @@ export class IWalletContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param hash Message hash that is signed. - * @param signature Proof of signing. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(hash: string, signature: string): string { - assert.isString('hash', hash); - assert.isString('signature', signature); - const self = (this as any) as IWalletContract; - const abiEncodedTransactionData = self._strictEncodeArguments('isValidSignature(bytes32,bytes)', [ - hash, - signature, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as IWalletContract; - const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as IWalletContract; - const abiEncoder = self._lookupAbiEncoder('isValidSignature(bytes32,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/multi_asset_proxy.ts b/packages/abi-gen-wrappers/src/generated-wrappers/multi_asset_proxy.ts index ddac12e1de..752c5eba6e 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/multi_asset_proxy.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/multi_asset_proxy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -55,6 +61,9 @@ export interface MultiAssetProxyAssetProxyRegisteredEventArgs extends DecodedLog // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class MultiAssetProxyContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode = '0x608060405234801561001057600080fd5b50600436106100d45760003560e01c80639ad2674411610081578063c585bb931161005b578063c585bb9314610789578063d39de6e9146107bc578063f2fde38b14610814576100d4565b80639ad26744146106cc578063ae25532e14610705578063b918161114610742576100d4565b806360704108116100b2578063607041081461065257806370712939146106915780638da5cb5b146106c4576100d4565b80633fd3c9971461059857806342f1181e14610600578063494503d414610635575b7fffffffff00000000000000000000000000000000000000000000000000000000600035167fa85e59e400000000000000000000000000000000000000000000000000000000811415610592573360005260026020526040600020546101a5577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c1553454e4445525f4e4f545f415554484f52495a454400000000000000604052600060605260646000fd5b600480350180356020600482030660448210171561022e577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c19494e56414c49445f41535345545f444154415f4c454e475448000000604052600060605260646000fd5b602081018201368111156102ad577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c16494e56414c49445f41535345545f444154415f454e44000000000000604052600060605260646000fd5b5050602481013560448201356044820183016020810335925060448201840160208103358085031561034a577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c0f4c454e4754485f4d49534d4154434800000000000000000000000000604052600060605260646000fd5b5060646000803760806004526000936064359060200285805b82811015610587578086013584810281868204148615176103ef577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c1055494e543235365f4f564552464c4f57000000000000000000000000604052600060605260646000fd5b60649081528287013589018b01604481019250018135600481101561049e577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c1e4c454e4754485f475245415445525f5448414e5f335f5245515549526040527f454400000000000000000000000000000000000000000000000000000000000060605260646000fd5b7fffffffff000000000000000000000000000000000000000000000000000000008235168b8103156104df57809b508b608452600160a45260406084205495505b5084610556577f08c379a0000000000000000000000000000000000000000000000000000000006000527c20000000000000000000000000000000000000000000000000000000006020527c1a41535345545f50524f58595f444f45535f4e4f545f45584953540000604052600060605260646000fd5b60208101836084376000808260a401600080895af1925050508061057e573d6000803e3d6000fd5b50602001610363565b505050505050505050005b50600080fd5b6105d7600480360360208110156105ae57600080fd5b50357fffffffff0000000000000000000000000000000000000000000000000000000016610847565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6106336004803603602081101561061657600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1661086f565b005b6105d76004803603602081101561064b57600080fd5b5035610a5b565b6105d76004803603602081101561066857600080fd5b50357fffffffff0000000000000000000000000000000000000000000000000000000016610a8f565b610633600480360360208110156106a757600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610ad9565b6105d7610dcc565b610633600480360360408110156106e257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610de8565b61070d611199565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b6107756004803603602081101561075857600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166111cf565b604080519115158252519081900360200190f35b6106336004803603602081101561079f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166111e4565b6107c4611446565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156108005781810151838201526020016107e8565b505050509050019250505060405180910390f35b6106336004803603602081101561082a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166114b5565b60016020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b60005473ffffffffffffffffffffffffffffffffffffffff1633146108f557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660009081526002602052604090205460ff161561098a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f5441524745545f414c52454144595f415554484f52495a454400000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660008181526002602052604080822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600190811790915560038054918201815583527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001684179055513392917f3147867c59d17e8fa9d522465651d44aae0a9e38f902f3475b97e58072f0ed4c91a350565b60038181548110610a6857fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b7fffffffff000000000000000000000000000000000000000000000000000000001660009081526001602052604090205473ffffffffffffffffffffffffffffffffffffffff1690565b60005473ffffffffffffffffffffffffffffffffffffffff163314610b5f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811660009081526002602052604090205460ff16610bf357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5441524745545f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8116600090815260026020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b600354811015610d85578173ffffffffffffffffffffffffffffffffffffffff1660038281548110610c6d57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff161415610d7d57600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101908110610cc557fe5b6000918252602090912001546003805473ffffffffffffffffffffffffffffffffffffffff9092169183908110610cf857fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190610d77908261159b565b50610d85565b600101610c3f565b50604051339073ffffffffffffffffffffffffffffffffffffffff8316907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a350565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b60005473ffffffffffffffffffffffffffffffffffffffff163314610e6e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff821660009081526002602052604090205460ff16610f0257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5441524745545f4e4f545f415554484f52495a45440000000000000000000000604482015290519081900360640190fd5b6003548110610f7257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f494e4445585f4f55545f4f465f424f554e445300000000000000000000000000604482015290519081900360640190fd5b8173ffffffffffffffffffffffffffffffffffffffff1660038281548110610f9657fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff161461102457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f415554484f52495a45445f414444524553535f4d49534d415443480000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8216600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811061109f57fe5b6000918252602090912001546003805473ffffffffffffffffffffffffffffffffffffffff90921691839081106110d257fe5b600091825260209091200180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190611151908261159b565b50604051339073ffffffffffffffffffffffffffffffffffffffff8416907f1f32c1b084e2de0713b8fb16bd46bb9df710a3dbeae2f3ca93af46e016dcc6b090600090a35050565b604080517f4d756c746941737365742875696e743235365b5d2c62797465735b5d290000008152905190819003601d0190205b90565b60026020526000908152604090205460ff1681565b60005473ffffffffffffffffffffffffffffffffffffffff16331461126a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b60008173ffffffffffffffffffffffffffffffffffffffff1663ae25532e6040518163ffffffff1660e01b815260040160206040518083038186803b1580156112b257600080fd5b505afa1580156112c6573d6000803e3d6000fd5b505050506040513d60208110156112dc57600080fd5b50517fffffffff00000000000000000000000000000000000000000000000000000000811660009081526001602052604090205490915073ffffffffffffffffffffffffffffffffffffffff16801561139657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f41535345545f50524f58595f414c52454144595f455849535453000000000000604482015290519081900360640190fd5b7fffffffff00000000000000000000000000000000000000000000000000000000821660008181526001602090815260409182902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff881690811790915582519384529083015280517fd2c6b762299c609bdb96520b58a49bfb80186934d4f71a86a367571a15c031949281900390910190a1505050565b606060038054806020026020016040519081016040528092919081815260200182805480156114ab57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311611480575b5050505050905090565b60005473ffffffffffffffffffffffffffffffffffffffff16331461153b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4f4e4c595f434f4e54524143545f4f574e455200000000000000000000000000604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff81161561159857600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83161790555b50565b8154818355818111156115bf576000838152602090206115bf9181019083016115c4565b505050565b6111cc91905b808211156115de57600081556001016115ca565b509056fea265627a7a72315820ff218c9e47c47135d1028b03281d63826ba3569217fc501ee67c0661fa98fc5164736f6c634300050b0032'; public assetProxies = { @@ -100,42 +109,6 @@ export class MultiAssetProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as MultiAssetProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('assetProxies(bytes4)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('assetProxies(bytes4)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('assetProxies(bytes4)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Authorizes an address. @@ -148,7 +121,11 @@ export class MultiAssetProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + target: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('target', target); const self = (this as any) as MultiAssetProxyContract; const encodedData = self._strictEncodeArguments('addAuthorizedAddress(address)', [target.toLowerCase()]); @@ -164,6 +141,10 @@ export class MultiAssetProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.addAuthorizedAddress.callAsync(target, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -178,20 +159,19 @@ export class MultiAssetProxyContract extends BaseContract { awaitTransactionSuccessAsync( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); const self = (this as any) as MultiAssetProxyContract; - const txHashPromise = self.addAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData); + const txHashPromise = self.addAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -221,11 +201,6 @@ export class MultiAssetProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -285,28 +260,12 @@ export class MultiAssetProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as MultiAssetProxyContract; const abiEncoder = self._lookupAbiEncoder('addAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('addAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public authorities = { @@ -356,42 +315,6 @@ export class MultiAssetProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: BigNumber): string { - assert.isBigNumber('index_0', index_0); - const self = (this as any) as MultiAssetProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('authorities(uint256)', [index_0]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): BigNumber { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorities(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorities(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Gets an asset proxy. @@ -445,43 +368,6 @@ export class MultiAssetProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param assetProxyId Id of the asset proxy. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(assetProxyId: string): string { - assert.isString('assetProxyId', assetProxyId); - const self = (this as any) as MultiAssetProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getAssetProxy(bytes4)', [assetProxyId]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAssetProxy(bytes4)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAssetProxy(bytes4)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Removes authorizion of an address. @@ -494,7 +380,11 @@ export class MultiAssetProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(target: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + target: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('target', target); const self = (this as any) as MultiAssetProxyContract; const encodedData = self._strictEncodeArguments('removeAuthorizedAddress(address)', [target.toLowerCase()]); @@ -510,6 +400,10 @@ export class MultiAssetProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeAuthorizedAddress.callAsync(target, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -524,20 +418,19 @@ export class MultiAssetProxyContract extends BaseContract { awaitTransactionSuccessAsync( target: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); const self = (this as any) as MultiAssetProxyContract; - const txHashPromise = self.removeAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData); + const txHashPromise = self.removeAuthorizedAddress.sendTransactionAsync(target.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -567,11 +460,6 @@ export class MultiAssetProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -631,28 +519,12 @@ export class MultiAssetProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as MultiAssetProxyContract; const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddress(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public owner = { @@ -697,41 +569,6 @@ export class MultiAssetProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('owner()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('owner()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Removes authorizion of an address. @@ -749,6 +586,7 @@ export class MultiAssetProxyContract extends BaseContract { target: string, index: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('target', target); assert.isBigNumber('index', index); @@ -769,6 +607,10 @@ export class MultiAssetProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.removeAuthorizedAddressAtIndex.callAsync(target, index, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -785,8 +627,7 @@ export class MultiAssetProxyContract extends BaseContract { target: string, index: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('target', target); assert.isBigNumber('index', index); @@ -795,6 +636,7 @@ export class MultiAssetProxyContract extends BaseContract { target.toLowerCase(), index, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -802,8 +644,8 @@ export class MultiAssetProxyContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -842,19 +684,6 @@ export class MultiAssetProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -927,28 +756,12 @@ export class MultiAssetProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, BigNumber] { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddressAtIndex(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as MultiAssetProxyContract; const abiEncoder = self._lookupAbiEncoder('removeAuthorizedAddressAtIndex(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -976,7 +789,7 @@ export class MultiAssetProxyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -989,41 +802,6 @@ export class MultiAssetProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getProxyId()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public authorized = { /** @@ -1072,44 +850,6 @@ export class MultiAssetProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as MultiAssetProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('authorized(address)', [ - index_0.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorized(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('authorized(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Registers an asset proxy to its asset proxy id. @@ -1123,7 +863,11 @@ export class MultiAssetProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(assetProxy: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + assetProxy: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('assetProxy', assetProxy); const self = (this as any) as MultiAssetProxyContract; const encodedData = self._strictEncodeArguments('registerAssetProxy(address)', [assetProxy.toLowerCase()]); @@ -1139,6 +883,10 @@ export class MultiAssetProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.registerAssetProxy.callAsync(assetProxy, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1153,20 +901,19 @@ export class MultiAssetProxyContract extends BaseContract { awaitTransactionSuccessAsync( assetProxy: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('assetProxy', assetProxy); const self = (this as any) as MultiAssetProxyContract; - const txHashPromise = self.registerAssetProxy.sendTransactionAsync(assetProxy.toLowerCase(), txData); + const txHashPromise = self.registerAssetProxy.sendTransactionAsync(assetProxy.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1196,14 +943,6 @@ export class MultiAssetProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1267,28 +1006,12 @@ export class MultiAssetProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string] { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('registerAssetProxy(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as MultiAssetProxyContract; const abiEncoder = self._lookupAbiEncoder('registerAssetProxy(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; /** @@ -1337,41 +1060,6 @@ export class MultiAssetProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as MultiAssetProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getAuthorizedAddresses()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAuthorizedAddresses()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string[] { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('getAuthorizedAddresses()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transferOwnership = { /** @@ -1380,7 +1068,11 @@ export class MultiAssetProxyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(newOwner: string, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + newOwner: string, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('newOwner', newOwner); const self = (this as any) as MultiAssetProxyContract; const encodedData = self._strictEncodeArguments('transferOwnership(address)', [newOwner.toLowerCase()]); @@ -1396,6 +1088,10 @@ export class MultiAssetProxyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferOwnership.callAsync(newOwner, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1409,20 +1105,19 @@ export class MultiAssetProxyContract extends BaseContract { awaitTransactionSuccessAsync( newOwner: string, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('newOwner', newOwner); const self = (this as any) as MultiAssetProxyContract; - const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData); + const txHashPromise = self.transferOwnership.sendTransactionAsync(newOwner.toLowerCase(), txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1451,11 +1146,6 @@ export class MultiAssetProxyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1513,28 +1203,12 @@ export class MultiAssetProxyContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): [string] { + getSelector(): string { const self = (this as any) as MultiAssetProxyContract; const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as MultiAssetProxyContract; - const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; private readonly _subscriptionManager: SubscriptionManager; diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/order_validator.ts b/packages/abi-gen-wrappers/src/generated-wrappers/order_validator.ts index de5099cd21..aadf482932 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/order_validator.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/order_validator.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class OrderValidatorContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode: string | undefined; public getOrderAndTraderInfo = { /** @@ -123,129 +132,6 @@ export class OrderValidatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - 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; - }, - takerAddress: string, - ): string { - assert.isString('takerAddress', takerAddress); - const self = (this as any) as OrderValidatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getOrderAndTraderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),address)', - [order, takerAddress.toLowerCase()], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): [ - { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - }, - string - ] { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrderAndTraderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),address)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [ - { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - }, - string - ] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): [ - { orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }, - { - makerBalance: BigNumber; - makerAllowance: BigNumber; - takerBalance: BigNumber; - takerAllowance: BigNumber; - makerZrxBalance: BigNumber; - makerZrxAllowance: BigNumber; - takerZrxBalance: BigNumber; - takerZrxAllowance: BigNumber; - } - ] { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrderAndTraderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),address)', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - [ - { orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }, - { - makerBalance: BigNumber; - makerAllowance: BigNumber; - takerBalance: BigNumber; - takerAllowance: BigNumber; - makerZrxBalance: BigNumber; - makerZrxAllowance: BigNumber; - takerZrxBalance: BigNumber; - takerZrxAllowance: BigNumber; - } - ] - >(returnData); - return abiDecodedReturnData; - }, }; public getBalanceAndAllowance = { /** @@ -299,46 +185,6 @@ export class OrderValidatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(target: string, assetData: string): string { - assert.isString('target', target); - assert.isString('assetData', assetData); - const self = (this as any) as OrderValidatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getBalanceAndAllowance(address,bytes)', [ - target.toLowerCase(), - assetData, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string] { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder('getBalanceAndAllowance(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [BigNumber, BigNumber] { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder('getBalanceAndAllowance(address,bytes)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[BigNumber, BigNumber]>(returnData); - return abiDecodedReturnData; - }, }; public getOrdersAndTradersInfo = { /** @@ -435,130 +281,6 @@ export class OrderValidatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - 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; - }>, - takerAddresses: string[], - ): string { - assert.isArray('orders', orders); - assert.isArray('takerAddresses', takerAddresses); - const self = (this as any) as OrderValidatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getOrdersAndTradersInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[],address[])', - [orders, takerAddresses], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): [ - 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; - }>, - string[] - ] { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrdersAndTradersInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[],address[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - [ - 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; - }>, - string[] - ] - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): [ - Array<{ orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }>, - Array<{ - makerBalance: BigNumber; - makerAllowance: BigNumber; - takerBalance: BigNumber; - takerAllowance: BigNumber; - makerZrxBalance: BigNumber; - makerZrxAllowance: BigNumber; - takerZrxBalance: BigNumber; - takerZrxAllowance: BigNumber; - }> - ] { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'getOrdersAndTradersInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[],address[])', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - [ - Array<{ orderStatus: number; orderHash: string; orderTakerAssetFilledAmount: BigNumber }>, - Array<{ - makerBalance: BigNumber; - makerAllowance: BigNumber; - takerBalance: BigNumber; - takerAllowance: BigNumber; - makerZrxBalance: BigNumber; - makerZrxAllowance: BigNumber; - takerZrxBalance: BigNumber; - takerZrxAllowance: BigNumber; - }> - ] - >(returnData); - return abiDecodedReturnData; - }, }; public getTradersInfo = { /** @@ -649,118 +371,6 @@ export class OrderValidatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - 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; - }>, - takerAddresses: string[], - ): string { - assert.isArray('orders', orders); - assert.isArray('takerAddresses', takerAddresses); - const self = (this as any) as OrderValidatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getTradersInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[],address[])', - [orders, takerAddresses], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): 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; - }> { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'getTradersInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[],address[])', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode< - 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; - }> - >(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): Array<{ - makerBalance: BigNumber; - makerAllowance: BigNumber; - takerBalance: BigNumber; - takerAllowance: BigNumber; - makerZrxBalance: BigNumber; - makerZrxAllowance: BigNumber; - takerZrxBalance: BigNumber; - takerZrxAllowance: BigNumber; - }> { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'getTradersInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes)[],address[])', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue< - Array<{ - makerBalance: BigNumber; - makerAllowance: BigNumber; - takerBalance: BigNumber; - takerAllowance: BigNumber; - makerZrxBalance: BigNumber; - makerZrxAllowance: BigNumber; - takerZrxBalance: BigNumber; - takerZrxAllowance: BigNumber; - }> - >(returnData); - return abiDecodedReturnData; - }, }; public getERC721TokenOwner = { /** @@ -814,46 +424,6 @@ export class OrderValidatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(token: string, tokenId: BigNumber): string { - assert.isString('token', token); - assert.isBigNumber('tokenId', tokenId); - const self = (this as any) as OrderValidatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getERC721TokenOwner(address,uint256)', [ - token.toLowerCase(), - tokenId, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder('getERC721TokenOwner(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder('getERC721TokenOwner(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public getBalancesAndAllowances = { /** @@ -907,46 +477,6 @@ export class OrderValidatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(target: string, assetData: string[]): string { - assert.isString('target', target); - assert.isArray('assetData', assetData); - const self = (this as any) as OrderValidatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getBalancesAndAllowances(address,bytes[])', [ - target.toLowerCase(), - assetData, - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string[]] { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder('getBalancesAndAllowances(address,bytes[])'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string[]]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): [BigNumber[], BigNumber[]] { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder('getBalancesAndAllowances(address,bytes[])'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[BigNumber[], BigNumber[]]>(returnData); - return abiDecodedReturnData; - }, }; public getTraderInfo = { /** @@ -1032,113 +562,6 @@ export class OrderValidatorContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData( - 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; - }, - takerAddress: string, - ): string { - assert.isString('takerAddress', takerAddress); - const self = (this as any) as OrderValidatorContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'getTraderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),address)', - [order, takerAddress.toLowerCase()], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData( - callData: string, - ): { - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - } { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'getTraderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),address)', - ); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<{ - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - senderAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; - }>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData( - returnData: string, - ): { - makerBalance: BigNumber; - makerAllowance: BigNumber; - takerBalance: BigNumber; - takerAllowance: BigNumber; - makerZrxBalance: BigNumber; - makerZrxAllowance: BigNumber; - takerZrxBalance: BigNumber; - takerZrxAllowance: BigNumber; - } { - const self = (this as any) as OrderValidatorContract; - const abiEncoder = self._lookupAbiEncoder( - 'getTraderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes),address)', - ); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ - makerBalance: BigNumber; - makerAllowance: BigNumber; - takerBalance: BigNumber; - takerAllowance: BigNumber; - makerZrxBalance: BigNumber; - makerZrxAllowance: BigNumber; - takerZrxBalance: BigNumber; - takerZrxAllowance: BigNumber; - }>(returnData); - return abiDecodedReturnData; - }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/static_call_proxy.ts b/packages/abi-gen-wrappers/src/generated-wrappers/static_call_proxy.ts index 954be6b254..c75c4d2457 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/static_call_proxy.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/static_call_proxy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class StaticCallProxyContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode = '0x608060405234801561001057600080fd5b50600436106100365760003560e01c8063a85e59e41461003b578063ae25532e146100d3575b600080fd5b6100d16004803603608081101561005157600080fd5b81019060208101813564010000000081111561006c57600080fd5b82018360208201111561007e57600080fd5b803590602001918460018302840111640100000000831117156100a057600080fd5b919350915073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610110565b005b6100db6103a5565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b6000606060006101656004898990508a8a8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092949392505063ffffffff6103c5169050565b806020019051606081101561017957600080fd5b8151602083018051604051929492938301929190846401000000008211156101a057600080fd5b9083019060208201858111156101b557600080fd5b82516401000000008111828201881017156101cf57600080fd5b82525081516020918201929091019080838360005b838110156101fc5781810151838201526020016101e4565b50505050905090810190601f1680156102295780820380516001836020036101000a031916815260200191505b5060405260200180519060200190929190505050925092509250600060608473ffffffffffffffffffffffffffffffffffffffff16846040518082805190602001908083835b602083106102ac57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161026f565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855afa9150503d806000811461030c576040519150601f19603f3d011682016040523d82523d6000602084013e610311565b606091505b50915091508161032357805160208201fd5b8051602082012083811461039857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f554e45585045435445445f5354415449435f43414c4c5f524553554c54000000604482015290519081900360640190fd5b5050505050505050505050565b600060405180806104b06021913960210190506040518091039020905090565b6060818311156103e3576103e36103de60008585610408565b6104a7565b83518211156103fc576103fc6103de6001848751610408565b50819003910190815290565b6060632800659560e01b8484846040516024018084600781111561042857fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090509392505050565b805160208201fdfe53746174696343616c6c28616464726573732c62797465732c6279746573333229a265627a7a72315820c55cf13cfcaaf322238d786911313ce7d45854692241ae9b56709bdbfed4f54c64736f6c634300050b0032'; /** @@ -96,53 +105,6 @@ export class StaticCallProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @param assetData Byte array encoded with staticCallTarget, staticCallData, - * and expectedCallResultHash - * @param from This value is ignored. - * @param to This value is ignored. - * @param amount This value is ignored. - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(assetData: string, from: string, to: string, amount: BigNumber): string { - assert.isString('assetData', assetData); - assert.isString('from', from); - assert.isString('to', to); - assert.isBigNumber('amount', amount); - const self = (this as any) as StaticCallProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments( - 'transferFrom(bytes,address,address,uint256)', - [assetData, from.toLowerCase(), to.toLowerCase(), amount], - ); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [string, string, string, BigNumber] { - const self = (this as any) as StaticCallProxyContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[string, string, string, BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): void { - const self = (this as any) as StaticCallProxyContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(bytes,address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * Gets the proxy id associated with the proxy address. @@ -169,7 +131,7 @@ export class StaticCallProxyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -182,41 +144,6 @@ export class StaticCallProxyContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as StaticCallProxyContract; - const abiEncodedTransactionData = self._strictEncodeArguments('getProxyId()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as StaticCallProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as StaticCallProxyContract; - const abiEncoder = self._lookupAbiEncoder('getProxyId()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/weth9.ts b/packages/abi-gen-wrappers/src/generated-wrappers/weth9.ts index 699f18d94c..ee4032ab99 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/weth9.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/weth9.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -64,8 +70,10 @@ export interface WETH9WithdrawalEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class WETH9Contract extends BaseContract { - public static deployedBytecode = - '0x6080604052600436106100925760003560e01c63ffffffff16806306fdde031461009c578063095ea7b31461012657806318160ddd1461016b57806323b872dd146101925780632e1a7d4d146101c9578063313ce567146101e157806370a082311461020c57806395d89b411461023a578063a9059cbb1461024f578063d0e30db014610092578063dd62ed3e14610280575b61009a6102b4565b005b3480156100a857600080fd5b506100b1610303565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100eb5781810151838201526020016100d3565b50505050905090810190601f1680156101185780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561013257600080fd5b5061015773ffffffffffffffffffffffffffffffffffffffff600435166024356103af565b604080519115158252519081900360200190f35b34801561017757600080fd5b50610180610422565b60408051918252519081900360200190f35b34801561019e57600080fd5b5061015773ffffffffffffffffffffffffffffffffffffffff60043581169060243516604435610427565b3480156101d557600080fd5b5061009a6004356105c7565b3480156101ed57600080fd5b506101f661065c565b6040805160ff9092168252519081900360200190f35b34801561021857600080fd5b5061018073ffffffffffffffffffffffffffffffffffffffff60043516610665565b34801561024657600080fd5b506100b1610677565b34801561025b57600080fd5b5061015773ffffffffffffffffffffffffffffffffffffffff600435166024356106ef565b34801561028c57600080fd5b5061018073ffffffffffffffffffffffffffffffffffffffff60043581169060243516610703565b33600081815260036020908152604091829020805434908101909155825190815291517fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9281900390910190a2565b6000805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156103a75780601f1061037c576101008083540402835291602001916103a7565b820191906000526020600020905b81548152906001019060200180831161038a57829003601f168201915b505050505081565b33600081815260046020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b303190565b73ffffffffffffffffffffffffffffffffffffffff831660009081526003602052604081205482111561045957600080fd5b73ffffffffffffffffffffffffffffffffffffffff841633148015906104cf575073ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14155b156105495773ffffffffffffffffffffffffffffffffffffffff8416600090815260046020908152604080832033845290915290205482111561051157600080fd5b73ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020805483900390555b73ffffffffffffffffffffffffffffffffffffffff808516600081815260036020908152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b336000908152600360205260409020548111156105e357600080fd5b33600081815260036020526040808220805485900390555183156108fc0291849190818181858888f19350505050158015610622573d6000803e3d6000fd5b5060408051828152905133917f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65919081900360200190a250565b60025460ff1681565b60036020526000908152604090205481565b60018054604080516020600284861615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156103a75780601f1061037c576101008083540402835291602001916103a7565b60006106fc338484610427565b9392505050565b6004602090815260009283526040808420909152908252902054815600a165627a7a723058201ebe888a6b56dd871f599adbe0f19ec3c29c28aec0685788dfac9b37a99fc9d20029'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; public name = { /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an @@ -108,41 +116,6 @@ export class WETH9Contract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as WETH9Contract; - const abiEncodedTransactionData = self._strictEncodeArguments('name()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('name()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('name()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public approve = { /** @@ -151,7 +124,12 @@ export class WETH9Contract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(guy: string, wad: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + guy: string, + wad: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('guy', guy); assert.isBigNumber('wad', wad); const self = (this as any) as WETH9Contract; @@ -168,6 +146,10 @@ export class WETH9Contract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.approve.callAsync(guy, wad, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -182,21 +164,20 @@ export class WETH9Contract extends BaseContract { guy: string, wad: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('guy', guy); assert.isBigNumber('wad', wad); const self = (this as any) as WETH9Contract; - const txHashPromise = self.approve.sendTransactionAsync(guy.toLowerCase(), wad, txData); + const txHashPromise = self.approve.sendTransactionAsync(guy.toLowerCase(), wad, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -226,15 +207,6 @@ export class WETH9Contract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -300,28 +272,12 @@ export class WETH9Contract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): boolean { + getSelector(): string { const self = (this as any) as WETH9Contract; const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public totalSupply = { @@ -366,41 +322,6 @@ export class WETH9Contract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as WETH9Contract; - const abiEncodedTransactionData = self._strictEncodeArguments('totalSupply()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('totalSupply()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('totalSupply()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transferFrom = { /** @@ -414,6 +335,7 @@ export class WETH9Contract extends BaseContract { dst: string, wad: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('src', src); assert.isString('dst', dst); @@ -436,6 +358,10 @@ export class WETH9Contract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferFrom.callAsync(src, dst, wad, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -451,8 +377,7 @@ export class WETH9Contract extends BaseContract { dst: string, wad: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('src', src); assert.isString('dst', dst); @@ -463,6 +388,7 @@ export class WETH9Contract extends BaseContract { dst.toLowerCase(), wad, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -470,8 +396,8 @@ export class WETH9Contract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -511,16 +437,6 @@ export class WETH9Contract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -594,28 +510,12 @@ export class WETH9Contract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): boolean { + getSelector(): string { const self = (this as any) as WETH9Contract; const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public withdraw = { @@ -625,7 +525,11 @@ export class WETH9Contract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(wad: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + wad: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isBigNumber('wad', wad); const self = (this as any) as WETH9Contract; const encodedData = self._strictEncodeArguments('withdraw(uint256)', [wad]); @@ -641,6 +545,10 @@ export class WETH9Contract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.withdraw.callAsync(wad, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -654,20 +562,19 @@ export class WETH9Contract extends BaseContract { awaitTransactionSuccessAsync( wad: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('wad', wad); const self = (this as any) as WETH9Contract; - const txHashPromise = self.withdraw.sendTransactionAsync(wad, txData); + const txHashPromise = self.withdraw.sendTransactionAsync(wad, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -696,11 +603,6 @@ export class WETH9Contract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -756,28 +658,12 @@ export class WETH9Contract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): [BigNumber] { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('withdraw(uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber]>(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as WETH9Contract; const abiEncoder = self._lookupAbiEncoder('withdraw(uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public decimals = { @@ -822,41 +708,6 @@ export class WETH9Contract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as WETH9Contract; - const abiEncodedTransactionData = self._strictEncodeArguments('decimals()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('decimals()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): number { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('decimals()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public balanceOf = { /** @@ -905,44 +756,6 @@ export class WETH9Contract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string): string { - assert.isString('index_0', index_0); - const self = (this as any) as WETH9Contract; - const abiEncodedTransactionData = self._strictEncodeArguments('balanceOf(address)', [ - index_0.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public symbol = { /** @@ -986,41 +799,6 @@ export class WETH9Contract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as WETH9Contract; - const abiEncodedTransactionData = self._strictEncodeArguments('symbol()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('symbol()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('symbol()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transfer = { /** @@ -1029,7 +807,12 @@ export class WETH9Contract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(dst: string, wad: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + dst: string, + wad: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isString('dst', dst); assert.isBigNumber('wad', wad); const self = (this as any) as WETH9Contract; @@ -1046,6 +829,10 @@ export class WETH9Contract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transfer.callAsync(dst, wad, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1060,21 +847,20 @@ export class WETH9Contract extends BaseContract { dst: string, wad: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('dst', dst); assert.isBigNumber('wad', wad); const self = (this as any) as WETH9Contract; - const txHashPromise = self.transfer.sendTransactionAsync(dst.toLowerCase(), wad, txData); + const txHashPromise = self.transfer.sendTransactionAsync(dst.toLowerCase(), wad, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1104,15 +890,6 @@ export class WETH9Contract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1178,28 +955,12 @@ export class WETH9Contract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): boolean { + getSelector(): string { const self = (this as any) as WETH9Contract; const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public deposit = { @@ -1209,7 +970,10 @@ export class WETH9Contract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(txData?: Partial | undefined): Promise { + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { const self = (this as any) as WETH9Contract; const encodedData = self._strictEncodeArguments('deposit()', []); const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( @@ -1224,6 +988,10 @@ export class WETH9Contract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.deposit.callAsync(txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1236,19 +1004,18 @@ export class WETH9Contract extends BaseContract { */ awaitTransactionSuccessAsync( txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { const self = (this as any) as WETH9Contract; - const txHashPromise = self.deposit.sendTransactionAsync(txData); + const txHashPromise = self.deposit.sendTransactionAsync(txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1276,11 +1043,6 @@ export class WETH9Contract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync(txData?: Partial | undefined): Promise { - await (this as any).deposit.callAsync(txData); - const txHash = await (this as any).deposit.sendTransactionAsync(txData); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1334,28 +1096,12 @@ export class WETH9Contract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('deposit()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedReturnData(returnData: string): void { + getSelector(): string { const self = (this as any) as WETH9Contract; const abiEncoder = self._lookupAbiEncoder('deposit()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public allowance = { @@ -1410,46 +1156,6 @@ export class WETH9Contract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(index_0: string, index_1: string): string { - assert.isString('index_0', index_0); - assert.isString('index_1', index_1); - const self = (this as any) as WETH9Contract; - const abiEncodedTransactionData = self._strictEncodeArguments('allowance(address,address)', [ - index_0.toLowerCase(), - index_1.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('allowance(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as WETH9Contract; - const abiEncoder = self._lookupAbiEncoder('allowance(address,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/abi-gen-wrappers/src/generated-wrappers/zrx_token.ts b/packages/abi-gen-wrappers/src/generated-wrappers/zrx_token.ts index 6f60e3abab..811787ec7b 100644 --- a/packages/abi-gen-wrappers/src/generated-wrappers/zrx_token.ts +++ b/packages/abi-gen-wrappers/src/generated-wrappers/zrx_token.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -48,8 +54,10 @@ export interface ZRXTokenApprovalEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class ZRXTokenContract extends BaseContract { - public static deployedBytecode = - '0x606060405236156100965763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde038114610098578063095ea7b31461014657806318160ddd1461018657806323b872dd146101a8578063313ce567146101ee57806370a082311461021457806395d89b411461024f578063a9059cbb146102fd578063dd62ed3e1461033d575bfe5b34156100a057fe5b6100a861037e565b60408051602080825283518183015283519192839290830191850190808383821561010c575b80518252602083111561010c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016100ce565b505050905090810190601f1680156101385780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014e57fe5b61017273ffffffffffffffffffffffffffffffffffffffff600435166024356103b5565b604080519115158252519081900360200190f35b341561018e57fe5b61019661042d565b60408051918252519081900360200190f35b34156101b057fe5b61017273ffffffffffffffffffffffffffffffffffffffff60043581169060243516604435610433565b604080519115158252519081900360200190f35b34156101f657fe5b6101fe6105d4565b6040805160ff9092168252519081900360200190f35b341561021c57fe5b61019673ffffffffffffffffffffffffffffffffffffffff600435166105d9565b60408051918252519081900360200190f35b341561025757fe5b6100a8610605565b60408051602080825283518183015283519192839290830191850190808383821561010c575b80518252602083111561010c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016100ce565b505050905090810190601f1680156101385780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561030557fe5b61017273ffffffffffffffffffffffffffffffffffffffff6004351660243561063c565b604080519115158252519081900360200190f35b341561034557fe5b61019673ffffffffffffffffffffffffffffffffffffffff60043581169060243516610727565b60408051918252519081900360200190f35b60408051808201909152601181527f30782050726f746f636f6c20546f6b656e000000000000000000000000000000602082015281565b73ffffffffffffffffffffffffffffffffffffffff338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60035481565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260016020908152604080832033909516835293815283822054928252819052918220548390108015906104835750828110155b80156104b6575073ffffffffffffffffffffffffffffffffffffffff841660009081526020819052604090205483810110155b156105c65773ffffffffffffffffffffffffffffffffffffffff808516600090815260208190526040808220805487019055918716815220805484900390557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156105585773ffffffffffffffffffffffffffffffffffffffff808616600090815260016020908152604080832033909416835292905220805484900390555b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3600191506105cb565b600091505b5b509392505050565b601281565b73ffffffffffffffffffffffffffffffffffffffff81166000908152602081905260409020545b919050565b60408051808201909152600381527f5a52580000000000000000000000000000000000000000000000000000000000602082015281565b73ffffffffffffffffffffffffffffffffffffffff3316600090815260208190526040812054829010801590610699575073ffffffffffffffffffffffffffffffffffffffff831660009081526020819052604090205482810110155b156107185773ffffffffffffffffffffffffffffffffffffffff33811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a3506001610427565b506000610427565b5b92915050565b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600160209081526040808320938516835292905220545b929150505600a165627a7a72305820d984298155c708a8164f1cbf83c7275bcc6851dd082c0404013c1f4463b238fa0029'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; public name = { /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an @@ -92,41 +100,6 @@ export class ZRXTokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ZRXTokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('name()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('name()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('name()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public approve = { /** @@ -139,6 +112,7 @@ export class ZRXTokenContract extends BaseContract { _spender: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_spender', _spender); assert.isBigNumber('_value', _value); @@ -159,6 +133,10 @@ export class ZRXTokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.approve.callAsync(_spender, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -173,21 +151,20 @@ export class ZRXTokenContract extends BaseContract { _spender: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_spender', _spender); assert.isBigNumber('_value', _value); const self = (this as any) as ZRXTokenContract; - const txHashPromise = self.approve.sendTransactionAsync(_spender.toLowerCase(), _value, txData); + const txHashPromise = self.approve.sendTransactionAsync(_spender.toLowerCase(), _value, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -224,15 +201,6 @@ export class ZRXTokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -301,28 +269,12 @@ export class ZRXTokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): string { + getSelector(): string { const self = (this as any) as ZRXTokenContract; const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public totalSupply = { @@ -367,41 +319,6 @@ export class ZRXTokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ZRXTokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('totalSupply()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('totalSupply()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('totalSupply()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; /** * ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance. @@ -421,6 +338,7 @@ export class ZRXTokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_from', _from); assert.isString('_to', _to); @@ -443,6 +361,10 @@ export class ZRXTokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transferFrom.callAsync(_from, _to, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -461,8 +383,7 @@ export class ZRXTokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_from', _from); assert.isString('_to', _to); @@ -473,6 +394,7 @@ export class ZRXTokenContract extends BaseContract { _to.toLowerCase(), _value, txData, + opts, ); return new PromiseWithTransactionHash( txHashPromise, @@ -480,8 +402,8 @@ export class ZRXTokenContract extends BaseContract { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -524,16 +446,6 @@ export class ZRXTokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -614,28 +526,12 @@ export class ZRXTokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): string { + getSelector(): string { const self = (this as any) as ZRXTokenContract; const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public decimals = { @@ -680,41 +576,6 @@ export class ZRXTokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ZRXTokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('decimals()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('decimals()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): number { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('decimals()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public balanceOf = { /** @@ -763,42 +624,6 @@ export class ZRXTokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string): string { - assert.isString('_owner', _owner); - const self = (this as any) as ZRXTokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('balanceOf(address)', [_owner.toLowerCase()]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('balanceOf(address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public symbol = { /** @@ -842,41 +667,6 @@ export class ZRXTokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(): string { - const self = (this as any) as ZRXTokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('symbol()', []); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): void { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('symbol()'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): string { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('symbol()'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; public transfer = { /** @@ -889,6 +679,7 @@ export class ZRXTokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { assert.isString('_to', _to); assert.isBigNumber('_value', _value); @@ -906,6 +697,10 @@ export class ZRXTokenContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.transfer.callAsync(_to, _value, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -920,21 +715,20 @@ export class ZRXTokenContract extends BaseContract { _to: string, _value: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isString('_to', _to); assert.isBigNumber('_value', _value); const self = (this as any) as ZRXTokenContract; - const txHashPromise = self.transfer.sendTransactionAsync(_to.toLowerCase(), _value, txData); + const txHashPromise = self.transfer.sendTransactionAsync(_to.toLowerCase(), _value, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -964,15 +758,6 @@ export class ZRXTokenContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1038,28 +823,12 @@ export class ZRXTokenContract extends BaseContract { return abiEncodedTransactionData; }, /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. + * Returns the 4 byte function selector as a hex string. */ - getABIDecodedTransactionData(callData: string): string { + getSelector(): string { const self = (this as any) as ZRXTokenContract; const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): boolean { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; + return abiEncoder.getSelector(); }, }; public allowance = { @@ -1114,46 +883,6 @@ export class ZRXTokenContract extends BaseContract { // tslint:enable boolean-naming return result; }, - /** - * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before - * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used - * to create a 0x transaction (see protocol spec for more details). - * @returns The ABI encoded transaction data as a string - */ - getABIEncodedTransactionData(_owner: string, _spender: string): string { - assert.isString('_owner', _owner); - assert.isString('_spender', _spender); - const self = (this as any) as ZRXTokenContract; - const abiEncodedTransactionData = self._strictEncodeArguments('allowance(address,address)', [ - _owner.toLowerCase(), - _spender.toLowerCase(), - ]); - return abiEncodedTransactionData; - }, - /** - * Decode the ABI-encoded transaction data into its input arguments - * @param callData The ABI-encoded transaction data - * @returns An array representing the input arguments in order. Keynames of nested structs are preserved. - */ - getABIDecodedTransactionData(callData: string): string { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('allowance(address,address)'); - // tslint:disable boolean-naming - const abiDecodedCallData = abiEncoder.strictDecode(callData); - return abiDecodedCallData; - }, - /** - * Decode the ABI-encoded return data from a transaction - * @param returnData the data returned after transaction execution - * @returns An array representing the output results in order. Keynames of nested structs are preserved. - */ - getABIDecodedReturnData(returnData: string): BigNumber { - const self = (this as any) as ZRXTokenContract; - const abiEncoder = self._lookupAbiEncoder('allowance(address,address)'); - // tslint:disable boolean-naming - const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); - return abiDecodedReturnData; - }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/abi-gen-wrappers/src/index.ts b/packages/abi-gen-wrappers/src/index.ts index 31a9875352..d0c5f1f991 100644 --- a/packages/abi-gen-wrappers/src/index.ts +++ b/packages/abi-gen-wrappers/src/index.ts @@ -30,6 +30,13 @@ export { DummyERC721TokenApprovalForAllEventArgs, DummyERC721TokenContract, } from './generated-wrappers/dummy_erc721_token'; +export { + ERC1155MintableContract, + ERC1155MintableApprovalForAllEventArgs, + ERC1155MintableTransferBatchEventArgs, + ERC1155MintableTransferSingleEventArgs, + ERC1155MintableURIEventArgs, +} from './generated-wrappers/erc1155_mintable'; export { DutchAuctionContract } from './generated-wrappers/dutch_auction'; export { ERC1155ProxyEventArgs, diff --git a/packages/abi-gen/CHANGELOG.json b/packages/abi-gen/CHANGELOG.json index de66262620..73b8d81211 100644 --- a/packages/abi-gen/CHANGELOG.json +++ b/packages/abi-gen/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "4.4.0-beta.0", + "changes": [ + { + "note": "Add `getSelector` method to all functions", + "pr": 2224 + } + ] + }, { "version": "4.3.0-beta.0", "changes": [ diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json index 79d7557875..b1cbfed930 100644 --- a/packages/abi-gen/package.json +++ b/packages/abi-gen/package.json @@ -36,7 +36,7 @@ "watch:sol": "sol-compiler -w", "prettier_contract_wrappers": "prettier --write ./test-cli/output/typescript/* --config ../../.prettierrc", "generate_contract_wrappers": "run-p gen_typescript gen_python", - "gen_typescript": "abi-gen --abis ${npm_package_config_abis} --output ./test-cli/output/typescript --backend ethers", + "gen_typescript": "abi-gen --abis ${npm_package_config_abis} --debug --output ./test-cli/output/typescript --backend ethers", "gen_python": "pip install black && abi-gen --abis ${npm_package_config_abis} --output ./test-cli/output/python --language Python", "diff_contract_wrappers": "git diff --exit-code ./test-cli/output", "coverage:report:text": "istanbul report text", @@ -79,9 +79,11 @@ "yargs": "^10.0.3" }, "devDependencies": { + "@0x/assert": "^2.2.0-beta.0", "@0x/base-contract": "^5.5.0-beta.0", "@0x/contracts-gen": "^1.1.0-beta.0", "@0x/dev-utils": "^2.4.0-beta.0", + "@0x/json-schemas": "^4.1.0-beta.0", "@0x/sol-compiler": "^3.2.0-beta.0", "@0x/subproviders": "^5.1.0-beta.0", "@0x/tslint-config": "^3.0.1", @@ -96,6 +98,7 @@ "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", + "ethers": "~4.0.4", "make-promises-safe": "^1.1.0", "mocha": "^6.2.0", "npm-run-all": "^4.1.2", diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index c7b243e97b..f9793aa5d6 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -44,6 +44,10 @@ const args = yargs normalize: true, demandOption: true, }) + .option('debug', { + describe: 'Includes debug functions in the wrappers such as `getABIDecodedTransactionData`', + type: 'boolean', + }) .option('partials', { describe: 'Glob pattern for the partial template files', type: 'string', @@ -73,12 +77,11 @@ const args = yargs default: 'TypeScript', }) .example( - "$0 --abis 'src/artifacts/**/*.json' --out 'src/contracts/generated/' --partials 'src/templates/partials/**/*.handlebars' --template 'src/templates/contract.handlebars'", + "$0 --abis 'src/artifacts/**/*.json' --out 'src/contracts/generated/' --debug --partials 'src/templates/partials/**/*.handlebars' --template 'src/templates/contract.handlebars'", 'Full usage example', ).argv; const templateFilename = args.template || `${__dirname}/../../templates/${args.language}/contract.handlebars`; - const mainTemplate = utils.getNamedContent(templateFilename); const template = Handlebars.compile(mainTemplate.content); const abiFileNames = globSync(args.abis); @@ -417,14 +420,17 @@ for (const abiFileName of abiFileNames) { return eventData; }); + const shouldIncludeBytecode = methodsData.find(methodData => methodData.stateMutability === 'pure') !== undefined; + const contextData = { contractName: namedContent.name, ctor, - deployedBytecode, + deployedBytecode: shouldIncludeBytecode ? deployedBytecode : undefined, ABI: ABI as ContractAbi, ABIString: JSON.stringify(ABI), methods: methodsData, events: eventsData, + debug: args.debug, }; const renderedCode = template(contextData); utils.writeOutputFile(outFilePath, renderedCode); diff --git a/packages/abi-gen/templates/TypeScript/contract.handlebars b/packages/abi-gen/templates/TypeScript/contract.handlebars index d7dd089680..2a2d56f845 100644 --- a/packages/abi-gen/templates/TypeScript/contract.handlebars +++ b/packages/abi-gen/templates/TypeScript/contract.handlebars @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract{{#if events}}, @@ -20,7 +20,7 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { AwaitTransactionSuccessOpts, EventCallback, IndexedFilterValues, SendTransactionOpts, SimpleContractArtifact } from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -48,6 +48,9 @@ export enum {{contractName}}Events { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class {{contractName}}Contract extends BaseContract { + /** + * @ignore + */ {{#ifEquals this.deployedBytecode undefined~}} public static deployedBytecode: string | undefined; {{else~}} @@ -69,7 +72,7 @@ export class {{contractName}}Contract extends BaseContract { {{else}} {{> method_call contractName=../contractName}} {{/ifEquals}} - {{> method_abi_helper contractName=../contractName}} + {{> method_abi_helper contractName=../contractName debug=../debug}} }; {{/each}} {{#if events}}private readonly _subscriptionManager: SubscriptionManager<{{contractName}}EventArgs, {{contractName}}Events>; diff --git a/packages/abi-gen/templates/TypeScript/partials/method_abi_helper.handlebars b/packages/abi-gen/templates/TypeScript/partials/method_abi_helper.handlebars index 0c8f1893af..64780645ea 100644 --- a/packages/abi-gen/templates/TypeScript/partials/method_abi_helper.handlebars +++ b/packages/abi-gen/templates/TypeScript/partials/method_abi_helper.handlebars @@ -1,3 +1,35 @@ +{{!-- if ((NOT constant) AND (NOT debug)), to avoid repetition bbecause we use all 4 functions if (debug) --}} +{{^if constant~}} +{{^if debug~}} +/** + * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before + * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used + * to create a 0x transaction (see protocol spec for more details). +{{> params_docstring inputs=inputs docstrings=devdoc.params}} + * @returns The ABI encoded transaction data as a string + */ +getABIEncodedTransactionData( + {{> typed_params inputs=inputs}} + ): string { + {{#each inputs}} + {{#assertionType name type}}{{/assertionType}} + {{/each}} + const self = this as any as {{contractName}}Contract; + const abiEncodedTransactionData = self._strictEncodeArguments('{{this.functionSignature}}', [{{> normalized_params inputs=inputs}}]); + return abiEncodedTransactionData; +}, +/** + * Returns the 4 byte function selector as a hex string. + */ +getSelector(): string { + const self = this as any as {{contractName}}Contract; + const abiEncoder = self._lookupAbiEncoder('{{this.functionSignature}}'); + return abiEncoder.getSelector(); +} +{{/if~}} +{{/if~}} + +{{#if debug~}} /** * Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before * sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used @@ -43,3 +75,12 @@ getABIDecodedReturnData( const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{{> return_type outputs=outputs}}>(returnData); return abiDecodedReturnData; }, +/** + * Returns the 4 byte function selector as a hex string. + */ +getSelector(): string { + const self = this as any as {{contractName}}Contract; + const abiEncoder = self._lookupAbiEncoder('{{this.functionSignature}}'); + return abiEncoder.getSelector(); +} +{{/if}} diff --git a/packages/abi-gen/templates/TypeScript/partials/method_call_pure.handlebars b/packages/abi-gen/templates/TypeScript/partials/method_call_pure.handlebars index 3b7e1ab82c..2ec68190f9 100644 --- a/packages/abi-gen/templates/TypeScript/partials/method_call_pure.handlebars +++ b/packages/abi-gen/templates/TypeScript/partials/method_call_pure.handlebars @@ -29,7 +29,7 @@ async callAsync( let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; diff --git a/packages/abi-gen/templates/TypeScript/partials/method_tx.handlebars b/packages/abi-gen/templates/TypeScript/partials/method_tx.handlebars index d4bbdc9d75..de4e7eb324 100644 --- a/packages/abi-gen/templates/TypeScript/partials/method_tx.handlebars +++ b/packages/abi-gen/templates/TypeScript/partials/method_tx.handlebars @@ -8,6 +8,7 @@ async sendTransactionAsync( {{> typed_params inputs=inputs}} txData?: Partial | undefined, +opts: SendTransactionOpts = { shouldValidate: true }, ): Promise { {{#each inputs}} {{#assertionType name type}}{{/assertionType}} @@ -26,6 +27,15 @@ txData?: Partial | undefined, txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.{{languageSpecificName}}.callAsync( + {{#each inputs~}} + {{name}}, + {{/each~}} + txDataWithDefaults, + ); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -40,17 +50,16 @@ txData?: Partial | undefined, awaitTransactionSuccessAsync( {{> typed_params inputs=inputs}} txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { {{#each inputs}} {{#assertionType name type}}{{/assertionType}} {{/each}} const self = this as any as {{contractName}}Contract; {{#if inputs}} - const txHashPromise = self.{{languageSpecificName}}.sendTransactionAsync({{> normalized_params input=inputs}}, txData); + const txHashPromise = self.{{languageSpecificName}}.sendTransactionAsync({{> normalized_params input=inputs}}, txData, opts); {{else}} - const txHashPromise = self.{{languageSpecificName}}.sendTransactionAsync(txData); + const txHashPromise = self.{{languageSpecificName}}.sendTransactionAsync(txData, opts); {{/if}} return new PromiseWithTransactionHash( txHashPromise, @@ -58,8 +67,8 @@ awaitTransactionSuccessAsync( // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -94,21 +103,3 @@ async estimateGasAsync( const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, -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/output/typescript/abi_gen_dummy.ts b/packages/abi-gen/test-cli/output/typescript/abi_gen_dummy.ts index 5b149586fb..816a927f33 100644 --- a/packages/abi-gen/test-cli/output/typescript/abi_gen_dummy.ts +++ b/packages/abi-gen/test-cli/output/typescript/abi_gen_dummy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, SubscriptionManager, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -19,7 +19,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { EventCallback, IndexedFilterValues, SimpleContractArtifact } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -46,6 +52,9 @@ export interface AbiGenDummySimpleEventEventArgs extends DecodedLogArgs { // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class AbiGenDummyContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode = '0x608060405234801561001057600080fd5b50600436106101d95760003560e01c806376f15d5b11610104578063bb607362116100a2578063d88be12f11610071578063d88be12f1461039b578063ee8b86fb146103a3578063f408fb3114610279578063fa315f9d146103b6576101d9565b8063bb60736214610353578063bdab168814610369578063cd3c0b971461037e578063d6d7618c14610386576101d9565b80638ee52b4e116100de5780638ee52b4e146103225780639a3b618514610335578063a3c2f6b61461033d578063ae2dae1714610345576101d9565b806376f15d5b146102f25780637833bec0146102fa5780637a791e6e1461031a576101d9565b80634303a5421161017c57806359c28add1161014b57806359c28add146102b45780635ba3c7c0146102c957806363d69c88146102d1578063647341eb146102e4576101d9565b80634303a542146102875780634582eab21461028f57806345fdbdb714610297578063586f84b21461029f576101d9565b80632e1a7d4d116101b85780632e1a7d4d146102245780633687617d1461023757806336b32396146102595780633e9ef66a14610279576101d9565b806209e437146101de5780630527c28f146101e85780631310e444146101fb575b600080fd5b6101e66103c4565b005b6101e66101f6366004610c7f565b610401565b61020e610209366004610d34565b610404565b60405161021b919061139a565b60405180910390f35b6101e6610232366004610d34565b61040b565b61024a610245366004610eac565b61045c565b60405161021b93929190611103565b61026c610267366004610cbc565b6104fc565b60405161021b9190611045565b6101e66101f6366004610cff565b61020e6105de565b6101e66105e5565b6101e661064a565b6102a761067c565b60405161021b9190611325565b6102bc610684565b60405161021b9190611330565b6101e661068c565b61026c6102df366004610c2d565b6106f1565b6101e66101f6366004610e77565b61020e6106fa565b61030d610308366004610d4d565b610708565b60405161021b9190611239565b6101e66107c5565b61020e610330366004610d34565b6107ca565b6101e66107d0565b61020e6107db565b6101e66101f6366004610de7565b61035b6107e0565b60405161021b9291906113a3565b610371610819565b60405161021b9190611066565b6101e661081e565b61038e610855565b60405161021b9190611387565b61020e6109ae565b6101e66103b1366004610d34565b6101f6565b6101e66101f6366004610d34565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f690611202565b60405180910390fd5b565b50565b506107c790565b3373ffffffffffffffffffffffffffffffffffffffff167f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b6582604051610451919061139a565b60405180910390a250565b505060408051808201825260048082527f1234567800000000000000000000000000000000000000000000000000000000602080840191909152835180850185528281527f87654321000000000000000000000000000000000000000000000000000000008183015284518086019095529184527f616d657400000000000000000000000000000000000000000000000000000000908401529093909250565b600060606040518060400160405280601c81526020017f19457468657265756d205369676e6564204d6573736167653a0a33320000000081525090506000818760405160200161054d929190611023565b6040516020818303038152906040528051906020012090506001818787876040516000815260200160405260405161058894939291906110e5565b6020604051602081039080840390855afa1580156105aa573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015198975050505050505050565b6107c75b90565b604080518082018252601481527f5245564552545f574954485f434f4e5354414e54000000000000000000000000602082015290517f08c379a00000000000000000000000000000000000000000000000000000000081526103f69190600401611145565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f6906111cb565b6105e26109b4565b6105e26109cc565b604080518082018252601581527f524551554952455f574954485f434f4e5354414e540000000000000000000000602082015290517f08c379a00000000000000000000000000000000000000000000000000000000081526103f69190600401611145565b50929392505050565b600080546001019081905590565b6107106109ec565b50604080516080810182529182528051808201825260048082527f123456780000000000000000000000000000000000000000000000000000000060208381019190915280850192909252825180840184528181527f87654321000000000000000000000000000000000000000000000000000000008184015284840152825180840190935282527f616d65740000000000000000000000000000000000000000000000000000000090820152606082015290565b6103ff565b60010190565b600080546001019055565b600190565b60408051808201909152600581527f68656c6c6f0000000000000000000000000000000000000000000000000000006020820152600191565b606090565b7f61a6029a4c7ddee5824d171331eecbd015d26a271310a223718b837facb5b77160405161084b9061115f565b60405180910390a1565b61085d610a1a565b6040805160028082526060828101909352816020015b60608152602001906001900390816108735790505090506040518060400160405280600581526020017f3078313233000000000000000000000000000000000000000000000000000000815250816000815181106108cd57fe5b60200260200101819052506040518060400160405280600581526020017f30783332310000000000000000000000000000000000000000000000000000008152508160018151811061091b57fe5b6020908102919091018101919091526040805160c0810182526005608082018181527f307831323300000000000000000000000000000000000000000000000000000060a0840152825281840152808201939093528051808201909152600381527f6162630000000000000000000000000000000000000000000000000000000000918101919091526060820152905090565b6104d290565b60405180602001604052806109c7610a48565b905290565b60405180604001604052806109df610a1a565b8152602001606081525090565b60405180608001604052806109ff610a5b565b81526020016060815260200160608152602001606081525090565b604051806080016040528060608152602001600063ffffffff16815260200160608152602001606081525090565b6040518060200160405280600081525090565b60405180606001604052806000815260200160608152602001606081525090565b600082601f830112610a8c578081fd5b813567ffffffffffffffff811115610aa2578182fd5b6020610ab181828402016113bc565b828152925080830184820160005b84811015610ae857610ad6888584358a0101610af3565b83529183019190830190600101610abf565b505050505092915050565b600082601f830112610b03578081fd5b813567ffffffffffffffff811115610b19578182fd5b610b4a60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116016113bc565b9150808252836020828501011115610b6157600080fd5b8060208401602084013760009082016020015292915050565b600060808284031215610b8b578081fd5b610b9560806113bc565b90506000823567ffffffffffffffff80821115610bb0578283fd5b610bbc86838701610af3565b84526020850135915063ffffffff82168214610bd6578283fd5b8160208501526040850135915080821115610bef578283fd5b610bfb86838701610a7c565b60408501526060850135915080821115610c13578283fd5b50610c2085828601610af3565b6060840152505092915050565b600080600080600060a08688031215610c4557600080fd5b8535610c5081611413565b945060208601359350604086013592506060860135610c6e81611413565b949793965091946080013592915050565b600060208284031215610c9157600080fd5b813567ffffffffffffffff811115610ca857600080fd5b610cb484828501610a7c565b949350505050565b60008060008060808587031215610cd257600080fd5b84359350602085013560ff81168114610cea57600080fd5b93969395505050506040820135916060013590565b600060208284031215610d1157600080fd5b813567ffffffffffffffff811115610d2857600080fd5b610cb484828501610af3565b600060208284031215610d4657600080fd5b5035919050565b600060208284031215610d5e578081fd5b813567ffffffffffffffff80821115610d75578283fd5b81840160608187031215610d87578384fd5b610d9160606113bc565b925080358352602081013582811115610da8578485fd5b610db487828401610af3565b602085015250604081013582811115610dcb578485fd5b610dd787828401610af3565b6040850152509195945050505050565b600060208284031215610df8578081fd5b813567ffffffffffffffff80821115610e0f578283fd5b81840160408187031215610e21578384fd5b610e2b60406113bc565b9250803582811115610e3b578485fd5b610e4787828401610b7a565b845250602081013582811115610e5b578485fd5b610e6787828401610af3565b6020850152509195945050505050565b600060208284031215610e8957600080fd5b813567ffffffffffffffff811115610ea057600080fd5b610cb484828501610b7a565b600080600060608486031215610ec0578081fd5b83359250602084013567ffffffffffffffff80821115610ede578283fd5b610eea87838801610af3565b93506040860135915080821115610eff578283fd5b50610f0c86828701610af3565b9150509250925092565b60008151808452610f2e8160208601602086016113e3565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6000815160808452610f756080850182610f16565b6020915063ffffffff82850151168286015260408401518582036040870152818151808452848401915084858202850101858401600094505b82851015610ffc577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0868303018452610fe8828251610f16565b600195909501949387019391508601610fae565b506060880151955088810360608a01526110168187610f16565b9998505050505050505050565b600083516110358184602088016113e3565b9190910191825250602001919050565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b600060208083018184528085518083526040860191506040848202870101925083870160005b828110156110d8577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08886030184526110c6858351610f60565b9450928501929085019060010161108c565b5092979650505050505050565b93845260ff9290921660208401526040830152606082015260800190565b6000606082526111166060830186610f16565b82810360208401526111288186610f16565b838103604085015261113a8186610f16565b979650505050505050565b6000602082526111586020830184610f16565b9392505050565b60408082526004908201527f123456780000000000000000000000000000000000000000000000000000000060608201526080602082018190526005908201527f6c6f72656d00000000000000000000000000000000000000000000000000000060a082015260c00190565b6020808252600d908201527f53494d504c455f52455645525400000000000000000000000000000000000000604082015260600190565b6020808252600e908201527f53494d504c455f52455155495245000000000000000000000000000000000000604082015260600190565b600060208252825160806020840152805160a08401526020810151606060c0850152611269610100850182610f16565b604083015191507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff608582030160e08601526112a48183610f16565b9250505060208401517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0808584030160408601526112e28383610f16565b60408701519350818682030160608701526112fd8185610f16565b92505060608601519250808583030160808601525061131c8183610f16565b95945050505050565b905151815260200190565b60006020825282516040602084015261134c6060840182610f60565b602085015191507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe084820301604085015261131c8183610f16565b6000602082526111586020830184610f60565b90815260200190565b600083825260406020830152610cb46040830184610f16565b60405181810167ffffffffffffffff811182821017156113db57600080fd5b604052919050565b60005b838110156113fe5781810151838201526020016113e6565b8381111561140d576000848401525b50505050565b73ffffffffffffffffffffffffffffffffffffffff8116811461040157600080fdfea365627a7a723158207f0854b76fc684de0be1f1a5db2d486bc187ff28d1e99d27ca0f61b452a1942f6c6578706572696d656e74616cf564736f6c634300050b0040'; public simpleRequire = { @@ -69,7 +78,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -117,6 +126,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('simpleRequire()'); + return abiEncoder.getSelector(); + }, }; /** * a method that accepts an array of bytes @@ -144,7 +161,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -194,6 +211,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('acceptsAnArrayOfBytes(bytes[])'); + return abiEncoder.getSelector(); + }, }; /** * Tests decoding when both input and output are non-empty. @@ -224,7 +249,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -275,6 +300,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('simpleInputSimpleOutput(uint256)'); + return abiEncoder.getSelector(); + }, }; public withdraw = { /** @@ -283,7 +316,11 @@ export class AbiGenDummyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(wad: BigNumber, txData?: Partial | undefined): Promise { + async sendTransactionAsync( + wad: BigNumber, + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { assert.isBigNumber('wad', wad); const self = (this as any) as AbiGenDummyContract; const encodedData = self._strictEncodeArguments('withdraw(uint256)', [wad]); @@ -299,6 +336,10 @@ export class AbiGenDummyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.withdraw.callAsync(wad, txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -312,20 +353,19 @@ export class AbiGenDummyContract extends BaseContract { awaitTransactionSuccessAsync( wad: BigNumber, txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { assert.isBigNumber('wad', wad); const self = (this as any) as AbiGenDummyContract; - const txHashPromise = self.withdraw.sendTransactionAsync(wad, txData); + const txHashPromise = self.withdraw.sendTransactionAsync(wad, txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -354,11 +394,6 @@ export class AbiGenDummyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - 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; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -437,6 +472,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('withdraw(uint256)'); + return abiEncoder.getSelector(); + }, }; /** * Tests decoding when the input and output are complex and have more than one argument. @@ -475,7 +518,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -529,6 +572,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[string, string, string]>(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('multiInputMultiOutput(uint256,bytes,string)'); + return abiEncoder.getSelector(); + }, }; /** * test that devdocs will be generated and @@ -578,7 +629,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -639,6 +690,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('ecrecoverFn(bytes32,uint8,bytes32,bytes32)'); + return abiEncoder.getSelector(); + }, }; public acceptsBytes = { /** @@ -662,7 +721,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -711,6 +770,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('acceptsBytes(bytes)'); + return abiEncoder.getSelector(); + }, }; /** * Tests decoding when input is empty and output is non-empty. @@ -736,7 +803,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -784,6 +851,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('noInputSimpleOutput()'); + return abiEncoder.getSelector(); + }, }; public revertWithConstant = { /** @@ -806,7 +881,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -854,6 +929,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('revertWithConstant()'); + return abiEncoder.getSelector(); + }, }; public simpleRevert = { /** @@ -876,7 +959,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -924,6 +1007,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('simpleRevert()'); + return abiEncoder.getSelector(); + }, }; public methodUsingNestedStructWithInnerStructNotUsedElsewhere = { /** @@ -952,7 +1043,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1005,6 +1096,14 @@ export class AbiGenDummyContract extends BaseContract { ); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('methodUsingNestedStructWithInnerStructNotUsedElsewhere()'); + return abiEncoder.getSelector(); + }, }; public nestedStructOutput = { /** @@ -1033,7 +1132,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1092,6 +1191,14 @@ export class AbiGenDummyContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('nestedStructOutput()'); + return abiEncoder.getSelector(); + }, }; public requireWithConstant = { /** @@ -1114,7 +1221,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1162,6 +1269,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('requireWithConstant()'); + return abiEncoder.getSelector(); + }, }; public withAddressInput = { /** @@ -1200,7 +1315,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1256,6 +1371,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('withAddressInput(address,uint256,uint256,address,uint256)'); + return abiEncoder.getSelector(); + }, }; public structInput = { /** @@ -1282,7 +1405,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1342,6 +1465,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('structInput((bytes,uint32,bytes[],string))'); + return abiEncoder.getSelector(); + }, }; public nonPureMethod = { /** @@ -1350,7 +1481,10 @@ export class AbiGenDummyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(txData?: Partial | undefined): Promise { + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { const self = (this as any) as AbiGenDummyContract; const encodedData = self._strictEncodeArguments('nonPureMethod()', []); const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( @@ -1365,6 +1499,10 @@ export class AbiGenDummyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.nonPureMethod.callAsync(txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1377,19 +1515,18 @@ export class AbiGenDummyContract extends BaseContract { */ awaitTransactionSuccessAsync( txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { const self = (this as any) as AbiGenDummyContract; - const txHashPromise = self.nonPureMethod.sendTransactionAsync(txData); + const txHashPromise = self.nonPureMethod.sendTransactionAsync(txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1417,11 +1554,6 @@ export class AbiGenDummyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync(txData?: Partial | undefined): Promise { - await (this as any).nonPureMethod.callAsync(txData); - const txHash = await (this as any).nonPureMethod.sendTransactionAsync(txData); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1498,6 +1630,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('nonPureMethod()'); + return abiEncoder.getSelector(); + }, }; /** * Tests decoding when the input and output are complex. @@ -1534,7 +1674,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1597,6 +1737,14 @@ export class AbiGenDummyContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('complexInputComplexOutput((uint256,bytes,string))'); + return abiEncoder.getSelector(); + }, }; /** * Tests decoding when both input and output are empty. @@ -1622,7 +1770,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1670,6 +1818,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('noInputNoOutput()'); + return abiEncoder.getSelector(); + }, }; public simplePureFunctionWithInput = { /** @@ -1693,7 +1849,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1742,6 +1898,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('simplePureFunctionWithInput(uint256)'); + return abiEncoder.getSelector(); + }, }; public nonPureMethodThatReturnsNothing = { /** @@ -1750,7 +1914,10 @@ export class AbiGenDummyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(txData?: Partial | undefined): Promise { + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { const self = (this as any) as AbiGenDummyContract; const encodedData = self._strictEncodeArguments('nonPureMethodThatReturnsNothing()', []); const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( @@ -1765,6 +1932,10 @@ export class AbiGenDummyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.nonPureMethodThatReturnsNothing.callAsync(txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -1777,19 +1948,18 @@ export class AbiGenDummyContract extends BaseContract { */ awaitTransactionSuccessAsync( txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { const self = (this as any) as AbiGenDummyContract; - const txHashPromise = self.nonPureMethodThatReturnsNothing.sendTransactionAsync(txData); + const txHashPromise = self.nonPureMethodThatReturnsNothing.sendTransactionAsync(txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -1817,11 +1987,6 @@ export class AbiGenDummyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync(txData?: Partial | undefined): Promise { - await (this as any).nonPureMethodThatReturnsNothing.callAsync(txData); - const txHash = await (this as any).nonPureMethodThatReturnsNothing.sendTransactionAsync(txData); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -1898,6 +2063,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('nonPureMethodThatReturnsNothing()'); + return abiEncoder.getSelector(); + }, }; public simplePureFunction = { /** @@ -1920,7 +2093,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -1968,6 +2141,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('simplePureFunction()'); + return abiEncoder.getSelector(); + }, }; public nestedStructInput = { /** @@ -2005,7 +2186,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2083,6 +2264,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('nestedStructInput(((bytes,uint32,bytes[],string),string))'); + return abiEncoder.getSelector(); + }, }; public methodReturningMultipleValues = { /** @@ -2105,7 +2294,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2153,6 +2342,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[BigNumber, string]>(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('methodReturningMultipleValues()'); + return abiEncoder.getSelector(); + }, }; public methodReturningArrayOfStructs = { /** @@ -2178,7 +2375,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2232,6 +2429,14 @@ export class AbiGenDummyContract extends BaseContract { >(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('methodReturningArrayOfStructs()'); + return abiEncoder.getSelector(); + }, }; public emitSimpleEvent = { /** @@ -2240,7 +2445,10 @@ export class AbiGenDummyContract extends BaseContract { * @param txData Additional data for transaction * @returns The hash of the transaction */ - async sendTransactionAsync(txData?: Partial | undefined): Promise { + async sendTransactionAsync( + txData?: Partial | undefined, + opts: SendTransactionOpts = { shouldValidate: true }, + ): Promise { const self = (this as any) as AbiGenDummyContract; const encodedData = self._strictEncodeArguments('emitSimpleEvent()', []); const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( @@ -2255,6 +2463,10 @@ export class AbiGenDummyContract extends BaseContract { txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase(); } + if (opts.shouldValidate !== false) { + await self.emitSimpleEvent.callAsync(txDataWithDefaults); + } + const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults); return txHash; }, @@ -2267,19 +2479,18 @@ export class AbiGenDummyContract extends BaseContract { */ awaitTransactionSuccessAsync( txData?: Partial, - pollingIntervalMs?: number, - timeoutMs?: number, + opts: AwaitTransactionSuccessOpts = { shouldValidate: true }, ): PromiseWithTransactionHash { const self = (this as any) as AbiGenDummyContract; - const txHashPromise = self.emitSimpleEvent.sendTransactionAsync(txData); + const txHashPromise = self.emitSimpleEvent.sendTransactionAsync(txData, opts); return new PromiseWithTransactionHash( txHashPromise, (async (): Promise => { // When the transaction hash resolves, wait for it to be mined. return self._web3Wrapper.awaitTransactionSuccessAsync( await txHashPromise, - pollingIntervalMs, - timeoutMs, + opts.pollingIntervalMs, + opts.timeoutMs, ); })(), ); @@ -2307,11 +2518,6 @@ export class AbiGenDummyContract extends BaseContract { const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; }, - async validateAndSendTransactionAsync(txData?: Partial | undefined): Promise { - await (this as any).emitSimpleEvent.callAsync(txData); - const txHash = await (this as any).emitSimpleEvent.sendTransactionAsync(txData); - return txHash; - }, /** * Sends a read-only call to the contract method. Returns the result that would happen if one were to send an * Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas @@ -2388,6 +2594,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('emitSimpleEvent()'); + return abiEncoder.getSelector(); + }, }; /** * a method that returns a struct @@ -2417,7 +2631,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2477,6 +2691,14 @@ export class AbiGenDummyContract extends BaseContract { }>(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('structOutput()'); + return abiEncoder.getSelector(); + }, }; public pureFunctionWithConstant = { /** @@ -2499,7 +2721,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2547,6 +2769,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('pureFunctionWithConstant()'); + return abiEncoder.getSelector(); + }, }; /** * Tests decoding when input is not empty but output is empty. @@ -2577,7 +2807,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2626,6 +2856,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('simpleInputNoOutput(uint256)'); + return abiEncoder.getSelector(); + }, }; public overloadedMethod2 = { /** @@ -2649,7 +2887,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2698,6 +2936,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('overloadedMethod(string)'); + return abiEncoder.getSelector(); + }, }; public overloadedMethod1 = { /** @@ -2721,7 +2967,7 @@ export class AbiGenDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -2770,6 +3016,14 @@ export class AbiGenDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as AbiGenDummyContract; + const abiEncoder = self._lookupAbiEncoder('overloadedMethod(int256)'); + return abiEncoder.getSelector(); + }, }; private readonly _subscriptionManager: SubscriptionManager; public static async deployFrom0xArtifactAsync( diff --git a/packages/abi-gen/test-cli/output/typescript/lib_dummy.ts b/packages/abi-gen/test-cli/output/typescript/lib_dummy.ts index 2d71295e25..39d6a9f45e 100644 --- a/packages/abi-gen/test-cli/output/typescript/lib_dummy.ts +++ b/packages/abi-gen/test-cli/output/typescript/lib_dummy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,8 +34,10 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class LibDummyContract extends BaseContract { - public static deployedBytecode = - '0x73000000000000000000000000000000000000000030146080604052600080fdfea265627a7a72305820b14322cd05aa1dcae66812e472d3ab85cced78118ea7f9a5098d073b2accc45964736f6c634300050a0032'; + /** + * @ignore + */ + public static deployedBytecode: string | undefined; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, supportedProvider: SupportedProvider, diff --git a/packages/abi-gen/test-cli/output/typescript/test_lib_dummy.ts b/packages/abi-gen/test-cli/output/typescript/test_lib_dummy.ts index 275781c69c..0af33346f0 100644 --- a/packages/abi-gen/test-cli/output/typescript/test_lib_dummy.ts +++ b/packages/abi-gen/test-cli/output/typescript/test_lib_dummy.ts @@ -1,4 +1,4 @@ -// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma +// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma enum-naming // tslint:disable:whitespace no-unbound-method no-trailing-whitespace // tslint:disable:no-unused-variable import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract'; @@ -18,7 +18,13 @@ import { SupportedProvider, } from 'ethereum-types'; import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils'; -import { SimpleContractArtifact, EventCallback, IndexedFilterValues } from '@0x/types'; +import { + AwaitTransactionSuccessOpts, + EventCallback, + IndexedFilterValues, + SendTransactionOpts, + SimpleContractArtifact, +} from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { assert } from '@0x/assert'; import * as ethers from 'ethers'; @@ -28,6 +34,9 @@ import * as ethers from 'ethers'; // tslint:disable:no-parameter-reassignment // tslint:disable-next-line:class-name export class TestLibDummyContract extends BaseContract { + /** + * @ignore + */ public static deployedBytecode = '0x6080604052348015600f57600080fd5b506004361060325760003560e01c806322935e921460375780632b82fdf0146063575b600080fd5b605160048036036020811015604b57600080fd5b5035607d565b60408051918252519081900360200190f35b605160048036036020811015607757600080fd5b5035608c565b60006086826095565b92915050565b6000608682609c565b6104d20190565b6001019056fea265627a7a72305820ddb720d14b34694daaefebcbd729af6ae04fa2232481812dd8fde63d6a4c32c164736f6c634300050a0032'; public publicAddConstant = { @@ -52,7 +61,7 @@ export class TestLibDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -101,6 +110,14 @@ export class TestLibDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as TestLibDummyContract; + const abiEncoder = self._lookupAbiEncoder('publicAddConstant(uint256)'); + return abiEncoder.getSelector(); + }, }; public publicAddOne = { /** @@ -124,7 +141,7 @@ export class TestLibDummyContract extends BaseContract { let rawCallResult; try { - rawCallResult = await self.evmExecAsync(encodedDataBytes); + rawCallResult = await self._evmExecAsync(encodedDataBytes); } catch (err) { BaseContract._throwIfThrownErrorIsRevertError(err); throw err; @@ -173,6 +190,14 @@ export class TestLibDummyContract extends BaseContract { const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue(returnData); return abiDecodedReturnData; }, + /** + * Returns the 4 byte function selector as a hex string. + */ + getSelector(): string { + const self = (this as any) as TestLibDummyContract; + const abiEncoder = self._lookupAbiEncoder('publicAddOne(uint256)'); + return abiEncoder.getSelector(); + }, }; public static async deployFrom0xArtifactAsync( artifact: ContractArtifact | SimpleContractArtifact, 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 80a4281061..948f909c7a 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 @@ -138,14 +138,6 @@ 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 @@ -284,6 +276,13 @@ describe('AbiGenDummy Contract', () => { expect(decodedOutput, 'decoded output').to.be.deep.equal(output); }); }); + describe('awaitTransactionSuccessAsync', async () => { + it('should successfully call the non pure function', async () => { + expect( + abiGenDummy.nonPureMethod.awaitTransactionSuccessAsync({}, { pollingIntervalMs: 10, timeoutMs: 100 }), + ).to.be.fulfilled(''); + }); + }); }); describe('Lib dummy contract', () => { diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts index 3dc0b96ea1..fd30833756 100644 --- a/packages/asset-buyer/src/asset_buyer.ts +++ b/packages/asset-buyer/src/asset_buyer.ts @@ -267,7 +267,7 @@ export class AssetBuyer { // if no ethAmount is provided, default to the worst ethAmount from buyQuote const value = ethAmount || worstCaseQuoteInfo.totalEthAmount; - const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEth.validateAndSendTransactionAsync( + const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEth.sendTransactionAsync( orders, assetBuyAmount, orders.map(o => o.signature), 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 981513fcf3..a81c2a2cc5 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 @@ -144,7 +144,7 @@ export class ExchangeSwapQuoteConsumer implements SwapQuoteConsumerBase o.signature), @@ -156,7 +156,7 @@ export class ExchangeSwapQuoteConsumer implements SwapQuoteConsumerBase o.signature), 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 f90f30fd0c..f4553572df 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 @@ -197,7 +197,7 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase o.signature), @@ -211,7 +211,7 @@ export class ForwarderSwapQuoteConsumer implements SwapQuoteConsumerBase o.signature), formattedFeePercentage, diff --git a/packages/base-contract/CHANGELOG.json b/packages/base-contract/CHANGELOG.json index 1e11866ef6..c691b66589 100644 --- a/packages/base-contract/CHANGELOG.json +++ b/packages/base-contract/CHANGELOG.json @@ -1,4 +1,17 @@ [ + { + "version": "5.5.0-beta.1", + "changes": [ + { + "note": "Make `evmExecAsync` protected and rename to `_evmExecAsync`", + "pr": 2243 + }, + { + "note": "Remove duplicate types `IndexedFilterValues`, `DecodedLogEvent`, `EventCallback`", + "pr": 2243 + } + ] + }, { "version": "5.5.0-beta.0", "changes": [ diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 2dc978569f..74b9f22c52 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -184,7 +184,7 @@ export class BaseContract { } return rawEncoded; } - public async evmExecAsync(input: Buffer): Promise { + protected async _evmExecAsync(input: Buffer): Promise { const addressBuf = Buffer.from(this.address.substr(2), 'hex'); // should only run once, the first time it is called if (this._evmIfExists === undefined) { diff --git a/packages/base-contract/src/subscription_manager.ts b/packages/base-contract/src/subscription_manager.ts index f6949d4f47..9f0bdd6cc2 100644 --- a/packages/base-contract/src/subscription_manager.ts +++ b/packages/base-contract/src/subscription_manager.ts @@ -13,7 +13,9 @@ import { import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream'; import * as _ from 'lodash'; -import { EventCallback, IndexedFilterValues, SubscriptionErrors } from './types'; +import { EventCallback, IndexedFilterValues } from '@0x/types'; + +import { SubscriptionErrors } from './types'; import { filterUtils } from './utils/filter_utils'; const DEFAULT_BLOCK_POLLING_INTERVAL = 1000; @@ -80,7 +82,7 @@ export class SubscriptionManager; + this._filterCallbacks[filterToken] = callback as EventCallback; // tslint:disable-line:no-unnecessary-type-assertion return filterToken; } public async getLogsAsync( diff --git a/packages/base-contract/src/types.ts b/packages/base-contract/src/types.ts index 28048b7af1..5414dd2090 100644 --- a/packages/base-contract/src/types.ts +++ b/packages/base-contract/src/types.ts @@ -1,15 +1,6 @@ -import { ContractEventArg, DecodedLogArgs, LogEntryEvent, LogWithDecodedArgs } from 'ethereum-types'; +import { LogEntryEvent } from 'ethereum-types'; export type LogEvent = LogEntryEvent; -export interface DecodedLogEvent { - isRemoved: boolean; - log: LogWithDecodedArgs; -} - -export type EventCallback = ( - err: null | Error, - log?: DecodedLogEvent, -) => void; export interface ContractEvent { logIndex: number; @@ -27,7 +18,3 @@ export enum SubscriptionErrors { SubscriptionNotFound = 'SUBSCRIPTION_NOT_FOUND', SubscriptionAlreadyPresent = 'SUBSCRIPTION_ALREADY_PRESENT', } - -export interface IndexedFilterValues { - [index: string]: ContractEventArg; -} diff --git a/packages/contract-addresses/CHANGELOG.json b/packages/contract-addresses/CHANGELOG.json index 6292a31230..0450bcc83d 100644 --- a/packages/contract-addresses/CHANGELOG.json +++ b/packages/contract-addresses/CHANGELOG.json @@ -5,6 +5,14 @@ { "note": "Removed `getNetworkIdByExchangeAddressOrThrow`. It's not needed with V3 tooling.", "pr": 2170 + }, + { + "note": "Add `zrxVault`, `readOnlyProxy`, `staking`, and `stakingProxy` schema with addresses for each tesnet", + "pr": 2224 + }, + { + "note": "Update `assetProxyOwner` address for each testnet", + "pr": 2224 } ], "timestamp": 1570135330 diff --git a/packages/contract-addresses/src/index.ts b/packages/contract-addresses/src/index.ts index 3e66e46fe9..a80bc70cbc 100644 --- a/packages/contract-addresses/src/index.ts +++ b/packages/contract-addresses/src/index.ts @@ -5,6 +5,7 @@ export interface ContractAddresses { erc721Proxy: string; zrxToken: string; etherToken: string; + exchangeV2: string; exchange: string; assetProxyOwner: string; forwarder: string; @@ -16,6 +17,10 @@ export interface ContractAddresses { staticCallProxy: string; erc1155Proxy: string; devUtils: string; + zrxVault: string; + readOnlyProxy: string; + staking: string; + stakingProxy: string; } export enum NetworkId { @@ -30,6 +35,7 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'; const networkToAddresses: { [networkId: number]: ContractAddresses } = { 1: { + exchangeV2: '0x080bf510fcbf18b91105470639e9561022937712', exchange: NULL_ADDRESS, erc20Proxy: '0x95e6f48254609a6ee006f7d493c8e5fb97094cef', erc721Proxy: '0xefc70a1b18c432bdc64b596838b4d138f6bc6cad', @@ -44,6 +50,10 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = { multiAssetProxy: '0xef701d5389ae74503d633396c4d654eabedc9d78', staticCallProxy: '0x3517b88c19508c08650616019062b898ab65ed29', erc1155Proxy: '0x7eefbd48fd63d441ec7435d024ec7c5131019add', + zrxVault: NULL_ADDRESS, + readOnlyProxy: NULL_ADDRESS, + staking: NULL_ADDRESS, + stakingProxy: NULL_ADDRESS, devUtils: NULL_ADDRESS, }, 3: { @@ -51,6 +61,7 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = { erc721Proxy: '0xe654aac058bfbf9f83fcaee7793311dd82f6ddb4', zrxToken: '0xff67881f8d12f372d91baae9752eb3631ff0ed00', etherToken: '0xc778417e063141139fce010982780140aa0cd5ab', + exchangeV2: '0xbff9493f92a3df4b0429b6d00743b3cfb4c85831', exchange: '0x725bc2f8c85ed0289d3da79cde3125d33fc1d7e6', assetProxyOwner: '0xdcf20f7b447d51f2b3e5499b7f6cbbf7295a5d26', forwarder: '0x31c3890769ed3bb30b2781fd238a5bb7ecfeb7c8', @@ -62,8 +73,13 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = { staticCallProxy: '0xe1b97e47aa3796276033a5341e884d2ba46b6ac1', erc1155Proxy: '0x19bb6caa3bc34d39e5a23cedfa3e6c7e7f3c931d', devUtils: '0x3dfd5157eec10eb1a357c1074de30787ce92cb43', + zrxVault: '0xffd161026865ad8b4ab28a76840474935eec4dfa', + readOnlyProxy: '0x8e1dfaf747b804d041adaed79d68dcef85b8de85', + staking: '0xb2ca5824630e526f0f3181a4ea0447c795a84411', + stakingProxy: '0x5d751aa855a1aee5fe44cf5350ed25b5727b66ae', }, 4: { + exchangeV2: '0xbff9493f92a3df4b0429b6d00743b3cfb4c85831', exchange: '0x8e1dfaf747b804d041adaed79d68dcef85b8de85', erc20Proxy: '0x2f5ae4f6106e89b4147651688a92256885c5f410', erc721Proxy: '0x7656d773e11ff7383a14dcf09a9c50990481cd10', @@ -79,12 +95,17 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = { staticCallProxy: '0xe1b97e47aa3796276033a5341e884d2ba46b6ac1', erc1155Proxy: '0x19bb6caa3bc34d39e5a23cedfa3e6c7e7f3c931d', devUtils: '0xcfc66b8e75e8f075c3e1d61e6487d73dfe35d808', + zrxVault: '0xa5bf6ac73bc40790fc6ffc9dbbbce76c9176e224', + readOnlyProxy: '0xffd161026865ad8b4ab28a76840474935eec4dfa', + staking: '0x8ec5a989a06432dace637c8d592727627a45a592', + stakingProxy: '0xb2ca5824630e526f0f3181a4ea0447c795a84411', }, 42: { erc20Proxy: '0xf1ec01d6236d3cd881a0bf0130ea25fe4234003e', erc721Proxy: '0x2a9127c745688a165106c11cd4d647d2220af821', zrxToken: '0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa', etherToken: '0xd0a1e359811322d97991e03f863a0c30c2cf029c', + exchangeV2: '0x30589010550762d2f0d06f650d8e8b6ade6dbf4b', exchange: '0x617602cd3f734cf1e028c96b3f54c0489bed8022', assetProxyOwner: '0x3654e5363cd75c8974c76208137df9691e820e97', forwarder: '0x4c4edb103a6570fa4b58a309d7ff527b7d9f7cf2', @@ -96,6 +117,10 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = { staticCallProxy: '0x48e94bdb9033640d45ea7c721e25f380f8bffa43', erc1155Proxy: '0x64517fa2b480ba3678a2a3c0cf08ef7fd4fad36f', devUtils: '0xb1863ac46ae23ec55d6eeb8ecc8815655ee638a8', + zrxVault: '0xf36eabdfe986b35b62c8fd5a98a7f2aebb79b291', + readOnlyProxy: '0x25397d8aa7e6844dae70ee658fe072d45d6cf528', + staking: '0xd67f2f346f6e85db70632d9f18f50e04192ab54d', + stakingProxy: '0x9e7eef766702c3d9056a3de779e5d9d976bc3bdb', }, // NetworkId 50 represents our Ganache snapshot generated from migrations. 50: { @@ -104,6 +129,7 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = { erc1155Proxy: '0x6a4a62e5a7ed13c361b176a5f62c2ee620ac0df8', zrxToken: '0x871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c', etherToken: '0x0b1ba0af832d7c05fd64161e0db78e85978e8082', + exchangeV2: '0x48bacb9266a570d521063ef5dd96e61686dbe788', exchange: '0x48bacb9266a570d521063ef5dd96e61686dbe788', assetProxyOwner: NULL_ADDRESS, forwarder: NULL_ADDRESS, @@ -114,6 +140,10 @@ const networkToAddresses: { [networkId: number]: ContractAddresses } = { multiAssetProxy: '0xcfc18cec799fbd1793b5c43e773c98d4d61cc2db', staticCallProxy: '0x6dfff22588be9b3ef8cf0ad6dc9b84796f9fb45f', devUtils: '0x38ef19fdf8e8415f18c307ed71967e19aac28ba1', + zrxVault: NULL_ADDRESS, + readOnlyProxy: NULL_ADDRESS, + staking: NULL_ADDRESS, + stakingProxy: NULL_ADDRESS, }, }; diff --git a/packages/contract-artifacts/artifacts/ERC1155Mintable.json b/packages/contract-artifacts/artifacts/ERC1155Mintable.json new file mode 100644 index 0000000000..c406fbe89b --- /dev/null +++ b/packages/contract-artifacts/artifacts/ERC1155Mintable.json @@ -0,0 +1,384 @@ +{ + "schemaVersion": "2.0.0", + "contractName": "ERC1155Mintable", + "compilerOutput": { + "abi": [ + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "operator", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "operator", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256[]", "name": "ids", "type": "uint256[]" }, + { "indexed": false, "internalType": "uint256[]", "name": "values", "type": "uint256[]" } + ], + "name": "TransferBatch", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "operator", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "id", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "TransferSingle", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "string", "name": "value", "type": "string" }, + { "indexed": true, "internalType": "uint256", "name": "id", "type": "uint256" } + ], + "name": "URI", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "ERC1155_BATCH_RECEIVED", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "ERC1155_RECEIVED", + "outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint256", "name": "id", "type": "uint256" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address[]", "name": "owners", "type": "address[]" }, + { "internalType": "uint256[]", "name": "ids", "type": "uint256[]" } + ], + "name": "balanceOfBatch", + "outputs": [{ "internalType": "uint256[]", "name": "balances_", "type": "uint256[]" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "string", "name": "uri", "type": "string" }, + { "internalType": "bool", "name": "isNF", "type": "bool" } + ], + "name": "create", + "outputs": [{ "internalType": "uint256", "name": "type_", "type": "uint256" }], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "uint256", "name": "type_", "type": "uint256" }, + { "internalType": "string", "name": "uri", "type": "string" } + ], + "name": "createWithType", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "creators", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "getNonFungibleBaseType", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "getNonFungibleIndex", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "operator", "type": "address" } + ], + "name": "isApprovedForAll", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "isFungible", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "isNonFungible", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "isNonFungibleBaseType", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "isNonFungibleItem", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "maxIndex", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "address[]", "name": "to", "type": "address[]" }, + { "internalType": "uint256[]", "name": "quantities", "type": "uint256[]" } + ], + "name": "mintFungible", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "uint256", "name": "type_", "type": "uint256" }, + { "internalType": "address[]", "name": "to", "type": "address[]" } + ], + "name": "mintNonFungible", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], + "name": "ownerOf", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256[]", "name": "ids", "type": "uint256[]" }, + { "internalType": "uint256[]", "name": "values", "type": "uint256[]" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "safeBatchTransferFrom", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "id", "type": "uint256" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "safeTransferFrom", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "setApprovalForAll", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } + ], + "devdoc": { + "details": "Mintable form of ERC1155 Shows how easy it is to mint new items", + "methods": { + "balanceOf(address,uint256)": { + "params": { "id": "ID of the Token", "owner": "The address of the token holder" }, + "return": "The _owner's balance of the Token type requested" + }, + "balanceOfBatch(address[],uint256[])": { + "params": { "ids": "ID of the Tokens", "owners": "The addresses of the token holders" }, + "return": "The _owner's balance of the Token types requested" + }, + "create(string,bool)": { + "details": "creates a new token", + "params": { "isNF": "is non-fungible token", "uri": "URI of token" }, + "return": "type_ of token (a unique identifier)" + }, + "createWithType(uint256,string)": { + "details": "creates a new token", + "params": { "type_": "of token", "uri": "URI of token" } + }, + "getNonFungibleBaseType(uint256)": { "details": "Returns base type of non-fungible token" }, + "getNonFungibleIndex(uint256)": { "details": "Returns index of non-fungible token" }, + "isApprovedForAll(address,address)": { + "params": { "operator": "Address of authorized operator", "owner": "The owner of the Tokens" }, + "return": "True if the operator is approved, false if not" + }, + "isFungible(uint256)": { "details": "Returns true if token is fungible" }, + "isNonFungible(uint256)": { "details": "Returns true if token is non-fungible" }, + "isNonFungibleBaseType(uint256)": { + "details": "Returns true if input is base-type of a non-fungible token" + }, + "isNonFungibleItem(uint256)": { "details": "Returns true if input is a non-fungible token" }, + "mintFungible(uint256,address[],uint256[])": { + "details": "mints fungible tokens", + "params": { + "id": "token type", + "quantities": "amounts of minted tokens", + "to": "beneficiaries of minted tokens" + } + }, + "mintNonFungible(uint256,address[])": { + "details": "mints a non-fungible token", + "params": { "to": "beneficiaries of minted tokens", "type_": "token type" } + }, + "ownerOf(uint256)": { "details": "returns owner of a non-fungible token" }, + "safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)": { + "details": "MUST emit TransferBatch event on success. Caller must be approved to manage the _from account's tokens (see isApprovedForAll). MUST throw if `_to` is the zero address. MUST throw if length of `_ids` is not the same as length of `_values`. MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_values` sent. MUST throw on any other error. When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return value is not `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`.", + "params": { + "data": "Additional data with no specified format, sent in call to `_to`", + "from": "Source addresses", + "ids": "IDs of each token type", + "to": "Target addresses", + "values": "Transfer amounts per token type" + } + }, + "safeTransferFrom(address,address,uint256,uint256,bytes)": { + "details": "MUST emit TransferSingle event on success. Caller must be approved to manage the _from account's tokens (see isApprovedForAll). MUST throw if `_to` is the zero address. MUST throw if balance of sender for token `_id` is lower than the `_value` sent. MUST throw on any other error. When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return value is not `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`.", + "params": { + "data": "Additional data with no specified format, sent in call to `_to`", + "from": "Source address", + "id": "ID of the token type", + "to": "Target address", + "value": "Transfer amount" + } + }, + "setApprovalForAll(address,bool)": { + "details": "MUST emit the ApprovalForAll event on success.", + "params": { + "approved": "True if the operator is approved, false to revoke approval", + "operator": "Address to add to the set of authorized operators" + } + } + } + }, + "evm": { + "bytecode": { + "object": "0x608060405234801561001057600080fd5b506125ef806100206000396000f3fe608060405234801561001057600080fd5b50600436106101765760003560e01c80639f4b286a116100d8578063e0a5c9491161008c578063f242432a11610066578063f242432a146107bb578063f94190881461085d578063fc67bf1c146108d457610176565b8063e0a5c94914610726578063e44591f014610763578063e985e9c51461078057610176565b8063adebf6f2116100bd578063adebf6f21461067a578063cc10e40114610697578063cd53d08e1461070957610176565b80639f4b286a146105c8578063a22cb4651461063f57610176565b80636352211e1161012f5780637269a327116101145780637269a327146104c557806378b27221146104e25780639cca1c64146105ab57610176565b80636352211e146104625780636f969c2d146104a857610176565b80632eb2c2d6116101605780632eb2c2d6146101e35780634e1273f41461031f5780635e81b9581461043157610176565b8062fdd58e1461017b57806308d7d469146101c6575b600080fd5b6101b46004803603604081101561019157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356108dc565b60408051918252519081900360200190f35b6101b4600480360360208110156101dc57600080fd5b5035610966565b61031d600480360360a08110156101f957600080fd5b73ffffffffffffffffffffffffffffffffffffffff823581169260208101359091169181019060608101604082013564010000000081111561023a57600080fd5b82018360208201111561024c57600080fd5b8035906020019184602083028401116401000000008311171561026e57600080fd5b91939092909160208101903564010000000081111561028c57600080fd5b82018360208201111561029e57600080fd5b803590602001918460208302840111640100000000831117156102c057600080fd5b9193909290916020810190356401000000008111156102de57600080fd5b8201836020820111156102f057600080fd5b8035906020019184600183028401116401000000008311171561031257600080fd5b509092509050610978565b005b6103e16004803603604081101561033557600080fd5b81019060208101813564010000000081111561035057600080fd5b82018360208201111561036257600080fd5b8035906020019184602083028401116401000000008311171561038457600080fd5b9193909290916020810190356401000000008111156103a257600080fd5b8201836020820111156103b457600080fd5b803590602001918460208302840111640100000000831117156103d657600080fd5b509092509050611192565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561041d578181015183820152602001610405565b505050509050019250505060405180910390f35b61044e6004803603602081101561044757600080fd5b5035611357565b604080519115158252519081900360200190f35b61047f6004803603602081101561047857600080fd5b503561139d565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6101b4600480360360208110156104be57600080fd5b50356113c5565b61044e600480360360208110156104db57600080fd5b50356113ea565b61031d600480360360608110156104f857600080fd5b8135919081019060408101602082013564010000000081111561051a57600080fd5b82018360208201111561052c57600080fd5b8035906020019184602083028401116401000000008311171561054e57600080fd5b91939092909160208101903564010000000081111561056c57600080fd5b82018360208201111561057e57600080fd5b803590602001918460208302840111640100000000831117156105a057600080fd5b50909250905061142f565b6101b4600480360360208110156105c157600080fd5b5035611760565b61031d600480360360408110156105de57600080fd5b8135919081019060408101602082013564010000000081111561060057600080fd5b82018360208201111561061257600080fd5b8035906020019184600183028401116401000000008311171561063457600080fd5b509092509050611775565b61031d6004803603604081101561065557600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001351515611875565b61044e6004803603602081101561069057600080fd5b503561190e565b6101b4600480360360408110156106ad57600080fd5b8101906020810181356401000000008111156106c857600080fd5b8201836020820111156106da57600080fd5b803590602001918460018302840111640100000000831117156106fc57600080fd5b9193509150351515611934565b61047f6004803603602081101561071f57600080fd5b5035611a6d565b61072e611a95565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b61044e6004803603602081101561077957600080fd5b5035611ab9565b61044e6004803603604081101561079657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611ae1565b61031d600480360360a08110156107d157600080fd5b73ffffffffffffffffffffffffffffffffffffffff823581169260208101359091169160408201359160608101359181019060a08101608082013564010000000081111561081e57600080fd5b82018360208201111561083057600080fd5b8035906020019184600183028401116401000000008311171561085257600080fd5b509092509050611b1c565b61031d6004803603604081101561087357600080fd5b8135919081019060408101602082013564010000000081111561089557600080fd5b8201836020820111156108a757600080fd5b803590602001918460208302840111640100000000831117156108c957600080fd5b5090925090506120fb565b61072e61242b565b60006108e782611357565b1561092e5760008281526020819052604090205473ffffffffffffffffffffffffffffffffffffffff848116911614610921576000610924565b60015b60ff169050610960565b50600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff861684529091529020545b92915050565b60056020526000908152604090205481565b73ffffffffffffffffffffffffffffffffffffffff87166109fa57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f43414e4e4f545f5452414e534645525f544f5f414444524553535f5a45524f00604482015290519081900360640190fd5b848314610a6857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f544f4b454e5f414e445f56414c5545535f4c454e4754485f4d49534d41544348604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8816331480610ac1575073ffffffffffffffffffffffffffffffffffffffff8816600090815260026020908152604080832033845290915290205460ff1615156001145b610b2c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f494e53554646494349454e545f414c4c4f57414e434500000000000000000000604482015290519081900360640190fd5b60005b85811015610deb576000878783818110610b4557fe5b9050602002013590506000868684818110610b5c57fe5b905060200201359050610b6e82611ab9565b15610cc85780600114610be257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f414d4f554e545f455155414c5f544f5f4f4e455f524551554952454400000000604482015290519081900360640190fd5b60008281526020819052604090205473ffffffffffffffffffffffffffffffffffffffff8c8116911614610c7757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4e46545f4e4f545f4f574e45445f42595f46524f4d5f41444452455353000000604482015290519081900360640190fd5b600082815260208190526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8c16179055610de1565b600082815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8f168452909152902054610d02908261244f565b6001600084815260200190815260200160002060008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610db06001600084815260200190815260200160002060008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482612473565b600083815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8f1684529091529020555b5050600101610b2f565b508673ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb898989896040518080602001806020018381038352878782818152602001925060200280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169091018481038352858152602090810191508690860280828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039850909650505050505050a4610f1f8773ffffffffffffffffffffffffffffffffffffffff1661248f565b156111885760008773ffffffffffffffffffffffffffffffffffffffff1663bc197c81338b8a8a8a8a8a8a6040518963ffffffff1660e01b8152600401808973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001806020018060200184810384528a8a82818152602001925060200280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169091018581038452888152602090810191508990890280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910185810383528681526020019050868680828437600081840152601f19601f8201169050808301925050509b505050505050505050505050602060405180830381600087803b1580156110a857600080fd5b505af11580156110bc573d6000803e3d6000fd5b505050506040513d60208110156110d257600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167fbc197c81000000000000000000000000000000000000000000000000000000001461118657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b5050505050505050565b60608382146111ec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061256a6024913960400191505060405180910390fd5b604080518581526020808702820101909152848015611215578160200160208202803883390190505b50905060005b8481101561134e57600084848381811061123157fe5b90506020020135905061124381611357565b156112b95786868381811061125457fe5b600084815260208181526040909120549102929092013573ffffffffffffffffffffffffffffffffffffffff9081169216919091149050611296576000611299565b60015b60ff168383815181106112a857fe5b602002602001018181525050611345565b6000818152600160205260408120908888858181106112d457fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483838151811061133857fe5b6020026020010181815250505b5060010161121b565b50949350505050565b60007f80000000000000000000000000000000000000000000000000000000000000008083161480156109605750506fffffffffffffffffffffffffffffffff16151590565b60009081526020819052604090205473ffffffffffffffffffffffffffffffffffffffff1690565b7fffffffffffffffffffffffffffffffff000000000000000000000000000000001690565b60007f80000000000000000000000000000000000000000000000000000000000000008083161480156109605750506fffffffffffffffffffffffffffffffff161590565b600085815260046020526040902054859073ffffffffffffffffffffffffffffffffffffffff16331461146157600080fd5b61146a8661190e565b6114bf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d81526020018061258e602d913960400191505060405180910390fd5b60005b848110156117575760008686838181106114d857fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff169050600085858481811061150557fe5b60008c815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8916845282529091205491029290920135925061154a91839150612473565b60008a815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083528184209490945580518d8152918201859052805133927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6292908290030190a46115d68273ffffffffffffffffffffffffffffffffffffffff1661248f565b1561174d57604080517ff23a6e6100000000000000000000000000000000000000000000000000000000815233600482018190526024820152604481018b90526064810183905260a06084820152600060a48201819052915173ffffffffffffffffffffffffffffffffffffffff85169163f23a6e619160e480830192602092919082900301818787803b15801561166d57600080fd5b505af1158015611681573d6000803e3d6000fd5b505050506040513d602081101561169757600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e61000000000000000000000000000000000000000000000000000000001461174b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b50506001016114c2565b50505050505050565b6fffffffffffffffffffffffffffffffff1690565b600083815260046020908152604080832080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163390811790915581518781529283018490528151849391927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62928290030190a4801561187057827f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b838360405180806020018281038252848482818152602001925080828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039550909350505050a25b505050565b33600081815260026020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016861515908117909155815190815290519293927f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31929181900390910190a35050565b7f8000000000000000000000000000000000000000000000000000000000000000161590565b600380546001019081905560801b811561196b577f8000000000000000000000000000000000000000000000000000000000000000175b600081815260046020908152604080832080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163390811790915581518581529283018490528151849391927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62928290030190a48215611a6657807f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b858560405180806020018281038252848482818152602001925080828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039550909350505050a25b9392505050565b60046020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b7ff23a6e610000000000000000000000000000000000000000000000000000000081565b7f80000000000000000000000000000000000000000000000000000000000000009081161490565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260026020908152604080832093909416825291909152205460ff1690565b73ffffffffffffffffffffffffffffffffffffffff8516611b9e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f43414e4e4f545f5452414e534645525f544f5f414444524553535f5a45524f00604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8616331480611bf7575073ffffffffffffffffffffffffffffffffffffffff8616600090815260026020908152604080832033845290915290205460ff1615156001145b611c6257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f494e53554646494349454e545f414c4c4f57414e434500000000000000000000604482015290519081900360640190fd5b611c6b84611ab9565b15611dc55782600114611cdf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f414d4f554e545f455155414c5f544f5f4f4e455f524551554952454400000000604482015290519081900360640190fd5b60008481526020819052604090205473ffffffffffffffffffffffffffffffffffffffff878116911614611d7457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4e46545f4e4f545f4f574e45445f42595f46524f4d5f41444452455353000000604482015290519081900360640190fd5b600084815260208190526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8716179055611e74565b600084815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8a168452909152902054611dff908461244f565b600085815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8b81168552925280832093909355871681522054611e439084612473565b600085815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8a1684529091529020555b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628787604051808381526020018281526020019250505060405180910390a4611f178573ffffffffffffffffffffffffffffffffffffffff1661248f565b156120f35760008573ffffffffffffffffffffffffffffffffffffffff1663f23a6e613389888888886040518763ffffffff1660e01b8152600401808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f820116905080830192505050975050505050505050602060405180830381600087803b15801561201557600080fd5b505af1158015612029573d6000803e3d6000fd5b505050506040513d602081101561203f57600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e61000000000000000000000000000000000000000000000000000000001461175757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505050505050565b600083815260046020526040902054839073ffffffffffffffffffffffffffffffffffffffff16331461212d57600080fd5b61213684611ab9565b61218b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d81526020018061253d602d913960400191505060405180910390fd5b600084815260056020526040812054600101905b838110156123f75760008585838181106121b557fe5b8486018a176000818152602081815260408083208054958302979097013573ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffff00000000000000000000000000000000000000009095168517909655855183815260019181019190915285519396509194869450909233927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6292908290030190a46122768273ffffffffffffffffffffffffffffffffffffffff1661248f565b156123ed57604080517ff23a6e6100000000000000000000000000000000000000000000000000000000815233600482018190526024820152604481018390526001606482015260a06084820152600060a48201819052915173ffffffffffffffffffffffffffffffffffffffff85169163f23a6e619160e480830192602092919082900301818787803b15801561230d57600080fd5b505af1158015612321573d6000803e3d6000fd5b505050506040513d602081101561233757600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e6100000000000000000000000000000000000000000000000000000000146123eb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b505060010161219f565b50600085815260056020526040902054612412908490612473565b6000958652600560205260409095209490945550505050565b7fbc197c810000000000000000000000000000000000000000000000000000000081565b60008282111561246d5761246d61246860028585612495565b612534565b50900390565b600082820183811015611a6657611a6661246860008686612495565b3b151590565b606063e946c1bb60e01b848484604051602401808460038111156124b557fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090509392505050565b805160208201fdfe54524945445f544f5f4d494e545f4e4f4e5f46554e4749424c455f464f525f46554e4749424c455f544f4b454e4f574e4552535f414e445f4944535f4d5553545f484156455f53414d455f4c454e47544854524945445f544f5f4d494e545f46554e4749424c455f464f525f4e4f4e5f46554e4749424c455f544f4b454ea265627a7a723158205af7d187cbffb255b374d24e5838a04f6b3a3245622025907396b2a61f9d93da64736f6c634300050c0032" + }, + "deployedBytecode": { + "object": "0x608060405234801561001057600080fd5b50600436106101765760003560e01c80639f4b286a116100d8578063e0a5c9491161008c578063f242432a11610066578063f242432a146107bb578063f94190881461085d578063fc67bf1c146108d457610176565b8063e0a5c94914610726578063e44591f014610763578063e985e9c51461078057610176565b8063adebf6f2116100bd578063adebf6f21461067a578063cc10e40114610697578063cd53d08e1461070957610176565b80639f4b286a146105c8578063a22cb4651461063f57610176565b80636352211e1161012f5780637269a327116101145780637269a327146104c557806378b27221146104e25780639cca1c64146105ab57610176565b80636352211e146104625780636f969c2d146104a857610176565b80632eb2c2d6116101605780632eb2c2d6146101e35780634e1273f41461031f5780635e81b9581461043157610176565b8062fdd58e1461017b57806308d7d469146101c6575b600080fd5b6101b46004803603604081101561019157600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356108dc565b60408051918252519081900360200190f35b6101b4600480360360208110156101dc57600080fd5b5035610966565b61031d600480360360a08110156101f957600080fd5b73ffffffffffffffffffffffffffffffffffffffff823581169260208101359091169181019060608101604082013564010000000081111561023a57600080fd5b82018360208201111561024c57600080fd5b8035906020019184602083028401116401000000008311171561026e57600080fd5b91939092909160208101903564010000000081111561028c57600080fd5b82018360208201111561029e57600080fd5b803590602001918460208302840111640100000000831117156102c057600080fd5b9193909290916020810190356401000000008111156102de57600080fd5b8201836020820111156102f057600080fd5b8035906020019184600183028401116401000000008311171561031257600080fd5b509092509050610978565b005b6103e16004803603604081101561033557600080fd5b81019060208101813564010000000081111561035057600080fd5b82018360208201111561036257600080fd5b8035906020019184602083028401116401000000008311171561038457600080fd5b9193909290916020810190356401000000008111156103a257600080fd5b8201836020820111156103b457600080fd5b803590602001918460208302840111640100000000831117156103d657600080fd5b509092509050611192565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561041d578181015183820152602001610405565b505050509050019250505060405180910390f35b61044e6004803603602081101561044757600080fd5b5035611357565b604080519115158252519081900360200190f35b61047f6004803603602081101561047857600080fd5b503561139d565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6101b4600480360360208110156104be57600080fd5b50356113c5565b61044e600480360360208110156104db57600080fd5b50356113ea565b61031d600480360360608110156104f857600080fd5b8135919081019060408101602082013564010000000081111561051a57600080fd5b82018360208201111561052c57600080fd5b8035906020019184602083028401116401000000008311171561054e57600080fd5b91939092909160208101903564010000000081111561056c57600080fd5b82018360208201111561057e57600080fd5b803590602001918460208302840111640100000000831117156105a057600080fd5b50909250905061142f565b6101b4600480360360208110156105c157600080fd5b5035611760565b61031d600480360360408110156105de57600080fd5b8135919081019060408101602082013564010000000081111561060057600080fd5b82018360208201111561061257600080fd5b8035906020019184600183028401116401000000008311171561063457600080fd5b509092509050611775565b61031d6004803603604081101561065557600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001351515611875565b61044e6004803603602081101561069057600080fd5b503561190e565b6101b4600480360360408110156106ad57600080fd5b8101906020810181356401000000008111156106c857600080fd5b8201836020820111156106da57600080fd5b803590602001918460018302840111640100000000831117156106fc57600080fd5b9193509150351515611934565b61047f6004803603602081101561071f57600080fd5b5035611a6d565b61072e611a95565b604080517fffffffff000000000000000000000000000000000000000000000000000000009092168252519081900360200190f35b61044e6004803603602081101561077957600080fd5b5035611ab9565b61044e6004803603604081101561079657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611ae1565b61031d600480360360a08110156107d157600080fd5b73ffffffffffffffffffffffffffffffffffffffff823581169260208101359091169160408201359160608101359181019060a08101608082013564010000000081111561081e57600080fd5b82018360208201111561083057600080fd5b8035906020019184600183028401116401000000008311171561085257600080fd5b509092509050611b1c565b61031d6004803603604081101561087357600080fd5b8135919081019060408101602082013564010000000081111561089557600080fd5b8201836020820111156108a757600080fd5b803590602001918460208302840111640100000000831117156108c957600080fd5b5090925090506120fb565b61072e61242b565b60006108e782611357565b1561092e5760008281526020819052604090205473ffffffffffffffffffffffffffffffffffffffff848116911614610921576000610924565b60015b60ff169050610960565b50600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff861684529091529020545b92915050565b60056020526000908152604090205481565b73ffffffffffffffffffffffffffffffffffffffff87166109fa57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f43414e4e4f545f5452414e534645525f544f5f414444524553535f5a45524f00604482015290519081900360640190fd5b848314610a6857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f544f4b454e5f414e445f56414c5545535f4c454e4754485f4d49534d41544348604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8816331480610ac1575073ffffffffffffffffffffffffffffffffffffffff8816600090815260026020908152604080832033845290915290205460ff1615156001145b610b2c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f494e53554646494349454e545f414c4c4f57414e434500000000000000000000604482015290519081900360640190fd5b60005b85811015610deb576000878783818110610b4557fe5b9050602002013590506000868684818110610b5c57fe5b905060200201359050610b6e82611ab9565b15610cc85780600114610be257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f414d4f554e545f455155414c5f544f5f4f4e455f524551554952454400000000604482015290519081900360640190fd5b60008281526020819052604090205473ffffffffffffffffffffffffffffffffffffffff8c8116911614610c7757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4e46545f4e4f545f4f574e45445f42595f46524f4d5f41444452455353000000604482015290519081900360640190fd5b600082815260208190526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8c16179055610de1565b600082815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8f168452909152902054610d02908261244f565b6001600084815260200190815260200160002060008d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610db06001600084815260200190815260200160002060008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482612473565b600083815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8f1684529091529020555b5050600101610b2f565b508673ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb898989896040518080602001806020018381038352878782818152602001925060200280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169091018481038352858152602090810191508690860280828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039850909650505050505050a4610f1f8773ffffffffffffffffffffffffffffffffffffffff1661248f565b156111885760008773ffffffffffffffffffffffffffffffffffffffff1663bc197c81338b8a8a8a8a8a8a6040518963ffffffff1660e01b8152600401808973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001806020018060200184810384528a8a82818152602001925060200280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169091018581038452888152602090810191508990890280828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910185810383528681526020019050868680828437600081840152601f19601f8201169050808301925050509b505050505050505050505050602060405180830381600087803b1580156110a857600080fd5b505af11580156110bc573d6000803e3d6000fd5b505050506040513d60208110156110d257600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167fbc197c81000000000000000000000000000000000000000000000000000000001461118657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b5050505050505050565b60608382146111ec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602481526020018061256a6024913960400191505060405180910390fd5b604080518581526020808702820101909152848015611215578160200160208202803883390190505b50905060005b8481101561134e57600084848381811061123157fe5b90506020020135905061124381611357565b156112b95786868381811061125457fe5b600084815260208181526040909120549102929092013573ffffffffffffffffffffffffffffffffffffffff9081169216919091149050611296576000611299565b60015b60ff168383815181106112a857fe5b602002602001018181525050611345565b6000818152600160205260408120908888858181106112d457fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205483838151811061133857fe5b6020026020010181815250505b5060010161121b565b50949350505050565b60007f80000000000000000000000000000000000000000000000000000000000000008083161480156109605750506fffffffffffffffffffffffffffffffff16151590565b60009081526020819052604090205473ffffffffffffffffffffffffffffffffffffffff1690565b7fffffffffffffffffffffffffffffffff000000000000000000000000000000001690565b60007f80000000000000000000000000000000000000000000000000000000000000008083161480156109605750506fffffffffffffffffffffffffffffffff161590565b600085815260046020526040902054859073ffffffffffffffffffffffffffffffffffffffff16331461146157600080fd5b61146a8661190e565b6114bf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d81526020018061258e602d913960400191505060405180910390fd5b60005b848110156117575760008686838181106114d857fe5b9050602002013573ffffffffffffffffffffffffffffffffffffffff169050600085858481811061150557fe5b60008c815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8916845282529091205491029290920135925061154a91839150612473565b60008a815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083528184209490945580518d8152918201859052805133927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6292908290030190a46115d68273ffffffffffffffffffffffffffffffffffffffff1661248f565b1561174d57604080517ff23a6e6100000000000000000000000000000000000000000000000000000000815233600482018190526024820152604481018b90526064810183905260a06084820152600060a48201819052915173ffffffffffffffffffffffffffffffffffffffff85169163f23a6e619160e480830192602092919082900301818787803b15801561166d57600080fd5b505af1158015611681573d6000803e3d6000fd5b505050506040513d602081101561169757600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e61000000000000000000000000000000000000000000000000000000001461174b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b50506001016114c2565b50505050505050565b6fffffffffffffffffffffffffffffffff1690565b600083815260046020908152604080832080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163390811790915581518781529283018490528151849391927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62928290030190a4801561187057827f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b838360405180806020018281038252848482818152602001925080828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039550909350505050a25b505050565b33600081815260026020908152604080832073ffffffffffffffffffffffffffffffffffffffff87168085529083529281902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016861515908117909155815190815290519293927f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31929181900390910190a35050565b7f8000000000000000000000000000000000000000000000000000000000000000161590565b600380546001019081905560801b811561196b577f8000000000000000000000000000000000000000000000000000000000000000175b600081815260046020908152604080832080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163390811790915581518581529283018490528151849391927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62928290030190a48215611a6657807f6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b858560405180806020018281038252848482818152602001925080828437600083820152604051601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018290039550909350505050a25b9392505050565b60046020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b7ff23a6e610000000000000000000000000000000000000000000000000000000081565b7f80000000000000000000000000000000000000000000000000000000000000009081161490565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260026020908152604080832093909416825291909152205460ff1690565b73ffffffffffffffffffffffffffffffffffffffff8516611b9e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f43414e4e4f545f5452414e534645525f544f5f414444524553535f5a45524f00604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff8616331480611bf7575073ffffffffffffffffffffffffffffffffffffffff8616600090815260026020908152604080832033845290915290205460ff1615156001145b611c6257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f494e53554646494349454e545f414c4c4f57414e434500000000000000000000604482015290519081900360640190fd5b611c6b84611ab9565b15611dc55782600114611cdf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f414d4f554e545f455155414c5f544f5f4f4e455f524551554952454400000000604482015290519081900360640190fd5b60008481526020819052604090205473ffffffffffffffffffffffffffffffffffffffff878116911614611d7457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4e46545f4e4f545f4f574e45445f42595f46524f4d5f41444452455353000000604482015290519081900360640190fd5b600084815260208190526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8716179055611e74565b600084815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8a168452909152902054611dff908461244f565b600085815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8b81168552925280832093909355871681522054611e439084612473565b600085815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8a1684529091529020555b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f628787604051808381526020018281526020019250505060405180910390a4611f178573ffffffffffffffffffffffffffffffffffffffff1661248f565b156120f35760008573ffffffffffffffffffffffffffffffffffffffff1663f23a6e613389888888886040518763ffffffff1660e01b8152600401808773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f820116905080830192505050975050505050505050602060405180830381600087803b15801561201557600080fd5b505af1158015612029573d6000803e3d6000fd5b505050506040513d602081101561203f57600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e61000000000000000000000000000000000000000000000000000000001461175757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505050505050565b600083815260046020526040902054839073ffffffffffffffffffffffffffffffffffffffff16331461212d57600080fd5b61213684611ab9565b61218b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602d81526020018061253d602d913960400191505060405180910390fd5b600084815260056020526040812054600101905b838110156123f75760008585838181106121b557fe5b8486018a176000818152602081815260408083208054958302979097013573ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffff00000000000000000000000000000000000000009095168517909655855183815260019181019190915285519396509194869450909233927fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6292908290030190a46122768273ffffffffffffffffffffffffffffffffffffffff1661248f565b156123ed57604080517ff23a6e6100000000000000000000000000000000000000000000000000000000815233600482018190526024820152604481018390526001606482015260a06084820152600060a48201819052915173ffffffffffffffffffffffffffffffffffffffff85169163f23a6e619160e480830192602092919082900301818787803b15801561230d57600080fd5b505af1158015612321573d6000803e3d6000fd5b505050506040513d602081101561233757600080fd5b505190507fffffffff0000000000000000000000000000000000000000000000000000000081167ff23a6e6100000000000000000000000000000000000000000000000000000000146123eb57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4241445f52454345495645525f52455455524e5f56414c554500000000000000604482015290519081900360640190fd5b505b505060010161219f565b50600085815260056020526040902054612412908490612473565b6000958652600560205260409095209490945550505050565b7fbc197c810000000000000000000000000000000000000000000000000000000081565b60008282111561246d5761246d61246860028585612495565b612534565b50900390565b600082820183811015611a6657611a6661246860008686612495565b3b151590565b606063e946c1bb60e01b848484604051602401808460038111156124b557fe5b60ff1681526020018381526020018281526020019350505050604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090509392505050565b805160208201fdfe54524945445f544f5f4d494e545f4e4f4e5f46554e4749424c455f464f525f46554e4749424c455f544f4b454e4f574e4552535f414e445f4944535f4d5553545f484156455f53414d455f4c454e47544854524945445f544f5f4d494e545f46554e4749424c455f464f525f4e4f4e5f46554e4749424c455f544f4b454ea265627a7a723158205af7d187cbffb255b374d24e5838a04f6b3a3245622025907396b2a61f9d93da64736f6c634300050c0032" + } + } + }, + "compiler": { + "name": "solc", + "version": "soljson-v0.5.12+commit.7709ece9.js", + "settings": { + "optimizer": { + "enabled": true, + "runs": 1000000, + "details": { "yul": true, "deduplicate": true, "cse": true, "constantOptimizer": true } + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "devdoc", + "evm.bytecode.object", + "evm.bytecode.sourceMap", + "evm.deployedBytecode.object", + "evm.deployedBytecode.sourceMap" + ] + } + }, + "evmVersion": "constantinople" + } + }, + "networks": {} +} diff --git a/packages/contract-artifacts/src/index.ts b/packages/contract-artifacts/src/index.ts index a1a5db3b8d..7917b556b7 100644 --- a/packages/contract-artifacts/src/index.ts +++ b/packages/contract-artifacts/src/index.ts @@ -5,6 +5,7 @@ import * as DevUtils from '../artifacts/DevUtils.json'; import * as DummyERC20Token from '../artifacts/DummyERC20Token.json'; import * as DummyERC721Token from '../artifacts/DummyERC721Token.json'; import * as DutchAuction from '../artifacts/DutchAuction.json'; +import * as ERC1155Mintable from '../artifacts/ERC1155Mintable.json'; import * as ERC1155Proxy from '../artifacts/ERC1155Proxy.json'; import * as ERC20Proxy from '../artifacts/ERC20Proxy.json'; import * as ERC20Token from '../artifacts/ERC20Token.json'; @@ -28,6 +29,7 @@ export { DevUtils, DummyERC20Token, DummyERC721Token, + ERC1155Mintable, ERC1155Proxy, ERC20Proxy, ERC20Token, diff --git a/packages/contract-artifacts/tsconfig.json b/packages/contract-artifacts/tsconfig.json index 7d339682c3..6dcc87100e 100644 --- a/packages/contract-artifacts/tsconfig.json +++ b/packages/contract-artifacts/tsconfig.json @@ -12,6 +12,7 @@ "./artifacts/DutchAuction.json", "./artifacts/DummyERC20Token.json", "./artifacts/DummyERC721Token.json", + "./artifacts/ERC1155Mintable.json", "./artifacts/ERC20Proxy.json", "./artifacts/ERC20Token.json", "./artifacts/ERC721Proxy.json", diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index 9da6d1ace8..96d46327cd 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -154,6 +154,8 @@ export { SignedZeroExTransaction, SimpleEvmOutput, SimpleEvmBytecodeOutput, + AwaitTransactionSuccessOpts, + SendTransactionOpts, EIP712DomainWithDefaultSchema, EventCallback, DecodedLogEvent, diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index 048e08981d..5ac052858c 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -40,6 +40,7 @@ export interface ContractWrappersConfig { blockPollingIntervalMs?: number; } +// TODO(xianny): remove after refactoring coordinator wrapper /** * gasPrice: Gas price in Wei to use for a transaction * gasLimit: The amount of gas to send with a transaction (in Gwei) @@ -51,6 +52,7 @@ export interface TransactionOpts { nonce?: number; } +// TODO(xianny): remove after refactoring coordinator wrapper /** * shouldValidate: Flag indicating whether the library should make attempts to validate a transaction before * broadcasting it. For example, order has a valid signature, maker has sufficient funds, etc. Default=true. diff --git a/packages/migrations/Dockerfile b/packages/migrations/Dockerfile index 80586edabf..05f8cca30f 100644 --- a/packages/migrations/Dockerfile +++ b/packages/migrations/Dockerfile @@ -2,7 +2,7 @@ FROM mhart/alpine-node:10 WORKDIR /usr/src/app -RUN npm install -g ganache-cli@6.4.1 +RUN npm install -g ganache-cli@6.7.0 ENV MNEMONIC "concert load couple harbor equip island argue ramp clarify fence smart topic" ENV NETWORK_ID 50 diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 548e739b20..873377b56e 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -55,6 +55,10 @@ "yargs": "^10.0.3" }, "dependencies": { + "@0x/contracts-multisig": "^3.2.0-beta.0", + "@0x/contracts-staking": "^1.1.0-beta.0", + "@0x/contracts-exchange": "^2.2.0-beta.0", + "@0x/contracts-utils": "^3.3.0-beta.0", "@0x/abi-gen-wrappers": "^5.4.0-beta.0", "@0x/base-contract": "^5.5.0-beta.0", "@0x/contract-addresses": "^3.3.0-beta.0", diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index db3a1a7239..994c8c2bd4 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -7,6 +7,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper'; import { MethodAbi, SupportedProvider, TxData } from 'ethereum-types'; import * as _ from 'lodash'; +import { constants } from './utils/constants'; import { erc20TokenInfo, erc721TokenInfo } from './utils/token_info'; // HACK (xianny): Copied from @0x/order-utils to get rid of circular dependency @@ -142,58 +143,26 @@ export async function runMigrationsAsync( artifacts, ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc1155Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, txDefaults), - ); + await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, txDefaults); + await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, txDefaults); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, txDefaults); + await multiAssetProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, txDefaults); // MultiAssetProxy - await web3Wrapper.awaitTransactionSuccessAsync( - await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc1155Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc721Proxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc1155Proxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await multiAssetProxy.registerAssetProxy.sendTransactionAsync(staticCallProxy.address, txDefaults), - ); + await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, txDefaults); + await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, txDefaults); + await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, txDefaults); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, txDefaults); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, txDefaults); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc1155Proxy.address, txDefaults); + await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(staticCallProxy.address, txDefaults); // Register the Asset Proxies to the Exchange - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(erc721Proxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(erc1155Proxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(multiAssetProxy.address, txDefaults), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(staticCallProxy.address, txDefaults), - ); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, txDefaults); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, txDefaults); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(erc1155Proxy.address, txDefaults); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(multiAssetProxy.address, txDefaults); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(staticCallProxy.address, txDefaults); // Forwarder const forwarder = await wrappers.ForwarderContract.deployFrom0xArtifactAsync( @@ -270,9 +239,7 @@ export async function runMigrationsAsync( // Fund the Forwarder with ZRX const zrxDecimals = await zrxToken.decimals.callAsync(); const zrxForwarderAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(5000), zrxDecimals); - await web3Wrapper.awaitTransactionSuccessAsync( - await zrxToken.transfer.sendTransactionAsync(forwarder.address, zrxForwarderAmount, txDefaults), - ); + await zrxToken.transfer.awaitTransactionSuccessAsync(forwarder.address, zrxForwarderAmount, txDefaults); // CoordinatorRegistry const coordinatorRegistry = await wrappers.CoordinatorRegistryContract.deployFrom0xArtifactAsync( @@ -300,6 +267,14 @@ export async function runMigrationsAsync( exchange.address, ); + // tslint:disable-next-line:no-unused-variable + const erc1155DummyToken = await wrappers.ERC1155MintableContract.deployFrom0xArtifactAsync( + artifacts.ERC1155Mintable, + provider, + txDefaults, + artifacts, + ); + const contractAddresses = { erc20Proxy: erc20Proxy.address, erc721Proxy: erc721Proxy.address, @@ -308,7 +283,7 @@ export async function runMigrationsAsync( etherToken: etherToken.address, exchange: exchange.address, // TODO (xianny): figure out how to deploy AssetProxyOwnerContract - assetProxyOwner: '0x0000000000000000000000000000000000000000', + assetProxyOwner: constants.NULL_ADDRESS, forwarder: forwarder.address, orderValidator: orderValidator.address, dutchAuction: dutchAuction.address, @@ -317,6 +292,11 @@ export async function runMigrationsAsync( multiAssetProxy: multiAssetProxy.address, staticCallProxy: staticCallProxy.address, devUtils: devUtils.address, + exchangeV2: constants.NULL_ADDRESS, + zrxVault: constants.NULL_ADDRESS, + readOnlyProxy: constants.NULL_ADDRESS, + staking: constants.NULL_ADDRESS, + stakingProxy: constants.NULL_ADDRESS, }; return contractAddresses; diff --git a/packages/migrations/src/test_contract_configs.ts b/packages/migrations/src/test_contract_configs.ts index 08ad3cfe4e..f22a601131 100644 --- a/packages/migrations/src/test_contract_configs.ts +++ b/packages/migrations/src/test_contract_configs.ts @@ -1,6 +1,8 @@ #!/usr/bin/env node import * as wrappers from '@0x/abi-gen-wrappers'; import { getContractAddressesForNetworkOrThrow } from '@0x/contract-addresses'; +import { ExchangeContract } from '@0x/contracts-exchange'; +import { StakingContract, StakingProxyContract, ZrxVaultContract } from '@0x/contracts-staking'; import { EmptyWalletSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders'; import { AssetProxyId } from '@0x/types'; import { logUtils, providerUtils } from '@0x/utils'; @@ -8,13 +10,16 @@ import { Web3Wrapper } from '@0x/web3-wrapper'; import { SupportedProvider } from 'ethereum-types'; // NOTE: add your own Infura Project ID to RPC urls before running +const INFURA_PROJECT_ID = ''; + const networkIdToRpcUrl = { - 1: 'https://mainnet.infura.io/v3/', - 3: 'https://ropsten.infura.io/v3/', - 4: 'https://rinkeby.infura.io/v3/', - 42: 'https://kovan.infura.io/v3/', + 1: `https://mainnet.infura.io/v3/${INFURA_PROJECT_ID}`, + 3: `https://ropsten.infura.io/v3/${INFURA_PROJECT_ID}`, + 4: `https://rinkeby.infura.io/v3/${INFURA_PROJECT_ID}`, + 42: `https://kovan.infura.io/v3/${INFURA_PROJECT_ID}`, }; +// tslint:disable:custom-no-magic-numbers async function testContractConfigsAsync(provider: SupportedProvider): Promise { const web3Wrapper = new Web3Wrapper(provider); const networkId = await web3Wrapper.getNetworkIdAsync(); @@ -26,140 +31,235 @@ async function testContractConfigsAsync(provider: SupportedProvider): Promise { + const exchangeOwner = await exchangeV2.owner.callAsync(); + warnIfMismatch(exchangeOwner, assetProxyOwner.address, 'Unexpected ExchangeV2 owner'); + + const registeredERC20Proxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.ERC20); + warnIfMismatch(registeredERC20Proxy, erc20Proxy.address, 'Unexpected ERC20Proxy registered in ExchangeV2'); + + const registeredERC721Proxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.ERC721); + warnIfMismatch(registeredERC721Proxy, erc721Proxy.address, 'Unexpected ERC721Proxy registered in ExchangeV2'); + + const registeredERC1155Proxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.ERC1155); + warnIfMismatch( + registeredERC1155Proxy, + erc1155Proxy.address, + 'Unexpected ERC1155Proxy registered in ExchangeV2', + ); + + const registeredMultiAssetProxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.MultiAsset); + warnIfMismatch( + registeredMultiAssetProxy, + multiAssetProxy.address, + 'Unexpected MultiAssetProxy registered in ExchangeV2', + ); + + const registeredStaticCallProxy = await exchangeV2.getAssetProxy.callAsync(AssetProxyId.StaticCall); + warnIfMismatch( + registeredStaticCallProxy, + addresses.staticCallProxy, + 'Unexpected StaticCallProxy registered in ExchangeV2', + ); + } + + async function verifyExchangeV3ConfigsAsync(): Promise { + const exchangeOwner = await exchange.owner.callAsync(); + warnIfMismatch(exchangeOwner, assetProxyOwner.address, 'Unexpected Exchange owner'); + + const registeredERC20Proxy = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC20); + warnIfMismatch(registeredERC20Proxy, erc20Proxy.address, 'Unexpected ERC20Proxy registered in Exchange'); + + const registeredERC721Proxy = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC721); + warnIfMismatch(registeredERC721Proxy, erc721Proxy.address, 'Unexpected ERC721Proxy registered in Exchange'); + + const registeredERC1155Proxy = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC1155); + warnIfMismatch(registeredERC1155Proxy, erc1155Proxy.address, 'Unexpected ERC1155Proxy registered in Exchange'); + + const registeredMultiAssetProxy = await exchange.getAssetProxy.callAsync(AssetProxyId.MultiAsset); + warnIfMismatch( + registeredMultiAssetProxy, + multiAssetProxy.address, + 'Unexpected MultiAssetProxy registered in Exchange', + ); + + const registeredStaticCallProxy = await exchange.getAssetProxy.callAsync(AssetProxyId.StaticCall); + warnIfMismatch( + registeredStaticCallProxy, + addresses.staticCallProxy, + 'Unexpected StaticCallProxy registered in Exchange', + ); + + const protocolFeeCollector = await exchange.protocolFeeCollector.callAsync(); + warnIfMismatch(protocolFeeCollector, addresses.stakingProxy, 'Unexpected StakingProxy attached to Exchange'); + + const protocolFeeMultiplier = await exchange.protocolFeeMultiplier.callAsync(); + warnIfMismatch(protocolFeeMultiplier.toString(), '150000', 'Unexpected protocolFeeMultiplier in Exchange'); + } + + async function verifyAssetProxyConfigsAsync(): Promise { + // Verify ERC20Proxy configs + const erc20ProxyOwner = await erc20Proxy.owner.callAsync(); + warnIfMismatch(erc20ProxyOwner, assetProxyOwner.address, 'Unexpected ERC20Proxy owner'); + + const erc20AuthorizedAddresses = await erc20Proxy.getAuthorizedAddresses.callAsync(); + warnIfMismatch(erc20AuthorizedAddresses.length, 4, 'Unexpected number of authorized addresses in ERC20Proxy'); + + const isExchangeV2AuthorizedInERC20Proxy = await erc20Proxy.authorized.callAsync(exchangeV2.address); + warnIfMismatch(isExchangeV2AuthorizedInERC20Proxy, true, 'ExchangeV2 not authorized in ERC20Proxy'); + + const isExchangeAuthorizedInERC20Proxy = await erc20Proxy.authorized.callAsync(exchange.address); + warnIfMismatch(isExchangeAuthorizedInERC20Proxy, true, 'Exchange not authorized in ERC20Proxy'); + + const isMAPAuthorizedInER20Proxy = await erc20Proxy.authorized.callAsync(multiAssetProxy.address); + warnIfMismatch(isMAPAuthorizedInER20Proxy, true, 'MultiAssetProxy not authorized in ERC20Proxy'); + + const isZrxVaultAuthorizedInER20Proxy = await erc20Proxy.authorized.callAsync(zrxVault.address); + warnIfMismatch(isZrxVaultAuthorizedInER20Proxy, true, 'ZrxVault not authorized in ERC20Proxy'); + + // Verify ERC721Proxy configs + const erc721ProxyOwner = await erc721Proxy.owner.callAsync(); + warnIfMismatch(erc721ProxyOwner, assetProxyOwner.address, 'Unexpected ERC721Proxy owner'); + + const erc721AuthorizedAddresses = await erc721Proxy.getAuthorizedAddresses.callAsync(); + warnIfMismatch(erc721AuthorizedAddresses.length, 3, 'Unexpected number of authorized addresses in ERC721Proxy'); + + const isExchangeV2AuthorizedInERC721Proxy = await erc721Proxy.authorized.callAsync(exchangeV2.address); + warnIfMismatch(isExchangeV2AuthorizedInERC721Proxy, true, 'ExchangeV2 not authorized in ERC721Proxy'); + + const isExchangeAuthorizedInERC721Proxy = await erc721Proxy.authorized.callAsync(exchange.address); + warnIfMismatch(isExchangeAuthorizedInERC721Proxy, true, 'Exchange not authorized in ERC721Proxy'); + + const isMAPAuthorizedInER721Proxy = await erc721Proxy.authorized.callAsync(multiAssetProxy.address); + warnIfMismatch(isMAPAuthorizedInER721Proxy, true, 'MultiAssetProxy not authorized in ERC721Proxy'); + + // Verify ERC1155Proxy configs + const erc1155ProxyOwner = await erc1155Proxy.owner.callAsync(); + warnIfMismatch(erc1155ProxyOwner, assetProxyOwner.address, 'Unexpected ERC1155Proxy owner'); + + const erc1155AuthorizedAddresses = await erc1155Proxy.getAuthorizedAddresses.callAsync(); + warnIfMismatch( + erc1155AuthorizedAddresses.length, + 3, + 'Unexpected number of authorized addresses in ERC1155Proxy', + ); + + const isExchangeV2AuthorizedInERC1155Proxy = await erc1155Proxy.authorized.callAsync(exchangeV2.address); + warnIfMismatch(isExchangeV2AuthorizedInERC1155Proxy, true, 'ExchangeV2 not authorized in ERC1155Proxy'); + + const isExchangeAuthorizedInERC1155Proxy = await erc1155Proxy.authorized.callAsync(exchange.address); + warnIfMismatch(isExchangeAuthorizedInERC1155Proxy, true, 'Exchange not authorized in ERC1155Proxy'); + + const isMAPAuthorizedInER1155Proxy = await erc1155Proxy.authorized.callAsync(multiAssetProxy.address); + warnIfMismatch(isMAPAuthorizedInER1155Proxy, true, 'MultiAssetProxy not authorized in ERC1155Proxy'); + + // Verify MultiAssetProxy configs + const multiAssetProxyOwner = await multiAssetProxy.owner.callAsync(); + warnIfMismatch(multiAssetProxyOwner, assetProxyOwner.address, 'Unexpected MultiAssetProxy owner'); + + const multiAssetProxyAuthorizedAddresses = await multiAssetProxy.getAuthorizedAddresses.callAsync(); + warnIfMismatch( + multiAssetProxyAuthorizedAddresses.length, + 2, + 'Unexpected number of authorized addresses in MultiAssetProxy', + ); + + const isExchangeV2AuthorizedInMultiAssetProxy = await multiAssetProxy.authorized.callAsync(exchangeV2.address); + warnIfMismatch(isExchangeV2AuthorizedInMultiAssetProxy, true, 'ExchangeV2 not authorized in MultiAssetProxy'); + + const isExchangeAuthorizedInMultiAssetProxy = await multiAssetProxy.authorized.callAsync(exchange.address); + warnIfMismatch(isExchangeAuthorizedInMultiAssetProxy, true, 'Exchange not authorized in MultiAssetProxy'); + + const registeredERC20ProxyInMAP = await multiAssetProxy.getAssetProxy.callAsync(AssetProxyId.ERC20); + warnIfMismatch( + registeredERC20ProxyInMAP, + erc20Proxy.address, + 'Unexpected ERC20Proxy registered in MultiAssetProxy', + ); + + const registeredERC721ProxyInMAP = await multiAssetProxy.getAssetProxy.callAsync(AssetProxyId.ERC721); + warnIfMismatch( + registeredERC721ProxyInMAP, + erc721Proxy.address, + 'Unexpected ERC721Proxy registered in MultiAssetProxy', + ); + + const registeredERC1155ProxyInMAP = await multiAssetProxy.getAssetProxy.callAsync(AssetProxyId.ERC1155); + warnIfMismatch( + registeredERC1155ProxyInMAP, + erc1155Proxy.address, + 'Unexpected ERC1155Proxy registered in MultiAssetProxy', + ); + + const registeredStaticCallProxyInMAP = await multiAssetProxy.getAssetProxy.callAsync(AssetProxyId.StaticCall); + warnIfMismatch( + registeredStaticCallProxyInMAP, + addresses.staticCallProxy, + 'Unexpected StaticCallProxy registered in MultiAssetProxy', + ); + } + + async function verifyStakingConfigsAsync(): Promise { + const stakingLogicAddress = await stakingProxy.stakingContract.callAsync(); + warnIfMismatch(stakingLogicAddress, addresses.staking, 'Unexpected Staking contract attached to StakingProxy'); + + const readOnlyProxy = await stakingProxy.readOnlyProxy.callAsync(); + warnIfMismatch(readOnlyProxy, addresses.readOnlyProxy, 'Unexpected ReadOnlyProxy set in StakingProxy'); + + const readOnlyCallee = await stakingProxy.readOnlyProxyCallee.callAsync(); + warnIfMismatch(readOnlyCallee, addresses.staking, 'Unexpected readOnlyProxyCallee'); + + const zrxVaultAddress = await stakingContract.getZrxVault.callAsync(); + warnIfMismatch(zrxVaultAddress, addresses.zrxVault, 'Unexpected ZrxVault set in Staking contract'); + + const wethAddress = await stakingContract.getWethContract.callAsync(); + warnIfMismatch(wethAddress, addresses.etherToken, 'Unexpected WETH contract set in Staking contract'); + + const stakingProxyOwner = await stakingProxy.owner.callAsync(); + warnIfMismatch(stakingProxyOwner, addresses.assetProxyOwner, 'Unexpected StakingProxy owner'); + + const zrxVaultOwner = await zrxVault.owner.callAsync(); + warnIfMismatch(zrxVaultOwner, addresses.assetProxyOwner, 'Unexpected ZrxVault owner'); + + const stakingProxyAuthorizedAddresses = await stakingProxy.getAuthorizedAddresses.callAsync(); + warnIfMismatch( + stakingProxyAuthorizedAddresses.length, + 1, + 'Unexpected number of authorized addresses in StakingProxy', + ); + const isAssetProxyOwnerAuthorizedInStakingProxy = await stakingProxy.authorized.callAsync( + addresses.assetProxyOwner, + ); + warnIfMismatch( + isAssetProxyOwnerAuthorizedInStakingProxy, + true, + 'AssetProxyOwner not authorized in StakingProxy', + ); + + const zrxVaultAuthorizedAddresses = await zrxVault.getAuthorizedAddresses.callAsync(); + warnIfMismatch(zrxVaultAuthorizedAddresses.length, 1, 'Unexpected number of authorized addresses in ZrxVault'); + const isAssetProxyOwnerAuthorizedInZrxVault = await zrxVault.authorized.callAsync(addresses.assetProxyOwner); + warnIfMismatch(isAssetProxyOwnerAuthorizedInZrxVault, true, 'AssetProxyOwner not authorized in ZrxVault'); + } + + // TODO: implement AssetProxyOwner config tests + // async function verifyAssetProxyOwnerConfigsAsync(): Promise {} - // Verify Exchange configs - const exchangeOwner = await exchange.owner.callAsync(); - warnIfMismatch(exchangeOwner, assetProxyOwner.address, 'Unexpected Exchange owner'); - - const registeredERC20Proxy = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC20); - warnIfMismatch(registeredERC20Proxy, erc20Proxy.address, 'Unexpected ERC20Proxy registered in Exchange'); - - const registeredERC721Proxy = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC721); - warnIfMismatch(registeredERC721Proxy, erc721Proxy.address, 'Unexpected ERC721Proxy registered in Exchange'); - - const registeredERC1155Proxy = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC1155); - warnIfMismatch(registeredERC1155Proxy, erc1155Proxy.address, 'Unexpected ERC1155Proxy registered in Exchange'); - - const registeredMultiAssetProxy = await exchange.getAssetProxy.callAsync(AssetProxyId.MultiAsset); - warnIfMismatch( - registeredMultiAssetProxy, - multiAssetProxy.address, - 'Unexpected MultiAssetProxy registered in Exchange', - ); - - const registeredStaticCallProxy = await exchange.getAssetProxy.callAsync(AssetProxyId.StaticCall); - warnIfMismatch( - registeredStaticCallProxy, - addresses.staticCallProxy, - 'Unexpected StaticCallProxy registered in Exchange', - ); - - // Verify ERC20Proxy configs - const erc20ProxyOwner = await erc20Proxy.owner.callAsync(); - warnIfMismatch(erc20ProxyOwner, assetProxyOwner.address, 'Unexpected ERC20Proxy owner'); - - const erc20AuthorizedAddresses = await erc20Proxy.getAuthorizedAddresses.callAsync(); - warnIfMismatch(erc20AuthorizedAddresses.length, 2, 'Unexpected number of authorized addresses in ERC20Proxy'); - - const isExchangeAuthorizedInERC20Proxy = await erc20Proxy.authorized.callAsync(exchange.address); - warnIfMismatch(isExchangeAuthorizedInERC20Proxy, true, 'Exchange not authorized in ERC20Proxy'); - - const isMAPAuthorizedInER20Proxy = await erc20Proxy.authorized.callAsync(multiAssetProxy.address); - warnIfMismatch(isMAPAuthorizedInER20Proxy, true, 'MultiAssetProxy not authorized in ERC20Proxy'); - - // Verify ERC721Proxy configs - const erc721ProxyOwner = await erc721Proxy.owner.callAsync(); - warnIfMismatch(erc721ProxyOwner, assetProxyOwner.address, 'Unexpected ERC721Proxy owner'); - - const erc721AuthorizedAddresses = await erc721Proxy.getAuthorizedAddresses.callAsync(); - warnIfMismatch(erc721AuthorizedAddresses.length, 2, 'Unexpected number of authorized addresses in ERC721Proxy'); - - const isExchangeAuthorizedInERC721Proxy = await erc721Proxy.authorized.callAsync(exchange.address); - warnIfMismatch(isExchangeAuthorizedInERC721Proxy, true, 'Exchange not authorized in ERC721Proxy'); - - const isMAPAuthorizedInER721Proxy = await erc721Proxy.authorized.callAsync(multiAssetProxy.address); - warnIfMismatch(isMAPAuthorizedInER721Proxy, true, 'MultiAssetProxy not authorized in ERC721Proxy'); - - // Verify ERC1155Proxy configs - const erc1155ProxyOwner = await erc1155Proxy.owner.callAsync(); - warnIfMismatch(erc1155ProxyOwner, assetProxyOwner.address, 'Unexpected ERC1155Proxy owner'); - - const erc1155AuthorizedAddresses = await erc1155Proxy.getAuthorizedAddresses.callAsync(); - warnIfMismatch(erc1155AuthorizedAddresses.length, 2, 'Unexpected number of authorized addresses in ERC1155Proxy'); - - const isExchangeAuthorizedInERC1155Proxy = await erc1155Proxy.authorized.callAsync(exchange.address); - warnIfMismatch(isExchangeAuthorizedInERC1155Proxy, true, 'Exchange not authorized in ERC1155Proxy'); - - const isMAPAuthorizedInER1155Proxy = await erc1155Proxy.authorized.callAsync(multiAssetProxy.address); - warnIfMismatch(isMAPAuthorizedInER1155Proxy, true, 'MultiAssetProxy not authorized in ERC1155Proxy'); - - // Verify MultiAssetProxy configs - const multiAssetProxyOwner = await multiAssetProxy.owner.callAsync(); - warnIfMismatch(multiAssetProxyOwner, assetProxyOwner.address, 'Unexpected MultiAssetProxy owner'); - - const multiAssetProxyAuthorizedAddresses = await multiAssetProxy.getAuthorizedAddresses.callAsync(); - warnIfMismatch( - multiAssetProxyAuthorizedAddresses.length, - 1, - 'Unexpected number of authorized addresses in MultiAssetProxy', - ); - - const isExchangeAuthorizedInMultiAssetProxy = await multiAssetProxy.authorized.callAsync(exchange.address); - warnIfMismatch(isExchangeAuthorizedInMultiAssetProxy, true, 'Exchange not authorized in MultiAssetProxy'); - - const registeredERC20ProxyInMAP = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC20); - warnIfMismatch( - registeredERC20ProxyInMAP, - erc20Proxy.address, - 'Unexpected ERC20Proxy registered in MultiAssetProxy', - ); - - const registeredERC721ProxyInMAP = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC721); - warnIfMismatch( - registeredERC721ProxyInMAP, - erc721Proxy.address, - 'Unexpected ERC721Proxy registered in MultiAssetProxy', - ); - - const registeredERC1155ProxyInMAP = await exchange.getAssetProxy.callAsync(AssetProxyId.ERC1155); - warnIfMismatch( - registeredERC1155ProxyInMAP, - erc1155Proxy.address, - 'Unexpected ERC1155Proxy registered in MultiAssetProxy', - ); - - const registeredStaticCallProxyInMAP = await exchange.getAssetProxy.callAsync(AssetProxyId.StaticCall); - warnIfMismatch( - registeredStaticCallProxyInMAP, - addresses.staticCallProxy, - 'Unexpected StaticCallProxy registered in MultiAssetProxy', - ); - - // Verify AssetProxyOwner configs - // TODO (xianny): re-enable when AssetProxyOwner contract is finalised - // const isERC20ProxyRegisteredInAPOwner = await assetProxyOwner.getAssetProxy.callAsync(erc20Proxy.address); - // warnIfMismatch(isERC20ProxyRegisteredInAPOwner, true, 'ERC20Proxy not registered in AssetProxyOwner'); - - // const isERC721ProxyRegisteredInAPOwner = await assetProxyOwner.getAssetProxy.callAsync( - // erc721Proxy.address, - // ); - // warnIfMismatch(isERC721ProxyRegisteredInAPOwner, true, 'ERC721Proxy not registered in AssetProxyOwner'); - - // const isERC1155ProxyRegisteredInAPOwner = await assetProxyOwner.getAssetProxy.callAsync( - // erc1155Proxy.address, - // ); - // warnIfMismatch(isERC1155ProxyRegisteredInAPOwner, true, 'ERC1155Proxy not registered in AssetProxyOwner'); - - // const isMultiAssetProxyRegisteredInAPOwner = await assetProxyOwner.getAssetProxy.callAsync( - // multiAssetProxy.address, - // ); - // warnIfMismatch(isMultiAssetProxyRegisteredInAPOwner, true, 'MultiAssetProxy not registered in AssetProxyOwner'); + await verifyExchangeV2ConfigsAsync(); + await verifyExchangeV3ConfigsAsync(); + await verifyStakingConfigsAsync(); + await verifyAssetProxyConfigsAsync(); } (async () => { diff --git a/packages/migrations/src/testnet_migrations.ts b/packages/migrations/src/testnet_migrations.ts new file mode 100644 index 0000000000..d93903e305 --- /dev/null +++ b/packages/migrations/src/testnet_migrations.ts @@ -0,0 +1,259 @@ +import { getContractAddressesForNetworkOrThrow } from '@0x/contract-addresses'; +import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts-exchange'; +import { artifacts, ZeroExGovernorContract, ZeroExGovernorSubmissionEventArgs } from '@0x/contracts-multisig'; +import { + artifacts as stakingArtifacts, + ReadOnlyProxyContract, + StakingContract, + StakingProxyContract, + ZrxVaultContract, +} from '@0x/contracts-staking'; +import { IAuthorizableContract, IOwnableContract } from '@0x/contracts-utils'; +import { AbiEncoder, BigNumber, logUtils, providerUtils } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; +import { LogWithDecodedArgs, SupportedProvider, TxData } from 'ethereum-types'; + +import { constants } from './utils/constants'; +import { providerFactory } from './utils/provider_factory'; + +async function submitAndExecuteTransactionAsync( + governor: ZeroExGovernorContract, + destination: string, + data: string, +): Promise { + const txReceipt = await governor.submitTransaction.awaitTransactionSuccessAsync( + destination, + constants.ZERO_AMOUNT, + data, + ); + // tslint:disable-next-line:no-unnecessary-type-assertion + const txId = (txReceipt.logs[0] as LogWithDecodedArgs).args.transactionId; + logUtils.log(`${txId} submitted`); + await governor.executeTransaction.awaitTransactionSuccessAsync(txId); + logUtils.log(`${txId} executed`); +} + +/** + * Deploys all 3.0 contracts and reconfigures existing 2.0 contracts. + * @param supportedProvider Web3 provider instance. Your provider instance should connect to the testnet you want to deploy to. + * @param txDefaults Default transaction values to use when deploying contracts (e.g., specify the desired contract creator with the `from` parameter). + */ +export async function runMigrationsAsync(supportedProvider: SupportedProvider, txDefaults: TxData): Promise { + const provider = providerUtils.standardizeOrThrow(supportedProvider); + const web3Wrapper = new Web3Wrapper(provider); + const networkId = await web3Wrapper.getNetworkIdAsync(); + const chainId = new BigNumber(await providerUtils.getChainIdAsync(provider)); + const deployedAddresses = getContractAddressesForNetworkOrThrow(networkId); + + // NOTE: This must be deployed before running these migrations, since its address is hard coded in the + // staking logic contract. + const zrxVault = new ZrxVaultContract(deployedAddresses.zrxVault, provider, txDefaults); + + // NOTE: This may need to be deployed in its own step, since this contract requires a smaller + // amount of optimizer runs in order to deploy below the codesize limit. + const stakingLogic = await StakingContract.deployFrom0xArtifactAsync( + stakingArtifacts.Staking, + provider, + txDefaults, + stakingArtifacts, + ); + + const exchange = await ExchangeContract.deployFrom0xArtifactAsync( + exchangeArtifacts.Exchange, + provider, + txDefaults, + exchangeArtifacts, + chainId, + ); + + const readOnlyProxy = await ReadOnlyProxyContract.deployFrom0xArtifactAsync( + stakingArtifacts.ReadOnlyProxy, + provider, + txDefaults, + stakingArtifacts, + ); + + const stakingProxy = await StakingProxyContract.deployFrom0xArtifactAsync( + stakingArtifacts.StakingProxy, + provider, + txDefaults, + stakingArtifacts, + stakingLogic.address, + readOnlyProxy.address, + ); + + const authorizableInterface = new IAuthorizableContract(constants.NULL_ADDRESS, provider, txDefaults); + const ownableInterface = new IOwnableContract(constants.NULL_ADDRESS, provider, txDefaults); + + const customTimeLocks = [ + { + destination: deployedAddresses.erc20Proxy, + functionSelector: authorizableInterface.removeAuthorizedAddress.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.erc20Proxy, + functionSelector: authorizableInterface.removeAuthorizedAddressAtIndex.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.erc721Proxy, + functionSelector: authorizableInterface.removeAuthorizedAddress.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.erc721Proxy, + functionSelector: authorizableInterface.removeAuthorizedAddressAtIndex.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.erc1155Proxy, + functionSelector: authorizableInterface.removeAuthorizedAddress.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.erc1155Proxy, + functionSelector: authorizableInterface.removeAuthorizedAddressAtIndex.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.multiAssetProxy, + functionSelector: authorizableInterface.removeAuthorizedAddress.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.multiAssetProxy, + functionSelector: authorizableInterface.removeAuthorizedAddressAtIndex.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.stakingProxy, + functionSelector: stakingProxy.setReadOnlyMode.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.zrxVault, + functionSelector: zrxVault.enterCatastrophicFailure.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, + }, + { + destination: deployedAddresses.stakingProxy, + functionSelector: stakingProxy.attachStakingContract.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, // 3 epochs on mainnet + }, + { + destination: deployedAddresses.stakingProxy, + functionSelector: stakingLogic.setParams.getSelector(), + secondsTimeLocked: constants.ZERO_AMOUNT, // 1 epoch on mainnet + }, + ]; + + const governor = await ZeroExGovernorContract.deployFrom0xArtifactAsync( + artifacts.ZeroExGovernor, + provider, + txDefaults, + artifacts, + customTimeLocks.map(timeLockInfo => timeLockInfo.functionSelector), + customTimeLocks.map(timeLockInfo => timeLockInfo.destination), + customTimeLocks.map(timeLockInfo => timeLockInfo.secondsTimeLocked), + constants.ASSET_PROXY_OWNER_OWNERS, + constants.ASSET_PROXY_OWNER_CONFIRMATIONS, + constants.ASSET_PROXY_OWNER_TIMELOCK, + ); + + logUtils.log('Configuring Exchange...'); + await exchange.setProtocolFeeCollectorAddress.awaitTransactionSuccessAsync(stakingProxy.address); + await exchange.setProtocolFeeMultiplier.awaitTransactionSuccessAsync(new BigNumber(150000)); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(deployedAddresses.erc20Proxy); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(deployedAddresses.erc721Proxy); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(deployedAddresses.erc1155Proxy); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(deployedAddresses.multiAssetProxy); + await exchange.registerAssetProxy.awaitTransactionSuccessAsync(deployedAddresses.staticCallProxy); + await exchange.transferOwnership.awaitTransactionSuccessAsync(governor.address); + logUtils.log('Exchange configured!'); + + logUtils.log('Configuring ZrxVault...'); + await zrxVault.addAuthorizedAddress.awaitTransactionSuccessAsync(governor.address); + logUtils.log('ZrxVault configured!'); + + logUtils.log('Configuring StakingProxy...'); + await stakingProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(governor.address); + logUtils.log('StakingProxy configured!'); + + logUtils.log('Transfering ownership of 2.0 contracts...'); + const oldAssetProxyOwner = new ZeroExGovernorContract(deployedAddresses.assetProxyOwner, provider, txDefaults); + await submitAndExecuteTransactionAsync( + oldAssetProxyOwner, + deployedAddresses.exchangeV2, // Exchange 2.1 address + ownableInterface.transferOwnership.getABIEncodedTransactionData(governor.address), + ); + await submitAndExecuteTransactionAsync( + oldAssetProxyOwner, + deployedAddresses.erc20Proxy, + ownableInterface.transferOwnership.getABIEncodedTransactionData(governor.address), + ); + await submitAndExecuteTransactionAsync( + oldAssetProxyOwner, + deployedAddresses.erc721Proxy, + ownableInterface.transferOwnership.getABIEncodedTransactionData(governor.address), + ); + await submitAndExecuteTransactionAsync( + oldAssetProxyOwner, + deployedAddresses.erc1155Proxy, + ownableInterface.transferOwnership.getABIEncodedTransactionData(governor.address), + ); + await submitAndExecuteTransactionAsync( + oldAssetProxyOwner, + deployedAddresses.multiAssetProxy, + ownableInterface.transferOwnership.getABIEncodedTransactionData(governor.address), + ); + logUtils.log('Ownership transferred!'); + + const functionCalls = [ + { + destination: zrxVault.address, + data: zrxVault.setStakingProxy.getABIEncodedTransactionData(stakingProxy.address), + }, + { + destination: stakingProxy.address, + data: stakingLogic.addExchangeAddress.getABIEncodedTransactionData(exchange.address), + }, + { + destination: deployedAddresses.erc20Proxy, + data: authorizableInterface.addAuthorizedAddress.getABIEncodedTransactionData(exchange.address), + }, + { + destination: deployedAddresses.erc20Proxy, + data: authorizableInterface.addAuthorizedAddress.getABIEncodedTransactionData(zrxVault.address), + }, + { + destination: deployedAddresses.erc721Proxy, + data: authorizableInterface.addAuthorizedAddress.getABIEncodedTransactionData(exchange.address), + }, + { + destination: deployedAddresses.erc1155Proxy, + data: authorizableInterface.addAuthorizedAddress.getABIEncodedTransactionData(exchange.address), + }, + { + destination: deployedAddresses.multiAssetProxy, + data: authorizableInterface.addAuthorizedAddress.getABIEncodedTransactionData(exchange.address), + }, + ]; + const batchTransactionEncoder = AbiEncoder.create('(bytes[],address[],uint256[])'); + const batchTransactionData = batchTransactionEncoder.encode([ + functionCalls.map(item => item.data), + functionCalls.map(item => item.destination), + functionCalls.map(() => constants.ZERO_AMOUNT), + ]); + await submitAndExecuteTransactionAsync(governor, governor.address, batchTransactionData); +} + +(async () => { + const networkId = 4; + const rpcUrl = 'https://rinkeby.infura.io/v3/'; + const provider = await providerFactory.getLedgerProviderAsync(networkId, rpcUrl); + await runMigrationsAsync(provider, { from: constants.ASSET_PROXY_OWNER_OWNERS[0], gasPrice: 60000000000 }); +})().catch(err => { + logUtils.log(err); + process.exit(1); +}); diff --git a/packages/migrations/src/utils/constants.ts b/packages/migrations/src/utils/constants.ts index 8b16a0520b..15629e870e 100644 --- a/packages/migrations/src/utils/constants.ts +++ b/packages/migrations/src/utils/constants.ts @@ -15,4 +15,5 @@ export const constants = { KOVAN_NETWORK_ID: 42, MAINNET_RPC_URL: 'https://mainnet.infura.io/', MAINNET_NETWORK_ID: 1, + ZERO_AMOUNT: new BigNumber(0), }; diff --git a/packages/migrations/src/utils/provider_factory.ts b/packages/migrations/src/utils/provider_factory.ts index 330a263e87..0806981fb7 100644 --- a/packages/migrations/src/utils/provider_factory.ts +++ b/packages/migrations/src/utils/provider_factory.ts @@ -5,35 +5,21 @@ import Eth from '@ledgerhq/hw-app-eth'; import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'; import { Provider } from 'ethereum-types'; -import { constants } from './constants'; - async function ledgerEthereumNodeJsClientFactoryAsync(): Promise { const ledgerConnection = await TransportNodeHid.create(); const ledgerEthClient = new Eth(ledgerConnection); return ledgerEthClient; } export const providerFactory = { - async getKovanLedgerProviderAsync(): Promise { - const provider = new Web3ProviderEngine(); - const ledgerWalletConfigs = { - networkId: constants.KOVAN_NETWORK_ID, - ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync, - }; - const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs); - provider.addProvider(ledgerSubprovider); - provider.addProvider(new RPCSubprovider(constants.KOVAN_RPC_URL)); - providerUtils.startProviderEngine(provider); - return provider; - }, - async getMainnetLedgerProviderAsync(): Promise { + async getLedgerProviderAsync(networkId: number, rpcUrl: string): Promise { const provider = new Web3ProviderEngine(); const ledgerWalletConfigs = { - networkId: constants.MAINNET_NETWORK_ID, + networkId, ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync, }; const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs); provider.addProvider(ledgerSubprovider); - provider.addProvider(new RPCSubprovider(constants.MAINNET_RPC_URL)); + provider.addProvider(new RPCSubprovider(rpcUrl)); providerUtils.startProviderEngine(provider); return provider; }, diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json index 176896ea82..b2fabad0c2 100644 --- a/packages/order-utils/package.json +++ b/packages/order-utils/package.json @@ -40,7 +40,6 @@ "homepage": "https://github.com/0xProject/0x-monorepo/packages/order-utils/README.md", "devDependencies": { "@0x/dev-utils": "^2.4.0-beta.0", - "@0x/migrations": "^4.4.0-beta.0", "@0x/subproviders": "^5.1.0-beta.0", "@0x/ts-doc-gen": "^0.0.22", "@0x/tslint-config": "^3.0.1", diff --git a/packages/order-utils/src/staking_revert_errors.ts b/packages/order-utils/src/staking_revert_errors.ts index 4298ca0f5d..8debcffe8e 100644 --- a/packages/order-utils/src/staking_revert_errors.ts +++ b/packages/order-utils/src/staking_revert_errors.ts @@ -178,6 +178,12 @@ export class PreviousEpochNotFinalizedError extends RevertError { } } +export class PoolNotFinalizedError extends RevertError { + constructor(poolId: string, epoch: BigNumber | number | string) { + super('PoolNotFinalizedError', 'PoolNotFinalizedError(bytes32 poolId, uint256 epoch)', { poolId, epoch }); + } +} + const types = [ BlockTimestampTooLowError, ExchangeManagerError, @@ -195,6 +201,7 @@ const types = [ PoolExistenceError, PreviousEpochNotFinalizedError, ProxyDestinationCannotBeNilError, + PoolNotFinalizedError, ]; // Register the types we've defined. diff --git a/packages/types/CHANGELOG.json b/packages/types/CHANGELOG.json index b6aca3e427..5c9a0722f3 100644 --- a/packages/types/CHANGELOG.json +++ b/packages/types/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "2.5.0-beta.1", + "changes": [ + { + "note": "Add `SendTransactionOpts` and `AwaitTransactionSuccessOpts` types for contract wrappers", + "pr": 2243 + } + ] + }, { "version": "2.5.0-beta.0", "changes": [ diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 64fa91da2f..ceac35918c 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -670,6 +670,18 @@ export interface Type { tupleElements?: Type[]; } +/** + * * shouldValidate: Flag indicating whether the library should make attempts to validate a transaction before + * broadcasting it. For example, order has a valid signature, maker has sufficient funds, etc. Default=true. + * * pollingIntervalMs: Used with `awaitTransactionSuccessAsync` to determine polling interval in milliseconds + * * timeoutMs: Used with `awaitTransactionSuccessAsync` to determine timeout in milliseconds + */ +export interface SendTransactionOpts { + shouldValidate?: boolean; + pollingIntervalMs?: number; + timeoutMs?: number; +} + export interface ElementType { name: string; typeDocType: TypeDocTypes; @@ -742,27 +754,6 @@ export interface Stats { orderCount: number; } -export interface SimpleContractArtifact { - schemaVersion: string; - contractName: string; - compilerOutput: SimpleStandardContractOutput; - networks: ContractNetworks; -} - -export interface SimpleStandardContractOutput { - abi: ContractAbi; - evm: SimpleEvmOutput; - devdoc?: DevdocOutput; -} - -export interface SimpleEvmOutput { - bytecode: SimpleEvmBytecodeOutput; -} - -export interface SimpleEvmBytecodeOutput { - object: string; -} - export interface DutchAuctionDetails { beginTimeSeconds: BigNumber; endTimeSeconds: BigNumber; @@ -862,3 +853,48 @@ export type EventCallback = ( export interface IndexedFilterValues { [index: string]: ContractEventArg; } + +/* Begin types for @0x/abi-gen-wrappers + * Allow these types to be imported when needed instead of having to import + * the whole package, which is large + */ + +/** + * Used with `sendTransactionAsync` + * * shouldValidate: Flag indicating whether the library should make attempts to validate a transaction before + * broadcasting it. For example, order has a valid signature, maker has sufficient funds, etc. Default=true. + */ +export interface SendTransactionOpts { + shouldValidate?: boolean; +} + +/** + * Used with `awaitTransactionSuccessAsync` + * * pollingIntervalMs: Determine polling intervals in milliseconds + * * timeoutMs: Determines timeout in milliseconds + */ +export interface AwaitTransactionSuccessOpts extends SendTransactionOpts { + pollingIntervalMs?: number; + timeoutMs?: number; +} + +export interface SimpleContractArtifact { + schemaVersion: string; + contractName: string; + compilerOutput: SimpleStandardContractOutput; + networks: ContractNetworks; +} + +export interface SimpleStandardContractOutput { + abi: ContractAbi; + evm: SimpleEvmOutput; + devdoc?: DevdocOutput; +} + +export interface SimpleEvmOutput { + bytecode: SimpleEvmBytecodeOutput; +} + +export interface SimpleEvmBytecodeOutput { + object: string; +}