aboutsummaryrefslogtreecommitdiffstats
path: root/packages/fill-scenarios
diff options
context:
space:
mode:
Diffstat (limited to 'packages/fill-scenarios')
-rw-r--r--packages/fill-scenarios/CHANGELOG.json45
-rw-r--r--packages/fill-scenarios/CHANGELOG.md16
-rw-r--r--packages/fill-scenarios/package.json22
-rw-r--r--packages/fill-scenarios/src/fill_scenarios.ts63
4 files changed, 101 insertions, 45 deletions
diff --git a/packages/fill-scenarios/CHANGELOG.json b/packages/fill-scenarios/CHANGELOG.json
index deeae5f5d..2c3e261cb 100644
--- a/packages/fill-scenarios/CHANGELOG.json
+++ b/packages/fill-scenarios/CHANGELOG.json
@@ -1,5 +1,50 @@
[
{
+ "version": "1.1.0",
+ "changes": [
+ {
+ "note": "Add support for MultiAssetProxy",
+ "pr": 1363
+ }
+ ]
+ },
+ {
+ "version": "1.0.16",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ],
+ "timestamp": 1544739608
+ },
+ {
+ "version": "1.0.15",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ],
+ "timestamp": 1544570656
+ },
+ {
+ "timestamp": 1543401373,
+ "version": "1.0.14",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1542821676,
+ "version": "1.0.13",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"timestamp": 1542208198,
"version": "1.0.12",
"changes": [
diff --git a/packages/fill-scenarios/CHANGELOG.md b/packages/fill-scenarios/CHANGELOG.md
index c8bd402de..e9b88547d 100644
--- a/packages/fill-scenarios/CHANGELOG.md
+++ b/packages/fill-scenarios/CHANGELOG.md
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v1.0.16 - _December 13, 2018_
+
+ * Dependencies updated
+
+## v1.0.15 - _December 11, 2018_
+
+ * Dependencies updated
+
+## v1.0.14 - _November 28, 2018_
+
+ * Dependencies updated
+
+## v1.0.13 - _November 21, 2018_
+
+ * Dependencies updated
+
## v1.0.12 - _November 14, 2018_
* Dependencies updated
diff --git a/packages/fill-scenarios/package.json b/packages/fill-scenarios/package.json
index 2d9bff0e7..7a9d21e0a 100644
--- a/packages/fill-scenarios/package.json
+++ b/packages/fill-scenarios/package.json
@@ -1,6 +1,6 @@
{
"name": "@0x/fill-scenarios",
- "version": "1.0.12",
+ "version": "1.0.16",
"description": "0x order fill scenario generator",
"main": "lib/index.js",
"types": "lib/index.d.ts",
@@ -20,7 +20,7 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/fill-scenarios/README.md",
"devDependencies": {
- "@0x/tslint-config": "^1.0.10",
+ "@0x/tslint-config": "^2.0.0",
"@types/lodash": "4.14.104",
"make-promises-safe": "^1.1.0",
"shx": "^0.2.2",
@@ -28,15 +28,15 @@
"typescript": "3.0.1"
},
"dependencies": {
- "@0x/abi-gen-wrappers": "^1.0.5",
- "@0x/base-contract": "^3.0.6",
- "@0x/contract-artifacts": "^1.1.0",
- "@0x/order-utils": "^3.0.2",
- "@0x/types": "^1.2.1",
- "@0x/typescript-typings": "^3.0.4",
- "@0x/utils": "^2.0.5",
- "@0x/web3-wrapper": "^3.1.4",
- "ethereum-types": "^1.1.2",
+ "@0x/abi-gen-wrappers": "^2.0.2",
+ "@0x/base-contract": "^3.0.10",
+ "@0x/contract-artifacts": "^1.1.2",
+ "@0x/order-utils": "^3.0.7",
+ "@0x/types": "^1.4.1",
+ "@0x/typescript-typings": "^3.0.6",
+ "@0x/utils": "^2.0.8",
+ "@0x/web3-wrapper": "^3.2.1",
+ "ethereum-types": "^1.1.4",
"ethers": "~4.0.4",
"lodash": "^4.17.5"
},
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,
+ );
+ }
+ }
+ }
}