diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-12-01 08:13:35 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2019-01-08 02:31:11 +0800 |
commit | 19e93440b39161e8b1ecb79f29548faae1be4b1b (patch) | |
tree | 874621887722ea375963cabdf401f751b7ba10ea | |
parent | 0cb5209266b979bcee094f3863efca0a1fa63697 (diff) | |
download | dexon-0x-contracts-19e93440b39161e8b1ecb79f29548faae1be4b1b.tar dexon-0x-contracts-19e93440b39161e8b1ecb79f29548faae1be4b1b.tar.gz dexon-0x-contracts-19e93440b39161e8b1ecb79f29548faae1be4b1b.tar.bz2 dexon-0x-contracts-19e93440b39161e8b1ecb79f29548faae1be4b1b.tar.lz dexon-0x-contracts-19e93440b39161e8b1ecb79f29548faae1be4b1b.tar.xz dexon-0x-contracts-19e93440b39161e8b1ecb79f29548faae1be4b1b.tar.zst dexon-0x-contracts-19e93440b39161e8b1ecb79f29548faae1be4b1b.zip |
fix: Add error message if assetProxyId is not ERC20 or ERC721
-rw-r--r-- | packages/fill-scenarios/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/fill-scenarios/src/fill_scenarios.ts | 25 |
2 files changed, 27 insertions, 7 deletions
diff --git a/packages/fill-scenarios/CHANGELOG.json b/packages/fill-scenarios/CHANGELOG.json index ca256399a..176267df9 100644 --- a/packages/fill-scenarios/CHANGELOG.json +++ b/packages/fill-scenarios/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "1.0.17", + "changes": [ + { + "note": "Add error message if assetProxyId is not ERC20 or ERC721", + "pr": 1363 + } + ] + }, + { "version": "1.0.16", "changes": [ { diff --git a/packages/fill-scenarios/src/fill_scenarios.ts b/packages/fill-scenarios/src/fill_scenarios.ts index 0154bcd0a..e08c6ae5f 100644 --- a/packages/fill-scenarios/src/fill_scenarios.ts +++ b/packages/fill-scenarios/src/fill_scenarios.ts @@ -2,7 +2,14 @@ import { DummyERC20TokenContract, DummyERC721TokenContract, ExchangeContract } f import * as artifacts from '@0x/contract-artifacts'; import { assetDataUtils } from '@0x/order-utils'; import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; -import { AssetProxyId, ERC721AssetData, OrderWithoutExchangeAddress, SignedOrder } from '@0x/types'; +import { + AssetData, + AssetProxyId, + ERC20AssetData, + ERC721AssetData, + OrderWithoutExchangeAddress, + SignedOrder, +} from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { Provider } from 'ethereum-types'; @@ -153,35 +160,39 @@ export class FillScenarios { const decodedMakerAssetData = assetDataUtils.decodeAssetDataOrThrow(makerAssetData); if (decodedMakerAssetData.assetProxyId === AssetProxyId.ERC20) { await this._increaseERC20BalanceAndAllowanceAsync( - decodedMakerAssetData.tokenAddress, + (decodedMakerAssetData as ERC20AssetData).tokenAddress, makerAddress, makerFillableAmount, ); - } else { + } else if (decodedMakerAssetData.assetProxyId === AssetProxyId.ERC721) { if (!makerFillableAmount.equals(1)) { throw new Error(`ERC721 makerFillableAmount should be equal 1. Found: ${makerFillableAmount}`); } await this._increaseERC721BalanceAndAllowanceAsync( - decodedMakerAssetData.tokenAddress, + (decodedMakerAssetData as ERC721AssetData).tokenAddress, makerAddress, // tslint:disable-next-line:no-unnecessary-type-assertion (decodedMakerAssetData as ERC721AssetData).tokenId, ); + } else { + throw new Error(`Proxy with id ${decodedMakerAssetData.assetProxyId} not supported`); } const decodedTakerAssetData = assetDataUtils.decodeAssetDataOrThrow(takerAssetData); if (decodedTakerAssetData.assetProxyId === AssetProxyId.ERC20) { - const takerTokenAddress = decodedTakerAssetData.tokenAddress; + const takerTokenAddress = (decodedTakerAssetData as ERC20AssetData).tokenAddress; await this._increaseERC20BalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount); - } else { + } else if (decodedTakerAssetData.assetProxyId === AssetProxyId.ERC721) { if (!takerFillableAmount.equals(1)) { throw new Error(`ERC721 takerFillableAmount should be equal 1. Found: ${takerFillableAmount}`); } await this._increaseERC721BalanceAndAllowanceAsync( - decodedTakerAssetData.tokenAddress, + (decodedTakerAssetData as ERC721AssetData).tokenAddress, takerAddress, // tslint:disable-next-line:no-unnecessary-type-assertion (decodedMakerAssetData as ERC721AssetData).tokenId, ); + } else { + throw new Error(`Proxy with id ${decodedTakerAssetData.assetProxyId} not supported`); } // Fees await Promise.all([ |