aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/erc20_wrapper.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-08 00:00:13 +0800
committerFabio Berger <me@fabioberger.com>2018-06-08 00:00:13 +0800
commitab5e021bda5cc8e39d8595580c09c3540a09aff5 (patch)
treee40c3be709d10e1a2463cb0807419c7b276f1548 /packages/contracts/src/utils/erc20_wrapper.ts
parent0fc981400442e4c567ca363bdf0f4c03ba87473d (diff)
downloaddexon-sol-tools-ab5e021bda5cc8e39d8595580c09c3540a09aff5.tar
dexon-sol-tools-ab5e021bda5cc8e39d8595580c09c3540a09aff5.tar.gz
dexon-sol-tools-ab5e021bda5cc8e39d8595580c09c3540a09aff5.tar.bz2
dexon-sol-tools-ab5e021bda5cc8e39d8595580c09c3540a09aff5.tar.lz
dexon-sol-tools-ab5e021bda5cc8e39d8595580c09c3540a09aff5.tar.xz
dexon-sol-tools-ab5e021bda5cc8e39d8595580c09c3540a09aff5.tar.zst
dexon-sol-tools-ab5e021bda5cc8e39d8595580c09c3540a09aff5.zip
POC: Generates an order from spec, get's the amount fillable
Diffstat (limited to 'packages/contracts/src/utils/erc20_wrapper.ts')
-rw-r--r--packages/contracts/src/utils/erc20_wrapper.ts28
1 files changed, 25 insertions, 3 deletions
diff --git a/packages/contracts/src/utils/erc20_wrapper.ts b/packages/contracts/src/utils/erc20_wrapper.ts
index dceeceeea..efb245c89 100644
--- a/packages/contracts/src/utils/erc20_wrapper.ts
+++ b/packages/contracts/src/utils/erc20_wrapper.ts
@@ -25,8 +25,11 @@ export class ERC20Wrapper {
this._tokenOwnerAddresses = tokenOwnerAddresses;
this._contractOwnerAddress = contractOwnerAddress;
}
- public async deployDummyTokensAsync(): Promise<DummyERC20TokenContract[]> {
- for (let i = 0; i < constants.NUM_DUMMY_ERC20_TO_DEPLOY; i++) {
+ public async deployDummyTokensAsync(num?: number, decimals?: BigNumber): Promise<DummyERC20TokenContract[]> {
+ // TODO(fabio): Remove and refactor all tests
+ const finalNum = _.isUndefined(num) ? constants.NUM_DUMMY_ERC20_TO_DEPLOY : num;
+ const finalDecimals = _.isUndefined(decimals) ? constants.DUMMY_TOKEN_DECIMALS : decimals;
+ for (let i = 0; i < finalNum; i++) {
this._dummyTokenContracts.push(
await DummyERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC20Token,
@@ -34,7 +37,7 @@ export class ERC20Wrapper {
txDefaults,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
- constants.DUMMY_TOKEN_DECIMALS,
+ finalDecimals,
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
),
);
@@ -73,6 +76,25 @@ export class ERC20Wrapper {
}
}
}
+ public async getBalanceAsync(owner: string, token: string): Promise<BigNumber> {
+ const tokenContractIfExists = _.find(this._dummyTokenContracts, c => c.address === token);
+ if (_.isUndefined(tokenContractIfExists)) {
+ throw new Error(`Token: ${token} was not deployed through ERC20Wrapper`);
+ }
+ const balance = new BigNumber(await tokenContractIfExists.balanceOf.callAsync(owner));
+ return balance;
+ }
+ public async getProxyAllowanceAsync(owner: string, token: string): Promise<BigNumber> {
+ this._validateProxyContractExistsOrThrow();
+ const tokenContractIfExists = _.find(this._dummyTokenContracts, c => c.address === token);
+ if (_.isUndefined(tokenContractIfExists)) {
+ throw new Error(`Token: ${token} was not deployed through ERC20Wrapper`);
+ }
+ const balance = new BigNumber(
+ await tokenContractIfExists.allowance.callAsync(owner, (this._proxyContract as ERC20ProxyContract).address),
+ );
+ return balance;
+ }
public async getBalancesAsync(): Promise<ERC20BalancesByOwner> {
this._validateDummyTokenContractsExistOrThrow();
const balancesByOwner: ERC20BalancesByOwner = {};