aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/fill_scenarios.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-03 01:03:53 +0800
committerFabio Berger <me@fabioberger.com>2017-06-03 01:03:53 +0800
commit35c9330d6246183509a3543cdf1278b9ced191e2 (patch)
tree5cef8b37a52ef4ce258a971b1ae52c5c2ad63a63 /test/utils/fill_scenarios.ts
parentab5b5a881bc8f8f8d176ae65440de8fcd25ad906 (diff)
parentc83587a16d016d1efafaf31abb9b39eb54128568 (diff)
downloaddexon-sol-tools-35c9330d6246183509a3543cdf1278b9ced191e2.tar
dexon-sol-tools-35c9330d6246183509a3543cdf1278b9ced191e2.tar.gz
dexon-sol-tools-35c9330d6246183509a3543cdf1278b9ced191e2.tar.bz2
dexon-sol-tools-35c9330d6246183509a3543cdf1278b9ced191e2.tar.lz
dexon-sol-tools-35c9330d6246183509a3543cdf1278b9ced191e2.tar.xz
dexon-sol-tools-35c9330d6246183509a3543cdf1278b9ced191e2.tar.zst
dexon-sol-tools-35c9330d6246183509a3543cdf1278b9ced191e2.zip
Merge branch 'master' into unavailableFilledCancelled
# Conflicts: # src/contract_wrappers/exchange_wrapper.ts # src/types.ts # test/exchange_wrapper_test.ts
Diffstat (limited to 'test/utils/fill_scenarios.ts')
-rw-r--r--test/utils/fill_scenarios.ts97
1 files changed, 72 insertions, 25 deletions
diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts
index 17c2dbeba..d186593b9 100644
--- a/test/utils/fill_scenarios.ts
+++ b/test/utils/fill_scenarios.ts
@@ -2,47 +2,64 @@ import * as BigNumber from 'bignumber.js';
import {ZeroEx} from '../../src/0x.js';
import {Token, SignedOrder} from '../../src/types';
import {orderFactory} from '../utils/order_factory';
+import {constants} from './constants';
export class FillScenarios {
private zeroEx: ZeroEx;
private userAddresses: string[];
private tokens: Token[];
- private coinBase: string;
- constructor(zeroEx: ZeroEx, userAddresses: string[], tokens: Token[]) {
+ private coinbase: string;
+ private zrxTokenAddress: string;
+ constructor(zeroEx: ZeroEx, userAddresses: string[], tokens: Token[], zrxTokenAddress: string) {
this.zeroEx = zeroEx;
this.userAddresses = userAddresses;
this.tokens = tokens;
- this.coinBase = userAddresses[0];
+ this.coinbase = userAddresses[0];
+ this.zrxTokenAddress = zrxTokenAddress;
}
- public async createAFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
- makerAddress: string, takerAddress: string,
- fillableAmount: BigNumber.BigNumber,
- expirationUnixTimestampSec?: BigNumber.BigNumber):
+ public async createFillableSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
+ makerAddress: string, takerAddress: string,
+ fillableAmount: BigNumber.BigNumber,
+ expirationUnixTimestampSec?: BigNumber.BigNumber):
Promise<SignedOrder> {
- await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinBase, makerAddress, fillableAmount);
- await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, fillableAmount);
- await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinBase, takerAddress, fillableAmount);
- await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, fillableAmount);
-
- const transactionSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync();
- this.zeroEx.setTransactionSenderAccount(makerAddress);
- const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, makerAddress,
- takerAddress, fillableAmount, makerTokenAddress, fillableAmount, takerTokenAddress,
- expirationUnixTimestampSec);
- this.zeroEx.setTransactionSenderAccount(transactionSenderAccount as string);
- return signedOrder;
+ return this.createAsymmetricFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress,
+ fillableAmount, fillableAmount, expirationUnixTimestampSec,
+ );
+ }
+ public async createFillableSignedOrderWithFeesAsync(
+ makerTokenAddress: string, takerTokenAddress: string,
+ makerFee: BigNumber.BigNumber, takerFee: BigNumber.BigNumber,
+ makerAddress: string, takerAddress: string,
+ fillableAmount: BigNumber.BigNumber,
+ feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber,
+ ): Promise<SignedOrder> {
+ return this.createAsymmetricFillableSignedOrderWithFeesAsync(
+ makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress,
+ fillableAmount, fillableAmount, feeRecepient, expirationUnixTimestampSec,
+ );
+ }
+ public async createAsymmetricFillableSignedOrderAsync(
+ makerTokenAddress: string, takerTokenAddress: string, makerAddress: string, takerAddress: string,
+ makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber,
+ expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> {
+ const makerFee = new BigNumber(0);
+ const takerFee = new BigNumber(0);
+ const feeRecepient = constants.NULL_ADDRESS;
+ return this.createAsymmetricFillableSignedOrderWithFeesAsync(
+ makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress,
+ makerFillableAmount, takerFillableAmount, feeRecepient, expirationUnixTimestampSec,
+ );
}
public async createPartiallyFilledSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
takerAddress: string, fillableAmount: BigNumber.BigNumber,
partialFillAmount: BigNumber.BigNumber) {
const prevSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync();
const [makerAddress] = this.userAddresses;
- await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, fillableAmount);
- await this.zeroEx.token.transferAsync(takerTokenAddress, makerAddress, takerAddress, fillableAmount);
- await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, fillableAmount);
-
- const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, makerAddress,
- takerAddress, fillableAmount, makerTokenAddress, fillableAmount, takerTokenAddress);
+ const signedOrder = await this.createAsymmetricFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress,
+ fillableAmount, fillableAmount,
+ );
this.zeroEx.setTransactionSenderAccount(takerAddress);
const shouldCheckTransfer = false;
@@ -52,4 +69,34 @@ export class FillScenarios {
this.zeroEx.setTransactionSenderAccount(prevSenderAccount as string);
return signedOrder;
}
+ private async createAsymmetricFillableSignedOrderWithFeesAsync(
+ makerTokenAddress: string, takerTokenAddress: string,
+ makerFee: BigNumber.BigNumber, takerFee: BigNumber.BigNumber,
+ makerAddress: string, takerAddress: string,
+ makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber,
+ feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> {
+ await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinbase, makerAddress, makerFillableAmount);
+ await this.zeroEx.token.setProxyAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount);
+ await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinbase, takerAddress, takerFillableAmount);
+ await this.zeroEx.token.setProxyAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount);
+
+ if (!makerFee.isZero()) {
+ await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, makerAddress, makerFee);
+ await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, makerAddress, makerFee);
+ }
+ if (!takerFee.isZero()) {
+ await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, takerAddress, takerFee);
+ await this.zeroEx.token.setProxyAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee);
+ }
+
+ const prevTransactionSenderAccount = await this.zeroEx.getTransactionSenderAccountIfExistsAsync();
+ this.zeroEx.setTransactionSenderAccount(makerAddress);
+ const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx,
+ makerAddress, takerAddress, makerFee, takerFee,
+ makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress,
+ feeRecepient, expirationUnixTimestampSec);
+ // We re-set the transactionSender to avoid introducing side-effects
+ this.zeroEx.setTransactionSenderAccount(prevTransactionSenderAccount as string);
+ return signedOrder;
+ }
}