diff options
author | Fabio Berger <me@fabioberger.com> | 2019-01-08 21:30:38 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2019-01-08 21:30:38 +0800 |
commit | 1631031fa74894143cb6835030b7dcd44d7c3c6b (patch) | |
tree | 06dea01cc64fb42905a5f95c95f4b3e16ecfe744 /packages/fill-scenarios | |
parent | 0bcb81d3a918fbcf71d68f42fa661d884d5d74cf (diff) | |
parent | 0ac36cef288deecd36caa601c53d13517eef5ca8 (diff) | |
download | dexon-0x-contracts-1631031fa74894143cb6835030b7dcd44d7c3c6b.tar dexon-0x-contracts-1631031fa74894143cb6835030b7dcd44d7c3c6b.tar.gz dexon-0x-contracts-1631031fa74894143cb6835030b7dcd44d7c3c6b.tar.bz2 dexon-0x-contracts-1631031fa74894143cb6835030b7dcd44d7c3c6b.tar.lz dexon-0x-contracts-1631031fa74894143cb6835030b7dcd44d7c3c6b.tar.xz dexon-0x-contracts-1631031fa74894143cb6835030b7dcd44d7c3c6b.tar.zst dexon-0x-contracts-1631031fa74894143cb6835030b7dcd44d7c3c6b.zip |
Merge branch 'development' into feature/order-watcher/dockerize
* development: (898 commits)
Fixed merge conflict from development
Ran prettier
Doc generation working for changes by dutch auction wrapper
added changelog entry for monorepo-scripts
Hide dutch auction wrapper from docs -- hopefully this will prevent the "must export Web3Wrapper" error from doc generation
relaxed version on contract-extension dependencies
Added NetworkID 50 address for dutch auction wrapper
removed manual updte of package.json version
export dutch auction wrapper types from 0x.js
Export dutch auction wrapper in 0x.js
ran prettier
Minor documentation updates to dutch auction wrapper
`afterAuctionDetails` -> `auctionDetails`
Added @todo for including dutch auction addresses once deployed
Ran prettier & linter
Removed redundant assignment
removed needless newline on contract-wrappers changelog
removed timestamp from changelog for abi-gen-wrappers
added dutch auction address for testnets
removed .only
...
Diffstat (limited to 'packages/fill-scenarios')
-rw-r--r-- | packages/fill-scenarios/CHANGELOG.json | 9 | ||||
-rw-r--r-- | packages/fill-scenarios/src/fill_scenarios.ts | 63 |
2 files changed, 38 insertions, 34 deletions
diff --git a/packages/fill-scenarios/CHANGELOG.json b/packages/fill-scenarios/CHANGELOG.json index ca256399a..2c3e261cb 100644 --- a/packages/fill-scenarios/CHANGELOG.json +++ b/packages/fill-scenarios/CHANGELOG.json @@ -1,5 +1,14 @@ [ { + "version": "1.1.0", + "changes": [ + { + "note": "Add support for MultiAssetProxy", + "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..ce1f7f9ff 100644 --- a/packages/fill-scenarios/src/fill_scenarios.ts +++ b/packages/fill-scenarios/src/fill_scenarios.ts @@ -2,7 +2,7 @@ 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 { OrderWithoutExchangeAddress, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { Provider } from 'ethereum-types'; @@ -150,39 +150,8 @@ export class FillScenarios { feeRecipientAddress: string, expirationTimeSeconds?: BigNumber, ): Promise<SignedOrder> { - const decodedMakerAssetData = assetDataUtils.decodeAssetDataOrThrow(makerAssetData); - if (decodedMakerAssetData.assetProxyId === AssetProxyId.ERC20) { - await this._increaseERC20BalanceAndAllowanceAsync( - decodedMakerAssetData.tokenAddress, - makerAddress, - makerFillableAmount, - ); - } else { - if (!makerFillableAmount.equals(1)) { - throw new Error(`ERC721 makerFillableAmount should be equal 1. Found: ${makerFillableAmount}`); - } - await this._increaseERC721BalanceAndAllowanceAsync( - decodedMakerAssetData.tokenAddress, - makerAddress, - // tslint:disable-next-line:no-unnecessary-type-assertion - (decodedMakerAssetData as ERC721AssetData).tokenId, - ); - } - const decodedTakerAssetData = assetDataUtils.decodeAssetDataOrThrow(takerAssetData); - if (decodedTakerAssetData.assetProxyId === AssetProxyId.ERC20) { - const takerTokenAddress = decodedTakerAssetData.tokenAddress; - await this._increaseERC20BalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount); - } else { - if (!takerFillableAmount.equals(1)) { - throw new Error(`ERC721 takerFillableAmount should be equal 1. Found: ${takerFillableAmount}`); - } - await this._increaseERC721BalanceAndAllowanceAsync( - decodedTakerAssetData.tokenAddress, - takerAddress, - // tslint:disable-next-line:no-unnecessary-type-assertion - (decodedMakerAssetData as ERC721AssetData).tokenId, - ); - } + await this._increaseBalanceAndAllowanceWithAssetDataAsync(makerAssetData, makerAddress, makerFillableAmount); + await this._increaseBalanceAndAllowanceWithAssetDataAsync(takerAssetData, takerAddress, takerFillableAmount); // Fees await Promise.all([ this._increaseERC20BalanceAndAllowanceAsync(this._zrxTokenAddress, makerAddress, makerFee), @@ -298,4 +267,30 @@ export class FillScenarios { }); await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); } + private async _increaseBalanceAndAllowanceWithAssetDataAsync( + assetData: string, + userAddress: string, + amount: BigNumber, + ): Promise<void> { + const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); + if (assetDataUtils.isERC20AssetData(decodedAssetData)) { + await this._increaseERC20BalanceAndAllowanceAsync(decodedAssetData.tokenAddress, userAddress, amount); + } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) { + await this._increaseERC721BalanceAndAllowanceAsync( + decodedAssetData.tokenAddress, + userAddress, + decodedAssetData.tokenId, + ); + } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) { + for (const [index, nestedAssetDataElement] of decodedAssetData.nestedAssetData.entries()) { + const amountsElement = decodedAssetData.amounts[index]; + const totalAmount = amount.times(amountsElement); + await this._increaseBalanceAndAllowanceWithAssetDataAsync( + nestedAssetDataElement, + userAddress, + totalAmount, + ); + } + } + } } |