aboutsummaryrefslogtreecommitdiffstats
path: root/packages/fill-scenarios/src/index.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-07-06 17:10:55 +0800
committerGitHub <noreply@github.com>2018-07-06 17:10:55 +0800
commitb21f6e4d8652eb402fc1c8bbf8a13a024d945c74 (patch)
tree106a622d3b121c61fa011cd7e4134c12dd788b3a /packages/fill-scenarios/src/index.ts
parentbc52303402e6ee1b3ab9d948d909d1d10ebf26e4 (diff)
parent0c8264801ac15952861724ecd6a2620dc3055e5e (diff)
downloaddexon-0x-contracts-b21f6e4d8652eb402fc1c8bbf8a13a024d945c74.tar.gz
dexon-0x-contracts-b21f6e4d8652eb402fc1c8bbf8a13a024d945c74.tar.zst
dexon-0x-contracts-b21f6e4d8652eb402fc1c8bbf8a13a024d945c74.zip
Merge pull request #822 from 0xProject/v2-contract-wrappers-WIP
V2 contract wrappers
Diffstat (limited to 'packages/fill-scenarios/src/index.ts')
-rw-r--r--packages/fill-scenarios/src/index.ts49
1 files changed, 10 insertions, 39 deletions
diff --git a/packages/fill-scenarios/src/index.ts b/packages/fill-scenarios/src/index.ts
index 038826af2..f9b69e1f3 100644
--- a/packages/fill-scenarios/src/index.ts
+++ b/packages/fill-scenarios/src/index.ts
@@ -1,5 +1,5 @@
import { assetProxyUtils, orderFactory } from '@0xproject/order-utils';
-import { OrderWithoutExchangeAddress, SignedOrder, Token } from '@0xproject/types';
+import { OrderWithoutExchangeAddress, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider } from 'ethereum-types';
@@ -7,52 +7,29 @@ import * as _ from 'lodash';
import { artifacts } from './artifacts';
import { constants } from './constants';
-import { DummyERC20TokenContract } from './generated_contract_wrappers/dummy_e_r_c20_token';
-import { ERC20TokenContract } from './generated_contract_wrappers/e_r_c20_token';
+import { ERC20TokenContract } from './generated_contract_wrappers/erc20_token';
import { ExchangeContract } from './generated_contract_wrappers/exchange';
-const INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS = new BigNumber(100);
-
export class FillScenarios {
private _web3Wrapper: Web3Wrapper;
private _userAddresses: string[];
- private _tokens: Token[];
private _coinbase: string;
private _zrxTokenAddress: string;
private _exchangeAddress: string;
+ private _erc20ProxyAddress: string;
constructor(
provider: Provider,
userAddresses: string[],
- tokens: Token[],
zrxTokenAddress: string,
exchangeAddress: string,
+ erc20ProxyAddress: string,
) {
this._web3Wrapper = new Web3Wrapper(provider);
this._userAddresses = userAddresses;
- this._tokens = tokens;
this._coinbase = userAddresses[0];
this._zrxTokenAddress = zrxTokenAddress;
this._exchangeAddress = exchangeAddress;
- }
- public async initTokenBalancesAsync(): Promise<void> {
- for (const token of this._tokens) {
- if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') {
- const dummyERC20Token = new DummyERC20TokenContract(
- artifacts.DummyToken.abi,
- token.address,
- this._web3Wrapper.getProvider(),
- this._web3Wrapper.getContractDefaults(),
- );
- const tokenSupply = Web3Wrapper.toBaseUnitAmount(
- INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS,
- token.decimals,
- );
- const txHash = await dummyERC20Token.setBalance.sendTransactionAsync(this._coinbase, tokenSupply, {
- from: this._coinbase,
- });
- await this._web3Wrapper.awaitTransactionSuccessAsync(txHash);
- }
- }
+ this._erc20ProxyAddress = erc20ProxyAddress;
}
public async createFillableSignedOrderAsync(
makerAssetData: string,
@@ -138,7 +115,7 @@ export class FillScenarios {
fillableAmount,
);
const exchangeInstance = new ExchangeContract(
- artifacts.Exchange.abi,
+ artifacts.Exchange.compilerOutput.abi,
signedOrder.exchangeAddress,
this._web3Wrapper.getProvider(),
this._web3Wrapper.getContractDefaults(),
@@ -215,7 +192,7 @@ export class FillScenarios {
}
private async _increaseERC20BalanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
const token = new ERC20TokenContract(
- artifacts.Token.abi,
+ artifacts.ERC20Token.compilerOutput.abi,
tokenAddress,
this._web3Wrapper.getProvider(),
this._web3Wrapper.getContractDefaults(),
@@ -230,21 +207,15 @@ export class FillScenarios {
amount: BigNumber,
): Promise<void> {
const tokenInstance = new ERC20TokenContract(
- artifacts.Token.abi,
+ artifacts.ERC20Token.compilerOutput.abi,
tokenAddress,
this._web3Wrapper.getProvider(),
this._web3Wrapper.getContractDefaults(),
);
- const networkId = await this._web3Wrapper.getNetworkIdAsync();
- const networkArtifactsIfExists = artifacts.TokenTransferProxy.networks[networkId];
- if (_.isUndefined(networkArtifactsIfExists)) {
- throw new Error(`Did not find network artifacts for networkId: ${networkId}`);
- }
- const proxyAddress = networkArtifactsIfExists.address;
- const oldMakerAllowance = await tokenInstance.allowance.callAsync(address, proxyAddress);
+ const oldMakerAllowance = await tokenInstance.allowance.callAsync(address, this._erc20ProxyAddress);
const newMakerAllowance = oldMakerAllowance.plus(amount);
- await tokenInstance.approve.sendTransactionAsync(proxyAddress, newMakerAllowance, {
+ await tokenInstance.approve.sendTransactionAsync(this._erc20ProxyAddress, newMakerAllowance, {
from: address,
});
}