diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-14 18:07:57 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-14 18:07:57 +0800 |
commit | 12033abe095e902102f1d56e7a2711a630e6826b (patch) | |
tree | c3dcea6850ab2e4769fc969611018ba445a62191 /packages/contracts | |
parent | f9410d5d008ce289d075741710c6f7705bd3ad2a (diff) | |
download | dexon-sol-tools-12033abe095e902102f1d56e7a2711a630e6826b.tar dexon-sol-tools-12033abe095e902102f1d56e7a2711a630e6826b.tar.gz dexon-sol-tools-12033abe095e902102f1d56e7a2711a630e6826b.tar.bz2 dexon-sol-tools-12033abe095e902102f1d56e7a2711a630e6826b.tar.lz dexon-sol-tools-12033abe095e902102f1d56e7a2711a630e6826b.tar.xz dexon-sol-tools-12033abe095e902102f1d56e7a2711a630e6826b.tar.zst dexon-sol-tools-12033abe095e902102f1d56e7a2711a630e6826b.zip |
Rename OrderAmountScenario to OrderAssetAmountScenario and convert generateOrderCombinations to generateFillOrderCombinations
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/src/utils/core_combinatorial_utils.ts | 47 | ||||
-rw-r--r-- | packages/contracts/src/utils/new_order_factory.ts | 34 | ||||
-rw-r--r-- | packages/contracts/src/utils/types.ts | 10 | ||||
-rw-r--r-- | packages/contracts/test/exchange/combinatorial_tests.ts | 8 | ||||
-rw-r--r-- | packages/contracts/test/exchange/fill_order.ts | 20 |
5 files changed, 59 insertions, 60 deletions
diff --git a/packages/contracts/src/utils/core_combinatorial_utils.ts b/packages/contracts/src/utils/core_combinatorial_utils.ts index 4ce23d450..776d7b2fe 100644 --- a/packages/contracts/src/utils/core_combinatorial_utils.ts +++ b/packages/contracts/src/utils/core_combinatorial_utils.ts @@ -33,11 +33,11 @@ import { AssetDataScenario, ExpirationTimeSecondsScenario, FeeRecipientAddressScenario, - OrderAmountScenario, + FillScenario, + OrderAssetAmountScenario, OrderScenario, TakerAssetFillAmountScenario, TakerScenario, - FillScenario, } from '../utils/types'; chaiSetup.configure(); @@ -144,13 +144,13 @@ export class CoreCombinatorialUtils { public zrxAssetData: string; public exchangeWrapper: ExchangeWrapper; public assetWrapper: AssetWrapper; - public static generateOrderCombinations(): OrderScenario[] { + public static generateFillOrderCombinations(): FillScenario[] { const takerScenarios = [TakerScenario.Unspecified]; const feeRecipientScenarios = [FeeRecipientAddressScenario.EthUserAddress]; - const makerAssetAmountScenario = [OrderAmountScenario.Large]; - const takerAssetAmountScenario = [OrderAmountScenario.Large]; - const makerFeeScenario = [OrderAmountScenario.Large]; - const takerFeeScenario = [OrderAmountScenario.Large]; + const makerAssetAmountScenario = [OrderAssetAmountScenario.Large]; + const takerAssetAmountScenario = [OrderAssetAmountScenario.Large]; + const makerFeeScenario = [OrderAssetAmountScenario.Large]; + const takerFeeScenario = [OrderAssetAmountScenario.Large]; const expirationTimeSecondsScenario = [ExpirationTimeSecondsScenario.InFuture]; const makerAssetDataScenario = [ AssetDataScenario.ERC20FiveDecimals, @@ -164,7 +164,8 @@ export class CoreCombinatorialUtils { AssetDataScenario.ERC721, AssetDataScenario.ZRXFeeToken, ]; - const orderScenarioArrays = CoreCombinatorialUtils._allPossibleCases([ + const takerAssetFillAmountScenario = [TakerAssetFillAmountScenario.ExactlyRemainingFillableTakerAssetAmount]; + const fillScenarioArrays = CoreCombinatorialUtils._allPossibleCases([ takerScenarios, feeRecipientScenarios, makerAssetAmountScenario, @@ -174,24 +175,28 @@ export class CoreCombinatorialUtils { expirationTimeSecondsScenario, makerAssetDataScenario, takerAssetDataScenario, + takerAssetFillAmountScenario, ]); - const orderScenarios = _.map(orderScenarioArrays, orderScenarioArray => { - const orderScenario: OrderScenario = { - takerScenario: orderScenarioArray[0] as TakerScenario, - feeRecipientScenario: orderScenarioArray[1] as FeeRecipientAddressScenario, - makerAssetAmountScenario: orderScenarioArray[2] as OrderAmountScenario, - takerAssetAmountScenario: orderScenarioArray[3] as OrderAmountScenario, - makerFeeScenario: orderScenarioArray[4] as OrderAmountScenario, - takerFeeScenario: orderScenarioArray[5] as OrderAmountScenario, - expirationTimeSecondsScenario: orderScenarioArray[6] as ExpirationTimeSecondsScenario, - makerAssetDataScenario: orderScenarioArray[7] as AssetDataScenario, - takerAssetDataScenario: orderScenarioArray[8] as AssetDataScenario, + const fillScenarios = _.map(fillScenarioArrays, fillScenarioArray => { + const fillScenario: FillScenario = { + orderScenario: { + takerScenario: fillScenarioArray[0] as TakerScenario, + feeRecipientScenario: fillScenarioArray[1] as FeeRecipientAddressScenario, + makerAssetAmountScenario: fillScenarioArray[2] as OrderAssetAmountScenario, + takerAssetAmountScenario: fillScenarioArray[3] as OrderAssetAmountScenario, + makerFeeScenario: fillScenarioArray[4] as OrderAssetAmountScenario, + takerFeeScenario: fillScenarioArray[5] as OrderAssetAmountScenario, + expirationTimeSecondsScenario: fillScenarioArray[6] as ExpirationTimeSecondsScenario, + makerAssetDataScenario: fillScenarioArray[7] as AssetDataScenario, + takerAssetDataScenario: fillScenarioArray[8] as AssetDataScenario, + }, + takerAssetFillAmountScenario: fillScenarioArray[9] as TakerAssetFillAmountScenario, }; - return orderScenario; + return fillScenario; }); - return orderScenarios; + return fillScenarios; } private static _allPossibleCases(arrays: string[][]): string[][] { if (arrays.length === 1) { diff --git a/packages/contracts/src/utils/new_order_factory.ts b/packages/contracts/src/utils/new_order_factory.ts index 7de7be3bd..22705d3e7 100644 --- a/packages/contracts/src/utils/new_order_factory.ts +++ b/packages/contracts/src/utils/new_order_factory.ts @@ -10,7 +10,7 @@ import { ERC721TokenIdsByOwner, ExpirationTimeSecondsScenario, FeeRecipientAddressScenario, - OrderAmountScenario, + OrderAssetAmountScenario, OrderScenario, TakerScenario, } from './types'; @@ -118,7 +118,7 @@ export class NewOrderFactory { } switch (orderScenario.makerAssetAmountScenario) { - case OrderAmountScenario.Large: + case OrderAssetAmountScenario.Large: switch (orderScenario.makerAssetDataScenario) { case AssetDataScenario.ZRXFeeToken: case AssetDataScenario.ERC20NonZRXEighteenDecimals: @@ -134,7 +134,7 @@ export class NewOrderFactory { throw errorUtils.spawnSwitchErr('AssetDataScenario', orderScenario.makerAssetDataScenario); } break; - case OrderAmountScenario.Small: + case OrderAssetAmountScenario.Small: switch (orderScenario.makerAssetDataScenario) { case AssetDataScenario.ZRXFeeToken: case AssetDataScenario.ERC20NonZRXEighteenDecimals: @@ -150,15 +150,15 @@ export class NewOrderFactory { throw errorUtils.spawnSwitchErr('AssetDataScenario', orderScenario.makerAssetDataScenario); } break; - case OrderAmountScenario.Zero: + case OrderAssetAmountScenario.Zero: makerAssetAmount = new BigNumber(0); break; default: - throw errorUtils.spawnSwitchErr('OrderAmountScenario', orderScenario.makerAssetAmountScenario); + throw errorUtils.spawnSwitchErr('OrderAssetAmountScenario', orderScenario.makerAssetAmountScenario); } switch (orderScenario.takerAssetAmountScenario) { - case OrderAmountScenario.Large: + case OrderAssetAmountScenario.Large: switch (orderScenario.takerAssetDataScenario) { case AssetDataScenario.ERC20NonZRXEighteenDecimals: case AssetDataScenario.ZRXFeeToken: @@ -174,7 +174,7 @@ export class NewOrderFactory { throw errorUtils.spawnSwitchErr('AssetDataScenario', orderScenario.takerAssetDataScenario); } break; - case OrderAmountScenario.Small: + case OrderAssetAmountScenario.Small: switch (orderScenario.takerAssetDataScenario) { case AssetDataScenario.ERC20NonZRXEighteenDecimals: case AssetDataScenario.ZRXFeeToken: @@ -190,39 +190,39 @@ export class NewOrderFactory { throw errorUtils.spawnSwitchErr('AssetDataScenario', orderScenario.takerAssetDataScenario); } break; - case OrderAmountScenario.Zero: + case OrderAssetAmountScenario.Zero: takerAssetAmount = new BigNumber(0); break; default: - throw errorUtils.spawnSwitchErr('OrderAmountScenario', orderScenario.takerAssetAmountScenario); + throw errorUtils.spawnSwitchErr('OrderAssetAmountScenario', orderScenario.takerAssetAmountScenario); } switch (orderScenario.makerFeeScenario) { - case OrderAmountScenario.Large: + case OrderAssetAmountScenario.Large: makerFee = POINT_ONE_UNITS_EIGHTEEN_DECIMALS; break; - case OrderAmountScenario.Small: + case OrderAssetAmountScenario.Small: makerFee = POINT_ZERO_FIVE_UNITS_EIGHTEEN_DECIMALS; break; - case OrderAmountScenario.Zero: + case OrderAssetAmountScenario.Zero: makerFee = new BigNumber(0); break; default: - throw errorUtils.spawnSwitchErr('OrderAmountScenario', orderScenario.makerFeeScenario); + throw errorUtils.spawnSwitchErr('OrderAssetAmountScenario', orderScenario.makerFeeScenario); } switch (orderScenario.takerFeeScenario) { - case OrderAmountScenario.Large: + case OrderAssetAmountScenario.Large: takerFee = POINT_ONE_UNITS_EIGHTEEN_DECIMALS; break; - case OrderAmountScenario.Small: + case OrderAssetAmountScenario.Small: takerFee = POINT_ZERO_FIVE_UNITS_EIGHTEEN_DECIMALS; break; - case OrderAmountScenario.Zero: + case OrderAssetAmountScenario.Zero: takerFee = new BigNumber(0); break; default: - throw errorUtils.spawnSwitchErr('OrderAmountScenario', orderScenario.takerFeeScenario); + throw errorUtils.spawnSwitchErr('OrderAssetAmountScenario', orderScenario.takerFeeScenario); } switch (orderScenario.expirationTimeSecondsScenario) { diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index 318ea91f9..f0e2dde02 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -158,7 +158,7 @@ export enum FeeRecipientAddressScenario { EthUserAddress = 'ETH_USER_ADDRESS', } -export enum OrderAmountScenario { +export enum OrderAssetAmountScenario { Zero = 'ZERO', Large = 'LARGE', Small = 'SMALL', @@ -192,10 +192,10 @@ export enum TakerAssetFillAmountScenario { export interface OrderScenario { takerScenario: TakerScenario; feeRecipientScenario: FeeRecipientAddressScenario; - makerAssetAmountScenario: OrderAmountScenario; - takerAssetAmountScenario: OrderAmountScenario; - makerFeeScenario: OrderAmountScenario; - takerFeeScenario: OrderAmountScenario; + makerAssetAmountScenario: OrderAssetAmountScenario; + takerAssetAmountScenario: OrderAssetAmountScenario; + makerFeeScenario: OrderAssetAmountScenario; + takerFeeScenario: OrderAssetAmountScenario; expirationTimeSecondsScenario: ExpirationTimeSecondsScenario; makerAssetDataScenario: AssetDataScenario; takerAssetDataScenario: AssetDataScenario; diff --git a/packages/contracts/test/exchange/combinatorial_tests.ts b/packages/contracts/test/exchange/combinatorial_tests.ts index fd9193d69..754af9b08 100644 --- a/packages/contracts/test/exchange/combinatorial_tests.ts +++ b/packages/contracts/test/exchange/combinatorial_tests.ts @@ -42,13 +42,7 @@ describe('Combinatorial tests', () => { }); }; - const allOrderScenarios = CoreCombinatorialUtils.generateOrderCombinations(); - const allFillScenarios = _.map(allOrderScenarios, orderScenario => { - return { - orderScenario, - takerAssetFillAmountScenario: TakerAssetFillAmountScenario.LessThanRemainingFillableTakerAssetAmount, - }; - }); + const allFillScenarios = CoreCombinatorialUtils.generateFillOrderCombinations(); describe('Fills orders', () => test(allFillScenarios)); }); diff --git a/packages/contracts/test/exchange/fill_order.ts b/packages/contracts/test/exchange/fill_order.ts index 3f49f6119..2498ee27e 100644 --- a/packages/contracts/test/exchange/fill_order.ts +++ b/packages/contracts/test/exchange/fill_order.ts @@ -9,7 +9,7 @@ import { AssetDataScenario, ExpirationTimeSecondsScenario, FeeRecipientAddressScenario, - OrderAmountScenario, + OrderAssetAmountScenario, OrderScenario, TakerAssetFillAmountScenario, TakerScenario, @@ -22,10 +22,10 @@ const defaultFillScenario = { orderScenario: { takerScenario: TakerScenario.Unspecified, feeRecipientScenario: FeeRecipientAddressScenario.EthUserAddress, - makerAssetAmountScenario: OrderAmountScenario.Large, - takerAssetAmountScenario: OrderAmountScenario.Large, - makerFeeScenario: OrderAmountScenario.Large, - takerFeeScenario: OrderAmountScenario.Large, + makerAssetAmountScenario: OrderAssetAmountScenario.Large, + takerAssetAmountScenario: OrderAssetAmountScenario.Large, + makerFeeScenario: OrderAssetAmountScenario.Large, + takerFeeScenario: OrderAssetAmountScenario.Large, expirationTimeSecondsScenario: ExpirationTimeSecondsScenario.InFuture, makerAssetDataScenario: AssetDataScenario.ERC20NonZRXEighteenDecimals, takerAssetDataScenario: AssetDataScenario.ERC20NonZRXEighteenDecimals, @@ -33,7 +33,7 @@ const defaultFillScenario = { takerAssetFillAmountScenario: TakerAssetFillAmountScenario.LessThanRemainingFillableTakerAssetAmount, }; -describe.only('FillOrder Tests', () => { +describe('FillOrder Tests', () => { let coreCombinatorialUtils: CoreCombinatorialUtils; before(async () => { @@ -61,7 +61,7 @@ describe.only('FillOrder Tests', () => { ...defaultFillScenario, orderScenario: { ...defaultFillScenario.orderScenario, - takerAssetAmountScenario: OrderAmountScenario.Small, + takerAssetAmountScenario: OrderAssetAmountScenario.Small, }, }; await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); @@ -71,7 +71,7 @@ describe.only('FillOrder Tests', () => { ...defaultFillScenario, orderScenario: { ...defaultFillScenario.orderScenario, - makerAssetAmountScenario: OrderAmountScenario.Small, + makerAssetAmountScenario: OrderAssetAmountScenario.Small, }, }; await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); @@ -109,7 +109,7 @@ describe.only('FillOrder Tests', () => { ...defaultFillScenario, orderScenario: { ...defaultFillScenario.orderScenario, - makerAssetAmountScenario: OrderAmountScenario.Zero, + makerAssetAmountScenario: OrderAssetAmountScenario.Zero, }, }; await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); @@ -120,7 +120,7 @@ describe.only('FillOrder Tests', () => { ...defaultFillScenario, orderScenario: { ...defaultFillScenario.orderScenario, - takerAssetAmountScenario: OrderAmountScenario.Zero, + takerAssetAmountScenario: OrderAssetAmountScenario.Zero, }, }; await coreCombinatorialUtils.testFillOrderScenarioAsync(provider, fillScenario); |