aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-07-03 20:49:51 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-07-05 21:05:57 +0800
commitc65b2573c46c118fad1fcada22e5b4033de115fb (patch)
tree4598d59a90916e21706cfa83508a7887414e17fa /packages
parent7fbee778751be1d396deede878a542a00e0b18c7 (diff)
downloaddexon-sol-tools-c65b2573c46c118fad1fcada22e5b4033de115fb.tar
dexon-sol-tools-c65b2573c46c118fad1fcada22e5b4033de115fb.tar.gz
dexon-sol-tools-c65b2573c46c118fad1fcada22e5b4033de115fb.tar.bz2
dexon-sol-tools-c65b2573c46c118fad1fcada22e5b4033de115fb.tar.lz
dexon-sol-tools-c65b2573c46c118fad1fcada22e5b4033de115fb.tar.xz
dexon-sol-tools-c65b2573c46c118fad1fcada22e5b4033de115fb.tar.zst
dexon-sol-tools-c65b2573c46c118fad1fcada22e5b4033de115fb.zip
Refactor fill-scenarios for V2
Diffstat (limited to 'packages')
-rw-r--r--packages/fill-scenarios/package.json4
-rw-r--r--packages/fill-scenarios/src/artifacts.ts14
-rw-r--r--packages/fill-scenarios/src/index.ts47
3 files changed, 16 insertions, 49 deletions
diff --git a/packages/fill-scenarios/package.json b/packages/fill-scenarios/package.json
index 91024ed34..32b02947f 100644
--- a/packages/fill-scenarios/package.json
+++ b/packages/fill-scenarios/package.json
@@ -9,14 +9,14 @@
"build": "yarn pre_build && tsc",
"pre_build": "run-s update_artifacts generate_contract_wrappers",
"update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json lib/artifacts; done;",
- "generate_contract_wrappers": "abi-gen --abis 'lib/artifacts/@(Exchange|ERC20Token|DummyERC20Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
+ "generate_contract_wrappers": "abi-gen --abis 'lib/artifacts/@(Exchange|ERC20Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
"copy_monorepo_scripts": "copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"clean": "shx rm -rf lib scripts src/generated_contract_wrappers",
"lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/*",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js"
},
"config": {
- "contracts": "Exchange ERC20Token DummyERC20Token"
+ "contracts": "Exchange ERC20Token"
},
"license": "Apache-2.0",
"repository": {
diff --git a/packages/fill-scenarios/src/artifacts.ts b/packages/fill-scenarios/src/artifacts.ts
index aa60e2fc4..f75374ba2 100644
--- a/packages/fill-scenarios/src/artifacts.ts
+++ b/packages/fill-scenarios/src/artifacts.ts
@@ -1,13 +1,9 @@
-import { Artifact } from '@0xproject/types';
+import { ContractArtifact } from '@0xproject/sol-compiler';
-import * as DummyToken from './compact_artifacts/DummyToken.json';
-import * as Exchange from './compact_artifacts/Exchange.json';
-import * as Token from './compact_artifacts/Token.json';
-import * as TokenTransferProxy from './compact_artifacts/TokenTransferProxy.json';
+import * as ERC20Token from './artifacts/ERC20Token.json';
+import * as Exchange from './artifacts/Exchange.json';
export const artifacts = {
- DummyToken: (DummyToken as any) as Artifact,
- Token: (Token as any) as Artifact,
- TokenTransferProxy: (TokenTransferProxy as any) as Artifact,
- Exchange: (Exchange as any) as Artifact,
+ ERC20Token: (ERC20Token as any) as ContractArtifact,
+ Exchange: (Exchange as any) as ContractArtifact,
};
diff --git a/packages/fill-scenarios/src/index.ts b/packages/fill-scenarios/src/index.ts
index 75417cf3a..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_erc20_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,
});
}